2 #include "mpeg3protos.h"
6 mpeg3_vtrack_t
* mpeg3_new_vtrack(mpeg3_t
*file
,
8 mpeg3_demuxer_t
*demuxer
,
12 mpeg3_vtrack_t
*new_vtrack
;
14 new_vtrack
= calloc(1, sizeof(mpeg3_vtrack_t
));
15 new_vtrack
->demuxer
= mpeg3_new_demuxer(file
, 0, 1, custom_id
);
18 mpeg3demux_copy_titles(new_vtrack
->demuxer
, demuxer
);
20 new_vtrack
->current_position
= 0;
21 new_vtrack
->pid
= custom_id
;
24 if(file
->frame_offsets
)
26 new_vtrack
->frame_offsets
= file
->frame_offsets
[number
];
27 new_vtrack
->total_frame_offsets
= file
->total_frame_offsets
[number
];
28 new_vtrack
->keyframe_numbers
= file
->keyframe_numbers
[number
];
29 new_vtrack
->total_keyframe_numbers
= file
->total_keyframe_numbers
[number
];
30 new_vtrack
->demuxer
->stream_end
= file
->video_eof
[number
];
33 /* Get information about the track here. */
34 new_vtrack
->video
= mpeg3video_new(file
,
36 if(!new_vtrack
->video
)
39 mpeg3_delete_vtrack(file
, new_vtrack
);
47 int mpeg3_delete_vtrack(mpeg3_t
*file
, mpeg3_vtrack_t
*vtrack
)
49 if(vtrack
->video
) mpeg3video_delete(vtrack
->video
);
50 if(vtrack
->demuxer
) mpeg3_delete_demuxer(vtrack
->demuxer
);
51 if(vtrack
->private_offsets
)
53 if(vtrack
->frame_offsets
) free(vtrack
->frame_offsets
);
54 if(vtrack
->keyframe_numbers
) free(vtrack
->keyframe_numbers
);
60 void mpeg3_append_frame(mpeg3_vtrack_t
*vtrack
, int64_t offset
, int is_keyframe
)
62 if(vtrack
->total_frame_offsets
>= vtrack
->frame_offsets_allocated
)
64 vtrack
->frame_offsets_allocated
=
65 MAX(vtrack
->total_frame_offsets
* 2, 1024);
66 vtrack
->frame_offsets
= realloc(vtrack
->frame_offsets
,
67 sizeof(int64_t) * vtrack
->frame_offsets_allocated
);
70 vtrack
->frame_offsets
[vtrack
->total_frame_offsets
++] = offset
;
74 if(vtrack
->total_keyframe_numbers
>= vtrack
->keyframe_numbers_allocated
)
76 vtrack
->keyframe_numbers_allocated
=
77 MAX(vtrack
->total_keyframe_numbers
* 2, 1024);
78 vtrack
->keyframe_numbers
= realloc(vtrack
->keyframe_numbers
,
79 sizeof(int64_t) * vtrack
->keyframe_numbers_allocated
);
82 // Because the frame offsets are for the frame
83 // after, this needs to take off one frame.
84 int corrected_frame
= vtrack
->total_frame_offsets
- 2;
85 if(corrected_frame
< 0) corrected_frame
= 0;
86 vtrack
->keyframe_numbers
[vtrack
->total_keyframe_numbers
++] =
90 vtrack
->private_offsets
= 1;