xref: /reactos/dll/directx/wine/msdmo/dmort.c (revision 7fdc6821)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Copyright (C) 2003 Michael Günnewig
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck  * License as published by the Free Software Foundation; either
7c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck  *
9c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12c2c66affSColin Finck  * Lesser General Public License for more details.
13c2c66affSColin Finck  *
14c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck  */
18c2c66affSColin Finck 
19*7fdc6821SAmine Khaldi #include <stdarg.h>
20c2c66affSColin Finck 
21*7fdc6821SAmine Khaldi #define COBJMACROS
22*7fdc6821SAmine Khaldi 
23*7fdc6821SAmine Khaldi #include "windef.h"
24*7fdc6821SAmine Khaldi #include "winbase.h"
25*7fdc6821SAmine Khaldi #include "objbase.h"
26*7fdc6821SAmine Khaldi #include "mediaobj.h"
27*7fdc6821SAmine Khaldi #include "dmort.h"
28*7fdc6821SAmine Khaldi 
29*7fdc6821SAmine Khaldi #include "wine/debug.h"
30*7fdc6821SAmine Khaldi 
31*7fdc6821SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
32c2c66affSColin Finck 
33c2c66affSColin Finck /***********************************************************************
34c2c66affSColin Finck  *        MoCreateMediaType    (MSDMO.@)
35c2c66affSColin Finck  *
36c2c66affSColin Finck  * Allocate a new media type structure
37c2c66affSColin Finck  */
MoCreateMediaType(DMO_MEDIA_TYPE ** ppmedia,DWORD cbFormat)38c2c66affSColin Finck HRESULT WINAPI MoCreateMediaType(DMO_MEDIA_TYPE** ppmedia, DWORD cbFormat)
39c2c66affSColin Finck {
40c2c66affSColin Finck     HRESULT r;
41c2c66affSColin Finck 
42c2c66affSColin Finck     TRACE("%p %u\n", ppmedia, cbFormat);
43c2c66affSColin Finck 
44c2c66affSColin Finck     if (!ppmedia)
45c2c66affSColin Finck         return E_POINTER;
46c2c66affSColin Finck 
47c2c66affSColin Finck     *ppmedia = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
48c2c66affSColin Finck     if (!*ppmedia)
49c2c66affSColin Finck         return E_OUTOFMEMORY;
50c2c66affSColin Finck 
51c2c66affSColin Finck     r = MoInitMediaType(*ppmedia, cbFormat);
52c2c66affSColin Finck     if (FAILED(r))
53c2c66affSColin Finck     {
54c2c66affSColin Finck         CoTaskMemFree(*ppmedia);
55c2c66affSColin Finck         *ppmedia = NULL;
56c2c66affSColin Finck     }
57c2c66affSColin Finck 
58c2c66affSColin Finck     return r;
59c2c66affSColin Finck }
60c2c66affSColin Finck 
61c2c66affSColin Finck /***********************************************************************
62c2c66affSColin Finck  *        MoInitMediaType        (MSDMO.@)
63c2c66affSColin Finck  *
64c2c66affSColin Finck  * Initialize media type structure
65c2c66affSColin Finck  */
MoInitMediaType(DMO_MEDIA_TYPE * pmedia,DWORD cbFormat)66c2c66affSColin Finck HRESULT WINAPI MoInitMediaType(DMO_MEDIA_TYPE* pmedia, DWORD cbFormat)
67c2c66affSColin Finck {
68c2c66affSColin Finck     TRACE("%p %u\n", pmedia, cbFormat);
69c2c66affSColin Finck 
70c2c66affSColin Finck     if (!pmedia)
71c2c66affSColin Finck         return E_POINTER;
72c2c66affSColin Finck 
73c2c66affSColin Finck     memset(pmedia, 0, sizeof(DMO_MEDIA_TYPE));
74c2c66affSColin Finck 
75c2c66affSColin Finck     if (cbFormat > 0)
76c2c66affSColin Finck     {
77c2c66affSColin Finck         pmedia->pbFormat = CoTaskMemAlloc(cbFormat);
78c2c66affSColin Finck         if (!pmedia->pbFormat)
79c2c66affSColin Finck             return E_OUTOFMEMORY;
80c2c66affSColin Finck 
81c2c66affSColin Finck         pmedia->cbFormat = cbFormat;
82c2c66affSColin Finck     }
83c2c66affSColin Finck 
84c2c66affSColin Finck     return S_OK;
85c2c66affSColin Finck }
86c2c66affSColin Finck 
87c2c66affSColin Finck /***********************************************************************
88c2c66affSColin Finck  *        MoDeleteMediaType    (MSDMO.@)
89c2c66affSColin Finck  *
90c2c66affSColin Finck  * Delete a media type structure
91c2c66affSColin Finck  */
MoDeleteMediaType(DMO_MEDIA_TYPE * pmedia)92c2c66affSColin Finck HRESULT WINAPI MoDeleteMediaType(DMO_MEDIA_TYPE* pmedia)
93c2c66affSColin Finck {
94c2c66affSColin Finck     TRACE("%p\n", pmedia);
95c2c66affSColin Finck 
96c2c66affSColin Finck     if (!pmedia)
97c2c66affSColin Finck         return E_POINTER;
98c2c66affSColin Finck 
99c2c66affSColin Finck     MoFreeMediaType(pmedia);
100c2c66affSColin Finck     CoTaskMemFree(pmedia);
101c2c66affSColin Finck 
102c2c66affSColin Finck     return S_OK;
103c2c66affSColin Finck }
104c2c66affSColin Finck 
105c2c66affSColin Finck /***********************************************************************
106c2c66affSColin Finck  *        MoFreeMediaType        (MSDMO.@)
107c2c66affSColin Finck  *
108c2c66affSColin Finck  * Free allocated members of a media type structure
109c2c66affSColin Finck  */
MoFreeMediaType(DMO_MEDIA_TYPE * pmedia)110c2c66affSColin Finck HRESULT WINAPI MoFreeMediaType(DMO_MEDIA_TYPE* pmedia)
111c2c66affSColin Finck {
112c2c66affSColin Finck     TRACE("%p\n", pmedia);
113c2c66affSColin Finck 
114c2c66affSColin Finck     if (!pmedia)
115c2c66affSColin Finck         return E_POINTER;
116c2c66affSColin Finck 
117c2c66affSColin Finck     if (pmedia->pUnk)
118c2c66affSColin Finck     {
119c2c66affSColin Finck         IUnknown_Release(pmedia->pUnk);
120c2c66affSColin Finck         pmedia->pUnk = NULL;
121c2c66affSColin Finck     }
122c2c66affSColin Finck 
123c2c66affSColin Finck     CoTaskMemFree(pmedia->pbFormat);
124c2c66affSColin Finck     pmedia->pbFormat = NULL;
125c2c66affSColin Finck 
126c2c66affSColin Finck     return S_OK;
127c2c66affSColin Finck }
128c2c66affSColin Finck 
129c2c66affSColin Finck /***********************************************************************
130c2c66affSColin Finck  *        MoDuplicateMediaType    (MSDMO.@)
131c2c66affSColin Finck  *
132c2c66affSColin Finck  * Duplicates a media type structure
133c2c66affSColin Finck  */
MoDuplicateMediaType(DMO_MEDIA_TYPE ** ppdst,const DMO_MEDIA_TYPE * psrc)134c2c66affSColin Finck HRESULT WINAPI MoDuplicateMediaType(DMO_MEDIA_TYPE** ppdst,
135c2c66affSColin Finck                                     const DMO_MEDIA_TYPE* psrc)
136c2c66affSColin Finck {
137c2c66affSColin Finck     HRESULT r;
138c2c66affSColin Finck 
139c2c66affSColin Finck     TRACE("%p %p\n", ppdst, psrc);
140c2c66affSColin Finck 
141c2c66affSColin Finck     if (!ppdst || !psrc)
142c2c66affSColin Finck         return E_POINTER;
143c2c66affSColin Finck 
144c2c66affSColin Finck     *ppdst = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
145c2c66affSColin Finck     if (!*ppdst)
146c2c66affSColin Finck         return E_OUTOFMEMORY;
147c2c66affSColin Finck 
148c2c66affSColin Finck     r = MoCopyMediaType(*ppdst, psrc);
149c2c66affSColin Finck     if (FAILED(r))
150c2c66affSColin Finck     {
151c2c66affSColin Finck         MoFreeMediaType(*ppdst);
152c2c66affSColin Finck         *ppdst = NULL;
153c2c66affSColin Finck     }
154c2c66affSColin Finck 
155c2c66affSColin Finck     return r;
156c2c66affSColin Finck }
157c2c66affSColin Finck 
158c2c66affSColin Finck /***********************************************************************
159c2c66affSColin Finck  *        MoCopyMediaType        (MSDMO.@)
160c2c66affSColin Finck  *
161c2c66affSColin Finck  * Copy a new media type structure
162c2c66affSColin Finck  */
MoCopyMediaType(DMO_MEDIA_TYPE * pdst,const DMO_MEDIA_TYPE * psrc)163c2c66affSColin Finck HRESULT WINAPI MoCopyMediaType(DMO_MEDIA_TYPE* pdst,
164c2c66affSColin Finck                                const DMO_MEDIA_TYPE* psrc)
165c2c66affSColin Finck {
166c2c66affSColin Finck     TRACE("%p %p\n", pdst, psrc);
167c2c66affSColin Finck 
168c2c66affSColin Finck     if (!pdst || !psrc)
169c2c66affSColin Finck         return E_POINTER;
170c2c66affSColin Finck 
171c2c66affSColin Finck     pdst->majortype = psrc->majortype;
172c2c66affSColin Finck     pdst->subtype = psrc->subtype;
173c2c66affSColin Finck     pdst->formattype = psrc->formattype;
174c2c66affSColin Finck 
175c2c66affSColin Finck     pdst->bFixedSizeSamples    = psrc->bFixedSizeSamples;
176c2c66affSColin Finck     pdst->bTemporalCompression = psrc->bTemporalCompression;
177c2c66affSColin Finck     pdst->lSampleSize          = psrc->lSampleSize;
178c2c66affSColin Finck     pdst->cbFormat             = psrc->cbFormat;
179c2c66affSColin Finck 
180c2c66affSColin Finck     if (psrc->pbFormat && psrc->cbFormat > 0)
181c2c66affSColin Finck     {
182c2c66affSColin Finck         pdst->pbFormat = CoTaskMemAlloc(psrc->cbFormat);
183c2c66affSColin Finck         if (!pdst->pbFormat)
184c2c66affSColin Finck             return E_OUTOFMEMORY;
185c2c66affSColin Finck 
186c2c66affSColin Finck         memcpy(pdst->pbFormat, psrc->pbFormat, psrc->cbFormat);
187c2c66affSColin Finck     }
188c2c66affSColin Finck     else
189c2c66affSColin Finck         pdst->pbFormat = NULL;
190c2c66affSColin Finck 
191c2c66affSColin Finck     if (psrc->pUnk)
192c2c66affSColin Finck     {
193c2c66affSColin Finck         pdst->pUnk = psrc->pUnk;
194c2c66affSColin Finck         IUnknown_AddRef(pdst->pUnk);
195c2c66affSColin Finck     }
196c2c66affSColin Finck     else
197c2c66affSColin Finck         pdst->pUnk = NULL;
198c2c66affSColin Finck 
199c2c66affSColin Finck     return S_OK;
200c2c66affSColin Finck }
201