static gboolean gst_directsound_sink_open (GstAudioSink * asink) { GstDirectSoundSink *dsoundsink; HRESULT hRes; dsoundsink = GST_DIRECTSOUND_SINK (asink); /* create and initialize a DirecSound object */ if (FAILED (hRes = DirectSoundCreate (NULL, &dsoundsink->pDS, NULL))) { GST_ELEMENT_ERROR (dsoundsink, RESOURCE, OPEN_READ, ("gst_directsound_sink_open: DirectSoundCreate: %s", DXGetErrorString9 (hRes)), (NULL)); return FALSE; } if (FAILED (hRes = IDirectSound_SetCooperativeLevel (dsoundsink->pDS, GetDesktopWindow (), DSSCL_PRIORITY))) { GST_ELEMENT_ERROR (dsoundsink, RESOURCE, OPEN_READ, ("gst_directsound_sink_open: IDirectSound_SetCooperativeLevel: %s", DXGetErrorString9 (hRes)), (NULL)); return FALSE; } return TRUE; }
static GstCaps * gst_directsound_probe_supported_formats (GstDirectSoundSink * dsoundsink, const GstCaps * template_caps) { HRESULT hRes; DSBUFFERDESC descSecondary; WAVEFORMATEX wfx; GstCaps *caps; caps = gst_caps_copy (template_caps); /* * Check availability of digital output by trying to create an SPDIF buffer */ /* fill the WAVEFORMATEX structure with some standard AC3 over SPDIF params */ memset (&wfx, 0, sizeof (wfx)); wfx.cbSize = 0; wfx.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF; wfx.nChannels = 2; wfx.nSamplesPerSec = 48000; wfx.wBitsPerSample = 16; wfx.nBlockAlign = 4; wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; // create a secondary directsound buffer memset (&descSecondary, 0, sizeof (DSBUFFERDESC)); descSecondary.dwSize = sizeof (DSBUFFERDESC); descSecondary.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; descSecondary.dwBufferBytes = 6144; descSecondary.lpwfxFormat = &wfx; hRes = IDirectSound_CreateSoundBuffer (dsoundsink->pDS, &descSecondary, &dsoundsink->pDSBSecondary, NULL); if (FAILED (hRes)) { GST_INFO_OBJECT (dsoundsink, "AC3 passthrough not supported " "(IDirectSound_CreateSoundBuffer returned: %s)\n", DXGetErrorString9 (hRes)); caps = gst_caps_subtract (caps, gst_caps_new_simple ("audio/x-iec958", NULL)); } else { GST_INFO_OBJECT (dsoundsink, "AC3 passthrough supported"); hRes = IDirectSoundBuffer_Release (dsoundsink->pDSBSecondary); if (FAILED (hRes)) { GST_DEBUG_OBJECT (dsoundsink, "(IDirectSoundBuffer_Release returned: %s)\n", DXGetErrorString9 (hRes)); } } return caps; }
void LcD3D_GetDxError(HRESULT hr, char* pBufferPointer) { char* s = (char*) malloc(2048); if(pBufferPointer) { sprintf(s , "File:%s\n" "Error Line:%d\n" "Error Msg: %s\n" "Error Desc:%s\n" "Error Pointer: %s\n" , __FILE__ , __LINE__ , DXGetErrorString9(hr) , DXGetErrorDescription9(hr) , pBufferPointer ); } else { sprintf(s , "File:%s\n" "Error Line:%d\n" "Error Msg: %s\n" "Error Desc:%s\n" , __FILE__ , __LINE__ , DXGetErrorString9(hr) , DXGetErrorDescription9(hr)); } OutputDebugString( s ); MessageBox(0, s, "Err", MB_OK | MB_ICONERROR); free(s); }
/************************************************************************** Error: msg Code: hr Description: desc(hr) **************************************************************************/ void cLog::Error(HRESULT hr, char *msg) { FILE *f; char s[256]; ZeroMemory(s,sizeof(s)); sprintf(s,"Error: %s\n",msg); sprintf(s,"%sCode: %s\n",s,(char *)DXGetErrorString9(hr)); sprintf(s,"%sDescription: %s\n",s,DXGetErrorDescription9(hr)); f=fopen("log.txt","a+"); fwrite(s,sizeof(char),strlen(s),f); fclose(f); }
void DX9Texture::loadFromFile(const char* szPath, int numMipLevels, HDResourceMgr *pMgr) { // szPath can be null ASSERT(pMgr); destroy(); //-- string szSafePath; if(szPath) szSafePath = szPath; else szSafePath = getRefName(); DX9ResourceMgr* pDX9Mgr = (DX9ResourceMgr*)pMgr; IDirect3DDevice9* pDev = pDX9Mgr->getDX9Device(); HRESULT hr; D3DXIMAGE_INFO imgInfo; hr = D3DXCreateTextureFromFileEx(pDev, szSafePath.c_str(), D3DX_DEFAULT, // width D3DX_DEFAULT, // height numMipLevels, 0, // usage D3DFMT_UNKNOWN, // format, D3DPOOL_MANAGED,// pool D3DX_DEFAULT, // filter D3DX_DEFAULT, // mip filter 0, // color key &imgInfo, NULL,//palette &m_texture); if(FAILED(hr)) { LOG("texture load failed, path = %s, error = %s.\r\n", szSafePath.c_str(), DXGetErrorString9(hr)); m_texture = s_fallbackTexture; throw HDAPIException("texture file load failed."); } }
HRESULT LoadTextureFromRes( LPDIRECT3DDEVICE9 pDevice, LPCTSTR pFileName, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, DWORD Filter, DWORD MipFilter, D3DCOLOR ColorKey, D3DXIMAGE_INFO *pSrcInfo, PALETTEENTRY *pPalette, LPDIRECT3DTEXTURE9 *ppTexture ) { HRESULT hr = E_FAIL; CResFile file; if( file.Open( pFileName, "rb" ) == FALSE ) { LPCTSTR szErr = Error( "::LoadTextureFromRes : %s not found", pFileName ); ADDERRORMSG( szErr ); return E_FAIL; } int nSrcDataSize = file.GetLength(); LPBYTE pSrcData = new BYTE[ nSrcDataSize ]; if( file.Read( pSrcData, nSrcDataSize ) >= 1 ) { hr = D3DXCreateTextureFromFileInMemoryEx( pDevice, pSrcData, nSrcDataSize, Width, Height, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture ); if( FAILED( hr ) ) { LPCTSTR szErr = Error( "D3DXCreateTextureFromFileInMemoryEx %s %s", pFileName, DXGetErrorString9( hr ) ); ADDERRORMSG( szErr ); } } SAFE_DELETE_ARRAY( pSrcData ); return hr; }
void D3D9Device::drawIndexedPrimitives( const video::PrimitivesType type, video::Vertexstream& vertexstream, video::Indexstream& indexstream, const ion_uint32 indexOffset, const ion_uint32 numElements) { vertexstream.bind(); indexstream.bind(); HRESULT hr=m_pD3DDev9->DrawIndexedPrimitive( d3dprimitivetype(type),0,0,vertexstream.capacity(),indexOffset,numElements); if (FAILED(hr)) { base::log("D3D9Device::drawIndexedPrimitives()",base::Error); base::logstream() << DXGetErrorString9(hr) << " " << DXGetErrorDescription9(hr) << "\n"; base::logstream() << "Index stream capacity: " << indexstream.capacity() << "\n"; base::logstream() << "Vertex stream capacity: " << vertexstream.capacity() << "\n"; base::logstream() << "Index offset: " << indexOffset << "\n"; base::logstream() << "Num elements: " << numElements << "\n"; } }
static gboolean gst_directsound_sink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec) { GstDirectSoundSink *dsoundsink = GST_DIRECTSOUND_SINK (asink); HRESULT hRes; DSBUFFERDESC descSecondary; WAVEFORMATEX wfx; /*save number of bytes per sample and buffer format */ dsoundsink->bytes_per_sample = spec->bytes_per_sample; dsoundsink->buffer_format = spec->format; /* fill the WAVEFORMATEX structure with spec params */ memset (&wfx, 0, sizeof (wfx)); if (spec->format != GST_IEC958) { wfx.cbSize = sizeof (wfx); wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = spec->channels; wfx.nSamplesPerSec = spec->rate; wfx.wBitsPerSample = (spec->bytes_per_sample * 8) / wfx.nChannels; wfx.nBlockAlign = spec->bytes_per_sample; wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; /* Create directsound buffer with size based on our configured * buffer_size (which is 200 ms by default) */ dsoundsink->buffer_size = gst_util_uint64_scale_int (wfx.nAvgBytesPerSec, spec->buffer_time, GST_MSECOND); /* Make sure we make those numbers multiple of our sample size in bytes */ dsoundsink->buffer_size += dsoundsink->buffer_size % spec->bytes_per_sample; spec->segsize = gst_util_uint64_scale_int (wfx.nAvgBytesPerSec, spec->latency_time, GST_MSECOND); spec->segsize += spec->segsize % spec->bytes_per_sample; spec->segtotal = dsoundsink->buffer_size / spec->segsize; } else { wfx.cbSize = 0; wfx.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF; wfx.nChannels = 2; wfx.nSamplesPerSec = spec->rate; wfx.wBitsPerSample = 16; wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels; wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; spec->segsize = 6144; spec->segtotal = 10; } // Make the final buffer size be an integer number of segments dsoundsink->buffer_size = spec->segsize * spec->segtotal; GST_INFO_OBJECT (dsoundsink, "GstRingBufferSpec->channels: %d, GstRingBufferSpec->rate: %d, GstRingBufferSpec->bytes_per_sample: %d\n" "WAVEFORMATEX.nSamplesPerSec: %ld, WAVEFORMATEX.wBitsPerSample: %d, WAVEFORMATEX.nBlockAlign: %d, WAVEFORMATEX.nAvgBytesPerSec: %ld\n" "Size of dsound circular buffer=>%d\n", spec->channels, spec->rate, spec->bytes_per_sample, wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nBlockAlign, wfx.nAvgBytesPerSec, dsoundsink->buffer_size); /* create a secondary directsound buffer */ memset (&descSecondary, 0, sizeof (DSBUFFERDESC)); descSecondary.dwSize = sizeof (DSBUFFERDESC); descSecondary.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; if (spec->format != GST_IEC958) descSecondary.dwFlags |= DSBCAPS_CTRLVOLUME; descSecondary.dwBufferBytes = dsoundsink->buffer_size; descSecondary.lpwfxFormat = (WAVEFORMATEX *) & wfx; hRes = IDirectSound_CreateSoundBuffer (dsoundsink->pDS, &descSecondary, &dsoundsink->pDSBSecondary, NULL); if (FAILED (hRes)) { GST_ELEMENT_ERROR (dsoundsink, RESOURCE, OPEN_READ, ("gst_directsound_sink_prepare: IDirectSound_CreateSoundBuffer: %s", DXGetErrorString9 (hRes)), (NULL)); return FALSE; } gst_directsound_sink_set_volume (dsoundsink); return TRUE; }