]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/h264.c
Cosmetic (turned a big macro into a function).
[vlc] / modules / packetizer / h264.c
index 680cc0e7b045d7f820c15535894e279647650c8a..eeb8d80fb4646a854edab9ff31b3046bfb2f6cd7 100644 (file)
@@ -32,7 +32,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_codec.h>
 #include <vlc_block.h>
@@ -49,7 +50,7 @@ static void Close( vlc_object_t * );
 vlc_module_begin();
     set_category( CAT_SOUT );
     set_subcategory( SUBCAT_SOUT_PACKETIZER );
-    set_description( _("H.264 video packetizer") );
+    set_description( N_("H.264 video packetizer") );
     set_capability( "packetizer", 50 );
     set_callbacks( Open, Close );
 vlc_module_end();
@@ -173,8 +174,7 @@ static int Open( vlc_object_t *p_this )
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys = malloc( sizeof(decoder_sys_t) ) ) == NULL )
     {
-        msg_Err( p_dec, "out of memory" );
-        return VLC_EGENERIC;
+        return VLC_ENOMEM;
     }
     p_sys->i_state = STATE_NOSYNC;
     p_sys->i_offset = 0;
@@ -259,16 +259,19 @@ static int Open( vlc_object_t *p_this )
                  p_sys->i_avcC_length_size, i_sps, i_pps );
 
         /* FIXME: FFMPEG isn't happy at all if you leave this */
-        if( p_dec->fmt_out.i_extra ) free( p_dec->fmt_out.p_extra );
-        p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = NULL;
+        if( p_dec->fmt_out.i_extra > 0 ) free( p_dec->fmt_out.p_extra );
+        p_dec->fmt_out.i_extra = 0;
+        p_dec->fmt_out.p_extra = NULL;
 
         /* Set the new extradata */
         p_dec->fmt_out.i_extra = p_sys->p_pps->i_buffer + p_sys->p_sps->i_buffer;
-        p_dec->fmt_out.p_extra = (uint8_t*)malloc( p_dec->fmt_out.i_extra );
+        p_dec->fmt_out.p_extra = malloc( p_dec->fmt_out.i_extra );
         if( p_dec->fmt_out.p_extra )
         {
-            memcpy( (uint8_t*)p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer);
-            memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer);
+            memcpy( (uint8_t*)p_dec->fmt_out.p_extra,
+                    p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer);
+            memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer,
+                    p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer);
             p_sys->b_header = true;
         }
         else p_dec->fmt_out.i_extra = 0;
@@ -411,7 +414,7 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
                     break;
                 }
 #if 0
-                msg_Dbg( p_dec, "pts="I64Fd" dts="I64Fd,
+                msg_Dbg( p_dec, "pts=%"PRId64" dts=%"PRId64,
                          p_pic->i_pts, p_pic->i_dts );
 #endif
 
@@ -500,6 +503,7 @@ static block_t *nal_get_annexeb( decoder_t *p_dec, uint8_t *p, int i_size )
     /* Copy nalu */
     memcpy( &p_nal->p_buffer[4], p, i_size );
 
+    VLC_UNUSED(p_dec);
     return p_nal;
 }
 
@@ -552,6 +556,39 @@ static inline int bs_read_se( bs_t *s )
  * ParseNALBlock: parses annexB type NALs
  * All p_frag blocks are required to start with 0 0 0 1 4-byte startcode
  *****************************************************************************/
+static block_t *OutputPicture( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    block_t *p_pic;
+
+    if( !p_sys->b_header && p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I)
+        return NULL;
+
+    if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I && p_sys->p_sps && p_sys->p_pps )
+    {
+        block_t *p_sps = block_Duplicate( p_sys->p_sps );
+        block_t *p_pps = block_Duplicate( p_sys->p_pps );
+        p_sps->i_dts = p_sys->p_frame->i_dts;
+        p_sps->i_pts = p_sys->p_frame->i_pts;
+        block_ChainAppend( &p_sps, p_pps );
+        block_ChainAppend( &p_sps, p_sys->p_frame );
+        p_sys->b_header = true;
+        p_pic = block_ChainGather( p_sps );
+    }
+    else
+    {
+        p_pic = block_ChainGather( p_sys->p_frame );
+    }
+    p_pic->i_length = 0;    /* FIXME */
+    p_pic->i_flags |= p_sys->slice.i_frame_type;
+
+    p_sys->slice.i_frame_type = 0;
+    p_sys->p_frame = NULL;
+    p_sys->b_slice = false;
+
+    return p_pic;
+}
+
 static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -560,32 +597,6 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
     const int i_nal_ref_idc = (p_frag->p_buffer[4] >> 5)&0x03;
     const int i_nal_type = p_frag->p_buffer[4]&0x1f;
 
-#define OUTPUT \
-    do {                                                      \
-        if( !p_sys->b_header && p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I) \
-            break;                                            \
-                                                              \
-        if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I && p_sys->p_sps && p_sys->p_pps ) \
-        { \
-            block_t *p_sps = block_Duplicate( p_sys->p_sps ); \
-            block_t *p_pps = block_Duplicate( p_sys->p_pps ); \
-            p_sps->i_dts = p_sys->p_frame->i_dts;           \
-            p_sps->i_pts = p_sys->p_frame->i_pts;           \
-            block_ChainAppend( &p_sps, p_pps );               \
-            block_ChainAppend( &p_sps, p_sys->p_frame );      \
-            p_sys->b_header = true;                       \
-            p_pic = block_ChainGather( p_sps );               \
-        } else { \
-            p_pic = block_ChainGather( p_sys->p_frame ); \
-        } \
-        p_pic->i_length = 0;    /* FIXME */                   \
-        p_pic->i_flags |= p_sys->slice.i_frame_type;          \
-            \
-        p_sys->slice.i_frame_type = 0;                        \
-        p_sys->p_frame = NULL;                                \
-        p_sys->b_slice = false;                           \
-    } while(0)
-
     if( p_sys->b_slice && ( !p_sys->b_sps || !p_sys->b_pps ) )
     {
         block_ChainRelease( p_sys->p_frame );
@@ -709,7 +720,7 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
         p_sys->slice = slice;
 
         if( b_pic && p_sys->b_slice )
-            OUTPUT;
+            p_pic = OutputPicture( p_dec );
 
         p_sys->b_slice = true;
 
@@ -836,7 +847,8 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
 
         free( dec );
 
-        if( p_sys->b_slice ) OUTPUT;
+        if( p_sys->b_slice )
+            p_pic = OutputPicture( p_dec );
 
         /* We have a new SPS */
         if( p_sys->p_sps ) block_Release( p_sys->p_sps );
@@ -860,7 +872,8 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
 
         /* TODO */
 
-        if( p_sys->b_slice ) OUTPUT;
+        if( p_sys->b_slice )
+            p_pic = OutputPicture( p_dec );
 
         /* We have a new PPS */
         if( p_sys->p_pps ) block_Release( p_sys->p_pps );
@@ -873,11 +886,10 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
              i_nal_type == NAL_SEI ||
              ( i_nal_type >= 13 && i_nal_type <= 18 ) )
     {
-        if( p_sys->b_slice ) OUTPUT;
+        if( p_sys->b_slice )
+            p_pic = OutputPicture( p_dec );
     }
 
-#undef OUTPUT
-
     /* Append the block */
     block_ChainAppend( &p_sys->p_frame, p_frag );