Bug 1426171 - Only use the graph's rate if supported by the AudioConduit. r=pehrsons
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 20 Dec 2017 14:16:04 +0100
changeset 397040 179ac22f4d3a988a306dc32d8af52c1ef4f8a7bb
parent 397039 f53e45ada4338e5fe31b1d78b409add29013a026
child 397041 1023f4bd9918988ad0728975db82a7aacd5d7384
push id33123
push userncsoregi@mozilla.com
push dateThu, 21 Dec 2017 10:00:47 +0000
treeherdermozilla-central@06a19fbe2581 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1426171
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 1426171 - Only use the graph's rate if supported by the AudioConduit. r=pehrsons Otherwise we will use 48kHz as default, the MSG will resample as needed. It would be possible to allow all frequencies in the AudioConduit as the webrtc backend supports them all, however it would require more changes and likely heap allocation that we're trying to limit in this part of the code. MozReview-Commit-ID: B3x5t1FSaQ8
media/webrtc/signaling/src/media-conduit/AudioConduit.h
media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.h
@@ -263,30 +263,30 @@ public:
                    const int64_t aTimestamp,
                    const uint32_t aJitter) override;
 
   // test-only: inserts fake CSRCs and audio level data
   void InsertAudioLevelForContributingSource(uint32_t aSource,
                                              int64_t aTimestamp,
                                              bool aHasLevel,
                                              uint8_t aLevel);
+
+  bool IsSamplingFreqSupported(int freq) const override;
+
 private:
   WebrtcAudioConduit(const WebrtcAudioConduit& other) = delete;
   void operator=(const WebrtcAudioConduit& other) = delete;
 
   //Local database of currently applied receive codecs
   typedef std::vector<AudioCodecConfig* > RecvCodecList;
 
   //Function to convert between WebRTC and Conduit codec structures
   bool CodecConfigToWebRTCCodec(const AudioCodecConfig* codecInfo,
                                 webrtc::CodecInst& cinst);
 
-  //Checks if given sampling frequency is supported
-  bool IsSamplingFreqSupported(int freq) const;
-
   //Generate block size in sample lenght for a given sampling frequency
   unsigned int GetNum10msSamplesForFrequency(int samplingFreqHz) const;
 
   // Function to copy a codec structure to Conduit's database
   bool CopyCodecToDB(const AudioCodecConfig* codecInfo);
 
   // Functions to verify if the codec passed is already in
   // conduits database
--- a/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
+++ b/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
@@ -514,16 +514,22 @@ public:
    *       This ensures the decoded samples are ready for reading.
    *
    */
   virtual MediaConduitErrorCode GetAudioFrame(int16_t speechData[],
                                               int32_t samplingFreqHz,
                                               int32_t capture_delay,
                                               int& lengthSamples) = 0;
 
+  /**
+   * Checks if given sampling frequency is supported
+   * @param freq: Sampling rate (in Hz) to check
+   */
+  virtual bool IsSamplingFreqSupported(int freq) const = 0;
+
    /**
     * Function to configure send codec for the audio session
     * @param sendSessionConfig: CodecConfiguration
     * NOTE: See VideoConduit for more information
     */
 
   virtual MediaConduitErrorCode ConfigureSendMediaCodec(const AudioCodecConfig* sendCodecConfig) = 0;
 
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -2167,17 +2167,25 @@ class MediaPipelineReceiveAudio::Pipelin
 {
 public:
   PipelineListener(dom::MediaStreamTrack* aTrack,
                    const RefPtr<MediaSessionConduit>& aConduit)
     : GenericReceiveListener(aTrack)
     , mConduit(aConduit)
     , mSource(mTrack->GetInputStream()->AsSourceStream())
     , mTrackId(mTrack->GetInputTrackId())
-    , mRate(mSource ? mSource->GraphRate() : 0)
+    // AudioSession conduit only supports 16, 32, 44.1 and 48kHz
+    // This is an artificial limitation, it would however require more changes
+    // to support any rates.
+    // If the sampling rate is not-supported, we will use 48kHz instead.
+    , mRate(mSource ? (static_cast<AudioSessionConduit*>(mConduit.get())
+                           ->IsSamplingFreqSupported(mSource->GraphRate())
+                         ? mSource->GraphRate()
+                         : WEBRTC_MAX_SAMPLE_RATE)
+                    : WEBRTC_MAX_SAMPLE_RATE)
     , mTaskQueue(
         new AutoTaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
                           "AudioPipelineListener"))
     , mLastLog(0)
   {
     MOZ_ASSERT(mSource);
   }