Bug 1426171 - Only use the graph's rate if supported by the AudioConduit. r?pehrsons draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 20 Dec 2017 14:16:04 +0100
changeset 713642 14c11fdfc47c02ca0bace6bb7da857a9d2709255
parent 713490 e0b8fdb1cf84e9918055b87e9a231ca508b65065
child 713650 c1f3c0c6415f608eb64a8499c07488231e82619d
child 714060 3f34c94dac865ca902b7316b15e694d2b7815902
push id93707
push userbmo:jyavenard@mozilla.com
push dateWed, 20 Dec 2017 20:19:24 +0000
reviewerspehrsons
bugs1426171
milestone59.0a1
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);
   }