mediatype.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Implementation of MedaType utility functions
  3. *
  4. * Copyright 2003 Robert Shearman
  5. * Copyright 2010 Aric Stewart, CodeWeavers
  6. *
  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.
  11. *
  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.
  16. *
  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
  20. */
  21. #include "strmbase_private.h"
  22. #include "dvdmedia.h"
  23. #include "dxva.h"
  24. WINE_DEFAULT_DEBUG_CHANNEL(quartz);
  25. static const struct
  26. {
  27. const GUID *guid;
  28. const char *name;
  29. }
  30. strmbase_guids[] =
  31. {
  32. #define X(g) {&(g), #g}
  33. X(GUID_NULL),
  34. #undef OUR_GUID_ENTRY
  35. #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) X(name),
  36. #include "uuids.h"
  37. #undef X
  38. };
  39. static const char *strmbase_debugstr_guid(const GUID *guid)
  40. {
  41. unsigned int i;
  42. for (i = 0; i < ARRAY_SIZE(strmbase_guids); ++i)
  43. {
  44. if (IsEqualGUID(strmbase_guids[i].guid, guid))
  45. return wine_dbg_sprintf("%s", strmbase_guids[i].name);
  46. }
  47. return debugstr_guid(guid);
  48. }
  49. static const char *debugstr_fourcc(DWORD fourcc)
  50. {
  51. char str[4] = {fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24};
  52. if (isprint(str[0]) && isprint(str[1]) && isprint(str[2]) && isprint(str[3]))
  53. return wine_dbgstr_an(str, 4);
  54. return wine_dbg_sprintf("%#lx", fourcc);
  55. }
  56. void strmbase_dump_media_type(const AM_MEDIA_TYPE *mt)
  57. {
  58. if (!TRACE_ON(quartz) || !mt) return;
  59. TRACE("Dumping media type %p: major type %s, subtype %s",
  60. mt, strmbase_debugstr_guid(&mt->majortype), strmbase_debugstr_guid(&mt->subtype));
  61. if (mt->bFixedSizeSamples) TRACE(", fixed size samples");
  62. if (mt->bTemporalCompression) TRACE(", temporal compression");
  63. if (mt->lSampleSize) TRACE(", sample size %ld", mt->lSampleSize);
  64. if (mt->pUnk) TRACE(", pUnk %p", mt->pUnk);
  65. TRACE(", format type %s.\n", strmbase_debugstr_guid(&mt->formattype));
  66. if (!mt->pbFormat) return;
  67. TRACE("Dumping format %p: ", mt->pbFormat);
  68. if (IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) && mt->cbFormat >= sizeof(WAVEFORMATEX))
  69. {
  70. WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
  71. TRACE("tag %#x, %u channels, sample rate %lu, %lu bytes/sec, alignment %u, %u bits/sample.\n",
  72. wfx->wFormatTag, wfx->nChannels, wfx->nSamplesPerSec,
  73. wfx->nAvgBytesPerSec, wfx->nBlockAlign, wfx->wBitsPerSample);
  74. if (wfx->cbSize)
  75. {
  76. const unsigned char *extra = (const unsigned char *)(wfx + 1);
  77. unsigned int i;
  78. TRACE(" Extra bytes:");
  79. for (i = 0; i < wfx->cbSize; ++i)
  80. {
  81. if (!(i % 16)) TRACE("\n ");
  82. TRACE(" %02x", extra[i]);
  83. }
  84. TRACE("\n");
  85. }
  86. }
  87. else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo) && mt->cbFormat >= sizeof(VIDEOINFOHEADER))
  88. {
  89. VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)mt->pbFormat;
  90. if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
  91. if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
  92. if (vih->dwBitRate) TRACE("bitrate %lu, ", vih->dwBitRate);
  93. if (vih->dwBitErrorRate) TRACE("error rate %lu, ", vih->dwBitErrorRate);
  94. TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
  95. TRACE("size %ldx%ld, %u planes, %u bpp, compression %s, image size %lu",
  96. vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
  97. vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
  98. vih->bmiHeader.biSizeImage);
  99. if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
  100. TRACE(", resolution %ldx%ld", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
  101. if (vih->bmiHeader.biClrUsed) TRACE(", %lu colours", vih->bmiHeader.biClrUsed);
  102. if (vih->bmiHeader.biClrImportant) TRACE(", %lu important colours", vih->bmiHeader.biClrImportant);
  103. TRACE(".\n");
  104. }
  105. else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo2) && mt->cbFormat >= sizeof(VIDEOINFOHEADER2))
  106. {
  107. VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2 *)mt->pbFormat;
  108. if (!IsRectEmpty(&vih->rcSource)) TRACE("source %s, ", wine_dbgstr_rect(&vih->rcSource));
  109. if (!IsRectEmpty(&vih->rcTarget)) TRACE("target %s, ", wine_dbgstr_rect(&vih->rcTarget));
  110. if (vih->dwBitRate) TRACE("bitrate %lu, ", vih->dwBitRate);
  111. if (vih->dwBitErrorRate) TRACE("error rate %lu, ", vih->dwBitErrorRate);
  112. TRACE("%s sec/frame, ", debugstr_time(vih->AvgTimePerFrame));
  113. if (vih->dwInterlaceFlags) TRACE("interlace flags %#lx, ", vih->dwInterlaceFlags);
  114. if (vih->dwCopyProtectFlags) TRACE("copy-protection flags %#lx, ", vih->dwCopyProtectFlags);
  115. TRACE("aspect ratio %lu/%lu, ", vih->dwPictAspectRatioX, vih->dwPictAspectRatioY);
  116. if (vih->u.dwControlFlags) TRACE("control flags %#lx, ", vih->u.dwControlFlags);
  117. if (vih->u.dwControlFlags & AMCONTROL_COLORINFO_PRESENT)
  118. {
  119. const DXVA_ExtendedFormat *colorimetry = (const DXVA_ExtendedFormat *)&vih->u.dwControlFlags;
  120. TRACE("chroma site %#x, range %#x, matrix %#x, lighting %#x, primaries %#x, transfer function %#x, ",
  121. colorimetry->VideoChromaSubsampling, colorimetry->NominalRange, colorimetry->VideoTransferMatrix,
  122. colorimetry->VideoLighting, colorimetry->VideoPrimaries, colorimetry->VideoTransferFunction);
  123. }
  124. TRACE("size %ldx%ld, %u planes, %u bpp, compression %s, image size %lu",
  125. vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
  126. vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
  127. vih->bmiHeader.biSizeImage);
  128. if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
  129. TRACE(", resolution %ldx%ld", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
  130. if (vih->bmiHeader.biClrUsed) TRACE(", %lu colours", vih->bmiHeader.biClrUsed);
  131. if (vih->bmiHeader.biClrImportant) TRACE(", %lu important colours", vih->bmiHeader.biClrImportant);
  132. TRACE(".\n");
  133. }
  134. else
  135. TRACE("not implemented for this format type.\n");
  136. }
  137. HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *dest, const AM_MEDIA_TYPE *src)
  138. {
  139. *dest = *src;
  140. if (src->pbFormat)
  141. {
  142. dest->pbFormat = CoTaskMemAlloc(src->cbFormat);
  143. if (!dest->pbFormat)
  144. return E_OUTOFMEMORY;
  145. memcpy(dest->pbFormat, src->pbFormat, src->cbFormat);
  146. }
  147. if (dest->pUnk)
  148. IUnknown_AddRef(dest->pUnk);
  149. return S_OK;
  150. }
  151. void WINAPI FreeMediaType(AM_MEDIA_TYPE * pMediaType)
  152. {
  153. CoTaskMemFree(pMediaType->pbFormat);
  154. pMediaType->pbFormat = NULL;
  155. if (pMediaType->pUnk)
  156. {
  157. IUnknown_Release(pMediaType->pUnk);
  158. pMediaType->pUnk = NULL;
  159. }
  160. }
  161. AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const * pSrc)
  162. {
  163. AM_MEDIA_TYPE * pDest;
  164. pDest = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
  165. if (!pDest)
  166. return NULL;
  167. if (FAILED(CopyMediaType(pDest, pSrc)))
  168. {
  169. CoTaskMemFree(pDest);
  170. return NULL;
  171. }
  172. return pDest;
  173. }
  174. void WINAPI DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
  175. {
  176. FreeMediaType(pMediaType);
  177. CoTaskMemFree(pMediaType);
  178. }