include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / libs / strmbase / mediatype.c
blobaf813e2ffee0fa24e6b07c2daf13ef0536126515
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(quartz);
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 void strmbase_dump_media_type(const AM_MEDIA_TYPE *mt)
60 if (!TRACE_ON(quartz) || !mt) return;
62 TRACE("Dumping media type %p: major type %s, subtype %s",
63 mt, strmbase_debugstr_guid(&mt->majortype), strmbase_debugstr_guid(&mt->subtype));
64 if (mt->bFixedSizeSamples) TRACE(", fixed size samples");
65 if (mt->bTemporalCompression) TRACE(", temporal compression");
66 if (mt->lSampleSize) TRACE(", sample size %ld", mt->lSampleSize);
67 if (mt->pUnk) TRACE(", pUnk %p", mt->pUnk);
68 TRACE(", format type %s.\n", strmbase_debugstr_guid(&mt->formattype));
70 if (!mt->pbFormat) return;
72 TRACE("Dumping format %p: ", mt->pbFormat);
74 if (IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) && mt->cbFormat >= sizeof(WAVEFORMATEX))
76 WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
78 TRACE("tag %#x, %u channels, sample rate %lu, %lu bytes/sec, alignment %u, %u bits/sample.\n",
79 wfx->wFormatTag, wfx->nChannels, wfx->nSamplesPerSec,
80 wfx->nAvgBytesPerSec, wfx->nBlockAlign, wfx->wBitsPerSample);
82 if (wfx->cbSize)
84 const unsigned char *extra = (const unsigned char *)(wfx + 1);
85 unsigned int i;
87 TRACE(" Extra bytes:");
88 for (i = 0; i < wfx->cbSize; ++i)
90 if (!(i % 16)) TRACE("\n ");
91 TRACE(" %02x", extra[i]);
93 TRACE("\n");
96 else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo) && mt->cbFormat >= sizeof(VIDEOINFOHEADER))
98 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)mt->pbFormat;
100 if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
101 if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
102 if (vih->dwBitRate) TRACE("bitrate %lu, ", vih->dwBitRate);
103 if (vih->dwBitErrorRate) TRACE("error rate %lu, ", vih->dwBitErrorRate);
104 TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
105 TRACE("size %ldx%ld, %u planes, %u bpp, compression %s, image size %lu",
106 vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
107 vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
108 vih->bmiHeader.biSizeImage);
109 if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
110 TRACE(", resolution %ldx%ld", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
111 if (vih->bmiHeader.biClrUsed) TRACE(", %lu colours", vih->bmiHeader.biClrUsed);
112 if (vih->bmiHeader.biClrImportant) TRACE(", %lu important colours", vih->bmiHeader.biClrImportant);
113 TRACE(".\n");
115 else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo2) && mt->cbFormat >= sizeof(VIDEOINFOHEADER2))
117 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2 *)mt->pbFormat;
119 if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
120 if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
121 if (vih->dwBitRate) TRACE("bitrate %lu, ", vih->dwBitRate);
122 if (vih->dwBitErrorRate) TRACE("error rate %lu, ", vih->dwBitErrorRate);
123 TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
124 if (vih->dwInterlaceFlags) TRACE("interlace flags %#lx, ", vih->dwInterlaceFlags);
125 if (vih->dwCopyProtectFlags) TRACE("copy-protection flags %#lx, ", vih->dwCopyProtectFlags);
126 TRACE("aspect ratio %lu/%lu, ", vih->dwPictAspectRatioX, vih->dwPictAspectRatioY);
127 if (vih->dwControlFlags) TRACE("control flags %#lx, ", vih->dwControlFlags);
128 if (vih->dwControlFlags & AMCONTROL_COLORINFO_PRESENT)
130 const DXVA_ExtendedFormat *colorimetry = (const DXVA_ExtendedFormat *)&vih->dwControlFlags;
132 TRACE("chroma site %#x, range %#x, matrix %#x, lighting %#x, primaries %#x, transfer function %#x, ",
133 colorimetry->VideoChromaSubsampling, colorimetry->NominalRange, colorimetry->VideoTransferMatrix,
134 colorimetry->VideoLighting, colorimetry->VideoPrimaries, colorimetry->VideoTransferFunction);
136 TRACE("size %ldx%ld, %u planes, %u bpp, compression %s, image size %lu",
137 vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
138 vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
139 vih->bmiHeader.biSizeImage);
140 if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
141 TRACE(", resolution %ldx%ld", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
142 if (vih->bmiHeader.biClrUsed) TRACE(", %lu colours", vih->bmiHeader.biClrUsed);
143 if (vih->bmiHeader.biClrImportant) TRACE(", %lu important colours", vih->bmiHeader.biClrImportant);
144 TRACE(".\n");
146 else
147 TRACE("not implemented for this format type.\n");
150 HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *dest, const AM_MEDIA_TYPE *src)
152 *dest = *src;
153 if (src->pbFormat)
155 dest->pbFormat = CoTaskMemAlloc(src->cbFormat);
156 if (!dest->pbFormat)
157 return E_OUTOFMEMORY;
158 memcpy(dest->pbFormat, src->pbFormat, src->cbFormat);
160 if (dest->pUnk)
161 IUnknown_AddRef(dest->pUnk);
162 return S_OK;
165 void WINAPI FreeMediaType(AM_MEDIA_TYPE * pMediaType)
167 CoTaskMemFree(pMediaType->pbFormat);
168 pMediaType->pbFormat = NULL;
169 if (pMediaType->pUnk)
171 IUnknown_Release(pMediaType->pUnk);
172 pMediaType->pUnk = NULL;
176 AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const * pSrc)
178 AM_MEDIA_TYPE * pDest;
180 pDest = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
181 if (!pDest)
182 return NULL;
184 if (FAILED(CopyMediaType(pDest, pSrc)))
186 CoTaskMemFree(pDest);
187 return NULL;
190 return pDest;
193 void WINAPI DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
195 FreeMediaType(pMediaType);
196 CoTaskMemFree(pMediaType);