]> git.sesse.net Git - vlc/blobdiff - modules/codec/avcodec/avcodec.c
avcodec: adjust MT contention scope
[vlc] / modules / codec / avcodec / avcodec.c
index bae7902a1b2814ac7952024e698494cff3ef982f..04ade540e98b99b708bdd180c17cecabe0acc8cf 100644 (file)
@@ -44,6 +44,8 @@
 
 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
 #   error You must update libavcodec to a version >= 53.34.0
+#elif LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 54, 25, 0 )
+#   warning You should update libavcodec to a version >= 54.25.0
 #endif
 
 /*****************************************************************************
@@ -142,6 +144,7 @@ vlc_module_begin ()
     add_obsolete_integer( "ffmpeg-threads" ) /* removed since 2.1.0 */
     add_integer( "avcodec-threads", 0, THREADS_TEXT, THREADS_LONGTEXT, true );
 #endif
+    add_string( "avcodec-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
 
 
 #ifdef ENABLE_SOUT
@@ -183,7 +186,7 @@ vlc_module_begin ()
 
 
     add_string( ENC_CFG_PREFIX "codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true )
-    add_string( ENC_CFG_PREFIX "hq", "simple", ENC_HQ_TEXT,
+    add_string( ENC_CFG_PREFIX "hq", "rd", ENC_HQ_TEXT,
                 ENC_HQ_LONGTEXT, false )
         change_string_list( enc_hq_list, enc_hq_list_text )
     add_integer( ENC_CFG_PREFIX "keyint", 0, ENC_KEYINT_TEXT,
@@ -237,14 +240,9 @@ vlc_module_begin ()
     /* Audio AAC encoder profile */
     add_string( ENC_CFG_PREFIX "aac-profile", "low",
                 ENC_PROFILE_TEXT, ENC_PROFILE_LONGTEXT, true )
-#endif /* ENABLE_SOUT */
 
-    /* video filter submodule */
-    add_submodule ()
-    set_capability( "video filter2", 0 )
-    set_callbacks( OpenDeinterlace, CloseDeinterlace )
-    set_description( N_("FFmpeg deinterlace video filter") )
-    add_shortcut( "ffmpeg-deinterlace" )
+    add_string( ENC_CFG_PREFIX "options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
+#endif /* ENABLE_SOUT */
 
 #ifdef MERGE_FFMPEG
     add_submodule ()
@@ -300,11 +298,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     }
 
     /* *** get a p_context *** */
-#if LIBAVCODEC_VERSION_MAJOR >= 54
     p_context = avcodec_alloc_context3(p_codec);
-#else
-    p_context = avcodec_alloc_context();
-#endif
     if( !p_context )
         return VLC_ENOMEM;
     p_context->debug = var_InheritInteger( p_dec, "avcodec-debug" );
@@ -361,15 +355,9 @@ static void CloseDecoder( vlc_object_t *p_this )
 
     switch( p_sys->i_cat )
     {
-    case AUDIO_ES:
-         EndAudioDec ( p_dec );
-        break;
     case VIDEO_ES:
          EndVideoDec ( p_dec );
         break;
-    case SPU_ES:
-         EndSubtitleDec( p_dec );
-        break;
     }
 
     if( p_sys->p_context )
@@ -399,10 +387,10 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
 
     if( p_sys->p_context->extradata_size <= 0 )
     {
-        if( p_sys->i_codec_id == CODEC_ID_VC1 ||
-            p_sys->i_codec_id == CODEC_ID_VORBIS ||
-            p_sys->i_codec_id == CODEC_ID_THEORA ||
-            ( p_sys->i_codec_id == CODEC_ID_AAC &&
+        if( p_sys->i_codec_id == AV_CODEC_ID_VC1 ||
+            p_sys->i_codec_id == AV_CODEC_ID_VORBIS ||
+            p_sys->i_codec_id == AV_CODEC_ID_THEORA ||
+            ( p_sys->i_codec_id == AV_CODEC_ID_AAC &&
               !p_dec->fmt_in.b_packetized ) )
         {
             msg_Warn( p_dec, "waiting for extra data for codec %s",
@@ -424,20 +412,29 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
         p_sys->p_context->block_align = p_dec->fmt_in.audio.i_blockalign;
         p_sys->p_context->bit_rate = p_dec->fmt_in.i_bitrate;
         p_sys->p_context->bits_per_coded_sample = p_dec->fmt_in.audio.i_bitspersample;
-        if( p_sys->i_codec_id == CODEC_ID_ADPCM_G726 &&
+        if( p_sys->i_codec_id == AV_CODEC_ID_ADPCM_G726 &&
             p_sys->p_context->bit_rate > 0 &&
             p_sys->p_context->sample_rate >  0)
             p_sys->p_context->bits_per_coded_sample = p_sys->p_context->bit_rate /
                                                       p_sys->p_context->sample_rate;
     }
     int ret;
+    char *psz_opts = var_InheritString( p_dec, "avcodec-options" );
+    AVDictionary *options = NULL;
+    if (psz_opts && *psz_opts)
+        options = vlc_av_get_options(psz_opts);
+    free(psz_opts);
+
     vlc_avcodec_lock();
-#if LIBAVCODEC_VERSION_MAJOR >= 54
-    ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, NULL /* options */ );
-#else
-    ret = avcodec_open( p_sys->p_context, p_sys->p_codec );
-#endif
+    ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, options ? &options : NULL );
     vlc_avcodec_unlock();
+
+    AVDictionaryEntry *t = NULL;
+    while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+        msg_Err( p_dec, "Unknown option \"%s\"", t->key );
+    }
+    av_dict_free(&options);
+
     if( ret < 0 )
         return VLC_EGENERIC;
     msg_Dbg( p_dec, "avcodec codec (%s) started", p_sys->psz_namecodec );