[vlc-commits] avcodec: use context->channels in audio encoding

Ilkka Ollakka git at videolan.org
Sun Sep 22 16:08:55 CEST 2013


vlc/vlc-2.1 | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Sep 22 16:52:19 2013 +0300| [eb8e5c4dc130cc04abc28c7b1c9225fac708950f] | committer: Ilkka Ollakka

avcodec: use context->channels in audio encoding

Input and output channel count should be anyway the same and it's
hopefully littlebit clearer than fmt_in and fmt_out mixups.
(cherry picked from commit 4f11edd7bcacea1fa0b44161b76091e98aeed7a2)

Signed-off-by: Ilkka Ollakka <ileoo at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.1.git/?a=commit;h=eb8e5c4dc130cc04abc28c7b1c9225fac708950f
---

 modules/codec/avcodec/encoder.c |   30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 8193d07..a82d235 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -605,9 +605,8 @@ int OpenEncoder( vlc_object_t *p_this )
     else if( p_enc->fmt_in.i_cat == AUDIO_ES )
     {
         /* work around bug in libmp3lame encoding */
-        if( i_codec_id == AV_CODEC_ID_MP3 && p_enc->fmt_in.audio.i_channels > 2 )
-            p_enc->fmt_in.audio.i_channels = 2;
-
+        if( i_codec_id == AV_CODEC_ID_MP3 && p_enc->fmt_out.audio.i_channels  > 2 )
+            p_enc->fmt_out.audio.i_channels = 2;
         p_context->codec_type  = AVMEDIA_TYPE_AUDIO;
         p_context->sample_fmt  = p_codec->sample_fmts ?
                                     p_codec->sample_fmts[0] :
@@ -653,7 +652,7 @@ int OpenEncoder( vlc_object_t *p_this )
         date_Set( &p_sys->buffer_date, 0 );
         p_context->time_base.num = 1;
         p_context->time_base.den = p_context->sample_rate;
-        p_context->channels    = p_enc->fmt_out.audio.i_channels;
+        p_context->channels      = p_enc->fmt_out.audio.i_channels;
 #if LIBAVUTIL_VERSION_CHECK( 52, 2, 6, 0, 0)
         p_context->channel_layout = av_get_default_channel_layout( p_context->channels );
 #endif
@@ -870,7 +869,8 @@ int OpenEncoder( vlc_object_t *p_this )
         p_sys->i_frame_size = p_context->frame_size > 1 ?
                                     p_context->frame_size :
                                     FF_MIN_BUFFER_SIZE;
-        p_sys->p_buffer = malloc( p_sys->i_frame_size * p_sys->i_sample_bytes * p_enc->fmt_in.audio.i_channels);
+        p_sys->i_buffer_out = p_sys->i_frame_size * p_sys->i_sample_bytes * p_sys->p_context->channels;
+        p_sys->p_buffer = malloc( p_sys->i_buffer_out );
         if ( unlikely( p_sys->p_buffer == NULL ) )
         {
             goto error;
@@ -880,7 +880,6 @@ int OpenEncoder( vlc_object_t *p_this )
         //b_variable tells if we can feed any size frames to encoder
         p_sys->b_variable = p_context->frame_size ? false : true;
 
-        p_sys->i_buffer_out = p_sys->i_frame_size * p_sys->i_sample_bytes * p_enc->fmt_in.audio.i_channels;
 
         if( p_sys->b_planar )
         {
@@ -1119,9 +1118,10 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
     int got_packet,i_out;
     size_t buffer_delay = 0, i_samples_left = 0;
 
+
     //i_bytes_left is amount of bytes we get
     i_samples_left = p_aout_buf ? p_aout_buf->i_nb_samples : 0;
-    buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_enc->fmt_in.audio.i_channels;
+    buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_sys->p_context->channels;
 
     //p_sys->i_buffer_out = p_sys->i_frame_size * chan * p_sys->i_sample_bytes
     //Calculate how many bytes we would need from current buffer to fill frame
@@ -1138,7 +1138,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
          )
     {
         //How much we need to copy from new packet
-        const int leftover = leftover_samples * p_enc->fmt_in.audio.i_channels * p_sys->i_sample_bytes;
+        const int leftover = leftover_samples * p_sys->p_context->channels * p_sys->i_sample_bytes;
 
 #if LIBAVUTIL_VERSION_CHECK( 51,27,2,46,100 )
         const int align = 0;
@@ -1161,7 +1161,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
             // We need to deinterleave from p_aout_buf to p_buffer the leftover bytes
             if( p_sys->b_planar )
                 aout_Deinterleave( p_sys->p_interleave_buf, p_sys->p_buffer,
-                    p_sys->i_frame_size, p_enc->fmt_in.audio.i_channels, p_enc->fmt_in.i_codec );
+                    p_sys->i_frame_size, p_sys->p_context->channels, p_enc->fmt_in.i_codec );
             else
                 memcpy( p_sys->p_buffer + buffer_delay, p_aout_buf->p_buffer, leftover);
 
@@ -1178,7 +1178,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
             memset( p_sys->p_buffer + (leftover+buffer_delay), 0, padding_size );
             buffer_delay += padding_size;
         }
-        if( avcodec_fill_audio_frame( p_sys->frame, p_enc->fmt_in.audio.i_channels,
+        if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->channels,
                 p_sys->p_context->sample_fmt, p_sys->b_planar ? p_sys->p_interleave_buf : p_sys->p_buffer,
                 p_sys->i_buffer_out,
                 align) < 0 )
@@ -1269,11 +1269,11 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
         if( p_sys->b_planar )
         {
             aout_Deinterleave( p_sys->p_buffer, p_aout_buf->p_buffer,
-                               p_sys->frame->nb_samples, p_enc->fmt_in.audio.i_channels, p_enc->fmt_in.i_codec );
+                               p_sys->frame->nb_samples, p_sys->p_context->channels, p_enc->fmt_in.i_codec );
 
         }
 
-        if( avcodec_fill_audio_frame( p_sys->frame, p_enc->fmt_in.audio.i_channels,
+        if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->channels,
                                     p_sys->p_context->sample_fmt,
                                     p_sys->b_planar ? p_sys->p_buffer : p_aout_buf->p_buffer,
                                     __MIN(p_sys->i_buffer_out, p_aout_buf->i_buffer),
@@ -1283,8 +1283,8 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
                  p_sys->frame->nb_samples = 0;
         }
 
-        p_aout_buf->p_buffer     += (p_sys->frame->nb_samples * p_enc->fmt_in.audio.i_channels * p_sys->i_sample_bytes);
-        p_aout_buf->i_buffer     -= (p_sys->frame->nb_samples * p_enc->fmt_in.audio.i_channels * p_sys->i_sample_bytes);
+        p_aout_buf->p_buffer     += (p_sys->frame->nb_samples * p_sys->p_context->channels * p_sys->i_sample_bytes);
+        p_aout_buf->i_buffer     -= (p_sys->frame->nb_samples * p_sys->p_context->channels * p_sys->i_sample_bytes);
         p_aout_buf->i_nb_samples -= p_sys->frame->nb_samples;
         date_Increment( &p_sys->buffer_date, p_sys->frame->nb_samples );
 
@@ -1324,7 +1324,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
     if( p_aout_buf->i_nb_samples > 0 )
     {
        memcpy( p_sys->p_buffer + buffer_delay, p_aout_buf->p_buffer,
-               p_aout_buf->i_nb_samples * p_sys->i_sample_bytes * p_enc->fmt_in.audio.i_channels);
+               p_aout_buf->i_nb_samples * p_sys->i_sample_bytes * p_sys->p_context->channels);
        p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
     }
 



More information about the vlc-commits mailing list