mfplay: Keep user callback reference.
[wine.git] / dlls / mfplay / player.c
blob6905812835a28c9b59240b5a69644b8ed7027971
1 /*
2 * Copyright 2019 Nikolay Sivov for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "mfplay.h"
27 #include "wine/debug.h"
28 #include "wine/heap.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
32 struct media_player
34 IMFPMediaPlayer IMFPMediaPlayer_iface;
35 LONG refcount;
36 IMFPMediaPlayerCallback *callback;
39 static struct media_player *impl_from_IMFPMediaPlayer(IMFPMediaPlayer *iface)
41 return CONTAINING_RECORD(iface, struct media_player, IMFPMediaPlayer_iface);
44 static HRESULT WINAPI media_player_QueryInterface(IMFPMediaPlayer *iface, REFIID riid, void **obj)
46 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
48 if (IsEqualIID(riid, &IID_IMFPMediaPlayer) ||
49 IsEqualIID(riid, &IID_IUnknown))
51 *obj = iface;
52 IMFPMediaPlayer_AddRef(iface);
53 return S_OK;
56 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
57 *obj = NULL;
59 return E_NOINTERFACE;
62 static ULONG WINAPI media_player_AddRef(IMFPMediaPlayer *iface)
64 struct media_player *player = impl_from_IMFPMediaPlayer(iface);
65 ULONG refcount = InterlockedIncrement(&player->refcount);
67 TRACE("%p, refcount %u.\n", iface, refcount);
69 return refcount;
72 static ULONG WINAPI media_player_Release(IMFPMediaPlayer *iface)
74 struct media_player *player = impl_from_IMFPMediaPlayer(iface);
75 ULONG refcount = InterlockedDecrement(&player->refcount);
77 TRACE("%p, refcount %u.\n", iface, refcount);
79 if (!refcount)
81 if (player->callback)
82 IMFPMediaPlayerCallback_Release(player->callback);
83 heap_free(player);
86 return refcount;
89 static HRESULT WINAPI media_player_Play(IMFPMediaPlayer *iface)
91 FIXME("%p.\n", iface);
93 return E_NOTIMPL;
96 static HRESULT WINAPI media_player_Pause(IMFPMediaPlayer *iface)
98 FIXME("%p.\n", iface);
100 return E_NOTIMPL;
103 static HRESULT WINAPI media_player_Stop(IMFPMediaPlayer *iface)
105 FIXME("%p.\n", iface);
107 return E_NOTIMPL;
110 static HRESULT WINAPI media_player_FrameStep(IMFPMediaPlayer *iface)
112 FIXME("%p.\n", iface);
114 return E_NOTIMPL;
117 static HRESULT WINAPI media_player_SetPosition(IMFPMediaPlayer *iface, REFGUID postype, const PROPVARIANT *position)
119 FIXME("%p, %s, %p.\n", iface, debugstr_guid(postype), position);
121 return E_NOTIMPL;
124 static HRESULT WINAPI media_player_GetPosition(IMFPMediaPlayer *iface, REFGUID postype, PROPVARIANT *position)
126 FIXME("%p, %s, %p.\n", iface, debugstr_guid(postype), position);
128 return E_NOTIMPL;
131 static HRESULT WINAPI media_player_GetDuration(IMFPMediaPlayer *iface, REFGUID postype, PROPVARIANT *position)
133 FIXME("%p, %s, %p.\n", iface, debugstr_guid(postype), position);
135 return E_NOTIMPL;
138 static HRESULT WINAPI media_player_SetRate(IMFPMediaPlayer *iface, float rate)
140 FIXME("%p, %f.\n", iface, rate);
142 return E_NOTIMPL;
145 static HRESULT WINAPI media_player_GetRate(IMFPMediaPlayer *iface, float *rate)
147 FIXME("%p, %p.\n", iface, rate);
149 return E_NOTIMPL;
152 static HRESULT WINAPI media_player_GetSupportedRates(IMFPMediaPlayer *iface, BOOL forward, float *slowest_rate, float *fastest_rate)
154 FIXME("%p, %d, %p, %p.\n", iface, forward, slowest_rate, fastest_rate);
156 return E_NOTIMPL;
159 static HRESULT WINAPI media_player_GetState(IMFPMediaPlayer *iface, MFP_MEDIAPLAYER_STATE *state)
161 FIXME("%p, %p.\n", iface, state);
163 return E_NOTIMPL;
166 static HRESULT WINAPI media_player_CreateMediaItemFromURL(IMFPMediaPlayer *iface,
167 const WCHAR *url, BOOL sync, DWORD_PTR user_data, IMFPMediaItem **item)
169 FIXME("%p, %s, %d, %lx, %p.\n", iface, debugstr_w(url), sync, user_data, item);
171 return E_NOTIMPL;
174 static HRESULT WINAPI media_player_CreateMediaItemFromObject(IMFPMediaPlayer *iface,
175 IUnknown *object, BOOL sync, DWORD_PTR user_data, IMFPMediaItem **item)
177 FIXME("%p, %p, %d, %lx, %p.\n", iface, object, sync, user_data, item);
179 return E_NOTIMPL;
182 static HRESULT WINAPI media_player_SetMediaItem(IMFPMediaPlayer *iface, IMFPMediaItem *item)
184 FIXME("%p, %p.\n", iface, item);
186 return E_NOTIMPL;
189 static HRESULT WINAPI media_player_ClearMediaItem(IMFPMediaPlayer *iface)
191 FIXME("%p.\n", iface);
193 return E_NOTIMPL;
196 static HRESULT WINAPI media_player_GetMediaItem(IMFPMediaPlayer *iface, IMFPMediaItem **item)
198 FIXME("%p, %p.\n", iface, item);
200 return E_NOTIMPL;
203 static HRESULT WINAPI media_player_GetVolume(IMFPMediaPlayer *iface, float *volume)
205 FIXME("%p, %p.\n", iface, volume);
207 return E_NOTIMPL;
210 static HRESULT WINAPI media_player_SetVolume(IMFPMediaPlayer *iface, float volume)
212 FIXME("%p, %.8e.\n", iface, volume);
214 return E_NOTIMPL;
217 static HRESULT WINAPI media_player_GetBalance(IMFPMediaPlayer *iface, float *balance)
219 FIXME("%p, %p.\n", iface, balance);
221 return E_NOTIMPL;
224 static HRESULT WINAPI media_player_SetBalance(IMFPMediaPlayer *iface, float balance)
226 FIXME("%p, %.8e.\n", iface, balance);
228 return E_NOTIMPL;
231 static HRESULT WINAPI media_player_GetMute(IMFPMediaPlayer *iface, BOOL *mute)
233 FIXME("%p, %p.\n", iface, mute);
235 return E_NOTIMPL;
238 static HRESULT WINAPI media_player_SetMute(IMFPMediaPlayer *iface, BOOL mute)
240 FIXME("%p, %d.\n", iface, mute);
242 return E_NOTIMPL;
245 static HRESULT WINAPI media_player_GetNativeVideoSize(IMFPMediaPlayer *iface,
246 SIZE *video, SIZE *arvideo)
248 FIXME("%p, %p, %p.\n", iface, video, arvideo);
250 return E_NOTIMPL;
253 static HRESULT WINAPI media_player_GetIdealVideoSize(IMFPMediaPlayer *iface,
254 SIZE *min_size, SIZE *max_size)
256 FIXME("%p, %p, %p.\n", iface, min_size, max_size);
258 return E_NOTIMPL;
261 static HRESULT WINAPI media_player_SetVideoSourceRect(IMFPMediaPlayer *iface,
262 MFVideoNormalizedRect const *rect)
264 FIXME("%p, %p.\n", iface, rect);
266 return E_NOTIMPL;
269 static HRESULT WINAPI media_player_GetVideoSourceRect(IMFPMediaPlayer *iface,
270 MFVideoNormalizedRect *rect)
272 FIXME("%p, %p.\n", iface, rect);
274 return E_NOTIMPL;
277 static HRESULT WINAPI media_player_SetAspectRatioMode(IMFPMediaPlayer *iface, DWORD mode)
279 FIXME("%p, %u.\n", iface, mode);
281 return E_NOTIMPL;
284 static HRESULT WINAPI media_player_GetAspectRatioMode(IMFPMediaPlayer *iface,
285 DWORD *mode)
287 FIXME("%p, %p.\n", iface, mode);
289 return E_NOTIMPL;
292 static HRESULT WINAPI media_player_GetVideoWindow(IMFPMediaPlayer *iface, HWND *hwnd)
294 FIXME("%p, %p.\n", iface, hwnd);
296 return E_NOTIMPL;
299 static HRESULT WINAPI media_player_UpdateVideo(IMFPMediaPlayer *iface)
301 FIXME("%p.\n", iface);
303 return E_NOTIMPL;
306 static HRESULT WINAPI media_player_SetBorderColor(IMFPMediaPlayer *iface, COLORREF color)
308 FIXME("%p, %#x.\n", iface, color);
310 return E_NOTIMPL;
313 static HRESULT WINAPI media_player_GetBorderColor(IMFPMediaPlayer *iface, COLORREF *color)
315 FIXME("%p, %p.\n", iface, color);
317 return E_NOTIMPL;
320 static HRESULT WINAPI media_player_InsertEffect(IMFPMediaPlayer *iface, IUnknown *effect,
321 BOOL optional)
323 FIXME("%p, %p, %d.\n", iface, effect, optional);
325 return E_NOTIMPL;
328 static HRESULT WINAPI media_player_RemoveEffect(IMFPMediaPlayer *iface, IUnknown *effect)
330 FIXME("%p, %p.\n", iface, effect);
332 return E_NOTIMPL;
335 static HRESULT WINAPI media_player_RemoveAllEffects(IMFPMediaPlayer *iface)
337 FIXME("%p.\n", iface);
339 return E_NOTIMPL;
342 static HRESULT WINAPI media_player_Shutdown(IMFPMediaPlayer *iface)
344 FIXME("%p.\n", iface);
346 return E_NOTIMPL;
349 static const IMFPMediaPlayerVtbl media_player_vtbl =
351 media_player_QueryInterface,
352 media_player_AddRef,
353 media_player_Release,
354 media_player_Play,
355 media_player_Pause,
356 media_player_Stop,
357 media_player_FrameStep,
358 media_player_SetPosition,
359 media_player_GetPosition,
360 media_player_GetDuration,
361 media_player_SetRate,
362 media_player_GetRate,
363 media_player_GetSupportedRates,
364 media_player_GetState,
365 media_player_CreateMediaItemFromURL,
366 media_player_CreateMediaItemFromObject,
367 media_player_SetMediaItem,
368 media_player_ClearMediaItem,
369 media_player_GetMediaItem,
370 media_player_GetVolume,
371 media_player_SetVolume,
372 media_player_GetBalance,
373 media_player_SetBalance,
374 media_player_GetMute,
375 media_player_SetMute,
376 media_player_GetNativeVideoSize,
377 media_player_GetIdealVideoSize,
378 media_player_SetVideoSourceRect,
379 media_player_GetVideoSourceRect,
380 media_player_SetAspectRatioMode,
381 media_player_GetAspectRatioMode,
382 media_player_GetVideoWindow,
383 media_player_UpdateVideo,
384 media_player_SetBorderColor,
385 media_player_GetBorderColor,
386 media_player_InsertEffect,
387 media_player_RemoveEffect,
388 media_player_RemoveAllEffects,
389 media_player_Shutdown,
392 HRESULT WINAPI MFPCreateMediaPlayer(const WCHAR *url, BOOL start_playback, MFP_CREATION_OPTIONS options,
393 IMFPMediaPlayerCallback *callback, HWND hwnd, IMFPMediaPlayer **player)
395 struct media_player *object;
397 TRACE("%s, %d, %#x, %p, %p, %p.\n", debugstr_w(url), start_playback, options, callback, hwnd, player);
399 if (!(object = heap_alloc_zero(sizeof(*object))))
400 return E_OUTOFMEMORY;
402 object->IMFPMediaPlayer_iface.lpVtbl = &media_player_vtbl;
403 object->refcount = 1;
404 object->callback = callback;
405 if (object->callback)
406 IMFPMediaPlayerCallback_AddRef(object->callback);
408 *player = &object->IMFPMediaPlayer_iface;
410 return S_OK;