ntdll: Use a separate memory allocation for the kernel stack.
[wine.git] / dlls / winegstreamer / wma_decoder.c
blob4a0d5f2592eb9d0f08c4052fcfc861ff04a34d16
1 /* WMA Decoder DMO / MF Transform
3 * Copyright 2022 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "gst_private.h"
22 #include "mfapi.h"
23 #include "mferror.h"
24 #include "mfobjects.h"
25 #include "mftransform.h"
26 #include "wmcodecdsp.h"
28 #include "wine/debug.h"
29 #include "wine/heap.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wmadec);
32 WINE_DECLARE_DEBUG_CHANNEL(winediag);
34 static const GUID *const wma_decoder_input_types[] =
36 &MEDIASUBTYPE_MSAUDIO1,
37 &MFAudioFormat_WMAudioV8,
38 &MFAudioFormat_WMAudioV9,
39 &MFAudioFormat_WMAudio_Lossless,
41 static const GUID *const wma_decoder_output_types[] =
43 &MFAudioFormat_Float,
44 &MFAudioFormat_PCM,
47 struct wma_decoder
49 IUnknown IUnknown_inner;
50 IMFTransform IMFTransform_iface;
51 IMediaObject IMediaObject_iface;
52 IPropertyBag IPropertyBag_iface;
53 IUnknown *outer;
54 LONG refcount;
56 IMFMediaType *input_type;
57 MFT_INPUT_STREAM_INFO input_info;
58 IMFMediaType *output_type;
59 MFT_OUTPUT_STREAM_INFO output_info;
61 struct wg_transform *wg_transform;
62 struct wg_sample_queue *wg_sample_queue;
65 static inline struct wma_decoder *impl_from_IUnknown(IUnknown *iface)
67 return CONTAINING_RECORD(iface, struct wma_decoder, IUnknown_inner);
70 static HRESULT try_create_wg_transform(struct wma_decoder *decoder)
72 struct wg_format input_format, output_format;
74 if (decoder->wg_transform)
75 wg_transform_destroy(decoder->wg_transform);
76 decoder->wg_transform = NULL;
78 mf_media_type_to_wg_format(decoder->input_type, &input_format);
79 if (input_format.major_type == WG_MAJOR_TYPE_UNKNOWN)
80 return MF_E_INVALIDMEDIATYPE;
82 mf_media_type_to_wg_format(decoder->output_type, &output_format);
83 if (output_format.major_type == WG_MAJOR_TYPE_UNKNOWN)
84 return MF_E_INVALIDMEDIATYPE;
86 if (!(decoder->wg_transform = wg_transform_create(&input_format, &output_format)))
87 return E_FAIL;
89 return S_OK;
92 static HRESULT WINAPI unknown_QueryInterface(IUnknown *iface, REFIID iid, void **out)
94 struct wma_decoder *decoder = impl_from_IUnknown(iface);
96 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
98 if (IsEqualGUID(iid, &IID_IUnknown))
99 *out = &decoder->IUnknown_inner;
100 else if (IsEqualGUID(iid, &IID_IMFTransform))
101 *out = &decoder->IMFTransform_iface;
102 else if (IsEqualGUID(iid, &IID_IMediaObject))
103 *out = &decoder->IMediaObject_iface;
104 else if (IsEqualIID(iid, &IID_IPropertyBag))
105 *out = &decoder->IPropertyBag_iface;
106 else
108 *out = NULL;
109 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
110 return E_NOINTERFACE;
113 IUnknown_AddRef((IUnknown *)*out);
114 return S_OK;
117 static ULONG WINAPI unknown_AddRef(IUnknown *iface)
119 struct wma_decoder *decoder = impl_from_IUnknown(iface);
120 ULONG refcount = InterlockedIncrement(&decoder->refcount);
122 TRACE("iface %p increasing refcount to %lu.\n", decoder, refcount);
124 return refcount;
127 static ULONG WINAPI unknown_Release(IUnknown *iface)
129 struct wma_decoder *decoder = impl_from_IUnknown(iface);
130 ULONG refcount = InterlockedDecrement(&decoder->refcount);
132 TRACE("iface %p decreasing refcount to %lu.\n", decoder, refcount);
134 if (!refcount)
136 if (decoder->wg_transform)
137 wg_transform_destroy(decoder->wg_transform);
138 if (decoder->input_type)
139 IMFMediaType_Release(decoder->input_type);
140 if (decoder->output_type)
141 IMFMediaType_Release(decoder->output_type);
143 wg_sample_queue_destroy(decoder->wg_sample_queue);
144 free(decoder);
147 return refcount;
150 static const IUnknownVtbl unknown_vtbl =
152 unknown_QueryInterface,
153 unknown_AddRef,
154 unknown_Release,
157 static struct wma_decoder *impl_from_IMFTransform(IMFTransform *iface)
159 return CONTAINING_RECORD(iface, struct wma_decoder, IMFTransform_iface);
162 static HRESULT WINAPI transform_QueryInterface(IMFTransform *iface, REFIID iid, void **out)
164 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
165 return IUnknown_QueryInterface(decoder->outer, iid, out);
168 static ULONG WINAPI transform_AddRef(IMFTransform *iface)
170 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
171 return IUnknown_AddRef(decoder->outer);
174 static ULONG WINAPI transform_Release(IMFTransform *iface)
176 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
177 return IUnknown_Release(decoder->outer);
180 static HRESULT WINAPI transform_GetStreamLimits(IMFTransform *iface, DWORD *input_minimum,
181 DWORD *input_maximum, DWORD *output_minimum, DWORD *output_maximum)
183 TRACE("iface %p, input_minimum %p, input_maximum %p, output_minimum %p, output_maximum %p.\n",
184 iface, input_minimum, input_maximum, output_minimum, output_maximum);
185 *input_minimum = *input_maximum = *output_minimum = *output_maximum = 1;
186 return S_OK;
189 static HRESULT WINAPI transform_GetStreamCount(IMFTransform *iface, DWORD *inputs, DWORD *outputs)
191 TRACE("iface %p, inputs %p, outputs %p.\n", iface, inputs, outputs);
192 *inputs = *outputs = 1;
193 return S_OK;
196 static HRESULT WINAPI transform_GetStreamIDs(IMFTransform *iface, DWORD input_size, DWORD *inputs,
197 DWORD output_size, DWORD *outputs)
199 TRACE("iface %p, input_size %lu, inputs %p, output_size %lu, outputs %p.\n", iface,
200 input_size, inputs, output_size, outputs);
201 return E_NOTIMPL;
204 static HRESULT WINAPI transform_GetInputStreamInfo(IMFTransform *iface, DWORD id, MFT_INPUT_STREAM_INFO *info)
206 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
208 TRACE("iface %p, id %lu, info %p.\n", iface, id, info);
210 if (!decoder->input_type || !decoder->output_type)
212 memset(info, 0, sizeof(*info));
213 return MF_E_TRANSFORM_TYPE_NOT_SET;
216 *info = decoder->input_info;
217 return S_OK;
220 static HRESULT WINAPI transform_GetOutputStreamInfo(IMFTransform *iface, DWORD id, MFT_OUTPUT_STREAM_INFO *info)
222 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
224 TRACE("iface %p, id %lu, info %p.\n", iface, id, info);
226 if (!decoder->input_type || !decoder->output_type)
228 memset(info, 0, sizeof(*info));
229 return MF_E_TRANSFORM_TYPE_NOT_SET;
232 *info = decoder->output_info;
233 return S_OK;
236 static HRESULT WINAPI transform_GetAttributes(IMFTransform *iface, IMFAttributes **attributes)
238 TRACE("iface %p, attributes %p.\n", iface, attributes);
239 return E_NOTIMPL;
242 static HRESULT WINAPI transform_GetInputStreamAttributes(IMFTransform *iface, DWORD id, IMFAttributes **attributes)
244 TRACE("iface %p, id %#lx, attributes %p.\n", iface, id, attributes);
245 return E_NOTIMPL;
248 static HRESULT WINAPI transform_GetOutputStreamAttributes(IMFTransform *iface, DWORD id, IMFAttributes **attributes)
250 TRACE("iface %p, id %#lx, attributes %p.\n", iface, id, attributes);
251 return E_NOTIMPL;
254 static HRESULT WINAPI transform_DeleteInputStream(IMFTransform *iface, DWORD id)
256 TRACE("iface %p, id %#lx.\n", iface, id);
257 return E_NOTIMPL;
260 static HRESULT WINAPI transform_AddInputStreams(IMFTransform *iface, DWORD streams, DWORD *ids)
262 TRACE("iface %p, streams %lu, ids %p.\n", iface, streams, ids);
263 return E_NOTIMPL;
266 static HRESULT WINAPI transform_GetInputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
267 IMFMediaType **type)
269 FIXME("iface %p, id %lu, index %lu, type %p stub!\n", iface, id, index, type);
270 return E_NOTIMPL;
273 static HRESULT WINAPI transform_GetOutputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
274 IMFMediaType **type)
276 UINT32 channel_count, sample_size, sample_rate, block_alignment;
277 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
278 IMFMediaType *media_type;
279 const GUID *output_type;
280 HRESULT hr;
282 TRACE("iface %p, id %lu, index %lu, type %p.\n", iface, id, index, type);
284 if (!decoder->input_type)
285 return MF_E_TRANSFORM_TYPE_NOT_SET;
287 *type = NULL;
289 if (index >= ARRAY_SIZE(wma_decoder_output_types))
290 return MF_E_NO_MORE_TYPES;
291 output_type = wma_decoder_output_types[index];
293 if (FAILED(hr = MFCreateMediaType(&media_type)))
294 return hr;
296 if (FAILED(hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio)))
297 goto done;
298 if (FAILED(hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, output_type)))
299 goto done;
301 if (IsEqualGUID(output_type, &MFAudioFormat_Float))
302 sample_size = 32;
303 else if (IsEqualGUID(output_type, &MFAudioFormat_PCM))
304 sample_size = 16;
305 else
307 FIXME("Subtype %s not implemented!\n", debugstr_guid(output_type));
308 hr = E_NOTIMPL;
309 goto done;
312 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_BITS_PER_SAMPLE, sample_size)))
313 goto done;
315 if (FAILED(hr = IMFMediaType_GetUINT32(decoder->input_type, &MF_MT_AUDIO_NUM_CHANNELS, &channel_count)))
316 goto done;
317 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_NUM_CHANNELS, channel_count)))
318 goto done;
320 if (FAILED(hr = IMFMediaType_GetUINT32(decoder->input_type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &sample_rate)))
321 goto done;
322 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, sample_rate)))
323 goto done;
325 block_alignment = sample_size * channel_count / 8;
326 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, block_alignment)))
327 goto done;
328 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, sample_rate * block_alignment)))
329 goto done;
331 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1)))
332 goto done;
333 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1)))
334 goto done;
335 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1)))
336 goto done;
338 done:
339 if (SUCCEEDED(hr))
340 IMFMediaType_AddRef((*type = media_type));
342 IMFMediaType_Release(media_type);
343 return hr;
346 static HRESULT WINAPI transform_SetInputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
348 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
349 MF_ATTRIBUTE_TYPE item_type;
350 UINT32 block_alignment;
351 GUID major, subtype;
352 HRESULT hr;
353 ULONG i;
355 TRACE("iface %p, id %lu, type %p, flags %#lx.\n", iface, id, type, flags);
357 if (FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_MAJOR_TYPE, &major)) ||
358 FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &subtype)))
359 return hr;
361 if (!IsEqualGUID(&major, &MFMediaType_Audio))
362 return MF_E_INVALIDMEDIATYPE;
364 for (i = 0; i < ARRAY_SIZE(wma_decoder_input_types); ++i)
365 if (IsEqualGUID(&subtype, wma_decoder_input_types[i]))
366 break;
367 if (i == ARRAY_SIZE(wma_decoder_input_types))
368 return MF_E_INVALIDMEDIATYPE;
370 if (FAILED(IMFMediaType_GetItemType(type, &MF_MT_USER_DATA, &item_type)) ||
371 item_type != MF_ATTRIBUTE_BLOB)
372 return MF_E_INVALIDMEDIATYPE;
373 if (FAILED(IMFMediaType_GetUINT32(type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &block_alignment)))
374 return MF_E_INVALIDMEDIATYPE;
375 if (FAILED(IMFMediaType_GetItemType(type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &item_type)) ||
376 item_type != MF_ATTRIBUTE_UINT32)
377 return MF_E_INVALIDMEDIATYPE;
378 if (FAILED(IMFMediaType_GetItemType(type, &MF_MT_AUDIO_NUM_CHANNELS, &item_type)) ||
379 item_type != MF_ATTRIBUTE_UINT32)
380 return MF_E_INVALIDMEDIATYPE;
381 if (flags & MFT_SET_TYPE_TEST_ONLY)
382 return S_OK;
384 if (!decoder->input_type && FAILED(hr = MFCreateMediaType(&decoder->input_type)))
385 return hr;
387 if (decoder->output_type)
389 IMFMediaType_Release(decoder->output_type);
390 decoder->output_type = NULL;
393 if (SUCCEEDED(hr = IMFMediaType_CopyAllItems(type, (IMFAttributes *)decoder->input_type)))
394 decoder->input_info.cbSize = block_alignment;
395 else
397 IMFMediaType_Release(decoder->input_type);
398 decoder->input_info.cbSize = 0;
399 decoder->input_type = NULL;
402 return hr;
405 static HRESULT WINAPI transform_SetOutputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
407 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
408 UINT32 channel_count, block_alignment;
409 MF_ATTRIBUTE_TYPE item_type;
410 ULONG i, sample_size;
411 GUID major, subtype;
412 HRESULT hr;
414 TRACE("iface %p, id %lu, type %p, flags %#lx.\n", iface, id, type, flags);
416 if (!decoder->input_type)
417 return MF_E_TRANSFORM_TYPE_NOT_SET;
419 if (FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_MAJOR_TYPE, &major)) ||
420 FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &subtype)))
421 return hr;
423 if (!IsEqualGUID(&major, &MFMediaType_Audio))
424 return MF_E_INVALIDMEDIATYPE;
426 for (i = 0; i < ARRAY_SIZE(wma_decoder_output_types); ++i)
427 if (IsEqualGUID(&subtype, wma_decoder_output_types[i]))
428 break;
429 if (i == ARRAY_SIZE(wma_decoder_output_types))
430 return MF_E_INVALIDMEDIATYPE;
432 if (IsEqualGUID(&subtype, &MFAudioFormat_Float))
433 sample_size = 32;
434 else if (IsEqualGUID(&subtype, &MFAudioFormat_PCM))
435 sample_size = 16;
436 else
438 FIXME("Subtype %s not implemented!\n", debugstr_guid(&subtype));
439 hr = E_NOTIMPL;
440 return hr;
443 if (FAILED(IMFMediaType_GetItemType(type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &item_type)) ||
444 item_type != MF_ATTRIBUTE_UINT32)
445 return MF_E_INVALIDMEDIATYPE;
446 if (FAILED(IMFMediaType_GetItemType(type, &MF_MT_AUDIO_BITS_PER_SAMPLE, &item_type)) ||
447 item_type != MF_ATTRIBUTE_UINT32)
448 return MF_E_INVALIDMEDIATYPE;
449 if (FAILED(IMFMediaType_GetUINT32(type, &MF_MT_AUDIO_NUM_CHANNELS, &channel_count)))
450 return MF_E_INVALIDMEDIATYPE;
451 if (FAILED(IMFMediaType_GetItemType(type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &item_type)) ||
452 item_type != MF_ATTRIBUTE_UINT32)
453 return MF_E_INVALIDMEDIATYPE;
454 if (FAILED(IMFMediaType_GetUINT32(type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &block_alignment)))
455 return MF_E_INVALIDMEDIATYPE;
456 if (flags & MFT_SET_TYPE_TEST_ONLY)
457 return S_OK;
459 if (FAILED(IMFMediaType_SetUINT32(decoder->input_type, &MF_MT_AUDIO_BITS_PER_SAMPLE, sample_size)))
460 return MF_E_INVALIDMEDIATYPE;
462 if (!decoder->output_type && FAILED(hr = MFCreateMediaType(&decoder->output_type)))
463 return hr;
465 if (FAILED(hr = IMFMediaType_CopyAllItems(type, (IMFAttributes *)decoder->output_type)))
466 goto failed;
468 if (FAILED(hr = try_create_wg_transform(decoder)))
469 goto failed;
471 decoder->output_info.cbSize = 1024 * block_alignment * channel_count;
472 return S_OK;
474 failed:
475 IMFMediaType_Release(decoder->output_type);
476 decoder->output_info.cbSize = 0;
477 decoder->output_type = NULL;
478 return hr;
481 static HRESULT WINAPI transform_GetInputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
483 FIXME("iface %p, id %lu, type %p stub!\n", iface, id, type);
484 return E_NOTIMPL;
487 static HRESULT WINAPI transform_GetOutputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
489 FIXME("iface %p, id %lu, type %p stub!\n", iface, id, type);
490 return E_NOTIMPL;
493 static HRESULT WINAPI transform_GetInputStatus(IMFTransform *iface, DWORD id, DWORD *flags)
495 FIXME("iface %p, id %lu, flags %p stub!\n", iface, id, flags);
496 return E_NOTIMPL;
499 static HRESULT WINAPI transform_GetOutputStatus(IMFTransform *iface, DWORD *flags)
501 FIXME("iface %p, flags %p stub!\n", iface, flags);
502 return E_NOTIMPL;
505 static HRESULT WINAPI transform_SetOutputBounds(IMFTransform *iface, LONGLONG lower, LONGLONG upper)
507 TRACE("iface %p, lower %I64d, upper %I64d.\n", iface, lower, upper);
508 return E_NOTIMPL;
511 static HRESULT WINAPI transform_ProcessEvent(IMFTransform *iface, DWORD id, IMFMediaEvent *event)
513 FIXME("iface %p, id %lu, event %p stub!\n", iface, id, event);
514 return E_NOTIMPL;
517 static HRESULT WINAPI transform_ProcessMessage(IMFTransform *iface, MFT_MESSAGE_TYPE message, ULONG_PTR param)
519 FIXME("iface %p, message %#x, param %p stub!\n", iface, message, (void *)param);
520 return S_OK;
523 static HRESULT WINAPI transform_ProcessInput(IMFTransform *iface, DWORD id, IMFSample *sample, DWORD flags)
525 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
526 MFT_INPUT_STREAM_INFO info;
527 DWORD total_length;
528 HRESULT hr;
530 TRACE("iface %p, id %lu, sample %p, flags %#lx.\n", iface, id, sample, flags);
532 if (!decoder->wg_transform)
533 return MF_E_TRANSFORM_TYPE_NOT_SET;
535 if (FAILED(hr = IMFTransform_GetInputStreamInfo(iface, 0, &info))
536 || FAILED(hr = IMFSample_GetTotalLength(sample, &total_length)))
537 return hr;
539 /* WMA transform uses fixed size input samples and ignores samples with invalid sizes */
540 if (total_length % info.cbSize)
541 return S_OK;
543 return wg_transform_push_mf(decoder->wg_transform, sample, decoder->wg_sample_queue);
546 static HRESULT WINAPI transform_ProcessOutput(IMFTransform *iface, DWORD flags, DWORD count,
547 MFT_OUTPUT_DATA_BUFFER *samples, DWORD *status)
549 struct wma_decoder *decoder = impl_from_IMFTransform(iface);
550 MFT_OUTPUT_STREAM_INFO info;
551 HRESULT hr;
553 TRACE("iface %p, flags %#lx, count %lu, samples %p, status %p.\n", iface, flags, count, samples, status);
555 if (count != 1)
556 return E_INVALIDARG;
558 if (!decoder->wg_transform)
559 return MF_E_TRANSFORM_TYPE_NOT_SET;
561 *status = samples->dwStatus = 0;
562 if (!samples->pSample)
564 samples[0].dwStatus = MFT_OUTPUT_DATA_BUFFER_NO_SAMPLE;
565 return MF_E_TRANSFORM_NEED_MORE_INPUT;
568 if (FAILED(hr = IMFTransform_GetOutputStreamInfo(iface, 0, &info)))
569 return hr;
571 if (SUCCEEDED(hr = wg_transform_read_mf(decoder->wg_transform, samples->pSample,
572 info.cbSize, NULL, &samples->dwStatus)))
573 wg_sample_queue_flush(decoder->wg_sample_queue, false);
575 return hr;
578 static const IMFTransformVtbl transform_vtbl =
580 transform_QueryInterface,
581 transform_AddRef,
582 transform_Release,
583 transform_GetStreamLimits,
584 transform_GetStreamCount,
585 transform_GetStreamIDs,
586 transform_GetInputStreamInfo,
587 transform_GetOutputStreamInfo,
588 transform_GetAttributes,
589 transform_GetInputStreamAttributes,
590 transform_GetOutputStreamAttributes,
591 transform_DeleteInputStream,
592 transform_AddInputStreams,
593 transform_GetInputAvailableType,
594 transform_GetOutputAvailableType,
595 transform_SetInputType,
596 transform_SetOutputType,
597 transform_GetInputCurrentType,
598 transform_GetOutputCurrentType,
599 transform_GetInputStatus,
600 transform_GetOutputStatus,
601 transform_SetOutputBounds,
602 transform_ProcessEvent,
603 transform_ProcessMessage,
604 transform_ProcessInput,
605 transform_ProcessOutput,
608 static inline struct wma_decoder *impl_from_IMediaObject(IMediaObject *iface)
610 return CONTAINING_RECORD(iface, struct wma_decoder, IMediaObject_iface);
613 static HRESULT WINAPI media_object_QueryInterface(IMediaObject *iface, REFIID iid, void **obj)
615 struct wma_decoder *decoder = impl_from_IMediaObject(iface);
616 return IUnknown_QueryInterface(decoder->outer, iid, obj);
619 static ULONG WINAPI media_object_AddRef(IMediaObject *iface)
621 struct wma_decoder *decoder = impl_from_IMediaObject(iface);
622 return IUnknown_AddRef(decoder->outer);
625 static ULONG WINAPI media_object_Release(IMediaObject *iface)
627 struct wma_decoder *decoder = impl_from_IMediaObject(iface);
628 return IUnknown_Release(decoder->outer);
631 static HRESULT WINAPI media_object_GetStreamCount(IMediaObject *iface, DWORD *input, DWORD *output)
633 FIXME("iface %p, input %p, output %p semi-stub!\n", iface, input, output);
634 *input = *output = 1;
635 return S_OK;
638 static HRESULT WINAPI media_object_GetInputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
640 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
641 return E_NOTIMPL;
644 static HRESULT WINAPI media_object_GetOutputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
646 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
647 return E_NOTIMPL;
650 static HRESULT WINAPI media_object_GetInputType(IMediaObject *iface, DWORD index, DWORD type_index,
651 DMO_MEDIA_TYPE *type)
653 FIXME("iface %p, index %lu, type_index %lu, type %p stub!\n", iface, index, type_index, type);
654 return E_NOTIMPL;
657 static HRESULT WINAPI media_object_GetOutputType(IMediaObject *iface, DWORD index, DWORD type_index,
658 DMO_MEDIA_TYPE *type)
660 FIXME("iface %p, index %lu, type_index %lu, type %p stub!\n", iface, index, type_index, type);
661 return E_NOTIMPL;
664 static HRESULT WINAPI media_object_SetInputType(IMediaObject *iface, DWORD index,
665 const DMO_MEDIA_TYPE *type, DWORD flags)
667 FIXME("iface %p, index %lu, type %p, flags %#lx stub!\n", iface, index, type, flags);
668 return E_NOTIMPL;
671 static HRESULT WINAPI media_object_SetOutputType(IMediaObject *iface, DWORD index,
672 const DMO_MEDIA_TYPE *type, DWORD flags)
674 FIXME("iface %p, index %lu, type %p, flags %#lx stub!\n", iface, index, type, flags);
675 return E_NOTIMPL;
678 static HRESULT WINAPI media_object_GetInputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
680 FIXME("iface %p, index %lu, type %p stub!\n", iface, index, type);
681 return E_NOTIMPL;
684 static HRESULT WINAPI media_object_GetOutputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
686 FIXME("iface %p, index %lu, type %p stub!\n", iface, index, type);
687 return E_NOTIMPL;
690 static HRESULT WINAPI media_object_GetInputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size,
691 DWORD *lookahead, DWORD *alignment)
693 FIXME("iface %p, index %lu, size %p, lookahead %p, alignment %p stub!\n", iface, index, size,
694 lookahead, alignment);
695 return E_NOTIMPL;
698 static HRESULT WINAPI media_object_GetOutputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size, DWORD *alignment)
700 FIXME("iface %p, index %lu, size %p, alignment %p stub!\n", iface, index, size, alignment);
701 return E_NOTIMPL;
704 static HRESULT WINAPI media_object_GetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME *latency)
706 FIXME("iface %p, index %lu, latency %p stub!\n", iface, index, latency);
707 return E_NOTIMPL;
710 static HRESULT WINAPI media_object_SetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME latency)
712 FIXME("iface %p, index %lu, latency %s stub!\n", iface, index, wine_dbgstr_longlong(latency));
713 return E_NOTIMPL;
716 static HRESULT WINAPI media_object_Flush(IMediaObject *iface)
718 FIXME("iface %p stub!\n", iface);
719 return E_NOTIMPL;
722 static HRESULT WINAPI media_object_Discontinuity(IMediaObject *iface, DWORD index)
724 FIXME("iface %p, index %lu stub!\n", iface, index);
725 return E_NOTIMPL;
728 static HRESULT WINAPI media_object_AllocateStreamingResources(IMediaObject *iface)
730 FIXME("iface %p stub!\n", iface);
731 return E_NOTIMPL;
734 static HRESULT WINAPI media_object_FreeStreamingResources(IMediaObject *iface)
736 FIXME("iface %p stub!\n", iface);
737 return E_NOTIMPL;
740 static HRESULT WINAPI media_object_GetInputStatus(IMediaObject *iface, DWORD index, DWORD *flags)
742 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
743 return E_NOTIMPL;
746 static HRESULT WINAPI media_object_ProcessInput(IMediaObject *iface, DWORD index,
747 IMediaBuffer *buffer, DWORD flags, REFERENCE_TIME timestamp, REFERENCE_TIME timelength)
749 FIXME("iface %p, index %lu, buffer %p, flags %#lx, timestamp %s, timelength %s stub!\n", iface,
750 index, buffer, flags, wine_dbgstr_longlong(timestamp), wine_dbgstr_longlong(timelength));
751 return E_NOTIMPL;
754 static HRESULT WINAPI media_object_ProcessOutput(IMediaObject *iface, DWORD flags, DWORD count,
755 DMO_OUTPUT_DATA_BUFFER *buffers, DWORD *status)
757 FIXME("iface %p, flags %#lx, count %lu, buffers %p, status %p stub!\n", iface, flags, count, buffers, status);
758 return E_NOTIMPL;
761 static HRESULT WINAPI media_object_Lock(IMediaObject *iface, LONG lock)
763 FIXME("iface %p, lock %ld stub!\n", iface, lock);
764 return E_NOTIMPL;
767 static const IMediaObjectVtbl media_object_vtbl =
769 media_object_QueryInterface,
770 media_object_AddRef,
771 media_object_Release,
772 media_object_GetStreamCount,
773 media_object_GetInputStreamInfo,
774 media_object_GetOutputStreamInfo,
775 media_object_GetInputType,
776 media_object_GetOutputType,
777 media_object_SetInputType,
778 media_object_SetOutputType,
779 media_object_GetInputCurrentType,
780 media_object_GetOutputCurrentType,
781 media_object_GetInputSizeInfo,
782 media_object_GetOutputSizeInfo,
783 media_object_GetInputMaxLatency,
784 media_object_SetInputMaxLatency,
785 media_object_Flush,
786 media_object_Discontinuity,
787 media_object_AllocateStreamingResources,
788 media_object_FreeStreamingResources,
789 media_object_GetInputStatus,
790 media_object_ProcessInput,
791 media_object_ProcessOutput,
792 media_object_Lock,
795 static inline struct wma_decoder *impl_from_IPropertyBag(IPropertyBag *iface)
797 return CONTAINING_RECORD(iface, struct wma_decoder, IPropertyBag_iface);
800 static HRESULT WINAPI property_bag_QueryInterface(IPropertyBag *iface, REFIID iid, void **out)
802 struct wma_decoder *filter = impl_from_IPropertyBag(iface);
803 return IUnknown_QueryInterface(filter->outer, iid, out);
806 static ULONG WINAPI property_bag_AddRef(IPropertyBag *iface)
808 struct wma_decoder *filter = impl_from_IPropertyBag(iface);
809 return IUnknown_AddRef(filter->outer);
812 static ULONG WINAPI property_bag_Release(IPropertyBag *iface)
814 struct wma_decoder *filter = impl_from_IPropertyBag(iface);
815 return IUnknown_Release(filter->outer);
818 static HRESULT WINAPI property_bag_Read(IPropertyBag *iface, const WCHAR *prop_name, VARIANT *value,
819 IErrorLog *error_log)
821 FIXME("iface %p, prop_name %s, value %p, error_log %p stub!\n", iface, debugstr_w(prop_name), value, error_log);
822 return E_NOTIMPL;
825 static HRESULT WINAPI property_bag_Write(IPropertyBag *iface, const WCHAR *prop_name, VARIANT *value)
827 FIXME("iface %p, prop_name %s, value %p stub!\n", iface, debugstr_w(prop_name), value);
828 return S_OK;
831 static const IPropertyBagVtbl property_bag_vtbl =
833 property_bag_QueryInterface,
834 property_bag_AddRef,
835 property_bag_Release,
836 property_bag_Read,
837 property_bag_Write,
840 HRESULT wma_decoder_create(IUnknown *outer, IUnknown **out)
842 static const struct wg_format output_format =
844 .major_type = WG_MAJOR_TYPE_AUDIO,
845 .u.audio =
847 .format = WG_AUDIO_FORMAT_F32LE,
848 .channel_mask = 1,
849 .channels = 1,
850 .rate = 44100,
853 static const struct wg_format input_format = {.major_type = WG_MAJOR_TYPE_AUDIO_WMA};
854 struct wg_transform *transform;
855 struct wma_decoder *decoder;
856 HRESULT hr;
858 TRACE("outer %p, out %p.\n", outer, out);
860 if (!(transform = wg_transform_create(&input_format, &output_format)))
862 ERR_(winediag)("GStreamer doesn't support WMA decoding, please install appropriate plugins\n");
863 return E_FAIL;
865 wg_transform_destroy(transform);
867 if (!(decoder = calloc(1, sizeof(*decoder))))
868 return E_OUTOFMEMORY;
870 if (FAILED(hr = wg_sample_queue_create(&decoder->wg_sample_queue)))
872 free(decoder);
873 return hr;
876 decoder->IUnknown_inner.lpVtbl = &unknown_vtbl;
877 decoder->IMFTransform_iface.lpVtbl = &transform_vtbl;
878 decoder->IMediaObject_iface.lpVtbl = &media_object_vtbl;
879 decoder->IPropertyBag_iface.lpVtbl = &property_bag_vtbl;
880 decoder->refcount = 1;
881 decoder->outer = outer ? outer : &decoder->IUnknown_inner;
883 decoder->input_info.cbAlignment = 1;
884 decoder->output_info.cbAlignment = 1;
886 *out = &decoder->IUnknown_inner;
887 TRACE("Created decoder %p\n", *out);
888 return S_OK;