1 #include "funcprotos.h"
16 static int is_keyframe(quicktime_trak_t
*trak
, int frame
)
19 quicktime_stss_t
*stss
= &trak
->mdia
.minf
.stbl
.stss
;
21 for(i
= 0; i
< stss
->total_entries
; i
++)
23 if(stss
->table
[i
].sample
== frame
) return 1;
29 void quicktime_delete_idx1(quicktime_idx1_t
*idx1
)
31 if(idx1
->table
) free(idx1
->table
);
34 void quicktime_read_idx1(quicktime_t
*file
,
35 quicktime_riff_t
*riff
,
36 quicktime_atom_t
*parent_atom
)
39 quicktime_riff_t
*first_riff
= file
->riff
[0];
40 quicktime_hdrl_t
*hdrl
= &first_riff
->hdrl
;
41 quicktime_idx1_t
*idx1
= &riff
->idx1
;
43 //printf("quicktime_read_idx1 1 %llx\n", quicktime_position(file));
46 idx1
->table_size
= (parent_atom
->end
- quicktime_position(file
)) / 16;
47 idx1
->table_allocation
= idx1
->table_size
;
48 idx1
->table
= calloc(sizeof(quicktime_idx1table_t
), idx1
->table_size
);
49 //printf("quicktime_read_idx1 10\n");
51 // Store it in idx1 table now.
52 // Wait for full ix table discovery before converting to stco.
53 for(i
= 0; i
< idx1
->table_size
; i
++)
55 quicktime_idx1table_t
*idx1table
= idx1
->table
+ i
;
57 quicktime_read_data(file
, idx1table
->tag
, 4);
58 idx1table
->flags
= quicktime_read_int32_le(file
);
59 idx1table
->offset
= quicktime_read_int32_le(file
);
60 idx1table
->size
= quicktime_read_int32_le(file
);
63 //printf("quicktime_read_idx1 100\n");
73 void quicktime_write_idx1(quicktime_t
*file
,
74 quicktime_idx1_t
*idx1
)
77 quicktime_idx1table_t
*table
= idx1
->table
;
78 int table_size
= idx1
->table_size
;
83 quicktime_atom_write_header(file
, &idx1
->atom
, "idx1");
85 for(i
= 0; i
< table_size
; i
++)
87 quicktime_idx1table_t
*entry
= &table
[i
];
88 quicktime_write_char32(file
, entry
->tag
);
89 quicktime_write_int32_le(file
, entry
->flags
);
90 quicktime_write_int32_le(file
, entry
->offset
);
91 quicktime_write_int32_le(file
, entry
->size
);
95 quicktime_atom_write_footer(file
, &idx1
->atom
);
98 void quicktime_set_idx1_keyframe(quicktime_t
*file
,
99 quicktime_trak_t
*trak
,
102 quicktime_riff_t
*riff
= file
->riff
[0];
103 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
104 quicktime_strl_t
*strl
= hdrl
->strl
[trak
->tkhd
.track_id
- 1];
105 char *tag
= strl
->tag
;
106 quicktime_idx1_t
*idx1
= &riff
->idx1
;
110 // Search through entire index for right numbered tag.
111 // Since all the tracks are combined in the same index, this is unavoidable.
112 for(i
= 0; i
< idx1
->table_size
; i
++)
114 quicktime_idx1table_t
*idx1_table
= &idx1
->table
[i
];
115 if(!memcmp(idx1_table
->tag
, tag
, 4))
118 if(counter
== new_keyframe
)
120 idx1_table
->flags
|= AVI_KEYFRAME
;
127 void quicktime_update_idx1table(quicktime_t
*file
,
128 quicktime_trak_t
*trak
,
132 quicktime_riff_t
*riff
= file
->riff
[0];
133 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
134 quicktime_strl_t
*strl
= hdrl
->strl
[trak
->tkhd
.track_id
- 1];
135 char *tag
= strl
->tag
;
136 quicktime_idx1_t
*idx1
= &riff
->idx1
;
137 quicktime_movi_t
*movi
= &riff
->movi
;
138 quicktime_idx1table_t
*idx1_table
;
139 quicktime_stss_t
*stss
= &trak
->mdia
.minf
.stbl
.stss
;
142 int keyframe_frame
= idx1
->table_size
+ 1;
144 // Set flag for keyframe
145 for(i
= stss
->total_entries
- 1; i
>= 0; i
--)
147 if(stss
->table
[i
].sample
== keyframe_frame
)
149 flags
|= AVI_KEYFRAME
;
153 if(stss
->table
[i
].sample
< keyframe_frame
)
161 if(idx1
->table_size
>= idx1
->table_allocation
)
163 quicktime_idx1table_t
*old_table
= idx1
->table
;
164 int new_allocation
= idx1
->table_allocation
* 2;
165 if(new_allocation
< 1) new_allocation
= 1;
166 idx1
->table
= calloc(1, sizeof(quicktime_idx1table_t
) * new_allocation
);
169 memcpy(idx1
->table
, old_table
, sizeof(quicktime_idx1table_t
) * idx1
->table_size
);
172 idx1
->table_allocation
= new_allocation
;
177 idx1_table
= &idx1
->table
[idx1
->table_size
];
178 memcpy(idx1_table
->tag
, tag
, 4);
179 idx1_table
->flags
= flags
;
180 idx1_table
->offset
= offset
- 8 - movi
->atom
.start
;
181 idx1_table
->size
= size
;