- Implemented Mo* methods.
[wine/wine64.git] / dlls / msdmo / dmort.c
blob827c5d05460078f4ba403a60d472c76c95cd9114
1 /*
2 * Copyright (C) 2003 Michael Günnewig
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define COM_NO_WINDOWS_H
20 #include "winbase.h"
21 #include "objbase.h"
22 #include "mediaobj.h"
23 #include "dmort.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
29 /***********************************************************************
30 * MoCreateMediaType (MSDMO.@)
32 HRESULT WINAPI MoCreateMediaType(DMO_MEDIA_TYPE** ppmedia, DWORD cbFormat)
34 HRESULT hr;
36 TRACE("(%p,%lu)\n", ppmedia, cbFormat);
38 if (ppmedia == NULL)
39 return E_POINTER;
41 *ppmedia = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
42 if (*ppmedia == NULL)
43 return E_OUTOFMEMORY;
45 hr = MoInitMediaType(*ppmedia, cbFormat);
46 if (FAILED(hr)) {
47 CoTaskMemFree(*ppmedia);
48 *ppmedia = NULL;
51 return hr;
54 /***********************************************************************
55 * MoInitMediaType (MSDMO.@)
57 HRESULT WINAPI MoInitMediaType(DMO_MEDIA_TYPE* pmedia, DWORD cbFormat)
59 TRACE("(%p,%lu)\n", pmedia,cbFormat);
61 if (pmedia == NULL)
62 return E_POINTER;
64 memset(pmedia, 0, sizeof(DMO_MEDIA_TYPE));
66 if (cbFormat > 0) {
67 pmedia->pbFormat = CoTaskMemAlloc(cbFormat);
68 if (pmedia->pbFormat == NULL)
69 return E_OUTOFMEMORY;
71 pmedia->cbFormat = cbFormat;
74 return S_OK;
77 /***********************************************************************
78 * MoDeleteMediaType (MSDMO.@)
80 HRESULT WINAPI MoDeleteMediaType(DMO_MEDIA_TYPE* pmedia)
82 TRACE("(%p)\n", pmedia);
84 if (pmedia == NULL)
85 return E_POINTER;
87 MoFreeMediaType(pmedia);
88 CoTaskMemFree(pmedia);
90 return S_OK;
93 /***********************************************************************
94 * MoFreeMediaType (MSDMO.@)
96 HRESULT WINAPI MoFreeMediaType(DMO_MEDIA_TYPE* pmedia)
98 TRACE("(%p)\n", pmedia);
100 if (pmedia == NULL)
101 return E_POINTER;
103 if (pmedia->pUnk != NULL) {
104 IUnknown_Release(pmedia->pUnk);
105 pmedia->pUnk = NULL;
108 if (pmedia->pbFormat != NULL) {
109 CoTaskMemFree(pmedia->pbFormat);
110 pmedia->pbFormat = NULL;
113 return S_OK;
116 /***********************************************************************
117 * MoDuplicateMediaType (MSDMO.@)
119 HRESULT WINAPI MoDuplicateMediaType(DMO_MEDIA_TYPE** ppdst,
120 const DMO_MEDIA_TYPE* psrc)
122 HRESULT hr;
124 TRACE("(%p,%p)\n", ppdst, psrc);
126 if (ppdst == NULL || psrc == NULL)
127 return E_POINTER;
129 *ppdst = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
130 if (*ppdst == NULL)
131 return E_OUTOFMEMORY;
133 hr = MoCopyMediaType(*ppdst, psrc);
134 if (FAILED(hr)) {
135 MoFreeMediaType(*ppdst);
136 *ppdst = NULL;
139 return hr;
142 /***********************************************************************
143 * MoCopyMediaType (MSDMO.@)
145 HRESULT WINAPI MoCopyMediaType(DMO_MEDIA_TYPE* pdst,
146 const DMO_MEDIA_TYPE* psrc)
148 TRACE("(%p,%p)\n", pdst, psrc);
150 if (pdst == NULL || psrc == NULL)
151 return E_POINTER;
153 memcpy(&pdst->majortype, &psrc->majortype, sizeof(psrc->majortype));
154 memcpy(&pdst->subtype, &psrc->subtype, sizeof(psrc->subtype));
155 memcpy(&pdst->formattype, &psrc->formattype, sizeof(psrc->formattype));
157 pdst->bFixedSizeSamples = psrc->bFixedSizeSamples;
158 pdst->bTemporalCompression = psrc->bTemporalCompression;
159 pdst->lSampleSize = psrc->lSampleSize;
160 pdst->cbFormat = psrc->cbFormat;
162 if (psrc->pbFormat != NULL && psrc->cbFormat > 0) {
163 pdst->pbFormat = CoTaskMemAlloc(psrc->cbFormat);
164 if (pdst->pbFormat == NULL)
165 return E_OUTOFMEMORY;
167 memcpy(pdst->pbFormat, psrc->pbFormat, psrc->cbFormat);
168 } else
169 pdst->pbFormat = NULL;
171 if (psrc->pUnk != NULL) {
172 pdst->pUnk = psrc->pUnk;
173 IUnknown_AddRef(pdst->pUnk);
174 } else
175 pdst->pUnk = NULL;
177 return S_OK;