]> git.sesse.net Git - vlc/blobdiff - modules/codec/avcodec/avcodec.c
Fix file rights.
[vlc] / modules / codec / avcodec / avcodec.c
index afd173e1df625a4b1e736a47bed69a1c17c04caf..a09be391a8bd50cd62c5ad710867fb965658002b 100644 (file)
 
 #include "avcodec.h"
 #include "avutil.h"
+#include "chroma.h"
 
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 51, 48, 0 )
-#   error You must update libavcodec to a version >= 51.48.0
-#elif LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 25, 0 )
-#   warning You should update libavcodec to get subtitle support
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 25, 0 )
+#   error You must update libavcodec to a version >= 52.25.0
 #endif
 
 /*****************************************************************************
@@ -87,7 +86,7 @@ static const char *const enc_hq_list_text[] = {
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define MODULE_DESCRIPTION N_( "Various audio and video decoders/encoders" \
+#define MODULE_DESCRIPTION N_( "Various audio and video decoders/encoders " \
         "delivered by the FFmpeg library. This includes (MS)MPEG4, DivX, SV1,"\
         "H261, H263, H264, WMV, WMA, AAC, AMR, DV, MJPEG and other codecs")
 
@@ -140,6 +139,10 @@ vlc_module_begin ()
 #if defined(HAVE_AVCODEC_VAAPI) || defined(HAVE_AVCODEC_DXVA2)
     add_bool( "ffmpeg-hw", false, NULL, HW_TEXT, HW_LONGTEXT, true )
 #endif
+#if defined(FF_THREAD_FRAME)
+    add_integer( "ffmpeg-threads", 0, NULL, THREADS_TEXT, THREADS_LONGTEXT, true );
+#endif
+
 
 #ifdef ENABLE_SOUT
     /* encoder submodule */
@@ -310,13 +313,11 @@ static int OpenDecoder( vlc_object_t *p_this )
         i_result =  InitAudioDec ( p_dec, p_context, p_codec,
                                        i_codec_id, psz_namecodec );
         break;
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 52, 25, 0 )
     case SPU_ES:
         p_dec->pf_decode_sub = DecodeSubtitle;
         i_result =  InitSubtitleDec( p_dec, p_context, p_codec,
                                      i_codec_id, psz_namecodec );
         break;
-#endif
     default:
         i_result = VLC_EGENERIC;
     }
@@ -349,11 +350,9 @@ static void CloseDecoder( vlc_object_t *p_this )
     case VIDEO_ES:
          EndVideoDec ( p_dec );
         break;
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 52, 25, 0 )
     case SPU_ES:
          EndSubtitleDec( p_dec );
         break;
-#endif
     }
 
     if( p_sys->p_context )
@@ -398,3 +397,75 @@ void InitLibavcodec( vlc_object_t *p_object )
 
     vlc_avcodec_unlock();
 }
+
+/*****************************************************************************
+ * ffmpeg_OpenCodec:
+ *****************************************************************************/
+int ffmpeg_OpenCodec( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    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 )
+        {
+            msg_Warn( p_dec, "waiting for extra data for codec %s",
+                      p_sys->psz_namecodec );
+            return 1;
+        }
+    }
+    if( p_dec->fmt_in.i_cat == VIDEO_ES )
+    {
+        p_sys->p_context->width  = p_dec->fmt_in.video.i_width;
+        p_sys->p_context->height = p_dec->fmt_in.video.i_height;
+        p_sys->p_context->bits_per_coded_sample = p_dec->fmt_in.video.i_bits_per_pixel;
+    }
+    else if( p_dec->fmt_in.i_cat == AUDIO_ES )
+    {
+        p_sys->p_context->sample_rate = p_dec->fmt_in.audio.i_rate;
+        p_sys->p_context->channels = p_dec->fmt_in.audio.i_channels;
+
+        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;
+    }
+    int ret;
+    vlc_avcodec_lock();
+    ret = avcodec_open( p_sys->p_context, p_sys->p_codec );
+    vlc_avcodec_unlock();
+    if( ret < 0 )
+        return VLC_EGENERIC;
+    msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
+
+#ifdef HAVE_AVCODEC_MT
+    if( p_dec->fmt_in.i_cat == VIDEO_ES )
+    {
+        switch( p_sys->p_context->active_thread_type )
+        {
+            case FF_THREAD_FRAME:
+                msg_Dbg( p_dec, "using frame thread mode with %d threads",
+                         p_sys->p_context->thread_count );
+                break;
+            case FF_THREAD_SLICE:
+                msg_Dbg( p_dec, "using slice thread mode with %d threads",
+                         p_sys->p_context->thread_count );
+                break;
+            case 0:
+                if( p_sys->p_context->thread_count > 1 )
+                    msg_Warn( p_dec, "failed to enable threaded decoding" );
+                break;
+            default:
+                msg_Warn( p_dec, "using unknown thread mode with %d threads",
+                          p_sys->p_context->thread_count );
+                break;
+        }
+    }
+#endif
+
+    p_sys->b_delayed_open = false;
+
+    return VLC_SUCCESS;
+}