]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/transcode.c
* rtp, display: update p_sout->i_out_pace_nocontrol.
[vlc] / modules / stream_out / transcode.c
index d93338e5f376534e6d862873975a21d7b128cea6..9238e0bdeb45cc6e67a1cae4cb6ca89e0644f9f7 100644 (file)
@@ -2,7 +2,7 @@
  * transcode.c: transcoding stream output module
  *****************************************************************************
  * Copyright (C) 2003-2004 VideoLAN
- * $Id: transcode.c,v 1.80 2004/02/24 17:42:07 gbazin Exp $
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Gildas Bazin <gbazin@netcourrier.com>
 #   include <avcodec.h>
 #endif
 
+#if LIBAVCODEC_BUILD < 4704
+#   define AV_NOPTS_VALUE 0
+#endif
+
 /*****************************************************************************
  * Exported prototypes
  *****************************************************************************/
@@ -782,7 +786,7 @@ static int transcode_audio_ffmpeg_new( sout_stream_t *p_stream,
     id->p_encoder->fmt_out.i_bitrate = id->f_dst.i_bitrate;
 
     id->p_encoder->p_module =
-        module_Need( id->p_encoder, "encoder", NULL );
+        module_Need( id->p_encoder, "encoder", NULL, 0 );
     if( !id->p_encoder->p_module )
     {
         vlc_object_destroy( id->p_encoder );
@@ -1072,9 +1076,54 @@ static int transcode_video_ffmpeg_new( sout_stream_t *p_stream,
         id->ff_dec_c = avcodec_alloc_context();
         id->ff_dec_c->width         = id->f_src.video.i_width;
         id->ff_dec_c->height        = id->f_src.video.i_height;
+        id->ff_dec_c->bits_per_sample=id->f_src.video.i_bits_per_pixel;
         /* id->ff_dec_c->bit_rate      = id->f_src.i_bitrate; */
-        id->ff_dec_c->extradata_size= id->f_src.i_extra;
-        id->ff_dec_c->extradata     = id->f_src.p_extra;
+
+        if( id->f_src.i_extra > 0 )
+        {
+            if( i_ff_codec == CODEC_ID_SVQ3 )
+            {
+                int i_size = id->f_src.i_extra;
+                uint8_t *p;
+
+                id->ff_dec_c->extradata_size = i_size + 12;
+                p = id->ff_dec_c->extradata  = malloc( i_size + 12 );
+
+                memcpy( &p[0],  "SVQ3", 4 );
+                memset( &p[4], 0, 8 );
+                memcpy( &p[12], id->f_src.p_extra, i_size );
+
+                /* Now remove all atoms before the SMI one */
+                if( id->ff_dec_c->extradata_size > 0x5a && strncmp( &p[0x56], "SMI ", 4 ) )
+                {
+                    uint8_t *psz = &p[0x52];
+
+                    while( psz < &p[id->ff_dec_c->extradata_size - 8] )
+                    {
+                        int i_size = GetDWBE( psz );
+                        if( i_size <= 1 )
+                        {
+                            /* FIXME handle 1 as long size */
+                            break;
+                        }
+                        if( !strncmp( &psz[4], "SMI ", 4 ) )
+                        {
+                            memmove( &p[0x52], psz, &p[id->ff_dec_c->extradata_size] - psz );
+                            break;
+                        }
+                        psz += i_size;
+                    }
+                }
+            }
+            else
+            {
+                id->ff_dec_c->extradata_size= id->f_src.i_extra;
+                id->ff_dec_c->extradata = malloc( id->f_src.i_extra + FF_INPUT_BUFFER_PADDING_SIZE );
+
+                memcpy( id->ff_dec_c->extradata, id->f_src.p_extra, id->f_src.i_extra );
+                memset( (uint8_t*)id->ff_dec_c->extradata + id->f_src.i_extra, 0, FF_INPUT_BUFFER_PADDING_SIZE );
+            }
+        }
         id->ff_dec_c->workaround_bugs = FF_BUG_AUTODETECT;
         id->ff_dec_c->error_resilience= -1;
         id->ff_dec_c->get_buffer    = transcode_video_ffmpeg_getframebuf;
@@ -1085,7 +1134,7 @@ static int transcode_video_ffmpeg_new( sout_stream_t *p_stream,
             msg_Err( p_stream, "cannot open decoder" );
             return VLC_EGENERIC;
         }
-
+#if 0
         if( i_ff_codec == CODEC_ID_MPEG4 && id->ff_dec_c->extradata_size > 0 )
         {
             int b_gotpicture;
@@ -1103,6 +1152,7 @@ static int transcode_video_ffmpeg_new( sout_stream_t *p_stream,
                                   id->ff_dec_c->extradata_size );
             free( p_vol );
         }
+#endif
     }
 
     /* Open encoder */
@@ -1174,7 +1224,7 @@ static int transcode_video_ffmpeg_new( sout_stream_t *p_stream,
     id->p_vresample      = NULL;
 
     id->p_encoder->p_module =
-        module_Need( id->p_encoder, "encoder", NULL );
+        module_Need( id->p_encoder, "encoder", NULL, 0 );
 
     if( !id->p_encoder->p_module )
     {
@@ -1306,7 +1356,8 @@ static int transcode_video_ffmpeg_process( sout_stream_t *p_stream,
             b_gotpicture = 1;
 
             /* Set PTS */
-            frame->pts = p_sys->i_input_pts;
+            frame->pts = p_sys->i_input_pts ? p_sys->i_input_pts :
+                         AV_NOPTS_VALUE;
         }
 
         if( i_used < 0 )
@@ -1324,7 +1375,7 @@ static int transcode_video_ffmpeg_process( sout_stream_t *p_stream,
 
         /* Get the pts of the decoded frame if any, otherwise keep the
          * interpolated one */
-        if( frame->pts > 0 )
+        if( frame->pts != AV_NOPTS_VALUE )
         {
             p_sys->i_output_pts = frame->pts;
         }
@@ -1370,7 +1421,7 @@ static int transcode_video_ffmpeg_process( sout_stream_t *p_stream,
             id->p_encoder->fmt_out.p_extra = NULL;
 
             id->p_encoder->p_module =
-                module_Need( id->p_encoder, "encoder", NULL );
+                module_Need( id->p_encoder, "encoder", NULL, 0 );
             if( !id->p_encoder->p_module )
             {
                 vlc_object_destroy( id->p_encoder );
@@ -1594,6 +1645,9 @@ static int transcode_video_ffmpeg_process( sout_stream_t *p_stream,
                 p_out->i_dts = p_block->i_dts;
                 p_out->i_pts = p_block->i_pts;
                 p_out->i_length = p_block->i_length;
+                p_out->i_flags =
+                        (p_block->i_flags << SOUT_BUFFER_FLAGS_BLOCK_SHIFT)
+                          & SOUT_BUFFER_FLAGS_BLOCK_MASK;
                 sout_BufferChain( out, p_out );
 
                 p_block = p_block->p_next;
@@ -1652,6 +1706,9 @@ static int EncoderThread( sout_stream_sys_t * p_sys )
             p_out->i_dts = p_block->i_dts;
             p_out->i_pts = p_block->i_pts;
             p_out->i_length = p_block->i_length;
+            p_out->i_flags =
+                (p_block->i_flags << SOUT_BUFFER_FLAGS_BLOCK_SHIFT)
+                  & SOUT_BUFFER_FLAGS_BLOCK_MASK;
             sout_BufferChain( &p_sys->p_buffers, p_out );
 
             p_block = p_block->p_next;
@@ -1701,7 +1758,7 @@ static int transcode_video_ffmpeg_getframebuf(struct AVCodecContext *p_context,
     sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_context->opaque;
 
     /* Set PTS */
-    p_frame->pts = p_sys->i_input_pts;
+    p_frame->pts = p_sys->i_input_pts ? p_sys->i_input_pts : AV_NOPTS_VALUE;
 
     return avcodec_default_get_buffer( p_context, p_frame );
 }