9102781c049eaec83e58f837b9c6e983f09eb2f8
[reactos.git] / reactos / dll / directx / wine / msdmo / dmort.c
1 /*
2 * Copyright (C) 2003 Michael G├╝nnewig
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #include <windef.h>
27 #include <winbase.h>
28 #include <objbase.h>
29 #include <mediaobj.h>
30 #include <dmort.h>
31
32 #include <wine/debug.h>
33
34 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
35
36 /***********************************************************************
37 * MoCreateMediaType (MSDMO.@)
38 *
39 * Allocate a new media type structure
40 */
41 HRESULT WINAPI MoCreateMediaType(DMO_MEDIA_TYPE** ppmedia, DWORD cbFormat)
42 {
43 HRESULT r;
44
45 TRACE("%p %u\n", ppmedia, cbFormat);
46
47 if (!ppmedia)
48 return E_POINTER;
49
50 *ppmedia = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
51 if (!*ppmedia)
52 return E_OUTOFMEMORY;
53
54 r = MoInitMediaType(*ppmedia, cbFormat);
55 if (FAILED(r))
56 {
57 CoTaskMemFree(*ppmedia);
58 *ppmedia = NULL;
59 }
60
61 return r;
62 }
63
64 /***********************************************************************
65 * MoInitMediaType (MSDMO.@)
66 *
67 * Initialize media type structure
68 */
69 HRESULT WINAPI MoInitMediaType(DMO_MEDIA_TYPE* pmedia, DWORD cbFormat)
70 {
71 TRACE("%p %u\n", pmedia, cbFormat);
72
73 if (!pmedia)
74 return E_POINTER;
75
76 memset(pmedia, 0, sizeof(DMO_MEDIA_TYPE));
77
78 if (cbFormat > 0)
79 {
80 pmedia->pbFormat = CoTaskMemAlloc(cbFormat);
81 if (!pmedia->pbFormat)
82 return E_OUTOFMEMORY;
83
84 pmedia->cbFormat = cbFormat;
85 }
86
87 return S_OK;
88 }
89
90 /***********************************************************************
91 * MoDeleteMediaType (MSDMO.@)
92 *
93 * Delete a media type structure
94 */
95 HRESULT WINAPI MoDeleteMediaType(DMO_MEDIA_TYPE* pmedia)
96 {
97 TRACE("%p\n", pmedia);
98
99 if (!pmedia)
100 return E_POINTER;
101
102 MoFreeMediaType(pmedia);
103 CoTaskMemFree(pmedia);
104
105 return S_OK;
106 }
107
108 /***********************************************************************
109 * MoFreeMediaType (MSDMO.@)
110 *
111 * Free allocated members of a media type structure
112 */
113 HRESULT WINAPI MoFreeMediaType(DMO_MEDIA_TYPE* pmedia)
114 {
115 TRACE("%p\n", pmedia);
116
117 if (!pmedia)
118 return E_POINTER;
119
120 if (pmedia->pUnk)
121 {
122 IUnknown_Release(pmedia->pUnk);
123 pmedia->pUnk = NULL;
124 }
125
126 CoTaskMemFree(pmedia->pbFormat);
127 pmedia->pbFormat = NULL;
128
129 return S_OK;
130 }
131
132 /***********************************************************************
133 * MoDuplicateMediaType (MSDMO.@)
134 *
135 * Duplicates a media type structure
136 */
137 HRESULT WINAPI MoDuplicateMediaType(DMO_MEDIA_TYPE** ppdst,
138 const DMO_MEDIA_TYPE* psrc)
139 {
140 HRESULT r;
141
142 TRACE("%p %p\n", ppdst, psrc);
143
144 if (!ppdst || !psrc)
145 return E_POINTER;
146
147 *ppdst = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
148 if (!*ppdst)
149 return E_OUTOFMEMORY;
150
151 r = MoCopyMediaType(*ppdst, psrc);
152 if (FAILED(r))
153 {
154 MoFreeMediaType(*ppdst);
155 *ppdst = NULL;
156 }
157
158 return r;
159 }
160
161 /***********************************************************************
162 * MoCopyMediaType (MSDMO.@)
163 *
164 * Copy a new media type structure
165 */
166 HRESULT WINAPI MoCopyMediaType(DMO_MEDIA_TYPE* pdst,
167 const DMO_MEDIA_TYPE* psrc)
168 {
169 TRACE("%p %p\n", pdst, psrc);
170
171 if (!pdst || !psrc)
172 return E_POINTER;
173
174 pdst->majortype = psrc->majortype;
175 pdst->subtype = psrc->subtype;
176 pdst->formattype = psrc->formattype;
177
178 pdst->bFixedSizeSamples = psrc->bFixedSizeSamples;
179 pdst->bTemporalCompression = psrc->bTemporalCompression;
180 pdst->lSampleSize = psrc->lSampleSize;
181 pdst->cbFormat = psrc->cbFormat;
182
183 if (psrc->pbFormat && psrc->cbFormat > 0)
184 {
185 pdst->pbFormat = CoTaskMemAlloc(psrc->cbFormat);
186 if (!pdst->pbFormat)
187 return E_OUTOFMEMORY;
188
189 memcpy(pdst->pbFormat, psrc->pbFormat, psrc->cbFormat);
190 }
191 else
192 pdst->pbFormat = NULL;
193
194 if (psrc->pUnk)
195 {
196 pdst->pUnk = psrc->pUnk;
197 IUnknown_AddRef(pdst->pUnk);
198 }
199 else
200 pdst->pUnk = NULL;
201
202 return S_OK;
203 }