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