]> git.sesse.net Git - vlc/blobdiff - modules/codec/avcodec/encoder.c
Plugins: push cancellation down
[vlc] / modules / codec / avcodec / encoder.c
index 8bac88b778be27a9b3e0b6c6e1cd1380c9e2a856..98089fbe13f1f1098742930ec3b08b5a35cd0bbc 100644 (file)
@@ -69,7 +69,7 @@ static block_t *EncodeVideo( encoder_t *, picture_t * );
 static block_t *EncodeAudio( encoder_t *, aout_buffer_t * );
 
 struct thread_context_t;
-static int FfmpegThread( struct thread_context_t *p_context );
+static void* FfmpegThread( vlc_object_t *p_this );
 static int FfmpegExecute( AVCodecContext *s,
                           int (*pf_func)(AVCodecContext *c2, void *arg2),
                           void **arg, int *ret, int count );
@@ -212,7 +212,7 @@ int OpenEncoder( vlc_object_t *p_this )
     if( !GetFfmpegCodec( p_enc->fmt_out.i_codec, &i_cat, &i_codec_id,
                              &psz_namecodec ) )
     {
-        if( GetFfmpegChroma( p_enc->fmt_out.i_codec ) < 0 )
+        if( TestFfmpegChroma( -1, p_enc->fmt_out.i_codec ) != VLC_SUCCESS )
         {
             /* handed chroma output */
             return VLC_EGENERIC;
@@ -378,7 +378,7 @@ int OpenEncoder( vlc_object_t *p_this )
 
 #if LIBAVCODEC_VERSION_INT >= ((51<<16)+(40<<8)+4)
     var_Get( p_enc, ENC_CFG_PREFIX "aac-profile", &val );
-    p_sys->i_aac_profile = FF_PROFILE_UNKNOWN;
+    p_sys->i_aac_profile = FF_PROFILE_AAC_LOW;
     if( val.psz_string && *val.psz_string )
     {
         if( !strncmp( val.psz_string, "main", 4 ) )
@@ -393,8 +393,8 @@ int OpenEncoder( vlc_object_t *p_this )
             p_sys->i_aac_profile = FF_PROFILE_AAC_LTP;
         else
         {
-            msg_Warn( p_enc, "unknown AAC profile requested" );
-            p_sys->i_aac_profile = FF_PROFILE_UNKNOWN;
+            msg_Warn( p_enc, "unknown AAC profile requested, setting it to low" );
+            p_sys->i_aac_profile = FF_PROFILE_AAC_LOW;
         }
     }
     free( val.psz_string );
@@ -460,7 +460,9 @@ int OpenEncoder( vlc_object_t *p_this )
         p_sys->p_buffer_out = malloc( p_sys->i_buffer_out );
 
         p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0');
-        p_context->pix_fmt = GetFfmpegChroma( p_enc->fmt_in.i_codec );
+        p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec;
+        GetFfmpegChroma( &p_context->pix_fmt, p_enc->fmt_in.video );
+
         if( p_codec->pix_fmts )
         {
             const enum PixelFormat *p = p_codec->pix_fmts;
@@ -469,7 +471,8 @@ int OpenEncoder( vlc_object_t *p_this )
                 if( *p == p_context->pix_fmt ) break;
             }
             if( *p == -1 ) p_context->pix_fmt = p_codec->pix_fmts[0];
-            p_enc->fmt_in.i_codec = GetVlcChroma( p_context->pix_fmt );
+            GetVlcChroma( &p_enc->fmt_in.video, p_context->pix_fmt );
+            p_enc->fmt_in.i_codec = p_enc->fmt_in.video.i_chroma;
         }
 
 
@@ -588,8 +591,8 @@ int OpenEncoder( vlc_object_t *p_this )
     if( i_codec_id == CODEC_ID_RAWVIDEO )
     {
         /* XXX: hack: Force same codec (will be handled by transcode) */
-        p_enc->fmt_in.i_codec = p_enc->fmt_out.i_codec;
-        p_context->pix_fmt = GetFfmpegChroma( p_enc->fmt_in.i_codec );
+        p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec = p_enc->fmt_out.i_codec;
+        GetFfmpegChroma( &p_context->pix_fmt, p_enc->fmt_in.video );
     }
 
     /* Make sure we get extradata filled by the encoder */
@@ -700,18 +703,20 @@ int OpenEncoder( vlc_object_t *p_this )
 /****************************************************************************
  * Ffmpeg threading system
  ****************************************************************************/
-static int FfmpegThread( struct thread_context_t *p_context )
+static void* FfmpegThread( vlc_object_t *p_this )
 {
-    while ( !p_context->b_die && !p_context->b_error )
+    struct thread_context_t *p_context = (struct thread_context_t *)p_this;
+    int canc = vlc_savecancel ();
+    while ( vlc_object_alive (p_context) && !p_context->b_error )
     {
         vlc_mutex_lock( &p_context->lock );
-        while ( !p_context->b_work && !p_context->b_die && !p_context->b_error )
+        while ( !p_context->b_work && vlc_object_alive (p_context) && !p_context->b_error )
         {
             vlc_cond_wait( &p_context->cond, &p_context->lock );
         }
         p_context->b_work = 0;
         vlc_mutex_unlock( &p_context->lock );
-        if ( p_context->b_die || p_context->b_error )
+        if ( !vlc_object_alive (p_context) || p_context->b_error )
             break;
 
         if ( p_context->pf_func )
@@ -726,7 +731,8 @@ static int FfmpegThread( struct thread_context_t *p_context )
         vlc_mutex_unlock( &p_context->lock );
     }
 
-    return 0;
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 static int FfmpegExecute( AVCodecContext *s,