2 * AM_MEDIA_TYPE service functions implementations
3 * Code is based on quartz/enummedia.c file from wine project.
4 * Modified by Vladimir Voroshilov
6 * Original code: Copyright 2003 Robert Shearman
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "libmpcodecs/img_format.h"
25 #include "wine/winerror.h"
27 #include "mediatype.h"
30 void DisplayMediaType(const char * label
,const AM_MEDIA_TYPE
* pmt
){
32 VIDEOINFOHEADER
* Vhdr
;
37 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"=======================\n");
39 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"AM_MEDIA_TYPE: %s\n",label
);
41 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"AM_MEDIA_TYPE:\n");
42 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"-(Ptr:%p)--------\n",pmt
);
43 for(i
=0;i
<sizeof(AM_MEDIA_TYPE
);i
++){
44 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"%02x ",(BYTE
)((BYTE
*)pmt
)[i
]);
45 if((i
+1)%8==0) Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"\n");
47 if((i
)%8!=0) Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"\n");
48 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"-(Ptr:%p)--(%lu)--\n",pmt
->pbFormat
,pmt
->cbFormat
);
49 for(i
=0;i
<pmt
->cbFormat
;i
++){
50 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"%02x ",(BYTE
)pmt
->pbFormat
[i
]);
51 if((i
+1)%8==0) Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"\n");
53 if((i
)%8!=0) Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"\n");
54 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"-----------------------\n");
55 iid
=(GUID
*)&(pmt
->subtype
);
56 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Subtype: %08x-%04x-%04x-%02x%02x-"
57 "%02x%02x%02x%02x%02x%02x\n",
58 iid
->f1
, iid
->f2
, iid
->f3
,
59 (unsigned char)iid
->f4
[1], (unsigned char)iid
->f4
[0],
60 (unsigned char)iid
->f4
[2], (unsigned char)iid
->f4
[3],
61 (unsigned char)iid
->f4
[4], (unsigned char)iid
->f4
[5],
62 (unsigned char)iid
->f4
[6], (unsigned char)iid
->f4
[7]);
64 iid
=(GUID
*)&(pmt
->formattype
);
65 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Format type: %08x-%04x-%04x-%02x%02x-"
66 "%02x%02x%02x%02x%02x%02x\n",
67 iid
->f1
, iid
->f2
, iid
->f3
,
68 (unsigned char)iid
->f4
[1], (unsigned char)iid
->f4
[0],
69 (unsigned char)iid
->f4
[2], (unsigned char)iid
->f4
[3],
70 (unsigned char)iid
->f4
[4], (unsigned char)iid
->f4
[5],
71 (unsigned char)iid
->f4
[6], (unsigned char)iid
->f4
[7]);
72 if(pmt
&& memcmp(&pmt
->formattype
,&FORMAT_WaveFormatEx
,16)==0 && pmt
->pbFormat
){
73 pWF
=(WAVEFORMATEX
*)pmt
->pbFormat
;
74 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"PMT: nChannels %d\n",pWF
->nChannels
);
75 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"PMT: nSamplesPerSec %ld\n",pWF
->nSamplesPerSec
);
76 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"PMT: wBitsPerSample %d\n",pWF
->wBitsPerSample
);
77 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"PMT: nBlockAlign %d\n",pWF
->nBlockAlign
);
78 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"PMT: nAvgBytesPerSec %ld\n",pWF
->nAvgBytesPerSec
);
79 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"PMT: SampleSize %ld\n",pmt
->lSampleSize
);
81 if(pmt
&& memcmp(&pmt
->formattype
,&FORMAT_VideoInfo
,16)==0 && pmt
->pbFormat
){
82 Vhdr
=(VIDEOINFOHEADER
*)pmt
->pbFormat
;
83 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: dwBitRate %ld\n",Vhdr
->dwBitRate
);
84 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: biWidth %ld\n",Vhdr
->bmiHeader
.biWidth
);
85 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: biHeight %ld\n",Vhdr
->bmiHeader
.biHeight
);
86 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: biSizeImage %ld\n",Vhdr
->bmiHeader
.biSizeImage
);
87 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: biBitCount %d\n",Vhdr
->bmiHeader
.biBitCount
);
88 if(Vhdr
->bmiHeader
.biCompression
){
89 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: biComression 0x%08lx (%s)\n",Vhdr
->bmiHeader
.biCompression
,vo_format_name(Vhdr
->bmiHeader
.biCompression
));
91 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"Vhdr: biComression 0x00000000\n");
94 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"=======================\n");
97 HRESULT
CopyMediaType(AM_MEDIA_TYPE
* pDest
, const AM_MEDIA_TYPE
*pSrc
)
99 Debug
mp_msg(MSGT_LOADER
,MSGL_DBG4
,"%s(%p) called\n", "CopyMediaType",pSrc
);
101 if(!pSrc
|| !pDest
) return E_POINTER
;
103 if(pSrc
== pDest
) return E_INVALIDARG
;
105 if(!pSrc
->pbFormat
&& pSrc
->cbFormat
) return E_POINTER
;
107 memcpy(pDest
, pSrc
, sizeof(AM_MEDIA_TYPE
));
108 if (!pSrc
->pbFormat
) return S_OK
;
109 if (!(pDest
->pbFormat
= CoTaskMemAlloc(pSrc
->cbFormat
)))
110 return E_OUTOFMEMORY
;
111 memcpy(pDest
->pbFormat
, pSrc
->pbFormat
, pSrc
->cbFormat
);
113 pDest
->pUnk
->vt
->AddRef(pDest
->pUnk
);
117 void FreeMediaType(AM_MEDIA_TYPE
* pMediaType
)
119 if (!pMediaType
) return;
120 if (pMediaType
->pbFormat
)
122 CoTaskMemFree(pMediaType
->pbFormat
);
123 pMediaType
->pbFormat
= NULL
;
125 if (pMediaType
->pUnk
)
127 pMediaType
->pUnk
->vt
->Release(pMediaType
->pUnk
);
128 pMediaType
->pUnk
= NULL
;
132 AM_MEDIA_TYPE
* CreateMediaType(AM_MEDIA_TYPE
const * pSrc
)
134 AM_MEDIA_TYPE
* pDest
;
135 if (!pSrc
) return NULL
;
136 pDest
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
140 if (FAILED(CopyMediaType(pDest
, pSrc
)))
142 CoTaskMemFree(pDest
);
149 void DeleteMediaType(AM_MEDIA_TYPE
* pMediaType
)
151 if (!pMediaType
) return;
152 FreeMediaType(pMediaType
);
153 CoTaskMemFree(pMediaType
);
156 #define IsEqualGUID(a,b) (memcmp(a,b,16)==0)
157 int CompareMediaTypes(const AM_MEDIA_TYPE
* pmt1
, const AM_MEDIA_TYPE
* pmt2
, int bWildcards
)
159 return (((bWildcards
&& (IsEqualGUID(&pmt1
->majortype
, &GUID_NULL
) || IsEqualGUID(&pmt2
->majortype
, &GUID_NULL
))) || IsEqualGUID(&pmt1
->majortype
, &pmt2
->majortype
)) &&
160 ((bWildcards
&& (IsEqualGUID(&pmt1
->subtype
, &GUID_NULL
) || IsEqualGUID(&pmt2
->subtype
, &GUID_NULL
))) || IsEqualGUID(&pmt1
->subtype
, &pmt2
->subtype
)));