add avcodec_get_subtitle_defaults() to initialize AVSubtitle struct

Call this new function before decode() to replace the custom and
inconsistant initialization in various decoders.
This function is equivalent to avcodec_get_frame_defaults() for AVFrame.

Signed-off-by: Aurelien Jacobs <aurel@gnuage.org>
This commit is contained in:
Aurelien Jacobs 2011-04-05 09:04:48 +02:00
parent c104a6e902
commit 3ee8ca9b08
9 changed files with 7 additions and 23 deletions

View File

@ -62,11 +62,6 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx)
ASS_DEFAULT_ALIGNMENT);
}
void ff_ass_init(AVSubtitle *sub)
{
memset(sub, 0, sizeof(*sub));
}
static int ts_to_string(char *str, int strlen, int ts)
{
int h, m, s;

View File

@ -69,13 +69,6 @@ int ff_ass_subtitle_header(AVCodecContext *avctx,
*/
int ff_ass_subtitle_header_default(AVCodecContext *avctx);
/**
* Initialize an AVSubtitle structure for use with ff_ass_add_rect().
*
* @param sub pointer to the AVSubtitle
*/
void ff_ass_init(AVSubtitle *sub);
/**
* Add an ASS dialog line to an AVSubtitle as a new AVSubtitleRect.
*

View File

@ -38,8 +38,6 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
const char *ptr = avpkt->data;
int len, size = avpkt->size;
ff_ass_init(data);
while (size > 0) {
len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
if (len < 0)

View File

@ -1323,10 +1323,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
int i;
int offset_x=0, offset_y=0;
sub->rects = NULL;
sub->start_display_time = 0;
sub->end_display_time = ctx->time_out * 1000;
sub->format = 0;
if (display_def) {
offset_x = display_def->x;

View File

@ -173,7 +173,6 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
if (buf_size < 10)
return -1;
memset(sub_header, 0, sizeof(*sub_header));
if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */
big_offsets = 1;

View File

@ -357,7 +357,6 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
* not been cleared by a subsequent empty display command.
*/
memset(sub, 0, sizeof(*sub));
// Blank if last object_number was 0.
// Note that this may be wrong for more complex subtitles.
if (!ctx->presentation.object_number)

View File

@ -216,8 +216,6 @@ static int srt_decode_frame(AVCodecContext *avctx,
if (avpkt->size <= 0)
return avpkt->size;
ff_ass_init(sub);
while (ptr < end && *ptr) {
ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2);
if (!ptr)

View File

@ -474,6 +474,12 @@ AVFrame *avcodec_alloc_frame(void){
return pic;
}
static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
{
memset(sub, 0, sizeof(*sub));
sub->pts = AV_NOPTS_VALUE;
}
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
{
int ret= -1;
@ -795,6 +801,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
avctx->pkt = avpkt;
*got_sub_ptr = 0;
avcodec_get_subtitle_defaults(sub);
ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
if (*got_sub_ptr)
avctx->frame_number++;

View File

@ -55,8 +55,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int64_t packet_time = 0;
GetBitContext gb;
memset(sub, 0, sizeof(*sub));
// check that at least header fits
if (buf_size < 27 + 7 * 2 + 4 * 3) {
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");