Bug 1312431 - Support for higher sample rates in dtmf_inband.cc can not be reached; r=jesup
authorDan Minor <dminor@mozilla.com>
Mon, 24 Oct 2016 11:36:29 -0400
changeset 320003 355c7ec8b68e965787e18517eeef2a693434992a
parent 320002 726ec9c83018397c0617eb25f71dde6e383b5ec3
child 320004 ddb7b94d3a6ae8a8c415e61f4bdf34794f09ba77
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1312431
milestone52.0a1
Bug 1312431 - Support for higher sample rates in dtmf_inband.cc can not be reached; r=jesup This also fixes a potential buffer overflow as the buffer size was hard coded to be the old maximum buffer size of 320. MozReview-Commit-ID: 5DD8vWlIDPQ
media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.cc
media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.h
--- a/media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.cc
+++ b/media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.cc
@@ -244,17 +244,17 @@ DtmfInband::ReInit()
 bool 
 DtmfInband::IsAddingTone()
 {
     CriticalSectionScoped lock(&_critSect);
     return (_remainingSamples > 0 || _playing);
 }
 
 int
-DtmfInband::Get10msTone(int16_t output[320],
+DtmfInband::Get10msTone(int16_t output[MAX_DTMF_SAMPLERATE/100],
                         uint16_t& outputSizeInSamples)
 {
     CriticalSectionScoped lock(&_critSect);
     if (DtmfFix_generate(output,
                          _eventCode,
                          _attenuationDb,
                          _frameLengthSamples,
                          _outputFrequencyHz) == -1)
@@ -284,17 +284,17 @@ DtmfInband::DelaySinceLastTone() const
     return _delaySinceLastToneMS;
 }
 
 int16_t
 DtmfInband::DtmfFix_generate(int16_t *decoded,
                              int16_t value,
                              int16_t volume,
                              int16_t frameLen,
-                             int16_t fs)
+                             uint16_t fs)
 {
     const int16_t *a_times2Tbl;
     const int16_t *y2_Table;
     int16_t a1_times2 = 0, a2_times2 = 0;
 
     if (fs==8000) {
         a_times2Tbl=Dtmf_a_times2Tab8Khz;
         y2_Table=Dtmf_ym2Tab8Khz;
--- a/media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.h
+++ b/media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.h
@@ -9,16 +9,18 @@
  */
 
 #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_
 #define WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_
 
 #include "webrtc/typedefs.h"
 #include "webrtc/voice_engine/voice_engine_defines.h"
 
+#define MAX_DTMF_SAMPLERATE 48000
+
 namespace webrtc {
 class CriticalSectionWrapper;
 
 class DtmfInband
 {
 public:
     DtmfInband(int32_t id);
 
@@ -36,48 +38,48 @@ public:
 
     int ResetTone();
     int StartTone(uint8_t eventCode, int32_t attenuationDb);
 
     int StopTone();
 
     bool IsAddingTone();
 
-    int Get10msTone(int16_t output[320], uint16_t& outputSizeInSamples);
+    int Get10msTone(int16_t output[MAX_DTMF_SAMPLERATE/100], uint16_t& outputSizeInSamples);
 
     uint32_t DelaySinceLastTone() const;
 
     void UpdateDelaySinceLastTone();
 
 private:
     void ReInit();
     int16_t DtmfFix_generate(int16_t* decoded,
                              int16_t value,
                              int16_t volume,
                              int16_t frameLen,
-                             int16_t fs);
+                             uint16_t fs);
 
 private:
     enum {kDtmfFrameSizeMs = 10};
     enum {kDtmfAmpHigh = 32768};
     enum {kDtmfAmpLow  = 23171};	// 3 dB lower than the high frequency
 
     int16_t DtmfFix_generateSignal(int16_t a1_times2,
                                    int16_t a2_times2,
                                    int16_t volume,
                                    int16_t* signal,
                                    int16_t length);
 
 private:
     CriticalSectionWrapper& _critSect;
     int32_t _id;
-    uint16_t _outputFrequencyHz;  // {8000, 16000, 32000}
+    uint16_t _outputFrequencyHz;  // {8000, 16000, 32000, 44100, 48000}
     int16_t _oldOutputLow[2];     // Data needed for oscillator model
     int16_t _oldOutputHigh[2];    // Data needed for oscillator model
-    int16_t _frameLengthSamples;  // {80, 160, 320}
+    int16_t _frameLengthSamples;  // {80, 160, 320, 441, 480}
     int32_t _remainingSamples;
     int16_t _eventCode;           // [0, 15]
     int16_t _attenuationDb;       // [0, 36]
     int32_t _lengthMs;
     bool _reinit;  // 'true' if the oscillator should be reinit for next event
     bool _playing;
     uint32_t _delaySinceLastToneMS; // time since last generated tone [ms]
 };