]> git.sesse.net Git - mlt/commitdiff
Fix sample rate and channel count from avformat producer.
authorDan Dennedy <dan@dennedy.org>
Sun, 1 May 2011 02:03:13 +0000 (19:03 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 1 May 2011 02:03:13 +0000 (19:03 -0700)
If unable to resample or the decoder does not give the requested channel
count, then we should return the actual values so downstream components
can do the correct thing if they can. A good example of this is 6
channel AAC when the consumer requests 2 channels. Unlike the AC-3
decoder, the AAC decoder can not downmix. So, we were returning audio
pcm containing 6 channels but with a channel count of 2.

src/modules/avformat/producer_avformat.c

index 7afd2f1c15d1a0bf1cbd9b3e841fe4b0781b6ba9..d914dab077e965af934baaa7cd7f22d9aad3890c 100644 (file)
@@ -2107,7 +2107,14 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                                }
                        }
                }
-               
+
+               // Set some additional return values
+               if ( self->audio_index != INT_MAX && !self->audio_resample[ self->audio_index ] )
+               {
+                       *channels  = self->audio_codec[ self->audio_index ]->channels;
+                       *frequency = self->audio_codec[ self->audio_index ]->sample_rate;
+               }
+
                // Allocate and set the frame's audio buffer
                int size = *samples * *channels * sizeof(int16_t);
                *buffer = mlt_pool_alloc( size );
@@ -2158,12 +2165,6 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                                // Otherwise fill with silence
                                memset( *buffer, 0, *samples * *channels * sizeof(int16_t) );
                        }
-                       if ( !self->audio_resample[ index ] )
-                       {
-                               // TODO: uncomment and remove following line when full multi-channel support is ready
-                               // *channels = codec_context->channels;
-                               *frequency = self->audio_codec[ index ]->sample_rate;
-                       }
                }
        }
        else