]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/transcode/video.c
Fixed video AR given to the encoder when transcoding.
[vlc] / modules / stream_out / transcode / video.c
index fcbde831264e3546b1d4e54e9663d5b3305a8db0..130f64b90c26295d6e30d2f31afd4d65fced2acc 100644 (file)
@@ -42,23 +42,6 @@ struct decoder_owner_sys_t
     sout_stream_sys_t *p_sys;
 };
 
-static inline void video_timer_start( encoder_t * p_encoder )
-{
-    stats_TimerStart( p_encoder, "encoding video frame",
-                      STATS_TIMER_VIDEO_FRAME_ENCODING );
-}
-
-static inline void video_timer_stop( encoder_t * p_encoder )
-{
-    stats_TimerStop( p_encoder, STATS_TIMER_VIDEO_FRAME_ENCODING );
-}
-
-static inline void video_timer_close( encoder_t * p_encoder )
-{
-    stats_TimerDump(  p_encoder, STATS_TIMER_VIDEO_FRAME_ENCODING );
-    stats_TimerClean( p_encoder, STATS_TIMER_VIDEO_FRAME_ENCODING );
-}
-
 static void video_del_buffer_decoder( decoder_t *p_decoder, picture_t *p_pic )
 {
     VLC_UNUSED(p_decoder);
@@ -125,24 +108,22 @@ static void transcode_video_filter_allocation_clear( filter_t *p_filter )
     VLC_UNUSED(p_filter);
 }
 
-static void* EncoderThread( vlc_object_t* p_this )
+static void* EncoderThread( void *obj )
 {
-    sout_stream_sys_t *p_sys = (sout_stream_sys_t*)p_this;
+    sout_stream_sys_t *p_sys = (sout_stream_sys_t*)obj;
     sout_stream_id_t *id = p_sys->id_video;
     picture_t *p_pic;
     int canc = vlc_savecancel ();
 
-    while( vlc_object_alive (p_sys) && !p_sys->b_error )
+    for( ;; )
     {
         block_t *p_block;
 
         vlc_mutex_lock( &p_sys->lock_out );
-        while( p_sys->i_last_pic == p_sys->i_first_pic )
-        {
+        while( !p_sys->b_abort && p_sys->i_last_pic == p_sys->i_first_pic )
             vlc_cond_wait( &p_sys->cond, &p_sys->lock_out );
-            if( !vlc_object_alive (p_sys) || p_sys->b_error ) break;
-        }
-        if( !vlc_object_alive (p_sys) || p_sys->b_error )
+
+        if( p_sys->b_abort )
         {
             vlc_mutex_unlock( &p_sys->lock_out );
             break;
@@ -152,9 +133,7 @@ static void* EncoderThread( vlc_object_t* p_this )
         p_sys->i_first_pic %= PICTURE_RING_SIZE;
         vlc_mutex_unlock( &p_sys->lock_out );
 
-        video_timer_start( id->p_encoder );
         p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic );
-        video_timer_stop( id->p_encoder );
 
         vlc_mutex_lock( &p_sys->lock_out );
         block_ChainAppend( &p_sys->p_buffers, p_block );
@@ -274,8 +253,8 @@ int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_t *id )
         p_sys->i_first_pic = 0;
         p_sys->i_last_pic = 0;
         p_sys->p_buffers = NULL;
-        p_sys->b_die = p_sys->b_error = 0;
-        if( vlc_thread_create( p_sys, "encoder", EncoderThread, i_priority ) )
+        p_sys->b_abort = 0;
+        if( vlc_clone( &p_sys->thread, EncoderThread, p_sys, i_priority ) )
         {
             msg_Err( p_stream, "cannot spawn encoder thread" );
             module_unneed( id->p_decoder, id->p_decoder->p_module );
@@ -495,8 +474,14 @@ static void transcode_video_encoder_init( sout_stream_t *p_stream,
     if( id->p_encoder->fmt_out.video.i_sar_num <= 0 ||
         id->p_encoder->fmt_out.video.i_sar_den <= 0 )
     {
-        id->p_encoder->fmt_out.video.i_sar_num = id->p_decoder->fmt_out.video.i_sar_num * i_src_width / i_dst_width;
-        id->p_encoder->fmt_out.video.i_sar_den = id->p_decoder->fmt_out.video.i_sar_den * i_src_height / i_dst_height;
+        vlc_ureduce( &id->p_decoder->fmt_out.video.i_sar_num,
+                     &id->p_decoder->fmt_out.video.i_sar_den,
+                     id->p_decoder->fmt_out.video.i_sar_num,
+                     id->p_decoder->fmt_out.video.i_sar_den,
+                     0 );
+
+        id->p_encoder->fmt_out.video.i_sar_num = id->p_decoder->fmt_out.video.i_sar_num * i_src_width  * i_dst_height;
+        id->p_encoder->fmt_out.video.i_sar_den = id->p_decoder->fmt_out.video.i_sar_den * i_src_height * i_dst_width;
     }
     vlc_ureduce( &id->p_encoder->fmt_out.video.i_sar_num,
                  &id->p_encoder->fmt_out.video.i_sar_den,
@@ -558,16 +543,15 @@ void transcode_video_close( sout_stream_t *p_stream,
     if( p_stream->p_sys->i_threads >= 1 )
     {
         vlc_mutex_lock( &p_stream->p_sys->lock_out );
-        vlc_object_kill( p_stream->p_sys );
+        p_stream->p_sys->b_abort = true;
         vlc_cond_signal( &p_stream->p_sys->cond );
         vlc_mutex_unlock( &p_stream->p_sys->lock_out );
-        vlc_thread_join( p_stream->p_sys );
+
+        vlc_join( p_stream->p_sys->thread, NULL );
         vlc_mutex_destroy( &p_stream->p_sys->lock_out );
         vlc_cond_destroy( &p_stream->p_sys->cond );
     }
 
-    video_timer_close( id->p_encoder );
-
     /* Close decoder */
     if( id->p_decoder->p_module )
         module_unneed( id->p_decoder, id->p_decoder->p_module );
@@ -601,9 +585,7 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
         {
             block_t *p_block;
             do {
-                video_timer_start( id->p_encoder );
                 p_block = id->p_encoder->pf_encode_video(id->p_encoder, NULL );
-                video_timer_stop( id->p_encoder );
                 block_ChainAppend( out, p_block );
             } while( p_block );
         }
@@ -620,9 +602,6 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
 
     while( (p_pic = id->p_decoder->pf_decode_video( id->p_decoder, &in )) )
     {
-        subpicture_t *p_subpic = NULL;
-
-        sout_UpdateStatistic( p_stream->p_sout, SOUT_STATISTIC_DECODED_VIDEO, 1 );
 
         if( p_stream->p_sout->i_out_pace_nocontrol && p_sys->b_hurry_up )
         {
@@ -700,35 +679,36 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
 
         /* Check if we have a subpicture to overlay */
         if( p_sys->p_spu )
-        {
-            p_subpic = spu_SortSubpictures( p_sys->p_spu, p_pic->date, false );
-            /* TODO: get another pic */
-        }
-
-        /* Overlay subpicture */
-        if( p_subpic )
         {
             video_format_t fmt;
-
-            if( picture_IsReferenced( p_pic ) && !filter_chain_GetLength( id->p_f_chain ) )
-            {
-                /* We can't modify the picture, we need to duplicate it */
-                picture_t *p_tmp = video_new_buffer_decoder( id->p_decoder );
-                if( p_tmp )
-                {
-                    picture_Copy( p_tmp, p_pic );
-                    picture_Release( p_pic );
-                    p_pic = p_tmp;
-                }
-            }
-
             if( filter_chain_GetLength( id->p_f_chain ) > 0 )
                 fmt = filter_chain_GetFmtOut( id->p_f_chain )->video;
             else
                 fmt = id->p_decoder->fmt_out.video;
 
-            spu_RenderSubpictures( p_sys->p_spu, p_pic, &fmt,
-                                   p_subpic, &id->p_decoder->fmt_out.video, p_pic->date );
+            subpicture_t *p_subpic = spu_Render( p_sys->p_spu, NULL, &fmt, &fmt,
+                                                 p_pic->date, p_pic->date, false );
+
+            /* Overlay subpicture */
+            if( p_subpic )
+            {
+                if( picture_IsReferenced( p_pic ) && !filter_chain_GetLength( id->p_f_chain ) )
+                {
+                    /* We can't modify the picture, we need to duplicate it */
+                    picture_t *p_tmp = video_new_buffer_decoder( id->p_decoder );
+                    if( p_tmp )
+                    {
+                        picture_Copy( p_tmp, p_pic );
+                        picture_Release( p_pic );
+                        p_pic = p_tmp;
+                    }
+                }
+                if( !p_sys->p_spu_blend )
+                    p_sys->p_spu_blend = filter_NewBlend( VLC_OBJECT( p_sys->p_spu ), &fmt );
+                if( p_sys->p_spu_blend )
+                    picture_BlendSubpicture( p_pic, p_sys->p_spu_blend, p_subpic );
+                subpicture_Delete( p_subpic );
+            }
         }
 
         /* Run user specified filter chain */
@@ -739,10 +719,7 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
         {
             block_t *p_block;
 
-            video_timer_start( id->p_encoder );
             p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic );
-            video_timer_stop( id->p_encoder );
-
             block_ChainAppend( out, p_block );
         }
 
@@ -775,9 +752,7 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
                {
                    block_t *p_block;
                    p_pic->date = i_pts;
-                   video_timer_start( id->p_encoder );
                    p_block = id->p_encoder->pf_encode_video(id->p_encoder, p_pic);
-                   video_timer_stop( id->p_encoder );
                    block_ChainAppend( out, p_block );
                }
            }