Mercurial > mplayer.hg
annotate stream/tvi_dshow.c @ 36965:5fb43d5efdca
configure: add CONFIG_CABAC
fix ffmpeg linking
author | michael |
---|---|
date | Tue, 25 Mar 2014 00:15:02 +0000 |
parents | 389d43c448b3 |
children |
rev | line source |
---|---|
24744 | 1 /* |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
2 * TV support under Win32 |
24744 | 3 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
4 * (C) 2007 Vladimir Voroshilov <voroshil@gmail.com> |
24744 | 5 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
6 * Based on tvi_dummy.c with help of tv.c, tvi_v4l2.c code. |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
7 * |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
8 * This file is part of MPlayer. |
24744 | 9 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
10 * MPlayer is free software; you can redistribute it and/or modify |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
13 * (at your option) any later version. |
24744 | 14 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
15 * MPlayer is distributed in the hope that it will be useful, |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
18 * GNU General Public License for more details. |
24744 | 19 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
20 * You should have received a copy of the GNU General Public License along |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
21 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
23 */ |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
24 |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25689
diff
changeset
|
25 /* |
24744 | 26 * WARNING: This is alpha code! |
27 * | |
28 * Abilities: | |
29 * * Watching TV under Win32 using WDM Capture driver and DirectShow | |
30 * * Grabbing synchronized audio/video with mencoder (synchronization is beeing done by DirectShow) | |
31 * * If device driver provides IAMStreamConfig interface, user can choose width/height with "-tv height=<h>:width=<w>" | |
32 * * Adjusting BRIGHTNESS,HUE,SATURATION,CONTRAST if supported by device | |
33 * * Selecting Tuner,S-Video,... as media source | |
34 * * User can select used video capture device, passing -tv device=<dev#> | |
35 * * User can select used audio input, passing -tv audioid=<input#> | |
36 * | |
37 * options which will not be implemented (probably sometime in future, if possible): | |
38 * * alsa | |
39 * * mjpeg | |
40 * * decimation=<1|2|4> | |
41 * * quality=<0\-100> | |
42 * * forceaudio | |
43 * * forcechan=<1\-2> | |
44 * * [volume|bass|treble|balance] | |
45 * | |
46 * Works with: | |
47 * - LifeView FlyTV Prime 34FM (SAA7134 based) with driver from Ivan Uskov | |
48 * Partially works with: | |
49 * - ATI 9200 VIVO based card | |
50 * - ATI AIW 7500 | |
51 * - nVidia Ti-4400 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
52 * |
24744 | 53 * Known bugs: |
54 * * stream goes with 24.93 FPS (NTSC), while reporting 25 FPS (PAL) ?! | |
55 * * direct set frequency call does not work ('Insufficient Buffer' error) | |
56 * * audio stream goes with about 1 sample/sec rate when capturing sound from audio card | |
57 * | |
58 * TODO: | |
59 * * check audio with small buffer on vivo !!! | |
60 * * norm for IAMVideoDecoder and for IAMTVtuner - differs !! | |
61 * * check how to change TVFormat on VIVO card without tuner | |
62 * * Flip image upside-down for RGB formats. | |
63 * * | |
64 * * remove debug sleep() | |
65 * * Add some notes to methods' parameters | |
66 * * refactor console messages | |
67 * * check using header files and keep only needed | |
68 * * add additional comments to methods' bodies | |
69 * | |
70 */ | |
71 | |
72 | |
73 /// \ingroup tvi_dshow | |
74 | |
75 #include "config.h" | |
76 | |
77 #include <stdio.h> | |
35903 | 78 #include <strings.h> |
79 | |
24744 | 80 #include "libmpcodecs/img_format.h" |
29759
d287e2785570
Move teletext specific code from stream into libmpcodecs.
cehoyos
parents:
29263
diff
changeset
|
81 #include "libmpcodecs/dec_teletext.h" |
24744 | 82 #include "libaf/af_format.h" |
83 #include "help_mp.h" | |
84 #include "osdep/timer.h" | |
85 | |
86 | |
87 #include "tv.h" | |
88 #include "mp_msg.h" | |
89 #include "frequencies.h" | |
90 | |
91 | |
34115 | 92 #define MP_DEFINE_LOCAL_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ |
93 static const GUID name = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}} | |
94 | |
95 #ifdef __WINE__ | |
96 // take care of unions which are normally declared | |
97 // named by Wine but nameless (anonymous) by Windows | |
98 #define _FORCENAMELESSUNION | |
99 #endif | |
100 | |
24744 | 101 #include "tvi_dshow.h" |
102 | |
30127
774aa6f7399e
Several hacks to fix compilation of tvi_dshow on MinGW64.
reimar
parents:
29809
diff
changeset
|
103 #ifndef STDCALL |
774aa6f7399e
Several hacks to fix compilation of tvi_dshow on MinGW64.
reimar
parents:
29809
diff
changeset
|
104 // mingw64 needs this |
774aa6f7399e
Several hacks to fix compilation of tvi_dshow on MinGW64.
reimar
parents:
29809
diff
changeset
|
105 #define STDCALL __stdcall |
774aa6f7399e
Several hacks to fix compilation of tvi_dshow on MinGW64.
reimar
parents:
29809
diff
changeset
|
106 #endif |
774aa6f7399e
Several hacks to fix compilation of tvi_dshow on MinGW64.
reimar
parents:
29809
diff
changeset
|
107 |
24744 | 108 static tvi_handle_t *tvi_init_dshow(tv_param_t* tv_param); |
109 | |
110 /* | |
111 *--------------------------------------------------------------------------------------- | |
112 * | |
113 * Data structures | |
114 * | |
115 *--------------------------------------------------------------------------------------- | |
116 */ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
117 /** |
24744 | 118 information about this file |
119 */ | |
25689 | 120 const tvi_info_t tvi_info_dshow = { |
24744 | 121 tvi_init_dshow, |
122 "DirectShow TV", | |
123 "dshow", | |
124 "Vladimir Voroshilov", | |
125 "Very experimental!! Use with caution" | |
126 }; | |
127 | |
128 | |
129 /** | |
130 ringbuffer related info | |
131 */ | |
132 typedef struct { | |
133 CRITICAL_SECTION *pMutex; ///< pointer to critical section (mutex) | |
134 char **ringbuffer; ///< ringbuffer array | |
135 double*dpts; ///< samples' timestamps | |
136 | |
137 int buffersize; ///< size of buffer in blocks | |
138 int blocksize; ///< size of individual block | |
139 int head; ///< index of first valid sample | |
140 int tail; ///< index of last valid sample | |
141 int count; ///< count of valid samples in ringbuffer | |
142 double tStart; ///< pts of first sample (first sample should have pts 0) | |
143 } grabber_ringbuffer_t; | |
144 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
145 typedef enum { unknown, video, audio, vbi } stream_type; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
146 |
24744 | 147 /** |
148 CSampleGrabberCD definition | |
149 */ | |
150 typedef struct CSampleGrabberCB { | |
151 ISampleGrabberCBVtbl *lpVtbl; | |
152 int refcount; | |
153 GUID interfaces[2]; | |
154 grabber_ringbuffer_t *pbuf; | |
155 } CSampleGrabberCB; | |
156 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
157 /** |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
158 Chain related structure |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
159 */ |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
160 typedef struct { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
161 stream_type type; ///< stream type |
25080 | 162 const GUID* majortype; ///< GUID of major mediatype (video/audio/vbi) |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
163 const GUID* pin_category; ///< pin category (pointer to one of PIN_CATEGORY_*) |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
164 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
165 IBaseFilter *pCaptureFilter; ///< capture device filter |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
166 IAMStreamConfig *pStreamConfig; ///< for configuring stream |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
167 ISampleGrabber *pSG; ///< ISampleGrabber interface of SampleGrabber filter |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
168 IBaseFilter *pSGF; ///< IBaseFilter interface of SampleGrabber filter |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
169 IPin *pCapturePin; ///< output capture pin |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
170 IPin *pSGIn; ///< input pin of SampleGrabber filter |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
171 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
172 grabber_ringbuffer_t *rbuf; ///< sample frabber data |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
173 CSampleGrabberCB* pCSGCB; ///< callback object |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
174 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
175 AM_MEDIA_TYPE *pmt; ///< stream properties. |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
176 int nFormatUsed; ///< index of used format |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
177 AM_MEDIA_TYPE **arpmt; ///< available formats |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
178 void** arStreamCaps; ///< VIDEO_STREAM_CONFIG_CAPS or AUDIO_STREAM_CONFIG_CAPS |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
179 } chain_t; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
180 |
31322
016194f71de3
Fix function pointer types in tvi_functions struct
reimar
parents:
30702
diff
changeset
|
181 typedef struct priv { |
24744 | 182 int dev_index; ///< capture device index in device list (defaul: 0, first available device) |
183 int adev_index; ///< audio capture device index in device list (default: -1, not used) | |
184 int immediate_mode; ///< immediate mode (no sound capture) | |
185 int state; ///< state: 1-filter graph running, 0-filter graph stopped | |
186 int direct_setfreq_call; ///< 0-find nearest channels from system channel list(workaround),1-direct call to set frequency | |
187 int direct_getfreq_call; ///< 0-find frequncy from frequency table (workaround),1-direct call to get frequency | |
188 | |
189 int fcc; ///< used video format code (FourCC) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
190 int width; ///< picture width (default: auto) |
24744 | 191 int height; ///< picture height (default: auto) |
192 | |
193 int channels; ///< number of audio channels (default: auto) | |
194 int samplerate; ///< audio samplerate (default: auto) | |
195 | |
196 long *freq_table; ///< frequency table (in Hz) | |
197 int freq_table_len; ///< length of freq table | |
198 int first_channel; ///< channel number of first entry in freq table | |
199 int input; ///< used input | |
200 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
201 chain_t* chains[3]; ///< chains' data (0-video, 1-audio, 2-vbi) |
24744 | 202 |
203 IAMTVTuner *pTVTuner; ///< interface for tuner device | |
204 IGraphBuilder *pGraph; ///< filter graph | |
205 ICaptureGraphBuilder2 *pBuilder; ///< graph builder | |
206 IMediaControl *pMediaControl; ///< interface for controlling graph (start, stop,...) | |
207 IAMVideoProcAmp *pVideoProcAmp; ///< for adjusting hue,saturation,etc | |
208 IAMCrossbar *pCrossbar; ///< for selecting input (Tuner,Composite,S-Video,...) | |
209 DWORD dwRegister; ///< allow graphedit to connect to our graph | |
210 void *priv_vbi; ///< private VBI data structure | |
211 tt_stream_props tsp; ///< data for VBI initialization | |
212 | |
213 tv_param_t* tv_param; ///< TV parameters | |
214 } priv_t; | |
215 | |
216 #include "tvi_def.h" | |
217 | |
218 /** | |
219 country table entry structure (for loading freq table stored in kstvtuner.ax | |
220 | |
221 \note | |
222 structure have to be 2-byte aligned and have 10-byte length!! | |
223 */ | |
224 typedef struct __attribute__((__packed__)) { | |
225 WORD CountryCode; ///< Country code | |
226 WORD CableFreqTable; ///< index of resource with frequencies for cable channels | |
227 WORD BroadcastFreqTable; ///< index of resource with frequencies for broadcast channels | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
228 DWORD VideoStandard; ///< used video standard |
24744 | 229 } TRCCountryList; |
230 /** | |
231 information about image formats | |
232 */ | |
233 typedef struct { | |
234 uint32_t fmt; ///< FourCC | |
235 const GUID *subtype; ///< DirectShow's subtype | |
236 int nBits; ///< number of bits | |
237 int nCompression; ///< complression | |
238 int tail; ///< number of additional bytes followed VIDEOINFOHEADER structure | |
239 } img_fmt; | |
240 | |
241 /* | |
242 *--------------------------------------------------------------------------------------- | |
243 * | |
244 * Methods forward declaration | |
245 * | |
246 *--------------------------------------------------------------------------------------- | |
247 */ | |
248 static HRESULT init_ringbuffer(grabber_ringbuffer_t * rb, int buffersize, | |
249 int blocksize); | |
250 static HRESULT show_filter_info(IBaseFilter * pFilter); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
251 #if 0 |
24744 | 252 //defined in current MinGW release |
253 HRESULT STDCALL GetRunningObjectTable(DWORD, IRunningObjectTable **); | |
254 HRESULT STDCALL CreateItemMoniker(LPCOLESTR, LPCOLESTR, IMoniker **); | |
255 #endif | |
256 static CSampleGrabberCB *CSampleGrabberCB_Create(grabber_ringbuffer_t * | |
257 pbuf); | |
258 static int set_crossbar_input(priv_t * priv, int input); | |
259 static int subtype2imgfmt(const GUID * subtype); | |
260 | |
261 /* | |
262 *--------------------------------------------------------------------------------------- | |
263 * | |
264 * Global constants and variables | |
265 * | |
266 *--------------------------------------------------------------------------------------- | |
267 */ | |
268 /** | |
269 lookup tables for physical connector types | |
270 */ | |
271 static const struct { | |
272 long type; | |
273 char *name; | |
274 } tv_physcon_types[]={ | |
275 {PhysConn_Video_Tuner, "Tuner" }, | |
276 {PhysConn_Video_Composite, "Composite" }, | |
277 {PhysConn_Video_SVideo, "S-Video" }, | |
278 {PhysConn_Video_RGB, "RGB" }, | |
279 {PhysConn_Video_YRYBY, "YRYBY" }, | |
280 {PhysConn_Video_SerialDigital, "SerialDigital" }, | |
281 {PhysConn_Video_ParallelDigital, "ParallelDigital"}, | |
282 {PhysConn_Video_VideoDecoder, "VideoDecoder" }, | |
283 {PhysConn_Video_VideoEncoder, "VideoEncoder" }, | |
284 {PhysConn_Video_SCART, "SCART" }, | |
285 {PhysConn_Video_Black, "Blaack" }, | |
286 {PhysConn_Audio_Tuner, "Tuner" }, | |
287 {PhysConn_Audio_Line, "Line" }, | |
288 {PhysConn_Audio_Mic, "Mic" }, | |
289 {PhysConn_Audio_AESDigital, "AESDiital" }, | |
290 {PhysConn_Audio_SPDIFDigital, "SPDIFDigital" }, | |
291 {PhysConn_Audio_AudioDecoder, "AudioDecoder" }, | |
292 {PhysConn_Audio_SCSI, "SCSI" }, | |
293 {PhysConn_Video_SCSI, "SCSI" }, | |
294 {PhysConn_Audio_AUX, "AUX" }, | |
295 {PhysConn_Video_AUX, "AUX" }, | |
296 {PhysConn_Audio_1394, "1394" }, | |
297 {PhysConn_Video_1394, "1394" }, | |
298 {PhysConn_Audio_USB, "USB" }, | |
299 {PhysConn_Video_USB, "USB" }, | |
300 {-1, NULL } | |
301 }; | |
302 | |
303 static const struct { | |
304 char *chanlist_name; | |
305 int country_code; | |
306 } tv_chanlist2country[]={ | |
307 {"us-bcast", 1}, | |
308 {"russia", 7}, | |
309 {"argentina", 54}, | |
310 {"japan-bcast", 81}, | |
311 {"china-bcast", 86}, | |
312 {"southafrica", 27}, | |
313 {"australia", 61}, | |
314 {"ireland", 353}, | |
315 {"france", 33}, | |
316 {"italy", 39}, | |
317 {"newzealand", 64}, | |
318 //directshow table uses eastern europe freq table for russia | |
319 {"europe-east", 7}, | |
320 //directshow table uses western europe freq table for germany | |
321 {"europe-west", 49}, | |
322 /* cable channels */ | |
323 {"us-cable", 1}, | |
324 {"us-cable-hrc", 1}, | |
325 {"japan-cable", 81}, | |
326 //default is USA | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
327 {NULL, 1} |
24744 | 328 }; |
329 | |
330 /** | |
331 array, contains information about various supported (i hope) image formats | |
332 */ | |
333 static const img_fmt img_fmt_list[] = { | |
25054 | 334 {IMGFMT_YUY2, &MEDIASUBTYPE_YUY2, 16, IMGFMT_YUY2, 0}, |
335 {IMGFMT_YV12, &MEDIASUBTYPE_YV12, 12, IMGFMT_YV12, 0}, | |
336 {IMGFMT_IYUV, &MEDIASUBTYPE_IYUV, 12, IMGFMT_IYUV, 0}, | |
337 {IMGFMT_I420, &MEDIASUBTYPE_I420, 12, IMGFMT_I420, 0}, | |
338 {IMGFMT_UYVY, &MEDIASUBTYPE_UYVY, 16, IMGFMT_UYVY, 0}, | |
339 {IMGFMT_YVYU, &MEDIASUBTYPE_YVYU, 16, IMGFMT_YVYU, 0}, | |
340 {IMGFMT_YVU9, &MEDIASUBTYPE_YVU9, 9, IMGFMT_YVU9, 0}, | |
341 {IMGFMT_BGR32, &MEDIASUBTYPE_RGB32, 32, 0, 0}, | |
342 {IMGFMT_BGR24, &MEDIASUBTYPE_RGB24, 24, 0, 0}, | |
343 {IMGFMT_BGR16, &MEDIASUBTYPE_RGB565, 16, 3, 12}, | |
344 {IMGFMT_BGR15, &MEDIASUBTYPE_RGB555, 16, 3, 12}, | |
345 {0, &GUID_NULL, 0, 0, 0} | |
24744 | 346 }; |
347 | |
348 #define TV_NORMS_COUNT 19 | |
349 static const struct { | |
350 long index; | |
351 char *name; | |
352 } tv_norms[TV_NORMS_COUNT] = { | |
353 { | |
354 AnalogVideo_NTSC_M, "ntsc-m"}, { | |
355 AnalogVideo_NTSC_M_J, "ntsc-mj"}, { | |
356 AnalogVideo_NTSC_433, "ntsc-433"}, { | |
357 AnalogVideo_PAL_B, "pal-b"}, { | |
358 AnalogVideo_PAL_D, "pal-d"}, { | |
359 AnalogVideo_PAL_G, "pal-g"}, { | |
360 AnalogVideo_PAL_H, "pal-h"}, { | |
361 AnalogVideo_PAL_I, "pal-i"}, { | |
362 AnalogVideo_PAL_M, "pal-m"}, { | |
363 AnalogVideo_PAL_N, "pal-n"}, { | |
364 AnalogVideo_PAL_60, "pal-60"}, { | |
365 AnalogVideo_SECAM_B, "secam-b"}, { | |
366 AnalogVideo_SECAM_D, "secam-d"}, { | |
367 AnalogVideo_SECAM_G, "secam-g"}, { | |
368 AnalogVideo_SECAM_H, "secam-h"}, { | |
369 AnalogVideo_SECAM_K, "secam-k"}, { | |
370 AnalogVideo_SECAM_K1, "secam-k1"}, { | |
371 AnalogVideo_SECAM_L, "secam-l"}, { | |
372 AnalogVideo_SECAM_L1, "secam-l1"} | |
373 }; | |
374 static long tv_available_norms[TV_NORMS_COUNT]; | |
375 static int tv_available_norms_count = 0; | |
376 | |
377 | |
378 static long *tv_available_inputs; | |
379 static int tv_available_inputs_count = 0; | |
380 | |
381 /* | |
382 *--------------------------------------------------------------------------------------- | |
383 * | |
384 * Various GUID definitions | |
385 * | |
386 *--------------------------------------------------------------------------------------- | |
387 */ | |
30305
fd0de0336717
Add hack to fix tvi_dshow compilation with 64-bit MinGW
reimar
parents:
30300
diff
changeset
|
388 // selectany can not be used with "static", fixes compilation with mingw-w64 |
fd0de0336717
Add hack to fix tvi_dshow compilation with 64-bit MinGW
reimar
parents:
30300
diff
changeset
|
389 #undef DECLSPEC_SELECTANY |
fd0de0336717
Add hack to fix tvi_dshow compilation with 64-bit MinGW
reimar
parents:
30300
diff
changeset
|
390 #define DECLSPEC_SELECTANY |
24744 | 391 /// CLSID definitions (used for CoCreateInstance call) |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
392 #define CLSID_SampleGrabber MP_CLSID_SampleGrabber |
34115 | 393 MP_DEFINE_LOCAL_GUID(CLSID_SampleGrabber, 0xC1F400A0, 0x3F08, 0x11d3, 0x9F, 0x0B, |
24744 | 394 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
395 #define CLSID_NullRenderer MP_CLSID_NullRenderer |
34115 | 396 MP_DEFINE_LOCAL_GUID(CLSID_NullRenderer, 0xC1F400A4, 0x3F08, 0x11d3, 0x9F, 0x0B, |
24744 | 397 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
398 #define CLSID_SystemDeviceEnum MP_CLSID_SystemDeviceEnum |
34115 | 399 MP_DEFINE_LOCAL_GUID(CLSID_SystemDeviceEnum, 0x62BE5D10, 0x60EB, 0x11d0, 0xBD, 0x3B, |
24744 | 400 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
401 #define CLSID_CaptureGraphBuilder2 MP_CLSID_CaptureGraphBuilder2 |
34115 | 402 MP_DEFINE_LOCAL_GUID(CLSID_CaptureGraphBuilder2, 0xBF87B6E1, 0x8C27, 0x11d0, 0xB3, |
24744 | 403 0xF0, 0x00, 0xAA, 0x00, 0x37, 0x61, 0xC5); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
404 #define CLSID_VideoInputDeviceCategory MP_CLSID_VideoInputDeviceCategory |
34115 | 405 MP_DEFINE_LOCAL_GUID(CLSID_VideoInputDeviceCategory, 0x860BB310, 0x5D01, 0x11d0, |
24744 | 406 0xBD, 0x3B, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
407 #define CLSID_AudioInputDeviceCategory MP_CLSID_AudioInputDeviceCategory |
34115 | 408 MP_DEFINE_LOCAL_GUID(CLSID_AudioInputDeviceCategory, 0x33d9a762, 0x90c8, 0x11d0, |
24744 | 409 0xbd, 0x43, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
410 #define CLSID_FilterGraph MP_CLSID_FilterGraph |
34115 | 411 MP_DEFINE_LOCAL_GUID(CLSID_FilterGraph, 0xe436ebb3, 0x524f, 0x11ce, 0x9f, 0x53, |
24744 | 412 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
413 #define CLSID_SystemClock MP_CLSID_SystemClock |
34115 | 414 MP_DEFINE_LOCAL_GUID(CLSID_SystemClock, 0xe436ebb1, 0x524f, 0x11ce, 0x9f, 0x53, |
24744 | 415 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
416 #ifdef NOT_USED | |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
417 #define CLSID_CaptureGraphBuilder MP_CLSID_CaptureGraphBuilder |
34115 | 418 MP_DEFINE_LOCAL_GUID(CLSID_CaptureGraphBuilder, 0xBF87B6E0, 0x8C27, 0x11d0, 0xB3, |
24744 | 419 0xF0, 0x00, 0xAA, 0x00, 0x37, 0x61, 0xC5); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
420 #define CLSID_VideoPortManager MP_CLSID_VideoPortManager |
34115 | 421 MP_DEFINE_LOCAL_GUID(CLSID_VideoPortManager, 0x6f26a6cd, 0x967b, 0x47fd, 0x87, 0x4a, |
24744 | 422 0x7a, 0xed, 0x2c, 0x9d, 0x25, 0xa2); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
423 #define IID_IPin MP_IID_IPin |
34115 | 424 MP_DEFINE_LOCAL_GUID(IID_IPin, 0x56a86891, 0x0ad4, 0x11ce, 0xb0, 0x3a, 0x00, 0x20, |
24744 | 425 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
426 #define IID_ICaptureGraphBuilder MP_IID_ICaptureGraphBuilder |
34115 | 427 MP_DEFINE_LOCAL_GUID(IID_ICaptureGraphBuilder, 0xbf87b6e0, 0x8c27, 0x11d0, 0xb3, |
24744 | 428 0xf0, 0x00, 0xaa, 0x00, 0x37, 0x61, 0xc5); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
429 #define IID_IFilterGraph MP_IID_IFilterGraph |
34115 | 430 MP_DEFINE_LOCAL_GUID(IID_IFilterGraph, 0x56a8689f, 0x0ad4, 0x11ce, 0xb0, 0x3a, 0x00, |
24744 | 431 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
432 #define PIN_CATEGORY_PREVIEW MP_PIN_CATEGORY_PREVIEW |
34115 | 433 MP_DEFINE_LOCAL_GUID(PIN_CATEGORY_PREVIEW, 0xfb6c4282, 0x0353, 0x11d1, 0x90, 0x5f, |
24744 | 434 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); |
435 #endif | |
436 | |
437 /// IID definitions (used for QueryInterface call) | |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
438 #define IID_IReferenceClock MP_IID_IReferenceClock |
34115 | 439 MP_DEFINE_LOCAL_GUID(IID_IReferenceClock, 0x56a86897, 0x0ad4, 0x11ce, 0xb0, 0x3a, |
24744 | 440 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
441 #define IID_IAMBufferNegotiation MP_IID_IAMBufferNegotiation |
34115 | 442 MP_DEFINE_LOCAL_GUID(IID_IAMBufferNegotiation, 0x56ED71A0, 0xAF5F, 0x11D0, 0xB3, 0xF0, |
24744 | 443 0x00, 0xAA, 0x00, 0x37, 0x61, 0xC5); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
444 #define IID_IKsPropertySet MP_IID_IKsPropertySet |
34115 | 445 MP_DEFINE_LOCAL_GUID(IID_IKsPropertySet, 0x31efac30, 0x515c, 0x11d0, 0xa9, 0xaa, |
24744 | 446 0x00, 0xaa, 0x00, 0x61, 0xbe, 0x93); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
447 #define IID_ISampleGrabber MP_IID_ISampleGrabber |
34115 | 448 MP_DEFINE_LOCAL_GUID(IID_ISampleGrabber, 0x6B652FFF, 0x11FE, 0x4fce, 0x92, 0xAD, |
24744 | 449 0x02, 0x66, 0xB5, 0xD7, 0xC7, 0x8F); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
450 #define IID_ISampleGrabberCB MP_IID_ISampleGrabberCB |
34115 | 451 MP_DEFINE_LOCAL_GUID(IID_ISampleGrabberCB, 0x0579154A, 0x2B53, 0x4994, 0xB0, 0xD0, |
24744 | 452 0xE7, 0x73, 0x14, 0x8E, 0xFF, 0x85); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
453 #define IID_ICaptureGraphBuilder2 MP_IID_ICaptureGraphBuilder2 |
34115 | 454 MP_DEFINE_LOCAL_GUID(IID_ICaptureGraphBuilder2, 0x93e5a4e0, 0x2d50, 0x11d2, 0xab, |
24744 | 455 0xfa, 0x00, 0xa0, 0xc9, 0xc6, 0xe3, 0x8d); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
456 #define IID_ICreateDevEnum MP_IID_ICreateDevEnum |
34115 | 457 MP_DEFINE_LOCAL_GUID(IID_ICreateDevEnum, 0x29840822, 0x5b84, 0x11d0, 0xbd, 0x3b, |
24744 | 458 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
459 #define IID_IGraphBuilder MP_IID_IGraphBuilder |
34115 | 460 MP_DEFINE_LOCAL_GUID(IID_IGraphBuilder, 0x56a868a9, 0x0ad4, 0x11ce, 0xb0, 0x3a, |
24744 | 461 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
462 #define IID_IAMVideoProcAmp MP_IID_IAMVideoProcAmp |
34115 | 463 MP_DEFINE_LOCAL_GUID(IID_IAMVideoProcAmp, 0xC6E13360, 0x30AC, 0x11d0, 0xA1, 0x8C, |
24744 | 464 0x00, 0xA0, 0xC9, 0x11, 0x89, 0x56); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
465 #define IID_IVideoWindow MP_IID_IVideoWindow |
34115 | 466 MP_DEFINE_LOCAL_GUID(IID_IVideoWindow, 0x56a868b4, 0x0ad4, 0x11ce, 0xb0, 0x3a, 0x00, |
24744 | 467 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
468 #define IID_IMediaControl MP_IID_IMediaControl |
34115 | 469 MP_DEFINE_LOCAL_GUID(IID_IMediaControl, 0x56a868b1, 0x0ad4, 0x11ce, 0xb0, 0x3a, |
24744 | 470 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
471 #define IID_IAMTVTuner MP_IID_IAMTVTuner |
34115 | 472 MP_DEFINE_LOCAL_GUID(IID_IAMTVTuner, 0x211A8766, 0x03AC, 0x11d1, 0x8D, 0x13, 0x00, |
24744 | 473 0xAA, 0x00, 0xBD, 0x83, 0x39); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
474 #define IID_IAMCrossbar MP_IID_IAMCrossbar |
34115 | 475 MP_DEFINE_LOCAL_GUID(IID_IAMCrossbar, 0xc6e13380, 0x30ac, 0x11d0, 0xa1, 0x8c, 0x00, |
24744 | 476 0xa0, 0xc9, 0x11, 0x89, 0x56); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
477 #define IID_IAMStreamConfig MP_IID_IAMStreamConfig |
34115 | 478 MP_DEFINE_LOCAL_GUID(IID_IAMStreamConfig, 0xc6e13340, 0x30ac, 0x11d0, 0xa1, 0x8c, |
24744 | 479 0x00, 0xa0, 0xc9, 0x11, 0x89, 0x56); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
480 #define IID_IAMAudioInputMixer MP_IID_IAMAudioInputMixer |
34115 | 481 MP_DEFINE_LOCAL_GUID(IID_IAMAudioInputMixer, 0x54C39221, 0x8380, 0x11d0, 0xB3, 0xF0, |
24744 | 482 0x00, 0xAA, 0x00, 0x37, 0x61, 0xC5); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
483 #define IID_IAMTVAudio MP_IID_IAMTVAudio |
34115 | 484 MP_DEFINE_LOCAL_GUID(IID_IAMTVAudio, 0x83EC1C30, 0x23D1, 0x11d1, 0x99, 0xE6, 0x00, |
24744 | 485 0xA0, 0xC9, 0x56, 0x02, 0x66); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
486 #define IID_IAMAnalogVideoDecoder MP_IID_IAMAnalogVideoDecoder |
34115 | 487 MP_DEFINE_LOCAL_GUID(IID_IAMAnalogVideoDecoder, 0xC6E13350, 0x30AC, 0x11d0, 0xA1, |
24744 | 488 0x8C, 0x00, 0xA0, 0xC9, 0x11, 0x89, 0x56); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
489 #define IID_IPropertyBag MP_IID_IPropertyBag |
34115 | 490 MP_DEFINE_LOCAL_GUID(IID_IPropertyBag, 0x55272a00, 0x42cb, 0x11ce, 0x81, 0x35, 0x00, |
24744 | 491 0xaa, 0x00, 0x4b, 0xb8, 0x51); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
492 #define PIN_CATEGORY_CAPTURE MP_PIN_CATEGORY_CAPTURE |
34115 | 493 MP_DEFINE_LOCAL_GUID(PIN_CATEGORY_CAPTURE, 0xfb6c4281, 0x0353, 0x11d1, 0x90, 0x5f, |
24744 | 494 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
495 #define PIN_CATEGORY_VIDEOPORT MP_PIN_CATEGORY_VIDEOPORT |
34115 | 496 MP_DEFINE_LOCAL_GUID(PIN_CATEGORY_VIDEOPORT, 0xfb6c4285, 0x0353, 0x11d1, 0x90, 0x5f, |
24744 | 497 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
498 #define PIN_CATEGORY_PREVIEW MP_PIN_CATEGORY_PREVIEW |
34115 | 499 MP_DEFINE_LOCAL_GUID(PIN_CATEGORY_PREVIEW, 0xfb6c4282, 0x0353, 0x11d1, 0x90, 0x5f, |
24744 | 500 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
501 #define PIN_CATEGORY_VBI MP_PIN_CATEGORY_VBI |
34115 | 502 MP_DEFINE_LOCAL_GUID(PIN_CATEGORY_VBI, 0xfb6c4284, 0x0353, 0x11d1, 0x90, 0x5f, |
24744 | 503 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
504 #define PROPSETID_TUNER MP_PROPSETID_TUNER |
34115 | 505 MP_DEFINE_LOCAL_GUID(PROPSETID_TUNER, 0x6a2e0605, 0x28e4, 0x11d0, 0xa1, 0x8c, 0x00, |
24744 | 506 0xa0, 0xc9, 0x11, 0x89, 0x56); |
30300
191571148d95
Change GUID declarations in tvi_dshow so they are not exported and thus
reimar
parents:
30127
diff
changeset
|
507 #define MEDIATYPE_VBI MP_MEDIATYPE_VBI |
34115 | 508 MP_DEFINE_LOCAL_GUID(MEDIATYPE_VBI, 0xf72a76e1, 0xeb0a, 0x11d0, 0xac, 0xe4, 0x00, |
24744 | 509 0x00, 0xc0, 0xcc, 0x16, 0xba); |
510 | |
511 #define INSTANCEDATA_OF_PROPERTY_PTR(x) (((KSPROPERTY*)(x)) + 1) | |
512 #define INSTANCEDATA_OF_PROPERTY_SIZE(x) (sizeof((x)) - sizeof(KSPROPERTY)) | |
513 | |
514 #define DEVICE_NAME_MAX_LEN 2000 | |
515 | |
516 /*--------------------------------------------------------------------------------------- | |
517 * Methods, called only from this file | |
518 *---------------------------------------------------------------------------------------*/ | |
519 | |
33618
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
520 static void set_buffer_preference(int nDiv, WAVEFORMATEX *pWF, |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
521 IPin *pOutPin, IPin *pInPin) |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
522 { |
24744 | 523 ALLOCATOR_PROPERTIES prop; |
524 IAMBufferNegotiation* pBN; | |
525 HRESULT hr; | |
526 | |
527 prop.cbAlign = -1; | |
528 prop.cbBuffer = pWF->nAvgBytesPerSec/nDiv; | |
529 if (!prop.cbBuffer) | |
530 prop.cbBuffer = 1; | |
531 prop.cbBuffer += pWF->nBlockAlign - 1; | |
532 prop.cbBuffer -= prop.cbBuffer % pWF->nBlockAlign; | |
533 prop.cbPrefix = -1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
534 prop.cBuffers = -1; |
24744 | 535 |
536 hr=OLE_QUERYINTERFACE(pOutPin,IID_IAMBufferNegotiation,pBN); | |
537 if(FAILED(hr)) | |
538 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: pOutPin->QueryInterface(IID_IAMBufferNegotiation) Error: 0x%x\n",(unsigned int)hr); | |
539 else{ | |
540 hr=OLE_CALL_ARGS(pBN,SuggestAllocatorProperties,&prop); | |
541 if(FAILED(hr)) | |
542 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow:pOutPin->SuggestAllocatorProperties Error:0x%x\n",(unsigned int)hr); | |
543 OLE_RELEASE_SAFE(pBN); | |
544 } | |
545 hr=OLE_QUERYINTERFACE(pInPin,IID_IAMBufferNegotiation,pBN); | |
546 if(FAILED(hr)) | |
547 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: pInPin->QueryInterface(IID_IAMBufferNegotiation) Error: 0x%x",(unsigned int)hr); | |
548 else{ | |
549 hr=OLE_CALL_ARGS(pBN,SuggestAllocatorProperties,&prop); | |
550 if(FAILED(hr)) | |
551 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: pInPit->SuggestAllocatorProperties Error:0x%x\n",(unsigned int)hr); | |
552 OLE_RELEASE_SAFE(pBN); | |
553 } | |
554 } | |
555 /* | |
556 *--------------------------------------------------------------------------------------- | |
557 * | |
558 * CSampleGrabberCD class. Used for receiving samples from DirectShow. | |
559 * | |
560 *--------------------------------------------------------------------------------------- | |
561 */ | |
562 /// CSampleGrabberCD destructor | |
563 static void CSampleGrabberCB_Destroy(CSampleGrabberCB * This) | |
564 { | |
565 free(This->lpVtbl); | |
566 free(This); | |
567 } | |
568 | |
569 /// CSampleGrabberCD IUnknown interface methods implementation | |
570 static long STDCALL CSampleGrabberCB_QueryInterface(ISampleGrabberCB * | |
571 This, | |
572 const GUID * riid, | |
573 void **ppvObject) | |
574 { | |
575 CSampleGrabberCB *me = (CSampleGrabberCB *) This; | |
576 GUID *r; | |
577 unsigned int i = 0; | |
578 Debug printf("CSampleGrabberCB_QueryInterface(%p) called\n", This); | |
579 if (!ppvObject) | |
580 return E_POINTER; | |
581 for (r = me->interfaces; | |
582 i < sizeof(me->interfaces) / sizeof(me->interfaces[0]); r++, i++) | |
583 if (!memcmp(r, riid, sizeof(*r))) { | |
584 OLE_CALL(This, AddRef); | |
585 *ppvObject = This; | |
586 return 0; | |
587 } | |
588 Debug printf("Query failed! (GUID: 0x%x)\n", *(unsigned int *) riid); | |
589 return E_NOINTERFACE; | |
590 } | |
591 | |
592 static long STDCALL CSampleGrabberCB_AddRef(ISampleGrabberCB * This) | |
593 { | |
594 CSampleGrabberCB *me = (CSampleGrabberCB *) This; | |
595 Debug printf("CSampleGrabberCB_AddRef(%p) called (ref:%d)\n", This, | |
596 me->refcount); | |
597 return ++(me->refcount); | |
598 } | |
599 | |
600 static long STDCALL CSampleGrabberCB_Release(ISampleGrabberCB * This) | |
601 { | |
602 CSampleGrabberCB *me = (CSampleGrabberCB *) This; | |
603 Debug printf("CSampleGrabberCB_Release(%p) called (new ref:%d)\n", | |
604 This, me->refcount - 1); | |
605 if (--(me->refcount) == 0) | |
606 CSampleGrabberCB_Destroy(me); | |
607 return 0; | |
608 } | |
609 | |
610 | |
33618
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
611 static HRESULT STDCALL CSampleGrabberCB_BufferCB(ISampleGrabberCB *This, |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
612 double SampleTime, |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
613 BYTE *pBuffer, |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
614 long lBufferLen) |
24744 | 615 { |
616 CSampleGrabberCB *this = (CSampleGrabberCB *) This; | |
617 grabber_ringbuffer_t *rb = this->pbuf; | |
618 | |
619 if (!lBufferLen) | |
620 return E_FAIL; | |
621 | |
622 if (!rb->ringbuffer) { | |
623 rb->buffersize /= lBufferLen; | |
624 if (init_ringbuffer(rb, rb->buffersize, lBufferLen) != S_OK) | |
625 return E_FAIL; | |
626 } | |
627 mp_msg(MSGT_TV, MSGL_DBG4, | |
628 "tvi_dshow: BufferCB(%p): len=%ld ts=%f\n", This, lBufferLen, SampleTime); | |
629 EnterCriticalSection(rb->pMutex); | |
630 if (rb->count >= rb->buffersize) { | |
631 rb->head = (rb->head + 1) % rb->buffersize; | |
632 rb->count--; | |
633 } | |
634 | |
635 memcpy(rb->ringbuffer[rb->tail], pBuffer, | |
636 lBufferLen < rb->blocksize ? lBufferLen : rb->blocksize); | |
637 rb->dpts[rb->tail] = SampleTime; | |
638 rb->tail = (rb->tail + 1) % rb->buffersize; | |
639 rb->count++; | |
640 LeaveCriticalSection(rb->pMutex); | |
641 | |
642 return S_OK; | |
643 } | |
644 | |
645 /// wrapper. directshow does the same when BufferCB callback is requested | |
33618
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
646 static HRESULT STDCALL CSampleGrabberCB_SampleCB(ISampleGrabberCB *This, |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
647 double SampleTime, |
bdfb1aeb4b41
tvi_dshow: Mark functions not used outside of the file as static.
diego
parents:
32511
diff
changeset
|
648 LPMEDIASAMPLE pSample) |
24744 | 649 { |
650 char* buf; | |
651 long len; | |
652 long long tStart,tEnd; | |
653 HRESULT hr; | |
654 grabber_ringbuffer_t *rb = ((CSampleGrabberCB*)This)->pbuf; | |
655 | |
656 len=OLE_CALL(pSample,GetSize); | |
657 tStart=tEnd=0; | |
658 hr=OLE_CALL_ARGS(pSample,GetTime,&tStart,&tEnd); | |
659 if(FAILED(hr)){ | |
660 return hr; | |
661 } | |
662 mp_msg(MSGT_TV, MSGL_DBG4,"tvi_dshow: SampleCB(%p): %d/%d %f\n", This,rb->count,rb->buffersize,1e-7*tStart); | |
663 hr=OLE_CALL_ARGS(pSample,GetPointer,(void*)&buf); | |
664 if(FAILED(hr)){ | |
665 return hr; | |
666 } | |
667 hr=CSampleGrabberCB_BufferCB(This,1e-7*tStart,buf,len); | |
668 return hr; | |
669 | |
670 } | |
671 | |
672 /// main grabbing routine | |
673 static CSampleGrabberCB *CSampleGrabberCB_Create(grabber_ringbuffer_t * | |
674 pbuf) | |
675 { | |
676 CSampleGrabberCB *This = malloc(sizeof(CSampleGrabberCB)); | |
677 if (!This) | |
678 return NULL; | |
679 | |
680 This->lpVtbl = malloc(sizeof(ISampleGrabberVtbl)); | |
681 if (!This->lpVtbl) { | |
682 CSampleGrabberCB_Destroy(This); | |
683 return NULL; | |
684 } | |
685 This->refcount = 1; | |
686 This->lpVtbl->QueryInterface = CSampleGrabberCB_QueryInterface; | |
687 This->lpVtbl->AddRef = CSampleGrabberCB_AddRef; | |
688 This->lpVtbl->Release = CSampleGrabberCB_Release; | |
689 This->lpVtbl->SampleCB = CSampleGrabberCB_SampleCB; | |
690 This->lpVtbl->BufferCB = CSampleGrabberCB_BufferCB; | |
691 | |
692 This->interfaces[0] = IID_IUnknown; | |
693 This->interfaces[1] = IID_ISampleGrabberCB; | |
694 | |
695 This->pbuf = pbuf; | |
696 | |
697 return This; | |
698 } | |
699 | |
700 /* | |
701 *--------------------------------------------------------------------------------------- | |
702 * | |
703 * ROT related methods (register, unregister) | |
704 * | |
705 *--------------------------------------------------------------------------------------- | |
706 */ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
707 /** |
24744 | 708 Registering graph in ROT. User will be able to connect to graph from GraphEdit. |
709 */ | |
710 static HRESULT AddToRot(IUnknown * pUnkGraph, DWORD * pdwRegister) | |
711 { | |
712 IMoniker *pMoniker; | |
713 IRunningObjectTable *pROT; | |
714 WCHAR wsz[256]; | |
715 HRESULT hr; | |
716 | |
717 if (FAILED(GetRunningObjectTable(0, &pROT))) { | |
718 return E_FAIL; | |
719 } | |
720 wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR) pUnkGraph, | |
721 GetCurrentProcessId()); | |
722 hr = CreateItemMoniker(L"!", wsz, &pMoniker); | |
723 if (SUCCEEDED(hr)) { | |
724 hr = OLE_CALL_ARGS(pROT, Register, ROTFLAGS_REGISTRATIONKEEPSALIVE, | |
725 pUnkGraph, pMoniker, pdwRegister); | |
726 OLE_RELEASE_SAFE(pMoniker); | |
727 } | |
728 OLE_RELEASE_SAFE(pROT); | |
729 return hr; | |
730 } | |
731 | |
732 /// Unregistering graph in ROT | |
733 static void RemoveFromRot(DWORD dwRegister) | |
734 { | |
735 IRunningObjectTable *pROT; | |
736 if (SUCCEEDED(GetRunningObjectTable(0, &pROT))) { | |
737 OLE_CALL_ARGS(pROT, Revoke, dwRegister); | |
738 OLE_RELEASE_SAFE(pROT); | |
739 } | |
740 } | |
741 | |
742 /* | |
743 *--------------------------------------------------------------------------------------- | |
744 * | |
745 * ringbuffer related methods (init, destroy) | |
746 * | |
747 *--------------------------------------------------------------------------------------- | |
748 */ | |
749 /** | |
750 * \brief ringbuffer destroying routine | |
751 * | |
752 * \param rb pointer to empty (just allocated) ringbuffer structure | |
753 * | |
754 * \note routine does not frees memory, allocated for grabber_rinbuffer_s structure | |
755 */ | |
756 static void destroy_ringbuffer(grabber_ringbuffer_t * rb) | |
757 { | |
758 int i; | |
759 | |
760 if (!rb) | |
761 return; | |
762 | |
763 if (rb->ringbuffer) { | |
764 for (i = 0; i < rb->buffersize; i++) | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
765 free(rb->ringbuffer[i]); |
24744 | 766 free(rb->ringbuffer); |
767 rb->ringbuffer = NULL; | |
768 } | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
769 free(rb->dpts); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
770 rb->dpts = NULL; |
24744 | 771 if (rb->pMutex) { |
772 DeleteCriticalSection(rb->pMutex); | |
773 free(rb->pMutex); | |
774 rb->pMutex = NULL; | |
775 } | |
776 | |
777 rb->blocksize = 0; | |
778 rb->buffersize = 0; | |
779 rb->head = 0; | |
780 rb->tail = 0; | |
781 rb->count = 0; | |
782 } | |
783 | |
784 /** | |
785 * \brief ringbuffer initialization | |
786 * | |
787 * \param rb pointer to empty (just allocated) ringbuffer structure | |
788 * \param buffersize size of buffer in blocks | |
789 * \param blocksize size of buffer's block | |
790 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
791 * \return S_OK if success |
24744 | 792 * \return E_OUTOFMEMORY not enough memory |
793 * | |
794 * \note routine does not allocates memory for grabber_rinbuffer_s structure | |
795 */ | |
796 static HRESULT init_ringbuffer(grabber_ringbuffer_t * rb, int buffersize, | |
797 int blocksize) | |
798 { | |
799 int i; | |
800 | |
801 if (!rb) | |
802 return E_OUTOFMEMORY; | |
803 | |
804 rb->buffersize = buffersize < 2 ? 2 : buffersize; | |
805 rb->blocksize = blocksize; | |
806 | |
807 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Capture buffer: %d blocks of %d bytes.\n", | |
808 rb->buffersize, rb->blocksize); | |
809 | |
30702 | 810 rb->ringbuffer = malloc(rb->buffersize * sizeof(char *)); |
24744 | 811 if (!rb) |
812 return E_POINTER; | |
813 memset(rb->ringbuffer, 0, rb->buffersize * sizeof(char *)); | |
814 | |
815 for (i = 0; i < rb->buffersize; i++) { | |
30702 | 816 rb->ringbuffer[i] = malloc(rb->blocksize * sizeof(char)); |
24744 | 817 if (!rb->ringbuffer[i]) { |
818 destroy_ringbuffer(rb); | |
819 return E_OUTOFMEMORY; | |
820 } | |
821 } | |
30702 | 822 rb->dpts = malloc(rb->buffersize * sizeof(double)); |
24744 | 823 if (!rb->dpts) { |
824 destroy_ringbuffer(rb); | |
825 return E_OUTOFMEMORY; | |
826 } | |
827 rb->head = 0; | |
828 rb->tail = 0; | |
829 rb->count = 0; | |
830 rb->tStart = -1; | |
30702 | 831 rb->pMutex = malloc(sizeof(CRITICAL_SECTION)); |
24744 | 832 if (!rb->pMutex) { |
833 destroy_ringbuffer(rb); | |
834 return E_OUTOFMEMORY; | |
835 } | |
836 InitializeCriticalSection(rb->pMutex); | |
837 return S_OK; | |
838 } | |
839 | |
840 /* | |
841 *--------------------------------------------------------------------------------------- | |
842 * | |
843 * Tuner related methods (frequency, capabilities, etc | |
844 * | |
845 *--------------------------------------------------------------------------------------- | |
846 */ | |
847 /** | |
848 * \brief returns string with name for givend PsysCon_* constant | |
849 * | |
850 * \param lPhysicalType constant from PhysicalConnectorType enumeration | |
851 * | |
852 * \return pointer to string with apropriate name | |
853 * | |
854 * \note | |
855 * Caller should not free returned pointer | |
856 */ | |
857 static char *physcon2str(const long lPhysicalType) | |
858 { | |
859 int i; | |
860 for(i=0; tv_physcon_types[i].name; i++) | |
861 if(tv_physcon_types[i].type==lPhysicalType) | |
862 return tv_physcon_types[i].name; | |
863 return "Unknown"; | |
864 }; | |
865 | |
866 /** | |
867 * \brief converts MPlayer's chanlist to system country code. | |
868 * | |
869 * \param chanlist MPlayer's chanlist name | |
870 * | |
871 * \return system country code | |
872 * | |
873 * \remarks | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
874 * After call to IAMTVTuner::put_CountryCode with returned value tuner switches to frequency table used in specified |
24744 | 875 * country (which is usually larger then MPlayer's one, so workaround will work fine). |
876 * | |
877 * \todo | |
878 * Resolve trouble with cable channels (DirectShow's tuners must be switched between broadcast and cable channels modes. | |
879 */ | |
880 static int chanlist2country(char *chanlist) | |
881 { | |
882 int i; | |
883 for(i=0; tv_chanlist2country[i].chanlist_name; i++) | |
884 if (!strcmp(chanlist, tv_chanlist2country[i].chanlist_name)) | |
885 break; | |
886 return tv_chanlist2country[i].country_code; | |
887 } | |
888 | |
889 /** | |
890 * \brief loads specified resource from module and return pointer to it | |
891 * | |
892 * \param hDLL valid module desriptor | |
893 * \param index index of resource. resource with name "#<index>" will be loaded | |
894 * | |
895 * \return pointer to loader resource or NULL if error occured | |
896 */ | |
897 static void *GetRC(HMODULE hDLL, int index) | |
898 { | |
899 char szRCDATA[10]; | |
900 char szName[10]; | |
901 HRSRC hRes; | |
902 HGLOBAL hTable; | |
903 | |
904 snprintf(szRCDATA, 10, "#%d", (int)RT_RCDATA); | |
905 snprintf(szName, 10, "#%d", index); | |
906 | |
907 hRes = FindResource(hDLL, szName, szRCDATA); | |
908 if (!hRes) { | |
909 return NULL; | |
910 } | |
911 hTable = LoadResource(hDLL, hRes); | |
912 if (!hTable) { | |
913 return NULL; | |
914 } | |
915 return LockResource(hTable); | |
916 } | |
917 | |
918 /** | |
919 * \brief loads frequency table for given country from kstvtune.ax | |
920 * | |
921 * \param[in] nCountry - country code | |
922 * \param[in] nInputType (TunerInputCable or TunerInputAntenna) | |
923 * \param[out] pplFreqTable - address of variable that receives pointer to array, containing frequencies | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
924 * \param[out] pnLen length of array |
24744 | 925 * \param[out] pnFirst - channel number of first entry in array (nChannelMax) |
926 * | |
927 * \return S_OK if success | |
928 * \return E_POINTER pplFreqTable==NULL || plFirst==NULL || pnLen==NULL | |
929 * \return E_FAIL error occured during load | |
930 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
931 * \remarks |
24744 | 932 * - array must be freed by caller |
933 * - MSDN says that it is not neccessery to unlock or free resource. It will be done after unloading DLL | |
934 */ | |
935 static HRESULT load_freq_table(int nCountry, int nInputType, | |
936 long **pplFreqTable, int *pnLen, | |
937 int *pnFirst) | |
938 { | |
939 HMODULE hDLL; | |
940 long *plFreqTable; | |
941 TRCCountryList *pCountryList; | |
942 int i, index; | |
943 | |
27630
6fe56f6147ea
Add debug message about loaded frequency tables.
voroshil
parents:
27629
diff
changeset
|
944 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: load_freq_table called %d (%s)\n",nCountry,nInputType == TunerInputAntenna ? "broadcast" : "cable"); |
24744 | 945 /* ASSERT(sizeof(TRCCountryList)==10); // need properly aligned structure */ |
946 | |
947 if (!pplFreqTable || !pnFirst || !pnLen) | |
948 return E_POINTER; | |
949 if (!nCountry) | |
950 return E_FAIL; | |
951 | |
952 hDLL = LoadLibrary("kstvtune.ax"); | |
953 if (!hDLL) { | |
954 return E_FAIL; | |
955 } | |
956 pCountryList = GetRC(hDLL, 9999); | |
957 if (!pCountryList) { | |
958 FreeLibrary(hDLL); | |
959 return E_FAIL; | |
960 } | |
961 for (i = 0; pCountryList[i].CountryCode != 0; i++) | |
962 if (pCountryList[i].CountryCode == nCountry) | |
963 break; | |
964 if (pCountryList[i].CountryCode == 0) { | |
965 FreeLibrary(hDLL); | |
966 return E_FAIL; | |
967 } | |
968 if (nInputType == TunerInputCable) | |
969 index = pCountryList[i].CableFreqTable; | |
970 else | |
971 index = pCountryList[i].BroadcastFreqTable; | |
972 | |
973 plFreqTable = GetRC(hDLL, index); //First element is number of first channel, second - number of last channel | |
974 if (!plFreqTable) { | |
975 FreeLibrary(hDLL); | |
976 return E_FAIL; | |
977 } | |
978 *pnFirst = plFreqTable[0]; | |
979 *pnLen = (int) (plFreqTable[1] - plFreqTable[0] + 1); | |
30702 | 980 *pplFreqTable = malloc((*pnLen) * sizeof(long)); |
24744 | 981 if (!*pplFreqTable) { |
982 FreeLibrary(hDLL); | |
983 return E_FAIL; | |
984 } | |
985 for (i = 0; i < *pnLen; i++) { | |
986 (*pplFreqTable)[i] = plFreqTable[i + 2]; | |
27630
6fe56f6147ea
Add debug message about loaded frequency tables.
voroshil
parents:
27629
diff
changeset
|
987 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: load_freq_table #%d => (%ld)\n",i+*pnFirst,(*pplFreqTable)[i]); |
24744 | 988 } |
989 FreeLibrary(hDLL); | |
990 return S_OK; | |
991 } | |
992 | |
993 /** | |
994 * \brief tunes to given frequency through IKsPropertySet call | |
995 * | |
996 * \param pTVTuner IAMTVTuner interface of capture device | |
997 * \param lFreq frequency to tune (in Hz) | |
998 * | |
999 * \return S_OK success | |
1000 * \return apropriate error code otherwise | |
1001 * | |
1002 * \note | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1003 * Due to either bug in driver or error in following code calll to IKsProperty::Set |
24744 | 1004 * in this methods always fail with error 0x8007007a. |
1005 * | |
1006 * \todo test code on other machines and an error | |
1007 */ | |
1008 static HRESULT set_frequency_direct(IAMTVTuner * pTVTuner, long lFreq) | |
1009 { | |
1010 HRESULT hr; | |
1011 DWORD dwSupported = 0; | |
1012 DWORD cbBytes = 0; | |
1013 KSPROPERTY_TUNER_MODE_CAPS_S mode_caps; | |
1014 KSPROPERTY_TUNER_FREQUENCY_S frequency; | |
1015 IKsPropertySet *pKSProp; | |
1016 | |
1017 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_frequency_direct called\n"); | |
1018 | |
1019 memset(&mode_caps, 0, sizeof(mode_caps)); | |
1020 memset(&frequency, 0, sizeof(frequency)); | |
1021 | |
1022 hr = OLE_QUERYINTERFACE(pTVTuner, IID_IKsPropertySet, pKSProp); | |
1023 if (FAILED(hr)) | |
1024 return hr; //no IKsPropertySet interface | |
1025 | |
1026 mode_caps.Mode = AMTUNER_MODE_TV; | |
1027 hr = OLE_CALL_ARGS(pKSProp, QuerySupported, &PROPSETID_TUNER, | |
1028 KSPROPERTY_TUNER_MODE_CAPS, &dwSupported); | |
1029 if (FAILED(hr)) { | |
1030 OLE_RELEASE_SAFE(pKSProp); | |
1031 return hr; | |
1032 } | |
1033 | |
1034 if (!dwSupported & KSPROPERTY_SUPPORT_GET) { | |
1035 OLE_RELEASE_SAFE(pKSProp); | |
1036 return E_FAIL; //PROPSETID_TINER not supported | |
1037 } | |
1038 | |
1039 hr = OLE_CALL_ARGS(pKSProp, Get, &PROPSETID_TUNER, | |
1040 KSPROPERTY_TUNER_MODE_CAPS, | |
1041 INSTANCEDATA_OF_PROPERTY_PTR(&mode_caps), | |
1042 INSTANCEDATA_OF_PROPERTY_SIZE(mode_caps), | |
1043 &mode_caps, sizeof(mode_caps), &cbBytes); | |
1044 | |
1045 frequency.Frequency = lFreq; | |
1046 | |
1047 if (mode_caps.Strategy == KS_TUNER_STRATEGY_DRIVER_TUNES) | |
1048 frequency.TuningFlags = KS_TUNER_TUNING_FINE; | |
1049 else | |
1050 frequency.TuningFlags = KS_TUNER_TUNING_EXACT; | |
1051 | |
1052 if (lFreq < mode_caps.MinFrequency || lFreq > mode_caps.MaxFrequency) { | |
1053 OLE_RELEASE_SAFE(pKSProp); | |
1054 return E_FAIL; | |
1055 } | |
1056 | |
1057 hr = OLE_CALL_ARGS(pKSProp, Set, &PROPSETID_TUNER, | |
1058 KSPROPERTY_TUNER_FREQUENCY, | |
1059 INSTANCEDATA_OF_PROPERTY_PTR(&frequency), | |
1060 INSTANCEDATA_OF_PROPERTY_SIZE(frequency), | |
1061 &frequency, sizeof(frequency)); | |
1062 if (FAILED(hr)) { | |
1063 OLE_RELEASE_SAFE(pKSProp); | |
1064 return hr; | |
1065 } | |
1066 | |
1067 OLE_RELEASE_SAFE(pKSProp); | |
1068 | |
1069 return S_OK; | |
1070 } | |
1071 | |
1072 /** | |
1073 * \brief find channel with nearest frequency and set it | |
1074 * | |
1075 * \param priv driver's private data | |
1076 * \param lFreq frequency in Hz | |
1077 * | |
1078 * \return S_OK if success | |
1079 * \return E_FAIL if error occured | |
1080 */ | |
1081 static HRESULT set_nearest_freq(priv_t * priv, long lFreq) | |
1082 { | |
1083 HRESULT hr; | |
1084 int i; | |
1085 long lFreqDiff=-1; | |
1086 int nChannel; | |
1087 TunerInputType tunerInput; | |
1088 long lInput; | |
1089 | |
27629
d04568721d39
Make output messages of frequency selection code more useful by
voroshil
parents:
27628
diff
changeset
|
1090 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_nearest_freq called: %ld\n", lFreq); |
24744 | 1091 if(priv->freq_table_len == -1 && !priv->freq_table) { |
1092 | |
1093 hr = OLE_CALL_ARGS(priv->pTVTuner, get_ConnectInput, &lInput); | |
1094 if(FAILED(hr)){ //Falling back to 0 | |
1095 lInput=0; | |
1096 } | |
1097 | |
1098 hr = OLE_CALL_ARGS(priv->pTVTuner, get_InputType, lInput, &tunerInput); | |
1099 | |
1100 if (load_freq_table(chanlist2country(priv->tv_param->chanlist), tunerInput, &(priv->freq_table), &(priv->freq_table_len), &(priv->first_channel)) != S_OK) {//FIXME | |
1101 priv->freq_table_len=0; | |
1102 priv->freq_table=NULL; | |
1103 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableExtractFreqTable); | |
1104 return E_FAIL; | |
1105 }; | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
1106 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: loaded system (%s) frequency table for country id=%d (channels:%d).\n", tunerInput == TunerInputAntenna ? "broadcast" : "cable", |
24744 | 1107 chanlist2country(priv->tv_param->chanlist), priv->freq_table_len); |
1108 } | |
1109 | |
1110 if (priv->freq_table_len <= 0) | |
1111 return E_FAIL; | |
1112 | |
1113 //FIXME: rewrite search algo | |
1114 nChannel = -1; | |
1115 for (i = 0; i < priv->freq_table_len; i++) { | |
1116 if (nChannel == -1 || labs(lFreq - priv->freq_table[i]) < lFreqDiff) { | |
1117 nChannel = priv->first_channel + i; | |
1118 lFreqDiff = labs(lFreq - priv->freq_table[i]); | |
1119 } | |
27629
d04568721d39
Make output messages of frequency selection code more useful by
voroshil
parents:
27628
diff
changeset
|
1120 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_nearest_freq #%d (%ld) => %d (%ld)\n",i+priv->first_channel,priv->freq_table[i], nChannel,lFreqDiff); |
24744 | 1121 } |
1122 if (nChannel == -1) { | |
1123 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableFindNearestChannel); | |
1124 return E_FAIL; | |
1125 } | |
27629
d04568721d39
Make output messages of frequency selection code more useful by
voroshil
parents:
27628
diff
changeset
|
1126 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: set_nearest_freq #%d (%ld)\n",nChannel,priv->freq_table[nChannel - priv->first_channel]); |
24744 | 1127 hr = OLE_CALL_ARGS(priv->pTVTuner, put_Channel, nChannel, |
1128 AMTUNER_SUBCHAN_DEFAULT, AMTUNER_SUBCHAN_DEFAULT); | |
1129 if (FAILED(hr)) { | |
1130 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableToSetChannel, (unsigned int)hr); | |
1131 return E_FAIL; | |
1132 } | |
1133 return S_OK; | |
1134 } | |
1135 | |
1136 /** | |
1137 * \brief setting frequency. decides whether use direct call/workaround | |
1138 * | |
1139 * \param priv driver's private data | |
1140 * \param lFreq frequency in Hz | |
1141 * | |
1142 * \return TVI_CONTROL_TRUE if success | |
1143 * \return TVI_CONTROL_FALSE if error occured | |
1144 * | |
1145 * \todo check for freq boundary | |
1146 */ | |
1147 static int set_frequency(priv_t * priv, long lFreq) | |
1148 { | |
1149 HRESULT hr; | |
1150 | |
27629
d04568721d39
Make output messages of frequency selection code more useful by
voroshil
parents:
27628
diff
changeset
|
1151 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_frequency called: %ld\n", lFreq); |
24744 | 1152 if (!priv->pTVTuner) |
1153 return TVI_CONTROL_FALSE; | |
1154 if (priv->direct_setfreq_call) { //using direct call to set frequency | |
1155 hr = set_frequency_direct(priv->pTVTuner, lFreq); | |
1156 if (FAILED(hr)) { | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
1157 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: Unable to set frequency directly. OS built-in channels table will be used.\n"); |
24744 | 1158 priv->direct_setfreq_call = 0; |
1159 } | |
1160 } | |
1161 if (!priv->direct_setfreq_call) { | |
1162 hr = set_nearest_freq(priv, lFreq); | |
1163 } | |
1164 if (FAILED(hr)) | |
1165 return TVI_CONTROL_FALSE; | |
1166 #ifdef DEPRECATED | |
1167 priv->pGrabber->ClearBuffer(priv->pGrabber); | |
1168 #endif | |
1169 return TVI_CONTROL_TRUE; | |
1170 } | |
1171 | |
1172 /** | |
1173 * \brief return current frequency from tuner (in Hz) | |
1174 * | |
1175 * \param pTVTuner IAMTVTuner interface of tuner | |
1176 * \param plFreq address of variable that receives current frequency | |
1177 * | |
1178 * \return S_OK success | |
1179 * \return E_POINTER pTVTuner==NULL || plFreq==NULL | |
1180 * \return apropriate error code otherwise | |
1181 */ | |
1182 static HRESULT get_frequency_direct(IAMTVTuner * pTVTuner, long *plFreq) | |
1183 { | |
1184 HRESULT hr; | |
1185 KSPROPERTY_TUNER_STATUS_S TunerStatus; | |
1186 DWORD cbBytes; | |
1187 IKsPropertySet *pKSProp; | |
1188 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_frequency_direct called\n"); | |
1189 | |
1190 if (!plFreq) | |
1191 return E_POINTER; | |
1192 | |
1193 hr = OLE_QUERYINTERFACE(pTVTuner, IID_IKsPropertySet, pKSProp); | |
1194 if (FAILED(hr)) { | |
1195 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get freq QueryInterface failed\n"); | |
1196 return hr; | |
1197 } | |
1198 | |
1199 hr = OLE_CALL_ARGS(pKSProp, Get, &PROPSETID_TUNER, | |
1200 KSPROPERTY_TUNER_STATUS, | |
1201 INSTANCEDATA_OF_PROPERTY_PTR(&TunerStatus), | |
1202 INSTANCEDATA_OF_PROPERTY_SIZE(TunerStatus), | |
1203 &TunerStatus, sizeof(TunerStatus), &cbBytes); | |
1204 if (FAILED(hr)) { | |
1205 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get freq Get failure\n"); | |
1206 return hr; | |
1207 } | |
1208 *plFreq = TunerStatus.CurrentFrequency; | |
1209 return S_OK; | |
1210 } | |
1211 | |
1212 /** | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1213 * \brief gets current frequency |
24744 | 1214 * |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1215 * \param priv driver's private data structure |
24744 | 1216 * \param plFreq - pointer to long int to store frequency to (in Hz) |
1217 * | |
1218 * \return TVI_CONTROL_TRUE if success, TVI_CONTROL_FALSE otherwise | |
1219 */ | |
1220 static int get_frequency(priv_t * priv, long *plFreq) | |
1221 { | |
1222 HRESULT hr; | |
1223 | |
1224 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_frequency called\n"); | |
1225 | |
1226 if (!plFreq || !priv->pTVTuner) | |
1227 return TVI_CONTROL_FALSE; | |
1228 | |
1229 if (priv->direct_getfreq_call) { //using direct call to get frequency | |
1230 hr = get_frequency_direct(priv->pTVTuner, plFreq); | |
1231 if (FAILED(hr)) { | |
1232 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_DirectGetFreqFailed); | |
1233 priv->direct_getfreq_call = 0; | |
1234 } | |
1235 } | |
1236 if (!priv->direct_getfreq_call) { | |
1237 hr=OLE_CALL_ARGS(priv->pTVTuner, get_VideoFrequency, plFreq); | |
1238 if (FAILED(hr)) | |
1239 return TVI_CONTROL_FALSE; | |
1240 | |
1241 } | |
1242 return TVI_CONTROL_TRUE; | |
1243 } | |
1244 | |
1245 /** | |
1246 * \brief get tuner capabilities | |
1247 * | |
1248 * \param priv driver's private data | |
1249 */ | |
1250 static void get_capabilities(priv_t * priv) | |
1251 { | |
1252 long lAvailableFormats; | |
1253 HRESULT hr; | |
1254 int i; | |
1255 long lInputPins, lOutputPins, lRelated, lPhysicalType; | |
1256 IEnumPins *pEnum; | |
1257 char tmp[200]; | |
1258 IPin *pPin = 0; | |
1259 PIN_DIRECTION ThisPinDir; | |
1260 PIN_INFO pi; | |
1261 IAMAudioInputMixer *pIAMixer; | |
1262 | |
1263 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_capabilities called\n"); | |
1264 if (priv->pTVTuner) { | |
1265 | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
1266 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: supported norms:"); |
24744 | 1267 hr = OLE_CALL_ARGS(priv->pTVTuner, get_AvailableTVFormats, |
1268 &lAvailableFormats); | |
1269 if (FAILED(hr)) | |
1270 tv_available_norms_count = 0; | |
1271 else { | |
1272 for (i = 0; i < TV_NORMS_COUNT; i++) { | |
1273 if (lAvailableFormats & tv_norms[i].index) { | |
1274 tv_available_norms[tv_available_norms_count] = i; | |
1275 mp_msg(MSGT_TV, MSGL_V, " %d=%s;", | |
1276 tv_available_norms_count + 1, tv_norms[i].name); | |
1277 tv_available_norms_count++; | |
1278 } | |
1279 } | |
1280 } | |
1281 mp_msg(MSGT_TV, MSGL_INFO, "\n"); | |
1282 } | |
1283 if (priv->pCrossbar) { | |
1284 OLE_CALL_ARGS(priv->pCrossbar, get_PinCounts, &lOutputPins, | |
1285 &lInputPins); | |
1286 | |
30702 | 1287 tv_available_inputs = malloc(sizeof(long) * lInputPins); |
24744 | 1288 tv_available_inputs_count = 0; |
1289 | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
1290 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: available video inputs:"); |
24744 | 1291 for (i = 0; i < lInputPins; i++) { |
1292 OLE_CALL_ARGS(priv->pCrossbar, get_CrossbarPinInfo, 1, i, | |
1293 &lRelated, &lPhysicalType); | |
1294 | |
1295 if (lPhysicalType < 0x1000) { | |
1296 tv_available_inputs[tv_available_inputs_count++] = i; | |
1297 mp_msg(MSGT_TV, MSGL_V, " %d=%s;", | |
1298 tv_available_inputs_count - 1, | |
1299 physcon2str(lPhysicalType)); | |
1300 } | |
1301 } | |
1302 mp_msg(MSGT_TV, MSGL_INFO, "\n"); | |
1303 | |
1304 set_crossbar_input(priv, 0); | |
1305 } | |
1306 | |
1307 if (priv->adev_index != -1) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
1308 hr = OLE_CALL_ARGS(priv->chains[1]->pCaptureFilter, EnumPins, &pEnum); |
24744 | 1309 if (FAILED(hr)) |
1310 return; | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
1311 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: available audio inputs:"); |
24744 | 1312 i = 0; |
1313 while (OLE_CALL_ARGS(pEnum, Next, 1, &pPin, NULL) == S_OK) { | |
1314 memset(&pi, 0, sizeof(pi)); | |
1315 memset(tmp, 0, 200); | |
1316 OLE_CALL_ARGS(pPin, QueryDirection, &ThisPinDir); | |
1317 if (ThisPinDir == PINDIR_INPUT) { | |
1318 OLE_CALL_ARGS(pPin, QueryPinInfo, &pi); | |
1319 wtoa(pi.achName, tmp, 200); | |
1320 OLE_RELEASE_SAFE(pi.pFilter); | |
1321 mp_msg(MSGT_TV, MSGL_V, " %d=%s", i, tmp); | |
1322 mp_msg(MSGT_TV, MSGL_DBG3, " (%p)", pPin); | |
1323 hr = OLE_QUERYINTERFACE(pPin, IID_IAMAudioInputMixer,pIAMixer); | |
1324 if (SUCCEEDED(hr)) { | |
1325 if (i == priv->tv_param->audio_id) { | |
1326 OLE_CALL_ARGS(pIAMixer, put_Enable, TRUE); | |
1327 if(priv->tv_param->volume>0) | |
1328 OLE_CALL_ARGS(pIAMixer, put_MixLevel, 0.01 * priv->tv_param->volume); | |
1329 #if 0 | |
1330 else | |
1331 OLE_CALL_ARGS(pIAMixer, put_MixLevel, 1.0); | |
1332 #endif | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
1333 mp_msg(MSGT_TV, MSGL_V, "(selected)"); |
24744 | 1334 } else { |
1335 OLE_CALL_ARGS(pIAMixer, put_Enable, FALSE); | |
1336 #if 0 | |
1337 OLE_CALL_ARGS(pIAMixer, put_MixLevel, 0.0); | |
1338 #endif | |
1339 } | |
1340 OLE_RELEASE_SAFE(pIAMixer); | |
1341 } | |
1342 mp_msg(MSGT_TV, MSGL_V, ";"); | |
1343 OLE_RELEASE_SAFE(pPin); | |
1344 i++; | |
1345 } | |
1346 } | |
1347 mp_msg(MSGT_TV, MSGL_INFO, "\n"); | |
1348 OLE_RELEASE_SAFE(pEnum); | |
1349 } | |
1350 } | |
1351 | |
1352 /* | |
1353 *--------------------------------------------------------------------------------------- | |
1354 * | |
1355 * Filter related methods | |
1356 * | |
1357 *--------------------------------------------------------------------------------------- | |
1358 */ | |
1359 /** | |
1360 * \brief building in graph audio/video capture chain | |
1361 * | |
1362 * \param priv driver's private data | |
1363 * \param pCaptureFilter pointer to capture device's IBaseFilter interface | |
1364 * \param pbuf ringbuffer data structure | |
1365 * \param pmt media type for chain (AM_MEDIA_TYPE) | |
1366 * | |
1367 * \note routine does not frees memory, allocated for grabber_rinbuffer_s structure | |
1368 */ | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1369 static HRESULT build_sub_graph(priv_t * priv, chain_t * chain, const GUID* ppin_category) |
24744 | 1370 { |
1371 HRESULT hr; | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1372 int nFormatProbed = 0; |
25029
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1373 |
24744 | 1374 IPin *pSGOut; |
1375 IPin *pNRIn=NULL; | |
1376 | |
1377 IBaseFilter *pNR = NULL; | |
1378 | |
1379 hr=S_OK; | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1380 |
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1381 //No supported formats |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1382 if(!chain->arpmt[0]) |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1383 return E_FAIL; |
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1384 |
24744 | 1385 do{ |
1386 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1387 (IUnknown *) chain->pCaptureFilter, |
24744 | 1388 PINDIR_OUTPUT, ppin_category, |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1389 chain->majortype, FALSE, 0, &chain->pCapturePin); |
24744 | 1390 if(FAILED(hr)){ |
1391 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: FindPin(pCapturePin) call failed. Error:0x%x\n", (unsigned int)hr); | |
1392 break; | |
1393 } | |
1394 /* Addinf SampleGrabber filter for video stream */ | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1395 hr = CoCreateInstance((GUID *) & CLSID_SampleGrabber, NULL,CLSCTX_INPROC_SERVER, &IID_IBaseFilter,(void *) &chain->pSGF); |
24744 | 1396 if(FAILED(hr)){ |
1397 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CoCreateInstance(SampleGrabber) call failed. Error:0x%x\n", (unsigned int)hr); | |
1398 break; | |
1399 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1400 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, chain->pSGF, L"Sample Grabber"); |
24744 | 1401 if(FAILED(hr)){ |
1402 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: AddFilter(SampleGrabber) call failed. Error:0x%x\n", (unsigned int)hr); | |
1403 break; | |
1404 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1405 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, (IUnknown *) chain->pSGF,PINDIR_INPUT, NULL, NULL, FALSE, 0, &chain->pSGIn); |
24744 | 1406 if(FAILED(hr)){ |
1407 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pSGIn) call failed. Error:0x%x\n", (unsigned int)hr); | |
1408 break; | |
1409 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1410 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, (IUnknown *) chain->pSGF,PINDIR_OUTPUT, NULL, NULL, FALSE, 0, &pSGOut); |
24744 | 1411 if(FAILED(hr)){ |
1412 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pSGOut) call failed. Error:0x%x\n", (unsigned int)hr); | |
1413 break; | |
1414 } | |
1415 | |
1416 /* creating ringbuffer for video samples */ | |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
1417 chain->pCSGCB = CSampleGrabberCB_Create(chain->rbuf); |
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
1418 if(!chain->pCSGCB){ |
24744 | 1419 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CSampleGrabberCB_Create(pbuf) call failed. Error:0x%x\n", (unsigned int)E_OUTOFMEMORY); |
1420 break; | |
1421 } | |
1422 | |
1423 /* initializing SampleGrabber filter */ | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1424 hr = OLE_QUERYINTERFACE(chain->pSGF, IID_ISampleGrabber, chain->pSG); |
24744 | 1425 if(FAILED(hr)){ |
1426 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: QueryInterface(IID_ISampleGrabber) call failed. Error:0x%x\n", (unsigned int)hr); | |
1427 break; | |
1428 } | |
1429 // hr = OLE_CALL_ARGS(pSG, SetCallback, (ISampleGrabberCB *) pCSGCB, 1); //we want to receive copy of sample's data | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1430 hr = OLE_CALL_ARGS(chain->pSG, SetCallback, (ISampleGrabberCB *) chain->pCSGCB, 0); //we want to receive sample |
24744 | 1431 |
1432 if(FAILED(hr)){ | |
1433 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetCallback(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1434 break; | |
1435 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1436 hr = OLE_CALL_ARGS(chain->pSG, SetOneShot, FALSE); //... for all frames |
24744 | 1437 if(FAILED(hr)){ |
1438 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetOneShot(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1439 break; | |
1440 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1441 hr = OLE_CALL_ARGS(chain->pSG, SetBufferSamples, FALSE); //... do not buffer samples in sample grabber |
24744 | 1442 if(FAILED(hr)){ |
1443 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetBufferSamples(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1444 break; | |
1445 } | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1446 |
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1447 if(priv->tv_param->normalize_audio_chunks && chain->type==audio){ |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1448 set_buffer_preference(20,(WAVEFORMATEX*)(chain->arpmt[nFormatProbed]->pbFormat),chain->pCapturePin,chain->pSGIn); |
25048 | 1449 } |
24744 | 1450 |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1451 for(nFormatProbed=0; chain->arpmt[nFormatProbed]; nFormatProbed++) |
25065 | 1452 { |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1453 DisplayMediaType("Probing format", chain->arpmt[nFormatProbed]); |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1454 hr = OLE_CALL_ARGS(chain->pSG, SetMediaType, chain->arpmt[nFormatProbed]); //set desired mediatype |
25066 | 1455 if(FAILED(hr)){ |
1456 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetMediaType(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1457 continue; | |
1458 } | |
1459 /* connecting filters together: VideoCapture --> SampleGrabber */ | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1460 hr = OLE_CALL_ARGS(priv->pGraph, Connect, chain->pCapturePin, chain->pSGIn); |
25066 | 1461 if(FAILED(hr)){ |
1462 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: Unable to create pCapturePin<->pSGIn connection. Error:0x%x\n", (unsigned int)hr); | |
1463 continue; | |
1464 } | |
25065 | 1465 break; |
1466 } | |
1467 | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1468 if(!chain->arpmt[nFormatProbed]) |
25065 | 1469 { |
1470 mp_msg(MSGT_TV, MSGL_WARN, "tvi_dshow: Unable to negotiate media format\n"); | |
1471 hr = E_FAIL; | |
24744 | 1472 break; |
1473 } | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1474 |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1475 hr = OLE_CALL_ARGS(chain->pCapturePin, ConnectionMediaType, chain->pmt); |
25029
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1476 if(FAILED(hr)) |
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1477 { |
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1478 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_GetActualMediatypeFailed, (unsigned int)hr); |
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1479 } |
24744 | 1480 |
1481 if(priv->tv_param->hidden_video_renderer){ | |
1482 IEnumFilters* pEnum; | |
1483 IBaseFilter* pFilter; | |
1484 | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1485 hr=OLE_CALL_ARGS(priv->pBuilder,RenderStream,NULL,NULL,(IUnknown*)chain->pCapturePin,NULL,NULL); |
24744 | 1486 |
1487 OLE_CALL_ARGS(priv->pGraph, EnumFilters, &pEnum); | |
1488 while (OLE_CALL_ARGS(pEnum, Next, 1, &pFilter, NULL) == S_OK) { | |
1489 LPVIDEOWINDOW pVideoWindow; | |
1490 hr = OLE_QUERYINTERFACE(pFilter, IID_IVideoWindow, pVideoWindow); | |
1491 if (SUCCEEDED(hr)) | |
1492 { | |
1493 OLE_CALL_ARGS(pVideoWindow,put_Visible,/* OAFALSE*/ 0); | |
1494 OLE_CALL_ARGS(pVideoWindow,put_AutoShow,/* OAFALSE*/ 0); | |
1495 OLE_RELEASE_SAFE(pVideoWindow); | |
1496 } | |
1497 OLE_RELEASE_SAFE(pFilter); | |
1498 } | |
1499 OLE_RELEASE_SAFE(pEnum); | |
1500 }else | |
1501 { | |
25052
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1502 #if 0 |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1503 /* |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1504 Code below is disabled, because terminating chain with NullRenderer leads to jerky video. |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1505 Perhaps, this happens because NullRenderer filter discards each received |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1506 frame while discarded frames causes live source filter to dramatically reduce frame rate. |
25052
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1507 */ |
24744 | 1508 /* adding sink for video stream */ |
1509 hr = CoCreateInstance((GUID *) & CLSID_NullRenderer, NULL,CLSCTX_INPROC_SERVER, &IID_IBaseFilter,(void *) &pNR); | |
1510 if(FAILED(hr)){ | |
1511 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: CoCreateInstance(NullRenderer) call failed. Error:0x%x\n", (unsigned int)hr); | |
1512 break; | |
1513 } | |
1514 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, pNR, L"Null Renderer"); | |
1515 if(FAILED(hr)){ | |
1516 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: AddFilter(NullRenderer) call failed. Error:0x%x\n", (unsigned int)hr); | |
1517 break; | |
1518 } | |
1519 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, (IUnknown *) pNR,PINDIR_INPUT, NULL, NULL, FALSE, 0, &pNRIn); | |
1520 if(FAILED(hr)){ | |
1521 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pNRIn) call failed. Error:0x%x\n", (unsigned int)hr); | |
1522 break; | |
1523 } | |
1524 /* | |
1525 Prevent ending VBI chain with NullRenderer filter, because this causes VBI pin disconnection | |
1526 */ | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1527 if(memcmp(&(arpmt[nFormatProbed]->majortype),&MEDIATYPE_VBI,16)){ |
24744 | 1528 /* connecting filters together: SampleGrabber --> NullRenderer */ |
1529 hr = OLE_CALL_ARGS(priv->pGraph, Connect, pSGOut, pNRIn); | |
1530 if(FAILED(hr)){ | |
1531 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: Unable to create pSGOut<->pNRIn connection. Error:0x%x\n", (unsigned int)hr); | |
1532 break; | |
1533 } | |
1534 } | |
25052
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1535 #endif |
24744 | 1536 } |
1537 | |
1538 hr = S_OK; | |
1539 } while(0); | |
25029
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1540 |
24744 | 1541 OLE_RELEASE_SAFE(pSGOut); |
1542 OLE_RELEASE_SAFE(pNR); | |
1543 OLE_RELEASE_SAFE(pNRIn); | |
1544 | |
1545 return hr; | |
1546 } | |
1547 | |
1548 /** | |
1549 * \brief configures crossbar for grabbing video stream from given input | |
1550 * | |
1551 * \param priv driver's private data | |
1552 * \param input index of available video input to get data from | |
1553 * | |
1554 * \return TVI_CONTROL_TRUE success | |
1555 * \return TVI_CONTROL_FALSE error | |
1556 */ | |
1557 static int set_crossbar_input(priv_t * priv, int input) | |
1558 { | |
1559 HRESULT hr; | |
1560 int i, nVideoDecoder, nAudioDecoder; | |
1561 long lInput, lInputRelated, lRelated, lPhysicalType, lOutputPins, | |
1562 lInputPins; | |
1563 | |
1564 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: Configuring crossbar\n"); | |
1565 if (!priv->pCrossbar || input < 0 | |
1566 || input >= tv_available_inputs_count) | |
1567 return TVI_CONTROL_FALSE; | |
1568 | |
1569 OLE_CALL_ARGS(priv->pCrossbar, get_PinCounts, &lOutputPins, &lInputPins); | |
1570 | |
1571 lInput = tv_available_inputs[input]; | |
1572 | |
1573 if (lInput < 0 || lInput >= lInputPins) | |
1574 return TVI_CONTROL_FALSE; | |
1575 | |
1576 OLE_CALL_ARGS(priv->pCrossbar, get_CrossbarPinInfo, 1 /* input */ , lInput, | |
1577 &lInputRelated, &lPhysicalType); | |
1578 | |
1579 nVideoDecoder = nAudioDecoder = -1; | |
1580 for (i = 0; i < lOutputPins; i++) { | |
1581 OLE_CALL_ARGS(priv->pCrossbar, get_CrossbarPinInfo, 0 /*output */ , i, | |
1582 &lRelated, &lPhysicalType); | |
1583 if (lPhysicalType == PhysConn_Video_VideoDecoder) | |
1584 nVideoDecoder = i; | |
1585 if (lPhysicalType == PhysConn_Audio_AudioDecoder) | |
1586 nAudioDecoder = i; | |
1587 } | |
1588 if (nVideoDecoder >= 0) { | |
1589 //connecting given input with video decoder | |
1590 hr = OLE_CALL_ARGS(priv->pCrossbar, Route, nVideoDecoder, lInput); | |
1591 if (hr != S_OK) { | |
1592 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableConnectInputVideoDecoder, (unsigned int)hr); | |
1593 return TVI_CONTROL_FALSE; | |
1594 } | |
1595 } | |
1596 if (nAudioDecoder >= 0 && lInputRelated >= 0) { | |
1597 hr = OLE_CALL_ARGS(priv->pCrossbar, Route, nAudioDecoder, | |
1598 lInputRelated); | |
1599 if (hr != S_OK) { | |
1600 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableConnectInputAudioDecoder, (unsigned int)hr); | |
1601 return TVI_CONTROL_FALSE; | |
1602 } | |
1603 } | |
1604 return TVI_CONTROL_TRUE; | |
1605 } | |
1606 | |
1607 /** | |
1608 * \brief adjusts video control (hue,saturation,contrast,brightess) | |
1609 * | |
1610 * \param priv driver's private data | |
1611 * \param control which control to adjust | |
1612 * \param value new value for control (0-100) | |
1613 * | |
1614 * \return TVI_CONTROL_TRUE success | |
1615 * \return TVI_CONTROL_FALSE error | |
1616 */ | |
1617 static int set_control(priv_t * priv, int control, int value) | |
1618 { | |
1619 long lMin, lMax, lStepping, lDefault, lFlags, lValue; | |
1620 HRESULT hr; | |
1621 | |
1622 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_control called\n"); | |
1623 if (value < -100 || value > 100 || !priv->pVideoProcAmp) | |
1624 return TVI_CONTROL_FALSE; | |
1625 | |
1626 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, GetRange, control, | |
1627 &lMin, &lMax, &lStepping, &lDefault, &lFlags); | |
1628 if (FAILED(hr) || lFlags != VideoProcAmp_Flags_Manual) | |
1629 return TVI_CONTROL_FALSE; | |
1630 | |
1631 lValue = lMin + (value + 100) * (lMax - lMin) / 200; | |
1632 /* | |
1633 Workaround for ATI AIW 7500. The driver reports: max=255, stepping=256 | |
1634 */ | |
1635 if (lStepping > lMax) { | |
1636 mp_msg(MSGT_TV, MSGL_DBG3, | |
1637 "tvi_dshow: Stepping (%ld) is bigger than max value (%ld) for control %d. Assuming 1\n", | |
1638 lStepping, lMax,control); | |
1639 lStepping = 1; | |
1640 } | |
1641 lValue -= lValue % lStepping; | |
1642 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, Set, control, lValue, | |
1643 VideoProcAmp_Flags_Manual); | |
1644 if (FAILED(hr)) | |
1645 return TVI_CONTROL_FALSE; | |
1646 | |
1647 return TVI_CONTROL_TRUE; | |
1648 } | |
1649 | |
1650 /** | |
1651 * \brief get current value of video control (hue,saturation,contrast,brightess) | |
1652 * | |
1653 * \param priv driver's private data | |
1654 * \param control which control to adjust | |
1655 * \param pvalue address of variable thar receives current value | |
1656 * | |
1657 * \return TVI_CONTROL_TRUE success | |
1658 * \return TVI_CONTROL_FALSE error | |
1659 */ | |
1660 static int get_control(priv_t * priv, int control, int *pvalue) | |
1661 { | |
1662 long lMin, lMax, lStepping, lDefault, lFlags, lValue; | |
1663 HRESULT hr; | |
1664 | |
1665 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_control called\n"); | |
1666 if (!pvalue || !priv->pVideoProcAmp) | |
1667 return TVI_CONTROL_FALSE; | |
1668 | |
1669 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, GetRange, control, | |
1670 &lMin, &lMax, &lStepping, &lDefault, &lFlags); | |
1671 if (FAILED(hr)) | |
1672 return TVI_CONTROL_FALSE; | |
1673 if (lMin == lMax) { | |
1674 *pvalue = lMin; | |
1675 return TVI_CONTROL_TRUE; | |
1676 } | |
1677 | |
1678 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, Get, control, &lValue, &lFlags); | |
1679 if (FAILED(hr)) | |
1680 return TVI_CONTROL_FALSE; | |
1681 | |
1682 *pvalue = 200 * (lValue - lMin) / (lMax - lMin) - 100; | |
1683 | |
1684 return TVI_CONTROL_TRUE; | |
1685 } | |
1686 | |
1687 /** | |
25053
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1688 * \brief create AM_MEDIA_TYPE structure, corresponding to given FourCC code and width/height/fps |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1689 * \param fcc FourCC code for video format |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1690 * \param width picture width |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1691 * \param height pciture height |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1692 * \param fps frames per second (required for bitrate calculation) |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1693 * |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1694 * \return pointer to AM_MEDIA_TYPE structure if success, NULL - otherwise |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1695 */ |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1696 static AM_MEDIA_TYPE* create_video_format(int fcc, int width, int height, int fps) |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1697 { |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1698 int i; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1699 AM_MEDIA_TYPE mt; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1700 VIDEOINFOHEADER vHdr; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1701 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1702 /* Check given fcc in lookup table*/ |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1703 for(i=0; img_fmt_list[i].fmt && img_fmt_list[i].fmt!=fcc; i++) /* NOTHING */; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1704 if(!img_fmt_list[i].fmt) |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1705 return NULL; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1706 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1707 memset(&mt, 0, sizeof(AM_MEDIA_TYPE)); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1708 memset(&vHdr, 0, sizeof(VIDEOINFOHEADER)); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1709 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1710 vHdr.bmiHeader.biSize = sizeof(vHdr.bmiHeader); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1711 vHdr.bmiHeader.biWidth = width; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1712 vHdr.bmiHeader.biHeight = height; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1713 //FIXME: is biPlanes required too? |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1714 //vHdr.bmiHeader.biPlanes = img_fmt_list[i].nPlanes; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1715 vHdr.bmiHeader.biBitCount = img_fmt_list[i].nBits; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1716 vHdr.bmiHeader.biCompression = img_fmt_list[i].nCompression; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1717 vHdr.bmiHeader.biSizeImage = width * height * img_fmt_list[i].nBits / 8; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1718 vHdr.dwBitRate = vHdr.bmiHeader.biSizeImage * 8 * fps; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1719 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1720 mt.pbFormat = (char*)&vHdr; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1721 mt.cbFormat = sizeof(vHdr); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1722 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1723 mt.majortype = MEDIATYPE_Video; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1724 mt.subtype = *img_fmt_list[i].subtype; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1725 mt.formattype = FORMAT_VideoInfo; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1726 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1727 mt.bFixedSizeSamples = 1; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1728 mt.bTemporalCompression = 0; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1729 mt.lSampleSize = vHdr.bmiHeader.biSizeImage; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1730 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1731 return CreateMediaType(&mt); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1732 } |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1733 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1734 /** |
24744 | 1735 * \brief extracts fcc,width,height from AM_MEDIA_TYPE |
1736 * | |
1737 * \param pmt pointer to AM_MEDIA_TYPE to extract data from | |
1738 * \param pfcc address of variable that receives FourCC | |
1739 * \param pwidth address of variable that receives width | |
1740 * \param pheight address of variable that recevies height | |
1741 * | |
1742 * \return 1 if data extracted successfully, 0 - otherwise | |
1743 */ | |
1744 static int extract_video_format(AM_MEDIA_TYPE * pmt, int *pfcc, | |
1745 int *pwidth, int *pheight) | |
1746 { | |
1747 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: extract_video_format called\n"); | |
1748 if (!pmt) | |
1749 return 0; | |
1750 if (!pmt->pbFormat) | |
1751 return 0; | |
1752 if (memcmp(&(pmt->formattype), &FORMAT_VideoInfo, 16) != 0) | |
1753 return 0; | |
1754 if (pfcc) | |
1755 *pfcc = subtype2imgfmt(&(pmt->subtype)); | |
1756 if (pwidth) | |
1757 *pwidth = ((VIDEOINFOHEADER *) pmt->pbFormat)->bmiHeader.biWidth; | |
1758 if (pheight) | |
1759 *pheight = ((VIDEOINFOHEADER *) pmt->pbFormat)->bmiHeader.biHeight; | |
1760 return 1; | |
1761 } | |
1762 | |
1763 /** | |
1764 * \brief extracts samplerate,bits,channels from AM_MEDIA_TYPE | |
1765 * | |
1766 * \param pmt pointer to AM_MEDIA_TYPE to extract data from | |
1767 * \param pfcc address of variable that receives samplerate | |
1768 * \param pwidth address of variable that receives number of bits per sample | |
1769 * \param pheight address of variable that recevies number of channels | |
1770 * | |
1771 * \return 1 if data extracted successfully, 0 - otherwise | |
1772 */ | |
1773 static int extract_audio_format(AM_MEDIA_TYPE * pmt, int *psamplerate, | |
1774 int *pbits, int *pchannels) | |
1775 { | |
1776 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: extract_audio_format called\n"); | |
1777 if (!pmt) | |
1778 return 0; | |
1779 if (!pmt->pbFormat) | |
1780 return 0; | |
1781 if (memcmp(&(pmt->formattype), &FORMAT_WaveFormatEx, 16) != 0) | |
1782 return 0; | |
1783 if (psamplerate) | |
1784 *psamplerate = ((WAVEFORMATEX *) pmt->pbFormat)->nSamplesPerSec; | |
1785 if (pbits) | |
1786 *pbits = ((WAVEFORMATEX *) pmt->pbFormat)->wBitsPerSample; | |
1787 if (pchannels) | |
1788 *pchannels = ((WAVEFORMATEX *) pmt->pbFormat)->nChannels; | |
1789 return 1; | |
1790 } | |
1791 | |
1792 /** | |
1793 * \brief checks if AM_MEDIA_TYPE compatible with given samplerate,bits,channels | |
1794 * | |
1795 * \param pmt pointer to AM_MEDIA_TYPE for check | |
1796 * \param samplerate audio samplerate | |
1797 * \param bits bits per sample | |
1798 * \param channels number of audio channels | |
1799 * | |
1800 * \return 1 if AM_MEDIA_TYPE compatible | |
1801 * \return 0 if not | |
1802 */ | |
1803 static int check_audio_format(AM_MEDIA_TYPE * pmt, int samplerate, | |
1804 int bits, int channels) | |
1805 { | |
1806 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: check_audio_format called\n"); | |
1807 if (!pmt) | |
1808 return 0; | |
1809 if (memcmp(&(pmt->majortype), &MEDIATYPE_Audio, 16) != 0) | |
1810 return 0; | |
1811 if (memcmp(&(pmt->subtype), &MEDIASUBTYPE_PCM, 16) != 0) | |
1812 return 0; | |
1813 if (memcmp(&(pmt->formattype), &FORMAT_WaveFormatEx, 16) != 0) | |
1814 return 0; | |
1815 if (!pmt->pbFormat) | |
1816 return 0; | |
1817 if (((WAVEFORMATEX *) pmt->pbFormat)->nSamplesPerSec != samplerate) | |
1818 return 0; | |
1819 if (((WAVEFORMATEX *) pmt->pbFormat)->wBitsPerSample != bits) | |
1820 return 0; | |
1821 if (channels > 0 | |
1822 && ((WAVEFORMATEX *) pmt->pbFormat)->nChannels != channels) | |
1823 return 0; | |
1824 | |
1825 return 1; | |
1826 } | |
1827 | |
1828 /** | |
1829 * \brief checks if AM_MEDIA_TYPE compatible with given fcc,width,height | |
1830 * | |
1831 * \param pmt pointer to AM_MEDIA_TYPE for check | |
1832 * \param fcc FourCC (compression) | |
1833 * \param width width of picture | |
1834 * \param height height of picture | |
1835 * | |
1836 * \return 1 if AM_MEDIA_TYPE compatible | |
1837 & \return 0 if not | |
1838 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1839 * \note |
24744 | 1840 * width and height are currently not used |
1841 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1842 * \todo |
24744 | 1843 * add width/height check |
1844 */ | |
1845 static int check_video_format(AM_MEDIA_TYPE * pmt, int fcc, int width, | |
1846 int height) | |
1847 { | |
1848 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: check_video_format called\n"); | |
1849 if (!pmt) | |
1850 return 0; | |
1851 if (memcmp(&(pmt->majortype), &MEDIATYPE_Video, 16) != 0) | |
1852 return 0; | |
1853 if (subtype2imgfmt(&(pmt->subtype)) != fcc) | |
1854 return 0; | |
1855 return 1; | |
1856 } | |
1857 | |
1858 /** | |
1859 * \brief converts DirectShow subtype to MPlayer's IMGFMT | |
1860 * | |
1861 * \param subtype DirectShow subtype for video format | |
1862 * | |
1863 * \return MPlayer's IMGFMT or 0 if error occured | |
1864 */ | |
1865 static int subtype2imgfmt(const GUID * subtype) | |
1866 { | |
1867 int i; | |
1868 for (i = 0; img_fmt_list[i].fmt; i++) { | |
1869 if (memcmp(subtype, img_fmt_list[i].subtype, 16) == 0) | |
1870 return img_fmt_list[i].fmt; | |
1871 } | |
1872 return 0; | |
1873 } | |
1874 | |
1875 /** | |
1876 * \brief prints filter name and it pins | |
1877 * | |
1878 * \param pFilter - IBaseFilter to get data from | |
1879 * | |
1880 * \return S_OK if success, error code otherwise | |
1881 */ | |
1882 static HRESULT show_filter_info(IBaseFilter * pFilter) | |
1883 { | |
1884 char tmp[200]; | |
1885 FILTER_INFO fi; | |
1886 LPENUMPINS pEnum = 0; | |
1887 IPin *pPin = 0; | |
1888 PIN_DIRECTION ThisPinDir; | |
1889 PIN_INFO pi; | |
1890 HRESULT hr; | |
1891 int i; | |
1892 | |
1893 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: show_filter_info called\n"); | |
1894 memset(&fi, 0, sizeof(fi)); | |
1895 memset(tmp, 0, 200); | |
1896 | |
1897 OLE_CALL_ARGS(pFilter, QueryFilterInfo, &fi); | |
1898 OLE_RELEASE_SAFE(fi.pGraph); | |
1899 wtoa(fi.achName, tmp, 200); | |
1900 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: BaseFilter (%p): Name=%s, Graph=%p output pins:", | |
1901 pFilter, tmp, fi.pGraph); | |
1902 hr = OLE_CALL_ARGS(pFilter, EnumPins, &pEnum); | |
1903 if (FAILED(hr)) | |
1904 return hr; | |
1905 i = 0; | |
1906 while (OLE_CALL_ARGS(pEnum, Next, 1, &pPin, NULL) == S_OK) { | |
1907 memset(&pi, 0, sizeof(pi)); | |
1908 memset(tmp, 0, 200); | |
1909 OLE_CALL_ARGS(pPin, QueryDirection, &ThisPinDir); | |
1910 if (ThisPinDir == PINDIR_OUTPUT) { | |
1911 OLE_CALL_ARGS(pPin, QueryPinInfo, &pi); | |
1912 wtoa(pi.achName, tmp, 200); | |
1913 OLE_RELEASE_SAFE(pi.pFilter); | |
1914 mp_msg(MSGT_TV, MSGL_DBG2, " %d=%s", i, tmp); | |
1915 mp_msg(MSGT_TV, MSGL_DBG3, " (%p)", pPin); | |
1916 mp_msg(MSGT_TV, MSGL_DBG2, ";"); | |
1917 OLE_RELEASE_SAFE(pPin); | |
1918 i++; | |
1919 } | |
1920 } | |
1921 mp_msg(MSGT_TV, MSGL_DBG2, "\n"); | |
1922 OLE_RELEASE_SAFE(pEnum); | |
1923 return S_OK; | |
1924 } | |
1925 | |
1926 /** | |
1927 * \brief gets device's frendly in ANSI encoding | |
1928 * | |
1929 * \param pM IMoniker interface, got in enumeration process | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1930 * \param category device category |
24744 | 1931 * |
1932 * \return TVI_CONTROL_TRUE if operation succeded, TVI_CONTROL_FALSE - otherwise | |
1933 */ | |
1934 static int get_device_name(IMoniker * pM, char *pBuf, int nLen) | |
1935 { | |
1936 HRESULT hr; | |
1937 VARIANT var; | |
1938 IPropertyBag *pPropBag; | |
1939 hr = OLE_CALL_ARGS(pM, BindToStorage, 0, 0, &IID_IPropertyBag,(void *) &pPropBag); | |
1940 if (FAILED(hr)) { | |
1941 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Call to BindToStorage failed\n"); | |
1942 return TVI_CONTROL_FALSE; | |
1943 } | |
1944 var.vt = VT_BSTR; | |
1945 hr = OLE_CALL_ARGS(pPropBag, Read, L"Description", (LPVARIANT) & var, | |
1946 NULL); | |
1947 if (FAILED(hr)) { | |
1948 hr = OLE_CALL_ARGS(pPropBag, Read, L"FriendlyName", (LPVARIANT) & var, | |
1949 NULL); | |
1950 } | |
1951 OLE_RELEASE_SAFE(pPropBag); | |
1952 if (SUCCEEDED(hr)) { | |
1953 wtoa(var.bstrVal, pBuf, nLen); | |
1954 return TVI_CONTROL_TRUE; | |
1955 } | |
1956 return TVI_CONTROL_FALSE; | |
1957 } | |
1958 | |
1959 /** | |
1960 * \brief find capture device at given index | |
1961 * | |
1962 * \param index device index to search for (-1 mean only print available) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1963 * \param category device category |
24744 | 1964 * |
1965 * \return IBaseFilter interface for capture device with given index | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
1966 * |
24744 | 1967 * Sample values for category: |
1968 * CLSID_VideoInputDeviceCategory - Video Capture Sources | |
1969 * CLSID_AudioInputDeviceCategory - Audio Capture Sources | |
1970 * See DirectShow SDK documentation for other possible values | |
1971 */ | |
1972 static IBaseFilter *find_capture_device(int index, REFCLSID category) | |
1973 { | |
1974 IBaseFilter *pFilter = NULL; | |
1975 ICreateDevEnum *pDevEnum = NULL; | |
1976 IEnumMoniker *pClassEnum = NULL; | |
1977 IMoniker *pM; | |
1978 HRESULT hr; | |
1979 ULONG cFetched; | |
1980 int i; | |
1981 char tmp[DEVICE_NAME_MAX_LEN + 1]; | |
1982 hr = CoCreateInstance((GUID *) & CLSID_SystemDeviceEnum, NULL, | |
1983 CLSCTX_INPROC_SERVER, &IID_ICreateDevEnum, | |
1984 (void *) &pDevEnum); | |
1985 if (FAILED(hr)) { | |
1986 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to create device enumerator\n"); | |
1987 return NULL; | |
1988 } | |
1989 | |
1990 hr = OLE_CALL_ARGS(pDevEnum, CreateClassEnumerator, category, &pClassEnum, 0); | |
1991 OLE_RELEASE_SAFE(pDevEnum); | |
1992 if (FAILED(hr)) { | |
1993 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to create class enumerator\n"); | |
1994 return NULL; | |
1995 } | |
1996 if (hr == S_FALSE) { | |
1997 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: No capture devices found\n"); | |
1998 return NULL; | |
1999 } | |
2000 | |
2001 OLE_CALL(pClassEnum,Reset); | |
2002 for (i = 0; OLE_CALL_ARGS(pClassEnum, Next, 1, &pM, &cFetched) == S_OK; i++) { | |
2003 if(get_device_name(pM, tmp, DEVICE_NAME_MAX_LEN)!=TVI_CONTROL_TRUE) | |
2004 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableGetDeviceName, i); | |
2005 else | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
33622
diff
changeset
|
2006 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: Device #%d: %s\n", i, tmp); |
24744 | 2007 if (index != -1 && i == index) { |
2008 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_UsingDevice, index, tmp); | |
2009 hr = OLE_CALL_ARGS(pM, BindToObject, 0, 0, &IID_IBaseFilter,(void *) &pFilter); | |
2010 if (FAILED(hr)) | |
2011 pFilter = NULL; | |
2012 } | |
2013 OLE_RELEASE_SAFE(pM); | |
2014 } | |
2015 if (index != -1 && !pFilter) { | |
2016 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_DeviceNotFound, | |
2017 index); | |
2018 } | |
2019 OLE_RELEASE_SAFE(pClassEnum); | |
2020 | |
2021 return pFilter; | |
2022 } | |
2023 | |
2024 /** | |
2025 * \brief get array of available formats through call to IAMStreamConfig::GetStreamCaps | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2026 * |
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2027 * \praram[in] chain chain data structure |
24744 | 2028 * |
2029 * \return S_OK success | |
2030 * \return E_POINTER one of parameters is NULL | |
2031 * \return E_FAIL required size of buffer is unknown for given media type | |
2032 * \return E_OUTOFMEMORY not enough memory | |
2033 * \return other error code from called methods | |
2034 * | |
2035 * \remarks | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2036 * last items of chain->arpmt and chain->arStreamCaps will be NULL |
24744 | 2037 */ |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2038 static HRESULT get_available_formats_stream(chain_t *chain) |
24744 | 2039 { |
2040 AM_MEDIA_TYPE **arpmt; | |
2041 void **pBuf=NULL; | |
2042 | |
2043 HRESULT hr; | |
2044 int i, count, size; | |
2045 int done; | |
2046 | |
2047 mp_msg(MSGT_TV, MSGL_DBG4, | |
2048 "tvi_dshow: get_available_formats_stream called\n"); | |
2049 | |
25090 | 2050 if (!chain->pStreamConfig) |
24744 | 2051 return E_POINTER; |
2052 | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2053 hr=OLE_CALL_ARGS(chain->pStreamConfig, GetNumberOfCapabilities, &count, &size); |
24744 | 2054 if (FAILED(hr)) { |
2055 mp_msg(MSGT_TV, MSGL_DBG4, | |
2056 "tvi_dshow: Call to GetNumberOfCapabilities failed (get_available_formats_stream)\n"); | |
2057 return hr; | |
2058 } | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2059 if (chain->type == video){ |
24744 | 2060 if (size != sizeof(VIDEO_STREAM_CONFIG_CAPS)) { |
2061 mp_msg(MSGT_TV, MSGL_DBG4, | |
2062 "tvi_dshow: Wrong video structure size for GetNumberOfCapabilities (get_available_formats_stream)\n"); | |
2063 return E_FAIL; | |
25089
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2064 } |
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2065 } else if (chain->type == audio){ |
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2066 if (size != sizeof(AUDIO_STREAM_CONFIG_CAPS)) { |
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2067 mp_msg(MSGT_TV, MSGL_DBG4, |
24744 | 2068 "tvi_dshow: Wrong audio structure size for GetNumberOfCapabilities (get_available_formats_stream)\n"); |
25089
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2069 return E_FAIL; |
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2070 } |
791f867d0124
Fix totally wrong (due to mess of brackets) structures size check.
voroshil
parents:
25088
diff
changeset
|
2071 } else { |
24744 | 2072 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnsupportedMediaType,"get_available_formats_stream"); |
2073 return E_FAIL; | |
2074 } | |
2075 done = 0; | |
2076 | |
30702 | 2077 arpmt = malloc((count + 1) * sizeof(AM_MEDIA_TYPE *)); |
24744 | 2078 if (arpmt) { |
2079 memset(arpmt, 0, (count + 1) * sizeof(AM_MEDIA_TYPE *)); | |
2080 | |
30702 | 2081 pBuf = malloc((count + 1) * sizeof(void *)); |
24744 | 2082 if (pBuf) { |
2083 memset(pBuf, 0, (count + 1) * sizeof(void *)); | |
2084 | |
2085 for (i = 0; i < count; i++) { | |
25127
6e039dd0b5d8
Revert r25089 (Ignore video formats which are supported by device
voroshil
parents:
25126
diff
changeset
|
2086 pBuf[i] = malloc(size); |
6e039dd0b5d8
Revert r25089 (Ignore video formats which are supported by device
voroshil
parents:
25126
diff
changeset
|
2087 |
6e039dd0b5d8
Revert r25089 (Ignore video formats which are supported by device
voroshil
parents:
25126
diff
changeset
|
2088 if (!pBuf[i]) |
24744 | 2089 break; |
2090 | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2091 hr = OLE_CALL_ARGS(chain->pStreamConfig, GetStreamCaps, i, |
25127
6e039dd0b5d8
Revert r25089 (Ignore video formats which are supported by device
voroshil
parents:
25126
diff
changeset
|
2092 &(arpmt[i]), pBuf[i]); |
24744 | 2093 if (FAILED(hr)) |
2094 break; | |
2095 } | |
2096 if (i == count) { | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2097 chain->arpmt = arpmt; |
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2098 chain->arStreamCaps = pBuf; |
24744 | 2099 done = 1; |
2100 } | |
2101 } | |
2102 } | |
2103 if (!done) { | |
2104 for (i = 0; i < count; i++) { | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
2105 if (pBuf) |
24744 | 2106 free(pBuf[i]); |
2107 if (arpmt && arpmt[i]) | |
2108 DeleteMediaType(arpmt[i]); | |
2109 } | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
2110 free(pBuf); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
2111 free(arpmt); |
24744 | 2112 if (hr != S_OK) { |
2113 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: Call to GetStreamCaps failed (get_available_formats_stream)\n"); | |
2114 return hr; | |
2115 } else | |
2116 return E_OUTOFMEMORY; | |
2117 } | |
2118 return S_OK; | |
2119 } | |
2120 | |
2121 /** | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2122 * \brief returns allocates an array and store available media formats for given pin type to it |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2123 * |
24744 | 2124 * \param pBuilder ICaptureGraphBuilder2 interface of graph builder |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2125 * \param chain chain data structure |
24744 | 2126 * |
2127 * \return S_OK success | |
2128 * \return E_POINTER one of given pointers is null | |
2129 * \return apropriate error code otherwise | |
2130 */ | |
2131 static HRESULT get_available_formats_pin(ICaptureGraphBuilder2 * pBuilder, | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2132 chain_t *chain) |
24744 | 2133 { |
2134 IEnumMediaTypes *pEnum; | |
2135 int i, count, size; | |
2136 ULONG cFetched; | |
2137 AM_MEDIA_TYPE *pmt; | |
2138 HRESULT hr; | |
2139 void **pBuf; | |
2140 AM_MEDIA_TYPE **arpmt; //This will be real array | |
2141 VIDEO_STREAM_CONFIG_CAPS *pVideoCaps; | |
2142 AUDIO_STREAM_CONFIG_CAPS *pAudioCaps; | |
2143 int p1, p2, p3; | |
2144 | |
2145 mp_msg(MSGT_TV, MSGL_DBG4, | |
2146 "tvi_dshow: get_available_formats_pin called\n"); | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2147 if (!pBuilder || !chain->pCaptureFilter) |
24744 | 2148 return E_POINTER; |
2149 | |
25093 | 2150 if (!chain->pCapturePin) |
2151 { | |
2152 hr = OLE_CALL_ARGS(pBuilder, FindPin, | |
2153 (IUnknown *) chain->pCaptureFilter, | |
2154 PINDIR_OUTPUT, &PIN_CATEGORY_CAPTURE, | |
2155 chain->majortype, FALSE, 0, &chain->pCapturePin); | |
2156 | |
2157 if (!chain->pCapturePin) | |
2158 return E_POINTER; | |
2159 } | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2160 if (chain->type == video) { |
24744 | 2161 size = sizeof(VIDEO_STREAM_CONFIG_CAPS); |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2162 } else if (chain->type == audio) { |
24744 | 2163 size = sizeof(AUDIO_STREAM_CONFIG_CAPS); |
2164 } else { | |
2165 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnsupportedMediaType,"get_available_formats_pin"); | |
2166 return E_FAIL; | |
2167 } | |
2168 | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2169 hr = OLE_CALL_ARGS(chain->pCapturePin, EnumMediaTypes, &pEnum); |
24744 | 2170 if (FAILED(hr)) { |
2171 mp_msg(MSGT_TV, MSGL_DBG4, | |
2172 "tvi_dshow: Call to EnumMediaTypes failed (get_available_formats_pin)\n"); | |
2173 return hr; | |
2174 } | |
2175 for (i = 0; OLE_CALL_ARGS(pEnum, Next, 1, &pmt, &cFetched) == S_OK; i++) { | |
2176 if (!pmt) | |
2177 break; | |
2178 } | |
2179 OLE_CALL(pEnum,Reset); | |
2180 | |
2181 count = i; | |
30702 | 2182 arpmt = malloc((count + 1) * sizeof(AM_MEDIA_TYPE *)); |
24744 | 2183 if (!arpmt) |
2184 return E_OUTOFMEMORY; | |
2185 memset(arpmt, 0, (count + 1) * sizeof(AM_MEDIA_TYPE *)); | |
2186 | |
2187 for (i = 0; | |
2188 i < count | |
2189 && OLE_CALL_ARGS(pEnum, Next, 1, &(arpmt[i]), &cFetched) == S_OK; | |
2190 i++); | |
2191 | |
2192 OLE_RELEASE_SAFE(pEnum); | |
2193 | |
2194 | |
30702 | 2195 pBuf = malloc((count + 1) * sizeof(void *)); |
24744 | 2196 if (!pBuf) { |
2197 for (i = 0; i < count; i++) | |
2198 if (arpmt[i]) | |
2199 DeleteMediaType(arpmt[i]); | |
2200 free(arpmt); | |
2201 return E_OUTOFMEMORY; | |
2202 } | |
2203 memset(pBuf, 0, (count + 1) * sizeof(void *)); | |
2204 | |
2205 for (i = 0; i < count; i++) { | |
2206 pBuf[i] = malloc(size); | |
2207 if (!pBuf[i]) | |
2208 break; | |
2209 memset(pBuf[i], 0, size); | |
2210 | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2211 if (chain->type == video) { |
24744 | 2212 pVideoCaps = (VIDEO_STREAM_CONFIG_CAPS *) pBuf[i]; |
2213 extract_video_format(arpmt[i], NULL, &p1, &p2); | |
2214 pVideoCaps->MaxOutputSize.cx = pVideoCaps->MinOutputSize.cx = | |
2215 p1; | |
2216 pVideoCaps->MaxOutputSize.cy = pVideoCaps->MinOutputSize.cy = | |
2217 p2; | |
2218 } else { | |
2219 pAudioCaps = (AUDIO_STREAM_CONFIG_CAPS *) pBuf[i]; | |
2220 extract_audio_format(arpmt[i], &p1, &p2, &p3); | |
2221 pAudioCaps->MaximumSampleFrequency = | |
2222 pAudioCaps->MinimumSampleFrequency = p1; | |
2223 pAudioCaps->MaximumBitsPerSample = | |
2224 pAudioCaps->MinimumBitsPerSample = p2; | |
2225 pAudioCaps->MaximumChannels = pAudioCaps->MinimumChannels = p3; | |
2226 } | |
2227 | |
2228 } | |
2229 if (i != count) { | |
2230 for (i = 0; i < count; i++) { | |
2231 if (arpmt[i]) | |
2232 DeleteMediaType(arpmt[i]); | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32141
diff
changeset
|
2233 free(pBuf[i]); |
24744 | 2234 } |
2235 free(arpmt); | |
2236 free(pBuf); | |
2237 return E_OUTOFMEMORY; | |
2238 } | |
25088
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2239 chain->arpmt = arpmt; |
554bbb45a2f2
Replace several parameters for get_available_formats_stream
voroshil
parents:
25087
diff
changeset
|
2240 chain->arStreamCaps = pBuf; |
24744 | 2241 |
2242 return S_OK; | |
2243 } | |
2244 | |
2245 /* | |
2246 *--------------------------------------------------------------------------------------- | |
2247 * | |
2248 * Public methods | |
2249 * | |
2250 *--------------------------------------------------------------------------------------- | |
2251 */ | |
2252 /** | |
2253 * \brief fills given buffer with audio data (usually one block) | |
2254 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2255 * \param priv driver's private data structure |
24744 | 2256 * \param buffer buffer to store data to |
2257 * \param len buffer's size in bytes (usually one block size) | |
2258 * | |
2259 * \return audio pts if audio present, 1 - otherwise | |
2260 */ | |
2261 static double grab_audio_frame(priv_t * priv, char *buffer, int len) | |
2262 { | |
2263 int bytes = 0; | |
2264 int i; | |
2265 double pts; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2266 grabber_ringbuffer_t *rb = priv->chains[1]->rbuf; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2267 grabber_ringbuffer_t *vrb = priv->chains[0]->rbuf; |
24744 | 2268 |
2269 if (!rb || !rb->ringbuffer) | |
2270 return 1; | |
2271 | |
2272 if(vrb && vrb->tStart<0){ | |
2273 memset(buffer,0,len); | |
2274 return 0; | |
2275 } | |
2276 if(vrb && rb->tStart<0) | |
2277 rb->tStart=vrb->tStart; | |
2278 | |
2279 if (len < rb->blocksize) | |
2280 bytes = len; | |
2281 else | |
2282 bytes = rb->blocksize; | |
2283 | |
2284 mp_msg(MSGT_TV, MSGL_DBG3,"tvi_dshow: FillBuffer (audio) called. %d blocks in buffer, %d bytes requested\n", | |
2285 rb->count, len); | |
2286 if(!rb->count){ | |
2287 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting for frame\n"); | |
2288 for(i=0;i<1000 && !rb->count;i++) usec_sleep(1000); | |
2289 if(!rb->count){ | |
2290 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting timeout\n"); | |
2291 return 0; | |
2292 } | |
2293 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: got frame!\n"); | |
2294 } | |
2295 | |
2296 EnterCriticalSection(rb->pMutex); | |
2297 pts=rb->dpts[rb->head]-rb->tStart; | |
2298 memcpy(buffer, rb->ringbuffer[rb->head], bytes); | |
2299 rb->head = (rb->head + 1) % rb->buffersize; | |
2300 rb->count--; | |
2301 LeaveCriticalSection(rb->pMutex); | |
2302 return pts; | |
2303 } | |
2304 | |
2305 /** | |
2306 * \brief returns audio frame size | |
2307 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2308 * \param priv driver's private data structure |
24744 | 2309 * |
2310 * \return audio block size if audio enabled and 1 - otherwise | |
2311 */ | |
2312 static int get_audio_framesize(priv_t * priv) | |
2313 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2314 if (!priv->chains[1]->rbuf) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2315 return 1; //no audio |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2316 mp_msg(MSGT_TV,MSGL_DBG3,"get_audio_framesize: %d\n",priv->chains[1]->rbuf->blocksize); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2317 return priv->chains[1]->rbuf->blocksize; |
24744 | 2318 } |
2319 | |
2320 static int vbi_get_props(priv_t* priv,tt_stream_props* ptsp) | |
2321 { | |
2322 if(!priv || !ptsp) | |
2323 return TVI_CONTROL_FALSE; | |
2324 | |
2325 //STUBS!!! | |
2326 ptsp->interlaced=0; | |
2327 ptsp->offset=256; | |
2328 | |
2329 ptsp->sampling_rate=27e6; | |
2330 ptsp->samples_per_line=720; | |
2331 | |
2332 ptsp->count[0]=16; | |
2333 ptsp->count[1]=16; | |
2334 //END STUBS!!! | |
2335 ptsp->bufsize = ptsp->samples_per_line * (ptsp->count[0] + ptsp->count[1]); | |
2336 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2337 mp_msg(MSGT_TV,MSGL_V,"vbi_get_props: sampling_rate=%d,offset:%d,samples_per_line: %d\n interlaced:%s, count=[%d,%d]\n", |
24744 | 2338 ptsp->sampling_rate, |
2339 ptsp->offset, | |
2340 ptsp->samples_per_line, | |
2341 ptsp->interlaced?"Yes":"No", | |
2342 ptsp->count[0], | |
2343 ptsp->count[1]); | |
2344 | |
2345 return TVI_CONTROL_TRUE; | |
2346 } | |
2347 | |
2348 static void vbi_grabber(priv_t* priv) | |
2349 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2350 grabber_ringbuffer_t *rb = priv->chains[2]->rbuf; |
24744 | 2351 int i; |
2352 unsigned char* buf; | |
2353 if (!rb || !rb->ringbuffer) | |
2354 return; | |
2355 | |
2356 buf=calloc(1,rb->blocksize); | |
2357 for(i=0; i<23 && rb->count; i++){ | |
2358 memcpy(buf,rb->ringbuffer[rb->head],rb->blocksize); | |
2359 teletext_control(priv->priv_vbi,TV_VBI_CONTROL_DECODE_PAGE,&buf); | |
2360 rb->head = (rb->head + 1) % rb->buffersize; | |
2361 rb->count--; | |
2362 } | |
2363 free(buf); | |
2364 } | |
2365 | |
2366 /** | |
2367 * \brief fills given buffer with video data (usually one frame) | |
2368 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2369 * \param priv driver's private data structure |
24744 | 2370 * \param buffer buffer to store data to |
2371 * \param len buffer's size in bytes (usually one frame size) | |
2372 * | |
2373 * \return frame size if video present, 0 - otherwise | |
2374 */ | |
2375 static double grab_video_frame(priv_t * priv, char *buffer, int len) | |
2376 { | |
2377 int bytes = 0; | |
2378 int i; | |
2379 double pts; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2380 grabber_ringbuffer_t *rb = priv->chains[0]->rbuf; |
24744 | 2381 |
2382 if (!rb || !rb->ringbuffer) | |
2383 return 1; | |
2384 if (len < rb->blocksize) | |
2385 bytes = len; | |
2386 else | |
2387 bytes = rb->blocksize; | |
2388 | |
2389 mp_msg(MSGT_TV, MSGL_DBG3,"tvi_dshow: FillBuffer (video) called. %d blocks in buffer, %d bytes requested\n", | |
2390 rb->count, len); | |
2391 if(!rb->count){ | |
2392 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting for frame\n"); | |
2393 for(i=0;i<1000 && !rb->count;i++) usec_sleep(1000); | |
2394 if(!rb->count){ | |
2395 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting timeout\n"); | |
2396 return 0; | |
2397 } | |
2398 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: got frame!\n"); | |
2399 } | |
2400 EnterCriticalSection(rb->pMutex); | |
2401 if(rb->tStart<0) | |
2402 rb->tStart=rb->dpts[rb->head]; | |
2403 pts=rb->dpts[rb->head]-rb->tStart; | |
2404 memcpy(buffer, rb->ringbuffer[rb->head], bytes); | |
2405 rb->head = (rb->head + 1) % rb->buffersize; | |
2406 rb->count--; | |
2407 LeaveCriticalSection(rb->pMutex); | |
2408 | |
2409 vbi_grabber(priv); | |
2410 return pts; | |
2411 } | |
2412 | |
2413 /** | |
2414 * \brief returns frame size | |
2415 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2416 * \param priv driver's private data structure |
24744 | 2417 * |
2418 * \return frame size if video present, 0 - otherwise | |
2419 */ | |
2420 static int get_video_framesize(priv_t * priv) | |
2421 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2422 // if(!priv->pmtVideo) return 1; //no video |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
2423 // return priv->pmtVideo->lSampleSize; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2424 if (!priv->chains[0]->rbuf) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2425 return 1; //no video |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2426 mp_msg(MSGT_TV,MSGL_DBG3,"geT_video_framesize: %d\n",priv->chains[0]->rbuf->blocksize); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2427 return priv->chains[0]->rbuf->blocksize; |
24744 | 2428 } |
2429 | |
2430 /** | |
2431 * \brief calculate audio buffer size | |
2432 * \param video_buf_size size of video buffer in bytes | |
2433 * \param video_bitrate video bit rate | |
2434 * \param audio_bitrate audio bit rate | |
2435 * \return audio buffer isze in bytes | |
2436 * | |
2437 * \remarks length of video buffer and resulted audio buffer calculated in | |
2438 * seconds will be the same. | |
2439 */ | |
2440 static inline int audio_buf_size_from_video(int video_buf_size, int video_bitrate, int audio_bitrate) | |
2441 { | |
2442 int audio_buf_size = audio_bitrate * (video_buf_size / video_bitrate); | |
2443 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: Audio capture buffer: %d * %d / %d = %d\n", | |
2444 audio_bitrate,video_buf_size,video_bitrate,audio_buf_size); | |
2445 return audio_buf_size; | |
2446 } | |
2447 | |
2448 /** | |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2449 * \brief common chain initialization routine |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2450 * \param chain chain data structure |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2451 * |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2452 * \note pCaptureFilter member should be initialized before call to this routine |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2453 */ |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2454 static HRESULT init_chain_common(ICaptureGraphBuilder2 *pBuilder, chain_t *chain) |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2455 { |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2456 HRESULT hr; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2457 int i; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2458 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2459 if(!chain->pCaptureFilter) |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2460 return E_POINTER; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2461 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2462 show_filter_info(chain->pCaptureFilter); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2463 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2464 hr = OLE_CALL_ARGS(pBuilder, FindPin, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2465 (IUnknown *) chain->pCaptureFilter, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2466 PINDIR_OUTPUT, chain->pin_category, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2467 chain->majortype, FALSE, 0, &chain->pCapturePin); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2468 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2469 if (FAILED(hr)) { |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2470 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: FindPin(pCapturePin) call failed. Error:0x%x\n", (unsigned int)hr); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2471 return hr; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2472 } |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2473 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2474 hr = OLE_CALL_ARGS(pBuilder, FindInterface, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2475 chain->pin_category, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2476 chain->majortype, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2477 chain->pCaptureFilter, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2478 &IID_IAMStreamConfig, |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2479 (void **) &(chain->pStreamConfig)); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2480 if (FAILED(hr)) |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2481 chain->pStreamConfig = NULL; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2482 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2483 /* |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2484 Getting available video formats (last pointer in array will be NULL) |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2485 First tryin to call IAMStreamConfig::GetStreamCaos. this will give us additional information such as |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2486 min/max picture dimensions, etc. If this call fails trying IPIn::EnumMediaTypes with default |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2487 min/max values. |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2488 */ |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2489 hr = get_available_formats_stream(chain); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2490 if (FAILED(hr)) { |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2491 mp_msg(MSGT_TV, MSGL_DBG2, "Unable to use IAMStreamConfig for retriving available formats (Error:0x%x). Using EnumMediaTypes instead\n", (unsigned int)hr); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2492 hr = get_available_formats_pin(pBuilder, chain); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2493 if(FAILED(hr)){ |
25125
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2494 return hr; |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2495 } |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2496 } |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2497 chain->nFormatUsed = 0; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2498 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2499 //If argument to CreateMediaType is NULL then result will be NULL too. |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2500 chain->pmt = CreateMediaType(chain->arpmt[0]); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2501 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2502 for (i = 0; chain->arpmt[i]; i++) |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2503 DisplayMediaType("Available format", chain->arpmt[i]); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2504 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2505 return S_OK; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2506 } |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2507 /** |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2508 * \brief build video stream chain in graph |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2509 * \param priv private data structure |
24744 | 2510 * |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2511 * \return S_OK if chain was built successfully, apropriate error code otherwise |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2512 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2513 static HRESULT build_video_chain(priv_t *priv) |
24744 | 2514 { |
2515 HRESULT hr; | |
2516 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2517 if(priv->chains[0]->rbuf) |
25059 | 2518 return S_OK; |
2519 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2520 if (priv->chains[0]->pStreamConfig) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2521 hr = OLE_CALL_ARGS(priv->chains[0]->pStreamConfig, SetFormat, priv->chains[0]->pmt); |
24744 | 2522 if (FAILED(hr)) { |
2523 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableSelectVideoFormat, (unsigned int)hr); | |
2524 } | |
2525 } | |
2526 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2527 priv->chains[0]->rbuf=calloc(1,sizeof(grabber_ringbuffer_t)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2528 if(!priv->chains[0]->rbuf) |
25058 | 2529 return E_OUTOFMEMORY; |
24744 | 2530 |
2531 if (priv->tv_param->buffer_size >= 0) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2532 priv->chains[0]->rbuf->buffersize = priv->tv_param->buffer_size; |
24744 | 2533 } else { |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2534 priv->chains[0]->rbuf->buffersize = 16; |
24744 | 2535 } |
2536 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2537 priv->chains[0]->rbuf->buffersize *= 1024 * 1024; |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
2538 hr=build_sub_graph(priv, priv->chains[0], &PIN_CATEGORY_CAPTURE); |
24744 | 2539 if(FAILED(hr)){ |
2540 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVideoSubGraph,(unsigned int)hr); | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2541 return hr; |
24744 | 2542 } |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2543 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2544 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2545 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2546 /** |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2547 * \brief build audio stream chain in graph |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2548 * \param priv private data structure |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2549 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2550 * \return S_OK if chain was built successfully, apropriate error code otherwise |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2551 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2552 static HRESULT build_audio_chain(priv_t *priv) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2553 { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2554 HRESULT hr; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2555 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2556 if(priv->chains[1]->rbuf) |
25059 | 2557 return S_OK; |
2558 | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2559 if(priv->immediate_mode) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2560 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2561 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2562 if (priv->chains[1]->pStreamConfig) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2563 hr = OLE_CALL_ARGS(priv->chains[1]->pStreamConfig, SetFormat, |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2564 priv->chains[1]->pmt); |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2565 if (FAILED(hr)) { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2566 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableSelectAudioFormat, (unsigned int)hr); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2567 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2568 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2569 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2570 if(priv->chains[1]->pmt){ |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2571 priv->chains[1]->rbuf=calloc(1,sizeof(grabber_ringbuffer_t)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2572 if(!priv->chains[1]->rbuf) |
25058 | 2573 return E_OUTOFMEMORY; |
24744 | 2574 |
2575 /* let the audio buffer be the same size (in seconds) than video one */ | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2576 priv->chains[1]->rbuf->buffersize=audio_buf_size_from_video( |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2577 priv->chains[0]->rbuf->buffersize, |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2578 (((VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat)->dwBitRate), |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2579 (((WAVEFORMATEX *) (priv->chains[1]->pmt->pbFormat))->nAvgBytesPerSec)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2580 |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
2581 hr=build_sub_graph(priv, priv->chains[1],&PIN_CATEGORY_CAPTURE); |
24744 | 2582 if(FAILED(hr)){ |
2583 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildAudioSubGraph,(unsigned int)hr); | |
2584 return 0; | |
2585 } | |
2586 } | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2587 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2588 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2589 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2590 /** |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2591 * \brief build VBI stream chain in graph |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2592 * \param priv private data structure |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2593 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2594 * \return S_OK if chain was built successfully, apropriate error code otherwise |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2595 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2596 static HRESULT build_vbi_chain(priv_t *priv) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2597 { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2598 HRESULT hr; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2599 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2600 if(priv->chains[2]->rbuf) |
25059 | 2601 return S_OK; |
2602 | |
29806 | 2603 if(priv->tv_param->teletext.device) |
24744 | 2604 { |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2605 priv->chains[2]->rbuf=calloc(1,sizeof(grabber_ringbuffer_t)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2606 if(!priv->chains[2]->rbuf) |
25058 | 2607 return E_OUTOFMEMORY; |
2608 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2609 init_ringbuffer(priv->chains[2]->rbuf,24,priv->tsp.bufsize); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2610 |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
2611 hr=build_sub_graph(priv, priv->chains[2],&PIN_CATEGORY_VBI); |
24744 | 2612 if(FAILED(hr)){ |
2613 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVBISubGraph,(unsigned int)hr); | |
2614 return 0; | |
2615 } | |
2616 } | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2617 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2618 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2619 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2620 /** |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2621 * \brief playback/capture real start |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2622 * |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2623 * \param priv driver's private data structure |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2624 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2625 * \return 1 if success, 0 - otherwise |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2626 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2627 * TODO: move some code from init() here |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2628 */ |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2629 static int start(priv_t * priv) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2630 { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2631 HRESULT hr; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2632 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2633 hr = build_video_chain(priv); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2634 if(FAILED(hr)) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2635 return 0; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2636 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2637 hr = build_audio_chain(priv); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2638 if(FAILED(hr)) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2639 return 0; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2640 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2641 hr = build_vbi_chain(priv); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2642 if(FAILED(hr)) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2643 return 0; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2644 |
24744 | 2645 /* |
2646 Graph is ready to capture. Starting graph. | |
2647 */ | |
2648 if (mp_msg_test(MSGT_TV, MSGL_DBG2)) { | |
2649 mp_msg(MSGT_TV, MSGL_DBG2, "Debug pause 10sec\n"); | |
2650 usec_sleep(10000000); | |
2651 mp_msg(MSGT_TV, MSGL_DBG2, "Debug pause end\n"); | |
2652 } | |
2653 if (!priv->pMediaControl) { | |
2654 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableGetMediaControlInterface,(unsigned int)E_POINTER); | |
2655 return 0; | |
2656 } | |
2657 hr = OLE_CALL(priv->pMediaControl, Run); | |
2658 if (FAILED(hr)) { | |
2659 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableStartGraph, (unsigned int)hr); | |
2660 return 0; | |
2661 } | |
2662 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Graph is started.\n"); | |
2663 priv->state = 1; | |
2664 | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
2665 return 1; |
24744 | 2666 } |
2667 | |
2668 /** | |
2669 * \brief driver initialization | |
2670 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2671 * \param priv driver's private data structure |
24744 | 2672 * |
2673 * \return 1 if success, 0 - otherwise | |
2674 */ | |
2675 static int init(priv_t * priv) | |
2676 { | |
2677 HRESULT hr; | |
2678 int result = 0; | |
2679 long lInput, lTunerInput; | |
2680 IEnumFilters *pEnum; | |
2681 IBaseFilter *pFilter; | |
2682 IPin *pVPOutPin; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2683 int i; |
24744 | 2684 |
2685 priv->state=0; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2686 |
24744 | 2687 CoInitialize(NULL); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2688 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2689 for(i=0; i<3;i++) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2690 priv->chains[i] = calloc(1, sizeof(chain_t)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2691 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2692 priv->chains[0]->type=video; |
25080 | 2693 priv->chains[0]->majortype=&MEDIATYPE_Video; |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2694 priv->chains[0]->pin_category=&PIN_CATEGORY_CAPTURE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2695 priv->chains[1]->type=audio; |
25080 | 2696 priv->chains[1]->majortype=&MEDIATYPE_Audio; |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2697 priv->chains[1]->pin_category=&PIN_CATEGORY_CAPTURE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2698 priv->chains[2]->type=vbi; |
25080 | 2699 priv->chains[2]->majortype=&MEDIATYPE_VBI; |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2700 priv->chains[2]->pin_category=&PIN_CATEGORY_VBI; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2701 |
24744 | 2702 do{ |
2703 hr = CoCreateInstance((GUID *) & CLSID_FilterGraph, NULL, | |
2704 CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, | |
2705 (void **) &priv->pGraph); | |
2706 if(FAILED(hr)){ | |
2707 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CoCreateInstance(FilterGraph) call failed. Error:0x%x\n", (unsigned int)hr); | |
2708 break; | |
2709 } | |
2710 //Debug | |
2711 if (mp_msg_test(MSGT_TV, MSGL_DBG2)) { | |
2712 AddToRot((IUnknown *) priv->pGraph, &(priv->dwRegister)); | |
2713 } | |
2714 | |
2715 hr = CoCreateInstance((GUID *) & CLSID_CaptureGraphBuilder2, NULL, | |
2716 CLSCTX_INPROC_SERVER, &IID_ICaptureGraphBuilder2, | |
2717 (void **) &priv->pBuilder); | |
2718 if(FAILED(hr)){ | |
2719 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CoCreateInstance(CaptureGraphBuilder) call failed. Error:0x%x\n", (unsigned int)hr); | |
2720 break; | |
2721 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2722 |
24744 | 2723 hr = OLE_CALL_ARGS(priv->pBuilder, SetFiltergraph, priv->pGraph); |
2724 if(FAILED(hr)){ | |
2725 mp_msg(MSGT_TV,MSGL_ERR, "tvi_dshow: SetFiltergraph call failed. Error:0x%x\n",(unsigned int)hr); | |
2726 break; | |
2727 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
2728 |
24744 | 2729 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Searching for available video capture devices\n"); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2730 priv->chains[0]->pCaptureFilter = find_capture_device(priv->dev_index, &CLSID_VideoInputDeviceCategory); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2731 if(!priv->chains[0]->pCaptureFilter){ |
24744 | 2732 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_NoVideoCaptureDevice); |
2733 break; | |
2734 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2735 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, priv->chains[0]->pCaptureFilter, NULL); |
24744 | 2736 if(FAILED(hr)){ |
2737 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to add video capture device to Directshow graph. Error:0x%x\n", (unsigned int)hr); | |
2738 break; | |
2739 } | |
2740 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Searching for available audio capture devices\n"); | |
2741 if (priv->adev_index != -1) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2742 priv->chains[1]->pCaptureFilter = find_capture_device(priv->adev_index, &CLSID_AudioInputDeviceCategory); //output available audio edevices |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2743 if(!priv->chains[1]->pCaptureFilter){ |
24744 | 2744 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_NoAudioCaptureDevice); |
2745 break; | |
2746 } | |
2747 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2748 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, priv->chains[1]->pCaptureFilter, NULL); |
24744 | 2749 if(FAILED(hr)){ |
2750 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Unable to add audio capture device to Directshow graph. Error:0x%x\n", (unsigned int)hr); | |
2751 break; | |
2752 } | |
2753 } else | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2754 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter, IID_IBaseFilter, priv->chains[1]->pCaptureFilter); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2755 |
25082
b63b4b599cbe
Add capture filter's pointer to vbi chain structure too.
voroshil
parents:
25081
diff
changeset
|
2756 /* increase refrence counter for capture filter ad store pointer into vbi chain structure too */ |
b63b4b599cbe
Add capture filter's pointer to vbi chain structure too.
voroshil
parents:
25081
diff
changeset
|
2757 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter, IID_IBaseFilter, priv->chains[2]->pCaptureFilter); |
b63b4b599cbe
Add capture filter's pointer to vbi chain structure too.
voroshil
parents:
25081
diff
changeset
|
2758 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2759 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter, IID_IAMVideoProcAmp,priv->pVideoProcAmp); |
24744 | 2760 if (FAILED(hr) && hr != E_NOINTERFACE) |
2761 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get IID_IAMVideoProcAmp failed (0x%x).\n", (unsigned int)hr); | |
2762 | |
2763 if (hr != S_OK) { | |
2764 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_VideoAdjustigNotSupported); | |
2765 priv->pVideoProcAmp = NULL; | |
2766 } | |
2767 | |
2768 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, | |
2769 &PIN_CATEGORY_CAPTURE, | |
25080 | 2770 priv->chains[0]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2771 priv->chains[0]->pCaptureFilter, |
24744 | 2772 &IID_IAMCrossbar, (void **) &(priv->pCrossbar)); |
2773 if (FAILED(hr)) { | |
2774 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_SelectingInputNotSupported); | |
2775 priv->pCrossbar = NULL; | |
2776 } | |
2777 | |
2778 if (priv->tv_param->amode >= 0) { | |
2779 IAMTVAudio *pTVAudio; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2780 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, NULL, NULL,priv->chains[0]->pCaptureFilter,&IID_IAMTVAudio, (void *) &pTVAudio); |
24744 | 2781 if (hr == S_OK) { |
2782 switch (priv->tv_param->amode) { | |
2783 case 0: | |
2784 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, AMTVAUDIO_MODE_MONO); | |
2785 break; | |
2786 case 1: | |
2787 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, AMTVAUDIO_MODE_STEREO); | |
2788 break; | |
2789 case 2: | |
2790 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, | |
2791 AMTVAUDIO_MODE_LANG_A); | |
2792 break; | |
2793 case 3: | |
2794 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, | |
2795 AMTVAUDIO_MODE_LANG_B); | |
2796 break; | |
2797 } | |
2798 OLE_RELEASE_SAFE(pTVAudio); | |
2799 if (FAILED(hr)) | |
2800 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_UnableSetAudioMode, priv->tv_param->amode,(unsigned int)hr); | |
2801 } | |
2802 } | |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2803 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2804 // Video chain initialization |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2805 hr = init_chain_common(priv->pBuilder, priv->chains[0]); |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2806 if(FAILED(hr)) |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2807 break; |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2808 |
25125
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2809 /* |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2810 Audio chain initialization |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2811 Since absent audio stream is not fatal, |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2812 at least one NULL pointer should be kept in format arrays |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2813 (to avoid another additional check everywhere for array presence). |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2814 */ |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2815 hr = init_chain_common(priv->pBuilder, priv->chains[1]); |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2816 if(FAILED(hr)) |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2817 { |
33622
27f7a3196e18
tvi_dshow: Adjust mp_msg printf conversion specifier to avoid warnings.
diego
parents:
33618
diff
changeset
|
2818 mp_msg(MSGT_TV, MSGL_V, |
27f7a3196e18
tvi_dshow: Adjust mp_msg printf conversion specifier to avoid warnings.
diego
parents:
33618
diff
changeset
|
2819 "tvi_dshow: Unable to initialize audio chain (Error:0x%lx). Audio disabled\n", |
27f7a3196e18
tvi_dshow: Adjust mp_msg printf conversion specifier to avoid warnings.
diego
parents:
33618
diff
changeset
|
2820 (unsigned long)hr); |
25125
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2821 priv->chains[1]->arpmt=calloc(1, sizeof(AM_MEDIA_TYPE*)); |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2822 priv->chains[1]->arStreamCaps=calloc(1, sizeof(void*)); |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2823 } |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2824 |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2825 /* |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2826 VBI chain initialization |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2827 Since absent VBI stream is not fatal, |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2828 at least one NULL pointer should be kept in format arrays |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2829 (to avoid another additional check everywhere for array presence). |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2830 */ |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2831 hr = init_chain_common(priv->pBuilder, priv->chains[2]); |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2832 if(FAILED(hr)) |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2833 { |
33622
27f7a3196e18
tvi_dshow: Adjust mp_msg printf conversion specifier to avoid warnings.
diego
parents:
33618
diff
changeset
|
2834 mp_msg(MSGT_TV, MSGL_V, |
27f7a3196e18
tvi_dshow: Adjust mp_msg printf conversion specifier to avoid warnings.
diego
parents:
33618
diff
changeset
|
2835 "tvi_dshow: Unable to initialize VBI chain (Error:0x%lx). Teletext disabled\n", |
27f7a3196e18
tvi_dshow: Adjust mp_msg printf conversion specifier to avoid warnings.
diego
parents:
33618
diff
changeset
|
2836 (unsigned long)hr); |
25125
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2837 priv->chains[2]->arpmt=calloc(1, sizeof(AM_MEDIA_TYPE*)); |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2838 priv->chains[2]->arStreamCaps=calloc(1, sizeof(void*)); |
a1e6345207a1
§³reate empty format arrays in case of error in init_chain_common.
voroshil
parents:
25105
diff
changeset
|
2839 } |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2840 |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2841 if (!priv->chains[0]->pStreamConfig) |
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2842 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_ChangingWidthHeightNotSupported); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2843 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2844 if (!priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed] |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2845 || !extract_video_format(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed], |
24744 | 2846 &(priv->fcc), &(priv->width), |
2847 &(priv->height))) { | |
2848 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_ErrorParsingVideoFormatStruct); | |
2849 break; | |
2850 } | |
25094
e27cb70d2302
Move code related to chain initialization and similar
voroshil
parents:
25093
diff
changeset
|
2851 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2852 if (priv->chains[1]->arpmt[priv->chains[1]->nFormatUsed]) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2853 if (!extract_audio_format(priv->chains[1]->pmt, &(priv->samplerate), NULL, NULL)) { |
24744 | 2854 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_ErrorParsingAudioFormatStruct); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2855 DisplayMediaType("audio format failed",priv->chains[1]->arpmt[priv->chains[1]->nFormatUsed]); |
24744 | 2856 break; |
2857 } | |
2858 } | |
2859 | |
2860 hr = OLE_QUERYINTERFACE(priv->pGraph, IID_IMediaControl,priv->pMediaControl); | |
2861 if(FAILED(hr)){ | |
2862 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableGetMediaControlInterface,(unsigned int)hr); | |
2863 break; | |
2864 } | |
2865 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, | |
2866 &PIN_CATEGORY_CAPTURE, NULL, | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2867 priv->chains[0]->pCaptureFilter, |
24744 | 2868 &IID_IAMTVTuner, (void **) &(priv->pTVTuner)); |
2869 | |
2870 if (!priv->pTVTuner) { | |
2871 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to access IAMTVTuner (0x%x)\n", (unsigned int)hr); | |
2872 } | |
2873 | |
2874 // shows Tuner capabilities | |
2875 get_capabilities(priv); | |
2876 | |
2877 if (priv->pTVTuner) { | |
2878 hr = OLE_CALL_ARGS(priv->pTVTuner, put_CountryCode, | |
2879 chanlist2country(priv->tv_param->chanlist)); | |
2880 if(FAILED(hr)){ | |
2881 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to put_CountryCode failed. Error:0x%x\n",(unsigned int)hr); | |
2882 } | |
2883 | |
2884 hr = OLE_CALL_ARGS(priv->pTVTuner, put_Mode, AMTUNER_MODE_TV); | |
2885 if(FAILED(hr)){ | |
2886 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to put_Mode failed. Error:0x%x\n",(unsigned int)hr); | |
2887 break; | |
2888 } | |
2889 | |
2890 hr = OLE_CALL_ARGS(priv->pTVTuner, get_ConnectInput, &lInput); | |
2891 if(FAILED(hr)){ | |
2892 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to get_ConnectInput failed. Error:0x%x\n",(unsigned int)hr); | |
2893 break; | |
2894 } | |
2895 | |
2896 /* small hack */ | |
2897 lTunerInput = strstr(priv->tv_param->chanlist, "cable") ? TunerInputCable : TunerInputAntenna; | |
2898 | |
2899 hr = OLE_CALL_ARGS(priv->pTVTuner, put_InputType, lInput, lTunerInput); | |
2900 if(FAILED(hr)){ | |
2901 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to put_InputType failed. Error:0x%x\n",(unsigned int)hr); | |
2902 break; | |
2903 } | |
2904 | |
2905 } | |
2906 | |
2907 /** | |
2908 for VIVO cards we should check if preview pin is available on video capture device. | |
2909 If it is not, we have to connect Video Port Manager filter to VP pin of capture device filter. | |
2910 Otherwise we will get 0x8007001f (Device is not functioning properly) when attempting to start graph | |
2911 */ | |
2912 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2913 (IUnknown *) priv->chains[0]->pCaptureFilter, |
24744 | 2914 PINDIR_OUTPUT, |
2915 &PIN_CATEGORY_VIDEOPORT, NULL, FALSE, | |
2916 0, (IPin **) & pVPOutPin); | |
2917 if (SUCCEEDED(hr)) { | |
2918 hr = OLE_CALL_ARGS(priv->pGraph, Render, pVPOutPin); | |
2919 OLE_RELEASE_SAFE(pVPOutPin); | |
2920 | |
2921 if (FAILED(hr)) { | |
2922 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableTerminateVPPin, (unsigned int)hr); | |
2923 break; | |
2924 } | |
2925 } | |
2926 | |
2927 OLE_CALL_ARGS(priv->pGraph, EnumFilters, &pEnum); | |
2928 while (OLE_CALL_ARGS(pEnum, Next, 1, &pFilter, NULL) == S_OK) { | |
2929 LPVIDEOWINDOW pVideoWindow; | |
2930 hr = OLE_QUERYINTERFACE(pFilter, IID_IVideoWindow, pVideoWindow); | |
2931 if (SUCCEEDED(hr)) | |
2932 { | |
2933 if(priv->tv_param->hidden_vp_renderer){ | |
2934 OLE_CALL_ARGS(pVideoWindow,put_Visible,/* OAFALSE*/ 0); | |
2935 OLE_CALL_ARGS(pVideoWindow,put_AutoShow,/* OAFALSE*/ 0); | |
2936 }else | |
2937 { | |
2938 OLE_CALL_ARGS(priv->pGraph, RemoveFilter, pFilter); | |
2939 } | |
2940 OLE_RELEASE_SAFE(pVideoWindow); | |
2941 } | |
2942 OLE_RELEASE_SAFE(pFilter); | |
2943 } | |
2944 OLE_RELEASE_SAFE(pEnum); | |
2945 if(priv->tv_param->system_clock) | |
2946 { | |
2947 LPREFERENCECLOCK rc; | |
2948 IBaseFilter* pBF; | |
2949 hr = CoCreateInstance((GUID *) & CLSID_SystemClock, NULL, | |
2950 CLSCTX_INPROC_SERVER, &IID_IReferenceClock, | |
2951 (void *) &rc); | |
2952 | |
2953 OLE_QUERYINTERFACE(priv->pBuilder,IID_IBaseFilter,pBF); | |
2954 OLE_CALL_ARGS(pBF,SetSyncSource,rc); | |
2955 } | |
2956 if(vbi_get_props(priv,&(priv->tsp))!=TVI_CONTROL_TRUE) | |
2957 break; | |
2958 result = 1; | |
2959 } while(0); | |
2960 | |
2961 if (!result){ | |
2962 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_GraphInitFailure); | |
2963 uninit(priv); | |
2964 } | |
2965 return result; | |
2966 } | |
2967 | |
2968 /** | |
25085
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2969 * \brief chain uninitialization |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2970 * \param chain chain data structure |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2971 */ |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2972 static void destroy_chain(chain_t *chain) |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2973 { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2974 int i; |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2975 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2976 if(!chain) |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2977 return; |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2978 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2979 OLE_RELEASE_SAFE(chain->pStreamConfig); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2980 OLE_RELEASE_SAFE(chain->pCaptureFilter); |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
2981 OLE_RELEASE_SAFE(chain->pCSGCB); |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2982 OLE_RELEASE_SAFE(chain->pCapturePin); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2983 OLE_RELEASE_SAFE(chain->pSGIn); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2984 OLE_RELEASE_SAFE(chain->pSG); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2985 OLE_RELEASE_SAFE(chain->pSGF); |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
2986 |
25085
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2987 if (chain->pmt) |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2988 DeleteMediaType(chain->pmt); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2989 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2990 if (chain->arpmt) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2991 for (i = 0; chain->arpmt[i]; i++) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2992 DeleteMediaType(chain->arpmt[i]); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2993 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2994 free(chain->arpmt); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2995 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2996 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2997 if (chain->arStreamCaps) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2998 for (i = 0; chain->arStreamCaps[i]; i++) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2999 free(chain->arStreamCaps[i]); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3000 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3001 free(chain->arStreamCaps); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3002 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3003 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3004 if (chain->rbuf) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3005 destroy_ringbuffer(chain->rbuf); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3006 free(chain->rbuf); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3007 chain->rbuf = NULL; |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3008 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3009 free(chain); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3010 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3011 /** |
24744 | 3012 * \brief driver uninitialization |
3013 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
3014 * \param priv driver's private data structure |
24744 | 3015 * |
3016 * \return always 1 | |
3017 */ | |
3018 static int uninit(priv_t * priv) | |
3019 { | |
3020 int i; | |
3021 if (!priv) | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3022 return 1; |
24744 | 3023 //Debug |
3024 if (priv->dwRegister) { | |
3025 RemoveFromRot(priv->dwRegister); | |
3026 } | |
3027 teletext_control(priv->priv_vbi,TV_VBI_CONTROL_STOP,(void*)1); | |
3028 //stop audio grabber thread | |
3029 | |
3030 if (priv->state && priv->pMediaControl) { | |
3031 OLE_CALL(priv->pMediaControl, Stop); | |
3032 } | |
3033 OLE_RELEASE_SAFE(priv->pMediaControl); | |
3034 priv->state = 0; | |
3035 | |
3036 if (priv->pGraph) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3037 if (priv->chains[0]->pCaptureFilter) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3038 OLE_CALL_ARGS(priv->pGraph, RemoveFilter, priv->chains[0]->pCaptureFilter); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3039 if (priv->chains[1]->pCaptureFilter) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3040 OLE_CALL_ARGS(priv->pGraph, RemoveFilter, priv->chains[1]->pCaptureFilter); |
24744 | 3041 } |
3042 OLE_RELEASE_SAFE(priv->pCrossbar); | |
3043 OLE_RELEASE_SAFE(priv->pVideoProcAmp); | |
3044 OLE_RELEASE_SAFE(priv->pGraph); | |
3045 OLE_RELEASE_SAFE(priv->pBuilder); | |
3046 if(priv->freq_table){ | |
3047 priv->freq_table_len=-1; | |
3048 free(priv->freq_table); | |
3049 priv->freq_table=NULL; | |
3050 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3051 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3052 for(i=0; i<3;i++) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3053 { |
25085
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3054 destroy_chain(priv->chains[i]); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3055 priv->chains[i] = NULL; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3056 } |
24744 | 3057 CoUninitialize(); |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3058 return 1; |
24744 | 3059 } |
3060 | |
3061 /** | |
3062 * \brief driver pre-initialization | |
3063 * | |
3064 * \param device string, containing device name in form "x[.y]", where x is video capture device | |
3065 * (default: 0, first available); y (if given) sets audio capture device | |
3066 * | |
3067 * \return 1 if success,0 - otherwise | |
3068 */ | |
3069 static tvi_handle_t *tvi_init_dshow(tv_param_t* tv_param) | |
3070 { | |
3071 tvi_handle_t *h; | |
3072 priv_t *priv; | |
3073 int a; | |
3074 | |
32141
2802b8095bf7
Move TV input new_handle static function to tv.c and make it non-static.
diego
parents:
32090
diff
changeset
|
3075 h = tv_new_handle(sizeof(priv_t), &functions); |
24744 | 3076 if (!h) |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3077 return NULL; |
24744 | 3078 |
3079 priv = h->priv; | |
3080 | |
3081 memset(priv, 0, sizeof(priv_t)); | |
3082 priv->direct_setfreq_call = 1; //first using direct call. if it fails, workaround will be enabled | |
3083 priv->direct_getfreq_call = 1; //first using direct call. if it fails, workaround will be enabled | |
3084 priv->adev_index = -1; | |
3085 priv->freq_table_len=-1; | |
3086 priv->tv_param=tv_param; | |
3087 | |
3088 if (tv_param->device) { | |
3089 if (sscanf(tv_param->device, "%d", &a) == 1) { | |
3090 priv->dev_index = a; | |
3091 } else { | |
3092 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongDeviceParam, tv_param->device); | |
32090
535ebcd085e4
Move TV input free_handle static function to tv.c and make it non-static.
diego
parents:
31322
diff
changeset
|
3093 tv_free_handle(h); |
24744 | 3094 return NULL; |
3095 } | |
3096 if (priv->dev_index < 0) { | |
3097 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongDeviceIndex, a); | |
32090
535ebcd085e4
Move TV input free_handle static function to tv.c and make it non-static.
diego
parents:
31322
diff
changeset
|
3098 tv_free_handle(h); |
24744 | 3099 return NULL; |
3100 } | |
3101 } | |
3102 if (tv_param->adevice) { | |
3103 if (sscanf(tv_param->adevice, "%d", &a) == 1) { | |
3104 priv->adev_index = a; | |
3105 } else { | |
3106 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongADeviceParam, tv_param->adevice); | |
32090
535ebcd085e4
Move TV input free_handle static function to tv.c and make it non-static.
diego
parents:
31322
diff
changeset
|
3107 tv_free_handle(h); |
24744 | 3108 return NULL; |
3109 } | |
3110 if (priv->dev_index < 0) { | |
3111 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongADeviceIndex, a); | |
32090
535ebcd085e4
Move TV input free_handle static function to tv.c and make it non-static.
diego
parents:
31322
diff
changeset
|
3112 tv_free_handle(h); |
24744 | 3113 return NULL; |
3114 } | |
3115 } | |
3116 return h; | |
3117 } | |
3118 | |
3119 /** | |
3120 * \brief driver's ioctl handler | |
3121 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
3122 * \param priv driver's private data structure |
24744 | 3123 * \param cmd ioctl command |
3124 * \param arg ioct command's parameter | |
3125 * | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
3126 * \return TVI_CONTROL_TRUE if success |
24744 | 3127 * \return TVI_CONTROL_FALSE if failure |
3128 * \return TVI_CONTROL_UNKNOWN if unknowm cmd called | |
3129 */ | |
3130 static int control(priv_t * priv, int cmd, void *arg) | |
3131 { | |
3132 switch (cmd) { | |
3133 /* need rewrite */ | |
3134 case TVI_CONTROL_VID_SET_FORMAT: | |
3135 { | |
25126
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3136 int fcc, i,j; |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3137 void* tmp,*tmp2; |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3138 int result = TVI_CONTROL_TRUE; |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
3139 |
24744 | 3140 if (priv->state) |
3141 return TVI_CONTROL_FALSE; | |
3142 fcc = *(int *) arg; | |
3143 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3144 if(!priv->chains[0]->arpmt) |
24744 | 3145 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3146 for (i = 0; priv->chains[0]->arpmt[i]; i++) |
24744 | 3147 if (check_video_format |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3148 (priv->chains[0]->arpmt[i], fcc, priv->width, priv->height)) |
24744 | 3149 break; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3150 if (!priv->chains[0]->arpmt[i]) |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3151 { |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3152 int fps = 0; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3153 VIDEOINFOHEADER* Vhdr = NULL; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3154 AM_MEDIA_TYPE *pmt; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3155 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3156 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: will try also use undeclared video format: %dx%d, %s\n",priv->width, priv->height, vo_format_name(fcc)); |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3157 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3158 if (priv->chains[0]->arpmt[0]) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3159 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->arpmt[0]->pbFormat; |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3160 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3161 if(Vhdr && Vhdr->bmiHeader.biSizeImage) |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3162 fps = Vhdr->dwBitRate / (8 * Vhdr->bmiHeader.biSizeImage); |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3163 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3164 pmt=create_video_format(fcc, priv->width, priv->height, fps); |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3165 if(!pmt) |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3166 { |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3167 mp_msg(MSGT_TV, MSGL_V, "tvi_dshow: Unable to create AM_MEDIA_TYPE structure for given format\n"); |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3168 return TVI_CONTROL_FALSE; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3169 } |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3170 priv->chains[0]->arpmt=realloc(priv->chains[0]->arpmt, (i+2)*sizeof(AM_MEDIA_TYPE*)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3171 priv->chains[0]->arpmt[i+1] = NULL; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3172 priv->chains[0]->arpmt[i] = pmt; |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3173 |
25105 | 3174 priv->chains[0]->arStreamCaps=realloc(priv->chains[0]->arStreamCaps, (i+2)*sizeof(void*)); |
25096 | 3175 priv->chains[0]->arpmt[i+1] = NULL; |
3176 | |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3177 result = TVI_CONTROL_FALSE; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3178 } |
24744 | 3179 |
25126
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3180 |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3181 tmp=priv->chains[0]->arpmt[i]; |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3182 tmp2=priv->chains[0]->arStreamCaps[i]; |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3183 for(j=i; j>0; j--) |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3184 { |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3185 priv->chains[0]->arpmt[j] = priv->chains[0]->arpmt[j-1]; |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3186 priv->chains[0]->arStreamCaps[j] = priv->chains[0]->arStreamCaps[j-1]; |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3187 } |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3188 priv->chains[0]->arpmt[0] = tmp; |
8152446e42b1
Move requested format at top and shift all oters down
voroshil
parents:
25125
diff
changeset
|
3189 priv->chains[0]->arStreamCaps[0] = tmp2; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3190 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3191 priv->chains[0]->nFormatUsed = 0; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3192 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3193 if (priv->chains[0]->pmt) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3194 DeleteMediaType(priv->chains[0]->pmt); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3195 priv->chains[0]->pmt = |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3196 CreateMediaType(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed]); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3197 DisplayMediaType("VID_SET_FORMAT", priv->chains[0]->pmt); |
24744 | 3198 /* |
3199 Setting width & height to preferred by driver values | |
3200 */ | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3201 extract_video_format(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed], |
24744 | 3202 &(priv->fcc), &(priv->width), |
3203 &(priv->height)); | |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3204 return result; |
24744 | 3205 } |
3206 case TVI_CONTROL_VID_GET_FORMAT: | |
3207 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3208 if(!priv->chains[0]->pmt) |
24744 | 3209 return TVI_CONTROL_FALSE; |
25067
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3210 /* |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3211 Build video chain (for video format negotiation). |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3212 If this was done before, routine will do nothing. |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3213 */ |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3214 build_video_chain(priv); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3215 DisplayMediaType("VID_GET_FORMAT", priv->chains[0]->pmt); |
24744 | 3216 if (priv->fcc) { |
3217 *(int *) arg = priv->fcc; | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3218 return TVI_CONTROL_TRUE; |
24744 | 3219 } else |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3220 return TVI_CONTROL_FALSE; |
24744 | 3221 } |
3222 case TVI_CONTROL_VID_SET_WIDTH: | |
3223 { | |
3224 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3225 VIDEOINFOHEADER *Vhdr; | |
3226 int width = *(int *) arg; | |
3227 if (priv->state) | |
3228 return TVI_CONTROL_FALSE; | |
3229 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3230 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3231 if (!pCaps) |
3232 return TVI_CONTROL_FALSE; | |
3233 if (width < pCaps->MinOutputSize.cx | |
3234 || width > pCaps->MaxOutputSize.cx) | |
3235 return TVI_CONTROL_FALSE; | |
3236 | |
3237 if (width % pCaps->OutputGranularityX) | |
3238 return TVI_CONTROL_FALSE; | |
3239 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3240 if (!priv->chains[0]->pmt || !priv->chains[0]->pmt->pbFormat) |
24744 | 3241 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3242 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat; |
24744 | 3243 Vhdr->bmiHeader.biWidth = width; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3244 priv->chains[0]->pmt->lSampleSize = Vhdr->bmiHeader.biSizeImage = |
24744 | 3245 labs(Vhdr->bmiHeader.biBitCount * Vhdr->bmiHeader.biWidth * |
3246 Vhdr->bmiHeader.biHeight) >> 3; | |
3247 | |
3248 priv->width = width; | |
3249 | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3250 return TVI_CONTROL_TRUE; |
24744 | 3251 } |
3252 case TVI_CONTROL_VID_GET_WIDTH: | |
3253 { | |
3254 if (priv->width) { | |
3255 *(int *) arg = priv->width; | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3256 return TVI_CONTROL_TRUE; |
24744 | 3257 } else |
3258 return TVI_CONTROL_FALSE; | |
3259 } | |
3260 case TVI_CONTROL_VID_CHK_WIDTH: | |
3261 { | |
3262 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3263 int width = *(int *) arg; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3264 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3265 if (!pCaps) |
3266 return TVI_CONTROL_FALSE; | |
3267 if (width < pCaps->MinOutputSize.cx | |
3268 || width > pCaps->MaxOutputSize.cx) | |
3269 return TVI_CONTROL_FALSE; | |
3270 | |
3271 if (width % pCaps->OutputGranularityX) | |
3272 return TVI_CONTROL_FALSE; | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3273 return TVI_CONTROL_TRUE; |
24744 | 3274 } |
3275 case TVI_CONTROL_VID_SET_HEIGHT: | |
3276 { | |
3277 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3278 VIDEOINFOHEADER *Vhdr; | |
3279 int height = *(int *) arg; | |
3280 if (priv->state) | |
3281 return TVI_CONTROL_FALSE; | |
3282 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3283 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3284 if (!pCaps) |
3285 return TVI_CONTROL_FALSE; | |
3286 if (height < pCaps->MinOutputSize.cy | |
3287 || height > pCaps->MaxOutputSize.cy) | |
3288 return TVI_CONTROL_FALSE; | |
3289 | |
3290 if (height % pCaps->OutputGranularityY) | |
3291 return TVI_CONTROL_FALSE; | |
3292 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3293 if (!priv->chains[0]->pmt || !priv->chains[0]->pmt->pbFormat) |
24744 | 3294 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3295 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat; |
24744 | 3296 |
3297 if (Vhdr->bmiHeader.biHeight < 0) | |
3298 Vhdr->bmiHeader.biHeight = -height; | |
3299 else | |
3300 Vhdr->bmiHeader.biHeight = height; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3301 priv->chains[0]->pmt->lSampleSize = Vhdr->bmiHeader.biSizeImage = |
24744 | 3302 labs(Vhdr->bmiHeader.biBitCount * Vhdr->bmiHeader.biWidth * |
3303 Vhdr->bmiHeader.biHeight) >> 3; | |
3304 | |
3305 priv->height = height; | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3306 return TVI_CONTROL_TRUE; |
24744 | 3307 } |
3308 case TVI_CONTROL_VID_GET_HEIGHT: | |
3309 { | |
3310 if (priv->height) { | |
3311 *(int *) arg = priv->height; | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3312 return TVI_CONTROL_TRUE; |
24744 | 3313 } else |
3314 return TVI_CONTROL_FALSE; | |
3315 } | |
3316 case TVI_CONTROL_VID_CHK_HEIGHT: | |
3317 { | |
3318 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3319 int height = *(int *) arg; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3320 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3321 if (!pCaps) |
3322 return TVI_CONTROL_FALSE; | |
3323 if (height < pCaps->MinOutputSize.cy | |
3324 || height > pCaps->MaxOutputSize.cy) | |
3325 return TVI_CONTROL_FALSE; | |
3326 | |
3327 if (height % pCaps->OutputGranularityY) | |
3328 return TVI_CONTROL_FALSE; | |
3329 | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3330 return TVI_CONTROL_TRUE; |
24744 | 3331 } |
3332 case TVI_CONTROL_IS_AUDIO: | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3333 if (!priv->chains[1]->pmt) |
24744 | 3334 return TVI_CONTROL_FALSE; |
3335 else | |
3336 return TVI_CONTROL_TRUE; | |
3337 case TVI_CONTROL_IS_VIDEO: | |
3338 return TVI_CONTROL_TRUE; | |
3339 case TVI_CONTROL_AUD_GET_FORMAT: | |
3340 { | |
3341 *(int *) arg = AF_FORMAT_S16_LE; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3342 if (!priv->chains[1]->pmt) |
24744 | 3343 return TVI_CONTROL_FALSE; |
3344 else | |
3345 return TVI_CONTROL_TRUE; | |
3346 } | |
3347 case TVI_CONTROL_AUD_GET_CHANNELS: | |
3348 { | |
3349 *(int *) arg = priv->channels; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3350 if (!priv->chains[1]->pmt) |
24744 | 3351 return TVI_CONTROL_FALSE; |
3352 else | |
3353 return TVI_CONTROL_TRUE; | |
3354 } | |
3355 case TVI_CONTROL_AUD_SET_SAMPLERATE: | |
3356 { | |
3357 int i, samplerate; | |
3358 if (priv->state) | |
3359 return TVI_CONTROL_FALSE; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3360 if (!priv->chains[1]->arpmt[0]) |
24744 | 3361 return TVI_CONTROL_FALSE; |
3362 | |
28576 | 3363 samplerate = *(int *) arg; |
24744 | 3364 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3365 for (i = 0; priv->chains[1]->arpmt[i]; i++) |
24744 | 3366 if (check_audio_format |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3367 (priv->chains[1]->arpmt[i], samplerate, 16, priv->channels)) |
24744 | 3368 break; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
3369 if (!priv->chains[1]->arpmt[i]) { |
24744 | 3370 //request not found. failing back to first available |
3371 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_SamplerateNotsupported, samplerate); | |
3372 i = 0; | |
3373 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3374 if (priv->chains[1]->pmt) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3375 DeleteMediaType(priv->chains[1]->pmt); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3376 priv->chains[1]->pmt = CreateMediaType(priv->chains[1]->arpmt[i]); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3377 extract_audio_format(priv->chains[1]->arpmt[i], &(priv->samplerate), |
24744 | 3378 NULL, &(priv->channels)); |
3379 return TVI_CONTROL_TRUE; | |
3380 } | |
3381 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
3382 { | |
3383 *(int *) arg = priv->samplerate; | |
3384 if (!priv->samplerate) | |
3385 return TVI_CONTROL_FALSE; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3386 if (!priv->chains[1]->pmt) |
24744 | 3387 return TVI_CONTROL_FALSE; |
3388 else | |
3389 return TVI_CONTROL_TRUE; | |
3390 } | |
3391 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
3392 { | |
3393 WAVEFORMATEX *pWF; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3394 if (!priv->chains[1]->pmt) |
24744 | 3395 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3396 if (!priv->chains[1]->pmt->pbFormat) |
24744 | 3397 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3398 pWF = (WAVEFORMATEX *) priv->chains[1]->pmt->pbFormat; |
24744 | 3399 *(int *) arg = pWF->wBitsPerSample / 8; |
3400 return TVI_CONTROL_TRUE; | |
3401 } | |
3402 case TVI_CONTROL_IS_TUNER: | |
3403 { | |
3404 if (!priv->pTVTuner) | |
3405 return TVI_CONTROL_FALSE; | |
3406 | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3407 return TVI_CONTROL_TRUE; |
24744 | 3408 } |
3409 case TVI_CONTROL_TUN_SET_NORM: | |
3410 { | |
3411 IAMAnalogVideoDecoder *pVD; | |
3412 long lAnalogFormat; | |
3413 int i; | |
3414 HRESULT hr; | |
3415 | |
3416 i = *(int *) arg; | |
3417 i--; | |
3418 if (i < 0 || i >= tv_available_norms_count) | |
3419 return TVI_CONTROL_FALSE; | |
3420 lAnalogFormat = tv_norms[tv_available_norms[i]].index; | |
3421 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3422 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter,IID_IAMAnalogVideoDecoder, pVD); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28576
diff
changeset
|
3423 if (hr != S_OK) |
24744 | 3424 return TVI_CONTROL_FALSE; |
25077 | 3425 hr = OLE_CALL_ARGS(pVD, put_TVFormat, lAnalogFormat); |
24744 | 3426 OLE_RELEASE_SAFE(pVD); |
3427 if (FAILED(hr)) | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3428 return TVI_CONTROL_FALSE; |
24744 | 3429 else |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3430 return TVI_CONTROL_TRUE; |
24744 | 3431 } |
3432 case TVI_CONTROL_TUN_GET_NORM: | |
3433 { | |
3434 long lAnalogFormat; | |
3435 int i; | |
3436 HRESULT hr; | |
3437 IAMAnalogVideoDecoder *pVD; | |
3438 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3439 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter,IID_IAMAnalogVideoDecoder, pVD); |
24744 | 3440 if (hr == S_OK) { |
3441 hr = OLE_CALL_ARGS(pVD, get_TVFormat, &lAnalogFormat); | |
3442 OLE_RELEASE_SAFE(pVD); | |
3443 } | |
3444 | |
3445 if (FAILED(hr)) { //trying another method | |
3446 if (!priv->pTVTuner) | |
3447 return TVI_CONTROL_FALSE; | |
3448 hr=OLE_CALL_ARGS(priv->pTVTuner, get_TVFormat, &lAnalogFormat); | |
3449 if (FAILED(hr)) | |
3450 return TVI_CONTROL_FALSE; | |
3451 } | |
3452 for (i = 0; i < tv_available_norms_count; i++) { | |
3453 if (tv_norms[tv_available_norms[i]].index == lAnalogFormat) { | |
3454 *(int *) arg = i + 1; | |
3455 return TVI_CONTROL_TRUE; | |
3456 } | |
3457 } | |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3458 return TVI_CONTROL_FALSE; |
24744 | 3459 } |
3460 case TVI_CONTROL_SPC_GET_NORMID: | |
3461 { | |
3462 int i; | |
3463 if (!priv->pTVTuner) | |
3464 return TVI_CONTROL_FALSE; | |
3465 for (i = 0; i < tv_available_norms_count; i++) { | |
3466 if (!strcasecmp | |
3467 (tv_norms[tv_available_norms[i]].name, (char *) arg)) { | |
3468 *(int *) arg = i + 1; | |
3469 return TVI_CONTROL_TRUE; | |
3470 } | |
3471 } | |
3472 return TVI_CONTROL_FALSE; | |
3473 } | |
3474 case TVI_CONTROL_SPC_SET_INPUT: | |
3475 { | |
3476 return set_crossbar_input(priv, *(int *) arg); | |
3477 } | |
3478 case TVI_CONTROL_TUN_GET_FREQ: | |
3479 { | |
3480 unsigned long lFreq; | |
3481 int ret; | |
3482 if (!priv->pTVTuner) | |
3483 return TVI_CONTROL_FALSE; | |
3484 | |
3485 ret = get_frequency(priv, &lFreq); | |
27628
1779bbc0733a
Fix overflow in frequency conversion code inside tvi_dshow.
voroshil
parents:
27370
diff
changeset
|
3486 lFreq = lFreq / (1000000/16); //convert from Hz to 1/16 MHz units |
24744 | 3487 |
3488 *(unsigned long *) arg = lFreq; | |
3489 return ret; | |
3490 } | |
3491 case TVI_CONTROL_TUN_SET_FREQ: | |
3492 { | |
3493 unsigned long nFreq = *(unsigned long *) arg; | |
3494 if (!priv->pTVTuner) | |
3495 return TVI_CONTROL_FALSE; | |
3496 //convert to Hz | |
27628
1779bbc0733a
Fix overflow in frequency conversion code inside tvi_dshow.
voroshil
parents:
27370
diff
changeset
|
3497 nFreq = (1000000/16) * nFreq; //convert from 1/16 MHz units to Hz |
24744 | 3498 return set_frequency(priv, nFreq); |
3499 } | |
3500 case TVI_CONTROL_VID_SET_HUE: | |
3501 return set_control(priv, VideoProcAmp_Hue, *(int *) arg); | |
3502 case TVI_CONTROL_VID_GET_HUE: | |
3503 return get_control(priv, VideoProcAmp_Hue, (int *) arg); | |
3504 case TVI_CONTROL_VID_SET_CONTRAST: | |
3505 return set_control(priv, VideoProcAmp_Contrast, *(int *) arg); | |
3506 case TVI_CONTROL_VID_GET_CONTRAST: | |
3507 return get_control(priv, VideoProcAmp_Contrast, (int *) arg); | |
3508 case TVI_CONTROL_VID_SET_SATURATION: | |
3509 return set_control(priv, VideoProcAmp_Saturation, *(int *) arg); | |
3510 case TVI_CONTROL_VID_GET_SATURATION: | |
3511 return get_control(priv, VideoProcAmp_Saturation, (int *) arg); | |
3512 case TVI_CONTROL_VID_SET_BRIGHTNESS: | |
3513 return set_control(priv, VideoProcAmp_Brightness, *(int *) arg); | |
3514 case TVI_CONTROL_VID_GET_BRIGHTNESS: | |
3515 return get_control(priv, VideoProcAmp_Brightness, (int *) arg); | |
3516 | |
3517 case TVI_CONTROL_VID_GET_FPS: | |
3518 { | |
3519 VIDEOINFOHEADER *Vhdr; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3520 if (!priv->chains[0]->pmt) |
24744 | 3521 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3522 if (!priv->chains[0]->pmt->pbFormat) |
24744 | 3523 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3524 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat; |
24744 | 3525 *(float *) arg = |
25028
2cae9470f53b
Fix FPS from bitrate calculation (was 8 times larger than real value).
voroshil
parents:
25019
diff
changeset
|
3526 (1.0 * Vhdr->dwBitRate) / (Vhdr->bmiHeader.biSizeImage * 8); |
24744 | 3527 return TVI_CONTROL_TRUE; |
3528 } | |
3529 case TVI_CONTROL_IMMEDIATE: | |
3530 priv->immediate_mode = 1; | |
3531 return TVI_CONTROL_TRUE; | |
3532 case TVI_CONTROL_VBI_INIT: | |
3533 { | |
3534 void* ptr; | |
3535 ptr=&(priv->tsp); | |
29760
1cc8a20520e8
Add MSGT_TELETEXT, rename TVI_CONTROL as VBI_CONTROL and fix some paths
cehoyos
parents:
29759
diff
changeset
|
3536 if(teletext_control(NULL,TV_VBI_CONTROL_START,&ptr)==VBI_CONTROL_TRUE) |
24744 | 3537 priv->priv_vbi=ptr; |
3538 else | |
3539 priv->priv_vbi=NULL; | |
3540 return TVI_CONTROL_TRUE; | |
3541 } | |
29806 | 3542 case TVI_CONTROL_GET_VBI_PTR: |
3543 *(void **)arg=priv->priv_vbi; | |
3544 return TVI_CONTROL_TRUE; | |
24744 | 3545 } |
26756
c43ce7268677
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26737
diff
changeset
|
3546 return TVI_CONTROL_UNKNOWN; |
24744 | 3547 } |