MediaTypes.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 #include "stdafx.h"
00023 #include <initguid.h>
00024 #include "..\..\include\moreuuids.h"
00025 #include "MediaTypes.h"
00026 #include "DSUtil.h"
00027 
00028 #define VIH_NORMAL (sizeof(VIDEOINFOHEADER))
00029 #define VIH_BITFIELDS (sizeof(VIDEOINFOHEADER)+3*sizeof(RGBQUAD))
00030 #define VIH2_NORMAL (sizeof(VIDEOINFOHEADER2))
00031 #define VIH2_BITFIELDS (sizeof(VIDEOINFOHEADER2)+3*sizeof(RGBQUAD))
00032 #define BIH_SIZE (sizeof(BITMAPINFOHEADER))
00033 
00034 VIH vihs[] =
00035 {
00036         // YUY2
00037         {
00038                 {                                       
00039                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00040                         {BIH_SIZE, 0, 0, 1, 16, mmioFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0}             // bmiHeader
00041                 }, 
00042                 {0, 0, 0},                                                                                                              // mask[3]
00043                 VIH_NORMAL,                                                                                                             // size
00044                 &MEDIASUBTYPE_YUY2                                                                                              // subtype
00045         },
00046         // YV12
00047         {
00048                 {                                       
00049                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00050                         {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('Y','V','1','2'), 0, 0, 0, 0, 0}             // bmiHeader
00051                 }, 
00052                 {0, 0, 0},                                                                                                              // mask[3]
00053                 VIH_NORMAL,                                                                                                             // size
00054                 &MEDIASUBTYPE_YV12                                                                                              // subtype
00055         },
00056         // I420
00057         {
00058                 {                                       
00059                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00060                         {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','4','2','0'), 0, 0, 0, 0, 0}             // bmiHeader
00061                 }, 
00062                 {0, 0, 0},                                                                                                              // mask[3]
00063                 VIH_NORMAL,                                                                                                             // size
00064                 &MEDIASUBTYPE_I420                                                                                              // subtype
00065         },
00066         // IYUV
00067         {
00068                 {                                       
00069                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00070                         {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','Y','U','V'), 0, 0, 0, 0, 0}             // bmiHeader
00071                 }, 
00072                 {0, 0, 0},                                                                                                              // mask[3]
00073                 VIH_NORMAL,                                                                                                             // size
00074                 &MEDIASUBTYPE_IYUV                                                                                              // subtype
00075         },
00076         // 8888 normal
00077         {
00078                 {                                       
00079                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00080                         {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00081                 }, 
00082                 {0, 0, 0},                                                                                                              // mask[3]
00083                 VIH_NORMAL,                                                                                                             // size
00084                 &MEDIASUBTYPE_RGB32                                                                                             // subtype
00085         },
00086         // 8888 bitf 
00087         {
00088                 {                                       
00089                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00090                         {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00091                 }, 
00092                 {0xFF0000, 0x00FF00, 0x0000FF},                                                                 // mask[3]
00093                 VIH_BITFIELDS,                                                                                                  // size
00094                 &MEDIASUBTYPE_RGB32                                                                                             // subtype
00095         },
00096         // A888 normal
00097         {
00098                 {                                       
00099                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00100                         {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00101                 }, 
00102                 {0, 0, 0},                                                                                                              // mask[3]
00103                 VIH_NORMAL,                                                                                                             // size
00104                 &MEDIASUBTYPE_ARGB32                                                                                    // subtype
00105         },
00106         // A888 bitf (I'm not sure if this exist...)
00107         {
00108                 {                                       
00109                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00110                         {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00111                 }, 
00112                 {0xFF0000, 0x00FF00, 0x0000FF},                                                                 // mask[3]
00113                 VIH_BITFIELDS,                                                                                                  // size
00114                 &MEDIASUBTYPE_ARGB32                                                                                    // subtype
00115         },
00116         // 888 normal
00117         {
00118                 {                                       
00119                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00120                         {BIH_SIZE, 0, 0, 1, 24, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00121                 }, 
00122                 {0, 0, 0},                                                                                                              // mask[3]
00123                 VIH_NORMAL,                                                                                                             // size
00124                 &MEDIASUBTYPE_RGB24                                                                                             // subtype
00125         },
00126         // 888 bitf 
00127         {
00128                 {                                       
00129                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00130                         {BIH_SIZE, 0, 0, 1, 24, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00131                 }, 
00132                 {0xFF0000, 0x00FF00, 0x0000FF},                                                                 // mask[3]
00133                 VIH_BITFIELDS,                                                                                                  // size
00134                 &MEDIASUBTYPE_RGB24                                                                                             // subtype
00135         },
00136         // 565 normal
00137         {
00138                 {                                       
00139                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00140                         {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00141                 }, 
00142                 {0, 0, 0},                                                                                                              // mask[3]
00143                 VIH_NORMAL,                                                                                                             // size
00144                 &MEDIASUBTYPE_RGB565                                                                                    // subtype
00145         },
00146         // 565 bitf
00147         {
00148                 {                                       
00149                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00150                         {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00151                 }, 
00152                 {0xF800, 0x07E0, 0x001F},                                                                               // mask[3]
00153                 VIH_BITFIELDS,                                                                                                  // size
00154                 &MEDIASUBTYPE_RGB565                                                                                    // subtype
00155         },
00156         // 555 normal
00157         {
00158                 {                                       
00159                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00160                         {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00161                 }, 
00162                 {0, 0, 0},                                                                                                              // mask[3]
00163                 VIH_NORMAL,                                                                                                             // size
00164                 &MEDIASUBTYPE_RGB555                                                                                    // subtype
00165         },
00166         // 555 bitf
00167         {
00168                 {                                       
00169                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
00170                         {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00171                 }, 
00172                 {0x7C00, 0x03E0, 0x001F},                                                                               // mask[3]
00173                 VIH_BITFIELDS,                                                                                                  // size
00174                 &MEDIASUBTYPE_RGB555                                                                                    // subtype
00175         },
00176 };
00177 
00178 VIH2 vih2s[] =
00179 {
00180         // YUY2
00181         {
00182                 {                                       
00183                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00184                         {BIH_SIZE, 0, 0, 1, 16, mmioFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0}             // bmiHeader
00185                 }, 
00186                 {0, 0, 0},                                                                                                              // mask[3]
00187                 VIH2_NORMAL,                                                                                                    // size
00188                 &MEDIASUBTYPE_YUY2                                                                                              // subtype
00189         },
00190         // YV12
00191         {
00192                 {                                       
00193                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00194                         {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('Y','V','1','2'), 0, 0, 0, 0, 0}             // bmiHeader
00195                 }, 
00196                 {0, 0, 0},                                                                                                              // mask[3]
00197                 VIH2_NORMAL,                                                                                                    // size
00198                 &MEDIASUBTYPE_YV12                                                                                              // subtype
00199         },
00200         // I420
00201         {
00202                 {                                       
00203                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00204                         {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','4','2','0'), 0, 0, 0, 0, 0}             // bmiHeader
00205                 }, 
00206                 {0, 0, 0},                                                                                                              // mask[3]
00207                 VIH2_NORMAL,                                                                                                    // size
00208                 &MEDIASUBTYPE_I420                                                                                              // subtype
00209         },
00210         // IYUV
00211         {
00212                 {                                       
00213                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00214                         {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','Y','U','V'), 0, 0, 0, 0, 0}             // bmiHeader
00215                 }, 
00216                 {0, 0, 0},                                                                                                              // mask[3]
00217                 VIH2_NORMAL,                                                                                                    // size
00218                 &MEDIASUBTYPE_IYUV                                                                                              // subtype
00219         },
00220         // 8888 normal
00221         {
00222                 {                                       
00223                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00224                         {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00225                 }, 
00226                 {0, 0, 0},                                                                                                              // mask[3]
00227                 VIH2_NORMAL,                                                                                                    // size
00228                 &MEDIASUBTYPE_RGB32                                                                                             // subtype
00229         },
00230         // 8888 bitf 
00231         {
00232                 {                                       
00233                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00234                         {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00235                 }, 
00236                 {0xFF0000, 0x00FF00, 0x0000FF},                                                                 // mask[3]
00237                 VIH2_BITFIELDS,                                                                                                 // size
00238                 &MEDIASUBTYPE_RGB32                                                                                             // subtype
00239         },
00240         // A888 normal
00241         {
00242                 {                                       
00243                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00244                         {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00245                 }, 
00246                 {0, 0, 0},                                                                                                              // mask[3]
00247                 VIH2_NORMAL,                                                                                                    // size
00248                 &MEDIASUBTYPE_ARGB32                                                                                    // subtype
00249         },
00250         // A888 bitf (I'm not sure if this exist...)
00251         {
00252                 {                                       
00253                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00254                         {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00255                 }, 
00256                 {0xFF0000, 0x00FF00, 0x0000FF},                                                                 // mask[3]
00257                 VIH2_BITFIELDS,                                                                                                 // size
00258                 &MEDIASUBTYPE_ARGB32                                                                                    // subtype
00259         },
00260         // 888 normal
00261         {
00262                 {                                       
00263                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00264                         {BIH_SIZE, 0, 0, 1, 24, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00265                 }, 
00266                 {0, 0, 0},                                                                                                              // mask[3]
00267                 VIH2_NORMAL,                                                                                                    // size
00268                 &MEDIASUBTYPE_RGB24                                                                                             // subtype
00269         },
00270         // 888 bitf 
00271         {
00272                 {                                       
00273                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00274                         {BIH_SIZE, 0, 0, 1, 24, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00275                 }, 
00276                 {0xFF0000, 0x00FF00, 0x0000FF},                                                                 // mask[3]
00277                 VIH2_BITFIELDS,                                                                                                 // size
00278                 &MEDIASUBTYPE_RGB24                                                                                             // subtype
00279         },
00280         // 565 normal
00281         {
00282                 {                                       
00283                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00284                         {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00285                 }, 
00286                 {0, 0, 0},                                                                                                              // mask[3]
00287                 VIH2_NORMAL,                                                                                                    // size
00288                 &MEDIASUBTYPE_RGB565                                                                                    // subtype
00289         },
00290         // 565 bitf
00291         {
00292                 {                                       
00293                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00294                         {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00295                 }, 
00296                 {0xF800, 0x07E0, 0x001F},                                                                               // mask[3]
00297                 VIH2_BITFIELDS,                                                                                                 // size
00298                 &MEDIASUBTYPE_RGB565                                                                                    // subtype
00299         },
00300         // 555 normal
00301         {
00302                 {                                       
00303                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00304                         {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0}                  // bmiHeader
00305                 }, 
00306                 {0, 0, 0},                                                                                                              // mask[3]
00307                 VIH2_NORMAL,                                                                                                    // size
00308                 &MEDIASUBTYPE_RGB555                                                                                    // subtype
00309         },
00310         // 555 bitf
00311         {
00312                 {                                       
00313                         {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00314                         {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0}    // bmiHeader
00315                 }, 
00316                 {0x7C00, 0x03E0, 0x001F},                                                                               // mask[3]
00317                 VIH2_BITFIELDS,                                                                                                 // size
00318                 &MEDIASUBTYPE_RGB555                                                                                    // subtype
00319         },
00320 };
00321 
00322 int VIHSIZE = countof(vihs);
00323 
00324 CString VIH2String(int i)
00325 {
00326         CString ret = CString(GuidNames[*vihs[i].subtype]);
00327         if(!ret.Left(13).CompareNoCase(_T("MEDIASUBTYPE_"))) ret = ret.Mid(13);
00328         if(vihs[i].vih.bmiHeader.biCompression == 3) ret += _T(" BITF");
00329         if(*vihs[i].subtype == MEDIASUBTYPE_I420) ret = _T("I420"); // FIXME
00330         return(ret);
00331 }
00332 
00333 CString Subtype2String(const GUID& subtype)
00334 {
00335         CString ret = CString(GuidNames[subtype]);
00336         if(!ret.Left(13).CompareNoCase(_T("MEDIASUBTYPE_"))) ret = ret.Mid(13);
00337         if(subtype == MEDIASUBTYPE_I420) ret = _T("I420"); // FIXME
00338         return(ret);
00339 }
00340 
00341 void CorrectMediaType(AM_MEDIA_TYPE* pmt)
00342 {
00343         if(!pmt) return;
00344 
00345         CMediaType mt(*pmt);
00346 
00347         if(mt.formattype == FORMAT_VideoInfo)
00348         {
00349                 VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)mt.pbFormat;
00350 
00351                 for(int i = 0; i < VIHSIZE; i++)
00352                 {
00353                         if(mt.subtype == *vihs[i].subtype
00354                         && vih->bmiHeader.biCompression == vihs[i].vih.bmiHeader.biCompression)
00355                         {
00356                                 mt.AllocFormatBuffer(vihs[i].size);
00357                                 memcpy(mt.pbFormat, &vihs[i], vihs[i].size);
00358                                 memcpy(mt.pbFormat, pmt->pbFormat, sizeof(VIDEOINFOHEADER));
00359                                 break;
00360                         }
00361                 }
00362         }
00363         else if(mt.formattype == FORMAT_VideoInfo2)
00364         {
00365                 VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)mt.pbFormat;
00366 
00367                 for(int i = 0; i < VIHSIZE; i++)
00368                 {
00369                         if(mt.subtype == *vih2s[i].subtype
00370                         && vih2->bmiHeader.biCompression == vih2s[i].vih.bmiHeader.biCompression)
00371                         {
00372                                 mt.AllocFormatBuffer(vih2s[i].size);
00373                                 memcpy(mt.pbFormat, &vih2s[i], vih2s[i].size);
00374                                 memcpy(mt.pbFormat, pmt->pbFormat, sizeof(VIDEOINFOHEADER2));
00375                                 break;
00376                         }
00377                 }
00378         }
00379 
00380         CopyMediaType(pmt, &mt);
00381 }

Generated on Tue Dec 13 14:47:07 2005 for guliverkli by  doxygen 1.4.5