From 3ee8ca9b0894df3aaf5086c643283cb58ef9763d Mon Sep 17 00:00:00 2001 From: Aurelien Jacobs Date: Tue, 5 Apr 2011 09:04:48 +0200 Subject: [PATCH] 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 --- libavcodec/ass.c | 5 ----- libavcodec/ass.h | 7 ------- libavcodec/assdec.c | 2 -- libavcodec/dvbsubdec.c | 3 --- libavcodec/dvdsubdec.c | 1 - libavcodec/pgssubdec.c | 1 - libavcodec/srtdec.c | 2 -- libavcodec/utils.c | 7 +++++++ libavcodec/xsubdec.c | 2 -- 9 files changed, 7 insertions(+), 23 deletions(-) diff --git a/libavcodec/ass.c b/libavcodec/ass.c index 7553bf0778..a23567cba4 100644 --- a/libavcodec/ass.c +++ b/libavcodec/ass.c @@ -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; diff --git a/libavcodec/ass.h b/libavcodec/ass.h index e04b4cc747..74ef61b776 100644 --- a/libavcodec/ass.h +++ b/libavcodec/ass.h @@ -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. * diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c index c1ad0c4af4..024127a042 100644 --- a/libavcodec/assdec.c +++ b/libavcodec/assdec.c @@ -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) diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index 457371361c..288e6f51fe 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -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; diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index 507c1813ff..bb3e124bcd 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -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; diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index 3cc2e665b1..a91cfe7bf6 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -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) diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index 701100a96c..aa73f4c7bf 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -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) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 3fa012dde4..bd5bdfd383 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -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++; diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c index d24588b8d9..a577ac8f28 100644 --- a/libavcodec/xsubdec.c +++ b/libavcodec/xsubdec.c @@ -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");