]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/mpegvideo.c
Qt4 - Simple Preferences, audio: you expect to deal with % for the volume not abstrac...
[vlc] / modules / packetizer / mpegvideo.c
index 704f4d08d7cad2a28c39575e7dd7c6c957eeafab..19fd9543e36763934dd5e265c6571bd6912839d3 100644 (file)
  * Preamble
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_block.h>
 #include <vlc_codec.h>
 #include <vlc_block_helper.h>
+#include "../codec/cc.h"
 
 #define SYNC_INTRAFRAME_TEXT N_("Sync on Intra Frame")
 #define SYNC_INTRAFRAME_LONGTEXT N_("Normally the packetizer would " \
@@ -74,6 +79,7 @@ vlc_module_end();
  *****************************************************************************/
 static block_t *Packetize( decoder_t *, block_t ** );
 static block_t *ParseMPEGBlock( decoder_t *, block_t * );
+static block_t *GetCc( decoder_t *p_dec, vlc_bool_t pb_present[4] );
 
 struct decoder_sys_t
 {
@@ -82,7 +88,7 @@ struct decoder_sys_t
      */
     block_bytestream_t bytestream;
     int i_state;
-    int i_offset;
+    size_t i_offset;
     uint8_t p_startcode[3];
 
     /* Sequence header and extension */
@@ -123,6 +129,13 @@ struct decoder_sys_t
     /* Sync behaviour */
     vlc_bool_t  b_sync_on_intra_frame;
     vlc_bool_t  b_discontinuity;
+
+    /* */
+    vlc_bool_t b_cc_reset;
+    uint32_t i_cc_flags;
+    mtime_t i_cc_pts;
+    mtime_t i_cc_dts;
+    cc_data_t cc;
 };
 
 enum {
@@ -147,12 +160,13 @@ static int Open( vlc_object_t *p_this )
 
     es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC('m','p','g','v') );
     p_dec->pf_packetize = Packetize;
+    p_dec->pf_get_cc = GetCc;
 
     p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
 
     /* Misc init */
     p_sys->i_state = STATE_NOSYNC;
-    p_sys->bytestream = block_BytestreamInit( p_dec );
+    p_sys->bytestream = block_BytestreamInit();
     p_sys->p_startcode[0] = 0;
     p_sys->p_startcode[1] = 0;
     p_sys->p_startcode[2] = 1;
@@ -189,6 +203,12 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->b_sync_on_intra_frame )
         msg_Dbg( p_dec, "syncing on intra frame now" );
 
+    p_sys->b_cc_reset = VLC_FALSE;
+    p_sys->i_cc_pts = 0;
+    p_sys->i_cc_dts = 0;
+    p_sys->i_cc_flags = 0;
+    cc_Init( &p_sys->cc );
+
     return VLC_SUCCESS;
 }
 
@@ -367,6 +387,33 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
     }
 }
 
+/*****************************************************************************
+ * GetCc:
+ *****************************************************************************/
+static block_t *GetCc( decoder_t *p_dec, vlc_bool_t pb_present[4] )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    block_t *p_cc;
+    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;
+}
+
 /*****************************************************************************
  * ParseMPEGBlock: Re-assemble fragments into a block containing a picture
  *****************************************************************************/
@@ -498,6 +545,18 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
         {
             p_sys->b_second_field = 0;
         }
+
+        /* CC */
+        p_sys->b_cc_reset = VLC_TRUE;
+        p_sys->i_cc_pts = p_pic->i_pts;
+        p_sys->i_cc_dts = p_pic->i_dts;
+        p_sys->i_cc_flags = p_pic->i_flags;
+    }
+
+    if( !p_pic && p_sys->b_cc_reset )
+    {
+        p_sys->b_cc_reset = VLC_FALSE;
+        cc_Flush( &p_sys->cc );
     }
 
     /*
@@ -618,6 +677,10 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
             p_sys->i_progressive_frame = p_frag->p_buffer[8] >> 7;
         }
     }
+    else if( p_frag->p_buffer[3] == 0xb2 && p_frag->i_buffer > 4 )
+    {
+        cc_Extract( &p_sys->cc, &p_frag->p_buffer[4], p_frag->i_buffer - 4 );
+    }
     else if( p_frag->p_buffer[3] == 0x00 )
     {
         /* Picture start code */