Пример #1
0
//
//  Retrieves the device friendly name for a particular device in a device collection.  
//
//  The returned string was allocated using malloc() so it should be freed using free();
//
String GetDeviceName(IMMDeviceCollection *DeviceCollection, UINT DeviceIndex)
{
    IMMDevice *device;
    LPWSTR deviceId;
    HRESULT hr;

    hr = DeviceCollection->Item(DeviceIndex, &device);
    PersistentAssert(SUCCEEDED(hr), "DeviceCollection->Item failed");
    
    hr = device->GetId(&deviceId);
    PersistentAssert(SUCCEEDED(hr), "device->GetId failed");

    IPropertyStore *propertyStore;
    hr = device->OpenPropertyStore(STGM_READ, &propertyStore);
    SafeRelease(&device);
    PersistentAssert(SUCCEEDED(hr), "device->OpenPropertyStore failed");

    PROPVARIANT friendlyName;
    PropVariantInit(&friendlyName);
    hr = propertyStore->GetValue(PKEY_Device_FriendlyName, &friendlyName);
    SafeRelease(&propertyStore);
    PersistentAssert(SUCCEEDED(hr), "propertyStore->GetValue failed");

    String Result = String(UnicodeString(friendlyName.pwszVal)); // + String(" (") + String( UnicodeString(deviceId) ) + String(")")
    
    PropVariantClear(&friendlyName);
    CoTaskMemFree(deviceId);

    return Result;
}
Пример #2
0
void Compression::CompressStreamToFile(const BYTE *stream, UINT byteCount, const String &filename)
{
    BYTE *compressedStream = new BYTE[byteCount + 64];

    z_stream zstream;

    zstream.zalloc = Z_NULL;
    zstream.zfree = Z_NULL;
    zstream.opaque = Z_NULL;
	
	zstream.avail_in = byteCount;
	zstream.next_in = const_cast<BYTE*>(stream);

	zstream.data_type = Z_BINARY;

	zstream.avail_out = byteCount + 64;
    zstream.next_out = compressedStream;

	const int Level = 6;
    //Result = deflateInit(&Stream, Level);
	int result = deflateInit2(&zstream, Level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
	PersistentAssert(result == Z_OK, "deflateInit failed");

    result = deflate(&zstream, Z_FINISH);
	PersistentAssert(result == Z_STREAM_END, "deflate failed");

    deflateEnd(&zstream);

    FILE *file = Utility::CheckedFOpen(filename.CString(), "wb");
    Utility::CheckedFWrite(&byteCount, sizeof(UINT32), 1, file);
    Utility::CheckedFWrite(compressedStream, sizeof(BYTE), zstream.total_out, file);
    fclose(file);

    delete[] compressedStream;
}
Пример #3
0
void Compression::DecompressStreamFromMemory(const BYTE *compressedStream, UINT compressedStreamLength, BYTE *decompressedStream, UINT decompressedStreamLength)
{
    PersistentAssert(decompressedStreamLength > 0, "Caller must provide the length of the decompressed stream");

    uLongf finalByteCount = decompressedStreamLength;
    int result = uncompress(decompressedStream, &finalByteCount, compressedStream, compressedStreamLength);
    PersistentAssert(result == Z_OK, "Decompression failed");
    PersistentAssert(finalByteCount == decompressedStreamLength, "Decompression returned invalid length");
}
Пример #4
0
//void Thread::Begin(LPTHREAD_START_ROUTINE StartFunction, void *Context)
void Thread::BeginStdCall(unsigned int (__stdcall *StartFunction)(void *), void *Context)
{
    PersistentAssert(_Handle == NULL, "Begin called on active thread");
    //
    // without the CREATE_SUSPENDED flag, the thread will start immediately
    //
    //_Handle = CreateThread(NULL, 0, StartFunction, Context, 0, NULL);
    _Handle = (HANDLE)_beginthreadex(NULL, 0, StartFunction, Context, 0, NULL);
    PersistentAssert(_Handle != NULL, "CreateThread failed");
}
Пример #5
0
void D3D9PixelShader::Reset(GraphicsDevice &graphics)
{
    FreeMemory();

    HRESULT hr;

    _device = graphics.CastD3D9().GetDevice();
    Assert(_device != NULL, "_device == NULL");

    DWORD dwShaderFlags = 0;
    #ifdef DEBUG_PS
        dwShaderFlags |= D3DXSHADER_SKIPOPTIMIZATION | D3DXSHADER_DEBUG;
    #endif

    LPD3DXBUFFER pCode = NULL;
    LPD3DXBUFFER pErrors = NULL;

    PersistentAssert(Utility::FileExists(_shaderFile), String("Shader file not found: ") + _shaderFile);

    // Assemble the vertex shader from the file
    hr = D3DXCompileShaderFromFile( _shaderFile.CString(), NULL, NULL, "PShaderEntry",
                                    "ps_3_0", dwShaderFlags, &pCode,
                                    &pErrors, &_constantTable );
    
    String ErrorString;
    if(pErrors)
    {
        char *ErrorMessage = (char *)pErrors->GetBufferPointer();
        DWORD ErrorLength = pErrors->GetBufferSize();

        ofstream file("ShaderDebug.txt");
        for(UINT i = 0; i < ErrorLength; i++)
        {
            file << ErrorMessage[i];
            ErrorString += String(ErrorMessage[i]);
        }
        file.close();
    }

    PersistentAssert(!FAILED(hr), String("D3DXCompileShaderFromFile failed: ") + ErrorString);

    hr = _device->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
                                            &_shader );

    if(pErrors)
    {
        pErrors->Release();
    }
    if(pCode)
    {
        pCode->Release();
    }
    PersistentAssert(!FAILED(hr), "CreatePixelShader failed");
}
Пример #6
0
void ComplexMesh::ValidateTopology()
{
    for(UINT TriangleIndex = 0; TriangleIndex < _Triangles.Length(); TriangleIndex++)
    {
        Triangle &CurTriangle = _Triangles[TriangleIndex];
        for(UINT i = 0; i < 3; i++)
        {
            PersistentAssert(CurTriangle.GetHalfEdge(i).NextEdge() == CurTriangle.GetHalfEdge((i + 1) % 3), "Invalid topology");
            PersistentAssert(CurTriangle.GetHalfEdge(i).AcrossEdge() == CurTriangle.GetFullEdge(i), "Invalid topology");
        }
    }
}
Пример #7
0
void D3D9PixelShader::Reset(LPDIRECT3DDEVICE9 _Device)
{
    FreeMemory();

    HRESULT hr;

    Device = _Device;
    Assert(Device != NULL, "Device == NULL");

    DWORD dwShaderFlags = 0;
    #ifdef DEBUG_PS
        dwShaderFlags |= D3DXSHADER_SKIPOPTIMIZATION | D3DXSHADER_DEBUG;
    #endif

    LPD3DXBUFFER pCode = NULL;
    LPD3DXBUFFER pErrors = NULL;

    // Assemble the vertex shader from the file
    hr = D3DXCompileShaderFromFile( ShaderFile.CString(), NULL, NULL, "PShaderEntry",
                                    "ps_3_0", dwShaderFlags, &pCode,
                                    &pErrors, &ConstantTable );
    
    String ErrorString;
    if(pErrors)
    {
        char *ErrorMessage = (char *)pErrors->GetBufferPointer();
        DWORD ErrorLength = pErrors->GetBufferSize();

        ofstream file("ShaderDebug.txt");
        for(UINT i = 0; i < ErrorLength; i++)
        {
            file << ErrorMessage[i];
            ErrorString += String(ErrorMessage[i]);
        }
        file.close();
    }

    PersistentAssert(!FAILED(hr), String("D3DXCompileShaderFromFile failed: ") + ErrorString);

    // Create the vertex shader
    hr = Device->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
                                            &Shader );

    if(pErrors)
    {
        pErrors->Release();
    }
    if(pCode)
    {
        pCode->Release();
    }
    PersistentAssert(!FAILED(hr), "CreatePixelShader failed");
}
Пример #8
0
void Compression::DecompressStreamFromFile(const String &filename, Vector<BYTE> &stream)
{
    Vector<BYTE> input;
    Utility::GetFileData(filename, input);
    UINT32 decompressedByteCount = ((UINT32*)input.CArray())[0];
    stream.Allocate(decompressedByteCount);

    uLongf finalByteCount = decompressedByteCount;
    int result = uncompress(stream.CArray(), &finalByteCount, input.CArray() + sizeof(UINT32), input.Length() - sizeof(UINT32));
    PersistentAssert(result == Z_OK, "Decompression failed");
    PersistentAssert(finalByteCount == decompressedByteCount, "Decompression returned invalid length");
}
Пример #9
0
void Globals::Init()
{
	Initialized = true;
	
    UsingNullPixelShader = false;
    String fileName = String("WrapperParameters.txt");
    if (Utility::FileExists(fileName)) {
	    ParameterFile Parameters(fileName);
	    BaseDirectory = Parameters.GetRequiredString("BaseDirectory");
	    OutputFileDirectory = BaseDirectory + String("\\") + Parameters.GetRequiredString("OutputFileDirectory") + String("\\");
	    RealD3D9DLL = Parameters.GetRequiredString("RealD3D9DLL");
	
	    UsingOverlay = Parameters.GetBoolean("UsingOverlay");
	    ConsoleLineCount = Parameters.GetUnsignedInteger("ConsoleLineCount");

        ForceSoftwareVertexProcessing = Parameters.GetBoolean("ForceSoftwareVertexProcessing");
        IgnoreTextureLocks = Parameters.GetBoolean("IgnoreTextureLocks");

        VideoCaptureMode = Parameters.GetBoolean("VideoCaptureMode");
        WritingToFiles = true;
    } else {
        char systemDirectory[_MAX_PATH + 1] = "";
        ::GetSystemDirectoryA(systemDirectory, _MAX_PATH);
        RealD3D9DLL = String(systemDirectory) + String("\\d3d9.dll");
        UsingOverlay = false;
        IgnoreTextureLocks = true;
        VideoCaptureMode = false;
        WritingToFiles = false;
    }
    if(VideoCaptureMode)
    {
        IgnoreTextureLocks = true;
    }

    if (WritingToFiles) {
        const char *infoFilePath = (OutputFileDirectory + String("WrapperInfo.txt")).CString();
        _InfoFile = new ofstream(infoFilePath);
        PersistentAssert(!_InfoFile->fail(), "Failed to open InfoFile");

        const char *unreportedFilePath = (OutputFileDirectory + String("WrapperUnreportedEvents.txt")).CString();
        _UnreportedFile = new ofstream(unreportedFilePath);
        PersistentAssert(!_UnreportedFile->fail(), "Failed to open UnreportedFile");

        const char *errorFilePath = (OutputFileDirectory + String("WrapperErrors.txt")).CString();
        _ErrorFile = new ofstream(errorFilePath);
        PersistentAssert(!_ErrorFile->fail(), "Failed to open ErrorFile");
    } else {
        _InfoFile = new ::nullstream;
        _UnreportedFile = new ::nullstream;
        _ErrorFile = new ::nullstream;
    }
}
Пример #10
0
void D3D9Texture::ReadData(Grid<float> &Data)
{
    PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_R32F, "ReadData called on invalid surface");
    Data.Allocate(_Height, _Width);
    D3DLOCKED_RECT Rect;
    if(_RenderTarget)
    {
        D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData");
        D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    }
    else
    {
        D3DAlwaysValidate(_SurfaceTopLevel->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    }
    BYTE *Bytes = (BYTE *)Rect.pBits;
    for(UINT y = 0; y < _Height; y++)
    {
        float *CurRow = (float *)(Bytes + y * Rect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            Data(y, x) = CurRow[x];
        }
    }
    if(_RenderTarget)
    {
        D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect");
    }
    else
    {
        D3DValidate(_SurfaceTopLevel->UnlockRect(), "UnlockRect");
    }
}
Пример #11
0
//
//  Initialize WASAPI in event driven mode, associate the audio client with our samples ready event handle, retrieve 
//  a capture client for the transport, create the capture thread and start the audio engine.
//
bool CWASAPICapture::InitializeAudioEngine()
{
    HRESULT hr = _AudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST, _EngineLatencyInMS*10000, 0, MixFormat(), NULL);
    PersistentAssert(SUCCEEDED(hr), "_AudioClient->Initialize failed");
    
    //
    //  Retrieve the buffer size for the audio client.
    //
    hr = _AudioClient->GetBufferSize(&_BufferSize);
    PersistentAssert(SUCCEEDED(hr), "_AudioClient->GetBufferSize failed");

    hr = _AudioClient->GetService(IID_PPV_ARGS(&_CaptureClient));
    PersistentAssert(SUCCEEDED(hr), "_AudioClient->GetService failed");

    return true;
}
Пример #12
0
void Overlay::CreateNullPixelShader()
{
    HRESULT hr;

    DWORD dwShaderFlags = 0;
    D3D9Base::LPD3DXBUFFER pCode = NULL;
    D3D9Base::LPD3DXBUFFER pErrors = NULL;

    String ShaderFilename = g_Globals.BaseDirectory + String("\\") + String("Null.psh");

    PersistentAssert(Utility::FileExists(ShaderFilename), "Null.psh not found");

    // Assemble the vertex shader from the file
    hr = D3DXCompileShaderFromFile( ShaderFilename.CString(), NULL, NULL, "PShaderEntry",
                                    "ps_3_0", dwShaderFlags, &pCode,
                                    &pErrors, NULL );
    
    String ErrorString;
    if(pErrors)
    {
        char *ErrorMessage = (char *)pErrors->GetBufferPointer();
        DWORD ErrorLength = pErrors->GetBufferSize();

        for(UINT i = 0; i < ErrorLength; i++)
        {
            g_Globals.ErrorFile() << ErrorMessage[i];
            ErrorString += String(ErrorMessage[i]);
        }
    }

    PersistentAssert(!FAILED(hr), String("D3DXCompileShaderFromFile failed: ") + ErrorString);

    // Create the pixel shader
    hr = _Device->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
                                     &_NullPixelShader );

    if(pErrors)
    {
        pErrors->Release();
    }
    if(pCode)
    {
        pCode->Release();
    }
    PersistentAssert(!FAILED(hr), "CreatePixelShader failed");
}
Пример #13
0
 UINT GetFileSize(const String &Filename)
 {
     BOOL Success;
     WIN32_FILE_ATTRIBUTE_DATA Info;
     Success = GetFileAttributesEx(Filename.CString(), GetFileExInfoStandard, (void*)&Info);
     PersistentAssert(Success && Info.nFileSizeHigh == 0, String("GetFileAttributesEx failed on ") + Filename);
     return Info.nFileSizeLow;
 }
Пример #14
0
void D3D9Texture::Flush()
{
    PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_A32B32G32R32F && _RenderTarget, "ReadData called on invalid surface");
    D3DLOCKED_RECT Rect;
    D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData");
    D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect");
}
Пример #15
0
void D3D10Texture::Allocate(UINT Width, UINT Height, bool ConstructMipmaps, DXGI_FORMAT Format, const Bitmap &Bmp)
{
    FreeMemory();
    PersistentAssert(_GD != NULL, "D3D10Texture::Allocate on unassociated texture");
    ID3D10Device* Device = _GD->CastD3D10().GetDevice();

    D3D10_TEXTURE2D_DESC TextureDesc;
    TextureDesc.Width = Width;
    TextureDesc.Height = Height;
    TextureDesc.MipLevels = 0;
    if(!ConstructMipmaps)
    {
        TextureDesc.MipLevels = 1;
    }
    TextureDesc.ArraySize = 1;
    TextureDesc.Format = Format;
    TextureDesc.SampleDesc.Count = 1;
    TextureDesc.SampleDesc.Quality = 0;
    TextureDesc.Usage = D3D10_USAGE_DEFAULT;
    TextureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
    TextureDesc.CPUAccessFlags = 0;
    TextureDesc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;

    D3D10_SUBRESOURCE_DATA Data[12];
    for(UINT Index = 0; Index < 12; Index++)
    {
        Data[Index].pSysMem = &(Bmp[0][0]);
        Data[Index].SysMemPitch = Bmp.Width() * sizeof(RGBColor);
    }

    HRESULT hr = Device->CreateTexture2D(&TextureDesc, Data, &_Texture);
    PersistentAssert(SUCCEEDED(hr), "CreateTexture2D failed");

    _Texture->GetDesc(&TextureDesc);

    D3D10_SHADER_RESOURCE_VIEW_DESC ViewDesc;
    ViewDesc.Format = Format;
    ViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
    ViewDesc.Texture2D.MostDetailedMip = 0;
    ViewDesc.Texture2D.MipLevels = TextureDesc.MipLevels;

    hr = Device->CreateShaderResourceView(_Texture, &ViewDesc, &_View);
    PersistentAssert(SUCCEEDED(hr), "CreateShaderResourceView failed");

    Device->GenerateMips(_View);
}
Пример #16
0
//
//  Retrieve the format we'll use to capture samples.
//
//  We use the Mix format since we're capturing in shared mode.
//
bool CWASAPICapture::LoadFormat()
{
    HRESULT hr = _AudioClient->GetMixFormat((WAVEFORMATEX**)&_MixFormat);
    PersistentAssert(SUCCEEDED(hr), "_AudioClient->GetMixFormat failed");
    //-		SubFormat	{00000003-0000-0010-8000-00AA00389B71}	_GUID, KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
    _FrameSize = (_MixFormat->Format.wBitsPerSample / 8) * _MixFormat->Format.nChannels;
    return true;
}
Пример #17
0
bool AudioCapture::StartCaptureInternal(UINT AudioDeviceIndex)
{
    PersistentAssert(_CaptureDevice == NULL && _Capturer == NULL, "StartCapture called without StopCapture");

    const int TargetLatency = 20;
    int TargetDurationInSec = 10;

    //
    //  A GUI application should use COINIT_APARTMENTTHREADED instead of COINIT_MULTITHREADED.
    //
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    //PersistentAssert(SUCCEEDED(hr), "CoInitializeEx failed");
    
    //
    //  Now that we've parsed our command line, pick the device to capture.
    //
    bool Success = PickDevice(&_CaptureDevice, AudioDeviceIndex);
    PersistentAssert(Success, "PickDevice failed");
    
    //
    //  Instantiate a capturer and capture sounds for TargetDuration seconds
    //
    //  Configure the capturer to enable stream switching on the specified role if the user specified one of the default devices.
    //
    _Capturer = new (std::nothrow) CWASAPICapture(_CaptureDevice, _Compressor);
    PersistentAssert(_Capturer != NULL, "Allocate CWASAPICapture failed");
        
    if (_Capturer->Initialize(TargetLatency))
    {
        //
        //  We've initialized the capturer.  Once we've done that, we know some information about the
        //  mix format and we can allocate the buffer that we're going to capture.
        //
        //
        //  The buffer is going to contain "TargetDuration" seconds worth of PCM data.  That means 
        //  we're going to have TargetDuration*samples/second frames multiplied by the frame size.
        //
        size_t captureBufferSize = _Capturer->SamplesPerSecond() * TargetDurationInSec * _Capturer->FrameSize();
        _CaptureBuffer.Allocate(captureBufferSize);
        bool Success = _Capturer->Start(_CaptureBuffer.CArray(), captureBufferSize);
        PersistentAssert(Success, "_Capturer->Start failed");
    }

    return true;
}
Пример #18
0
void VideoCompressor::AddFrame(const Bitmap &Bmp, double TimeInSeconds)
{
    if(_Clock != NULL)
    {
        TimeInSeconds = _Clock->Elapsed();
    }
    _Sample->SetSampleTime( LONGLONG( TimeInSeconds * 10000000.0 ) );
        
    BYTE *BufferData;
    HRESULT hr = _Buffer->Lock(&BufferData, NULL, NULL);
    PersistentAssert(SUCCEEDED(hr), "_Buffer->Lock failed");

    memcpy( BufferData, &(Bmp[0][0]), Bmp.Width() * Bmp.Height() * sizeof(RGBColor) );
    _Buffer->Unlock();

    hr = _Writer->WriteSample(0, _Sample);
    PersistentAssert(SUCCEEDED(hr), "WriteSample failed");
}
Пример #19
0
void FileCollection::GetFileLines(const String &FileCollectionName, Vector<String> &Lines)
{
    _FileListMutex.Acquire();
    
    FileCollectionFile* CurFile = FindFile(FileCollectionName);
    PersistentAssert(CurFile != NULL, String("Failed to find ") + String(FileCollectionName) + " in database.");
    CurFile->GetFileLines(Lines);

    _FileListMutex.Release();
}
Пример #20
0
Camera::Camera(const String &s)
{
    Vector<String> v = s.Partition(',');
    PersistentAssert(v.Length() == 15, "Incorrect number of components");
    _eye     = Vec3f(v[0 ].ConvertToFloat(), v[1 ].ConvertToFloat(), v[2 ].ConvertToFloat());
    _look    = Vec3f(v[3 ].ConvertToFloat(), v[4 ].ConvertToFloat(), v[5 ].ConvertToFloat());
    _up      = Vec3f(v[6 ].ConvertToFloat(), v[7 ].ConvertToFloat(), v[8 ].ConvertToFloat());
    _right   = Vec3f(v[9 ].ConvertToFloat(), v[10].ConvertToFloat(), v[11].ConvertToFloat());
    _worldUp = Vec3f(v[12].ConvertToFloat(), v[13].ConvertToFloat(), v[14].ConvertToFloat());
}
Пример #21
0
//
//  Write the captured wave data to an output file so that it can be examined later.
//
void SaveWaveData(BYTE *CaptureBuffer, size_t BufferSize, const WAVEFORMATEX *WaveFormat, const String &Filename)
{
    HANDLE waveHandle = CreateFile(Filename.CString(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 
        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 
        NULL);
    if (waveHandle != INVALID_HANDLE_VALUE)
    {
        bool Success = WriteWaveFile(waveHandle, CaptureBuffer, BufferSize, WaveFormat);
        PersistentAssert(Success, "WriteWaveFile failed");
        CloseHandle(waveHandle);
    }
}
Пример #22
0
//
//  Start capturing...
//
bool CWASAPICapture::Start(BYTE *CaptureBuffer, size_t CaptureBufferSize)
{
    HRESULT hr;

    _CaptureBuffer = CaptureBuffer;
    _CaptureBufferSize = CaptureBufferSize;

    //
    //  Now create the thread which is going to drive the capture.
    //
    _CaptureThread = CreateThread(NULL, 0, WASAPICaptureThread, this, 0, NULL);
    PersistentAssert(_CaptureThread != NULL, "CreateThread failed");
    
    //
    //  We're ready to go, start capturing!
    //
    hr = _AudioClient->Start();
    PersistentAssert(SUCCEEDED(hr), "_AudioClient->Start failed");
    
    return true;
}
Пример #23
0
//
//  Initialize the capturer.
//
bool CWASAPICapture::Initialize(UINT32 EngineLatency)
{
    //
    //  Create our shutdown event - we want auto reset events that start in the not-signaled state.
    //
    _ShutdownEvent = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE);
    PersistentAssert(_ShutdownEvent != NULL, "CreateEventEx failed");
    
    //
    //  Create our stream switch event- we want auto reset events that start in the not-signaled state.
    //  Note that we create this event even if we're not going to stream switch - that's because the event is used
    //  in the main loop of the capturer and thus it has to be set.
    //
    _StreamSwitchEvent = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE);
    PersistentAssert(_StreamSwitchEvent != NULL, "CreateEventEx failed");
    
    //
    //  Now activate an IAudioClient object on our preferred endpoint and retrieve the mix format for that endpoint.
    //
    HRESULT hr = _Endpoint->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, NULL, reinterpret_cast<void **>(&_AudioClient));
    PersistentAssert(SUCCEEDED(hr), "_Endpoint->Activate failed");

    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&_DeviceEnumerator));
    PersistentAssert(SUCCEEDED(hr), "CoCreateInstance failed");

    //
    // Load the MixFormat.  This may differ depending on the shared mode used
    //
    LoadFormat();
    
    //
    //  Remember our configured latency in case we'll need it for a stream switch later.
    //
    _EngineLatencyInMS = EngineLatency;

    InitializeAudioEngine();
    return true;
}
Пример #24
0
//
//  Based on the input switches, pick the specified device to use.
//
bool PickDevice(IMMDevice **DeviceToUse, UINT AudioDeviceIndex)
{
    IMMDeviceEnumerator *deviceEnumerator = NULL;
    IMMDeviceCollection *deviceCollection = NULL;

    HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&deviceEnumerator));
    PersistentAssert(SUCCEEDED(hr), "CoCreateInstance failed");
    
    IMMDevice *device = NULL;

    //
    //  The user didn't specify an output device, prompt the user for a device and use that.
    //
    hr = deviceEnumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &deviceCollection);
    PersistentAssert(SUCCEEDED(hr), "deviceEnumerator->EnumAudioEndpoints failed");
    
    UINT deviceCount;
    hr = deviceCollection->GetCount(&deviceCount);
    PersistentAssert(SUCCEEDED(hr), "deviceCollection->GetCount failed");
    for (UINT DeviceIndex = 0 ; DeviceIndex < deviceCount; DeviceIndex++)
    {
        String deviceName = GetDeviceName(deviceCollection, DeviceIndex);
        //Console::WriteLine(String(DeviceIndex) + String(": ") + deviceName);
    }
    
    int deviceIndex = 0;
    if(AudioDeviceIndex < deviceCount)
    {
        deviceIndex = AudioDeviceIndex;
    }
    hr = deviceCollection->Item(deviceIndex, DeviceToUse);
    PersistentAssert(DeviceToUse != NULL && SUCCEEDED(hr), "deviceCollection->Item failed");
    
    SafeRelease(&deviceCollection);
    SafeRelease(&deviceEnumerator);
    return true;
}
Пример #25
0
void D3D9Texture::Allocate(D3DFORMAT Format, UINT Width, UINT Height, bool RenderTarget, UINT MipmapLevels)
{
    if(_Width != Width || _Height != Height || _Format != Format || _RenderTarget != RenderTarget)
    {
        FreeMemory();
        PersistentAssert(_Device != NULL, "D3D9Texture not associated");
        
        DWORD Usage = 0;

		if(MipmapLevels != 1)
		{
			Usage |= D3DUSAGE_AUTOGENMIPMAP;
		}
        
        D3DPOOL Pool = D3DPOOL_MANAGED;

        /*if(Format == D3DFMT_DXT1)
        {
            while((Width & 3) != 0)
            {
                Width--;
            }
            while((Height & 3) != 0)
            {
                Height--;
            }
            if(Width == 0) Width = 4;
            if(Height == 0) Height = 4;
        }*/

        if(RenderTarget)
        {
            Usage |= D3DUSAGE_RENDERTARGET;
            Pool = D3DPOOL_DEFAULT;
            D3DAlwaysValidate(_Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &_SurfacePlain, NULL), "CreateOffscreenPlainSurface");
        }
        
        D3DAlwaysValidate(_Device->CreateTexture(Width, Height, MipmapLevels, Usage, Format, Pool, &_Texture, NULL), "CreateTexture");
        D3DValidate(_Texture->GetSurfaceLevel(0, &_SurfaceTopLevel), "GetSurfaceLevel");
        _Width = Width;
        _Height = Height;
        _Format = Format;
        _RenderTarget = RenderTarget;
    }
}
Пример #26
0
void FileCollection::RemoveFile(const String &FileCollectionName)
{
    _FileListMutex.Acquire();
    for(UINT FileIndex = 0; FileIndex < _FileList.Length(); FileIndex++)
    {
        FileCollectionFile *CurFile = _FileList[FileIndex];
        if(CurFile->Filename == FileCollectionName)
        {
            delete CurFile;
            _FileList.RemoveSwap(FileIndex);
            PersistentAssert(_FileMap.find(FileCollectionName.CString()) != _FileMap.end(), "File not found in map");
            _FileMap.erase(_FileMap.find(FileCollectionName.CString()));
            _FileListMutex.Release();
            return;
        }
    }
    _FileListMutex.Release();
}
Пример #27
0
void D3D9Texture::ReadData(Bitmap &Bmp)
{
    PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_A8R8G8B8 && _RenderTarget, "ReadData called on invalid surface");
    Bmp.Allocate(_Width, _Height);
    D3DLOCKED_RECT Rect;
    D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData");
    D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    BYTE *Bytes = (BYTE *)Rect.pBits;
    for(UINT y = 0; y < _Height; y++)
    {
        RGBColor *CurRow = (RGBColor *)(Bytes + y * Rect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            Bmp[y][x] = CurRow[x];
        }
    }
    D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect");
}
Пример #28
0
void D3D9Texture::ReadData(Grid<Vec3f> &Data)
{
    PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_A32B32G32R32F && _RenderTarget, "ReadData called on invalid surface");
    Data.Allocate(_Height, _Width);
    D3DLOCKED_RECT Rect;
    D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData");
    D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    BYTE *Bytes = (BYTE *)Rect.pBits;
    for(UINT y = 0; y < _Height; y++)
    {
        Vec4f *CurRow = (Vec4f *)(Bytes + y * Rect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            Data(y, x) = Vec3f(CurRow[x].x, CurRow[x].y, CurRow[x].z);
        }
    }
    D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect");
}
void D3D9RenderTargetTexture::GetDepthData(Grid<float> &DepthMap)
{
    PersistentAssert(_DepthSurface != NULL, "_DepthSurface == NULL unexpected");
    D3DLOCKED_RECT LockedRect;
    D3DAlwaysValidate(_DepthSurface->LockRect(&LockedRect, NULL, 0), "LockRect");
    BYTE *Data = (BYTE *)LockedRect.pBits;
    
    DepthMap.Allocate(_Height, _Width);
    
    for(UINT y = 0; y < _Height; y++)
    {
        float *RowStart = (float *)(Data + y * LockedRect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            DepthMap.GetElement(y, x) = RowStart[x];
        }
    }
    D3DAlwaysValidate(_DepthSurface->UnlockRect(), "UnlockRect");
}
void D3D9RenderTargetTexture::Init(LPDIRECT3DDEVICE9 Device, UINT Width, UINT Height, bool CreateDepthSurface)
{
    FreeMemory();

    PersistentAssert(Device != NULL, "Device == NULL");
    _Device = Device;
    _Width = Width;
    _Height = Height;
    //FullValidate(_Device->CreateRenderTarget(_Width, _Height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &_Surface, NULL));
    D3DAlwaysValidate(_Device->CreateTexture(_Width, _Height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_Texture, NULL), "CreateTexture");
    D3DAlwaysValidate(_Device->CreateOffscreenPlainSurface(_Width, _Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &_SurfacePlain, NULL), "CreateOffscreenPlainSurface");
    D3DAlwaysValidate(_Texture->GetSurfaceLevel(0, &_Surface), "GetSurfaceLevel");

    if(CreateDepthSurface)
    {
        D3DAlwaysValidate(_Device->CreateDepthStencilSurface(_Width, _Height, D3DFMT_D32F_LOCKABLE, D3DMULTISAMPLE_NONE, 0, FALSE, &_DepthSurface, NULL), "CreateDepthStencilSurface");
    }

    _DataCopy.Allocate(_Width, _Height);
}