[vlc-devel] [PATCH 1/2] AVCodec Subtitle decoder : Add support for re-assembly of subtitle packets.

Jai Menon jmenon86 at gmail.com
Thu Jun 24 13:15:07 CEST 2010


---
 modules/codec/avcodec/subtitle.c |   46 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index 205e02b..26e521b 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -51,6 +51,9 @@
 
 struct decoder_sys_t {
     FFMPEG_COMMON_MEMBERS
+    int sub_packet_size;
+    int sub_count;
+    block_t *p_block;
 };
 
 static subpicture_t *ConvertSubtitle(decoder_t *, AVSubtitle *, mtime_t pts);
@@ -86,6 +89,9 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
     sys->i_codec_id = codec_id;
     sys->psz_namecodec = namecodec;
     sys->b_delayed_open = false;
+    sys->sub_packet_size = 0;
+    sys->sub_count = 0;
+    sys->p_block = NULL;
 
     /* */
     context->extradata_size = 0;
@@ -109,17 +115,55 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
     return VLC_SUCCESS;
 }
 
+static block_t *DVDSubPacketize( decoder_t *p_dec, block_t **pp_block )
+{
+    decoder_sys_t *sys = p_dec->p_sys;
+    block_t *p_block;
+
+    p_block = *pp_block;
+    *pp_block = NULL;
+
+    if( !( sys->sub_packet_size = GetWBE( p_block->p_buffer ) ) )
+    {
+        sys->sub_packet_size = GetDWBE( p_block->p_buffer + 2 );
+    }
+    if( !sys->sub_packet_size )
+    {
+        block_Release( p_block );
+        return NULL;
+    }
+
+    block_ChainAppend( &sys->p_block, p_block );
+    sys->sub_count += p_block->i_buffer;
+    if( sys->sub_count >= sys->sub_packet_size )
+    {
+        sys->sub_packet_size =
+        sys->sub_count = 0;
+        p_block = sys->p_block;
+        sys->p_block = NULL;
+        return block_ChainGather( p_block );
+    }
+    return NULL;
+}
+
 /**
  * Decode one subtitle
  */
 subpicture_t *DecodeSubtitle(decoder_t *dec, block_t **block_ptr)
 {
     decoder_sys_t *sys = dec->p_sys;
+    block_t *block;
 
     if (!block_ptr || !*block_ptr)
         return NULL;
 
-    block_t *block = *block_ptr;
+    if( sys->i_codec_id == CODEC_ID_DVD_SUBTITLE )
+    {
+        block = DVDSubPacketize(dec, block_ptr);
+        if (!block)
+            return NULL;
+    }
+    else block = *block_ptr;
 
     if (block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) {
         block_Release(block);
-- 
1.7.1




More information about the vlc-devel mailing list