]> git.sesse.net Git - vlc/blobdiff - modules/codec/ffmpeg/video.c
* include/video_output.h, ALL: changed api for vout_Request()/vout_Create() to be...
[vlc] / modules / codec / ffmpeg / video.c
index 623135e50fd714b201af8b95f34e56e72dc903b2..7813b7ad42d5b8af2c5ca3be8ab4049378a7bcad 100644 (file)
@@ -169,6 +169,8 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
         p_dec->fmt_out.video.i_aspect =
             VOUT_ASPECT_FACTOR * ( av_q2d(p_context->sample_aspect_ratio) *
                 p_context->width / p_context->height );
+       p_dec->fmt_out.video.i_sar_num = p_context->sample_aspect_ratio.num;
+       p_dec->fmt_out.video.i_sar_den = p_context->sample_aspect_ratio.den;
 #else
         p_dec->fmt_out.video.i_aspect =
             VOUT_ASPECT_FACTOR * p_context->aspect_ratio;
@@ -180,6 +182,12 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
         }
     }
 
+    if( p_context->frame_rate > 0 && p_context->frame_rate_base > 0 )
+    {
+        p_dec->fmt_out.video.i_frame_rate = p_context->frame_rate;
+        p_dec->fmt_out.video.i_frame_rate_base = p_context->frame_rate_base;
+    }
+
     p_pic = p_dec->pf_vout_buffer_new( p_dec );
 
 #ifdef LIBAVCODEC_PP
@@ -224,6 +232,9 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
     p_sys->p_ff_pic = avcodec_alloc_frame();
 
     /* ***** Fill p_context with init values ***** */
+    /* FIXME: remove when ffmpeg deals properly with avc1 */
+    if( p_dec->fmt_in.i_codec != VLC_FOURCC('a','v','c','1') )
+    /* End FIXME */
     p_sys->p_context->codec_tag = ffmpeg_CodecTag( p_dec->fmt_in.i_codec );
     p_sys->p_context->width  = p_dec->fmt_in.video.i_width;
     p_sys->p_context->height = p_dec->fmt_in.video.i_height;
@@ -245,6 +256,12 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
     if( val.i_int ) p_sys->p_context->debug_mv = val.i_int;
 #endif
 
+    var_Create( p_dec, "ffmpeg-lowres", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_dec, "ffmpeg-lowres", &val );
+#if LIBAVCODEC_BUILD >= 4723
+    if( val.i_int > 0 && val.i_int <= 2 ) p_sys->p_context->lowres = val.i_int;
+#endif
+
     /* ***** ffmpeg frame skipping ***** */
     var_Create( p_dec, "ffmpeg-hurry-up", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Get( p_dec, "ffmpeg-hurry-up", &val );
@@ -352,7 +369,13 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
                           p_sys->p_context->sub_id );
             }
         }
-        else if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'a', 'v', 'c', '1' ) )
+        /* FIXME: remove when ffmpeg deals properly with avc1 */
+        else if( p_dec->fmt_in.i_codec == VLC_FOURCC('a','v','c','1') )
+        {
+            ;
+        }
+        /* End FIXME */
+        else
         {
             p_sys->p_context->extradata_size = i_size;
             p_sys->p_context->extradata =
@@ -372,7 +395,7 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
     p_sys->i_late_frames = 0;
     p_sys->i_buffer = 0;
     p_sys->i_buffer_orig = 1;
-    p_sys->p_buffer_orig = p_sys->p_buffer = malloc( p_sys->i_buffer );
+    p_sys->p_buffer_orig = p_sys->p_buffer = malloc( p_sys->i_buffer_orig );
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = VIDEO_ES;
@@ -393,6 +416,7 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
     {
         vlc_mutex_unlock( lockval.p_address );
         msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
+        free( p_sys );
         return VLC_EGENERIC;
     }
     vlc_mutex_unlock( lockval.p_address );
@@ -416,7 +440,7 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
 
     p_block = *pp_block;
 
-    if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
+    if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
         p_sys->i_buffer = 0;
         p_sys->i_pts = 0; /* To make sure we recover properly */
@@ -428,7 +452,15 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    if( p_sys->i_late_frames > 0 &&
+    if( p_block->i_flags & BLOCK_FLAG_PREROLL )
+    {
+        /* Do not care about late frames when prerolling
+         * TODO avoid decoding of non reference frame
+         * (ie all B except for H264 where it depends only on nal_ref_idc) */
+        p_sys->i_late_frames = 0;
+    }
+
+    if( !p_dec->b_pace_control && p_sys->i_late_frames > 0 &&
         mdate() - p_sys->i_late_frames_start > I64C(5000000) )
     {
         if( p_sys->i_pts )
@@ -453,7 +485,8 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
 
     /* TODO implement it in a better way */
     /* A good idea could be to decode all I pictures and see for the other */
-    if( p_sys->b_hurry_up && p_sys->i_late_frames > 4 )
+    if( !p_dec->b_pace_control &&
+        p_sys->b_hurry_up && p_sys->i_late_frames > 4 )
     {
         b_drawpicture = 0;
         if( p_sys->i_late_frames < 8 )
@@ -473,8 +506,16 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
     }
     else
     {
-        b_drawpicture = 1;
-        p_sys->p_context->hurry_up = 0;
+        if (!(p_block->i_flags & BLOCK_FLAG_PREROLL))
+        {
+            b_drawpicture = 1;
+            p_sys->p_context->hurry_up = 0;
+        }
+        else
+        {
+            b_drawpicture = 0;
+            p_sys->p_context->hurry_up = 1;
+        }
     }
 
 
@@ -556,8 +597,9 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
             continue;
         }
 
-        /* Update frame late count*/
-        if( p_sys->i_pts && p_sys->i_pts <= mdate() )
+        /* Update frame late count (except when doing preroll) */
+        if( p_sys->i_pts && p_sys->i_pts <= mdate() &&
+            !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
         {
             p_sys->i_late_frames++;
             if( p_sys->i_late_frames == 1 )
@@ -622,6 +664,13 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
                 p_sys->b_first_frame = VLC_FALSE;
                 p_pic->b_force = VLC_TRUE;
             }
+
+            p_pic->i_nb_fields = 2 + p_sys->p_ff_pic->repeat_pict;
+#if LIBAVCODEC_BUILD >= 4685
+            p_pic->b_progressive = !p_sys->p_ff_pic->interlaced_frame;
+            p_pic->b_top_field_first = p_sys->p_ff_pic->top_field_first;
+#endif
+
             return p_pic;
         }
         else
@@ -644,7 +693,7 @@ void E_(EndVideoDec)( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    if( p_sys->p_ff_pic ) free( p_sys->p_ff_pic );
+    if( p_sys->p_ff_pic ) av_free( p_sys->p_ff_pic );
 
 #ifdef LIBAVCODEC_PP
     E_(ClosePostproc)( p_dec, p_sys->p_pp );
@@ -681,7 +730,8 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec,
             i_dst_stride = p_pic->p[i_plane].i_pitch;
 
             i_size = __MIN( i_src_stride, i_dst_stride );
-            for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
+            for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines;
+                 i_line++ )
             {
                 p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_size );
                 p_src += i_src_stride;