libavdevice/dshow_common.c
Go to the documentation of this file.
00001 /*
00002  * Directshow capture interface
00003  * Copyright (c) 2010 Ramiro Polla
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "dshow.h"
00023 
00024 long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src)
00025 {
00026     uint8_t *pbFormat = NULL;
00027 
00028     if (src->cbFormat) {
00029         pbFormat = CoTaskMemAlloc(src->cbFormat);
00030         if (!pbFormat)
00031             return E_OUTOFMEMORY;
00032         memcpy(pbFormat, src->pbFormat, src->cbFormat);
00033     }
00034 
00035     *dst = *src;
00036     dst->pUnk = NULL;
00037     dst->pbFormat = pbFormat;
00038 
00039     return S_OK;
00040 }
00041 
00042 void ff_printGUID(const GUID *g)
00043 {
00044 #if DSHOWDEBUG
00045     const uint32_t *d = (const uint32_t *) &g->Data1;
00046     const uint16_t *w = (const uint16_t *) &g->Data2;
00047     const uint8_t  *c = (const uint8_t  *) &g->Data4;
00048 
00049     dshowdebug("0x%08x 0x%04x 0x%04x %02x%02x%02x%02x%02x%02x%02x%02x",
00050                d[0], w[0], w[1],
00051                c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
00052 #endif
00053 }
00054 
00055 static const char *dshow_context_to_name(void *ptr)
00056 {
00057     return "dshow";
00058 }
00059 static const AVClass ff_dshow_context_class = { "DirectShow", dshow_context_to_name };
00060 const AVClass *ff_dshow_context_class_ptr = &ff_dshow_context_class;
00061 
00062 #define dstruct(pctx, sname, var, type) \
00063     dshowdebug("      "#var":\t%"type"\n", sname->var)
00064 
00065 #if DSHOWDEBUG
00066 static void dump_bih(void *s, BITMAPINFOHEADER *bih)
00067 {
00068     dshowdebug("      BITMAPINFOHEADER\n");
00069     dstruct(s, bih, biSize, "lu");
00070     dstruct(s, bih, biWidth, "ld");
00071     dstruct(s, bih, biHeight, "ld");
00072     dstruct(s, bih, biPlanes, "d");
00073     dstruct(s, bih, biBitCount, "d");
00074     dstruct(s, bih, biCompression, "lu");
00075     dshowdebug("      biCompression:\t\"%.4s\"\n",
00076                    (char*) &bih->biCompression);
00077     dstruct(s, bih, biSizeImage, "lu");
00078     dstruct(s, bih, biXPelsPerMeter, "lu");
00079     dstruct(s, bih, biYPelsPerMeter, "lu");
00080     dstruct(s, bih, biClrUsed, "lu");
00081     dstruct(s, bih, biClrImportant, "lu");
00082 }
00083 #endif
00084 
00085 void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps)
00086 {
00087 #if DSHOWDEBUG
00088     dshowdebug(" VIDEO_STREAM_CONFIG_CAPS\n");
00089     dshowdebug("  guid\t");
00090     ff_printGUID(&caps->guid);
00091     dshowdebug("\n");
00092     dshowdebug("  VideoStandard\t%lu\n", caps->VideoStandard);
00093     dshowdebug("  InputSize %ld\t%ld\n", caps->InputSize.cx, caps->InputSize.cy);
00094     dshowdebug("  MinCroppingSize %ld\t%ld\n", caps->MinCroppingSize.cx, caps->MinCroppingSize.cy);
00095     dshowdebug("  MaxCroppingSize %ld\t%ld\n", caps->MaxCroppingSize.cx, caps->MaxCroppingSize.cy);
00096     dshowdebug("  CropGranularityX\t%d\n", caps->CropGranularityX);
00097     dshowdebug("  CropGranularityY\t%d\n", caps->CropGranularityY);
00098     dshowdebug("  CropAlignX\t%d\n", caps->CropAlignX);
00099     dshowdebug("  CropAlignY\t%d\n", caps->CropAlignY);
00100     dshowdebug("  MinOutputSize %ld\t%ld\n", caps->MinOutputSize.cx, caps->MinOutputSize.cy);
00101     dshowdebug("  MaxOutputSize %ld\t%ld\n", caps->MaxOutputSize.cx, caps->MaxOutputSize.cy);
00102     dshowdebug("  OutputGranularityX\t%d\n", caps->OutputGranularityX);
00103     dshowdebug("  OutputGranularityY\t%d\n", caps->OutputGranularityY);
00104     dshowdebug("  StretchTapsX\t%d\n", caps->StretchTapsX);
00105     dshowdebug("  StretchTapsY\t%d\n", caps->StretchTapsY);
00106     dshowdebug("  ShrinkTapsX\t%d\n", caps->ShrinkTapsX);
00107     dshowdebug("  ShrinkTapsY\t%d\n", caps->ShrinkTapsY);
00108     dshowdebug("  MinFrameInterval\t%"PRId64"\n", caps->MinFrameInterval);
00109     dshowdebug("  MaxFrameInterval\t%"PRId64"\n", caps->MaxFrameInterval);
00110     dshowdebug("  MinBitsPerSecond\t%ld\n", caps->MinBitsPerSecond);
00111     dshowdebug("  MaxBitsPerSecond\t%ld\n", caps->MaxBitsPerSecond);
00112 #endif
00113 }
00114 
00115 void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps)
00116 {
00117 #if DSHOWDEBUG
00118     dshowdebug(" AUDIO_STREAM_CONFIG_CAPS\n");
00119     dshowdebug("  guid\t");
00120     ff_printGUID(&caps->guid);
00121     dshowdebug("\n");
00122     dshowdebug("  MinimumChannels\t%lu\n", caps->MinimumChannels);
00123     dshowdebug("  MaximumChannels\t%lu\n", caps->MaximumChannels);
00124     dshowdebug("  ChannelsGranularity\t%lu\n", caps->ChannelsGranularity);
00125     dshowdebug("  MinimumBitsPerSample\t%lu\n", caps->MinimumBitsPerSample);
00126     dshowdebug("  MaximumBitsPerSample\t%lu\n", caps->MaximumBitsPerSample);
00127     dshowdebug("  BitsPerSampleGranularity\t%lu\n", caps->BitsPerSampleGranularity);
00128     dshowdebug("  MinimumSampleFrequency\t%lu\n", caps->MinimumSampleFrequency);
00129     dshowdebug("  MaximumSampleFrequency\t%lu\n", caps->MaximumSampleFrequency);
00130     dshowdebug("  SampleFrequencyGranularity\t%lu\n", caps->SampleFrequencyGranularity);
00131 #endif
00132 }
00133 
00134 void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
00135 {
00136 #if DSHOWDEBUG
00137     dshowdebug("    majortype\t");
00138     ff_printGUID(&type->majortype);
00139     dshowdebug("\n");
00140     dshowdebug("    subtype\t");
00141     ff_printGUID(&type->subtype);
00142     dshowdebug("\n");
00143     dshowdebug("    bFixedSizeSamples\t%d\n", type->bFixedSizeSamples);
00144     dshowdebug("    bTemporalCompression\t%d\n", type->bTemporalCompression);
00145     dshowdebug("    lSampleSize\t%lu\n", type->lSampleSize);
00146     dshowdebug("    formattype\t");
00147     ff_printGUID(&type->formattype);
00148     dshowdebug("\n");
00149     dshowdebug("    pUnk\t%p\n", type->pUnk);
00150     dshowdebug("    cbFormat\t%lu\n", type->cbFormat);
00151     dshowdebug("    pbFormat\t%p\n", type->pbFormat);
00152 
00153     if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
00154         VIDEOINFOHEADER *v = (void *) type->pbFormat;
00155         dshowdebug("      rcSource: left %ld top %ld right %ld bottom %ld\n",
00156                    v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
00157         dshowdebug("      rcTarget: left %ld top %ld right %ld bottom %ld\n",
00158                    v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
00159         dshowdebug("      dwBitRate: %lu\n", v->dwBitRate);
00160         dshowdebug("      dwBitErrorRate: %lu\n", v->dwBitErrorRate);
00161         dshowdebug("      AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
00162         dump_bih(NULL, &v->bmiHeader);
00163     } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
00164         VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
00165         dshowdebug("      rcSource: left %ld top %ld right %ld bottom %ld\n",
00166                    v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
00167         dshowdebug("      rcTarget: left %ld top %ld right %ld bottom %ld\n",
00168                    v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
00169         dshowdebug("      dwBitRate: %lu\n", v->dwBitRate);
00170         dshowdebug("      dwBitErrorRate: %lu\n", v->dwBitErrorRate);
00171         dshowdebug("      AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
00172         dshowdebug("      dwInterlaceFlags: %lu\n", v->dwInterlaceFlags);
00173         dshowdebug("      dwCopyProtectFlags: %lu\n", v->dwCopyProtectFlags);
00174         dshowdebug("      dwPictAspectRatioX: %lu\n", v->dwPictAspectRatioX);
00175         dshowdebug("      dwPictAspectRatioY: %lu\n", v->dwPictAspectRatioY);
00176 //        dshowdebug("      dwReserved1: %lu\n", v->u.dwReserved1); /* mingw-w64 is buggy and doesn't name unnamed unions */
00177         dshowdebug("      dwReserved2: %lu\n", v->dwReserved2);
00178         dump_bih(NULL, &v->bmiHeader);
00179     } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
00180         WAVEFORMATEX *fx = (void *) type->pbFormat;
00181         dshowdebug("      wFormatTag: %u\n", fx->wFormatTag);
00182         dshowdebug("      nChannels: %u\n", fx->nChannels);
00183         dshowdebug("      nSamplesPerSec: %lu\n", fx->nSamplesPerSec);
00184         dshowdebug("      nAvgBytesPerSec: %lu\n", fx->nAvgBytesPerSec);
00185         dshowdebug("      nBlockAlign: %u\n", fx->nBlockAlign);
00186         dshowdebug("      wBitsPerSample: %u\n", fx->wBitsPerSample);
00187         dshowdebug("      cbSize: %u\n", fx->cbSize);
00188     }
00189 #endif
00190 }