ReactOS  0.4.15-dev-5606-gf34e425
dmort.c
Go to the documentation of this file.
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 
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "mediaobj.h"
27 #include "dmort.h"
28 
29 #include "wine/debug.h"
30 
32 
33 /***********************************************************************
34  * MoCreateMediaType (MSDMO.@)
35  *
36  * Allocate a new media type structure
37  */
39 {
40  HRESULT r;
41 
42  TRACE("%p %u\n", ppmedia, cbFormat);
43 
44  if (!ppmedia)
45  return E_POINTER;
46 
47  *ppmedia = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
48  if (!*ppmedia)
49  return E_OUTOFMEMORY;
50 
51  r = MoInitMediaType(*ppmedia, cbFormat);
52  if (FAILED(r))
53  {
54  CoTaskMemFree(*ppmedia);
55  *ppmedia = NULL;
56  }
57 
58  return r;
59 }
60 
61 /***********************************************************************
62  * MoInitMediaType (MSDMO.@)
63  *
64  * Initialize media type structure
65  */
67 {
68  TRACE("%p %u\n", pmedia, cbFormat);
69 
70  if (!pmedia)
71  return E_POINTER;
72 
73  memset(pmedia, 0, sizeof(DMO_MEDIA_TYPE));
74 
75  if (cbFormat > 0)
76  {
77  pmedia->pbFormat = CoTaskMemAlloc(cbFormat);
78  if (!pmedia->pbFormat)
79  return E_OUTOFMEMORY;
80 
81  pmedia->cbFormat = cbFormat;
82  }
83 
84  return S_OK;
85 }
86 
87 /***********************************************************************
88  * MoDeleteMediaType (MSDMO.@)
89  *
90  * Delete a media type structure
91  */
93 {
94  TRACE("%p\n", pmedia);
95 
96  if (!pmedia)
97  return E_POINTER;
98 
99  MoFreeMediaType(pmedia);
100  CoTaskMemFree(pmedia);
101 
102  return S_OK;
103 }
104 
105 /***********************************************************************
106  * MoFreeMediaType (MSDMO.@)
107  *
108  * Free allocated members of a media type structure
109  */
111 {
112  TRACE("%p\n", pmedia);
113 
114  if (!pmedia)
115  return E_POINTER;
116 
117  if (pmedia->pUnk)
118  {
119  IUnknown_Release(pmedia->pUnk);
120  pmedia->pUnk = NULL;
121  }
122 
123  CoTaskMemFree(pmedia->pbFormat);
124  pmedia->pbFormat = NULL;
125 
126  return S_OK;
127 }
128 
129 /***********************************************************************
130  * MoDuplicateMediaType (MSDMO.@)
131  *
132  * Duplicates a media type structure
133  */
135  const DMO_MEDIA_TYPE* psrc)
136 {
137  HRESULT r;
138 
139  TRACE("%p %p\n", ppdst, psrc);
140 
141  if (!ppdst || !psrc)
142  return E_POINTER;
143 
144  *ppdst = CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
145  if (!*ppdst)
146  return E_OUTOFMEMORY;
147 
148  r = MoCopyMediaType(*ppdst, psrc);
149  if (FAILED(r))
150  {
151  MoFreeMediaType(*ppdst);
152  *ppdst = NULL;
153  }
154 
155  return r;
156 }
157 
158 /***********************************************************************
159  * MoCopyMediaType (MSDMO.@)
160  *
161  * Copy a new media type structure
162  */
164  const DMO_MEDIA_TYPE* psrc)
165 {
166  TRACE("%p %p\n", pdst, psrc);
167 
168  if (!pdst || !psrc)
169  return E_POINTER;
170 
171  pdst->majortype = psrc->majortype;
172  pdst->subtype = psrc->subtype;
173  pdst->formattype = psrc->formattype;
174 
175  pdst->bFixedSizeSamples = psrc->bFixedSizeSamples;
177  pdst->lSampleSize = psrc->lSampleSize;
178  pdst->cbFormat = psrc->cbFormat;
179 
180  if (psrc->pbFormat && psrc->cbFormat > 0)
181  {
182  pdst->pbFormat = CoTaskMemAlloc(psrc->cbFormat);
183  if (!pdst->pbFormat)
184  return E_OUTOFMEMORY;
185 
186  memcpy(pdst->pbFormat, psrc->pbFormat, psrc->cbFormat);
187  }
188  else
189  pdst->pbFormat = NULL;
190 
191  if (psrc->pUnk)
192  {
193  pdst->pUnk = psrc->pUnk;
194  IUnknown_AddRef(pdst->pUnk);
195  }
196  else
197  pdst->pUnk = NULL;
198 
199  return S_OK;
200 }
HRESULT WINAPI MoCopyMediaType(DMO_MEDIA_TYPE *pdst, const DMO_MEDIA_TYPE *psrc)
Definition: dmort.c:163
HRESULT WINAPI MoDuplicateMediaType(DMO_MEDIA_TYPE **ppdst, const DMO_MEDIA_TYPE *psrc)
Definition: dmort.c:134
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BYTE * pbFormat
Definition: mediaobj.idl:44
ULONG lSampleSize
Definition: mediaobj.idl:40
BOOL bTemporalCompression
Definition: mediaobj.idl:39
HRESULT WINAPI MoInitMediaType(DMO_MEDIA_TYPE *pmedia, DWORD cbFormat)
Definition: dmort.c:66
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
IUnknown * pUnk
Definition: mediaobj.idl:42
#define TRACE(s)
Definition: solgame.cpp:4
ULONG cbFormat
Definition: mediaobj.idl:43
LONG HRESULT
Definition: typedefs.h:79
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL bFixedSizeSamples
Definition: mediaobj.idl:38
WINE_DEFAULT_DEBUG_CHANNEL(msdmo)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GUID formattype
Definition: mediaobj.idl:41
#define S_OK
Definition: intsafe.h:52
HRESULT WINAPI MoDeleteMediaType(DMO_MEDIA_TYPE *pmedia)
Definition: dmort.c:92
GUID majortype
Definition: mediaobj.idl:36
#define NULL
Definition: types.h:112
HRESULT WINAPI MoFreeMediaType(DMO_MEDIA_TYPE *pmedia)
Definition: dmort.c:110
#define E_POINTER
Definition: winerror.h:2365
#define memset(x, y, z)
Definition: compat.h:39
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
HRESULT WINAPI MoCreateMediaType(DMO_MEDIA_TYPE **ppmedia, DWORD cbFormat)
Definition: dmort.c:38