Commit 940a00ce authored by Julien Wadel's avatar Julien Wadel
Browse files

Fix a crash on multiple instance of Filter.

Remove constraint of having only one filter.
parent 36f5c602
......@@ -104,7 +104,10 @@ MSWasapi::MSWasapi(const std::string& mediaDirectionStr) : mAudioClient(NULL){
}
void MSWasapi::updateFormat(bool useBestFormat){
bool MSWasapi::updateFormat(bool useBestFormat){
bool ok = false;
if(!mAudioClient) goto error;
ok = true;
if(useBestFormat ) {
useBestFormat = false;
WAVEFORMATEX *pWfx = NULL;
......@@ -123,6 +126,7 @@ error:
mNChannels = 1;
}
mNBlockAlign = mWBitsPerSample * mNChannels / 8;
return ok;
}
WAVEFORMATPCMEX MSWasapi::buildFormat() const{
......
......@@ -87,7 +87,7 @@ public:
#if !defined(MS2_WINDOWS_PHONE) && !defined(MS2_WINDOWS_UNIVERSAL)
void changePolicies(IMMDevice *device);
#endif
void updateFormat(bool useBestFormat);
bool updateFormat(bool useBestFormat);// return true if no error occured
WAVEFORMATPCMEX buildFormat() const;
};
......
......@@ -38,11 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
}
bool MSWASAPIReader::smInstantiated = false;
MSWASAPIReader::MSWASAPIReader(MSFilter *filter)
: MSWasapi("input"), mAudioCaptureClient(NULL), mVolumeControler(NULL), mBufferFrameCount(0), mIsInitialized(false), mIsActivated(false), mIsStarted(false), mFilter(filter)
{
......@@ -69,7 +64,6 @@ MSWASAPIReader::~MSWASAPIReader()
}
#endif
ms_ticker_synchronizer_destroy(mTickerSynchronizer);
smInstantiated = false;
}
......@@ -89,10 +83,6 @@ void MSWASAPIReader::init(LPCWSTR id)
ms_error("Could not get the CaptureID of the MSWASAPI audio input interface");
goto error;
}
if (smInstantiated) {
ms_error("An MSWASAPIReader is already instantiated. A second one can not be created.");
goto error;
}
result = ActivateAudioInterfaceAsync(mCaptureId->Data(), IID_IAudioClient2, NULL, this, &asyncOp);
REPORT_ERROR("Could not activate the MSWASAPI audio input interface [%i]", result);
WaitForSingleObjectEx(mActivationEvent, INFINITE, FALSE);
......@@ -107,11 +97,6 @@ void MSWASAPIReader::init(LPCWSTR id)
goto error;
}
if (smInstantiated) {
ms_error("An MSWASAPIReader is already instantiated. A second one can not be created.");
goto error;
}
result = ActivateAudioInterface(mCaptureId, IID_IAudioClient2, (void **)&mAudioClient);
REPORT_ERROR("Could not activate the MSWASAPI audio input interface [%x]", result);
#else
......@@ -142,11 +127,10 @@ void MSWASAPIReader::init(LPCWSTR id)
#endif
useBestFormat = true;
error:
updateFormat(useBestFormat);
mIsInitialized = true;
smInstantiated = true;
activate();
if(updateFormat(useBestFormat)){
mIsInitialized = true;
activate();
}
return;
}
......@@ -381,7 +365,6 @@ MSWASAPIReaderPtr MSWASAPIReaderNew(MSFilter *f)
}
void MSWASAPIReaderDelete(MSWASAPIReaderPtr ptr)
{
ptr->reader->setAsNotInstantiated();
ptr->reader = nullptr;
delete ptr;
}
......
......@@ -55,7 +55,6 @@ public:
void setVolumeLevel(float volume);
#ifdef MS2_WINDOWS_UNIVERSAL
void setAsNotInstantiated() { smInstantiated = false; }
// IActivateAudioInterfaceCompletionHandler
STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *operation);
......@@ -63,7 +62,6 @@ public:
private:
void silence(MSFilter *f);
static bool smInstantiated;
#ifdef MS2_WINDOWS_UNIVERSAL
Platform::String^ mCaptureId;
HANDLE mActivationEvent;
......
......@@ -43,9 +43,6 @@ static const int flowControlInterval = 5000; // ms
static const int flowControlThreshold = 40; // ms
static const int minBufferDurationMs = 200; // ms
bool MSWASAPIWriter::smInstantiated = false;
MSWASAPIWriter::MSWASAPIWriter()
: MSWasapi("output"), mAudioRenderClient(NULL), mVolumeControler(NULL), mBufferFrameCount(0), mIsInitialized(false), mIsActivated(false), mIsStarted(false)
{
......@@ -70,7 +67,6 @@ MSWASAPIWriter::~MSWASAPIWriter()
mActivationEvent = INVALID_HANDLE_VALUE;
}
#endif
smInstantiated = false;
}
......@@ -89,10 +85,6 @@ void MSWASAPIWriter::init(LPCWSTR id, MSFilter *f) {
ms_error("Could not get the RenderID of the MSWASAPI audio output interface");
goto error;
}
if (smInstantiated) {
ms_error("An MSWASAPIWriter is already instantiated. A second one can not be created.");
goto error;
}
result = ActivateAudioInterfaceAsync(mRenderId->Data(), IID_IAudioClient2, NULL, this, &asyncOp);
REPORT_ERROR("Could not activate the MSWASAPI audio output interface [%i]", result);
WaitForSingleObjectEx(mActivationEvent, INFINITE, FALSE);
......@@ -106,12 +98,6 @@ void MSWASAPIWriter::init(LPCWSTR id, MSFilter *f) {
ms_error("Could not get the RenderId of the MSWASAPI audio output interface");
goto error;
}
if (smInstantiated) {
ms_error("An MSWASAPIWriter is already instantiated. A second one can not be created.");
goto error;
}
result = ActivateAudioInterface(mRenderId, IID_IAudioClient2, (void **)&mAudioClient);
REPORT_ERROR("Could not activate the MSWASAPI audio output interface [%i]", result);
#else
......@@ -143,11 +129,10 @@ void MSWASAPIWriter::init(LPCWSTR id, MSFilter *f) {
useBestFormat = true;
error:
updateFormat(useBestFormat);
mIsInitialized = true;
smInstantiated = true;
activate();
if(updateFormat(useBestFormat)){
mIsInitialized = true;
activate();
}
return;
}
......@@ -385,7 +370,6 @@ MSWASAPIWriterPtr MSWASAPIWriterNew()
}
void MSWASAPIWriterDelete(MSWASAPIWriterPtr ptr)
{
ptr->writer->setAsNotInstantiated();
ptr->writer = nullptr;
delete ptr;
}
......
......@@ -55,7 +55,6 @@ public:
void setVolumeLevel(float volume);
#ifdef MS2_WINDOWS_UNIVERSAL
void setAsNotInstantiated() { smInstantiated = false; }
// IActivateAudioInterfaceCompletionHandler
STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *operation);
......@@ -65,7 +64,6 @@ private:
void drop(MSFilter *f);
HRESULT configureAudioClient();
static bool smInstantiated;
#ifdef MS2_WINDOWS_UNIVERSAL
Platform::String^ mRenderId;
HANDLE mActivationEvent;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment