static BOOL CALLBACK enumeration_callback(const DIDEVICEINSTANCEA *lpddi, IDirectInputDevice8A *lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef) { HRESULT hr; DIPROPDWORD dp; DIPROPRANGE dpr; DIPROPSTRING dps; WCHAR usernameW[MAX_PATH]; DWORD username_size = MAX_PATH; struct enum_data *data = pvRef; DWORD cnt; DIDEVICEOBJECTDATA buffer[5]; if (!data) return DIENUM_CONTINUE; data->ndevices++; /* Convert username to WCHAR */ if (data->username != NULL) { username_size = MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, 0); MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, username_size); } else GetUserNameW(usernameW, &username_size); /* collect the mouse and keyboard */ if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard)) { IDirectInputDevice_AddRef(lpdid); data->keyboard = lpdid; ok (dwFlags & DIEDBS_MAPPEDPRI1, "Keyboard should be mapped as pri1 dwFlags=%08x\n", dwFlags); } if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse)) { IDirectInputDevice_AddRef(lpdid); data->mouse = lpdid; ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags); } /* Building and setting an action map */ /* It should not use any pre-stored mappings so we use DIDBAM_HWDEFAULTS */ hr = IDirectInputDevice8_BuildActionMap(lpdid, data->lpdiaf, NULL, DIDBAM_HWDEFAULTS); ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr); /* Device has no data format and thus can't be acquired */ hr = IDirectInputDevice8_Acquire(lpdid); ok (hr == DIERR_INVALIDPARAM, "Device was acquired before SetActionMap hr=%08x\n", hr); hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, data->username, 0); ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr); /* Some joysticks may have no suitable actions and thus should not be tested */ if (hr == DI_NOEFFECT) return DIENUM_CONTINUE; /* Test username after SetActionMap */ dps.diph.dwSize = sizeof(dps); dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); dps.diph.dwObj = 0; dps.diph.dwHow = DIPH_DEVICE; dps.wsz[0] = '\0'; hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph); ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr); ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_w(usernameW), wine_dbgstr_w(dps.wsz)); /* Test buffer size */ memset(&dp, 0, sizeof(dp)); dp.diph.dwSize = sizeof(dp); dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); dp.diph.dwHow = DIPH_DEVICE; hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_BUFFERSIZE, &dp.diph); ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr); ok (dp.dwData == data->lpdiaf->dwBufferSize, "SetActionMap must set the buffer, buffersize=%d\n", dp.dwData); cnt = 1; hr = IDirectInputDevice_GetDeviceData(lpdid, sizeof(buffer[0]), buffer, &cnt, 0); ok(hr == DIERR_NOTACQUIRED, "GetDeviceData() failed hr=%08x\n", hr); /* Test axis range */ memset(&dpr, 0, sizeof(dpr)); dpr.diph.dwSize = sizeof(dpr); dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER); dpr.diph.dwHow = DIPH_DEVICE; hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_RANGE, &dpr.diph); /* Only test if device supports the range property */ if (SUCCEEDED(hr)) { ok (dpr.lMin == data->lpdiaf->lAxisMin, "SetActionMap must set the min axis range expected=%d got=%d\n", data->lpdiaf->lAxisMin, dpr.lMin); ok (dpr.lMax == data->lpdiaf->lAxisMax, "SetActionMap must set the max axis range expected=%d got=%d\n", data->lpdiaf->lAxisMax, dpr.lMax); } /* SetActionMap has set the data format so now it should work */ hr = IDirectInputDevice8_Acquire(lpdid); ok (SUCCEEDED(hr), "Acquire failed hr=%08x\n", hr); cnt = 1; hr = IDirectInputDevice_GetDeviceData(lpdid, sizeof(buffer[0]), buffer, &cnt, 0); ok(hr == DI_OK, "GetDeviceData() failed hr=%08x\n", hr); /* SetActionMap should not work on an acquired device */ hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0); ok (hr == DIERR_ACQUIRED, "SetActionMap succeeded with an acquired device hr=%08x\n", hr); return DIENUM_CONTINUE; }
HRESULT WpdServiceMethods::DispatchMethod( _In_ LPCWSTR pwszContext, _In_ IPortableDeviceValues* pStartParams, _COM_Outptr_ IPortableDeviceValues** ppResults) { HRESULT hr = S_OK; HRESULT hrStatus = S_OK; GUID Method = GUID_NULL; CComPtr<IPortableDeviceValues> pMethodParams; CComPtr<IPortableDeviceValues> pMethodResults; *ppResults = NULL; // Get the method GUID hr = pStartParams->GetGuidValue(WPD_PROPERTY_SERVICE_METHOD, &Method); CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_METHOD"); // Get the method parameters. These can be optional if the methods don't require parameters if (SUCCEEDED(hr)) { HRESULT hrTemp = pStartParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_METHOD_PARAMETER_VALUES, &pMethodParams); CHECK_HR(hrTemp, "Failed to get WPD_PROPERTY_SERVICE_METHOD_PARAMETER_VALUES (ok if method does not require parameters)"); } // Prepare the results collection if (SUCCEEDED(hr)) { hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pMethodResults); CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); } if (SUCCEEDED(hr)) { // Invoke the method if (IsEqualGUID(METHOD_FullEnumSyncSvc_BeginSync, Method)) { hrStatus = m_pContactsService->OnBeginSync(pMethodParams, *ppResults); CHECK_HR(hrStatus, "BeginSync method failed"); } else if (IsEqualGUID(METHOD_FullEnumSyncSvc_EndSync, Method)) { hrStatus = m_pContactsService->OnEndSync(pMethodParams, *ppResults); CHECK_HR(hrStatus, "EndSync method failed"); } else if (IsEqualGUID(MyCustomMethod, Method)) { CComPtr<IPortableDeviceValues> pCustomEventParams; hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pCustomEventParams); CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); if (SUCCEEDED(hr)) { hrStatus = m_pContactsService->OnMyCustomMethod(pMethodParams, pMethodResults, pCustomEventParams); CHECK_HR(hrStatus, "MyCustomMethod method failed"); } if (SUCCEEDED(hr)) { // In addition to a method complete event, we can also send a custom event, // for example, to indicate progress of the method hr = PostWpdEvent(pStartParams, pCustomEventParams); CHECK_HR(hr, "Failed to post custom event"); } } else { hrStatus = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); CHECK_HR(hr, "Unknown method %ws received",CComBSTR(Method)); } } // We always want to post a method completion event // Even if the method has failed { CComPtr<IPortableDeviceValues> pEventParams; hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pEventParams); CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); if (SUCCEEDED(hr)) { hr = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_SERVICE_METHOD_COMPLETE); CHECK_HR(hr, "Failed to set the event id to WPD_EVENT_SERVICE_METHOD_COMPLETE"); } if (SUCCEEDED(hr)) { hr = pEventParams->SetStringValue(WPD_EVENT_PARAMETER_SERVICE_METHOD_CONTEXT, pwszContext); CHECK_HR(hr, "Failed to set the method context for WPD_EVENT_SERVICE_METHOD_COMPLETE"); } if (SUCCEEDED(hr)) { hr = PostWpdEvent(pStartParams, pEventParams); CHECK_HR(hr, "Failed to post WPD_EVENT_SERVICE_METHOD_COMPLETE"); } } if (SUCCEEDED(hr)) { hr = hrStatus; } if (SUCCEEDED(hr)) { *ppResults = pMethodResults.Detach(); } return hr; }
static void test_metadata_tEXt(void) { HRESULT hr; IWICMetadataReader *reader; IWICEnumMetadataItem *enumerator; PROPVARIANT schema, id, value; ULONG items_returned, count; GUID format; PropVariantInit(&schema); PropVariantInit(&id); PropVariantInit(&value); hr = CoCreateInstance(&CLSID_WICPngTextMetadataReader, NULL, CLSCTX_INPROC_SERVER, &IID_IWICMetadataReader, (void**)&reader); todo_wine ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); if (FAILED(hr)) return; hr = IWICMetadataReader_GetCount(reader, NULL); ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr); hr = IWICMetadataReader_GetCount(reader, &count); ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); ok(count == 0, "unexpected count %i\n", count); load_stream((IUnknown*)reader, metadata_tEXt, sizeof(metadata_tEXt)); hr = IWICMetadataReader_GetCount(reader, &count); ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); ok(count == 1, "unexpected count %i\n", count); hr = IWICMetadataReader_GetEnumerator(reader, NULL); ok(hr == E_INVALIDARG, "GetEnumerator failed, hr=%x\n", hr); hr = IWICMetadataReader_GetEnumerator(reader, &enumerator); ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); ok(hr == S_OK, "Next failed, hr=%x\n", hr); ok(items_returned == 1, "unexpected item count %i\n", items_returned); if (hr == S_OK && items_returned == 1) { ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); ok(!strcmp(id.pszVal, "winetest"), "unexpected id: %s\n", id.pszVal); ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); ok(!strcmp(value.pszVal, "value"), "unexpected value: %s\n", id.pszVal); PropVariantClear(&schema); PropVariantClear(&id); PropVariantClear(&value); } hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); ok(hr == S_FALSE, "Next failed, hr=%x\n", hr); ok(items_returned == 0, "unexpected item count %i\n", items_returned); IWICEnumMetadataItem_Release(enumerator); } hr = IWICMetadataReader_GetMetadataFormat(reader, &format); ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", debugstr_guid(&format)); hr = IWICMetadataReader_GetMetadataFormat(reader, NULL); ok(hr == E_INVALIDARG, "GetMetadataFormat failed, hr=%x\n", hr); id.vt = VT_LPSTR; id.pszVal = CoTaskMemAlloc(strlen("winetest") + 1); strcpy(id.pszVal, "winetest"); hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL); ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value); ok(hr == E_INVALIDARG, "GetValue failed, hr=%x\n", hr); hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value); ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); ok(!strcmp(value.pszVal, "value"), "unexpected value: %s\n", id.pszVal); PropVariantClear(&value); strcpy(id.pszVal, "test"); hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value); ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "GetValue failed, hr=%x\n", hr); PropVariantClear(&id); hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL); ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL); ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL); ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); ok(!strcmp(id.pszVal, "winetest"), "unexpected id: %s\n", id.pszVal); PropVariantClear(&id); hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value); ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); ok(!strcmp(value.pszVal, "value"), "unexpected value: %s\n", id.pszVal); PropVariantClear(&value); hr = IWICMetadataReader_GetValueByIndex(reader, 1, NULL, NULL, NULL); ok(hr == E_INVALIDARG, "GetValueByIndex failed, hr=%x\n", hr); IWICMetadataReader_Release(reader); }
static ULONG NTAPI PnpEventThread(IN PVOID Parameter) { NTSTATUS Status; PPLUGPLAY_EVENT_BLOCK PnpEvent, NewPnpEvent; ULONG PnpEventSize; UNREFERENCED_PARAMETER(Parameter); PnpEventSize = 0x1000; PnpEvent = RtlAllocateHeap(ProcessHeap, 0, PnpEventSize); if (PnpEvent == NULL) { Status = STATUS_NO_MEMORY; goto Quit; } for (;;) { DPRINT("Calling NtGetPlugPlayEvent()\n"); /* Wait for the next PnP event */ Status = NtGetPlugPlayEvent(0, 0, PnpEvent, PnpEventSize); /* Resize the buffer for the PnP event if it's too small */ if (Status == STATUS_BUFFER_TOO_SMALL) { PnpEventSize += 0x400; NewPnpEvent = RtlReAllocateHeap(ProcessHeap, 0, PnpEvent, PnpEventSize); if (NewPnpEvent == NULL) { Status = STATUS_NO_MEMORY; goto Quit; } PnpEvent = NewPnpEvent; continue; } if (!NT_SUCCESS(Status)) { DPRINT1("NtGetPlugPlayEvent() failed (Status 0x%08lx)\n", Status); goto Quit; } /* Process the PnP event */ DPRINT("Received PnP Event\n"); if (IsEqualGUID(&PnpEvent->EventGuid, &GUID_DEVICE_ENUMERATED)) { DeviceInstallParams* Params; ULONG len; ULONG DeviceIdLength; DPRINT("Device enumerated event: %S\n", PnpEvent->TargetDevice.DeviceIds); DeviceIdLength = wcslen(PnpEvent->TargetDevice.DeviceIds); if (DeviceIdLength) { /* Queue device install (will be dequeued by DeviceInstallThread) */ len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + (DeviceIdLength + 1) * sizeof(WCHAR); Params = RtlAllocateHeap(ProcessHeap, 0, len); if (Params) { wcscpy(Params->DeviceIds, PnpEvent->TargetDevice.DeviceIds); RtlInterlockedPushEntrySList(&DeviceInstallListHead, &Params->ListEntry); NtSetEvent(hDeviceInstallListNotEmpty, NULL); } else { DPRINT1("Not enough memory (size %lu)\n", len); } } } else { DPRINT("Unknown event, GUID {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n", PnpEvent->EventGuid.Data1, PnpEvent->EventGuid.Data2, PnpEvent->EventGuid.Data3, PnpEvent->EventGuid.Data4[0], PnpEvent->EventGuid.Data4[1], PnpEvent->EventGuid.Data4[2], PnpEvent->EventGuid.Data4[3], PnpEvent->EventGuid.Data4[4], PnpEvent->EventGuid.Data4[5], PnpEvent->EventGuid.Data4[6], PnpEvent->EventGuid.Data4[7]); } /* Dequeue the current PnP event and signal the next one */ NtPlugPlayControl(PlugPlayControlUserResponse, NULL, 0); } Status = STATUS_SUCCESS; Quit: if (PnpEvent) RtlFreeHeap(ProcessHeap, 0, PnpEvent); NtTerminateThread(NtCurrentThread(), Status); return Status; }
HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest) { ULONG DeviceID = ULONG_MAX, Flags; MMRESULT Result; LPFILTERINFO Filter; if (!pGuidSrc || !pGuidDest) { /* invalid param */ return DSERR_INVALIDPARAM; } /* sanity check */ ASSERT(!IsEqualGUID(pGuidSrc, &GUID_NULL)); if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc) || IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)) { Result = waveOutMessage(UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&DeviceID, (DWORD_PTR)&Flags); if (Result != MMSYSERR_NOERROR || DeviceID == ULONG_MAX) { /* hack */ DPRINT1("Failed to get DRVM_MAPPER_PREFERRED_GET, using device 0\n"); DeviceID = 0; } if (!FindDeviceByMappedId(DeviceID, &Filter, TRUE)) { /* device not found */ return DSERR_INVALIDPARAM; } /* copy device guid */ RtlMoveMemory(pGuidDest, &Filter->DeviceGuid[1], sizeof(GUID)); return DS_OK; } else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc) || IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)) { Result = waveInMessage(UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&DeviceID, (DWORD_PTR)&Flags); if (Result != MMSYSERR_NOERROR || DeviceID == ULONG_MAX) { /* hack */ DPRINT1("Failed to get DRVM_MAPPER_PREFERRED_GET, for record using device 0\n"); DeviceID = 0; } if (!FindDeviceByMappedId(DeviceID, &Filter, FALSE)) { /* device not found */ return DSERR_INVALIDPARAM; } /* copy device guid */ RtlMoveMemory(pGuidDest, &Filter->DeviceGuid[0], sizeof(GUID)); return DS_OK; } if (!FindDeviceByGuid(pGuidSrc, &Filter)) { /* unknown guid */ return DSERR_INVALIDPARAM; } /* done */ return DS_OK; }
NTSTATUS Bus_PDO_QueryInterface( IN PPDO_DEVICE_DATA DeviceData, IN PIRP Irp ) /*++ Routine Description: This requests enables a driver to export proprietary interface to other drivers. This function and the following 5 routines are meant to show how a typical interface is exported. Note: This and many other routines in this sample are not required if someone is using this sample for just device enumeration purpose. Arguments: DeviceData - Pointer to the PDO's device extension. Irp - Pointer to the irp. Return Value: NT STATUS --*/ { PIO_STACK_LOCATION irpStack; PTOASTER_INTERFACE_STANDARD toasterInterfaceStandard; GUID *interfaceType; NTSTATUS status = STATUS_SUCCESS; PAGED_CODE(); Bus_KdPrint_Cont (DeviceData, BUS_DBG_PNP_INFO, ("Entered\n")); irpStack = IoGetCurrentIrpStackLocation(Irp); interfaceType = (GUID *) irpStack->Parameters.QueryInterface.InterfaceType; if (IsEqualGUID(interfaceType, (PVOID) &GUID_LANSCSI_INTERFACE_STANDARD)) { if (irpStack->Parameters.QueryInterface.Size < sizeof(TOASTER_INTERFACE_STANDARD) && irpStack->Parameters.QueryInterface.Version != 1) { return STATUS_INVALID_PARAMETER; } toasterInterfaceStandard = (PTOASTER_INTERFACE_STANDARD) irpStack->Parameters.QueryInterface.Interface; toasterInterfaceStandard->Context = DeviceData; // // Fill in the exported functions // toasterInterfaceStandard->InterfaceReference = (PINTERFACE_REFERENCE) Bus_InterfaceReference; toasterInterfaceStandard->InterfaceDereference = (PINTERFACE_DEREFERENCE) Bus_InterfaceDereference; toasterInterfaceStandard->GetCrispinessLevel = Bus_GetCrispinessLevel; toasterInterfaceStandard->SetCrispinessLevel = Bus_SetCrispinessLevel; toasterInterfaceStandard->IsSafetyLockEnabled = Bus_IsSafetyLockEnabled; // // Must take a reference before returning // Bus_InterfaceReference(DeviceData); } else { // // Interface type not supported // status = Irp->IoStatus.Status; } return status; }
/** * It creates a DXVA2 decoder using the given video format */ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t *fmt) { vlc_va_sys_t *sys = va->sys; /* */ msg_Dbg(va, "DxCreateVideoDecoder id %d %dx%d", codec_id, fmt->i_width, fmt->i_height); sys->width = fmt->i_width; sys->height = fmt->i_height; /* Allocates all surfaces needed for the decoder */ sys->surface_width = (fmt->i_width + 15) & ~15; sys->surface_height = (fmt->i_height + 15) & ~15; int surface_count; switch (codec_id) { case AV_CODEC_ID_H264: surface_count = 16 + sys->thread_count + 2; break; case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: surface_count = 2 + 2; break; default: surface_count = 2 + 1; break; } if (surface_count > VA_DXVA2_MAX_SURFACE_COUNT) return VLC_EGENERIC; sys->surface_count = surface_count; if (FAILED(IDirectXVideoDecoderService_CreateSurface(sys->vs, sys->surface_width, sys->surface_height, sys->surface_count - 1, sys->render, D3DPOOL_DEFAULT, 0, DXVA2_VideoDecoderRenderTarget, sys->hw_surface, NULL))) { msg_Err(va, "IDirectXVideoAccelerationService_CreateSurface failed"); sys->surface_count = 0; return VLC_EGENERIC; } for (unsigned i = 0; i < sys->surface_count; i++) { vlc_va_surface_t *surface = &sys->surface[i]; surface->d3d = sys->hw_surface[i]; surface->refcount = 0; surface->order = 0; } msg_Dbg(va, "IDirectXVideoAccelerationService_CreateSurface succeed with %d surfaces (%dx%d)", sys->surface_count, fmt->i_width, fmt->i_height); /* */ DXVA2_VideoDesc dsc; ZeroMemory(&dsc, sizeof(dsc)); dsc.SampleWidth = fmt->i_width; dsc.SampleHeight = fmt->i_height; dsc.Format = sys->render; if (fmt->i_frame_rate > 0 && fmt->i_frame_rate_base > 0) { dsc.InputSampleFreq.Numerator = fmt->i_frame_rate; dsc.InputSampleFreq.Denominator = fmt->i_frame_rate_base; } else { dsc.InputSampleFreq.Numerator = 0; dsc.InputSampleFreq.Denominator = 0; } dsc.OutputFrameFreq = dsc.InputSampleFreq; dsc.UABProtectionLevel = FALSE; dsc.Reserved = 0; /* FIXME I am unsure we can let unknown everywhere */ DXVA2_ExtendedFormat *ext = &dsc.SampleFormat; ext->SampleFormat = 0;//DXVA2_SampleUnknown; ext->VideoChromaSubsampling = 0;//DXVA2_VideoChromaSubsampling_Unknown; ext->NominalRange = 0;//DXVA2_NominalRange_Unknown; ext->VideoTransferMatrix = 0;//DXVA2_VideoTransferMatrix_Unknown; ext->VideoLighting = 0;//DXVA2_VideoLighting_Unknown; ext->VideoPrimaries = 0;//DXVA2_VideoPrimaries_Unknown; ext->VideoTransferFunction = 0;//DXVA2_VideoTransFunc_Unknown; /* List all configurations available for the decoder */ UINT cfg_count = 0; DXVA2_ConfigPictureDecode *cfg_list = NULL; if (FAILED(IDirectXVideoDecoderService_GetDecoderConfigurations(sys->vs, &sys->input, &dsc, NULL, &cfg_count, &cfg_list))) { msg_Err(va, "IDirectXVideoDecoderService_GetDecoderConfigurations failed"); return VLC_EGENERIC; } msg_Dbg(va, "we got %d decoder configurations", cfg_count); /* Select the best decoder configuration */ int cfg_score = 0; for (unsigned i = 0; i < cfg_count; i++) { const DXVA2_ConfigPictureDecode *cfg = &cfg_list[i]; /* */ msg_Dbg(va, "configuration[%d] ConfigBitstreamRaw %d", i, cfg->ConfigBitstreamRaw); /* */ int score; if (cfg->ConfigBitstreamRaw == 1) score = 1; else if (codec_id == AV_CODEC_ID_H264 && cfg->ConfigBitstreamRaw == 2) score = 2; else continue; if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA_NoEncrypt)) score += 16; if (cfg_score < score) { sys->cfg = *cfg; cfg_score = score; } } CoTaskMemFree(cfg_list); if (cfg_score <= 0) { msg_Err(va, "Failed to find a supported decoder configuration"); return VLC_EGENERIC; } /* Create the decoder */ IDirectXVideoDecoder *decoder; if (FAILED(IDirectXVideoDecoderService_CreateVideoDecoder(sys->vs, &sys->input, &dsc, &sys->cfg, sys->hw_surface, sys->surface_count, &decoder))) { msg_Err(va, "IDirectXVideoDecoderService_CreateVideoDecoder failed"); return VLC_EGENERIC; } sys->decoder = decoder; msg_Dbg(va, "IDirectXVideoDecoderService_CreateVideoDecoder succeed"); return VLC_SUCCESS; }
bool Video::GetFrame(CString fileName, CDIB *dib, double delta) { IMediaDet *mediaDet; HRESULT hRes; hRes = CoInitialize(NULL); if(FAILED(hRes)) { return false; } hRes = CoCreateInstance(CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER, IID_IMediaDet, (void**)&mediaDet); if(FAILED(hRes)) { CoUninitialize(); return false; } hRes = mediaDet->put_Filename(fileName.GetBuffer()); if(FAILED(hRes)) { mediaDet->Release(); CoUninitialize(); return false; } AM_MEDIA_TYPE mediaType; hRes = mediaDet->get_StreamMediaType(&mediaType); if(FAILED(hRes)) { mediaDet->Release(); CoUninitialize(); return false; } if(!IsEqualGUID(mediaType.majortype, MEDIATYPE_Video)) { mediaDet->Release(); CoUninitialize(); return false; } if(!IsEqualGUID(mediaType.formattype, FORMAT_VideoInfo)) { mediaDet->Release(); CoUninitialize(); return false; } double position; hRes = mediaDet->get_StreamLength(&position); if(FAILED(hRes)) { mediaDet->Release(); CoUninitialize(); return false; } position *= delta; BITMAPINFOHEADER *bmpInfo = &((VIDEOINFOHEADER*)mediaType.pbFormat)->bmiHeader; long size; hRes = mediaDet->GetBitmapBits(position, &size, NULL, bmpInfo->biWidth, bmpInfo->biHeight); if(FAILED(hRes)) { mediaDet->Release(); CoUninitialize(); return false; } void *buf = malloc(size); hRes = mediaDet->GetBitmapBits(position, &size, (char*)buf, bmpInfo->biWidth, bmpInfo->biHeight); if(FAILED(hRes)) { free(buf); mediaDet->Release(); CoUninitialize(); return false; } dib->Resize(bmpInfo->biWidth, bmpInfo->biHeight); DIB_AARGB *pd = (DIB_AARGB*)dib->scan0; RGBTRIPLE *ps = (RGBTRIPLE*)buf; ps = &ps[(bmpInfo->biHeight - 1) * bmpInfo->biWidth]; for(int y = 0; y < bmpInfo->biHeight; y++) { for(int x = 0; x < bmpInfo->biWidth; x++) { pd[x]->a = 255; pd[x]->r = ps[x].rgbtBlue; pd[x]->g = ps[x].rgbtRed; pd[x]->b = ps[x].rgbtGreen; } pd = &pd[bmpInfo->biWidth]; ps = &ps[-bmpInfo->biWidth]; } free(buf); mediaDet->Release(); CoUninitialize(); return true; }
// ========================================================================= // Hash function NTSTATUS ImpHashHashData( IN GUID* HashGUID, IN unsigned int DataLength, // In bits IN FREEOTFEBYTE* Data, IN OUT unsigned int* HashLength, // In bits OUT FREEOTFEBYTE* Hash ) { NTSTATUS status = STATUS_SUCCESS; hash_state md; WCHAR* tmpGUIDStr; DEBUGOUTHASHIMPL(DEBUGLEV_ENTER, (TEXT("ImpHashHashData\n"))); if (IsEqualGUID(&HASH_GUID_SHA512, HashGUID)) { if (*HashLength < (sha512_desc.hashsize * 8)) { DEBUGOUTHASHIMPL(DEBUGLEV_ERROR, (TEXT("output hash length buffer too small (got: %d; need: %d)\n"), *HashLength, (sha512_desc.hashsize * 8) )); status = STATUS_BUFFER_TOO_SMALL; } else { sha512_desc.init(&md); sha512_desc.process(&md, Data, (DataLength / 8)); sha512_desc.done(&md, Hash); *HashLength = (sha512_desc.hashsize * 8); } } else if (IsEqualGUID(&HASH_GUID_SHA384, HashGUID)) { if (*HashLength < (sha384_desc.hashsize * 8)) { DEBUGOUTHASHIMPL(DEBUGLEV_ERROR, (TEXT("output hash length buffer too small (got: %d; need: %d)\n"), *HashLength, (sha384_desc.hashsize * 8) )); status = STATUS_BUFFER_TOO_SMALL; } else { sha384_desc.init(&md); sha384_desc.process(&md, Data, (DataLength / 8)); sha384_desc.done(&md, Hash); *HashLength = (sha384_desc.hashsize * 8); } } else if (IsEqualGUID(&HASH_GUID_SHA256, HashGUID)) { if (*HashLength < (sha256_desc.hashsize * 8)) { DEBUGOUTHASHIMPL(DEBUGLEV_ERROR, (TEXT("output hash length buffer too small (got: %d; need: %d)\n"), *HashLength, (sha256_desc.hashsize * 8) )); status = STATUS_BUFFER_TOO_SMALL; } else { sha256_desc.init(&md); sha256_desc.process(&md, Data, (DataLength / 8)); sha256_desc.done(&md, Hash); *HashLength = (sha256_desc.hashsize * 8); } } else if (IsEqualGUID(&HASH_GUID_SHA224, HashGUID)) { if (*HashLength < (sha224_desc.hashsize * 8)) { DEBUGOUTHASHIMPL(DEBUGLEV_ERROR, (TEXT("output hash length buffer too small (got: %d; need: %d)\n"), *HashLength, (sha224_desc.hashsize * 8) )); status = STATUS_BUFFER_TOO_SMALL; } else { sha224_desc.init(&md); sha224_desc.process(&md, Data, (DataLength / 8)); sha224_desc.done(&md, Hash); *HashLength = (sha224_desc.hashsize * 8); } } else if (IsEqualGUID(&HASH_GUID_SHA1, HashGUID)) { if (*HashLength < (sha1_desc.hashsize * 8)) { DEBUGOUTHASHIMPL(DEBUGLEV_ERROR, (TEXT("output hash length buffer too small (got: %d; need: %d)\n"), *HashLength, (sha1_desc.hashsize * 8) )); status = STATUS_BUFFER_TOO_SMALL; } else { sha1_desc.init(&md); sha1_desc.process(&md, Data, (DataLength / 8)); sha1_desc.done(&md, Hash); *HashLength = (sha1_desc.hashsize * 8); } } else { DEBUGOUTHASHIMPL(DEBUGLEV_ERROR, (TEXT("Driver doesn't recognise GUID\n"))); GUIDToWCHAR(HashGUID, &tmpGUIDStr); DEBUGOUTHASHIMPL(DEBUGLEV_INFO, (TEXT("Hash passed in: %ls\n"), tmpGUIDStr)); SecZeroAndFreeWCHARMemory(tmpGUIDStr); status = STATUS_INVALID_PARAMETER; } DEBUGOUTHASHIMPL(DEBUGLEV_EXIT, (TEXT("ImpHashHashData\n"))); return status; }
HRESULT HrFindInstance (INetCfg *pnc, GUID &guidInstance, INetCfgComponent **ppnccMiniport) { IEnumNetCfgComponent *pencc; INetCfgComponent *pncc; GUID guid; WCHAR szGuid[MAX_PATH+1]; ULONG ulCount; BOOL found; HRESULT hr; TraceMsg( L"-->HrFindInstance.\n" ); hr = pnc->EnumComponents( &GUID_DEVCLASS_NET, &pencc ); if ( hr == S_OK ) { StringFromGUID2( guidInstance, szGuid, MAX_PATH+1 ); TraceMsg( L" Looking for component with InstanceGuid %s\n", szGuid ); hr = pencc->Next( 1, &pncc, &ulCount ); for ( found=FALSE; (hr == S_OK) && (found == FALSE); ) { hr = pncc->GetInstanceGuid( &guid ); if ( hr == S_OK ) { StringFromGUID2( guid, szGuid, MAX_PATH+1 ); TraceMsg( L" Found component with InstanceGuid %s\n", szGuid ); found = IsEqualGUID( guid, guidInstance ); if ( found == FALSE ) { ReleaseObj( pncc ); hr = pencc->Next( 1, &pncc, &ulCount ); } else { *ppnccMiniport = pncc; } } } ReleaseObj( pencc ); } else { TraceMsg( L" EnumComponents failed(HRESULT = %x).\n", hr ); } TraceMsg( L"<--HrFindInstance(HRESULT = %x).\n", hr ); return hr; }
static HRESULT WINAPI PHClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv) { PluginHost *This = impl_from_IOleClientSite(iface); if(IsEqualGUID(&IID_IUnknown, riid)) { TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv); *ppv = &This->IOleClientSite_iface; }else if(IsEqualGUID(&IID_IOleClientSite, riid)) { TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv); *ppv = &This->IOleClientSite_iface; }else if(IsEqualGUID(&IID_IAdviseSink, riid)) { TRACE("(%p)->(IID_IAdviseSink %p)\n", This, ppv); *ppv = &This->IAdviseSinkEx_iface; }else if(IsEqualGUID(&IID_IAdviseSinkEx, riid)) { TRACE("(%p)->(IID_IAdviseSinkEx %p)\n", This, ppv); *ppv = &This->IAdviseSinkEx_iface; }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) { TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv); *ppv = &This->IPropertyNotifySink_iface; }else if(IsEqualGUID(&IID_IDispatch, riid)) { TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv); *ppv = &This->IDispatch_iface; }else if(IsEqualGUID(&IID_IOleWindow, riid)) { TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv); *ppv = &This->IOleInPlaceSiteEx_iface; }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) { TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv); *ppv = &This->IOleInPlaceSiteEx_iface; }else if(IsEqualGUID(&IID_IOleInPlaceSiteEx, riid)) { TRACE("(%p)->(IID_IOleInPlaceSiteEx %p)\n", This, ppv); *ppv = &This->IOleInPlaceSiteEx_iface; }else if(IsEqualGUID(&IID_IOleControlSite, riid)) { TRACE("(%p)->(IID_IOleControlSite %p)\n", This, ppv); *ppv = &This->IOleControlSite_iface; }else if(IsEqualGUID(&IID_IBindHost, riid)) { TRACE("(%p)->(IID_IBindHost %p)\n", This, ppv); *ppv = &This->IBindHost_iface; }else if(IsEqualGUID(&IID_IServiceProvider, riid)) { TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv); *ppv = &This->IServiceProvider_iface; }else { WARN("Unsupported interface %s\n", debugstr_guid(riid)); *ppv = NULL; return E_NOINTERFACE; } IUnknown_AddRef((IUnknown*)*ppv); return S_OK; }
//HRESULT LoopbackCapture( // IMMDevice *pMMDevice, // bool bInt16, // HANDLE hStartedEvent, // HANDLE hStopEvent, // PUINT32 pnFrames, // HMMIO hFile, // AudioBuffer *pBuffer //) HRESULT LoopbackCapture::Process() { HRESULT hr; // activate an IAudioClient IAudioClient *pAudioClient; hr = pMMDevice->Activate( __uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pAudioClient ); if (FAILED(hr)) { printf("IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr); return hr; } // get the default device periodicity REFERENCE_TIME hnsDefaultDevicePeriod; hr = pAudioClient->GetDevicePeriod(&hnsDefaultDevicePeriod, NULL); if (FAILED(hr)) { printf("IAudioClient::GetDevicePeriod failed: hr = 0x%08x\n", hr); pAudioClient->Release(); return hr; } // get the default device format WAVEFORMATEX *pwfx; hr = pAudioClient->GetMixFormat(&pwfx); if (FAILED(hr)) { printf("IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr); CoTaskMemFree(pwfx); pAudioClient->Release(); return hr; } if (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx); //pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; printf("WAVE_FORMAT_EXTENSIBLE\n"); if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) { printf("float\n"); }// else if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_PCM, pEx->SubFormat)) { printf("PCM\n"); }//KSDATAFORMAT_SUBTYPE_WAVEFORMATEX else if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_WAVEFORMATEX, pEx->SubFormat)) { printf("WAVEFORMATEX\n"); } } if (bInt16) { // coerce int-16 wave format // can do this in-place since we're not changing the size of the format // also, the engine will auto-convert from float to int for us switch (pwfx->wFormatTag) { case WAVE_FORMAT_IEEE_FLOAT: pwfx->wFormatTag = WAVE_FORMAT_PCM; pwfx->wBitsPerSample = 16; pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8; pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec; break; case WAVE_FORMAT_EXTENSIBLE: { // naked scope for case-local variable PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx); if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) { pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; pEx->Samples.wValidBitsPerSample = 16; pwfx->wBitsPerSample = 16; pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8; pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec; } else { printf("Don't know how to coerce mix format to int-16\n"); CoTaskMemFree(pwfx); pAudioClient->Release(); return E_UNEXPECTED; } } break; default: printf("Don't know how to coerce WAVEFORMATEX with wFormatTag = 0x%08x to int-16\n", pwfx->wFormatTag); CoTaskMemFree(pwfx); pAudioClient->Release(); return E_UNEXPECTED; } } MMCKINFO ckRIFF = {0}; MMCKINFO ckData = {0}; if (hFile!=NULL) hr = WriteWaveHeader(hFile, pwfx, &ckRIFF, &ckData); if (pBuffer) { bool isFloat = false; switch (pwfx->wFormatTag) { case WAVE_FORMAT_IEEE_FLOAT: isFloat = true; break; case WAVE_FORMAT_EXTENSIBLE: { // naked scope for case-local variable PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx); if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) { isFloat = true; } } break; default: break; } pBuffer->SetAudioInfo(pwfx->nSamplesPerSec,pwfx->nBlockAlign,pwfx->nChannels,pwfx->wBitsPerSample,isFloat); } if (FAILED(hr)) { // WriteWaveHeader does its own logging CoTaskMemFree(pwfx); pAudioClient->Release(); return hr; } // create a periodic waitable timer HANDLE hWakeUp = CreateWaitableTimer(NULL, FALSE, NULL); if (NULL == hWakeUp) { DWORD dwErr = GetLastError(); printf("CreateWaitableTimer failed: last error = %u\n", dwErr); CoTaskMemFree(pwfx); pAudioClient->Release(); return HRESULT_FROM_WIN32(dwErr); } UINT32 nBlockAlign = pwfx->nBlockAlign; UINT32 nChannels = pwfx->nChannels; nFrames = 0; // call IAudioClient::Initialize // note that AUDCLNT_STREAMFLAGS_LOOPBACK and AUDCLNT_STREAMFLAGS_EVENTCALLBACK // do not work together... // the "data ready" event never gets set // so we're going to do a timer-driven loop hr = pAudioClient->Initialize( AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_LOOPBACK, 0, 0, pwfx, 0 ); if (FAILED(hr)) { printf("IAudioClient::Initialize failed: hr = 0x%08x\n", hr); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } CoTaskMemFree(pwfx); // activate an IAudioCaptureClient IAudioCaptureClient *pAudioCaptureClient; hr = pAudioClient->GetService( __uuidof(IAudioCaptureClient), (void**)&pAudioCaptureClient ); if (FAILED(hr)) { printf("IAudioClient::GetService(IAudioCaptureClient) failed: hr 0x%08x\n", hr); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } // register with MMCSS DWORD nTaskIndex = 0; HANDLE hTask = AvSetMmThreadCharacteristics(L"Capture", &nTaskIndex); if (NULL == hTask) { DWORD dwErr = GetLastError(); printf("AvSetMmThreadCharacteristics failed: last error = %u\n", dwErr); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return HRESULT_FROM_WIN32(dwErr); } // set the waitable timer LARGE_INTEGER liFirstFire; liFirstFire.QuadPart = -hnsDefaultDevicePeriod / 2; // negative means relative time LONG lTimeBetweenFires = (LONG)hnsDefaultDevicePeriod / 2 / (10 * 1000); // convert to milliseconds BOOL bOK = SetWaitableTimer( hWakeUp, &liFirstFire, lTimeBetweenFires, NULL, NULL, FALSE ); if (!bOK) { DWORD dwErr = GetLastError(); printf("SetWaitableTimer failed: last error = %u\n", dwErr); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return HRESULT_FROM_WIN32(dwErr); } // call IAudioClient::Start hr = pAudioClient->Start(); if (FAILED(hr)) { printf("IAudioClient::Start failed: hr = 0x%08x\n", hr); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } SetEvent(hStartedEvent); // loopback capture loop HANDLE waitArray[2] = { hStopEvent, hWakeUp }; DWORD dwWaitResult; DWORD immdState; bool bDone = false; bool bFirstPacket = true; for (UINT32 nPasses = 0; !bDone; nPasses++) { dwWaitResult = WaitForMultipleObjects( ARRAYSIZE(waitArray), waitArray, FALSE, INFINITE ); if (WAIT_OBJECT_0 == dwWaitResult) { //printf("Received stop event after %u passes and %u frames\n", nPasses, nFrames); bDone = true; continue; // exits loop } if (WAIT_OBJECT_0 + 1 != dwWaitResult) { printf("Unexpected WaitForMultipleObjects return value %u on pass %u after %u frames\n", dwWaitResult, nPasses, nFrames); pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return E_UNEXPECTED; } printf("'"); // got a "wake up" event - see if there's data UINT32 nNextPacketSize; hr = pAudioCaptureClient->GetNextPacketSize(&nNextPacketSize); if (FAILED(hr)) { if (hr == AUDCLNT_E_SERVICE_NOT_RUNNING) printf("AUDCLNT_E_SERVICE_NOT_RUNNING : \n"); else if (hr == AUDCLNT_E_DEVICE_INVALIDATED) printf("AUDCLNT_E_DEVICE_INVALIDATED : \n"); else printf("UNKNOWN ERROR!!! : \n"); printf("IAudioCaptureClient::GetNextPacketSize failed on pass %u after %u frames: hr = 0x%08x\n", nPasses, nFrames, hr); pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } if (0 == nNextPacketSize) { // no data yet continue; } // get the captured data BYTE *pData; UINT32 nNumFramesToRead; DWORD dwFlags; hr = pAudioCaptureClient->GetBuffer( &pData, &nNumFramesToRead, &dwFlags, NULL, NULL ); if (FAILED(hr)) { printf("IAudioCaptureClient::GetBuffer failed on pass %u after %u frames: hr = 0x%08x\n", nPasses, nFrames, hr); pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } if (bFirstPacket && AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY == dwFlags) { printf("Probably spurious glitch reported on first packet\n"); } else if (dwFlags & AUDCLNT_BUFFERFLAGS_SILENT) { printf("#"); } else if (dwFlags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) { printf("!"); } else if (0 != dwFlags) { printf("IAudioCaptureClient::GetBuffer set flags to 0x%08x on pass %u after %u frames\n", dwFlags, nPasses, nFrames); pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return E_UNEXPECTED; } if (0 == nNumFramesToRead) { // no data yet continue; } //if (0 == nNumFramesToRead) { // printf("IAudioCaptureClient::GetBuffer said to read 0 frames on pass %u after %u frames\n", nPasses, nFrames); // pAudioClient->Stop(); // CancelWaitableTimer(hWakeUp); // AvRevertMmThreadCharacteristics(hTask); // pAudioCaptureClient->Release(); // CloseHandle(hWakeUp); // pAudioClient->Release(); // return E_UNEXPECTED; //} LONG lBytesToWrite = nNumFramesToRead * nBlockAlign; #pragma prefast(suppress: __WARNING_INCORRECT_ANNOTATION, "IAudioCaptureClient::GetBuffer SAL annotation implies a 1-byte buffer") if (hFile!=NULL) { LONG lBytesWritten = mmioWrite(hFile, reinterpret_cast<PCHAR>(pData), lBytesToWrite); if (lBytesToWrite != lBytesWritten) { printf("mmioWrite wrote %u bytes on pass %u after %u frames: expected %u bytes\n", lBytesWritten, nPasses, nFrames, lBytesToWrite); pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return E_UNEXPECTED; } } if (pBuffer) { //switch (nBlockAlign/nChannels) //{ //case 1: // ShowPCM((unsigned char*)pData,nNumFramesToRead,nChannels,1024,60,"SYS_Byte"); // break; //case 2: // ShowPCM((short*)pData,nNumFramesToRead,nChannels,1024,60,"SYS_Short"); // break; //case 4: // ShowPCM((int*)pData,nNumFramesToRead,nChannels,1024,60,"SYS_Int"); // //ShowPCM((float*)pData,nNumFramesToRead,nChannels,1024,60,"SYS_float"); // break; //} pBuffer->PushBuffer(pData,lBytesToWrite); } nFrames += nNumFramesToRead; hr = pAudioCaptureClient->ReleaseBuffer(nNumFramesToRead); if (FAILED(hr)) { printf("IAudioCaptureClient::ReleaseBuffer failed on pass %u after %u frames: hr = 0x%08x\n", nPasses, nFrames, hr); pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } bFirstPacket = false; } // capture loop if (hFile!=NULL) hr = FinishWaveFile(hFile, &ckData, &ckRIFF); if (FAILED(hr)) { // FinishWaveFile does it's own logging pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; } pAudioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); pAudioCaptureClient->Release(); CloseHandle(hWakeUp); pAudioClient->Release(); return hr; }
static void test_wmp(void) { IProvideClassInfo2 *class_info; IOleClientSite *client_site; IOleInPlaceObject *ipobj; IPersistStreamInit *psi; IOleObject *oleobj; IWMPCore *wmpcore; DWORD misc_status; RECT pos = {0,0,100,100}; HWND hwnd; GUID guid; LONG ref; HRESULT hres; BSTR str; hres = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IOleObject, (void**)&oleobj); if(hres == REGDB_E_CLASSNOTREG) { win_skip("CLSID_WindowsMediaPlayer not registered\n"); return; } ok(hres == S_OK, "Could not create CLSID_WindowsMediaPlayer instance: %08x\n", hres); hres = IOleObject_QueryInterface(oleobj, &IID_IWMPCore, (void**)&wmpcore); ok(hres == S_OK, "got 0x%08x\n", hres); hres = IWMPCore_get_versionInfo(wmpcore, NULL); ok(hres == E_POINTER, "got 0x%08x\n", hres); hres = IWMPCore_get_versionInfo(wmpcore, &str); ok(hres == S_OK, "got 0x%08x\n", hres); SysFreeString(str); IWMPCore_Release(wmpcore); hres = IOleObject_QueryInterface(oleobj, &IID_IProvideClassInfo2, (void**)&class_info); ok(hres == S_OK, "Could not get IProvideClassInfo2 iface: %08x\n", hres); hres = IProvideClassInfo2_GetGUID(class_info, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &guid); ok(hres == S_OK, "GetGUID failed: %08x\n", hres); ok(IsEqualGUID(&guid, &IID__WMPOCXEvents), "guid = %s\n", wine_dbgstr_guid(&guid)); IProvideClassInfo2_Release(class_info); test_QI((IUnknown*)oleobj); hres = IOleObject_GetMiscStatus(oleobj, DVASPECT_CONTENT, &misc_status); ok(hres == S_OK, "GetMiscStatus failed: %08x\n", hres); ok(misc_status == (OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE), "misc_status = %x\n", misc_status); hres = IOleObject_QueryInterface(oleobj, &IID_IPersistStreamInit, (void**)&psi); ok(hres == S_OK, "Could not get IPersistStreamInit iface: %08x\n", hres); hres = IOleObject_QueryInterface(oleobj, &IID_IOleInPlaceObject, (void**)&ipobj); ok(hres == S_OK, "Could not get IOleInPlaceObject iface: %08x\n", hres); hres = IPersistStreamInit_InitNew(psi); ok(hres == E_FAIL || broken(hres == S_OK /* Old WMP */), "InitNew failed: %08x\n", hres); SET_EXPECT(GetContainer); SET_EXPECT(GetExtendedControl); SET_EXPECT(GetWindow); SET_EXPECT(Invoke_USERMODE); hres = IOleObject_SetClientSite(oleobj, &ClientSite); ok(hres == S_OK, "SetClientSite failed: %08x\n", hres); todo_wine CHECK_CALLED(GetContainer); CHECK_CALLED(GetExtendedControl); todo_wine CHECK_CALLED(GetWindow); todo_wine CHECK_CALLED(Invoke_USERMODE); client_site = NULL; hres = IOleObject_GetClientSite(oleobj, &client_site); ok(hres == S_OK, "GetClientSite failed: %08x\n", hres); ok(client_site == &ClientSite, "client_site != ClientSite\n"); SET_EXPECT(GetWindow); hres = IPersistStreamInit_InitNew(psi); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(GetWindow); hwnd = (HWND)0xdeadbeef; hres = IOleInPlaceObject_GetWindow(ipobj, &hwnd); ok(hres == E_UNEXPECTED, "GetWindow failed: %08x\n", hres); ok(!hwnd, "hwnd = %p\n", hwnd); SET_EXPECT(GetWindow); SET_EXPECT(CanWindowlessActivate); SET_EXPECT(OnInPlaceActivateEx); SET_EXPECT(GetWindowContext); SET_EXPECT(ShowObject); hres = IOleObject_DoVerb(oleobj, OLEIVERB_INPLACEACTIVATE, NULL, &ClientSite, 0, container_hwnd, &pos); ok(hres == S_OK, "DoVerb failed: %08x\n", hres); CHECK_CALLED(GetWindow); CHECK_CALLED(CanWindowlessActivate); CHECK_CALLED(OnInPlaceActivateEx); CHECK_CALLED(GetWindowContext); CHECK_CALLED(ShowObject); hwnd = NULL; hres = IOleInPlaceObject_GetWindow(ipobj, &hwnd); ok(hres == S_OK, "GetWindow failed: %08x\n", hres); ok(hwnd != NULL, "hwnd = NULL\n"); test_window(hwnd); SetRect(&pos, 1, 2, 301, 312); hres = IOleInPlaceObject_SetObjectRects(ipobj, &pos, &pos); ok(hres == S_OK, "SetObjectRects failed: %08x\n", hres); GetClientRect(hwnd, &pos); test_rect_size(&pos, 300, 310); test_wmp_ifaces(oleobj); hres = IOleObject_DoVerb(oleobj, OLEIVERB_HIDE, NULL, &ClientSite, 0, container_hwnd, &pos); ok(hres == S_OK, "DoVerb failed: %08x\n", hres); ok(!IsWindowVisible(hwnd), "Window is visible\n"); SET_EXPECT(OnShowWindow_FALSE); SET_EXPECT(OnInPlaceDeactivate); hres = IOleObject_Close(oleobj, 0); ok(hres == S_OK, "Close failed: %08x\n", hres); todo_wine CHECK_CALLED(OnShowWindow_FALSE); CHECK_CALLED(OnInPlaceDeactivate); hwnd = (HWND)0xdeadbeef; hres = IOleInPlaceObject_GetWindow(ipobj, &hwnd); ok(hres == E_UNEXPECTED, "GetWindow failed: %08x\n", hres); ok(!hwnd, "hwnd = %p\n", hwnd); hres = IOleObject_Close(oleobj, 0); ok(hres == S_OK, "Close failed: %08x\n", hres); hres = IOleObject_SetClientSite(oleobj, NULL); ok(hres == S_OK, "SetClientSite failed: %08x\n", hres); client_site = (void*)0xdeadbeef; hres = IOleObject_GetClientSite(oleobj, &client_site); ok(hres == E_FAIL || broken(hres == S_OK), "GetClientSite failed: %08x\n", hres); ok(!client_site, "client_site = %p\n", client_site); IPersistStreamInit_Release(psi); IOleInPlaceObject_Release(ipobj); ref = IOleObject_Release(oleobj); ok(!ref, "ref = %d\n", ref); }
static void test_save_settings(void) { HRESULT hr; HINSTANCE hinst = GetModuleHandleA(NULL); IDirectInput8A *pDI = NULL; DIACTIONFORMATA af; IDirectInputDevice8A *pKey; static const GUID mapping_guid = { 0xcafecafe, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } }; static const GUID other_guid = { 0xcafe, 0xcafe, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } }; static DIACTIONA actions[] = { { 0, DIKEYBOARD_A , 0, { "Blam" } }, { 1, DIKEYBOARD_B , 0, { "Kapow"} } }; static const DWORD results[] = { DIDFT_MAKEINSTANCE(DIK_A) | DIDFT_PSHBUTTON, DIDFT_MAKEINSTANCE(DIK_B) | DIDFT_PSHBUTTON }; static const DWORD other_results[] = { DIDFT_MAKEINSTANCE(DIK_C) | DIDFT_PSHBUTTON, DIDFT_MAKEINSTANCE(DIK_D) | DIDFT_PSHBUTTON }; hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI); if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION || hr == REGDB_E_CLASSNOTREG) { win_skip("ActionMapping requires dinput8\n"); return; } ok (SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr); if (FAILED(hr)) return; hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION); if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION) { win_skip("ActionMapping requires dinput8\n"); return; } ok (SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr); if (FAILED(hr)) return; hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL); ok (SUCCEEDED(hr), "IDirectInput_Create device failed hr: 0x%08x\n", hr); if (FAILED(hr)) return; memset (&af, 0, sizeof(af)); af.dwSize = sizeof(af); af.dwActionSize = sizeof(DIACTIONA); af.dwDataSize = 4 * sizeof(actions) / sizeof(actions[0]); af.dwNumActions = sizeof(actions) / sizeof(actions[0]); af.rgoAction = actions; af.guidActionMap = mapping_guid; af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */ af.dwBufferSize = 32; /* Easy case. Ask for default mapping, save, ask for previous map and read it back */ hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, DIDBAM_HWDEFAULTS); ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr); ok (results[0] == af.rgoAction[0].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID); ok (results[1] == af.rgoAction[1].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID); hr = IDirectInputDevice8_SetActionMap(pKey, &af, NULL, DIDSAM_FORCESAVE); ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr); if (hr == DI_SETTINGSNOTSAVED) { skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n"); return; } af.rgoAction[0].dwObjID = 0; af.rgoAction[1].dwObjID = 0; memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID)); memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID)); hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0); ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr); ok (results[0] == af.rgoAction[0].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID); ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n"); ok (results[1] == af.rgoAction[1].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID); ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n"); /* Test that a different action map with no pre-stored settings, in spite of the flags, does not try to load mappings and instead applies the default mapping */ af.guidActionMap = other_guid; af.rgoAction[0].dwObjID = 0; af.rgoAction[1].dwObjID = 0; memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID)); memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID)); hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0); ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr); ok (results[0] == af.rgoAction[0].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID); ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n"); ok (results[1] == af.rgoAction[1].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID); ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n"); af.guidActionMap = mapping_guid; /* Hard case. Customized mapping, save, ask for previous map and read it back */ af.rgoAction[0].dwObjID = other_results[0]; af.rgoAction[0].dwHow = DIAH_USERCONFIG; af.rgoAction[0].guidInstance = GUID_SysKeyboard; af.rgoAction[1].dwObjID = other_results[1]; af.rgoAction[1].dwHow = DIAH_USERCONFIG; af.rgoAction[1].guidInstance = GUID_SysKeyboard; hr = IDirectInputDevice8_SetActionMap(pKey, &af, NULL, DIDSAM_FORCESAVE); ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr); if (hr == DI_SETTINGSNOTSAVED) { skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n"); return; } af.rgoAction[0].dwObjID = 0; af.rgoAction[1].dwObjID = 0; memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID)); memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID)); hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0); ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr); ok (other_results[0] == af.rgoAction[0].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[0], af.rgoAction[0].dwObjID); ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n"); ok (other_results[1] == af.rgoAction[1].dwObjID, "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[1], af.rgoAction[1].dwObjID); ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n"); }
static HRESULT DirectSoundCaptureDevice_Initialize( DirectSoundCaptureDevice ** ppDevice, LPCGUID lpcGUID) { HRESULT hr; GUID devGUID; IMMDevice *mmdevice; struct _TestFormat *fmt; DirectSoundCaptureDevice *device; IAudioClient *client; TRACE("(%p, %s)\n", ppDevice, debugstr_guid(lpcGUID)); /* Default device? */ if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) ) lpcGUID = &DSDEVID_DefaultCapture; if(IsEqualGUID(lpcGUID, &DSDEVID_DefaultPlayback) || IsEqualGUID(lpcGUID, &DSDEVID_DefaultVoicePlayback)) return DSERR_NODRIVER; if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) { WARN("invalid parameter: lpcGUID\n"); return DSERR_INVALIDPARAM; } hr = get_mmdevice(eCapture, &devGUID, &mmdevice); if(FAILED(hr)) return hr; EnterCriticalSection(&DSOUND_capturers_lock); hr = DirectSoundCaptureDevice_Create(&device); if (hr != DS_OK) { WARN("DirectSoundCaptureDevice_Create failed\n"); LeaveCriticalSection(&DSOUND_capturers_lock); return hr; } device->guid = devGUID; device->mmdevice = mmdevice; device->drvcaps.dwFlags = 0; device->drvcaps.dwFormats = 0; device->drvcaps.dwChannels = 0; hr = IMMDevice_Activate(mmdevice, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&client); if(FAILED(hr)){ device->lock.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&device->lock); HeapFree(GetProcessHeap(), 0, device); LeaveCriticalSection(&DSOUND_capturers_lock); return DSERR_NODRIVER; } for(fmt = formats_to_test; fmt->flag; ++fmt){ if(DSOUND_check_supported(client, fmt->rate, fmt->depth, fmt->channels)){ device->drvcaps.dwFormats |= fmt->flag; if(fmt->channels > device->drvcaps.dwChannels) device->drvcaps.dwChannels = fmt->channels; } } IAudioClient_Release(client); device->timerID = DSOUND_create_timer(DSOUND_capture_timer, (DWORD_PTR)device); list_add_tail(&DSOUND_capturers, &device->entry); *ppDevice = device; LeaveCriticalSection(&DSOUND_capturers_lock); return S_OK; }
static void test_color_formats(void) { static const struct { char bit_depth, color_type; const GUID *format; const GUID *format_PLTE; const GUID *format_PLTE_tRNS; BOOL todo; BOOL todo_load; } td[] = { /* 2 - PNG_COLOR_TYPE_RGB */ { 1, 2, NULL, NULL, NULL }, { 2, 2, NULL, NULL, NULL }, { 4, 2, NULL, NULL, NULL }, { 8, 2, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppBGR }, /* libpng refuses to load our test image complaining about extra compressed data, * but libpng is still able to load the image with other combination of type/depth * making RGB 16 bpp case special for some reason. Therefore todo = TRUE. */ { 16, 2, &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat48bppRGB, TRUE, TRUE }, { 24, 2, NULL, NULL, NULL }, { 32, 2, NULL, NULL, NULL }, /* 0 - PNG_COLOR_TYPE_GRAY */ { 1, 0, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat1bppIndexed, TRUE }, { 2, 0, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppIndexed, TRUE }, { 4, 0, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppIndexed, TRUE }, { 8, 0, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppIndexed, TRUE }, { 16, 0, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat64bppRGBA, TRUE }, { 24, 0, NULL, NULL, NULL }, { 32, 0, NULL, NULL, NULL }, /* 3 - PNG_COLOR_TYPE_PALETTE */ { 1, 3, &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed }, { 2, 3, &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed }, { 4, 3, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed }, { 8, 3, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed }, { 16, 3, NULL, NULL, NULL }, { 24, 3, NULL, NULL, NULL }, { 32, 3, NULL, NULL, NULL }, }; char buf[sizeof(png_1x1_data)]; HRESULT hr; IWICBitmapDecoder *decoder; IWICBitmapFrameDecode *frame; GUID format; int i, PLTE_off = 0, tRNS_off = 0; memcpy(buf, png_1x1_data, sizeof(png_1x1_data)); for (i = 0; i < sizeof(png_1x1_data) - 4; i++) { if (!memcmp(buf + i, "tRNS", 4)) tRNS_off = i; else if (!memcmp(buf + i, "PLTE", 4)) PLTE_off = i; } ok(PLTE_off && tRNS_off, "PLTE offset %d, tRNS offset %d\n", PLTE_off, tRNS_off); if (!PLTE_off || !tRNS_off) return; /* In order to test the image data with and without PLTE and tRNS chunks * it's been decided to simply sero out the chunk id for testing puposes, * and under Windows such images get loaded just fine. But unfortunately * libpng refuses to load such images complaining about unknown chunk type. * A workaround for this libpng limitation is to mark the "disabled" chunks * with tEXt id. */ for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) { /* with the tRNS and PLTE chunks */ memcpy(buf, png_1x1_data, sizeof(png_1x1_data)); buf[24] = td[i].bit_depth; buf[25] = td[i].color_type; hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE)) ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr); if (hr != S_OK) goto next_1; hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); ok(hr == S_OK, "GetFrame error %#x\n", hr); hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format); ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); todo_wine_if(td[i].todo) ok(IsEqualGUID(&format, td[i].format_PLTE_tRNS), "PLTE+tRNS: expected %s, got %s (type %d, bpp %d)\n", wine_dbgstr_guid(td[i].format_PLTE_tRNS), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth); IWICBitmapFrameDecode_Release(frame); IWICBitmapDecoder_Release(decoder); next_1: /* without the tRNS chunk */ memcpy(buf, png_1x1_data, sizeof(png_1x1_data)); buf[24] = td[i].bit_depth; buf[25] = td[i].color_type; memcpy(buf + tRNS_off, "tEXt", 4); hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE)) ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr); if (hr != S_OK) goto next_2; hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); ok(hr == S_OK, "GetFrame error %#x\n", hr); hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format); ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); ok(IsEqualGUID(&format, td[i].format_PLTE), "PLTE: expected %s, got %s (type %d, bpp %d)\n", wine_dbgstr_guid(td[i].format_PLTE), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth); IWICBitmapFrameDecode_Release(frame); IWICBitmapDecoder_Release(decoder); next_2: /* without the tRNS and PLTE chunks */ memcpy(buf, png_1x1_data, sizeof(png_1x1_data)); buf[24] = td[i].bit_depth; buf[25] = td[i].color_type; memcpy(buf + PLTE_off, "tEXt", 4); memcpy(buf + tRNS_off, "tEXt", 4); hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE)) ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr); if (hr != S_OK) goto next_3; hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); ok(hr == S_OK, "GetFrame error %#x\n", hr); hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format); ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); ok(IsEqualGUID(&format, td[i].format), "expected %s, got %s (type %d, bpp %d)\n", wine_dbgstr_guid(td[i].format), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth); IWICBitmapFrameDecode_Release(frame); IWICBitmapDecoder_Release(decoder); next_3: /* without the PLTE chunk */ memcpy(buf, png_1x1_data, sizeof(png_1x1_data)); buf[24] = td[i].bit_depth; buf[25] = td[i].color_type; memcpy(buf + PLTE_off, "tEXt", 4); hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE)) ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr); if (hr != S_OK) continue; hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); ok(hr == S_OK, "GetFrame error %#x\n", hr); hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format); ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); todo_wine_if(td[i].todo) ok(IsEqualGUID(&format, td[i].format_PLTE_tRNS), "tRNS: expected %s, got %s (type %d, bpp %d)\n", wine_dbgstr_guid(td[i].format_PLTE_tRNS), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth); IWICBitmapFrameDecode_Release(frame); IWICBitmapDecoder_Release(decoder); } }
static HRESULT DoReset(ALCdevice *device) { MMDevApiData *data = device->ExtraData; WAVEFORMATEXTENSIBLE OutputType; WAVEFORMATEX *wfx = NULL; REFERENCE_TIME min_per, buf_time; UINT32 buffer_len, min_len; HRESULT hr; hr = IAudioClient_GetMixFormat(data->client, &wfx); if(FAILED(hr)) { ERR("Failed to get mix format: 0x%08lx\n", hr); return hr; } if(!MakeExtensible(&OutputType, wfx)) { CoTaskMemFree(wfx); return E_FAIL; } CoTaskMemFree(wfx); wfx = NULL; buf_time = ((REFERENCE_TIME)device->UpdateSize*device->NumUpdates*10000000 + device->Frequency-1) / device->Frequency; if(!(device->Flags&DEVICE_FREQUENCY_REQUEST)) device->Frequency = OutputType.Format.nSamplesPerSec; if(!(device->Flags&DEVICE_CHANNELS_REQUEST)) { if(OutputType.Format.nChannels == 1 && OutputType.dwChannelMask == MONO) device->FmtChans = DevFmtMono; else if(OutputType.Format.nChannels == 2 && OutputType.dwChannelMask == STEREO) device->FmtChans = DevFmtStereo; else if(OutputType.Format.nChannels == 4 && OutputType.dwChannelMask == QUAD) device->FmtChans = DevFmtQuad; else if(OutputType.Format.nChannels == 6 && OutputType.dwChannelMask == X5DOT1) device->FmtChans = DevFmtX51; else if(OutputType.Format.nChannels == 6 && OutputType.dwChannelMask == X5DOT1SIDE) device->FmtChans = DevFmtX51Side; else if(OutputType.Format.nChannels == 7 && OutputType.dwChannelMask == X6DOT1) device->FmtChans = DevFmtX61; else if(OutputType.Format.nChannels == 8 && OutputType.dwChannelMask == X7DOT1) device->FmtChans = DevFmtX71; else ERR("Unhandled channel config: %d -- 0x%08lx\n", OutputType.Format.nChannels, OutputType.dwChannelMask); } switch(device->FmtChans) { case DevFmtMono: OutputType.Format.nChannels = 1; OutputType.dwChannelMask = MONO; break; case DevFmtStereo: OutputType.Format.nChannels = 2; OutputType.dwChannelMask = STEREO; break; case DevFmtQuad: OutputType.Format.nChannels = 4; OutputType.dwChannelMask = QUAD; break; case DevFmtX51: OutputType.Format.nChannels = 6; OutputType.dwChannelMask = X5DOT1; break; case DevFmtX51Side: OutputType.Format.nChannels = 6; OutputType.dwChannelMask = X5DOT1SIDE; break; case DevFmtX61: OutputType.Format.nChannels = 7; OutputType.dwChannelMask = X6DOT1; break; case DevFmtX71: OutputType.Format.nChannels = 8; OutputType.dwChannelMask = X7DOT1; break; } switch(device->FmtType) { case DevFmtByte: device->FmtType = DevFmtUByte; /* fall-through */ case DevFmtUByte: OutputType.Format.wBitsPerSample = 8; OutputType.Samples.wValidBitsPerSample = 8; OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; break; case DevFmtUShort: device->FmtType = DevFmtShort; /* fall-through */ case DevFmtShort: OutputType.Format.wBitsPerSample = 16; OutputType.Samples.wValidBitsPerSample = 16; OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; break; case DevFmtUInt: device->FmtType = DevFmtInt; /* fall-through */ case DevFmtInt: OutputType.Format.wBitsPerSample = 32; OutputType.Samples.wValidBitsPerSample = 32; OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; break; case DevFmtFloat: OutputType.Format.wBitsPerSample = 32; OutputType.Samples.wValidBitsPerSample = 32; OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; break; } OutputType.Format.nSamplesPerSec = device->Frequency; OutputType.Format.nBlockAlign = OutputType.Format.nChannels * OutputType.Format.wBitsPerSample / 8; OutputType.Format.nAvgBytesPerSec = OutputType.Format.nSamplesPerSec * OutputType.Format.nBlockAlign; hr = IAudioClient_IsFormatSupported(data->client, AUDCLNT_SHAREMODE_SHARED, &OutputType.Format, &wfx); if(FAILED(hr)) { ERR("Failed to check format support: 0x%08lx\n", hr); hr = IAudioClient_GetMixFormat(data->client, &wfx); } if(FAILED(hr)) { ERR("Failed to find a supported format: 0x%08lx\n", hr); return hr; } if(wfx != NULL) { if(!MakeExtensible(&OutputType, wfx)) { CoTaskMemFree(wfx); return E_FAIL; } CoTaskMemFree(wfx); wfx = NULL; device->Frequency = OutputType.Format.nSamplesPerSec; if(OutputType.Format.nChannels == 1 && OutputType.dwChannelMask == MONO) device->FmtChans = DevFmtMono; else if(OutputType.Format.nChannels == 2 && OutputType.dwChannelMask == STEREO) device->FmtChans = DevFmtStereo; else if(OutputType.Format.nChannels == 4 && OutputType.dwChannelMask == QUAD) device->FmtChans = DevFmtQuad; else if(OutputType.Format.nChannels == 6 && OutputType.dwChannelMask == X5DOT1) device->FmtChans = DevFmtX51; else if(OutputType.Format.nChannels == 6 && OutputType.dwChannelMask == X5DOT1SIDE) device->FmtChans = DevFmtX51Side; else if(OutputType.Format.nChannels == 7 && OutputType.dwChannelMask == X6DOT1) device->FmtChans = DevFmtX61; else if(OutputType.Format.nChannels == 8 && OutputType.dwChannelMask == X7DOT1) device->FmtChans = DevFmtX71; else { ERR("Unhandled extensible channels: %d -- 0x%08lx\n", OutputType.Format.nChannels, OutputType.dwChannelMask); device->FmtChans = DevFmtStereo; OutputType.Format.nChannels = 2; OutputType.dwChannelMask = STEREO; } if(IsEqualGUID(&OutputType.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) { if(OutputType.Format.wBitsPerSample == 8) device->FmtType = DevFmtUByte; else if(OutputType.Format.wBitsPerSample == 16) device->FmtType = DevFmtShort; else if(OutputType.Format.wBitsPerSample == 32) device->FmtType = DevFmtInt; else { device->FmtType = DevFmtShort; OutputType.Format.wBitsPerSample = 16; } } else if(IsEqualGUID(&OutputType.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) { device->FmtType = DevFmtFloat; OutputType.Format.wBitsPerSample = 32; } else { ERR("Unhandled format sub-type\n"); device->FmtType = DevFmtShort; OutputType.Format.wBitsPerSample = 16; OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; } OutputType.Samples.wValidBitsPerSample = OutputType.Format.wBitsPerSample; } SetDefaultWFXChannelOrder(device); hr = IAudioClient_Initialize(data->client, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, buf_time, 0, &OutputType.Format, NULL); if(FAILED(hr)) { ERR("Failed to initialize audio client: 0x%08lx\n", hr); return hr; } hr = IAudioClient_GetDevicePeriod(data->client, &min_per, NULL); if(SUCCEEDED(hr)) { min_len = (UINT32)((min_per*device->Frequency + 10000000-1) / 10000000); /* Find the nearest multiple of the period size to the update size */ if(min_len < device->UpdateSize) min_len *= (device->UpdateSize + min_len/2)/min_len; hr = IAudioClient_GetBufferSize(data->client, &buffer_len); } if(FAILED(hr)) { ERR("Failed to get audio buffer info: 0x%08lx\n", hr); return hr; } device->UpdateSize = min_len; device->NumUpdates = buffer_len / device->UpdateSize; if(device->NumUpdates <= 1) { ERR("Audio client returned buffer_len < period*2; expect break up\n"); device->NumUpdates = 2; device->UpdateSize = buffer_len / device->NumUpdates; } return hr; }
HRESULT CGuidItemExtractIcon_CreateInstance(LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut) { CComPtr<IDefaultExtractIconInit> initIcon; HRESULT hr; GUID const * riid; int icon_idx; WCHAR wTemp[MAX_PATH]; hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit,&initIcon)); if (FAILED(hr)) return hr; if (_ILIsDesktop(pidl)) { initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DESKTOP); return initIcon->QueryInterface(iid, ppvOut); } riid = _ILGetGUIDPointer(pidl); if (!riid) return E_FAIL; /* my computer and other shell extensions */ static const WCHAR fmt[] = { 'C', 'L', 'S', 'I', 'D', '\\', '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0 }; WCHAR xriid[50]; swprintf(xriid, fmt, riid->Data1, riid->Data2, riid->Data3, riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]); const WCHAR* iconname = NULL; if (_ILIsBitBucket(pidl)) { static const WCHAR szFull[] = {'F','u','l','l',0}; static const WCHAR szEmpty[] = {'E','m','p','t','y',0}; CComPtr<IEnumIDList> EnumIDList; CoInitialize(NULL); CComPtr<IShellFolder2> psfRecycleBin; CComPtr<IShellFolder> psfDesktop; hr = SHGetDesktopFolder(&psfDesktop); if (SUCCEEDED(hr)) hr = psfDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder2, &psfRecycleBin)); if (SUCCEEDED(hr)) hr = psfRecycleBin->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &EnumIDList); ULONG itemcount; LPITEMIDLIST pidl = NULL; if (SUCCEEDED(hr) && (hr = EnumIDList->Next(1, &pidl, &itemcount)) == S_OK) { CoTaskMemFree(pidl); iconname = szFull; } else { iconname = szEmpty; } } if (HCR_GetIconW(xriid, wTemp, iconname, MAX_PATH, &icon_idx)) { initIcon->SetNormalIcon(wTemp, icon_idx); } else { if (IsEqualGUID(*riid, CLSID_MyComputer)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_COMPUTER); else if (IsEqualGUID(*riid, CLSID_MyDocuments)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_DOCUMENTS); else if (IsEqualGUID(*riid, CLSID_NetworkPlaces)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_NETWORK_PLACES); else initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_FOLDER); } return initIcon->QueryInterface(iid, ppvOut); }
/** * Find the best suited decoder mode GUID and render format. */ static int DxFindVideoServiceConversion(vlc_va_t *va, GUID *input, D3DFORMAT *output) { vlc_va_sys_t *sys = va->sys; /* Retreive supported modes from the decoder service */ UINT input_count = 0; GUID *input_list = NULL; if (FAILED(IDirectXVideoDecoderService_GetDecoderDeviceGuids(sys->vs, &input_count, &input_list))) { msg_Err(va, "IDirectXVideoDecoderService_GetDecoderDeviceGuids failed"); return VLC_EGENERIC; } for (unsigned i = 0; i < input_count; i++) { const GUID *g = &input_list[i]; const dxva2_mode_t *mode = Dxva2FindMode(g); if (mode) { msg_Dbg(va, "- '%s' is supported by hardware", mode->name); } else { msg_Warn(va, "- Unknown GUID = " GUID_FMT, GUID_PRINT( *g ) ); } } /* Try all supported mode by our priority */ for (unsigned i = 0; dxva2_modes[i].name; i++) { const dxva2_mode_t *mode = &dxva2_modes[i]; if (!mode->codec || mode->codec != sys->codec_id) continue; /* */ bool is_supported = false; for (const GUID *g = &input_list[0]; !is_supported && g < &input_list[input_count]; g++) { is_supported = IsEqualGUID(mode->guid, g); } if (!is_supported) continue; /* */ msg_Dbg(va, "Trying to use '%s' as input", mode->name); UINT output_count = 0; D3DFORMAT *output_list = NULL; if (FAILED(IDirectXVideoDecoderService_GetDecoderRenderTargets(sys->vs, mode->guid, &output_count, &output_list))) { msg_Err(va, "IDirectXVideoDecoderService_GetDecoderRenderTargets failed"); continue; } for (unsigned j = 0; j < output_count; j++) { const D3DFORMAT f = output_list[j]; const d3d_format_t *format = D3dFindFormat(f); if (format) { msg_Dbg(va, "%s is supported for output", format->name); } else { msg_Dbg(va, "%d is supported for output (%4.4s)", f, (const char*)&f); } } /* */ for (unsigned j = 0; d3d_formats[j].name; j++) { const d3d_format_t *format = &d3d_formats[j]; /* */ bool is_supported = false; for (unsigned k = 0; !is_supported && k < output_count; k++) { is_supported = format->format == output_list[k]; } if (!is_supported) continue; /* We have our solution */ msg_Dbg(va, "Using '%s' to decode to '%s'", mode->name, format->name); *input = *mode->guid; *output = format->format; CoTaskMemFree(output_list); CoTaskMemFree(input_list); return VLC_SUCCESS; } CoTaskMemFree(output_list); } CoTaskMemFree(input_list); return VLC_EGENERIC; }
static DPQ_DECL_COMPARECB( cbUglyPig, GUID ) { return IsEqualGUID( elem1, elem2 ); }
HRESULT CAudioRawFileRenderer::IsUsingTimeFormat(const struct _GUID *fmt) { if (IsEqualGUID(*fmt,m_TimeFormat)) return(S_OK); return(S_FALSE); }
bool SkImageEncoder_WIC::onEncode(SkWStream* stream , const SkBitmap& bitmapOrig , int quality) { GUID type; switch (fType) { case kBMP_Type: type = GUID_ContainerFormatBmp; break; case kICO_Type: type = GUID_ContainerFormatIco; break; case kJPEG_Type: type = GUID_ContainerFormatJpeg; break; case kPNG_Type: type = GUID_ContainerFormatPng; break; default: return false; } //Convert to 8888 if needed. const SkBitmap* bitmap; SkBitmap bitmapCopy; if (kN32_SkColorType == bitmapOrig.colorType() && bitmapOrig.isOpaque()) { bitmap = &bitmapOrig; } else { if (!bitmapOrig.copyTo(&bitmapCopy, kN32_SkColorType)) { return false; } bitmap = &bitmapCopy; } // We cannot use PBGRA so we need to unpremultiply ourselves if (!bitmap->isOpaque()) { SkAutoLockPixels alp(*bitmap); uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap->getPixels()); for (int y = 0; y < bitmap->height(); ++y) { for (int x = 0; x < bitmap->width(); ++x) { uint8_t* bytes = pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel(); SkPMColor* src = reinterpret_cast<SkPMColor*>(bytes); SkColor* dst = reinterpret_cast<SkColor*>(bytes); *dst = SkUnPreMultiply::PMColorToColor(*src); } } } //Initialize COM. SkAutoCoInitialize scopedCo; if (!scopedCo.succeeded()) { return false; } HRESULT hr = S_OK; //Create Windows Imaging Component ImagingFactory. SkTScopedComPtr<IWICImagingFactory> piImagingFactory; if (SUCCEEDED(hr)) { hr = CoCreateInstance( CLSID_WICImagingFactory , nullptr , CLSCTX_INPROC_SERVER , IID_PPV_ARGS(&piImagingFactory) ); } //Convert the SkWStream to an IStream. SkTScopedComPtr<IStream> piStream; if (SUCCEEDED(hr)) { hr = SkWIStream::CreateFromSkWStream(stream, &piStream); } //Create an encode of the appropriate type. SkTScopedComPtr<IWICBitmapEncoder> piEncoder; if (SUCCEEDED(hr)) { hr = piImagingFactory->CreateEncoder(type, nullptr, &piEncoder); } if (SUCCEEDED(hr)) { hr = piEncoder->Initialize(piStream.get(), WICBitmapEncoderNoCache); } //Create a the frame. SkTScopedComPtr<IWICBitmapFrameEncode> piBitmapFrameEncode; SkTScopedComPtr<IPropertyBag2> piPropertybag; if (SUCCEEDED(hr)) { hr = piEncoder->CreateNewFrame(&piBitmapFrameEncode, &piPropertybag); } if (SUCCEEDED(hr)) { PROPBAG2 name = { 0 }; name.dwType = PROPBAG2_TYPE_DATA; name.vt = VT_R4; name.pstrName = L"ImageQuality"; VARIANT value; VariantInit(&value); value.vt = VT_R4; value.fltVal = (FLOAT)(quality / 100.0); //Ignore result code. // This returns E_FAIL if the named property is not in the bag. //TODO(bungeman) enumerate the properties, // write and set hr iff property exists. piPropertybag->Write(1, &name, &value); } if (SUCCEEDED(hr)) { hr = piBitmapFrameEncode->Initialize(piPropertybag.get()); } //Set the size of the frame. const UINT width = bitmap->width(); const UINT height = bitmap->height(); if (SUCCEEDED(hr)) { hr = piBitmapFrameEncode->SetSize(width, height); } //Set the pixel format of the frame. If native encoded format cannot match BGRA, //it will choose the closest pixel format that it supports. const WICPixelFormatGUID formatDesired = GUID_WICPixelFormat32bppBGRA; WICPixelFormatGUID formatGUID = formatDesired; if (SUCCEEDED(hr)) { hr = piBitmapFrameEncode->SetPixelFormat(&formatGUID); } if (SUCCEEDED(hr)) { //Be sure the image format is the one requested. hr = IsEqualGUID(formatGUID, formatDesired) ? S_OK : E_FAIL; } //Write the pixels into the frame. if (SUCCEEDED(hr)) { SkAutoLockPixels alp(*bitmap); const UINT stride = (UINT) bitmap->rowBytes(); hr = piBitmapFrameEncode->WritePixels( height , stride , stride * height , reinterpret_cast<BYTE*>(bitmap->getPixels())); } if (SUCCEEDED(hr)) { hr = piBitmapFrameEncode->Commit(); } if (SUCCEEDED(hr)) { hr = piEncoder->Commit(); } return SUCCEEDED(hr); }
NTSTATUS WmipEnableDisableTrace( IN ULONG Ioctl, IN PWMITRACEENABLEDISABLEINFO TraceEnableInfo ) /*++ Routine Description: This routine will enable or disable a tracelog guid Arguments: Ioctl is the IOCTL used to call this routine from UM TraceEnableInfo has all the info needed to enable or disable Return Value: --*/ { NTSTATUS Status; LPGUID Guid; PBGUIDENTRY GuidEntry; BOOLEAN RequestSent; BOOLEAN IsEnable; ULONG64 LoggerContext; PAGED_CODE(); Guid = &TraceEnableInfo->Guid; Status = WmipCheckGuidAccess(Guid, TRACELOG_GUID_ENABLE, EtwpDefaultTraceSecurityDescriptor); if (NT_SUCCESS(Status)) { // // The following code is serialized for Trace Guids. Only one // control application can be enabling or disabling Trace Guids at a time. // Must be taken before SMCritSection is taken. Otherwise deadlocks will result. // WmipEnterTLCritSection(); IsEnable = TraceEnableInfo->Enable; // // Check for Heap and Crit Sec Tracing Guid. // if( IsEqualGUID(&HeapGuid,Guid)) { if(IsEnable){ SharedUserData->TraceLogging |= ENABLEHEAPTRACE; // // increment counter. The counter // is composed of first two bytes // SharedUserData->TraceLogging += 0x00010000; } else { SharedUserData->TraceLogging &= DISABLEHEAPTRACE; } WmipLeaveTLCritSection(); return STATUS_SUCCESS; } else if(IsEqualGUID(&CritSecGuid,Guid)){ if(IsEnable) { SharedUserData->TraceLogging |= ENABLECRITSECTRACE; // // increment counter. The counter // is composed of first two bytes // SharedUserData->TraceLogging += 0x00010000; } else { SharedUserData->TraceLogging &= DISABLECRITSECTRACE; } WmipLeaveTLCritSection(); return STATUS_SUCCESS; } else if(IsEqualGUID(&NtdllTraceGuid,Guid)){ if(!IsEnable){ SharedUserData->TraceLogging &= DISABLENTDLLTRACE; } } LoggerContext = TraceEnableInfo->LoggerContext; WmipEnterSMCritSection(); GuidEntry = WmipFindGEByGuid(Guid, FALSE); if (GuidEntry == NULL ) { // // The guid is not yet registered // if (IsEnable ) { // // If the NtdllTraceGuid is not in list then we do not want to enable it // the NtdllTraceGuid will make an entry only to call starttrace // if(IsEqualGUID(&NtdllTraceGuid,Guid)){ Status = STATUS_ILLEGAL_FUNCTION; } else { // // If we are enabling a guid that is not yet registered // we need to create the guid object for it // GuidEntry = WmipAllocGuidEntry(); if (GuidEntry != NULL) { // // Initialize the guid entry and keep the ref count // from creation. When tracelog enables we take a ref // count and when it disables we release it // GuidEntry->Guid = *Guid; GuidEntry->Flags |= GE_NOTIFICATION_TRACE_FLAG; GuidEntry->LoggerContext = LoggerContext; GuidEntry->EventRefCount = 1; InsertHeadList(WmipGEHeadPtr, &GuidEntry->MainGEList); Status = STATUS_SUCCESS; } else { Status = STATUS_INSUFFICIENT_RESOURCES; } } } } else { // // The control guid is already registered so lets go and // enabled or disable it // if (WmipIsControlGuid(GuidEntry)) { if (IsEnable) { GuidEntry->LoggerContext = LoggerContext; if (GuidEntry->Flags & GE_NOTIFICATION_TRACE_FLAG) { // // We are trying to enable a trace guid that is already // registered // GuidEntry->Flags |= GE_NOTIFICATION_TRACE_UPDATE; Status = WmipEnableCollectOrEvent(GuidEntry, Ioctl, &RequestSent, LoggerContext); } else { GuidEntry->Flags |= GE_NOTIFICATION_TRACE_FLAG; WmipReferenceGE(GuidEntry); Status = WmipEnableCollectOrEvent(GuidEntry, Ioctl, &RequestSent, LoggerContext); if (!NT_SUCCESS(Status) && (GuidEntry->Flags & GE_NOTIFICATION_TRACE_FLAG)) { // // We failed to enable the trace event, and our // flag is still set. Remove the flag and deref // the guid entry. // // When we call WmipEnableCollectOrEvent above, // we actually drop the SM lock for a little bit. // That means it's possible for a disable call to // come through at the same time, which would // remove the flag and deref the guid entry itself. // GuidEntry->Flags &= ~GE_NOTIFICATION_TRACE_FLAG; WmipUnreferenceGE(GuidEntry); } } } else { if (GuidEntry->Flags & GE_NOTIFICATION_TRACE_FLAG) { // // Send the disable collection call and then remove // the refcount that was taken when we enabled // GuidEntry->Flags &= ~GE_NOTIFICATION_TRACE_FLAG; Status = WmipDisableCollectOrEvent(GuidEntry, Ioctl, LoggerContext); // // Whether the Disable request succeeds or not // we will remove the extra refcount since we // reset the NOTIFICATION_FLAG // GuidEntry->LoggerContext = 0; WmipUnreferenceGE(GuidEntry); } else { Status = STATUS_WMI_ALREADY_DISABLED; } } } else if ( IsListEmpty(&GuidEntry->ISHead) && (! IsEnable) ) { // // If this GUID is not a control GUID, check to see if // there are no instance sets for this GUID. If so, // it is getting disabled before any instances // registered it. Disable the GUID and clean up the GE. // if (GuidEntry->Flags & GE_NOTIFICATION_TRACE_FLAG) { GuidEntry->Flags &= ~GE_NOTIFICATION_TRACE_FLAG; GuidEntry->LoggerContext = 0; WmipUnreferenceGE(GuidEntry); } Status = STATUS_SUCCESS; } else if(!IsEqualGUID(&NtdllTraceGuid,Guid)){ Status = STATUS_ILLEGAL_FUNCTION; } WmipUnreferenceGE(GuidEntry); } WmipLeaveSMCritSection(); WmipLeaveTLCritSection(); } return(Status); }
HRESULT enum_services_providers(const GUID * const service, DPN_SERVICE_PROVIDER_INFO * const info_buffer, DWORD * const buf_size, DWORD * const returned) { static const WCHAR serviceproviders[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\', 'D','i','r','e','c','t','P','l','a','y','8','\\', 'S','e','r','v','i','c','e',' ','P','r','o','v','i','d','e','r','s',0}; static const WCHAR friendly[] = {'F','r','i','e','n','d','l','y',' ','N','a','m','e',0}; static const WCHAR dp_adapterW[] = {'L','o','c','a','l',' ','A','r','e','a',' ','C','o','n','n','e','c','t','i','o','n', ' ','-',' ','I','P','v','4',0}; static const GUID adapter_guid = {0x4ce725f6, 0xd3c0, 0xdade, {0xba, 0x6f, 0x11, 0xf9, 0x65, 0xbc, 0x42, 0x99}}; DWORD req_size = 0; LONG res; HKEY key = NULL; LONG next_key; DWORD index = 0; WCHAR provider[MAX_PATH]; DWORD size; if(!returned || !buf_size) return E_POINTER; if(!service) { *returned = 0; res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, serviceproviders, 0, KEY_READ, &key); if(res == ERROR_FILE_NOT_FOUND) return DPNERR_DOESNOTEXIST; next_key = RegEnumKeyW( key, index, provider, MAX_PATH); while(next_key == ERROR_SUCCESS) { res = RegGetValueW(key, provider, friendly, RRF_RT_REG_SZ, NULL, NULL, &size); if(res == ERROR_SUCCESS) { req_size += sizeof(DPN_SERVICE_PROVIDER_INFO) + size; (*returned)++; } index++; next_key = RegEnumKeyW( key, index, provider, MAX_PATH ); } } else if(IsEqualGUID(service, &CLSID_DP8SP_TCPIP)) { req_size = sizeof(DPN_SERVICE_PROVIDER_INFO) + sizeof(dp_adapterW); } else { FIXME("Application requested a provider we don't handle (yet)\n"); return DPNERR_DOESNOTEXIST; } if(*buf_size < req_size) { RegCloseKey(key); *buf_size = req_size; return DPNERR_BUFFERTOOSMALL; } if(!service) { int offset = 0; int count = 0; char *infoend = ((char *)info_buffer + (sizeof(DPN_SERVICE_PROVIDER_INFO) * (*returned))); index = 0; next_key = RegEnumKeyW( key, index, provider, MAX_PATH); while(next_key == ERROR_SUCCESS) { res = RegGetValueW(key, provider, friendly, RRF_RT_REG_SZ, NULL, NULL, &size); if(res == ERROR_SUCCESS) { info_buffer[count].guid = CLSID_DP8SP_TCPIP; info_buffer[count].pwszName = (LPWSTR)(infoend + offset); RegGetValueW(key, provider, friendly, RRF_RT_REG_SZ, NULL, info_buffer[count].pwszName, &size); offset += size; count++; } index++; next_key = RegEnumKeyW(key, index, provider, MAX_PATH); } } else { info_buffer->pwszName = (LPWSTR)(info_buffer + 1); lstrcpyW(info_buffer->pwszName, dp_adapterW); info_buffer->guid = adapter_guid; *returned = 1; } RegCloseKey(key); return DPN_OK; }
static void test_lsa(void) { NTSTATUS status; LSA_HANDLE handle; LSA_OBJECT_ATTRIBUTES object_attributes; ZeroMemory(&object_attributes, sizeof(object_attributes)); object_attributes.Length = sizeof(object_attributes); status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle); ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED, "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status); /* try a more restricted access mask if necessary */ if (status == STATUS_ACCESS_DENIED) { trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n"); status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_VIEW_LOCAL_INFORMATION, &handle); ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08x\n", status); } if (status == STATUS_SUCCESS) { PPOLICY_AUDIT_EVENTS_INFO audit_events_info; PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info; PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info; PPOLICY_DNS_DOMAIN_INFO dns_domain_info; status = pLsaQueryInformationPolicy(handle, PolicyAuditEventsInformation, (PVOID*)&audit_events_info); if (status == STATUS_ACCESS_DENIED) skip("Not enough rights to retrieve PolicyAuditEventsInformation\n"); else ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { pLsaFreeMemory((LPVOID)audit_events_info); } status = pLsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (PVOID*)&primary_domain_info); ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { if (primary_domain_info->Sid) { LPSTR strsid; if (pConvertSidToStringSidA(primary_domain_info->Sid, &strsid)) { if (primary_domain_info->Name.Buffer) { LPSTR name = NULL; UINT len; len = WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL ); name = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, name, len, NULL, NULL ); trace(" name: %s sid: %s\n", name, strsid); LocalFree( name ); } else trace(" name: NULL sid: %s\n", strsid); LocalFree( strsid ); } else trace("invalid sid\n"); } else trace("Running on a standalone system.\n"); pLsaFreeMemory((LPVOID)primary_domain_info); } status = pLsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (PVOID*)&account_domain_info); ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { pLsaFreeMemory((LPVOID)account_domain_info); } /* This isn't supported in NT4 */ status = pLsaQueryInformationPolicy(handle, PolicyDnsDomainInformation, (PVOID*)&dns_domain_info); ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER, "LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { if (dns_domain_info->Sid || !IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL)) { LPSTR strsid = NULL; LPSTR name = NULL; LPSTR domain = NULL; LPSTR forest = NULL; LPSTR guidstr = NULL; WCHAR guidstrW[64]; UINT len; guidstrW[0] = '\0'; pConvertSidToStringSidA(dns_domain_info->Sid, &strsid); StringFromGUID2(&dns_domain_info->DomainGuid, guidstrW, sizeof(guidstrW)/sizeof(WCHAR)); len = WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, NULL, 0, NULL, NULL ); guidstr = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, guidstr, len, NULL, NULL ); if (dns_domain_info->Name.Buffer) { len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL ); name = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL ); } if (dns_domain_info->DnsDomainName.Buffer) { len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL ); domain = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL ); } if (dns_domain_info->DnsForestName.Buffer) { len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL ); forest = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL ); } trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n", name ? name : "NULL", domain ? domain : "NULL", forest ? forest : "NULL", guidstr, strsid ? strsid : "NULL"); LocalFree( name ); LocalFree( forest ); LocalFree( domain ); LocalFree( guidstr ); LocalFree( strsid ); } else trace("Running on a standalone system.\n"); pLsaFreeMemory((LPVOID)dns_domain_info); } status = pLsaClose(handle); ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status); } }
void LoopbackCaptureFor(IMMDevice* mmDevice, std::string filename, int secs) { // open new file MMIOINFO mi = { 0 }; // some flags cause mmioOpen write to this buffer // but not any that we're using std::wstring wsFilename(filename.begin(), filename.end()); // mmioOpen wants a wstring HMMIO file = mmioOpen(const_cast<LPWSTR>(wsFilename.c_str()), &mi, MMIO_WRITE | MMIO_CREATE); time_t startTime = time(nullptr); // activate an IAudioClient IAudioClient* audioClient; HRESULT hr = mmDevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, (void**)&audioClient); if (FAILED(hr)) { fprintf(stderr, "IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr); return; } // get the default device periodicity REFERENCE_TIME hnsDefaultDevicePeriod; hr = audioClient->GetDevicePeriod(&hnsDefaultDevicePeriod, nullptr); if (FAILED(hr)) { fprintf(stderr, "IAudioClient::GetDevicePeriod failed: hr = 0x%08x\n", hr); audioClient->Release(); return; } // get the default device format WAVEFORMATEX* waveform; hr = audioClient->GetMixFormat(&waveform); if (FAILED(hr)) { fprintf(stderr, "IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr); CoTaskMemFree(waveform); audioClient->Release(); return; } // coerce int-16 wave format // can do this in-place since we're not changing the size of the format // also, the engine will auto-convert from float to int for us switch (waveform->wFormatTag) { case WAVE_FORMAT_IEEE_FLOAT: waveform->wFormatTag = WAVE_FORMAT_PCM; waveform->wBitsPerSample = BITS_PER_SAMPLE; waveform->nBlockAlign = BLOCK_ALIGN; waveform->nAvgBytesPerSec = BYTE_RATE; break; case WAVE_FORMAT_EXTENSIBLE: { // naked scope for case-local variable PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(waveform); if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) { pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; pEx->Samples.wValidBitsPerSample = BITS_PER_SAMPLE; waveform->wBitsPerSample = BITS_PER_SAMPLE; waveform->nBlockAlign = waveform->nChannels * BYTE_PER_SAMPLE; waveform->nAvgBytesPerSec = waveform->nBlockAlign * waveform->nSamplesPerSec; } break; } } MMCKINFO ckRIFF = { 0 }; MMCKINFO ckData = { 0 }; hr = WriteWaveHeader(file, waveform, &ckRIFF, &ckData); // create a periodic waitable timer HANDLE hWakeUp = CreateWaitableTimer(nullptr, FALSE, nullptr); UINT32 nBlockAlign = waveform->nBlockAlign; // call IAudioClient::Initialize // note that AUDCLNT_STREAMFLAGS_LOOPBACK and AUDCLNT_STREAMFLAGS_EVENTCALLBACK // do not work together... // the "data ready" event never gets set // so we're going to do a timer-driven loop hr = audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_LOOPBACK, 0, 0, waveform, 0); if (FAILED(hr)) { fprintf(stderr, "IAudioClient::Initialize failed: hr = 0x%08x\n", hr); CloseHandle(hWakeUp); audioClient->Release(); return; } // free up waveform CoTaskMemFree(waveform); // activate an IAudioCaptureClient IAudioCaptureClient* audioCaptureClient; hr = audioClient->GetService(__uuidof(IAudioCaptureClient), (void**)&audioCaptureClient); // register with MMCSS DWORD nTaskIndex = 0; HANDLE hTask = AvSetMmThreadCharacteristics(L"Capture", &nTaskIndex); if (hTask == nullptr) { DWORD dwErr = GetLastError(); fprintf(stderr, "AvSetMmThreadCharacteristics failed: last error = %u\n", dwErr); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); return; } // set the waitable timer LARGE_INTEGER liFirstFire; liFirstFire.QuadPart = -hnsDefaultDevicePeriod / 2; // negative means relative time LONG lTimeBetweenFires = (LONG)hnsDefaultDevicePeriod / 2 / (10 * 1000); // convert to milliseconds if (!SetWaitableTimer(hWakeUp, &liFirstFire, lTimeBetweenFires, nullptr, nullptr, FALSE)) { DWORD dwErr = GetLastError(); fprintf(stderr, "SetWaitableTimer failed: last error = %u\n", dwErr); AvRevertMmThreadCharacteristics(hTask); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); return; } // call IAudioClient::Start hr = audioClient->Start(); // loopback capture loop DWORD dwWaitResult; UINT32 frames = 0; for (UINT32 passes = 0; ; passes++) { // drain data while it is available UINT32 nextPacketSize; for (hr = audioCaptureClient->GetNextPacketSize(&nextPacketSize); SUCCEEDED(hr) && nextPacketSize > 0; hr = audioCaptureClient->GetNextPacketSize(&nextPacketSize)) { // get the captured data BYTE* data; UINT32 framesToRead; DWORD dwFlags; hr = audioCaptureClient->GetBuffer(&data, &framesToRead, &dwFlags, nullptr, nullptr); if (FAILED(hr)) { fprintf(stderr, "IAudioCaptureClient::GetBuffer failed on pass %u after %u frames: hr = 0x%08x\n", passes, frames, hr); audioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); return; } // this type of error seems to happen often, ignore it if (dwFlags == AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) ; else if (dwFlags != 0) { fprintf(stderr, "IAudioCaptureClient::GetBuffer set flags to 0x%08x on pass %u after %u frames\n", dwFlags, passes, frames); audioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); return; } if (framesToRead == 0) { fprintf(stderr, "IAudioCaptureClient::GetBuffer said to read 0 frames on pass %u after %u frames\n", passes, frames); audioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); return; } LONG lBytesToWrite = framesToRead * nBlockAlign; #pragma prefast(suppress: __WARNING_INCORRECT_ANNOTATION, "IAudioCaptureClient::GetBuffer SAL annotation implies a 1-byte buffer") LONG lBytesWritten = mmioWrite(file, reinterpret_cast<PCHAR>(data), lBytesToWrite); if (lBytesToWrite != lBytesWritten) { fprintf(stderr, "mmioWrite wrote %u bytes on pass %u after %u frames: expected %u bytes\n", lBytesWritten, passes, frames, lBytesToWrite); audioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); return; } frames += framesToRead; hr = audioCaptureClient->ReleaseBuffer(framesToRead); } dwWaitResult = WaitForSingleObject(hWakeUp, INFINITE); if (time(nullptr) - startTime > secs) break; } FinishWaveFile(file, &ckData, &ckRIFF); audioClient->Stop(); CancelWaitableTimer(hWakeUp); AvRevertMmThreadCharacteristics(hTask); audioCaptureClient->Release(); CloseHandle(hWakeUp); audioClient->Release(); // everything went well... fixup the fact chunk in the file MMRESULT result = mmioClose(file, 0); file = nullptr; if (result != MMSYSERR_NOERROR) { fprintf(stderr, "mmioClose failed: MMSYSERR = %u\n", result); return; } // reopen the file in read/write mode mi = { 0 }; file = mmioOpen(const_cast<LPWSTR>(wsFilename.c_str()), &mi, MMIO_READWRITE); if (file == nullptr) { fprintf(stderr, "mmioOpen(\"%ls\", ...) failed. wErrorRet == %u\n", filename, mi.wErrorRet); return; } // descend into the RIFF/WAVE chunk ckRIFF = { 0 }; ckRIFF.ckid = MAKEFOURCC('W', 'A', 'V', 'E'); // this is right for mmioDescend result = mmioDescend(file, &ckRIFF, nullptr, MMIO_FINDRIFF); if (result != MMSYSERR_NOERROR) { fprintf(stderr, "mmioDescend(\"WAVE\") failed: MMSYSERR = %u\n", result); return; } // descend into the fact chunk MMCKINFO ckFact = { 0 }; ckFact.ckid = MAKEFOURCC('f', 'a', 'c', 't'); result = mmioDescend(file, &ckFact, &ckRIFF, MMIO_FINDCHUNK); if (result != MMSYSERR_NOERROR) { fprintf(stderr, "mmioDescend(\"fact\") failed: MMSYSERR = %u\n", result); return; } // write the correct data to the fact chunk LONG lBytesWritten = mmioWrite(file, reinterpret_cast<PCHAR>(&frames), sizeof(frames)); if (lBytesWritten != sizeof(frames)) { fprintf(stderr, "Updating the fact chunk wrote %u bytes; expected %u\n", lBytesWritten, (UINT32)sizeof(frames)); return; } // ascend out of the fact chunk result = mmioAscend(file, &ckFact, 0); if (result != MMSYSERR_NOERROR) fprintf(stderr, "mmioAscend(\"fact\") failed: MMSYSERR = %u\n", result); }
static void test_PSPropertyKeyFromString(void) { static const WCHAR emptyW[] = {0}; static const WCHAR fmtid_clsidW[] = {'S','t','d','F','o','n','t',' ','1',0}; static const WCHAR fmtid_truncatedW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-',0}; static const WCHAR fmtid_nobracketsW[] = {'1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2',0}; static const WCHAR fmtid_badbracketW[] = {'X','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badcharW[] = {'{','X','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar2W[] = {'{','1','2','3','4','5','6','7','X','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_baddashW[] = {'{','1','2','3','4','5','6','7','8','X','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar3W[] = {'{','1','2','3','4','5','6','7','8','-','X','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','X','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_baddash2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','X', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar5W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 'X','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar6W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','X','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_baddash3W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','X','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar7W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','X','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar8W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','X','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_baddash4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','X', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar9W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', 'X','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar9_adjW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','X','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar10W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','X','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar11W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','X','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar12W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','X','8','9','0','1','2','}',0}; static const WCHAR fmtid_badchar13W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','X','0','1','2','}',0}; static const WCHAR fmtid_badchar14W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','X','2','}',0}; static const WCHAR fmtid_badbracket2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','X',0}; static const WCHAR fmtid_spaceW[] = {' ','{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_spaceendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',0}; static const WCHAR fmtid_spacesendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ',0}; static const WCHAR fmtid_nopidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; static const WCHAR fmtid_badpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','D','E','A','D',0}; static const WCHAR fmtid_adjpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}','1','3','5','7','9',0}; static const WCHAR fmtid_spacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ','1','3','5','7','9',0}; static const WCHAR fmtid_negpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','1','3','5','7','9',0}; static const WCHAR fmtid_negnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','1','3','5','7','9',0}; static const WCHAR fmtid_negnegnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','-','1','3','5','7','9',0}; static const WCHAR fmtid_negspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','1','3','5','7','9',0}; static const WCHAR fmtid_negspacenegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-','1','3','5','7','9',0}; static const WCHAR fmtid_negspacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-',' ','-','1','3','5','7','9',0}; static const WCHAR fmtid_pospidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','1','3','5','7','9',0}; static const WCHAR fmtid_posnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','-','+','-','1','3','5','7','9',0}; static const WCHAR fmtid_symbolpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','/','$','-','1','3','5','7','9',0}; static const WCHAR fmtid_letterpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','B','C','D','1','3','5','7','9',0}; static const WCHAR fmtid_spacepadpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',' ',' ',' ',0}; static const WCHAR fmtid_spacemixpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1',' ','3',' ','5','7','9',' ',' ',' ',0}; static const WCHAR fmtid_tabpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}','\t','1','3','5','7','9',0}; static const WCHAR fmtid_hexpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','0','x','D','E','A','D',0}; static const WCHAR fmtid_mixedpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','9','B','5','C','3','D','1',0}; static const WCHAR fmtid_overflowpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','2','3','4','5','6','7','8','9','0','1',0}; static const WCHAR fmtid_commapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',',','1','3','5','7','9',0}; static const WCHAR fmtid_commaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',',',',',',','1','3','5','7','9',0}; static const WCHAR fmtid_commaspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','1','3','5','7','9',0}; static const WCHAR fmtid_spacecommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','1','3','5','7','9',0}; static const WCHAR fmtid_spccommaspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','1','3','5','7','9',0}; static const WCHAR fmtid_spacescommaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ',',','1','3','5','7','9',0}; static const WCHAR fmtid_commanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-','1','3','5','7','9',0}; static const WCHAR fmtid_spccommanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','-','1','3','5','7','9',0}; static const WCHAR fmtid_commaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','-','1','3','5','7','9',0}; static const WCHAR fmtid_spccommaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','-','1','3','5','7','9',0}; static const WCHAR fmtid_commanegspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-',' ','1','3','5','7','9',0}; static const WCHAR fmtid_negcommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}','-',',','1','3','5','7','9',0}; static const WCHAR fmtid_normalpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',0}; PROPERTYKEY out_init = {dummy_guid, 0xdeadbeef}; PROPERTYKEY out; HRESULT ret; char guid_buf[40], guid_buf2[40]; const struct { LPCWSTR pwzString; PROPERTYKEY *pkey; HRESULT hr_expect; PROPERTYKEY pkey_expect; } testcases[] = { {NULL, NULL, E_POINTER}, {NULL, &out, E_POINTER, out_init}, {emptyW, NULL, E_POINTER}, {emptyW, &out, E_INVALIDARG, {GUID_NULL, 0}}, {fmtid_clsidW, &out, E_INVALIDARG, {GUID_NULL, 0}}, {fmtid_truncatedW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_nobracketsW, &out, E_INVALIDARG, {GUID_NULL, 0}}, {fmtid_badbracketW, &out, E_INVALIDARG, {GUID_NULL, 0}}, {fmtid_badcharW, &out, E_INVALIDARG, {GUID_NULL, 0}}, {fmtid_badchar2W, &out, E_INVALIDARG, {GUID_NULL, 0}}, {fmtid_baddashW, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar3W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar4W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_baddash2W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar5W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar6W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_baddash3W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar7W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar8W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}}, {fmtid_baddash4W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}}, {fmtid_badchar9W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}}, {fmtid_badchar9_adjW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}}, {fmtid_badchar10W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0,0,0,0,0}}, 0}}, {fmtid_badchar11W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0,0,0,0}}, 0}}, {fmtid_badchar12W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0,0,0}}, 0}}, {fmtid_badchar13W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0,0}}, 0}}, {fmtid_badchar14W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0}}, 0}}, {fmtid_badbracket2W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x00}}, 0 }}, {fmtid_spaceW, &out, E_INVALIDARG, {GUID_NULL, 0 }}, {fmtid_spaceendW, &out, E_INVALIDARG, {expect_guid, 0}}, {fmtid_spacesendW, &out, E_INVALIDARG, {expect_guid, 0}}, {fmtid_nopidW, &out, E_INVALIDARG, {expect_guid, 0}}, {fmtid_badpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_adjpidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_spacespidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_negpidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_negnegpidW, &out, S_OK, {expect_guid, 4294953717U}}, {fmtid_negnegnegpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_negspacepidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_negspacenegpidW, &out, S_OK, {expect_guid, 4294953717U}}, {fmtid_negspacespidW, &out, S_OK, {expect_guid, 0}}, {fmtid_pospidW, &out, S_OK, {expect_guid, 0}}, {fmtid_posnegpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_symbolpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_letterpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_spacepadpidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_spacemixpidW, &out, S_OK, {expect_guid, 1}}, {fmtid_tabpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_hexpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_mixedpidW, &out, S_OK, {expect_guid, 0}}, {fmtid_overflowpidW, &out, S_OK, {expect_guid, 3755744309U}}, {fmtid_commapidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_commaspidW, &out, S_OK, {expect_guid, 0}}, {fmtid_commaspacepidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_spacecommapidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_spccommaspcpidW, &out, S_OK, {expect_guid, 13579}}, {fmtid_spacescommaspidW, &out, S_OK, {expect_guid, 0}}, {fmtid_commanegpidW, &out, S_OK, {expect_guid, 4294953717U}}, {fmtid_spccommanegpidW, &out, S_OK, {expect_guid, 4294953717U}}, {fmtid_commaspcnegpidW, &out, S_OK, {expect_guid, 4294953717U}}, {fmtid_spccommaspcnegpidW, &out, S_OK, {expect_guid, 4294953717U}}, {fmtid_commanegspcpidW, &out, S_OK, {expect_guid, 0U}}, {fmtid_negcommapidW, &out, S_OK, {expect_guid, 0}}, {fmtid_normalpidW, &out, S_OK, {expect_guid, 13579}}, }; int i; for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++) { if (testcases[i].pkey) *testcases[i].pkey = out_init; ret = PSPropertyKeyFromString(testcases[i].pwzString, testcases[i].pkey); ok(ret == testcases[i].hr_expect, "[%d] Expected PSPropertyKeyFromString to return 0x%08x, got 0x%08x\n", i, testcases[i].hr_expect, ret); if (testcases[i].pkey) { ok(IsEqualGUID(&testcases[i].pkey->fmtid, &testcases[i].pkey_expect.fmtid), "[%d] Expected GUID %s, got %s\n", i, show_guid(&testcases[i].pkey_expect.fmtid, guid_buf), show_guid(&testcases[i].pkey->fmtid, guid_buf2)); ok(testcases[i].pkey->pid == testcases[i].pkey_expect.pid, "[%d] Expected property ID %u, got %u\n", i, testcases[i].pkey_expect.pid, testcases[i].pkey->pid); } } }
// ========================================================================= // Decryption function // Note: PlaintextLength must be set to the size of the PlaintextData buffer on // entry; on exit, this will be set to the size of the buffer used. NTSTATUS ImpCypherDecryptSectorData( IN GUID* CypherGUID, IN LARGE_INTEGER SectorID, // Indexed from zero IN int SectorSize, // In bytes IN int KeyLength, // In bits IN FREEOTFEBYTE* Key, IN char* KeyASCII, // ASCII representation of "Key" IN int IVLength, // In bits IN FREEOTFEBYTE* IV, IN int CyphertextLength, // In bytes IN FREEOTFEBYTE* CyphertextData, OUT FREEOTFEBYTE* PlaintextData ) { NTSTATUS status = STATUS_SUCCESS; // libtomcrypt can't handle NULL IVs in CBC mode - it ASSERTs that IV != NULL char ltcNullIV[FREEOTFE_MAX_CYPHER_BLOCKSIZE]; int cipher; symmetric_CBC *cbc; int errnum; unsigned int blockLength; DEBUGOUTCYPHERIMPL(DEBUGLEV_ENTER, (TEXT("ImpCypherDecryptData\n"))); cbc = FREEOTFE_MEMALLOC(sizeof(symmetric_CBC)); FREEOTFE_MEMZERO(cbc, sizeof(symmetric_CBC)); if (IsEqualGUID(&CIPHER_GUID_DES, CypherGUID)) { status = InitLTCDESCypher(&cipher); blockLength = des_desc.block_length; } else if (IsEqualGUID(&CIPHER_GUID_3DES, CypherGUID)) { status = InitLTC3DESCypher(&cipher); blockLength = des3_desc.block_length; } else { DEBUGOUTCYPHERIMPL(DEBUGLEV_ERROR, (TEXT("Unsupported cipher GUID passed in.\n"))); status = STATUS_INVALID_PARAMETER; } // libtomcrypt can't handle NULL IVs in CBC mode - it ASSERTs that IV != NULL if ( (IVLength == 0) || (IV == NULL) ) { FREEOTFE_MEMZERO(<cNullIV, sizeof(ltcNullIV)); IV = (char*)<cNullIV; } if NT_SUCCESS(status) { // Start a CBC session if ((errnum = cbc_start( cipher, IV, Key, (KeyLength/8), 0, cbc )) != CRYPT_OK) { status = STATUS_UNSUCCESSFUL; DEBUGOUTCYPHERIMPL(DEBUGLEV_ERROR, (TEXT("Unable to start CBC session (errnum: %d)\n"), errnum)); } else { if ((errnum = cbc_decrypt( CyphertextData, PlaintextData, CyphertextLength, cbc )) != CRYPT_OK) { DEBUGOUTCYPHERIMPL(DEBUGLEV_ERROR, (TEXT("Unable to encrypt/decrypt block (errnum: %d)\n"), errnum)); status = STATUS_UNSUCCESSFUL; } cbc_done(cbc); } } SecZeroMemory(cbc, sizeof(symmetric_CBC)); FREEOTFE_FREE(cbc); DEBUGOUTCYPHERIMPL(DEBUGLEV_EXIT, (TEXT("ImpCypherDecryptData\n"))); return status; }
/************************************************************************** * IExtractIconW_Constructor */ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl) { CComPtr<IDefaultExtractIconInit> initIcon; IExtractIconW *extractIcon; GUID const * riid; int icon_idx; UINT flags; CHAR sTemp[MAX_PATH]; WCHAR wTemp[MAX_PATH]; LPITEMIDLIST pSimplePidl = ILFindLastID(pidl); HRESULT hr; hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit,&initIcon)); if (FAILED(hr)) return NULL; hr = initIcon->QueryInterface(IID_PPV_ARG(IExtractIconW,&extractIcon)); if (FAILED(hr)) return NULL; if (_ILIsDesktop(pSimplePidl)) { initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DESKTOP); } else if ((riid = _ILGetGUIDPointer(pSimplePidl))) { /* my computer and other shell extensions */ static const WCHAR fmt[] = { 'C', 'L', 'S', 'I', 'D', '\\', '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0 }; WCHAR xriid[50]; swprintf(xriid, fmt, riid->Data1, riid->Data2, riid->Data3, riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]); const WCHAR* iconname = NULL; if (_ILIsBitBucket(pSimplePidl)) { static const WCHAR szFull[] = {'F','u','l','l',0}; static const WCHAR szEmpty[] = {'E','m','p','t','y',0}; IEnumIDList *EnumIDList = NULL; CoInitialize(NULL); IShellFolder2 *psfRecycleBin = NULL; IShellFolder *psfDesktop = NULL; hr = SHGetDesktopFolder(&psfDesktop); if (SUCCEEDED(hr)) hr = psfDesktop->BindToObject(pSimplePidl, NULL, IID_IShellFolder2, (void**) &psfRecycleBin); if (SUCCEEDED(hr)) hr = psfRecycleBin->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &EnumIDList); ULONG itemcount; LPITEMIDLIST pidl = NULL; if (SUCCEEDED(hr) && (hr = EnumIDList->Next(1, &pidl, &itemcount)) == S_OK) { CoTaskMemFree(pidl); iconname = szFull; } else { iconname = szEmpty; } if (psfDesktop) psfDesktop->Release(); if (psfRecycleBin) psfRecycleBin->Release(); if (EnumIDList) EnumIDList->Release(); } if (HCR_GetIconW(xriid, wTemp, iconname, MAX_PATH, &icon_idx)) { initIcon->SetNormalIcon(wTemp, icon_idx); } else { if (IsEqualGUID(*riid, CLSID_MyComputer)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_COMPUTER); else if (IsEqualGUID(*riid, CLSID_MyDocuments)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_DOCUMENTS); else if (IsEqualGUID(*riid, CLSID_NetworkPlaces)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_NETWORK_PLACES); else initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_FOLDER); } } else if (_ILIsDrive (pSimplePidl)) { static const WCHAR drive[] = { 'D', 'r', 'i', 'v', 'e', 0 }; int icon_idx = -1; if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH)) { switch(GetDriveTypeA(sTemp)) { case DRIVE_REMOVABLE: icon_idx = IDI_SHELL_FLOPPY; break; case DRIVE_CDROM: icon_idx = IDI_SHELL_CDROM; break; case DRIVE_REMOTE: icon_idx = IDI_SHELL_NETDRIVE; break; case DRIVE_RAMDISK: icon_idx = IDI_SHELL_RAMDISK; break; case DRIVE_NO_ROOT_DIR: icon_idx = IDI_SHELL_CDROM; break; } } if (icon_idx != -1) { initIcon->SetNormalIcon(swShell32Name, -icon_idx); } else { if (HCR_GetIconW(drive, wTemp, NULL, MAX_PATH, &icon_idx)) initIcon->SetNormalIcon(wTemp, icon_idx); else initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DRIVE); } } else if (_ILIsFolder (pSimplePidl)) { if (SUCCEEDED(getIconLocationForFolder( pidl, 0, wTemp, MAX_PATH, &icon_idx, &flags))) { initIcon->SetNormalIcon(wTemp, icon_idx); // FIXME: if/when getIconLocationForFolder does something for // GIL_FORSHORTCUT, code below should be uncommented. and // the following line removed. initIcon->SetShortcutIcon(wTemp, icon_idx); } if (SUCCEEDED(getIconLocationForFolder( pidl, GIL_DEFAULTICON, wTemp, MAX_PATH, &icon_idx, &flags))) { initIcon->SetDefaultIcon(wTemp, icon_idx); } // if (SUCCEEDED(getIconLocationForFolder( // pidl, GIL_FORSHORTCUT, wTemp, MAX_PATH, // &icon_idx, // &flags))) // { // initIcon->SetShortcutIcon(wTemp, icon_idx); // } if (SUCCEEDED(getIconLocationForFolder( pidl, GIL_OPENICON, wTemp, MAX_PATH, &icon_idx, &flags))) { initIcon->SetOpenIcon(wTemp, icon_idx); } } else { BOOL found = FALSE; if (_ILIsCPanelStruct(pSimplePidl)) { if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, wTemp, MAX_PATH, &icon_idx))) found = TRUE; } else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH)) { if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE) && HCR_GetIconA(sTemp, sTemp, NULL, MAX_PATH, &icon_idx)) { if (!lstrcmpA("%1", sTemp)) /* icon is in the file */ { SHGetPathFromIDListW(pidl, wTemp); icon_idx = 0; } else { MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wTemp, MAX_PATH); } found = TRUE; } else if (!lstrcmpiA(sTemp, "lnkfile")) { /* extract icon from shell shortcut */ CComPtr<IShellFolder> dsf; CComPtr<IShellLinkW> psl; if (SUCCEEDED(SHGetDesktopFolder(&dsf))) { HRESULT hr = dsf->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidl, IID_IShellLinkW, NULL, (LPVOID *)&psl); if (SUCCEEDED(hr)) { hr = psl->GetIconLocation(wTemp, MAX_PATH, &icon_idx); if (SUCCEEDED(hr) && *sTemp) found = TRUE; } } } } if (!found) /* default icon */ initIcon->SetNormalIcon(swShell32Name, 0); else initIcon->SetNormalIcon(wTemp, icon_idx); } return extractIcon; }
static void test_lsa(void) { NTSTATUS status; LSA_HANDLE handle; LSA_OBJECT_ATTRIBUTES object_attributes; ZeroMemory(&object_attributes, sizeof(object_attributes)); object_attributes.Length = sizeof(object_attributes); status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle); ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED, "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status); /* try a more restricted access mask if necessary */ if (status == STATUS_ACCESS_DENIED) { trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES\n"); status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES, &handle); ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES) returned 0x%08x\n", status); } if (status == STATUS_SUCCESS) { PPOLICY_AUDIT_EVENTS_INFO audit_events_info; PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info; PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info; PPOLICY_DNS_DOMAIN_INFO dns_domain_info; HANDLE token; BOOL ret; status = pLsaQueryInformationPolicy(handle, PolicyAuditEventsInformation, (PVOID*)&audit_events_info); if (status == STATUS_ACCESS_DENIED) skip("Not enough rights to retrieve PolicyAuditEventsInformation\n"); else ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { pLsaFreeMemory((LPVOID)audit_events_info); } status = pLsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (PVOID*)&primary_domain_info); ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { if (primary_domain_info->Sid) { LPSTR strsid; if (pConvertSidToStringSidA(primary_domain_info->Sid, &strsid)) { if (primary_domain_info->Name.Buffer) { LPSTR name = NULL; UINT len; len = WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL ); name = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, name, len, NULL, NULL ); trace(" name: %s sid: %s\n", name, strsid); LocalFree( name ); } else trace(" name: NULL sid: %s\n", strsid); LocalFree( strsid ); } else trace("invalid sid\n"); } else trace("Running on a standalone system.\n"); pLsaFreeMemory((LPVOID)primary_domain_info); } status = pLsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (PVOID*)&account_domain_info); ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { pLsaFreeMemory((LPVOID)account_domain_info); } /* This isn't supported in NT4 */ status = pLsaQueryInformationPolicy(handle, PolicyDnsDomainInformation, (PVOID*)&dns_domain_info); ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER, "LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08x\n", status); if (status == STATUS_SUCCESS) { if (dns_domain_info->Sid || !IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL)) { LPSTR strsid = NULL; LPSTR name = NULL; LPSTR domain = NULL; LPSTR forest = NULL; LPSTR guidstr = NULL; WCHAR guidstrW[64]; UINT len; guidstrW[0] = '\0'; pConvertSidToStringSidA(dns_domain_info->Sid, &strsid); StringFromGUID2(&dns_domain_info->DomainGuid, guidstrW, sizeof(guidstrW)/sizeof(WCHAR)); len = WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, NULL, 0, NULL, NULL ); guidstr = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, guidstr, len, NULL, NULL ); if (dns_domain_info->Name.Buffer) { len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL ); name = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL ); } if (dns_domain_info->DnsDomainName.Buffer) { len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL ); domain = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL ); } if (dns_domain_info->DnsForestName.Buffer) { len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL ); forest = LocalAlloc( 0, len ); WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL ); } trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n", name ? name : "NULL", domain ? domain : "NULL", forest ? forest : "NULL", guidstr, strsid ? strsid : "NULL"); LocalFree( name ); LocalFree( forest ); LocalFree( domain ); LocalFree( guidstr ); LocalFree( strsid ); } else trace("Running on a standalone system.\n"); pLsaFreeMemory((LPVOID)dns_domain_info); } /* We need a valid SID to pass to LsaEnumerateAccountRights */ ret = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token ); ok(ret, "Unable to obtain process token, error %u\n", GetLastError( )); if (ret) { char buffer[64]; DWORD len; TOKEN_USER *token_user = (TOKEN_USER *) buffer; ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, sizeof(buffer), &len ); ok(ret || GetLastError( ) == ERROR_INSUFFICIENT_BUFFER, "Unable to obtain token information, error %u\n", GetLastError( )); if (! ret && GetLastError( ) == ERROR_INSUFFICIENT_BUFFER) { trace("Resizing buffer to %u.\n", len); token_user = LocalAlloc( 0, len ); if (token_user != NULL) ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, len, &len ); } if (ret) { PLSA_UNICODE_STRING rights; ULONG rights_count; rights = (PLSA_UNICODE_STRING) 0xdeadbeaf; rights_count = 0xcafecafe; status = pLsaEnumerateAccountRights(handle, token_user->User.Sid, &rights, &rights_count); ok(status == STATUS_SUCCESS || status == STATUS_OBJECT_NAME_NOT_FOUND, "Unexpected status 0x%x\n", status); if (status == STATUS_SUCCESS) pLsaFreeMemory( rights ); else ok(rights == NULL && rights_count == 0, "Expected rights and rights_count to be set to 0 on failure\n"); } if (token_user != NULL && token_user != (TOKEN_USER *) buffer) LocalFree( token_user ); CloseHandle( token ); } status = pLsaClose(handle); ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status); } }