]> git.sesse.net Git - ffmpeg/blob - libavdevice/dshow_common.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavdevice / dshow_common.c
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
22 #include "dshow.h"
23
24 long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src)
25 {
26     uint8_t *pbFormat = NULL;
27
28     if (src->cbFormat) {
29         pbFormat = CoTaskMemAlloc(src->cbFormat);
30         if (!pbFormat)
31             return E_OUTOFMEMORY;
32         memcpy(pbFormat, src->pbFormat, src->cbFormat);
33     }
34
35     *dst = *src;
36     dst->pUnk = NULL;
37     dst->pbFormat = pbFormat;
38
39     return S_OK;
40 }
41
42 void ff_printGUID(const GUID *g)
43 {
44 #if DSHOWDEBUG
45     const uint32_t *d = (const uint32_t *) &g->Data1;
46     const uint16_t *w = (const uint16_t *) &g->Data2;
47     const uint8_t  *c = (const uint8_t  *) &g->Data4;
48
49     dshowdebug("0x%08x 0x%04x 0x%04x %02x%02x%02x%02x%02x%02x%02x%02x",
50                d[0], w[0], w[1],
51                c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
52 #endif
53 }
54
55 static const char *dshow_context_to_name(void *ptr)
56 {
57     return "dshow";
58 }
59 static const AVClass ff_dshow_context_class = { "DirectShow", dshow_context_to_name };
60 const AVClass *ff_dshow_context_class_ptr = &ff_dshow_context_class;
61
62 #define dstruct(pctx, sname, var, type) \
63     dshowdebug("      "#var":\t%"type"\n", sname->var)
64
65 #if DSHOWDEBUG
66 static void dump_bih(void *s, BITMAPINFOHEADER *bih)
67 {
68     dshowdebug("      BITMAPINFOHEADER\n");
69     dstruct(s, bih, biSize, "lu");
70     dstruct(s, bih, biWidth, "ld");
71     dstruct(s, bih, biHeight, "ld");
72     dstruct(s, bih, biPlanes, "d");
73     dstruct(s, bih, biBitCount, "d");
74     dstruct(s, bih, biCompression, "lu");
75     dshowdebug("      biCompression:\t\"%.4s\"\n",
76                    (char*) &bih->biCompression);
77     dstruct(s, bih, biSizeImage, "lu");
78     dstruct(s, bih, biXPelsPerMeter, "lu");
79     dstruct(s, bih, biYPelsPerMeter, "lu");
80     dstruct(s, bih, biClrUsed, "lu");
81     dstruct(s, bih, biClrImportant, "lu");
82 }
83 #endif
84
85 void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
86 {
87 #if DSHOWDEBUG
88     dshowdebug("    majortype\t");
89     ff_printGUID(&type->majortype);
90     dshowdebug("\n");
91     dshowdebug("    subtype\t");
92     ff_printGUID(&type->subtype);
93     dshowdebug("\n");
94     dshowdebug("    bFixedSizeSamples\t%d\n", type->bFixedSizeSamples);
95     dshowdebug("    bTemporalCompression\t%d\n", type->bTemporalCompression);
96     dshowdebug("    lSampleSize\t%lu\n", type->lSampleSize);
97     dshowdebug("    formattype\t");
98     ff_printGUID(&type->formattype);
99     dshowdebug("\n");
100     dshowdebug("    pUnk\t%p\n", type->pUnk);
101     dshowdebug("    cbFormat\t%lu\n", type->cbFormat);
102     dshowdebug("    pbFormat\t%p\n", type->pbFormat);
103
104     if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
105         VIDEOINFOHEADER *v = (void *) type->pbFormat;
106         dshowdebug("      rcSource: left %ld top %ld right %ld bottom %ld\n",
107                    v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
108         dshowdebug("      rcTarget: left %ld top %ld right %ld bottom %ld\n",
109                    v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
110         dshowdebug("      dwBitRate: %lu\n", v->dwBitRate);
111         dshowdebug("      dwBitErrorRate: %lu\n", v->dwBitErrorRate);
112         dshowdebug("      AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
113         dump_bih(NULL, &v->bmiHeader);
114     } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
115         VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
116         dshowdebug("      rcSource: left %ld top %ld right %ld bottom %ld\n",
117                    v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
118         dshowdebug("      rcTarget: left %ld top %ld right %ld bottom %ld\n",
119                    v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
120         dshowdebug("      dwBitRate: %lu\n", v->dwBitRate);
121         dshowdebug("      dwBitErrorRate: %lu\n", v->dwBitErrorRate);
122         dshowdebug("      AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
123         dshowdebug("      dwInterlaceFlags: %lu\n", v->dwInterlaceFlags);
124         dshowdebug("      dwCopyProtectFlags: %lu\n", v->dwCopyProtectFlags);
125         dshowdebug("      dwPictAspectRatioX: %lu\n", v->dwPictAspectRatioX);
126         dshowdebug("      dwPictAspectRatioY: %lu\n", v->dwPictAspectRatioY);
127 //        dshowdebug("      dwReserved1: %lu\n", v->u.dwReserved1); /* mingw-w64 is buggy and doesn't name unnamed unions */
128         dshowdebug("      dwReserved2: %lu\n", v->dwReserved2);
129         dump_bih(NULL, &v->bmiHeader);
130     } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
131         WAVEFORMATEX *fx = (void *) type->pbFormat;
132         dshowdebug("      wFormatTag: %u\n", fx->wFormatTag);
133         dshowdebug("      nChannels: %u\n", fx->nChannels);
134         dshowdebug("      nSamplesPerSec: %lu\n", fx->nSamplesPerSec);
135         dshowdebug("      nAvgBytesPerSec: %lu\n", fx->nAvgBytesPerSec);
136         dshowdebug("      nBlockAlign: %u\n", fx->nBlockAlign);
137         dshowdebug("      wBitsPerSample: %u\n", fx->wBitsPerSample);
138         dshowdebug("      cbSize: %u\n", fx->cbSize);
139     }
140 #endif
141 }