xactengine3_7: Add new dll.
[wine.git] / dlls / strmbase / mediatype.c
blobc2560352aae9dbc8c1a4be34bd15525dc538d0e3
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"
25 WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
27 static const struct
29 const GUID *guid;
30 const char *name;
32 strmbase_guids[] =
34 #define X(g) {&(g), #g}
35 X(GUID_NULL),
37 #undef OUR_GUID_ENTRY
38 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) X(name),
39 #include "uuids.h"
41 #undef X
44 static const char *strmbase_debugstr_guid(const GUID *guid)
46 unsigned int i;
48 for (i = 0; i < ARRAY_SIZE(strmbase_guids); ++i)
50 if (IsEqualGUID(strmbase_guids[i].guid, guid))
51 return wine_dbg_sprintf("%s", strmbase_guids[i].name);
54 return debugstr_guid(guid);
57 static const char *debugstr_fourcc(DWORD fourcc)
59 char str[4] = {fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24};
60 if (isprint(str[0]) && isprint(str[1]) && isprint(str[2]) && isprint(str[3]))
61 return wine_dbgstr_an(str, 4);
62 return wine_dbg_sprintf("%#x", fourcc);
65 void strmbase_dump_media_type(const AM_MEDIA_TYPE *mt)
67 if (!TRACE_ON(strmbase) || !mt) return;
69 TRACE("Dumping media type %p: major type %s, subtype %s",
70 mt, strmbase_debugstr_guid(&mt->majortype), strmbase_debugstr_guid(&mt->subtype));
71 if (mt->bFixedSizeSamples) TRACE(", fixed size samples");
72 if (mt->bTemporalCompression) TRACE(", temporal compression");
73 if (mt->lSampleSize) TRACE(", sample size %d", mt->lSampleSize);
74 if (mt->pUnk) TRACE(", pUnk %p", mt->pUnk);
75 TRACE(", format type %s.\n", strmbase_debugstr_guid(&mt->formattype));
77 if (!mt->pbFormat) return;
79 TRACE("Dumping format %p: ", mt->pbFormat);
81 if (IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) && mt->cbFormat >= sizeof(WAVEFORMATEX))
83 WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
85 TRACE("tag %#x, %u channels, sample rate %u, %u bytes/sec, alignment %u, %u bits/sample.\n",
86 wfx->wFormatTag, wfx->nChannels, wfx->nSamplesPerSec,
87 wfx->nAvgBytesPerSec, wfx->nBlockAlign, wfx->wBitsPerSample);
89 if (wfx->cbSize)
91 const unsigned char *extra = (const unsigned char *)(wfx + 1);
92 unsigned int i;
94 TRACE(" Extra bytes:");
95 for (i = 0; i < wfx->cbSize; ++i)
97 if (!(i % 16)) TRACE("\n ");
98 TRACE(" %02x", extra[i]);
100 TRACE("\n");
103 else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo) && mt->cbFormat >= sizeof(VIDEOINFOHEADER))
105 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)mt->pbFormat;
107 if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
108 if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
109 if (vih->dwBitRate) TRACE("bitrate %u, ", vih->dwBitRate);
110 if (vih->dwBitErrorRate) TRACE("error rate %u, ", vih->dwBitErrorRate);
111 TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
112 TRACE("size %dx%d, %u planes, %u bpp, compression %s, image size %u",
113 vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
114 vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
115 vih->bmiHeader.biSizeImage);
116 if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
117 TRACE(", resolution %dx%d", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
118 if (vih->bmiHeader.biClrUsed) TRACE(", %d colours", vih->bmiHeader.biClrUsed);
119 if (vih->bmiHeader.biClrImportant) TRACE(", %d important colours", vih->bmiHeader.biClrImportant);
120 TRACE(".\n");
122 else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo2) && mt->cbFormat >= sizeof(VIDEOINFOHEADER2))
124 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2 *)mt->pbFormat;
126 if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
127 if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
128 if (vih->dwBitRate) TRACE("bitrate %u, ", vih->dwBitRate);
129 if (vih->dwBitErrorRate) TRACE("error rate %u, ", vih->dwBitErrorRate);
130 TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
131 if (vih->dwInterlaceFlags) TRACE("interlace flags %#x, ", vih->dwInterlaceFlags);
132 if (vih->dwCopyProtectFlags) TRACE("copy-protection flags %#x, ", vih->dwCopyProtectFlags);
133 TRACE("aspect ratio %u/%u, ", vih->dwPictAspectRatioX, vih->dwPictAspectRatioY);
134 if (vih->u.dwControlFlags) TRACE("control flags %#x, ", vih->u.dwControlFlags);
135 TRACE("size %dx%d, %u planes, %u bpp, compression %s, image size %u",
136 vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
137 vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
138 vih->bmiHeader.biSizeImage);
139 if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
140 TRACE(", resolution %dx%d", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
141 if (vih->bmiHeader.biClrUsed) TRACE(", %d colours", vih->bmiHeader.biClrUsed);
142 if (vih->bmiHeader.biClrImportant) TRACE(", %d important colours", vih->bmiHeader.biClrImportant);
143 TRACE(".\n");
145 else
146 TRACE("not implemented for this format type.\n");
149 HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *dest, const AM_MEDIA_TYPE *src)
151 *dest = *src;
152 if (src->pbFormat)
154 dest->pbFormat = CoTaskMemAlloc(src->cbFormat);
155 if (!dest->pbFormat)
156 return E_OUTOFMEMORY;
157 memcpy(dest->pbFormat, src->pbFormat, src->cbFormat);
159 if (dest->pUnk)
160 IUnknown_AddRef(dest->pUnk);
161 return S_OK;
164 void WINAPI FreeMediaType(AM_MEDIA_TYPE * pMediaType)
166 CoTaskMemFree(pMediaType->pbFormat);
167 pMediaType->pbFormat = NULL;
168 if (pMediaType->pUnk)
170 IUnknown_Release(pMediaType->pUnk);
171 pMediaType->pUnk = NULL;
175 AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const * pSrc)
177 AM_MEDIA_TYPE * pDest;
179 pDest = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
180 if (!pDest)
181 return NULL;
183 if (FAILED(CopyMediaType(pDest, pSrc)))
185 CoTaskMemFree(pDest);
186 return NULL;
189 return pDest;
192 void WINAPI DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
194 FreeMediaType(pMediaType);
195 CoTaskMemFree(pMediaType);