cmd: DIR command outputs free space for the path.
[wine.git] / dlls / winegstreamer / wmv_decoder.c
blob89da25074c64efd0aa7b17ccb515fbe6b35c6e15
1 /* Copyright 2022 RĂ©mi Bernon for CodeWeavers
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 #include "gst_private.h"
20 #include "mfapi.h"
21 #include "mferror.h"
22 #include "mediaerr.h"
23 #include "mfobjects.h"
24 #include "mftransform.h"
25 #include "wmcodecdsp.h"
26 #include "initguid.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
31 WINE_DECLARE_DEBUG_CHANNEL(winediag);
33 extern const GUID MEDIASUBTYPE_VC1S;
35 DEFINE_GUID(MEDIASUBTYPE_WMV_Unknown, 0x7ce12ca9,0xbfbf,0x43d9,0x9d,0x00,0x82,0xb8,0xed,0x54,0x31,0x6b);
37 struct decoder_type
39 const GUID *subtype;
40 WORD bpp;
41 DWORD compression;
44 static const GUID *const wmv_decoder_input_types[] =
46 &MEDIASUBTYPE_WMV1,
47 &MEDIASUBTYPE_WMV2,
48 &MEDIASUBTYPE_WMVA,
49 &MEDIASUBTYPE_WMVP,
50 &MEDIASUBTYPE_WVP2,
51 &MEDIASUBTYPE_WMV_Unknown,
52 &MEDIASUBTYPE_WVC1,
53 &MEDIASUBTYPE_WMV3,
54 &MEDIASUBTYPE_VC1S,
57 static const struct decoder_type wmv_decoder_output_types[] =
59 { &MEDIASUBTYPE_NV12, 12, MAKEFOURCC('N', 'V', '1', '2') },
60 { &MEDIASUBTYPE_YV12, 12, MAKEFOURCC('Y', 'V', '1', '2') },
61 { &MEDIASUBTYPE_IYUV, 12, MAKEFOURCC('I', 'Y', 'U', 'V') },
62 { &MEDIASUBTYPE_I420, 12, MAKEFOURCC('I', '4', '2', '0') },
63 { &MEDIASUBTYPE_YUY2, 16, MAKEFOURCC('Y', 'U', 'Y', '2') },
64 { &MEDIASUBTYPE_UYVY, 16, MAKEFOURCC('U', 'Y', 'V', 'Y') },
65 { &MEDIASUBTYPE_YVYU, 16, MAKEFOURCC('Y', 'V', 'Y', 'U') },
66 { &MEDIASUBTYPE_NV11, 12, MAKEFOURCC('N', 'V', '1', '1') },
67 { &MEDIASUBTYPE_RGB32, 32, BI_RGB },
68 { &MEDIASUBTYPE_RGB24, 24, BI_RGB },
69 { &MEDIASUBTYPE_RGB565, 16, BI_BITFIELDS },
70 { &MEDIASUBTYPE_RGB555, 16, BI_RGB },
71 { &MEDIASUBTYPE_RGB8, 8, BI_RGB },
74 struct wmv_decoder
76 IUnknown IUnknown_inner;
77 IMFTransform IMFTransform_iface;
78 IMediaObject IMediaObject_iface;
79 IPropertyBag IPropertyBag_iface;
80 IPropertyStore IPropertyStore_iface;
81 IUnknown *outer;
82 LONG refcount;
84 struct wg_format input_format;
85 struct wg_format output_format;
86 GUID output_subtype;
88 wg_transform_t wg_transform;
89 struct wg_sample_queue *wg_sample_queue;
92 static bool wg_format_is_set(struct wg_format *format)
94 return format->major_type != WG_MAJOR_TYPE_UNKNOWN;
97 static inline struct wmv_decoder *impl_from_IUnknown(IUnknown *iface)
99 return CONTAINING_RECORD(iface, struct wmv_decoder, IUnknown_inner);
102 static HRESULT WINAPI unknown_QueryInterface(IUnknown *iface, REFIID iid, void **out)
104 struct wmv_decoder *impl = impl_from_IUnknown(iface);
106 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
108 if (IsEqualGUID(iid, &IID_IUnknown))
109 *out = &impl->IUnknown_inner;
110 else if (IsEqualGUID(iid, &IID_IMFTransform))
111 *out = &impl->IMFTransform_iface;
112 else if (IsEqualGUID(iid, &IID_IMediaObject))
113 *out = &impl->IMediaObject_iface;
114 else if (IsEqualIID(iid, &IID_IPropertyBag))
115 *out = &impl->IPropertyBag_iface;
116 else if (IsEqualIID(iid, &IID_IPropertyStore))
117 *out = &impl->IPropertyStore_iface;
118 else
120 *out = NULL;
121 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
122 return E_NOINTERFACE;
125 IUnknown_AddRef((IUnknown *)*out);
126 return S_OK;
129 static ULONG WINAPI unknown_AddRef(IUnknown *iface)
131 struct wmv_decoder *impl = impl_from_IUnknown(iface);
132 ULONG refcount = InterlockedIncrement(&impl->refcount);
134 TRACE("iface %p increasing refcount to %lu.\n", iface, refcount);
136 return refcount;
139 static ULONG WINAPI unknown_Release(IUnknown *iface)
141 struct wmv_decoder *impl = impl_from_IUnknown(iface);
142 ULONG refcount = InterlockedDecrement(&impl->refcount);
144 TRACE("iface %p decreasing refcount to %lu.\n", iface, refcount);
146 if (!refcount)
148 if (impl->wg_transform)
149 wg_transform_destroy(impl->wg_transform);
150 wg_sample_queue_destroy(impl->wg_sample_queue);
151 free(impl);
154 return refcount;
157 static const IUnknownVtbl unknown_vtbl =
159 unknown_QueryInterface,
160 unknown_AddRef,
161 unknown_Release,
164 static struct wmv_decoder *impl_from_IMFTransform(IMFTransform *iface)
166 return CONTAINING_RECORD(iface, struct wmv_decoder, IMFTransform_iface);
169 static HRESULT WINAPI transform_QueryInterface(IMFTransform *iface, REFIID iid, void **out)
171 return IUnknown_QueryInterface(impl_from_IMFTransform(iface)->outer, iid, out);
174 static ULONG WINAPI transform_AddRef(IMFTransform *iface)
176 return IUnknown_AddRef(impl_from_IMFTransform(iface)->outer);
179 static ULONG WINAPI transform_Release(IMFTransform *iface)
181 return IUnknown_Release(impl_from_IMFTransform(iface)->outer);
184 static HRESULT WINAPI transform_GetStreamLimits(IMFTransform *iface, DWORD *input_minimum,
185 DWORD *input_maximum, DWORD *output_minimum, DWORD *output_maximum)
187 TRACE("iface %p, input_minimum %p, input_maximum %p, output_minimum %p, output_maximum %p.\n",
188 iface, input_minimum, input_maximum, output_minimum, output_maximum);
189 *input_minimum = *input_maximum = *output_minimum = *output_maximum = 1;
190 return S_OK;
193 static HRESULT WINAPI transform_GetStreamCount(IMFTransform *iface, DWORD *inputs, DWORD *outputs)
195 TRACE("iface %p, inputs %p, outputs %p.\n", iface, inputs, outputs);
196 *inputs = *outputs = 1;
197 return S_OK;
200 static HRESULT WINAPI transform_GetStreamIDs(IMFTransform *iface, DWORD input_size, DWORD *inputs,
201 DWORD output_size, DWORD *outputs)
203 TRACE("iface %p, input_size %lu, inputs %p, output_size %lu, outputs %p.\n", iface,
204 input_size, inputs, output_size, outputs);
205 return E_NOTIMPL;
208 static HRESULT WINAPI transform_GetInputStreamInfo(IMFTransform *iface, DWORD id, MFT_INPUT_STREAM_INFO *info)
210 FIXME("iface %p, id %#lx, info %p stub!\n", iface, id, info);
211 return E_NOTIMPL;
214 static HRESULT WINAPI transform_GetOutputStreamInfo(IMFTransform *iface, DWORD id, MFT_OUTPUT_STREAM_INFO *info)
216 FIXME("iface %p, id %#lx, info %p stub!\n", iface, id, info);
217 return E_NOTIMPL;
220 static HRESULT WINAPI transform_GetAttributes(IMFTransform *iface, IMFAttributes **attributes)
222 FIXME("iface %p, attributes %p stub!\n", iface, attributes);
223 return E_NOTIMPL;
226 static HRESULT WINAPI transform_GetInputStreamAttributes(IMFTransform *iface, DWORD id, IMFAttributes **attributes)
228 TRACE("iface %p, id %#lx, attributes %p.\n", iface, id, attributes);
229 return E_NOTIMPL;
232 static HRESULT WINAPI transform_GetOutputStreamAttributes(IMFTransform *iface, DWORD id, IMFAttributes **attributes)
234 FIXME("iface %p, id %#lx, attributes %p stub!\n", iface, id, attributes);
235 return E_NOTIMPL;
238 static HRESULT WINAPI transform_DeleteInputStream(IMFTransform *iface, DWORD id)
240 TRACE("iface %p, id %#lx.\n", iface, id);
241 return E_NOTIMPL;
244 static HRESULT WINAPI transform_AddInputStreams(IMFTransform *iface, DWORD streams, DWORD *ids)
246 TRACE("iface %p, streams %lu, ids %p.\n", iface, streams, ids);
247 return E_NOTIMPL;
250 static HRESULT WINAPI transform_GetInputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
251 IMFMediaType **type)
253 FIXME("iface %p, id %#lx, index %lu, type %p stub!\n", iface, id, index, type);
254 return E_NOTIMPL;
257 static HRESULT WINAPI transform_GetOutputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
258 IMFMediaType **type)
260 FIXME("iface %p, id %#lx, index %lu, type %p stub!\n", iface, id, index, type);
261 return E_NOTIMPL;
264 static HRESULT WINAPI transform_SetInputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
266 FIXME("iface %p, id %#lx, type %p, flags %#lx stub!\n", iface, id, type, flags);
267 return E_NOTIMPL;
270 static HRESULT WINAPI transform_SetOutputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
272 FIXME("iface %p, id %#lx, type %p, flags %#lx stub!\n", iface, id, type, flags);
273 return E_NOTIMPL;
276 static HRESULT WINAPI transform_GetInputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
278 FIXME("iface %p, id %#lx, type %p stub!\n", iface, id, type);
279 return E_NOTIMPL;
282 static HRESULT WINAPI transform_GetOutputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
284 FIXME("iface %p, id %#lx, type %p stub!\n", iface, id, type);
285 return E_NOTIMPL;
288 static HRESULT WINAPI transform_GetInputStatus(IMFTransform *iface, DWORD id, DWORD *flags)
290 FIXME("iface %p, id %#lx, flags %p stub!\n", iface, id, flags);
291 return E_NOTIMPL;
294 static HRESULT WINAPI transform_GetOutputStatus(IMFTransform *iface, DWORD *flags)
296 FIXME("iface %p, flags %p stub!\n", iface, flags);
297 return E_NOTIMPL;
300 static HRESULT WINAPI transform_SetOutputBounds(IMFTransform *iface, LONGLONG lower, LONGLONG upper)
302 TRACE("iface %p, lower %I64d, upper %I64d.\n", iface, lower, upper);
303 return E_NOTIMPL;
306 static HRESULT WINAPI transform_ProcessEvent(IMFTransform *iface, DWORD id, IMFMediaEvent *event)
308 FIXME("iface %p, id %#lx, event %p stub!\n", iface, id, event);
309 return E_NOTIMPL;
312 static HRESULT WINAPI transform_ProcessMessage(IMFTransform *iface, MFT_MESSAGE_TYPE message, ULONG_PTR param)
314 FIXME("iface %p, message %#x, param %#Ix stub!\n", iface, message, param);
315 return E_NOTIMPL;
318 static HRESULT WINAPI transform_ProcessInput(IMFTransform *iface, DWORD id, IMFSample *sample, DWORD flags)
320 FIXME("iface %p, id %#lx, sample %p, flags %#lx stub!\n", iface, id, sample, flags);
321 return E_NOTIMPL;
324 static HRESULT WINAPI transform_ProcessOutput(IMFTransform *iface, DWORD flags, DWORD count,
325 MFT_OUTPUT_DATA_BUFFER *samples, DWORD *status)
327 FIXME("iface %p, flags %#lx, count %lu, samples %p, status %p stub!\n", iface, flags, count, samples, status);
328 return E_NOTIMPL;
331 static const IMFTransformVtbl transform_vtbl =
333 transform_QueryInterface,
334 transform_AddRef,
335 transform_Release,
336 transform_GetStreamLimits,
337 transform_GetStreamCount,
338 transform_GetStreamIDs,
339 transform_GetInputStreamInfo,
340 transform_GetOutputStreamInfo,
341 transform_GetAttributes,
342 transform_GetInputStreamAttributes,
343 transform_GetOutputStreamAttributes,
344 transform_DeleteInputStream,
345 transform_AddInputStreams,
346 transform_GetInputAvailableType,
347 transform_GetOutputAvailableType,
348 transform_SetInputType,
349 transform_SetOutputType,
350 transform_GetInputCurrentType,
351 transform_GetOutputCurrentType,
352 transform_GetInputStatus,
353 transform_GetOutputStatus,
354 transform_SetOutputBounds,
355 transform_ProcessEvent,
356 transform_ProcessMessage,
357 transform_ProcessInput,
358 transform_ProcessOutput,
361 static inline struct wmv_decoder *impl_from_IMediaObject(IMediaObject *iface)
363 return CONTAINING_RECORD(iface, struct wmv_decoder, IMediaObject_iface);
366 static HRESULT WINAPI media_object_QueryInterface(IMediaObject *iface, REFIID iid, void **obj)
368 return IUnknown_QueryInterface(impl_from_IMediaObject(iface)->outer, iid, obj);
371 static ULONG WINAPI media_object_AddRef(IMediaObject *iface)
373 return IUnknown_AddRef(impl_from_IMediaObject(iface)->outer);
376 static ULONG WINAPI media_object_Release(IMediaObject *iface)
378 return IUnknown_Release(impl_from_IMediaObject(iface)->outer);
381 static HRESULT WINAPI media_object_GetStreamCount(IMediaObject *iface, DWORD *input, DWORD *output)
383 TRACE("iface %p, input %p, output %p.\n", iface, input, output);
385 if (!input || !output)
386 return E_POINTER;
388 *input = *output = 1;
390 return S_OK;
393 static HRESULT WINAPI media_object_GetInputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
395 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
396 return E_NOTIMPL;
399 static HRESULT WINAPI media_object_GetOutputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
401 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
402 return E_NOTIMPL;
405 static HRESULT WINAPI media_object_GetInputType(IMediaObject *iface, DWORD index, DWORD type_index,
406 DMO_MEDIA_TYPE *type)
408 TRACE("iface %p, index %lu, type_index %lu, type %p.\n", iface, index, type_index, type);
410 if (index > 0)
411 return DMO_E_INVALIDSTREAMINDEX;
412 if (type_index >= ARRAY_SIZE(wmv_decoder_input_types))
413 return DMO_E_NO_MORE_ITEMS;
414 if (!type)
415 return S_OK;
417 memset(type, 0, sizeof(*type));
418 type->majortype = MFMediaType_Video;
419 type->subtype = *wmv_decoder_input_types[type_index];
420 type->bFixedSizeSamples = FALSE;
421 type->bTemporalCompression = TRUE;
422 type->lSampleSize = 0;
424 return S_OK;
427 static HRESULT WINAPI media_object_GetOutputType(IMediaObject *iface, DWORD index, DWORD type_index,
428 DMO_MEDIA_TYPE *type)
430 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
431 VIDEOINFOHEADER *info;
432 const GUID *subtype;
433 LONG width, height;
434 UINT32 image_size;
435 HRESULT hr;
437 TRACE("iface %p, index %lu, type_index %lu, type %p.\n", iface, index, type_index, type);
439 if (index > 0)
440 return DMO_E_INVALIDSTREAMINDEX;
441 if (type_index >= ARRAY_SIZE(wmv_decoder_output_types))
442 return DMO_E_NO_MORE_ITEMS;
443 if (!type)
444 return S_OK;
445 if (!wg_format_is_set(&decoder->input_format))
446 return DMO_E_TYPE_NOT_SET;
448 width = decoder->input_format.u.video_wmv.width;
449 height = abs(decoder->input_format.u.video_wmv.height);
450 subtype = wmv_decoder_output_types[type_index].subtype;
451 if (FAILED(hr = MFCalculateImageSize(subtype, width, height, &image_size)))
453 FIXME("Failed to get image size of subtype %s.\n", debugstr_guid(subtype));
454 return hr;
457 memset(type, 0, sizeof(*type));
458 type->majortype = MFMediaType_Video;
459 type->subtype = *subtype;
460 type->bFixedSizeSamples = TRUE;
461 type->bTemporalCompression = FALSE;
462 type->lSampleSize = image_size;
463 type->formattype = FORMAT_VideoInfo;
464 type->cbFormat = sizeof(VIDEOINFOHEADER);
465 type->pbFormat = CoTaskMemAlloc(type->cbFormat);
466 memset(type->pbFormat, 0, type->cbFormat);
468 info = (VIDEOINFOHEADER *)type->pbFormat;
469 info->rcSource.right = width;
470 info->rcSource.bottom = height;
471 info->rcTarget.right = width;
472 info->rcTarget.bottom = height;
473 info->bmiHeader.biSize = sizeof(info->bmiHeader);
474 info->bmiHeader.biWidth = width;
475 info->bmiHeader.biHeight = height;
476 info->bmiHeader.biPlanes = 1;
477 info->bmiHeader.biBitCount = wmv_decoder_output_types[type_index].bpp;
478 info->bmiHeader.biCompression = wmv_decoder_output_types[type_index].compression;
479 info->bmiHeader.biSizeImage = image_size;
481 return S_OK;
484 static HRESULT WINAPI media_object_SetInputType(IMediaObject *iface, DWORD index,
485 const DMO_MEDIA_TYPE *type, DWORD flags)
487 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
488 struct wg_format wg_format;
489 unsigned int i;
491 TRACE("iface %p, index %lu, type %p, flags %#lx.\n", iface, index, type, flags);
493 if (index > 0)
494 return DMO_E_INVALIDSTREAMINDEX;
496 if (!type)
498 if (flags & DMO_SET_TYPEF_CLEAR)
500 memset(&decoder->input_format, 0, sizeof(decoder->input_format));
501 if (decoder->wg_transform)
503 wg_transform_destroy(decoder->wg_transform);
504 decoder->wg_transform = 0;
506 return S_OK;
508 return DMO_E_TYPE_NOT_ACCEPTED;
511 if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Video))
512 return DMO_E_TYPE_NOT_ACCEPTED;
514 for (i = 0; i < ARRAY_SIZE(wmv_decoder_input_types); ++i)
515 if (IsEqualGUID(&type->subtype, wmv_decoder_input_types[i]))
516 break;
517 if (i == ARRAY_SIZE(wmv_decoder_input_types))
518 return DMO_E_TYPE_NOT_ACCEPTED;
520 if (!amt_to_wg_format((const AM_MEDIA_TYPE *)type, &wg_format))
521 return DMO_E_TYPE_NOT_ACCEPTED;
522 assert(wg_format.major_type == WG_MAJOR_TYPE_VIDEO_WMV);
523 wg_format.u.video_wmv.fps_n = 0;
524 wg_format.u.video_wmv.fps_d = 0;
526 if (flags & DMO_SET_TYPEF_TEST_ONLY)
527 return S_OK;
529 decoder->input_format = wg_format;
530 if (decoder->wg_transform)
532 wg_transform_destroy(decoder->wg_transform);
533 decoder->wg_transform = 0;
536 return S_OK;
539 static HRESULT WINAPI media_object_SetOutputType(IMediaObject *iface, DWORD index,
540 const DMO_MEDIA_TYPE *type, DWORD flags)
542 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
543 struct wg_transform_attrs attrs = {0};
544 struct wg_format wg_format;
545 unsigned int i;
547 TRACE("iface %p, index %lu, type %p, flags %#lx,\n", iface, index, type, flags);
549 if (index > 0)
550 return DMO_E_INVALIDSTREAMINDEX;
552 if (!type)
554 if (flags & DMO_SET_TYPEF_CLEAR)
556 memset(&decoder->output_format, 0, sizeof(decoder->output_format));
557 if (decoder->wg_transform)
559 wg_transform_destroy(decoder->wg_transform);
560 decoder->wg_transform = 0;
562 return S_OK;
564 return E_POINTER;
567 if (!wg_format_is_set(&decoder->input_format))
568 return DMO_E_TYPE_NOT_SET;
570 if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Video))
571 return DMO_E_TYPE_NOT_ACCEPTED;
573 for (i = 0; i < ARRAY_SIZE(wmv_decoder_output_types); ++i)
574 if (IsEqualGUID(&type->subtype, wmv_decoder_output_types[i].subtype))
575 break;
576 if (i == ARRAY_SIZE(wmv_decoder_output_types))
577 return DMO_E_TYPE_NOT_ACCEPTED;
579 if (!amt_to_wg_format((const AM_MEDIA_TYPE *)type, &wg_format))
580 return DMO_E_TYPE_NOT_ACCEPTED;
581 assert(wg_format.major_type == WG_MAJOR_TYPE_VIDEO);
582 wg_format.u.video.fps_n = 0;
583 wg_format.u.video.fps_d = 0;
585 if (flags & DMO_SET_TYPEF_TEST_ONLY)
586 return S_OK;
588 decoder->output_subtype = type->subtype;
589 decoder->output_format = wg_format;
591 /* Set up wg_transform. */
592 if (decoder->wg_transform)
594 wg_transform_destroy(decoder->wg_transform);
595 decoder->wg_transform = 0;
597 if (!(decoder->wg_transform = wg_transform_create(&decoder->input_format, &decoder->output_format, &attrs)))
598 return E_FAIL;
600 return S_OK;
603 static HRESULT WINAPI media_object_GetInputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
605 FIXME("iface %p, index %lu, type %p stub!\n", iface, index, type);
606 return E_NOTIMPL;
609 static HRESULT WINAPI media_object_GetOutputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
611 FIXME("iface %p, index %lu, type %p stub!\n", iface, index, type);
612 return E_NOTIMPL;
615 static HRESULT WINAPI media_object_GetInputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size,
616 DWORD *lookahead, DWORD *alignment)
618 FIXME("iface %p, index %lu, size %p, lookahead %p, alignment %p stub!\n", iface, index, size,
619 lookahead, alignment);
620 return E_NOTIMPL;
623 static HRESULT WINAPI media_object_GetOutputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size, DWORD *alignment)
625 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
626 HRESULT hr;
628 TRACE("iface %p, index %lu, size %p, alignment %p.\n", iface, index, size, alignment);
630 if (index > 0)
631 return DMO_E_INVALIDSTREAMINDEX;
632 if (!wg_format_is_set(&decoder->output_format))
633 return DMO_E_TYPE_NOT_SET;
635 if (FAILED(hr = MFCalculateImageSize(&decoder->output_subtype,
636 decoder->output_format.u.video.width, abs(decoder->output_format.u.video.height), (UINT32 *)size)))
638 FIXME("Failed to get image size of subtype %s.\n", debugstr_guid(&decoder->output_subtype));
639 return hr;
641 *alignment = 1;
643 return S_OK;
646 static HRESULT WINAPI media_object_GetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME *latency)
648 FIXME("iface %p, index %lu, latency %p stub!\n", iface, index, latency);
649 return E_NOTIMPL;
652 static HRESULT WINAPI media_object_SetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME latency)
654 FIXME("iface %p, index %lu, latency %s stub!\n", iface, index, wine_dbgstr_longlong(latency));
655 return E_NOTIMPL;
658 static HRESULT WINAPI media_object_Flush(IMediaObject *iface)
660 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
661 HRESULT hr;
663 TRACE("iface %p.\n", iface);
665 if (FAILED(hr = wg_transform_flush(decoder->wg_transform)))
666 return hr;
668 wg_sample_queue_flush(decoder->wg_sample_queue, TRUE);
670 return S_OK;
673 static HRESULT WINAPI media_object_Discontinuity(IMediaObject *iface, DWORD index)
675 TRACE("iface %p, index %lu.\n", iface, index);
677 if (index > 0)
678 return DMO_E_INVALIDSTREAMINDEX;
680 return S_OK;
683 static HRESULT WINAPI media_object_AllocateStreamingResources(IMediaObject *iface)
685 FIXME("iface %p stub!\n", iface);
686 return E_NOTIMPL;
689 static HRESULT WINAPI media_object_FreeStreamingResources(IMediaObject *iface)
691 FIXME("iface %p stub!\n", iface);
692 return E_NOTIMPL;
695 static HRESULT WINAPI media_object_GetInputStatus(IMediaObject *iface, DWORD index, DWORD *flags)
697 TRACE("iface %p, index %lu, flags %p.\n", iface, index, flags);
699 if (index > 0)
700 return DMO_E_INVALIDSTREAMINDEX;
701 if (!flags)
702 return E_POINTER;
704 *flags = DMO_INPUT_STATUSF_ACCEPT_DATA;
706 return S_OK;
709 static HRESULT WINAPI media_object_ProcessInput(IMediaObject *iface, DWORD index,
710 IMediaBuffer *buffer, DWORD flags, REFERENCE_TIME timestamp, REFERENCE_TIME timelength)
712 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
714 TRACE("iface %p, index %lu, buffer %p, flags %#lx, timestamp %s, timelength %s.\n", iface,
715 index, buffer, flags, wine_dbgstr_longlong(timestamp), wine_dbgstr_longlong(timelength));
717 if (!decoder->wg_transform)
718 return DMO_E_TYPE_NOT_SET;
720 return wg_transform_push_dmo(decoder->wg_transform, buffer, flags, timestamp, timelength, decoder->wg_sample_queue);
723 static HRESULT WINAPI media_object_ProcessOutput(IMediaObject *iface, DWORD flags, DWORD count,
724 DMO_OUTPUT_DATA_BUFFER *buffers, DWORD *status)
726 struct wmv_decoder *decoder = impl_from_IMediaObject(iface);
727 HRESULT hr;
729 TRACE("iface %p, flags %#lx, count %lu, buffers %p, status %p.\n", iface, flags, count, buffers, status);
731 if (!decoder->wg_transform)
732 return DMO_E_TYPE_NOT_SET;
734 if ((hr = wg_transform_read_dmo(decoder->wg_transform, buffers)) == MF_E_TRANSFORM_STREAM_CHANGE)
735 hr = wg_transform_read_dmo(decoder->wg_transform, buffers);
737 if (SUCCEEDED(hr))
738 wg_sample_queue_flush(decoder->wg_sample_queue, false);
740 return hr;
743 static HRESULT WINAPI media_object_Lock(IMediaObject *iface, LONG lock)
745 FIXME("iface %p, lock %ld stub!\n", iface, lock);
746 return E_NOTIMPL;
749 static const IMediaObjectVtbl media_object_vtbl =
751 media_object_QueryInterface,
752 media_object_AddRef,
753 media_object_Release,
754 media_object_GetStreamCount,
755 media_object_GetInputStreamInfo,
756 media_object_GetOutputStreamInfo,
757 media_object_GetInputType,
758 media_object_GetOutputType,
759 media_object_SetInputType,
760 media_object_SetOutputType,
761 media_object_GetInputCurrentType,
762 media_object_GetOutputCurrentType,
763 media_object_GetInputSizeInfo,
764 media_object_GetOutputSizeInfo,
765 media_object_GetInputMaxLatency,
766 media_object_SetInputMaxLatency,
767 media_object_Flush,
768 media_object_Discontinuity,
769 media_object_AllocateStreamingResources,
770 media_object_FreeStreamingResources,
771 media_object_GetInputStatus,
772 media_object_ProcessInput,
773 media_object_ProcessOutput,
774 media_object_Lock,
777 static inline struct wmv_decoder *impl_from_IPropertyBag(IPropertyBag *iface)
779 return CONTAINING_RECORD(iface, struct wmv_decoder, IPropertyBag_iface);
782 static HRESULT WINAPI property_bag_QueryInterface(IPropertyBag *iface, REFIID iid, void **out)
784 return IUnknown_QueryInterface(impl_from_IPropertyBag(iface)->outer, iid, out);
787 static ULONG WINAPI property_bag_AddRef(IPropertyBag *iface)
789 return IUnknown_AddRef(impl_from_IPropertyBag(iface)->outer);
792 static ULONG WINAPI property_bag_Release(IPropertyBag *iface)
794 return IUnknown_Release(impl_from_IPropertyBag(iface)->outer);
797 static HRESULT WINAPI property_bag_Read(IPropertyBag *iface, const WCHAR *prop_name, VARIANT *value,
798 IErrorLog *error_log)
800 FIXME("iface %p, prop_name %s, value %p, error_log %p stub!\n", iface, debugstr_w(prop_name), value, error_log);
801 return E_NOTIMPL;
804 static HRESULT WINAPI property_bag_Write(IPropertyBag *iface, const WCHAR *prop_name, VARIANT *value)
806 FIXME("iface %p, prop_name %s, value %p stub!\n", iface, debugstr_w(prop_name), value);
807 return S_OK;
810 static const IPropertyBagVtbl property_bag_vtbl =
812 property_bag_QueryInterface,
813 property_bag_AddRef,
814 property_bag_Release,
815 property_bag_Read,
816 property_bag_Write,
819 static inline struct wmv_decoder *impl_from_IPropertyStore(IPropertyStore *iface)
821 return CONTAINING_RECORD(iface, struct wmv_decoder, IPropertyStore_iface);
824 static HRESULT WINAPI property_store_QueryInterface(IPropertyStore *iface, REFIID iid, void **out)
826 return IUnknown_QueryInterface(impl_from_IPropertyStore(iface)->outer, iid, out);
829 static ULONG WINAPI property_store_AddRef(IPropertyStore *iface)
831 return IUnknown_AddRef(impl_from_IPropertyStore(iface)->outer);
834 static ULONG WINAPI property_store_Release(IPropertyStore *iface)
836 return IUnknown_Release(impl_from_IPropertyStore(iface)->outer);
839 static HRESULT WINAPI property_store_GetCount(IPropertyStore *iface, DWORD *count)
841 FIXME("iface %p, count %p stub!\n", iface, count);
842 return E_NOTIMPL;
845 static HRESULT WINAPI property_store_GetAt(IPropertyStore *iface, DWORD index, PROPERTYKEY *key)
847 FIXME("iface %p, index %lu, key %p stub!\n", iface, index, key);
848 return E_NOTIMPL;
851 static HRESULT WINAPI property_store_GetValue(IPropertyStore *iface, REFPROPERTYKEY key, PROPVARIANT *value)
853 FIXME("iface %p, key %p, value %p stub!\n", iface, key, value);
854 return E_NOTIMPL;
857 static HRESULT WINAPI property_store_SetValue(IPropertyStore *iface, REFPROPERTYKEY key, REFPROPVARIANT value)
859 FIXME("iface %p, key %p, value %p stub!\n", iface, key, value);
860 return E_NOTIMPL;
863 static HRESULT WINAPI property_store_Commit(IPropertyStore *iface)
865 FIXME("iface %p stub!\n", iface);
866 return E_NOTIMPL;
869 static const IPropertyStoreVtbl property_store_vtbl =
871 property_store_QueryInterface,
872 property_store_AddRef,
873 property_store_Release,
874 property_store_GetCount,
875 property_store_GetAt,
876 property_store_GetValue,
877 property_store_SetValue,
878 property_store_Commit,
881 HRESULT wmv_decoder_create(IUnknown *outer, IUnknown **out)
883 static const struct wg_format input_format =
885 .major_type = WG_MAJOR_TYPE_VIDEO_WMV,
886 .u.video_wmv.format = WG_WMV_VIDEO_FORMAT_WMV3,
888 static const struct wg_format output_format =
890 .major_type = WG_MAJOR_TYPE_VIDEO,
891 .u.video =
893 .format = WG_VIDEO_FORMAT_NV12,
894 .width = 1920,
895 .height = 1080,
898 struct wg_transform_attrs attrs = {0};
899 wg_transform_t transform;
900 struct wmv_decoder *decoder;
901 HRESULT hr;
903 TRACE("outer %p, out %p.\n", outer, out);
905 if (!(transform = wg_transform_create(&input_format, &output_format, &attrs)))
907 ERR_(winediag)("GStreamer doesn't support WMV decoding, please install appropriate plugins.\n");
908 return E_FAIL;
910 wg_transform_destroy(transform);
912 if (!(decoder = calloc(1, sizeof(*decoder))))
913 return E_OUTOFMEMORY;
914 if (FAILED(hr = wg_sample_queue_create(&decoder->wg_sample_queue)))
916 free(decoder);
917 return hr;
920 decoder->IUnknown_inner.lpVtbl = &unknown_vtbl;
921 decoder->IMFTransform_iface.lpVtbl = &transform_vtbl;
922 decoder->IMediaObject_iface.lpVtbl = &media_object_vtbl;
923 decoder->IPropertyBag_iface.lpVtbl = &property_bag_vtbl;
924 decoder->IPropertyStore_iface.lpVtbl = &property_store_vtbl;
925 decoder->refcount = 1;
926 decoder->outer = outer ? outer : &decoder->IUnknown_inner;
928 *out = &decoder->IUnknown_inner;
929 TRACE("Created %p\n", *out);
930 return S_OK;