forked from duiniuluantanqin/mp4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stsd.c
149 lines (122 loc) · 3.84 KB
/
stsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "quicktime.h"
#include "funcprotos.h"
int quicktime_stsd_init(quicktime_stsd_t *stsd)
{
stsd->version = 0;
stsd->flags = 0;
stsd->total_entries = 0;
return 0;
}
int quicktime_stsd_init_table(quicktime_stsd_t *stsd)
{
if(!stsd->total_entries)
{
stsd->total_entries = 1;
stsd->table = (quicktime_stsd_table_t*)malloc(sizeof(quicktime_stsd_table_t) * stsd->total_entries);
quicktime_stsd_table_init(&(stsd->table[0]));
}
return 0;
}
int quicktime_stsd_init_video(quicktime_t *file,
quicktime_stsd_t *stsd,
int frame_w,
int frame_h,
float frame_rate,
char *compression)
{
quicktime_stsd_table_t *table;
quicktime_stsd_init_table(stsd);
table = &(stsd->table[0]);
quicktime_copy_char32(table->format, compression);
table->width = frame_w;
table->height = frame_h;
table->frames_per_sample = 1;
table->depth = 24;
table->ctab_id = 65535;
return 0;
}
int quicktime_stsd_init_audio(quicktime_t *file,
quicktime_stsd_t *stsd,
int channels,
int sample_rate,
int bits,
char *compressor)
{
quicktime_stsd_table_t *table;
quicktime_stsd_init_table(stsd);
table = &(stsd->table[0]);
quicktime_copy_char32(table->format, compressor);
table->channels = channels;
table->sample_size = bits;
table->sample_rate = sample_rate;
return 0;
}
int quicktime_stsd_init_hint(quicktime_t *file,
quicktime_stsd_t *stsd,
int maxPktSize,
int timeScale)
{
quicktime_stsd_table_t *table;
quicktime_stsd_init_table(stsd);
table = &(stsd->table[0]);
quicktime_copy_char32(table->format, "rtp ");
table->version = 1;
table->revision = 1;
table->maxPktSize = maxPktSize;
table->tims.timeScale = timeScale;
return 0;
}
int quicktime_stsd_delete(quicktime_stsd_t *stsd)
{
int i;
if(stsd->total_entries)
{
for(i = 0; i < stsd->total_entries; i++)
quicktime_stsd_table_delete(&(stsd->table[i]));
free(stsd->table);
}
stsd->total_entries = 0;
return 0;
}
int quicktime_stsd_dump(void *minf_ptr, quicktime_stsd_t *stsd)
{
int i;
printf(" sample description\n");
printf(" version %d\n", stsd->version);
printf(" flags %d\n", stsd->flags);
printf(" total_entries %d\n", stsd->total_entries);
for(i = 0; i < stsd->total_entries; i++)
{
quicktime_stsd_table_dump(minf_ptr, &(stsd->table[i]));
}
return 0;
}
int quicktime_read_stsd(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_t *stsd)
{
int i;
stsd->version = quicktime_read_char(file);
stsd->flags = quicktime_read_int24(file);
stsd->total_entries = quicktime_read_int32(file);
stsd->table = (quicktime_stsd_table_t*)malloc(sizeof(quicktime_stsd_table_t) * stsd->total_entries);
for(i = 0; i < stsd->total_entries; i++)
{
quicktime_stsd_table_init(&(stsd->table[i]));
quicktime_read_stsd_table(file, minf, &(stsd->table[i]));
}
return 0;
}
int quicktime_write_stsd(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_t *stsd)
{
quicktime_atom_t atom;
int i;
quicktime_atom_write_header(file, &atom, "stsd");
quicktime_write_char(file, stsd->version);
quicktime_write_int24(file, stsd->flags);
quicktime_write_int32(file, stsd->total_entries);
for(i = 0; i < stsd->total_entries; i++)
{
quicktime_write_stsd_table(file, minf, stsd->table);
}
quicktime_atom_write_footer(file, &atom);
return 0;
}