Bug 1277198. Part 2 - fix OpenDumpFile(). r=kinetik. draft 1274214_remove_WMFMediaDataDecoder_TaskQueue
authorJW Wang <jwwang@mozilla.com>
Wed, 01 Jun 2016 17:54:37 +0800
branch1274214_remove_WMFMediaDataDecoder_TaskQueue
changeset 375534 39c105ad766947ebe350b8b2afc2685bb00339dc
parent 375533 d578e00f15300fbcf1cc41fb5242868a4b31b57d
child 375535 49589d5bd8ea1b2575caaf608569c64fab307c5b
push id20304
push userjwwang@mozilla.com
push dateMon, 06 Jun 2016 03:29:59 +0000
reviewerskinetik
bugs1277198
milestone49.0a1
Bug 1277198. Part 2 - fix OpenDumpFile(). r=kinetik. MozReview-Commit-ID: IWzvlWnhuFe
dom/media/AudioStream.cpp
dom/media/AudioStream.h
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -235,17 +235,17 @@ static void SetUint16LE(uint8_t* aDest, 
 
 static void SetUint32LE(uint8_t* aDest, uint32_t aValue)
 {
   SetUint16LE(aDest, aValue & 0xFFFF);
   SetUint16LE(aDest + 2, aValue >> 16);
 }
 
 static FILE*
-OpenDumpFile(AudioStream* aStream)
+OpenDumpFile(uint32_t aChannels, uint32_t aRate)
 {
   if (!getenv("MOZ_DUMP_AUDIO"))
     return nullptr;
   char buf[100];
   snprintf_literal(buf, "dumped-audio-%d.wav", gDumpedAudioCount);
   FILE* f = fopen(buf, "wb");
   if (!f)
     return nullptr;
@@ -258,19 +258,19 @@ OpenDumpFile(AudioStream* aStream)
     0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0xFF, 0xFF,
     0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x10, 0x00,
     // data chunk
     0x64, 0x61, 0x74, 0x61, 0xFE, 0xFF, 0xFF, 0x7F
   };
   static const int CHANNEL_OFFSET = 22;
   static const int SAMPLE_RATE_OFFSET = 24;
   static const int BLOCK_ALIGN_OFFSET = 32;
-  SetUint16LE(header + CHANNEL_OFFSET, aStream->GetChannels());
-  SetUint32LE(header + SAMPLE_RATE_OFFSET, aStream->GetRate());
-  SetUint16LE(header + BLOCK_ALIGN_OFFSET, aStream->GetChannels()*2);
+  SetUint16LE(header + CHANNEL_OFFSET, aChannels);
+  SetUint32LE(header + SAMPLE_RATE_OFFSET, aRate);
+  SetUint16LE(header + BLOCK_ALIGN_OFFSET, aChannels * 2);
   fwrite(header, sizeof(header), 1, f);
 
   return f;
 }
 
 template <typename T>
 typename EnableIf<IsSame<T, int16_t>::value, void>::Type
 WriteDumpFileHelper(T* aInput, size_t aSamples, FILE* aFile) {
@@ -327,17 +327,17 @@ AudioStream::Init(uint32_t aNumChannels,
   auto startTime = TimeStamp::Now();
   auto isFirst = CubebUtils::GetFirstStream();
 
   LOG("%s channels: %d, rate: %d", __FUNCTION__, aNumChannels, aRate);
   mInRate = mOutRate = aRate;
   mChannels = aNumChannels;
   mOutChannels = aNumChannels;
 
-  mDumpFile = OpenDumpFile(this);
+  mDumpFile = OpenDumpFile(aNumChannels, aRate);
 
   cubeb_stream_params params;
   params.rate = aRate;
   params.channels = mOutChannels;
 #if defined(__ANDROID__)
 #if defined(MOZ_B2G)
   params.stream_type = CubebUtils::ConvertChannelToCubebType(aAudioChannel);
 #else
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -219,18 +219,17 @@ public:
   // was opened, of the audio hardware.  Thread-safe.
   int64_t GetPositionInFrames();
 
   static uint32_t GetPreferredRate()
   {
     CubebUtils::InitPreferredSampleRate();
     return CubebUtils::PreferredSampleRate();
   }
-  uint32_t GetRate() { return mOutRate; }
-  uint32_t GetChannels() { return mChannels; }
+
   uint32_t GetOutChannels() { return mOutChannels; }
 
   // Set playback rate as a multiple of the intrinsic playback rate. This is to
   // be called only with aPlaybackRate > 0.0.
   nsresult SetPlaybackRate(double aPlaybackRate);
   // Switch between resampling (if false) and time stretching (if true, default).
   nsresult SetPreservesPitch(bool aPreservesPitch);