dshow_common.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Directshow capture interface
  3. * Copyright (c) 2010 Ramiro Polla
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "dshow_capture.h"
  22. long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src)
  23. {
  24. uint8_t *pbFormat = NULL;
  25. if (src->cbFormat) {
  26. pbFormat = CoTaskMemAlloc(src->cbFormat);
  27. if (!pbFormat)
  28. return E_OUTOFMEMORY;
  29. memcpy(pbFormat, src->pbFormat, src->cbFormat);
  30. }
  31. *dst = *src;
  32. dst->pUnk = NULL;
  33. dst->pbFormat = pbFormat;
  34. return S_OK;
  35. }
  36. void ff_printGUID(const GUID *g)
  37. {
  38. #if DSHOWDEBUG
  39. const uint32_t *d = (const uint32_t *) &g->Data1;
  40. const uint16_t *w = (const uint16_t *) &g->Data2;
  41. const uint8_t *c = (const uint8_t *) &g->Data4;
  42. dshowdebug("0x%08x 0x%04x 0x%04x %02x%02x%02x%02x%02x%02x%02x%02x",
  43. d[0], w[0], w[1],
  44. c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
  45. #endif
  46. }
  47. static const char *dshow_context_to_name(void *ptr)
  48. {
  49. return "dshow";
  50. }
  51. static const AVClass ff_dshow_context_class = { "DirectShow", dshow_context_to_name };
  52. const AVClass *ff_dshow_context_class_ptr = &ff_dshow_context_class;
  53. #define dstruct(pctx, sname, var, type) \
  54. dshowdebug(" "#var":\t%"type"\n", sname->var)
  55. #if DSHOWDEBUG
  56. static void dump_bih(void *s, BITMAPINFOHEADER *bih)
  57. {
  58. dshowdebug(" BITMAPINFOHEADER\n");
  59. dstruct(s, bih, biSize, "lu");
  60. dstruct(s, bih, biWidth, "ld");
  61. dstruct(s, bih, biHeight, "ld");
  62. dstruct(s, bih, biPlanes, "d");
  63. dstruct(s, bih, biBitCount, "d");
  64. dstruct(s, bih, biCompression, "lu");
  65. dshowdebug(" biCompression:\t\"%.4s\"\n",
  66. (char*) &bih->biCompression);
  67. dstruct(s, bih, biSizeImage, "lu");
  68. dstruct(s, bih, biXPelsPerMeter, "lu");
  69. dstruct(s, bih, biYPelsPerMeter, "lu");
  70. dstruct(s, bih, biClrUsed, "lu");
  71. dstruct(s, bih, biClrImportant, "lu");
  72. }
  73. #endif
  74. void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps)
  75. {
  76. #if DSHOWDEBUG
  77. dshowdebug(" VIDEO_STREAM_CONFIG_CAPS\n");
  78. dshowdebug(" guid\t");
  79. ff_printGUID(&caps->guid);
  80. dshowdebug("\n");
  81. dshowdebug(" VideoStandard\t%lu\n", caps->VideoStandard);
  82. dshowdebug(" InputSize %ld\t%ld\n", caps->InputSize.cx, caps->InputSize.cy);
  83. dshowdebug(" MinCroppingSize %ld\t%ld\n", caps->MinCroppingSize.cx, caps->MinCroppingSize.cy);
  84. dshowdebug(" MaxCroppingSize %ld\t%ld\n", caps->MaxCroppingSize.cx, caps->MaxCroppingSize.cy);
  85. dshowdebug(" CropGranularityX\t%d\n", caps->CropGranularityX);
  86. dshowdebug(" CropGranularityY\t%d\n", caps->CropGranularityY);
  87. dshowdebug(" CropAlignX\t%d\n", caps->CropAlignX);
  88. dshowdebug(" CropAlignY\t%d\n", caps->CropAlignY);
  89. dshowdebug(" MinOutputSize %ld\t%ld\n", caps->MinOutputSize.cx, caps->MinOutputSize.cy);
  90. dshowdebug(" MaxOutputSize %ld\t%ld\n", caps->MaxOutputSize.cx, caps->MaxOutputSize.cy);
  91. dshowdebug(" OutputGranularityX\t%d\n", caps->OutputGranularityX);
  92. dshowdebug(" OutputGranularityY\t%d\n", caps->OutputGranularityY);
  93. dshowdebug(" StretchTapsX\t%d\n", caps->StretchTapsX);
  94. dshowdebug(" StretchTapsY\t%d\n", caps->StretchTapsY);
  95. dshowdebug(" ShrinkTapsX\t%d\n", caps->ShrinkTapsX);
  96. dshowdebug(" ShrinkTapsY\t%d\n", caps->ShrinkTapsY);
  97. dshowdebug(" MinFrameInterval\t%"PRId64"\n", caps->MinFrameInterval);
  98. dshowdebug(" MaxFrameInterval\t%"PRId64"\n", caps->MaxFrameInterval);
  99. dshowdebug(" MinBitsPerSecond\t%ld\n", caps->MinBitsPerSecond);
  100. dshowdebug(" MaxBitsPerSecond\t%ld\n", caps->MaxBitsPerSecond);
  101. #endif
  102. }
  103. void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps)
  104. {
  105. #if DSHOWDEBUG
  106. dshowdebug(" AUDIO_STREAM_CONFIG_CAPS\n");
  107. dshowdebug(" guid\t");
  108. ff_printGUID(&caps->guid);
  109. dshowdebug("\n");
  110. dshowdebug(" MinimumChannels\t%lu\n", caps->MinimumChannels);
  111. dshowdebug(" MaximumChannels\t%lu\n", caps->MaximumChannels);
  112. dshowdebug(" ChannelsGranularity\t%lu\n", caps->ChannelsGranularity);
  113. dshowdebug(" MinimumBitsPerSample\t%lu\n", caps->MinimumBitsPerSample);
  114. dshowdebug(" MaximumBitsPerSample\t%lu\n", caps->MaximumBitsPerSample);
  115. dshowdebug(" BitsPerSampleGranularity\t%lu\n", caps->BitsPerSampleGranularity);
  116. dshowdebug(" MinimumSampleFrequency\t%lu\n", caps->MinimumSampleFrequency);
  117. dshowdebug(" MaximumSampleFrequency\t%lu\n", caps->MaximumSampleFrequency);
  118. dshowdebug(" SampleFrequencyGranularity\t%lu\n", caps->SampleFrequencyGranularity);
  119. #endif
  120. }
  121. void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
  122. {
  123. #if DSHOWDEBUG
  124. dshowdebug(" majortype\t");
  125. ff_printGUID(&type->majortype);
  126. dshowdebug("\n");
  127. dshowdebug(" subtype\t");
  128. ff_printGUID(&type->subtype);
  129. dshowdebug("\n");
  130. dshowdebug(" bFixedSizeSamples\t%d\n", type->bFixedSizeSamples);
  131. dshowdebug(" bTemporalCompression\t%d\n", type->bTemporalCompression);
  132. dshowdebug(" lSampleSize\t%lu\n", type->lSampleSize);
  133. dshowdebug(" formattype\t");
  134. ff_printGUID(&type->formattype);
  135. dshowdebug("\n");
  136. dshowdebug(" pUnk\t%p\n", type->pUnk);
  137. dshowdebug(" cbFormat\t%lu\n", type->cbFormat);
  138. dshowdebug(" pbFormat\t%p\n", type->pbFormat);
  139. if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
  140. VIDEOINFOHEADER *v = (void *) type->pbFormat;
  141. dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n",
  142. v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
  143. dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n",
  144. v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
  145. dshowdebug(" dwBitRate: %lu\n", v->dwBitRate);
  146. dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate);
  147. dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
  148. dump_bih(NULL, &v->bmiHeader);
  149. } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
  150. VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
  151. dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n",
  152. v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
  153. dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n",
  154. v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
  155. dshowdebug(" dwBitRate: %lu\n", v->dwBitRate);
  156. dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate);
  157. dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
  158. dshowdebug(" dwInterlaceFlags: %lu\n", v->dwInterlaceFlags);
  159. dshowdebug(" dwCopyProtectFlags: %lu\n", v->dwCopyProtectFlags);
  160. dshowdebug(" dwPictAspectRatioX: %lu\n", v->dwPictAspectRatioX);
  161. dshowdebug(" dwPictAspectRatioY: %lu\n", v->dwPictAspectRatioY);
  162. // dshowdebug(" dwReserved1: %lu\n", v->u.dwReserved1); /* mingw-w64 is buggy and doesn't name unnamed unions */
  163. dshowdebug(" dwReserved2: %lu\n", v->dwReserved2);
  164. dump_bih(NULL, &v->bmiHeader);
  165. } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
  166. WAVEFORMATEX *fx = (void *) type->pbFormat;
  167. dshowdebug(" wFormatTag: %u\n", fx->wFormatTag);
  168. dshowdebug(" nChannels: %u\n", fx->nChannels);
  169. dshowdebug(" nSamplesPerSec: %lu\n", fx->nSamplesPerSec);
  170. dshowdebug(" nAvgBytesPerSec: %lu\n", fx->nAvgBytesPerSec);
  171. dshowdebug(" nBlockAlign: %u\n", fx->nBlockAlign);
  172. dshowdebug(" wBitsPerSample: %u\n", fx->wBitsPerSample);
  173. dshowdebug(" cbSize: %u\n", fx->cbSize);
  174. }
  175. #endif
  176. }