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"
24 WINE_DEFAULT_DEBUG_CHANNEL(strmbase
);
33 #define X(g) {&(g), #g}
37 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) X(name),
43 static const char *strmbase_debugstr_guid(const GUID
*guid
)
47 for (i
= 0; i
< ARRAY_SIZE(strmbase_guids
); ++i
)
49 if (IsEqualGUID(strmbase_guids
[i
].guid
, guid
))
50 return wine_dbg_sprintf("%s", strmbase_guids
[i
].name
);
53 return debugstr_guid(guid
);
56 static const char *debugstr_fourcc(DWORD fourcc
)
58 char str
[4] = {fourcc
, fourcc
>> 8, fourcc
>> 16, fourcc
>> 24};
59 if (isprint(str
[0]) && isprint(str
[1]) && isprint(str
[2]) && isprint(str
[3]))
60 return wine_dbgstr_an(str
, 4);
61 return wine_dbg_sprintf("%#x", fourcc
);
64 void strmbase_dump_media_type(const AM_MEDIA_TYPE
*mt
)
66 if (!TRACE_ON(strmbase
) || !mt
) return;
68 TRACE("Dumping media type %p: major type %s, subtype %s",
69 mt
, strmbase_debugstr_guid(&mt
->majortype
), strmbase_debugstr_guid(&mt
->subtype
));
70 if (mt
->bFixedSizeSamples
) TRACE(", fixed size samples");
71 if (mt
->bTemporalCompression
) TRACE(", temporal compression");
72 if (mt
->lSampleSize
) TRACE(", sample size %d", mt
->lSampleSize
);
73 if (mt
->pUnk
) TRACE(", pUnk %p", mt
->pUnk
);
74 TRACE(", format type %s.\n", strmbase_debugstr_guid(&mt
->formattype
));
76 if (!mt
->pbFormat
) return;
78 TRACE("Dumping format %p: ", mt
->pbFormat
);
80 if (IsEqualGUID(&mt
->formattype
, &FORMAT_WaveFormatEx
) && mt
->cbFormat
>= sizeof(WAVEFORMATEX
))
82 WAVEFORMATEX
*wfx
= (WAVEFORMATEX
*)mt
->pbFormat
;
84 TRACE("tag %#x, %u channels, sample rate %u, %u bytes/sec, alignment %u, %u bits/sample.\n",
85 wfx
->wFormatTag
, wfx
->nChannels
, wfx
->nSamplesPerSec
,
86 wfx
->nAvgBytesPerSec
, wfx
->nBlockAlign
, wfx
->wBitsPerSample
);
90 const unsigned char *extra
= (const unsigned char *)(wfx
+ 1);
93 TRACE(" Extra bytes:");
94 for (i
= 0; i
< wfx
->cbSize
; ++i
)
96 if (!(i
% 16)) TRACE("\n ");
97 TRACE(" %02x", extra
[i
]);
102 else if (IsEqualGUID(&mt
->formattype
, &FORMAT_VideoInfo
) && mt
->cbFormat
>= sizeof(VIDEOINFOHEADER
))
104 VIDEOINFOHEADER
*vih
= (VIDEOINFOHEADER
*)mt
->pbFormat
;
106 TRACE("source %s, target %s, bitrate %u, error rate %u, %s sec/frame, ",
107 wine_dbgstr_rect(&vih
->rcSource
), wine_dbgstr_rect(&vih
->rcTarget
),
108 vih
->dwBitRate
, vih
->dwBitErrorRate
, debugstr_time(vih
->AvgTimePerFrame
));
109 TRACE("size %dx%d, %u planes, %u bpp, compression %s, image size %u",
110 vih
->bmiHeader
.biWidth
, vih
->bmiHeader
.biHeight
, vih
->bmiHeader
.biPlanes
,
111 vih
->bmiHeader
.biBitCount
, debugstr_fourcc(vih
->bmiHeader
.biCompression
),
112 vih
->bmiHeader
.biSizeImage
);
113 if (vih
->bmiHeader
.biXPelsPerMeter
|| vih
->bmiHeader
.biYPelsPerMeter
)
114 TRACE(", resolution %dx%d", vih
->bmiHeader
.biXPelsPerMeter
, vih
->bmiHeader
.biYPelsPerMeter
);
115 if (vih
->bmiHeader
.biClrUsed
) TRACE(", %d colours", vih
->bmiHeader
.biClrUsed
);
116 if (vih
->bmiHeader
.biClrImportant
) TRACE(", %d important colours", vih
->bmiHeader
.biClrImportant
);
120 TRACE("not implemented for this format type.\n");
123 HRESULT WINAPI
CopyMediaType(AM_MEDIA_TYPE
*dest
, const AM_MEDIA_TYPE
*src
)
128 dest
->pbFormat
= CoTaskMemAlloc(src
->cbFormat
);
130 return E_OUTOFMEMORY
;
131 memcpy(dest
->pbFormat
, src
->pbFormat
, src
->cbFormat
);
134 IUnknown_AddRef(dest
->pUnk
);
138 void WINAPI
FreeMediaType(AM_MEDIA_TYPE
* pMediaType
)
140 CoTaskMemFree(pMediaType
->pbFormat
);
141 pMediaType
->pbFormat
= NULL
;
142 if (pMediaType
->pUnk
)
144 IUnknown_Release(pMediaType
->pUnk
);
145 pMediaType
->pUnk
= NULL
;
149 AM_MEDIA_TYPE
* WINAPI
CreateMediaType(AM_MEDIA_TYPE
const * pSrc
)
151 AM_MEDIA_TYPE
* pDest
;
153 pDest
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
157 if (FAILED(CopyMediaType(pDest
, pSrc
)))
159 CoTaskMemFree(pDest
);
166 void WINAPI
DeleteMediaType(AM_MEDIA_TYPE
* pMediaType
)
168 FreeMediaType(pMediaType
);
169 CoTaskMemFree(pMediaType
);