Bug 1368490 - Make sure number of channels is correctly set for opus encoder. r=jesup
authorBryce Van Dyk <bvandyk@mozilla.com>
Tue, 30 May 2017 21:01:02 +1200
changeset 361902 542348829591bffff44980cb5689c8a0a4bf80bb
parent 361901 11c66c13481d028d5a3ab76c4568316b643195c3
child 361903 3005c1464a2c90a7a2f711caf6466d1ab15cc628
push id31948
push userkwierso@gmail.com
push dateFri, 02 Jun 2017 00:27:01 +0000
treeherdermozilla-central@1e229cf8933b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1368490
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1368490 - Make sure number of channels is correctly set for opus encoder. r=jesup MozReview-Commit-ID: 7bOxCvlvTDq
dom/media/encoder/TrackEncoder.cpp
--- a/dom/media/encoder/TrackEncoder.cpp
+++ b/dom/media/encoder/TrackEncoder.cpp
@@ -138,29 +138,31 @@ AudioTrackEncoder::AppendAudioSegment(co
 
 /*static*/
 void
 AudioTrackEncoder::InterleaveTrackData(AudioChunk& aChunk,
                                        int32_t aDuration,
                                        uint32_t aOutputChannels,
                                        AudioDataValue* aOutput)
 {
+  uint32_t numChannelsToCopy = std::min(aOutputChannels,
+                                        static_cast<uint32_t>(aChunk.mChannelData.Length()));
   switch(aChunk.mBufferFormat) {
     case AUDIO_FORMAT_S16: {
       AutoTArray<const int16_t*, 2> array;
-      array.SetLength(aOutputChannels);
+      array.SetLength(numChannelsToCopy);
       for (uint32_t i = 0; i < array.Length(); i++) {
         array[i] = static_cast<const int16_t*>(aChunk.mChannelData[i]);
       }
       InterleaveTrackData(array, aDuration, aOutputChannels, aOutput, aChunk.mVolume);
       break;
     }
     case AUDIO_FORMAT_FLOAT32: {
       AutoTArray<const float*, 2> array;
-      array.SetLength(aOutputChannels);
+      array.SetLength(numChannelsToCopy);
       for (uint32_t i = 0; i < array.Length(); i++) {
         array[i] = static_cast<const float*>(aChunk.mChannelData[i]);
       }
       InterleaveTrackData(array, aDuration, aOutputChannels, aOutput, aChunk.mVolume);
       break;
    }
    case AUDIO_FORMAT_SILENCE: {
       MOZ_ASSERT(false, "To implement.");