[vlc-devel] commit: libmpeg2: Enable CC parsing. (Derk-Jan Hartman )

git version control git at videolan.org
Fri Oct 10 23:20:31 CEST 2008


vlc | branch: 0.9-bugfix | Derk-Jan Hartman <hartman at videolan.org> | Fri Oct 10 23:11:48 2008 +0200| [2f4a1c6c182ec76aca7bc58a777aaad4a36d6af7] | committer: Derk-Jan Hartman 

libmpeg2: Enable CC parsing.

This is a feature, but almost fully copied from existing avcodec code.

Cherry-Picked from:
[d47c4459f76ebef89b941a045a4a20d941c85c11]
[74095abc994d2d59dc4840c7cfcc468c27485ffb]
[2b73786266205faa3e7b18f1d2dd33d459b3aa2f]

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2f4a1c6c182ec76aca7bc58a777aaad4a36d6af7
---

 modules/codec/libmpeg2.c |   74 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/modules/codec/libmpeg2.c b/modules/codec/libmpeg2.c
index 149ae58..ec6d332 100644
--- a/modules/codec/libmpeg2.c
+++ b/modules/codec/libmpeg2.c
@@ -33,6 +33,8 @@
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_codec.h>
+#include <vlc_block_helper.h>
+#include "../codec/cc.h"
 
 #include <mpeg2.h>
 
@@ -71,11 +73,16 @@ struct decoder_sys_t
      * Output properties
      */
     decoder_synchro_t *p_synchro;
-    int            i_aspect;
-    int            i_sar_num;
-    int            i_sar_den;
-    mtime_t        i_last_frame_pts;
-
+    int             i_aspect;
+    int             i_sar_num;
+    int             i_sar_den;
+    mtime_t         i_last_frame_pts;
+
+    /* Closed captioning support */
+    uint32_t        i_cc_flags;
+    mtime_t         i_cc_pts;
+    mtime_t         i_cc_dts;
+    cc_data_t       cc;
 };
 
 /*****************************************************************************
@@ -85,6 +92,7 @@ static int  OpenDecoder( vlc_object_t * );
 static void CloseDecoder( vlc_object_t * );
 
 static picture_t *DecodeBlock( decoder_t *, block_t ** );
+static block_t   *GetCc( decoder_t *p_dec, bool pb_present[4] );
 
 static picture_t *GetNewPicture( decoder_t *, uint8_t ** );
 static void GetAR( decoder_t *p_dec );
@@ -142,6 +150,14 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->b_skip     = 0;
     p_sys->b_preroll = false;
 
+    p_sys->i_cc_pts = 0;
+    p_sys->i_cc_dts = 0;
+    p_sys->i_cc_flags = 0;
+#if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
+    p_dec->pf_get_cc = GetCc;
+    cc_Init( &p_sys->cc );
+#endif
+
 #if defined( __i386__ ) || defined( __x86_64__ )
     if( vlc_CPU() & CPU_CAPABILITY_MMX )
     {
@@ -216,6 +232,9 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 block_Release( p_block );
                 return NULL;
             }
+            if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
+                                      | BLOCK_FLAG_CORRUPTED))
+                cc_Flush( &p_sys->cc );
 
             if( (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
                                       | BLOCK_FLAG_CORRUPTED)) &&
@@ -436,7 +455,21 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 }
 
                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
-        mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
+                mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
+            }
+            if( p_sys->p_info->user_data_len > 2 )
+            {
+                p_sys->i_cc_pts = i_pts;
+                p_sys->i_cc_dts = i_dts;
+                if( (p_sys->p_info->current_picture->flags
+                             & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P )
+                    p_sys->i_cc_flags = BLOCK_FLAG_TYPE_P;
+                else if( (p_sys->p_info->current_picture->flags
+                             & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
+                    p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B;
+                else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I;
+
+                cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
             }
         }
         break;
@@ -485,7 +518,6 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
                 return p_pic;
             }
-
             break;
 
         case STATE_INVALID:
@@ -502,6 +534,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             }
             mpeg2_skip( p_sys->p_mpeg2dec, 1 );
             p_sys->b_skip = 1;
+            cc_Flush( &p_sys->cc );
 
             if( p_sys->p_info->current_fbuf &&
                 p_sys->p_info->current_fbuf->id )
@@ -620,6 +653,33 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
 }
 
 /*****************************************************************************
+ * GetCc: Retrieves the Closed Captions for the CC decoder.
+ *****************************************************************************/
+static block_t *GetCc( decoder_t *p_dec, bool pb_present[4] )
+{
+    decoder_sys_t   *p_sys = p_dec->p_sys;
+    block_t         *p_cc = NULL;
+    int i;
+
+    for( i = 0; i < 4; i++ )
+        pb_present[i] = p_sys->cc.pb_present[i];
+
+    if( p_sys->cc.i_data <= 0 )
+        return NULL;
+
+    p_cc = block_New( p_dec, p_sys->cc.i_data);
+    if( p_cc )
+    {
+        memcpy( p_cc->p_buffer, p_sys->cc.p_data, p_sys->cc.i_data );
+        p_cc->i_dts =
+        p_cc->i_pts = p_sys->cc.b_reorder ? p_sys->i_cc_pts : p_sys->i_cc_dts;
+        p_cc->i_flags = ( p_sys->cc.b_reorder  ? p_sys->i_cc_flags : BLOCK_FLAG_TYPE_P ) & ( BLOCK_FLAG_TYPE_I|BLOCK_FLAG_TYPE_P|BLOCK_FLAG_TYPE_B);
+    }
+    cc_Flush( &p_sys->cc );
+    return p_cc;
+}
+
+/*****************************************************************************
  * GetAR: Get aspect ratio
  *****************************************************************************/
 static void GetAR( decoder_t *p_dec )




More information about the vlc-devel mailing list