xmllite: Drop superfluous casts to self.
[wine.git] / dlls / strmbase / mediatype.c
blob9544d1b8baee236b807ed4d6e545a9622986f154
1 /*
2 * Implementation of MedaType utility functions
4 * Copyright 2003 Robert Shearman
5 * Copyright 2010 Aric Stewart, CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "strmbase_private.h"
23 #include "dvdmedia.h"
24 #include "dxva.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
28 static const struct
30 const GUID *guid;
31 const char *name;
33 strmbase_guids[] =
35 #define X(g) {&(g), #g}
36 X(GUID_NULL),
38 #undef OUR_GUID_ENTRY
39 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) X(name),
40 #include "uuids.h"
42 #undef X
45 static const char *strmbase_debugstr_guid(const GUID *guid)
47 unsigned int i;
49 for (i = 0; i < ARRAY_SIZE(strmbase_guids); ++i)
51 if (IsEqualGUID(strmbase_guids[i].guid, guid))
52 return wine_dbg_sprintf("%s", strmbase_guids[i].name);
55 return debugstr_guid(guid);
58 static const char *debugstr_fourcc(DWORD fourcc)
60 char str[4] = {fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24};
61 if (isprint(str[0]) && isprint(str[1]) && isprint(str[2]) && isprint(str[3]))
62 return wine_dbgstr_an(str, 4);
63 return wine_dbg_sprintf("%#x", fourcc);
66 void strmbase_dump_media_type(const AM_MEDIA_TYPE *mt)
68 if (!TRACE_ON(strmbase) || !mt) return;
70 TRACE("Dumping media type %p: major type %s, subtype %s",
71 mt, strmbase_debugstr_guid(&mt->majortype), strmbase_debugstr_guid(&mt->subtype));
72 if (mt->bFixedSizeSamples) TRACE(", fixed size samples");
73 if (mt->bTemporalCompression) TRACE(", temporal compression");
74 if (mt->lSampleSize) TRACE(", sample size %d", mt->lSampleSize);
75 if (mt->pUnk) TRACE(", pUnk %p", mt->pUnk);
76 TRACE(", format type %s.\n", strmbase_debugstr_guid(&mt->formattype));
78 if (!mt->pbFormat) return;
80 TRACE("Dumping format %p: ", mt->pbFormat);
82 if (IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) && mt->cbFormat >= sizeof(WAVEFORMATEX))
84 WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
86 TRACE("tag %#x, %u channels, sample rate %u, %u bytes/sec, alignment %u, %u bits/sample.\n",
87 wfx->wFormatTag, wfx->nChannels, wfx->nSamplesPerSec,
88 wfx->nAvgBytesPerSec, wfx->nBlockAlign, wfx->wBitsPerSample);
90 if (wfx->cbSize)
92 const unsigned char *extra = (const unsigned char *)(wfx + 1);
93 unsigned int i;
95 TRACE(" Extra bytes:");
96 for (i = 0; i < wfx->cbSize; ++i)
98 if (!(i % 16)) TRACE("\n ");
99 TRACE(" %02x", extra[i]);
101 TRACE("\n");
104 else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo) && mt->cbFormat >= sizeof(VIDEOINFOHEADER))
106 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)mt->pbFormat;
108 if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
109 if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
110 if (vih->dwBitRate) TRACE("bitrate %u, ", vih->dwBitRate);
111 if (vih->dwBitErrorRate) TRACE("error rate %u, ", vih->dwBitErrorRate);
112 TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
113 TRACE("size %dx%d, %u planes, %u bpp, compression %s, image size %u",
114 vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
115 vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
116 vih->bmiHeader.biSizeImage);
117 if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
118 TRACE(", resolution %dx%d", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
119 if (vih->bmiHeader.biClrUsed) TRACE(", %d colours", vih->bmiHeader.biClrUsed);
120 if (vih->bmiHeader.biClrImportant) TRACE(", %d important colours", vih->bmiHeader.biClrImportant);
121 TRACE(".\n");
123 else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo2) && mt->cbFormat >= sizeof(VIDEOINFOHEADER2))
125 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2 *)mt->pbFormat;
127 if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
128 if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
129 if (vih->dwBitRate) TRACE("bitrate %u, ", vih->dwBitRate);
130 if (vih->dwBitErrorRate) TRACE("error rate %u, ", vih->dwBitErrorRate);
131 TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
132 if (vih->dwInterlaceFlags) TRACE("interlace flags %#x, ", vih->dwInterlaceFlags);
133 if (vih->dwCopyProtectFlags) TRACE("copy-protection flags %#x, ", vih->dwCopyProtectFlags);
134 TRACE("aspect ratio %u/%u, ", vih->dwPictAspectRatioX, vih->dwPictAspectRatioY);
135 if (vih->u.dwControlFlags) TRACE("control flags %#x, ", vih->u.dwControlFlags);
136 if (vih->u.dwControlFlags & AMCONTROL_COLORINFO_PRESENT)
138 const DXVA_ExtendedFormat *colorimetry = (const DXVA_ExtendedFormat *)&vih->u.dwControlFlags;
140 TRACE("chroma site %#x, range %#x, matrix %#x, lighting %#x, primaries %#x, transfer function %#x, ",
141 colorimetry->VideoChromaSubsampling, colorimetry->NominalRange, colorimetry->VideoTransferMatrix,
142 colorimetry->VideoLighting, colorimetry->VideoPrimaries, colorimetry->VideoTransferFunction);
144 TRACE("size %dx%d, %u planes, %u bpp, compression %s, image size %u",
145 vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
146 vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
147 vih->bmiHeader.biSizeImage);
148 if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
149 TRACE(", resolution %dx%d", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
150 if (vih->bmiHeader.biClrUsed) TRACE(", %d colours", vih->bmiHeader.biClrUsed);
151 if (vih->bmiHeader.biClrImportant) TRACE(", %d important colours", vih->bmiHeader.biClrImportant);
152 TRACE(".\n");
154 else
155 TRACE("not implemented for this format type.\n");
158 HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *dest, const AM_MEDIA_TYPE *src)
160 *dest = *src;
161 if (src->pbFormat)
163 dest->pbFormat = CoTaskMemAlloc(src->cbFormat);
164 if (!dest->pbFormat)
165 return E_OUTOFMEMORY;
166 memcpy(dest->pbFormat, src->pbFormat, src->cbFormat);
168 if (dest->pUnk)
169 IUnknown_AddRef(dest->pUnk);
170 return S_OK;
173 void WINAPI FreeMediaType(AM_MEDIA_TYPE * pMediaType)
175 CoTaskMemFree(pMediaType->pbFormat);
176 pMediaType->pbFormat = NULL;
177 if (pMediaType->pUnk)
179 IUnknown_Release(pMediaType->pUnk);
180 pMediaType->pUnk = NULL;
184 AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const * pSrc)
186 AM_MEDIA_TYPE * pDest;
188 pDest = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
189 if (!pDest)
190 return NULL;
192 if (FAILED(CopyMediaType(pDest, pSrc)))
194 CoTaskMemFree(pDest);
195 return NULL;
198 return pDest;
201 void WINAPI DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
203 FreeMediaType(pMediaType);
204 CoTaskMemFree(pMediaType);