dmime: Support playing secondary and control segments.
[wine.git] / dlls / dmusic / download.c
blob008e52edbfdb46417738068e7217086df5de6bd4
1 /*
2 * IDirectMusicDownload Implementation
4 * Copyright (C) 2003-2004 Rok Mandeljc
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "dmusic_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
25 struct download
27 IDirectMusicDownload IDirectMusicDownload_iface;
28 LONG ref;
30 DWORD size;
31 BYTE data[];
34 C_ASSERT(sizeof(struct download) == offsetof(struct download, data[0]));
36 static inline struct download *impl_from_IDirectMusicDownload(IDirectMusicDownload *iface)
38 return CONTAINING_RECORD(iface, struct download, IDirectMusicDownload_iface);
41 static HRESULT WINAPI download_QueryInterface(IDirectMusicDownload *iface, REFIID riid, void **ret_iface)
43 TRACE("(%p, %s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
45 if (IsEqualIID(riid, &IID_IUnknown) ||
46 IsEqualIID(riid, &IID_IDirectMusicDownload))
48 IDirectMusicDownload_AddRef(iface);
49 *ret_iface = iface;
50 return S_OK;
53 *ret_iface = NULL;
54 WARN("(%p, %s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
55 return E_NOINTERFACE;
58 static ULONG WINAPI download_AddRef(IDirectMusicDownload *iface)
60 struct download *This = impl_from_IDirectMusicDownload(iface);
61 ULONG ref = InterlockedIncrement(&This->ref);
63 TRACE("(%p): new ref = %lu\n", iface, ref);
65 return ref;
68 static ULONG WINAPI download_Release(IDirectMusicDownload *iface)
70 struct download *This = impl_from_IDirectMusicDownload(iface);
71 ULONG ref = InterlockedDecrement(&This->ref);
73 TRACE("(%p): new ref = %lu\n", iface, ref);
75 if (!ref) {
76 free(This);
79 return ref;
82 static HRESULT WINAPI download_GetBuffer(IDirectMusicDownload *iface, void **buffer, DWORD *size)
84 struct download *This = impl_from_IDirectMusicDownload(iface);
86 TRACE("(%p, %p, %p)\n", iface, buffer, size);
88 *buffer = This->data;
89 *size = This->size;
91 return S_OK;
94 static const IDirectMusicDownloadVtbl download_vtbl =
96 download_QueryInterface,
97 download_AddRef,
98 download_Release,
99 download_GetBuffer,
102 HRESULT download_create(DWORD size, IDirectMusicDownload **ret_iface)
104 struct download *download;
106 *ret_iface = NULL;
107 if (!(download = malloc(offsetof(struct download, data[size])))) return E_OUTOFMEMORY;
108 download->IDirectMusicDownload_iface.lpVtbl = &download_vtbl;
109 download->ref = 1;
110 download->size = size;
112 TRACE("Created DirectMusicDownload %p\n", download);
113 *ret_iface = &download->IDirectMusicDownload_iface;
114 return S_OK;