Bug 1397793 - Move away from VoEExternalMedia "external" API in AudioConduit.cpp. r=dminor
authorPaul Adenot <paul@paul.cx>
Tue, 31 Oct 2017 17:33:42 +0100
changeset 396331 3d315303d3761d6c015b209b53d4435b449cda0c
parent 396330 aa3ff283d9e75de7fa14775568a3fdbf2a81ed52
child 396332 80f8abb62e07c5212409ff2fd9d8c14f7094d65d
push id56975
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:59:07 +0000
treeherderautoland@16bcfaad13e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor
bugs1397793
milestone59.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 1397793 - Move away from VoEExternalMedia "external" API in AudioConduit.cpp. r=dminor This forces us to do a copy. It's not the end of the world but could be avoided. The number of channels received is now explicit (via `AudioFrame::num_channels_`), instead of being guessed based on the number of samples (considering we're always dealing with 10ms of audio, and we know the rate). It's still coupled a bit with audio devices, but we cheat, and use a "fake audio device", which isn't going to touch actual OS APIs. MozReview-Commit-ID: 1Tfajkv1HQR
media/webrtc/signaling/src/media-conduit/AudioConduit.h
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.h
@@ -12,16 +12,17 @@
 #include "nsTArray.h"
 
 #include "MediaConduitInterface.h"
 #include "MediaEngineWrapper.h"
 #include "RtpSourceObserver.h"
 
 // Audio Engine Includes
 #include "webrtc/common_types.h"
+#include "webrtc/modules/audio_device/include/fake_audio_device.h"
 #include "webrtc/voice_engine/include/voe_base.h"
 #include "webrtc/voice_engine/include/voe_volume_control.h"
 #include "webrtc/voice_engine/include/voe_codec.h"
 #include "webrtc/voice_engine/include/voe_file.h"
 #include "webrtc/voice_engine/include/voe_network.h"
 #include "webrtc/voice_engine/include/voe_external_media.h"
 #include "webrtc/voice_engine/include/voe_audio_processing.h"
 #include "webrtc/voice_engine/include/voe_video_sync.h"
@@ -169,16 +170,17 @@ public:
   virtual bool SendRtcp(const uint8_t *data,
                         size_t len) override;
 
   virtual uint64_t CodecPluginID() override { return 0; }
   virtual void SetPCHandle(const std::string& aPCHandle) override {}
 
   explicit WebrtcAudioConduit():
                       mVoiceEngine(nullptr),
+                      mFakeAudioDevice(new webrtc::FakeAudioDeviceModule()),
                       mTransportMonitor("WebrtcAudioConduit"),
                       mTransmitterTransport(nullptr),
                       mReceiverTransport(nullptr),
                       mEngineTransmitting(false),
                       mEngineReceiving(false),
                       mChannel(-1),
                       mDtmfEnabled(false),
                       mCodecMutex("AudioConduit codec db"),
@@ -292,16 +294,17 @@ private:
                            const AudioCodecConfig* codecInfo) const;
   //Checks the codec to be applied
   MediaConduitErrorCode ValidateCodecConfig(const AudioCodecConfig* codecInfo, bool send);
 
   //Utility function to dump recv codec database
   void DumpCodecDB() const;
 
   webrtc::VoiceEngine* mVoiceEngine;
+  UniquePtr<webrtc::FakeAudioDeviceModule> mFakeAudioDevice;
   mozilla::ReentrantMonitor mTransportMonitor;
   RefPtr<TransportInterface> mTransmitterTransport;
   RefPtr<TransportInterface> mReceiverTransport;
   ScopedCustomReleasePtr<webrtc::VoENetwork>   mPtrVoENetwork;
   ScopedCustomReleasePtr<webrtc::VoEBase>      mPtrVoEBase;
   ScopedCustomReleasePtr<webrtc::VoECodec>     mPtrVoECodec;
   ScopedCustomReleasePtr<webrtc::VoEExternalMedia> mPtrVoEXmedia;
   ScopedCustomReleasePtr<webrtc::VoEAudioProcessing> mPtrVoEProcessing;
@@ -329,16 +332,18 @@ private:
   Mutex mCodecMutex; // protects mCurSendCodecConfig
   nsAutoPtr<AudioCodecConfig> mCurSendCodecConfig;
 
   // Current "capture" delay (really output plus input delay)
   int32_t mCaptureDelay;
 
   uint32_t mLastTimestamp;
 
+  webrtc::AudioFrame mAudioFrame; // for output pulls
+
   uint32_t mSamples;
   uint32_t mLastSyncLog;
 
   RtpSourceObserver mRtpSourceObserver;
 };
 
 } // end namespace
 
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -2120,17 +2120,17 @@ public:
 
       segment.AppendFrames(samples.forget(), outputChannels, frames,
                            principal_handle_);
 
       // Handle track not actually added yet or removed/finished
       if (source->AppendToTrack(track_->GetInputTrackId(), &segment)) {
         played_ticks_ += frames;
         if (MOZ_LOG_TEST(AudioLogModule(), LogLevel::Debug)) {
-          if (played_ticks_ > last_log_ + graph->GraphRate()) { // ~ 1 second
+          if (played_ticks_ > last_log_ + rate) { // ~ 1 second
             MOZ_LOG(AudioLogModule(), LogLevel::Debug,
                     ("%p: Inserting %zu samples into track %d, total = %" PRIu64,
                      (void*) this, frames, track_->GetInputTrackId(),
                      played_ticks_));
             last_log_ = played_ticks_;
           }
         }
       } else {
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -22,17 +22,16 @@
 #include "AudioPacketizer.h"
 #include "StreamTracks.h"
 #include "signaling/src/peerconnection/PacketDumper.h"
 
 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
 
 // Should come from MediaEngine.h, but that's a pain to include here
 // because of the MOZILLA_EXTERNAL_LINKAGE stuff.
-#define WEBRTC_DEFAULT_SAMPLE_RATE 32000
 #define WEBRTC_MAX_SAMPLE_RATE 48000
 
 class nsIPrincipal;
 
 namespace mozilla {
 class MediaPipelineFilter;
 class PeerIdentity;
 class AudioProxyThread;
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -2250,16 +2250,17 @@ PeerConnectionImpl::InsertAudioLevelForC
     if (transceiver->HasReceiveTrack(&aRecvTrack)) {
       transceiver->InsertAudioLevelForContributingSource(aSource,
                                                          aTimestamp,
                                                          aHasLevel,
                                                          aLevel);
       break;
     }
   }
+
   return NS_OK;
 }
 
 nsresult
 PeerConnectionImpl::AddRIDExtension(MediaStreamTrack& aRecvTrack,
                                     unsigned short aExtensionId)
 {
   return mMedia->AddRIDExtension(aRecvTrack, aExtensionId);