From 209bdf88930e97856384829dcde087686d53e926 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Mon, 30 May 2016 15:24:17 +0200 Subject: [PATCH] Bug 1271585 - Part 1 - Keep a buffer around instead of allocating for each packetizer packets for input data. r=jesup This what was meant to happen, but it didn't work because `mInputBufferLen` was never set. An nsTArray prevents this to happen. MozReview-Commit-ID: PBFTluFcrs --- dom/media/webrtc/MediaEngineWebRTC.h | 6 ++---- dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 10 +++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/dom/media/webrtc/MediaEngineWebRTC.h b/dom/media/webrtc/MediaEngineWebRTC.h index 719e540c725f..56c0fd53eda3 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.h +++ b/dom/media/webrtc/MediaEngineWebRTC.h @@ -434,7 +434,7 @@ public: , mSampleFrequency(MediaEngine::DEFAULT_SAMPLE_RATE) , mPlayoutDelay(0) , mNullTransport(nullptr) - , mInputBufferLen(0) { + { MOZ_ASSERT(aVoiceEnginePtr); MOZ_ASSERT(aAudioInput); mDeviceName.Assign(NS_ConvertUTF8toUTF16(name)); @@ -554,9 +554,7 @@ private: NullTransport *mNullTransport; - // For full_duplex packetizer output - size_t mInputBufferLen; - UniquePtr mInputBuffer; + nsTArray mInputBuffer; }; class MediaEngineWebRTC : public MediaEngine diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index 4ca80b4468a9..f7953607de36 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -479,10 +479,10 @@ MediaEngineWebRTCMicrophoneSource::NotifyInputData(MediaStreamGraph* aGraph, while (mPacketizer->PacketsAvailable()) { uint32_t samplesPerPacket = mPacketizer->PacketSize() * mPacketizer->Channels(); - if (mInputBufferLen < samplesPerPacket) { - mInputBuffer = MakeUnique(samplesPerPacket); + if (mInputBuffer.Length() < samplesPerPacket) { + mInputBuffer.SetLength(samplesPerPacket); } - int16_t *packet = mInputBuffer.get(); + int16_t* packet = mInputBuffer.Elements(); mPacketizer->Output(packet); mVoERender->ExternalRecordingInsertData(packet, samplesPerPacket, aRate, 0); @@ -516,10 +516,6 @@ do { \ } \ } while(0) - - - - void MediaEngineWebRTCMicrophoneSource::DeviceChanged() { // Reset some processing