--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -26,24 +26,16 @@ namespace mozilla {
#undef LOGW
LazyLogModule gAudioStreamLog("AudioStream");
// For simple logs
#define LOG(x, ...) MOZ_LOG(gAudioStreamLog, mozilla::LogLevel::Debug, ("%p " x, this, ##__VA_ARGS__))
#define LOGW(x, ...) MOZ_LOG(gAudioStreamLog, mozilla::LogLevel::Warning, ("%p " x, this, ##__VA_ARGS__))
/**
- * When MOZ_DUMP_AUDIO is set in the environment (to anything),
- * we'll drop a series of files in the current working directory named
- * dumped-audio-<nnn>.wav, one per AudioStream created, containing
- * the audio for the stream including any skips due to underruns.
- */
-static int gDumpedAudioCount = 0;
-
-/**
* Keep a list of frames sent to the audio engine in each DataCallback along
* with the playback rate at the moment. Since the playback rate and number of
* underrun frames can vary in each callback. We need to keep the whole history
* in order to calculate the playback position of the audio engine correctly.
*/
class FrameHistory {
struct Chunk {
uint32_t servicedFrames;
@@ -235,24 +227,31 @@ static void SetUint32LE(uint8_t* aDest,
{
SetUint16LE(aDest, aValue & 0xFFFF);
SetUint16LE(aDest + 2, aValue >> 16);
}
static FILE*
OpenDumpFile(uint32_t aChannels, uint32_t aRate)
{
+ /**
+ * When MOZ_DUMP_AUDIO is set in the environment (to anything),
+ * we'll drop a series of files in the current working directory named
+ * dumped-audio-<nnn>.wav, one per AudioStream created, containing
+ * the audio for the stream including any skips due to underruns.
+ */
+ static Atomic<int> gDumpedAudioCount(0);
+
if (!getenv("MOZ_DUMP_AUDIO"))
return nullptr;
char buf[100];
- snprintf_literal(buf, "dumped-audio-%d.wav", gDumpedAudioCount);
+ snprintf_literal(buf, "dumped-audio-%d.wav", ++gDumpedAudioCount);
FILE* f = fopen(buf, "wb");
if (!f)
return nullptr;
- ++gDumpedAudioCount;
uint8_t header[] = {
// RIFF header
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45,
// fmt chunk. We always write 16-bit samples.
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