Bug 901633 - Part 11 - Add an API in webrtc.org's output mixer to get the output channel count. r=jesup
authorPaul Adenot <paul@paul.cx>
Tue, 01 Sep 2015 14:25:48 +0200
changeset 294637 54499fc0c9c64a4934779e4edc3ee07d1a6d3cb8
parent 294636 f7cbf699f687563b56f18eb0ee94901c3039ca2e
child 294638 ac76eb834c135bbb14a6d53c159b4847c4f96877
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs901633
milestone43.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 901633 - Part 11 - Add an API in webrtc.org's output mixer to get the output channel count. r=jesup
media/webrtc/trunk/webrtc/voice_engine/output_mixer.cc
media/webrtc/trunk/webrtc/voice_engine/output_mixer.h
media/webrtc/trunk/webrtc/voice_engine/voe_external_media_impl.cc
--- a/media/webrtc/trunk/webrtc/voice_engine/output_mixer.cc
+++ b/media/webrtc/trunk/webrtc/voice_engine/output_mixer.cc
@@ -292,16 +292,21 @@ OutputMixer::GetOutputVolumePan(float& l
     left = _panLeft;
     right = _panRight;
     WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1),
                  "GetOutputVolumePan() => left=%2.1f, right=%2.1f",
                  left, right);
     return 0;
 }
 
+int OutputMixer::GetOutputChannelCount()
+{
+  return _audioFrame.num_channels_;
+}
+
 int OutputMixer::StartRecordingPlayout(const char* fileName,
                                        const CodecInst* codecInst)
 {
     WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1),
                  "OutputMixer::StartRecordingPlayout(fileName=%s)", fileName);
 
     if (_outputFileRecording)
     {
--- a/media/webrtc/trunk/webrtc/voice_engine/output_mixer.h
+++ b/media/webrtc/trunk/webrtc/voice_engine/output_mixer.h
@@ -112,16 +112,18 @@ public:
     void RecordNotification(int32_t id, uint32_t durationMs);
 
     void PlayFileEnded(int32_t id);
     void RecordFileEnded(int32_t id);
 
     // so ExternalPlayoutData() can insert far-end audio from the audio drivers
     void APMAnalyzeReverseStream(AudioFrame &audioFrame);
 
+    int GetOutputChannelCount();
+
 private:
     OutputMixer(uint32_t instanceId);
     int InsertInbandDtmfTone();
 
     // uses
     Statistics* _engineStatisticsPtr;
     AudioProcessing* _audioProcessingModulePtr;
 
--- a/media/webrtc/trunk/webrtc/voice_engine/voe_external_media_impl.cc
+++ b/media/webrtc/trunk/webrtc/voice_engine/voe_external_media_impl.cc
@@ -378,26 +378,33 @@ int VoEExternalMediaImpl::ExternalPlayou
     {
         shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
             "ExternalPlayoutGetData() invalid delay)");
         return -1;
     }
 
     AudioFrame audioFrame;
 
+    uint32_t channels = shared_->output_mixer()->GetOutputChannelCount();
+    // If we have not received any data yet, consider it's mono since it's the
+    // most common case.
+    if (channels == 0) {
+      channels = 1;
+    }
+
     // Retrieve mixed output at the specified rate
     shared_->output_mixer()->MixActiveChannels();
     shared_->output_mixer()->DoOperationsOnCombinedSignal(true);
-    shared_->output_mixer()->GetMixedAudio(samplingFreqHz, 1, &audioFrame);
+    shared_->output_mixer()->GetMixedAudio(samplingFreqHz, channels, &audioFrame);
 
     // Deliver audio (PCM) samples to the external sink
     memcpy(speechData10ms,
            audioFrame.data_,
-           sizeof(int16_t)*(audioFrame.samples_per_channel_));
-    lengthSamples = audioFrame.samples_per_channel_;
+           sizeof(int16_t)*audioFrame.samples_per_channel_*channels);
+    lengthSamples = audioFrame.samples_per_channel_ * channels;
 
     // Store current playout delay (to be used by ExternalRecordingInsertData).
     playout_delay_ms_ = current_delay_ms;
 
     return 0;
 #else
     shared_->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
        "ExternalPlayoutGetData() external playout is not supported");