--- a/dom/media/GraphDriver.h
+++ b/dom/media/GraphDriver.h
@@ -227,17 +227,17 @@ protected:
// Something has signaled RunThread() to wake up immediately,
// but it hasn't done so yet
WAITSTATE_WAKING_UP
};
// This must be access with the monitor.
WaitState mWaitState;
// Callback for mic data, if any
- RefPtr<AudioDataListener> mAudioInput;
+ AudioDataListener *mAudioInput;
// This is used on the main thread (during initialization), and the graph
// thread. No monitor needed because we know the graph thread does not run
// during the initialization.
TimeStamp mCurrentTimeStamp;
// This is non-null only when this driver has recently switched from an other
// driver, and has not cleaned it up yet (for example because the audio stream
// is currently calling the callback during initialization).
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -1291,18 +1291,18 @@ public:
void UnregisterCaptureStreamForWindow(uint64_t aWindowId);
already_AddRefed<MediaInputPort> ConnectToCaptureStream(
uint64_t aWindowId, MediaStream* aMediaStream);
/**
* Data going to the speakers from the GraphDriver's DataCallback
* to notify any listeners (for echo cancellation).
*/
- void NotifySpeakerData(AudioDataValue* aBuffer, size_t aFrames,
- uint32_t aChannels);
+ void NotifyOutputData(AudioDataValue* aBuffer, size_t aFrames,
+ uint32_t aChannels);
protected:
explicit MediaStreamGraph(TrackRate aSampleRate)
: mSampleRate(aSampleRate)
{
MOZ_COUNT_CTOR(MediaStreamGraph);
}
virtual ~MediaStreamGraph()
@@ -1315,14 +1315,18 @@ protected:
/**
* Sample rate at which this graph runs. For real time graphs, this is
* the rate of the audio mixer. For offline graphs, this is the rate specified
* at construction.
*/
TrackRate mSampleRate;
- nsTArray<RefPtr<AudioDataListener>> mAudioInputs;
+ /**
+ * Lifetime is controlled by OpenAudioInput/CloseAudioInput. Destroying the listener
+ * without removing it is an error; callers should assert on that.
+ */
+ nsTArray<AudioDataListener *> mAudioInputs;
};
} // namespace mozilla
#endif /* MOZILLA_MEDIASTREAMGRAPH_H_ */
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -131,44 +131,40 @@ protected:
nsCString mUUID;
};
// Small subset of VoEHardware
class AudioInput
{
public:
AudioInput(webrtc::VoiceEngine* aVoiceEngine) : mVoiceEngine(aVoiceEngine) {};
- virtual ~AudioInput() {}
-
- NS_INLINE_DECL_REFCOUNTING(AudioInput)
+ // Threadsafe because it's referenced from an MicrophoneSource, which can
+ // had references to it on other threads.
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioInput)
virtual int GetNumOfRecordingDevices(int& aDevices) = 0;
virtual int GetRecordingDeviceName(int aIndex, char aStrNameUTF8[128],
char aStrGuidUTF8[128]) = 0;
virtual int GetRecordingDeviceStatus(bool& aIsAvailable) = 0;
virtual void StartRecording(MediaStreamGraph *aGraph, AudioDataListener *aListener) = 0;
virtual void StopRecording(MediaStreamGraph *aGraph, AudioDataListener *aListener) = 0;
virtual int SetRecordingDevice(int aIndex) = 0;
protected:
+ // Protected destructor, to discourage deletion outside of Release():
+ virtual ~AudioInput() {}
+
webrtc::VoiceEngine* mVoiceEngine;
};
class AudioInputCubeb : public AudioInput
{
public:
AudioInputCubeb(webrtc::VoiceEngine* aVoiceEngine) :
AudioInput(aVoiceEngine), mDevices(nullptr) {}
- virtual ~AudioInputCubeb()
- {
- if (mDevices) {
- cubeb_device_collection_destroy(mDevices);
- mDevices = nullptr;
- }
- }
virtual int GetNumOfRecordingDevices(int& aDevices)
{
// devices = cubeb_get_num_devices(...)
if (CUBEB_OK != cubeb_enumerate_devices(CubebUtils::GetCubebContext(),
CUBEB_DEVICE_TYPE_INPUT,
&mDevices)) {
return 0;
@@ -221,25 +217,33 @@ public:
}
virtual int SetRecordingDevice(int aIndex)
{
// Relevant with devid support
return 1;
}
+protected:
+ virtual ~AudioInputCubeb()
+ {
+ if (mDevices) {
+ cubeb_device_collection_destroy(mDevices);
+ mDevices = nullptr;
+ }
+ }
+
private:
cubeb_device_collection* mDevices;
};
class AudioInputWebRTC : public AudioInput
{
public:
AudioInputWebRTC(webrtc::VoiceEngine* aVoiceEngine) : AudioInput(aVoiceEngine) {}
- virtual ~AudioInputWebRTC() {}
virtual int GetNumOfRecordingDevices(int& aDevices)
{
ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw;
ptrVoEHw = webrtc::VoEHardware::GetInterface(mVoiceEngine);
if (!ptrVoEHw) {
return 1;
}
@@ -276,16 +280,20 @@ public:
{
ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw;
ptrVoEHw = webrtc::VoEHardware::GetInterface(mVoiceEngine);
if (!ptrVoEHw) {
return 1;
}
return ptrVoEHw->SetRecordingDevice(aIndex);
}
+
+protected:
+ // Protected destructor, to discourage deletion outside of Release():
+ virtual ~AudioInputWebRTC() {}
};
class WebRTCAudioDataListener : public AudioDataListener
{
protected:
// Protected destructor, to discourage deletion outside of Release():
virtual ~WebRTCAudioDataListener() {}