mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-13 03:24:26 +00:00
Bug 1055141 - use a UniquePtr for AudioStream's mCubebStream member; r=kinetik
This commit is contained in:
parent
098b729147
commit
52e2e05296
@ -575,13 +575,13 @@ void AudioStream::PanOutputIfNeeded(bool aMicrophoneActive)
|
||||
}
|
||||
|
||||
if (!strncmp(name, "MacBookPro", 10)) {
|
||||
if (cubeb_stream_get_current_device(mCubebStream, &device) == CUBEB_OK) {
|
||||
if (cubeb_stream_get_current_device(mCubebStream.get(), &device) == CUBEB_OK) {
|
||||
// Check if we are currently outputing sound on external speakers.
|
||||
if (!strcmp(device->output_name, "ispk")) {
|
||||
// Pan everything to the right speaker.
|
||||
if (aMicrophoneActive) {
|
||||
LOG(("%p Panning audio output to the right.", this));
|
||||
if (cubeb_stream_set_panning(mCubebStream, 1.0) != CUBEB_OK) {
|
||||
if (cubeb_stream_set_panning(mCubebStream.get(), 1.0) != CUBEB_OK) {
|
||||
NS_WARNING("Could not pan audio output to the right.");
|
||||
}
|
||||
} else {
|
||||
@ -592,11 +592,11 @@ void AudioStream::PanOutputIfNeeded(bool aMicrophoneActive)
|
||||
}
|
||||
if (panCenter) {
|
||||
LOG(("%p Panning audio output to the center.", this));
|
||||
if (cubeb_stream_set_panning(mCubebStream, 0.0) != CUBEB_OK) {
|
||||
if (cubeb_stream_set_panning(mCubebStream.get(), 0.0) != CUBEB_OK) {
|
||||
NS_WARNING("Could not pan audio output to the center.");
|
||||
}
|
||||
}
|
||||
cubeb_stream_device_destroy(mCubebStream, device);
|
||||
cubeb_stream_device_destroy(mCubebStream.get(), device);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -609,14 +609,14 @@ void AudioStream::ResetStreamIfNeeded()
|
||||
if (!mMicrophoneActive || mLatencyRequest != LowLatency) {
|
||||
return;
|
||||
}
|
||||
if (cubeb_stream_get_current_device(mCubebStream, &device) == CUBEB_OK) {
|
||||
if (cubeb_stream_get_current_device(mCubebStream.get(), &device) == CUBEB_OK) {
|
||||
// This a microphone that goes through the headphone plug, reset the
|
||||
// output to prevent echo building up.
|
||||
if (strcmp(device->input_name, "emic") == 0) {
|
||||
LOG(("Resetting audio output"));
|
||||
Reset();
|
||||
}
|
||||
cubeb_stream_device_destroy(mCubebStream, device);
|
||||
cubeb_stream_device_destroy(mCubebStream.get(), device);
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,7 +660,7 @@ AudioStream::OpenCubeb(cubeb_stream_params &aParams,
|
||||
latency, DataCallback_S, StateCallback_S, this) == CUBEB_OK) {
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
MOZ_ASSERT(mState != SHUTDOWN);
|
||||
mCubebStream.own(stream);
|
||||
mCubebStream.reset(stream);
|
||||
// We can't cubeb_stream_start() the thread from a transient thread due to
|
||||
// cubeb API requirements (init can be called from another thread, but
|
||||
// not start/stop/destroy/etc)
|
||||
@ -672,7 +672,7 @@ AudioStream::OpenCubeb(cubeb_stream_params &aParams,
|
||||
}
|
||||
}
|
||||
|
||||
cubeb_stream_register_device_changed_callback(mCubebStream,
|
||||
cubeb_stream_register_device_changed_callback(mCubebStream.get(),
|
||||
AudioStream::DeviceChangedCallback_s);
|
||||
|
||||
mState = INITIALIZED;
|
||||
@ -844,7 +844,7 @@ AudioStream::SetVolume(double aVolume)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aVolume >= 0.0 && aVolume <= 1.0, "Invalid volume");
|
||||
|
||||
if (cubeb_stream_set_volume(mCubebStream, aVolume * GetVolumeScale()) != CUBEB_OK) {
|
||||
if (cubeb_stream_set_volume(mCubebStream.get(), aVolume * GetVolumeScale()) != CUBEB_OK) {
|
||||
NS_WARNING("Could not change volume on cubeb stream.");
|
||||
}
|
||||
}
|
||||
@ -902,7 +902,7 @@ AudioStream::StartUnlocked()
|
||||
int r;
|
||||
{
|
||||
MonitorAutoUnlock mon(mMonitor);
|
||||
r = cubeb_stream_start(mCubebStream);
|
||||
r = cubeb_stream_start(mCubebStream.get());
|
||||
|
||||
PanOutputIfNeeded(mMicrophoneActive);
|
||||
}
|
||||
@ -924,7 +924,7 @@ AudioStream::Pause()
|
||||
int r;
|
||||
{
|
||||
MonitorAutoUnlock mon(mMonitor);
|
||||
r = cubeb_stream_stop(mCubebStream);
|
||||
r = cubeb_stream_stop(mCubebStream.get());
|
||||
}
|
||||
if (mState != ERRORED && r == CUBEB_OK) {
|
||||
mState = STOPPED;
|
||||
@ -942,7 +942,7 @@ AudioStream::Resume()
|
||||
int r;
|
||||
{
|
||||
MonitorAutoUnlock mon(mMonitor);
|
||||
r = cubeb_stream_start(mCubebStream);
|
||||
r = cubeb_stream_start(mCubebStream.get());
|
||||
}
|
||||
if (mState != ERRORED && r == CUBEB_OK) {
|
||||
mState = STARTED;
|
||||
@ -962,7 +962,7 @@ AudioStream::Shutdown()
|
||||
if (mCubebStream) {
|
||||
MonitorAutoUnlock mon(mMonitor);
|
||||
// Force stop to put the cubeb stream in a stable state before deletion.
|
||||
cubeb_stream_stop(mCubebStream);
|
||||
cubeb_stream_stop(mCubebStream.get());
|
||||
// Must not try to shut down cubeb from within the lock! wasapi may still
|
||||
// call our callback after Pause()/stop()!?! Bug 996162
|
||||
mCubebStream.reset();
|
||||
@ -1004,7 +1004,7 @@ AudioStream::GetPositionInFramesUnlocked()
|
||||
uint64_t position = 0;
|
||||
{
|
||||
MonitorAutoUnlock mon(mMonitor);
|
||||
if (cubeb_stream_get_position(mCubebStream, &position) != CUBEB_OK) {
|
||||
if (cubeb_stream_get_position(mCubebStream.get(), &position) != CUBEB_OK) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1016,7 +1016,7 @@ int64_t
|
||||
AudioStream::GetLatencyInFrames()
|
||||
{
|
||||
uint32_t latency;
|
||||
if (cubeb_stream_get_latency(mCubebStream, &latency)) {
|
||||
if (cubeb_stream_get_latency(mCubebStream.get(), &latency)) {
|
||||
NS_WARNING("Could not get cubeb latency.");
|
||||
return 0;
|
||||
}
|
||||
@ -1291,7 +1291,7 @@ AudioStream::DataCallback(void* aBuffer, long aFrames)
|
||||
mState != SHUTDOWN &&
|
||||
insertTime != INT64_MAX && servicedFrames > underrunFrames) {
|
||||
uint32_t latency = UINT32_MAX;
|
||||
if (cubeb_stream_get_latency(mCubebStream, &latency)) {
|
||||
if (cubeb_stream_get_latency(mCubebStream.get(), &latency)) {
|
||||
NS_WARNING("Could not get latency from cubeb.");
|
||||
}
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
|
@ -8,29 +8,31 @@
|
||||
|
||||
#include "AudioSampleFormat.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsAutoRef.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "Latency.h"
|
||||
#include "mozilla/dom/AudioChannelBinding.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "cubeb/cubeb.h"
|
||||
|
||||
template <>
|
||||
class nsAutoRefTraits<cubeb_stream> : public nsPointerRefTraits<cubeb_stream>
|
||||
{
|
||||
public:
|
||||
static void Release(cubeb_stream* aStream) { cubeb_stream_destroy(aStream); }
|
||||
};
|
||||
|
||||
namespace soundtouch {
|
||||
class SoundTouch;
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
template<>
|
||||
struct DefaultDelete<cubeb_stream>
|
||||
{
|
||||
void operator()(cubeb_stream* aStream) const
|
||||
{
|
||||
cubeb_stream_destroy(aStream);
|
||||
}
|
||||
};
|
||||
|
||||
class AudioStream;
|
||||
class FrameHistory;
|
||||
|
||||
@ -387,9 +389,8 @@ private:
|
||||
// frames.
|
||||
CircularByteBuffer mBuffer;
|
||||
|
||||
// Owning reference to a cubeb_stream. cubeb_stream_destroy is called by
|
||||
// nsAutoRef's destructor.
|
||||
nsAutoRef<cubeb_stream> mCubebStream;
|
||||
// Owning reference to a cubeb_stream.
|
||||
UniquePtr<cubeb_stream> mCubebStream;
|
||||
|
||||
uint32_t mBytesPerFrame;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user