Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am developing an application in C++, one of whose features is to play audio (currently options for wav and mp3). I wrote the audio part using DirectShow, and it seems to be having this strange issue.

When trying to render the chosen file, sometimes the program will throw a "Cannot play back the audio stream: no audio hardware is available, or the hardware is not responding" error. This does seem to have a continuous behavior sometimes, where it would happen after I type data into an edit control, then press a button which updates a class's member variables with all the data that the user enters into a form and then try to play the sound file. However, if the user tried to play the sound file before pressing the update button, it would work fine afterwards. Like I said, whatever causes that error seems to be completely random though, because the trigger for causing the error has changed multiple times to different things that you can do with my application.
Also, if I build the program in Debug mode, everything works perfectly fine. The entire UI seems to be running much faster as well, because in release mode it takes a few seconds to open, for example, a file browser dialog, and in debug it happens almost instantly. The debug build works perfectly, but obviously I cannot release the debug build.
This also seems to be happening only on my laptop, but not my desktop. If I run the release build on my desktop, everything works perfectly, and the UI runs faster, which is strange because my laptop does not have a difference in power so much that there would be that much difference in speed.

My application is multi-threaded, but I stepped through the debugger (the release mode built with debug symbols) and I know for a fact that all the calls to my directshow code are being run only from the main thread.

Laptop:
Lenovo ThinkPad W520
Intel Core i7 2760QM
nVidia Quadro 1000M with optimus enabled
4GB DDR3 RAM
Windows 7 Professional 64-bit on Japanese locale

Desktop:
ASUS Essentio CG5270
Intel Core 2 Quad
nVIDIA GeForce GTX 460 1GB
8GB DDR2 RAM
Windows 7 Ultimate 64-bit on Japanese locale
 
code:
bool Sound::Open(char* file)
{
 
	hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void **)&m_pEvent);
	if (FAILED(hr))
	{
		char errText[MAX_ERROR_TEXT_LEN];
		AMGetErrorText(hr, errText, sizeof(errText));
		MessageBox(NULL, errText, "", MB_OK);
		//return false;
	}
 
	hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pControl);
	if (FAILED(hr))
	{
		char errText[MAX_ERROR_TEXT_LEN];
		AMGetErrorText(hr, errText, sizeof(errText));
		MessageBox(NULL, errText, "", MB_OK);
		//return false;
	}
 
	//hr = AddFilterByCLSID(m_pGraph, CLSID_DSoundRender, &m_pDeviceFilter, L"Default DirectSound Device");

	WCHAR *tmpW;
	int length = strlen(file)+1;
	tmpW = new WCHAR[length];
 
	MultiByteToWideChar(CP_ACP, 0, file, length, tmpW, length);
 
	hr = m_pGraph->RenderFile(tmpW, NULL);
	if (FAILED(hr))
	{
		char errText[MAX_ERROR_TEXT_LEN];
		AMGetErrorText(hr, errText, sizeof(errText));
		MessageBox(NULL, errText, "", MB_OK);
		return false;
	}
 

	return true;
 
}
Posted 14-Dec-11 12:25pm
Edited 14-Dec-11 12:29pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 690
1 Dnyaneshwar@Pune 540
2 ravikhoda 325
3 OriginalGriff 279
4 Manas Bhardwaj 230
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,777
2 Peter Leow 4,785
3 Abhinav S 3,813
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 14 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid