[FFmpeg-devel] [PATCH 2/2] lavc: add support for CODEC_CAP_DELAY in subtitles

Marton Balint cus at passwd.hu
Sun Oct 20 18:24:56 CEST 2013


This patch adds CODEC_CAP_DELAY support to avcodec_decode_subtitle2.

For DVB teletext decoding, a single teletext packet can contain multiple
teletext pages. In order to support that, the teletext decoder may buffer
some pages.

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 doc/APIchanges       | 3 +++
 libavcodec/avcodec.h | 8 ++++++++
 libavcodec/utils.c   | 2 +-
 libavcodec/version.h | 4 ++--
 4 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c1f103a..42e1e25 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-10-xx - xxxxxxx - lavc 55.38.100 - avcodec.h
+  Add CODEC_CAP_DELAY support to avcodec_decode_subtitle2.
+
 libavutil 52.47.100
 2013-10-17 - xxxxxxx - lavu 52.47.100 - opt.h
   Add AV_OPT_TYPE_CHANNEL_LAYOUT and channel layout option handlers
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b9a9f25..8b35e71 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3894,6 +3894,14 @@ int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  * and reusing a get_buffer written for video codecs would probably perform badly
  * due to a potentially very different allocation pattern.
  *
+ * Some decoders (those marked with CODEC_CAP_DELAY) have a delay between input
+ * and output. This means that for some packets they will not immediately
+ * produce decoded output and need to be flushed at the end of decoding to get
+ * all the decoded data. Flushing is done by calling this function with packets
+ * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
+ * returning samples. It is safe to flush even those decoders that are not
+ * marked with CODEC_CAP_DELAY, then no samples will be returned.
+ *
  * @param avctx the codec context
  * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
                    freed with avsubtitle_free if *got_sub_ptr is set.
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 37d6ee3..6620c49 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2352,7 +2352,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
     *got_sub_ptr = 0;
     avcodec_get_subtitle_defaults(sub);
 
-    if (avpkt->size) {
+    if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
         AVPacket pkt_recoded;
         AVPacket tmp = *avpkt;
         int did_split = av_packet_split_side_data(&tmp);
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 1bb8377..db43b83 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,8 +29,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 55
-#define LIBAVCODEC_VERSION_MINOR  37
-#define LIBAVCODEC_VERSION_MICRO 102
+#define LIBAVCODEC_VERSION_MINOR  38
+#define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
1.8.1.4



More information about the ffmpeg-devel mailing list