dshow_common.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.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_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
  75. {
  76. #if DSHOWDEBUG
  77. dshowdebug(" majortype\t");
  78. ff_printGUID(&type->majortype);
  79. dshowdebug("\n");
  80. dshowdebug(" subtype\t");
  81. ff_printGUID(&type->subtype);
  82. dshowdebug("\n");
  83. dshowdebug(" bFixedSizeSamples\t%d\n", type->bFixedSizeSamples);
  84. dshowdebug(" bTemporalCompression\t%d\n", type->bTemporalCompression);
  85. dshowdebug(" lSampleSize\t%lu\n", type->lSampleSize);
  86. dshowdebug(" formattype\t");
  87. ff_printGUID(&type->formattype);
  88. dshowdebug("\n");
  89. dshowdebug(" pUnk\t%p\n", type->pUnk);
  90. dshowdebug(" cbFormat\t%lu\n", type->cbFormat);
  91. dshowdebug(" pbFormat\t%p\n", type->pbFormat);
  92. if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
  93. VIDEOINFOHEADER *v = (void *) type->pbFormat;
  94. dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n",
  95. v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
  96. dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n",
  97. v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
  98. dshowdebug(" dwBitRate: %lu\n", v->dwBitRate);
  99. dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate);
  100. dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
  101. dump_bih(NULL, &v->bmiHeader);
  102. } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
  103. VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
  104. dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n",
  105. v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
  106. dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n",
  107. v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
  108. dshowdebug(" dwBitRate: %lu\n", v->dwBitRate);
  109. dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate);
  110. dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
  111. dshowdebug(" dwInterlaceFlags: %lu\n", v->dwInterlaceFlags);
  112. dshowdebug(" dwCopyProtectFlags: %lu\n", v->dwCopyProtectFlags);
  113. dshowdebug(" dwPictAspectRatioX: %lu\n", v->dwPictAspectRatioX);
  114. dshowdebug(" dwPictAspectRatioY: %lu\n", v->dwPictAspectRatioY);
  115. // dshowdebug(" dwReserved1: %lu\n", v->u.dwReserved1); /* mingw-w64 is buggy and doesn't name unnamed unions */
  116. dshowdebug(" dwReserved2: %lu\n", v->dwReserved2);
  117. dump_bih(NULL, &v->bmiHeader);
  118. } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
  119. WAVEFORMATEX *fx = (void *) type->pbFormat;
  120. dshowdebug(" wFormatTag: %u\n", fx->wFormatTag);
  121. dshowdebug(" nChannels: %u\n", fx->nChannels);
  122. dshowdebug(" nSamplesPerSec: %lu\n", fx->nSamplesPerSec);
  123. dshowdebug(" nAvgBytesPerSec: %lu\n", fx->nAvgBytesPerSec);
  124. dshowdebug(" nBlockAlign: %u\n", fx->nBlockAlign);
  125. dshowdebug(" wBitsPerSample: %u\n", fx->wBitsPerSample);
  126. dshowdebug(" cbSize: %u\n", fx->cbSize);
  127. }
  128. #endif
  129. }