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