]> git.sesse.net Git - vlc/commitdiff
AVCodec : Set audio related parameters in ffmpeg_OpenCodec and use it for audio decod...
authorJai Menon <jmenon86@gmail.com>
Thu, 5 Aug 2010 10:48:17 +0000 (16:18 +0530)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 9 Aug 2010 20:21:43 +0000 (22:21 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/avcodec/audio.c
modules/codec/avcodec/avcodec.c

index 4031c7c71e2c767dd2eea92d9c2016363276ad1b..483c3067c84515774f7747c3b45705de54cfad2c 100644 (file)
@@ -164,20 +164,8 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
     // Initialize decoder extradata
     InitDecoderConfig( p_dec, p_context);
 
-    /* ***** Fill p_context with init values ***** */
-    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;
-
     /* ***** Open the codec ***** */
-    int ret;
-    vlc_avcodec_lock();
-    ret = avcodec_open( p_sys->p_context, p_sys->p_codec );
-    vlc_avcodec_unlock();
-    if( ret < 0 )
+    if( ffmpeg_OpenCodec( p_dec ) < 0 )
     {
         msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
         free( p_sys->p_context->extradata );
@@ -185,8 +173,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
         return VLC_EGENERIC;
     }
 
-    msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
-
     switch( i_codec_id )
     {
     case CODEC_ID_WAVPACK:
index bbff589b86d98609df82095a583f73766c9f8700..9b54976087d0bdd66fab064d237844013427486a 100644 (file)
@@ -416,10 +416,21 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
             return 1;
         }
     }
-    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;
+    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 );
@@ -429,24 +440,27 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
     msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
 
 #ifdef HAVE_AVCODEC_MT
-    switch( p_sys->p_context->active_thread_type )
+    if( p_dec->fmt_in.i_cat == VIDEO_ES )
     {
-    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;
+        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