[FFmpeg-cvslog] add avcodec_get_subtitle_defaults() to initialize AVSubtitle struct

Aurelien Jacobs git at videolan.org
Mon Apr 11 23:31:16 CEST 2011


ffmpeg | branch: master | Aurelien Jacobs <aurel at gnuage.org> | Tue Apr  5 09:04:48 2011 +0200| [3ee8ca9b0894df3aaf5086c643283cb58ef9763d] | committer: Aurelien Jacobs

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 at gnuage.org>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3ee8ca9b0894df3aaf5086c643283cb58ef9763d
---

 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 7553bf0..a23567c 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 e04b4cc..74ef61b 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -70,13 +70,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.
  *
  * @param sub pointer to the AVSubtitle
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index c1ad0c4..024127a 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 4573713..288e6f5 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 507c181..bb3e124 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 3cc2e66..a91cfe7 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 701100a..aa73f4c 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 3fa012d..bd5bdfd 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 d24588b..a577ac8 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");



More information about the ffmpeg-cvslog mailing list