00001 #include "StdAfx.h"
00002 #include "DSUtil.h"
00003 #include "MediaTypeEx.h"
00004
00005 #include <mmreg.h>
00006 #include <initguid.h>
00007 #include "..\..\include\moreuuids.h"
00008 #include "..\..\include\ogg\OggDS.h"
00009
00010 CMediaTypeEx::CMediaTypeEx()
00011 {
00012 }
00013
00014 CString CMediaTypeEx::ToString(IPin* pPin)
00015 {
00016 CString packing, type, codec, dim, rate, dur;
00017
00018
00019
00020 if(majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
00021 {
00022 packing = _T("Encrypted MPEG2 Pack");
00023 }
00024 else if(majortype == MEDIATYPE_MPEG2_PACK)
00025 {
00026 packing = _T("MPEG2 Pack");
00027 }
00028 else if(majortype == MEDIATYPE_MPEG2_PES)
00029 {
00030 packing = _T("MPEG2 PES");
00031 }
00032
00033 if(majortype == MEDIATYPE_Video)
00034 {
00035 type = _T("Video");
00036
00037 BITMAPINFOHEADER bih;
00038 bool fBIH = ExtractBIH(this, &bih);
00039
00040 int w, h, arx, ary;
00041 bool fDim = ExtractDim(this, w, h, arx, ary);
00042
00043 if(fBIH && bih.biCompression)
00044 {
00045 codec = GetVideoCodecName(subtype, bih.biCompression);
00046 }
00047
00048 if(codec.IsEmpty())
00049 {
00050 if(formattype == FORMAT_MPEGVideo) codec = _T("MPEG1 Video");
00051 else if(formattype == FORMAT_MPEG2_VIDEO) codec = _T("MPEG2 Video");
00052 else if(formattype == FORMAT_DiracVideoInfo) codec = _T("Dirac Video");
00053 }
00054
00055 if(fDim)
00056 {
00057 dim.Format(_T("%dx%d"), w, h);
00058 if(w*ary != h*arx) dim.Format(_T("%s (%d:%d)"), CString(dim), arx, ary);
00059 }
00060
00061 if(formattype == FORMAT_VideoInfo || formattype == FORMAT_MPEGVideo)
00062 {
00063 VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pbFormat;
00064 if(vih->AvgTimePerFrame) rate.Format(_T("%0.2ffps "), 10000000.0f / vih->AvgTimePerFrame);
00065 if(vih->dwBitRate) rate.Format(_T("%s%dKbps"), CString(rate), vih->dwBitRate/1000);
00066 }
00067 else if(formattype == FORMAT_VideoInfo2 || formattype == FORMAT_MPEG2_VIDEO || formattype == FORMAT_DiracVideoInfo)
00068 {
00069 VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)pbFormat;
00070 if(vih->AvgTimePerFrame) rate.Format(_T("%0.2ffps "), 10000000.0f / vih->AvgTimePerFrame);
00071 if(vih->dwBitRate) rate.Format(_T("%s%dKbps"), CString(rate), vih->dwBitRate/1000);
00072 }
00073
00074 rate.Trim();
00075
00076 if(subtype == MEDIASUBTYPE_DVD_SUBPICTURE)
00077 {
00078 type = _T("Subtitle");
00079 codec = _T("DVD Subpicture");
00080 }
00081 }
00082 else if(majortype == MEDIATYPE_Audio)
00083 {
00084 type = _T("Audio");
00085
00086 if(formattype == FORMAT_WaveFormatEx)
00087 {
00088 WAVEFORMATEX* wfe = (WAVEFORMATEX*)Format();
00089 if(wfe->wFormatTag
00090 )
00091 {
00092 codec = GetAudioCodecName(subtype, wfe->wFormatTag);
00093 dim.Format(_T("%dHz"), wfe->nSamplesPerSec);
00094 if(wfe->nChannels == 1) dim.Format(_T("%s mono"), CString(dim));
00095 else if(wfe->nChannels == 2) dim.Format(_T("%s stereo"), CString(dim));
00096 else dim.Format(_T("%s %dch"), CString(dim), wfe->nChannels);
00097 if(wfe->nAvgBytesPerSec) rate.Format(_T("%dKbps"), wfe->nAvgBytesPerSec*8/1000);
00098 }
00099 }
00100 else if(formattype == FORMAT_VorbisFormat)
00101 {
00102 VORBISFORMAT* vf = (VORBISFORMAT*)Format();
00103
00104 codec = GetAudioCodecName(subtype, 0);
00105 dim.Format(_T("%dHz"), vf->nSamplesPerSec);
00106 if(vf->nChannels == 1) dim.Format(_T("%s mono"), CString(dim));
00107 else if(vf->nChannels == 2) dim.Format(_T("%s stereo"), CString(dim));
00108 else dim.Format(_T("%s %dch"), CString(dim), vf->nChannels);
00109 if(vf->nAvgBitsPerSec) rate.Format(_T("%dKbps"), vf->nAvgBitsPerSec/1000);
00110 }
00111 else if(formattype == FORMAT_VorbisFormat2)
00112 {
00113 VORBISFORMAT2* vf = (VORBISFORMAT2*)Format();
00114
00115 codec = GetAudioCodecName(subtype, 0);
00116 dim.Format(_T("%dHz"), vf->SamplesPerSec);
00117 if(vf->Channels == 1) dim.Format(_T("%s mono"), CString(dim));
00118 else if(vf->Channels == 2) dim.Format(_T("%s stereo"), CString(dim));
00119 else dim.Format(_T("%s %dch"), CString(dim), vf->Channels);
00120 }
00121 }
00122 else if(majortype == MEDIATYPE_Text)
00123 {
00124 type = _T("Text");
00125 }
00126 else if(majortype == MEDIATYPE_Subtitle)
00127 {
00128 type = _T("Subtitle");
00129 codec = GetSubtitleCodecName(subtype);
00130 }
00131 else
00132 {
00133 type = _T("Unknown");
00134 }
00135
00136 if(CComQIPtr<IMediaSeeking> pMS = pPin)
00137 {
00138 REFERENCE_TIME rtDur = 0;
00139 if(SUCCEEDED(pMS->GetDuration(&rtDur)) && rtDur)
00140 {
00141 rtDur /= 10000000;
00142 int s = rtDur%60;
00143 rtDur /= 60;
00144 int m = rtDur%60;
00145 rtDur /= 60;
00146 int h = rtDur;
00147 if(h) dur.Format(_T("%d:%02d:%02d"), h, m, s);
00148 else if(m) dur.Format(_T("%02d:%02d"), m, s);
00149 else if(s) dur.Format(_T("%ds"), s);
00150 }
00151 }
00152
00153 CString str;
00154 if(!codec.IsEmpty()) str += codec + _T(" ");
00155 if(!dim.IsEmpty()) str += dim + _T(" ");
00156 if(!rate.IsEmpty()) str += rate + _T(" ");
00157 if(!dur.IsEmpty()) str += dur + _T(" ");
00158 str.Trim(_T(" ,"));
00159
00160 if(!str.IsEmpty()) str = type + _T(": ") + str;
00161 else str = type;
00162
00163 return str;
00164 }
00165
00166 CString CMediaTypeEx::GetVideoCodecName(const GUID& subtype, DWORD biCompression)
00167 {
00168 CString str;
00169
00170 static CAtlMap<CString, CString, CStringElementTraits<CString> > names;
00171
00172 if(names.IsEmpty())
00173 {
00174 names[_T("WMV1")] = _T("Windows Media Video 7");
00175 names[_T("WMV2")] = _T("Windows Media Video 8");
00176 names[_T("WMV3")] = _T("Windows Media Video 9");
00177 names[_T("DIV3")] = _T("DivX 3");
00178 names[_T("DX50")] = _T("DivX 5");
00179 names[_T("MP4V")] = _T("MPEG4 Video");
00180 names[_T("AVC1")] = _T("MPEG4 Video (AVC)");
00181 names[_T("RV10")] = _T("RealVideo 1");
00182 names[_T("RV20")] = _T("RealVideo 2");
00183 names[_T("RV30")] = _T("RealVideo 3");
00184 names[_T("RV40")] = _T("RealVideo 4");
00185
00186 }
00187
00188 if(biCompression)
00189 {
00190 CString fcc;
00191 fcc.Format(_T("%4.4hs"), &biCompression);
00192 fcc.MakeUpper();
00193
00194 if(!names.Lookup(fcc, str))
00195 {
00196 if(subtype == MEDIASUBTYPE_DiracVideo) str = _T("Dirac Video");
00197
00198 else if(biCompression < 256) str.Format(_T("%d"), biCompression);
00199 else str = fcc;
00200 }
00201 }
00202
00203 return str;
00204 }
00205
00206 CString CMediaTypeEx::GetAudioCodecName(const GUID& subtype, WORD wFormatTag)
00207 {
00208 CString str;
00209
00210 static CAtlMap<WORD, CString> names;
00211
00212 if(names.IsEmpty())
00213 {
00214 names[WAVE_FORMAT_PCM] = _T("PCM");
00215 names[WAVE_FORMAT_EXTENSIBLE] = _T("WAVE_FORMAT_EXTENSIBLE");
00216 names[WAVE_FORMAT_IEEE_FLOAT] = _T("IEEE Float");
00217 names[WAVE_FORMAT_ADPCM] = _T("MS ADPCM");
00218 names[WAVE_FORMAT_ALAW] = _T("aLaw");
00219 names[WAVE_FORMAT_MULAW] = _T("muLaw");
00220 names[WAVE_FORMAT_DRM] = _T("DRM");
00221 names[WAVE_FORMAT_OKI_ADPCM] = _T("OKI ADPCM");
00222 names[WAVE_FORMAT_DVI_ADPCM] = _T("DVI ADPCM");
00223 names[WAVE_FORMAT_IMA_ADPCM] = _T("IMA ADPCM");
00224 names[WAVE_FORMAT_MEDIASPACE_ADPCM] = _T("Mediaspace ADPCM");
00225 names[WAVE_FORMAT_SIERRA_ADPCM] = _T("Sierra ADPCM");
00226 names[WAVE_FORMAT_G723_ADPCM] = _T("G723 ADPCM");
00227 names[WAVE_FORMAT_DIALOGIC_OKI_ADPCM] = _T("Dialogic OKI ADPCM");
00228 names[WAVE_FORMAT_MEDIAVISION_ADPCM] = _T("Media Vision ADPCM");
00229 names[WAVE_FORMAT_YAMAHA_ADPCM] = _T("Yamaha ADPCM");
00230 names[WAVE_FORMAT_DSPGROUP_TRUESPEECH] = _T("DSP Group Truespeech");
00231 names[WAVE_FORMAT_DOLBY_AC2] = _T("Dolby AC2");
00232 names[WAVE_FORMAT_GSM610] = _T("GSM610");
00233 names[WAVE_FORMAT_MSNAUDIO] = _T("MSN Audio");
00234 names[WAVE_FORMAT_ANTEX_ADPCME] = _T("Antex ADPCME");
00235 names[WAVE_FORMAT_CS_IMAADPCM] = _T("Crystal Semiconductor IMA ADPCM");
00236 names[WAVE_FORMAT_ROCKWELL_ADPCM] = _T("Rockwell ADPCM");
00237 names[WAVE_FORMAT_ROCKWELL_DIGITALK] = _T("Rockwell Digitalk");
00238 names[WAVE_FORMAT_G721_ADPCM] = _T("G721");
00239 names[WAVE_FORMAT_G728_CELP] = _T("G728");
00240 names[WAVE_FORMAT_MSG723] = _T("MSG723");
00241 names[WAVE_FORMAT_MPEG] = _T("MPEG Audio");
00242 names[WAVE_FORMAT_MPEGLAYER3] = _T("MPEG Audio Layer 3");
00243 names[WAVE_FORMAT_LUCENT_G723] = _T("Lucent G723");
00244 names[WAVE_FORMAT_VOXWARE] = _T("Voxware");
00245 names[WAVE_FORMAT_G726_ADPCM] = _T("G726");
00246 names[WAVE_FORMAT_G722_ADPCM] = _T("G722");
00247 names[WAVE_FORMAT_G729A] = _T("G729A");
00248 names[WAVE_FORMAT_MEDIASONIC_G723] = _T("MediaSonic G723");
00249 names[WAVE_FORMAT_ZYXEL_ADPCM] = _T("ZyXEL ADPCM");
00250 names[WAVE_FORMAT_RHETOREX_ADPCM] = _T("Rhetorex ADPCM");
00251 names[WAVE_FORMAT_VIVO_G723] = _T("Vivo G723");
00252 names[WAVE_FORMAT_VIVO_SIREN] = _T("Vivo Siren");
00253 names[WAVE_FORMAT_DIGITAL_G723] = _T("Digital G723");
00254 names[WAVE_FORMAT_SANYO_LD_ADPCM] = _T("Sanyo LD ADPCM");
00255 names[WAVE_FORMAT_CREATIVE_ADPCM] = _T("Creative ADPCM");
00256 names[WAVE_FORMAT_CREATIVE_FASTSPEECH8] = _T("Creative Fastspeech 8");
00257 names[WAVE_FORMAT_CREATIVE_FASTSPEECH10] = _T("Creative Fastspeech 10");
00258 names[WAVE_FORMAT_UHER_ADPCM] = _T("UHER ADPCM");
00259 names[WAVE_FORMAT_DOLBY_AC3] = _T("Dolby AC3");
00260 names[WAVE_FORMAT_DVD_DTS] = _T("DTS");
00261 names[WAVE_FORMAT_AAC] = _T("AAC");
00262 names[WAVE_FORMAT_FLAC] = _T("FLAC");
00263 names[WAVE_FORMAT_TTA1] = _T("TTA");
00264 names[WAVE_FORMAT_14_4] = _T("RealAudio 14.4");
00265 names[WAVE_FORMAT_28_8] = _T("RealAudio 28.8");
00266 names[WAVE_FORMAT_ATRC] = _T("RealAudio ATRC");
00267 names[WAVE_FORMAT_COOK] = _T("RealAudio COOK");
00268 names[WAVE_FORMAT_DNET] = _T("RealAudio DNET");
00269 names[WAVE_FORMAT_RAAC] = _T("RealAudio RAAC");
00270 names[WAVE_FORMAT_RACP] = _T("RealAudio RACP");
00271 names[WAVE_FORMAT_SIPR] = _T("RealAudio SIPR");
00272 names[WAVE_FORMAT_PS2_PCM] = _T("PS2 PCM");
00273 names[WAVE_FORMAT_PS2_ADPCM] = _T("PS2 ADPCM");
00274 names[0x0160] = _T("Windows Media Audio");
00275 names[0x0161] = _T("Windows Media Audio");
00276 names[0x0162] = _T("Windows Media Audio");
00277 names[0x0163] = _T("Windows Media Audio");
00278
00279 }
00280
00281 if(!names.Lookup(wFormatTag, str))
00282 {
00283 if(subtype == MEDIASUBTYPE_Vorbis) str = _T("Vorbis (deprecated)");
00284 else if(subtype == MEDIASUBTYPE_Vorbis2) str = _T("Vorbis");
00285 else if(subtype == MEDIASUBTYPE_MP4A) str = _T("MPEG4 Audio");
00286 else if(subtype == MEDIASUBTYPE_FLAC_FRAMED) str = _T("FLAC (framed)");
00287
00288 else str.Format(_T("0x%04x"), wFormatTag);
00289 }
00290
00291 if(wFormatTag == WAVE_FORMAT_PCM)
00292 {
00293 if(subtype == MEDIASUBTYPE_DTS) str += _T(" (DTS)");
00294 else if(subtype == MEDIASUBTYPE_DOLBY_AC3) str += _T(" (AC3)");
00295 }
00296
00297 return str;
00298 }
00299
00300 CString CMediaTypeEx::GetSubtitleCodecName(const GUID& subtype)
00301 {
00302 CString str;
00303
00304 static CAtlMap<GUID, CString> names;
00305
00306 if(names.IsEmpty())
00307 {
00308 names[MEDIASUBTYPE_UTF8] = _T("UTF-8");
00309 names[MEDIASUBTYPE_SSA] = _T("SubStation Alpha");
00310 names[MEDIASUBTYPE_ASS] = _T("Advanced SubStation Alpha");
00311 names[MEDIASUBTYPE_USF] = _T("Universal Subtitle Format");
00312 names[MEDIASUBTYPE_VOBSUB] = _T("VobSub");
00313
00314 }
00315
00316 if(names.Lookup(subtype, str))
00317 {
00318
00319 }
00320
00321 return str;
00322 }