Mercurial > mplayer.hg
annotate stream/tvi_dshow.c @ 25087:edc7391db7f5
New routine for reconnecting two pins with new media type
author | voroshil |
---|---|
date | Mon, 19 Nov 2007 20:19:33 +0000 |
parents | e91503fbf524 |
children | 554bbb45a2f2 |
rev | line source |
---|---|
24744 | 1 /* |
2 * TV support under Win32 | |
3 * | |
4 * (C) 2007 Vladimir Voroshilov <voroshil@gmail.com>. | |
5 * | |
6 * Based on tvi_dummy.c with help of tv.c, tvi_v4l2.c code . | |
7 * | |
8 * ------------------------------------------------------------------------------- | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
23 * | |
24 * | |
25 * ------------------------------------------------------------------------------- | |
26 * | |
27 * | |
28 * WARNING: This is alpha code! | |
29 * | |
30 * Abilities: | |
31 * * Watching TV under Win32 using WDM Capture driver and DirectShow | |
32 * * Grabbing synchronized audio/video with mencoder (synchronization is beeing done by DirectShow) | |
33 * * If device driver provides IAMStreamConfig interface, user can choose width/height with "-tv height=<h>:width=<w>" | |
34 * * Adjusting BRIGHTNESS,HUE,SATURATION,CONTRAST if supported by device | |
35 * * Selecting Tuner,S-Video,... as media source | |
36 * * User can select used video capture device, passing -tv device=<dev#> | |
37 * * User can select used audio input, passing -tv audioid=<input#> | |
38 * | |
39 * options which will not be implemented (probably sometime in future, if possible): | |
40 * * alsa | |
41 * * mjpeg | |
42 * * decimation=<1|2|4> | |
43 * * quality=<0\-100> | |
44 * * forceaudio | |
45 * * forcechan=<1\-2> | |
46 * * [volume|bass|treble|balance] | |
47 * | |
48 * Works with: | |
49 * - LifeView FlyTV Prime 34FM (SAA7134 based) with driver from Ivan Uskov | |
50 * Partially works with: | |
51 * - ATI 9200 VIVO based card | |
52 * - ATI AIW 7500 | |
53 * - nVidia Ti-4400 | |
54 * | |
55 * Known bugs: | |
56 * * stream goes with 24.93 FPS (NTSC), while reporting 25 FPS (PAL) ?! | |
57 * * direct set frequency call does not work ('Insufficient Buffer' error) | |
58 * * audio stream goes with about 1 sample/sec rate when capturing sound from audio card | |
59 * | |
60 * TODO: | |
61 * * check audio with small buffer on vivo !!! | |
62 * * norm for IAMVideoDecoder and for IAMTVtuner - differs !! | |
63 * * check how to change TVFormat on VIVO card without tuner | |
64 * * Flip image upside-down for RGB formats. | |
65 * * | |
66 * * remove debug sleep() | |
67 * * Add some notes to methods' parameters | |
68 * * refactor console messages | |
69 * * check using header files and keep only needed | |
70 * * add additional comments to methods' bodies | |
71 * | |
72 */ | |
73 | |
74 | |
75 /// \ingroup tvi_dshow | |
76 | |
77 #include "config.h" | |
78 | |
79 #include <stdio.h> | |
80 #include "libmpcodecs/img_format.h" | |
81 #include "libaf/af_format.h" | |
82 #include "help_mp.h" | |
83 #include "osdep/timer.h" | |
84 | |
85 | |
86 #include "tv.h" | |
87 #include "mp_msg.h" | |
88 #include "frequencies.h" | |
89 | |
90 | |
91 #include "tvi_dshow.h" | |
92 | |
93 static tvi_handle_t *tvi_init_dshow(tv_param_t* tv_param); | |
94 | |
95 /* | |
96 *--------------------------------------------------------------------------------------- | |
97 * | |
98 * Data structures | |
99 * | |
100 *--------------------------------------------------------------------------------------- | |
101 */ | |
102 /** | |
103 information about this file | |
104 */ | |
105 tvi_info_t tvi_info_dshow = { | |
106 tvi_init_dshow, | |
107 "DirectShow TV", | |
108 "dshow", | |
109 "Vladimir Voroshilov", | |
110 "Very experimental!! Use with caution" | |
111 }; | |
112 | |
113 | |
114 /** | |
115 ringbuffer related info | |
116 */ | |
117 typedef struct { | |
118 CRITICAL_SECTION *pMutex; ///< pointer to critical section (mutex) | |
119 char **ringbuffer; ///< ringbuffer array | |
120 double*dpts; ///< samples' timestamps | |
121 | |
122 int buffersize; ///< size of buffer in blocks | |
123 int blocksize; ///< size of individual block | |
124 int head; ///< index of first valid sample | |
125 int tail; ///< index of last valid sample | |
126 int count; ///< count of valid samples in ringbuffer | |
127 double tStart; ///< pts of first sample (first sample should have pts 0) | |
128 } grabber_ringbuffer_t; | |
129 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
130 typedef enum { unknown, video, audio, vbi } stream_type; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
131 |
24744 | 132 /** |
133 CSampleGrabberCD definition | |
134 */ | |
135 typedef struct CSampleGrabberCB { | |
136 ISampleGrabberCBVtbl *lpVtbl; | |
137 int refcount; | |
138 GUID interfaces[2]; | |
139 grabber_ringbuffer_t *pbuf; | |
140 } CSampleGrabberCB; | |
141 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
142 /** |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
143 Chain related structure |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
144 */ |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
145 typedef struct { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
146 stream_type type; ///< stream type |
25080 | 147 const GUID* majortype; ///< GUID of major mediatype (video/audio/vbi) |
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) | |
174 int width; ///< picture width (default: auto) | |
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 | |
212 DWORD VideoStandard; ///< used video standard | |
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); | |
235 #if 0 | |
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 | |
311 {NULL, 1} | |
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); | |
445 DEFINE_GUID(PIN_CATEGORY_PREVIEW, 0xfb6c4282, 0x0353, 0x11d1, 0x90, 0x5f, | |
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; | |
475 prop.cBuffers = -1; | |
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 */ | |
647 /** | |
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 * | |
734 * \return S_OK if success | |
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 | |
817 * After call to IAMTVTuner::put_CountryCode with returned value tuner switches to frequency table used in specified | |
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 | |
867 * \param[out] pnLen length of array | |
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 * | |
874 * \remarks | |
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 | |
887 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: load_freq_table called %d (%d)\n",nCountry,nInputType); | |
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]; | |
930 } | |
931 FreeLibrary(hDLL); | |
932 return S_OK; | |
933 } | |
934 | |
935 /** | |
936 * \brief tunes to given frequency through IKsPropertySet call | |
937 * | |
938 * \param pTVTuner IAMTVTuner interface of capture device | |
939 * \param lFreq frequency to tune (in Hz) | |
940 * | |
941 * \return S_OK success | |
942 * \return apropriate error code otherwise | |
943 * | |
944 * \note | |
945 * Due to either bug in driver or error in following code calll to IKsProperty::Set | |
946 * in this methods always fail with error 0x8007007a. | |
947 * | |
948 * \todo test code on other machines and an error | |
949 */ | |
950 static HRESULT set_frequency_direct(IAMTVTuner * pTVTuner, long lFreq) | |
951 { | |
952 HRESULT hr; | |
953 DWORD dwSupported = 0; | |
954 DWORD cbBytes = 0; | |
955 KSPROPERTY_TUNER_MODE_CAPS_S mode_caps; | |
956 KSPROPERTY_TUNER_FREQUENCY_S frequency; | |
957 IKsPropertySet *pKSProp; | |
958 | |
959 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_frequency_direct called\n"); | |
960 | |
961 memset(&mode_caps, 0, sizeof(mode_caps)); | |
962 memset(&frequency, 0, sizeof(frequency)); | |
963 | |
964 hr = OLE_QUERYINTERFACE(pTVTuner, IID_IKsPropertySet, pKSProp); | |
965 if (FAILED(hr)) | |
966 return hr; //no IKsPropertySet interface | |
967 | |
968 mode_caps.Mode = AMTUNER_MODE_TV; | |
969 hr = OLE_CALL_ARGS(pKSProp, QuerySupported, &PROPSETID_TUNER, | |
970 KSPROPERTY_TUNER_MODE_CAPS, &dwSupported); | |
971 if (FAILED(hr)) { | |
972 OLE_RELEASE_SAFE(pKSProp); | |
973 return hr; | |
974 } | |
975 | |
976 if (!dwSupported & KSPROPERTY_SUPPORT_GET) { | |
977 OLE_RELEASE_SAFE(pKSProp); | |
978 return E_FAIL; //PROPSETID_TINER not supported | |
979 } | |
980 | |
981 hr = OLE_CALL_ARGS(pKSProp, Get, &PROPSETID_TUNER, | |
982 KSPROPERTY_TUNER_MODE_CAPS, | |
983 INSTANCEDATA_OF_PROPERTY_PTR(&mode_caps), | |
984 INSTANCEDATA_OF_PROPERTY_SIZE(mode_caps), | |
985 &mode_caps, sizeof(mode_caps), &cbBytes); | |
986 | |
987 frequency.Frequency = lFreq; | |
988 | |
989 if (mode_caps.Strategy == KS_TUNER_STRATEGY_DRIVER_TUNES) | |
990 frequency.TuningFlags = KS_TUNER_TUNING_FINE; | |
991 else | |
992 frequency.TuningFlags = KS_TUNER_TUNING_EXACT; | |
993 | |
994 if (lFreq < mode_caps.MinFrequency || lFreq > mode_caps.MaxFrequency) { | |
995 OLE_RELEASE_SAFE(pKSProp); | |
996 return E_FAIL; | |
997 } | |
998 | |
999 hr = OLE_CALL_ARGS(pKSProp, Set, &PROPSETID_TUNER, | |
1000 KSPROPERTY_TUNER_FREQUENCY, | |
1001 INSTANCEDATA_OF_PROPERTY_PTR(&frequency), | |
1002 INSTANCEDATA_OF_PROPERTY_SIZE(frequency), | |
1003 &frequency, sizeof(frequency)); | |
1004 if (FAILED(hr)) { | |
1005 OLE_RELEASE_SAFE(pKSProp); | |
1006 return hr; | |
1007 } | |
1008 | |
1009 OLE_RELEASE_SAFE(pKSProp); | |
1010 | |
1011 return S_OK; | |
1012 } | |
1013 | |
1014 /** | |
1015 * \brief find channel with nearest frequency and set it | |
1016 * | |
1017 * \param priv driver's private data | |
1018 * \param lFreq frequency in Hz | |
1019 * | |
1020 * \return S_OK if success | |
1021 * \return E_FAIL if error occured | |
1022 */ | |
1023 static HRESULT set_nearest_freq(priv_t * priv, long lFreq) | |
1024 { | |
1025 HRESULT hr; | |
1026 int i; | |
1027 long lFreqDiff=-1; | |
1028 int nChannel; | |
1029 TunerInputType tunerInput; | |
1030 long lInput; | |
1031 | |
1032 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_nearest_freq called\n"); | |
1033 if(priv->freq_table_len == -1 && !priv->freq_table) { | |
1034 | |
1035 hr = OLE_CALL_ARGS(priv->pTVTuner, get_ConnectInput, &lInput); | |
1036 if(FAILED(hr)){ //Falling back to 0 | |
1037 lInput=0; | |
1038 } | |
1039 | |
1040 hr = OLE_CALL_ARGS(priv->pTVTuner, get_InputType, lInput, &tunerInput); | |
1041 | |
1042 if (load_freq_table(chanlist2country(priv->tv_param->chanlist), tunerInput, &(priv->freq_table), &(priv->freq_table_len), &(priv->first_channel)) != S_OK) {//FIXME | |
1043 priv->freq_table_len=0; | |
1044 priv->freq_table=NULL; | |
1045 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableExtractFreqTable); | |
1046 return E_FAIL; | |
1047 }; | |
1048 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_FreqTableLoaded, tunerInput == TunerInputAntenna ? "broadcast" : "cable", | |
1049 chanlist2country(priv->tv_param->chanlist), priv->freq_table_len); | |
1050 } | |
1051 | |
1052 if (priv->freq_table_len <= 0) | |
1053 return E_FAIL; | |
1054 | |
1055 //FIXME: rewrite search algo | |
1056 nChannel = -1; | |
1057 for (i = 0; i < priv->freq_table_len; i++) { | |
1058 if (nChannel == -1 || labs(lFreq - priv->freq_table[i]) < lFreqDiff) { | |
1059 nChannel = priv->first_channel + i; | |
1060 lFreqDiff = labs(lFreq - priv->freq_table[i]); | |
1061 } | |
1062 } | |
1063 if (nChannel == -1) { | |
1064 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableFindNearestChannel); | |
1065 return E_FAIL; | |
1066 } | |
1067 hr = OLE_CALL_ARGS(priv->pTVTuner, put_Channel, nChannel, | |
1068 AMTUNER_SUBCHAN_DEFAULT, AMTUNER_SUBCHAN_DEFAULT); | |
1069 if (FAILED(hr)) { | |
1070 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableToSetChannel, (unsigned int)hr); | |
1071 return E_FAIL; | |
1072 } | |
1073 return S_OK; | |
1074 } | |
1075 | |
1076 /** | |
1077 * \brief setting frequency. decides whether use direct call/workaround | |
1078 * | |
1079 * \param priv driver's private data | |
1080 * \param lFreq frequency in Hz | |
1081 * | |
1082 * \return TVI_CONTROL_TRUE if success | |
1083 * \return TVI_CONTROL_FALSE if error occured | |
1084 * | |
1085 * \todo check for freq boundary | |
1086 */ | |
1087 static int set_frequency(priv_t * priv, long lFreq) | |
1088 { | |
1089 HRESULT hr; | |
1090 | |
1091 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_frequency called\n"); | |
1092 if (!priv->pTVTuner) | |
1093 return TVI_CONTROL_FALSE; | |
1094 if (priv->direct_setfreq_call) { //using direct call to set frequency | |
1095 hr = set_frequency_direct(priv->pTVTuner, lFreq); | |
1096 if (FAILED(hr)) { | |
1097 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_DirectSetFreqFailed); | |
1098 priv->direct_setfreq_call = 0; | |
1099 } | |
1100 } | |
1101 if (!priv->direct_setfreq_call) { | |
1102 hr = set_nearest_freq(priv, lFreq); | |
1103 } | |
1104 if (FAILED(hr)) | |
1105 return TVI_CONTROL_FALSE; | |
1106 #ifdef DEPRECATED | |
1107 priv->pGrabber->ClearBuffer(priv->pGrabber); | |
1108 #endif | |
1109 return TVI_CONTROL_TRUE; | |
1110 } | |
1111 | |
1112 /** | |
1113 * \brief return current frequency from tuner (in Hz) | |
1114 * | |
1115 * \param pTVTuner IAMTVTuner interface of tuner | |
1116 * \param plFreq address of variable that receives current frequency | |
1117 * | |
1118 * \return S_OK success | |
1119 * \return E_POINTER pTVTuner==NULL || plFreq==NULL | |
1120 * \return apropriate error code otherwise | |
1121 */ | |
1122 static HRESULT get_frequency_direct(IAMTVTuner * pTVTuner, long *plFreq) | |
1123 { | |
1124 HRESULT hr; | |
1125 KSPROPERTY_TUNER_STATUS_S TunerStatus; | |
1126 DWORD cbBytes; | |
1127 IKsPropertySet *pKSProp; | |
1128 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_frequency_direct called\n"); | |
1129 | |
1130 if (!plFreq) | |
1131 return E_POINTER; | |
1132 | |
1133 hr = OLE_QUERYINTERFACE(pTVTuner, IID_IKsPropertySet, pKSProp); | |
1134 if (FAILED(hr)) { | |
1135 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get freq QueryInterface failed\n"); | |
1136 return hr; | |
1137 } | |
1138 | |
1139 hr = OLE_CALL_ARGS(pKSProp, Get, &PROPSETID_TUNER, | |
1140 KSPROPERTY_TUNER_STATUS, | |
1141 INSTANCEDATA_OF_PROPERTY_PTR(&TunerStatus), | |
1142 INSTANCEDATA_OF_PROPERTY_SIZE(TunerStatus), | |
1143 &TunerStatus, sizeof(TunerStatus), &cbBytes); | |
1144 if (FAILED(hr)) { | |
1145 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get freq Get failure\n"); | |
1146 return hr; | |
1147 } | |
1148 *plFreq = TunerStatus.CurrentFrequency; | |
1149 return S_OK; | |
1150 } | |
1151 | |
1152 /** | |
1153 * \brief gets current frequency | |
1154 * | |
1155 * \param priv driver's private data structure | |
1156 * \param plFreq - pointer to long int to store frequency to (in Hz) | |
1157 * | |
1158 * \return TVI_CONTROL_TRUE if success, TVI_CONTROL_FALSE otherwise | |
1159 */ | |
1160 static int get_frequency(priv_t * priv, long *plFreq) | |
1161 { | |
1162 HRESULT hr; | |
1163 | |
1164 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_frequency called\n"); | |
1165 | |
1166 if (!plFreq || !priv->pTVTuner) | |
1167 return TVI_CONTROL_FALSE; | |
1168 | |
1169 if (priv->direct_getfreq_call) { //using direct call to get frequency | |
1170 hr = get_frequency_direct(priv->pTVTuner, plFreq); | |
1171 if (FAILED(hr)) { | |
1172 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_DirectGetFreqFailed); | |
1173 priv->direct_getfreq_call = 0; | |
1174 } | |
1175 } | |
1176 if (!priv->direct_getfreq_call) { | |
1177 hr=OLE_CALL_ARGS(priv->pTVTuner, get_VideoFrequency, plFreq); | |
1178 if (FAILED(hr)) | |
1179 return TVI_CONTROL_FALSE; | |
1180 | |
1181 } | |
1182 return TVI_CONTROL_TRUE; | |
1183 } | |
1184 | |
1185 /** | |
1186 * \brief get tuner capabilities | |
1187 * | |
1188 * \param priv driver's private data | |
1189 */ | |
1190 static void get_capabilities(priv_t * priv) | |
1191 { | |
1192 long lAvailableFormats; | |
1193 HRESULT hr; | |
1194 int i; | |
1195 long lInputPins, lOutputPins, lRelated, lPhysicalType; | |
1196 IEnumPins *pEnum; | |
1197 char tmp[200]; | |
1198 IPin *pPin = 0; | |
1199 PIN_DIRECTION ThisPinDir; | |
1200 PIN_INFO pi; | |
1201 IAMAudioInputMixer *pIAMixer; | |
1202 | |
1203 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_capabilities called\n"); | |
1204 if (priv->pTVTuner) { | |
1205 | |
1206 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_SupportedNorms); | |
1207 hr = OLE_CALL_ARGS(priv->pTVTuner, get_AvailableTVFormats, | |
1208 &lAvailableFormats); | |
1209 if (FAILED(hr)) | |
1210 tv_available_norms_count = 0; | |
1211 else { | |
1212 for (i = 0; i < TV_NORMS_COUNT; i++) { | |
1213 if (lAvailableFormats & tv_norms[i].index) { | |
1214 tv_available_norms[tv_available_norms_count] = i; | |
1215 mp_msg(MSGT_TV, MSGL_V, " %d=%s;", | |
1216 tv_available_norms_count + 1, tv_norms[i].name); | |
1217 tv_available_norms_count++; | |
1218 } | |
1219 } | |
1220 } | |
1221 mp_msg(MSGT_TV, MSGL_INFO, "\n"); | |
1222 } | |
1223 if (priv->pCrossbar) { | |
1224 OLE_CALL_ARGS(priv->pCrossbar, get_PinCounts, &lOutputPins, | |
1225 &lInputPins); | |
1226 | |
1227 tv_available_inputs = (long *) malloc(sizeof(long) * lInputPins); | |
1228 tv_available_inputs_count = 0; | |
1229 | |
1230 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_AvailableVideoInputs); | |
1231 for (i = 0; i < lInputPins; i++) { | |
1232 OLE_CALL_ARGS(priv->pCrossbar, get_CrossbarPinInfo, 1, i, | |
1233 &lRelated, &lPhysicalType); | |
1234 | |
1235 if (lPhysicalType < 0x1000) { | |
1236 tv_available_inputs[tv_available_inputs_count++] = i; | |
1237 mp_msg(MSGT_TV, MSGL_V, " %d=%s;", | |
1238 tv_available_inputs_count - 1, | |
1239 physcon2str(lPhysicalType)); | |
1240 } | |
1241 } | |
1242 mp_msg(MSGT_TV, MSGL_INFO, "\n"); | |
1243 | |
1244 set_crossbar_input(priv, 0); | |
1245 } | |
1246 | |
1247 if (priv->adev_index != -1) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
1248 hr = OLE_CALL_ARGS(priv->chains[1]->pCaptureFilter, EnumPins, &pEnum); |
24744 | 1249 if (FAILED(hr)) |
1250 return; | |
1251 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_AvailableAudioInputs); | |
1252 i = 0; | |
1253 while (OLE_CALL_ARGS(pEnum, Next, 1, &pPin, NULL) == S_OK) { | |
1254 memset(&pi, 0, sizeof(pi)); | |
1255 memset(tmp, 0, 200); | |
1256 OLE_CALL_ARGS(pPin, QueryDirection, &ThisPinDir); | |
1257 if (ThisPinDir == PINDIR_INPUT) { | |
1258 OLE_CALL_ARGS(pPin, QueryPinInfo, &pi); | |
1259 wtoa(pi.achName, tmp, 200); | |
1260 OLE_RELEASE_SAFE(pi.pFilter); | |
1261 mp_msg(MSGT_TV, MSGL_V, " %d=%s", i, tmp); | |
1262 mp_msg(MSGT_TV, MSGL_DBG3, " (%p)", pPin); | |
1263 hr = OLE_QUERYINTERFACE(pPin, IID_IAMAudioInputMixer,pIAMixer); | |
1264 if (SUCCEEDED(hr)) { | |
1265 if (i == priv->tv_param->audio_id) { | |
1266 OLE_CALL_ARGS(pIAMixer, put_Enable, TRUE); | |
1267 if(priv->tv_param->volume>0) | |
1268 OLE_CALL_ARGS(pIAMixer, put_MixLevel, 0.01 * priv->tv_param->volume); | |
1269 #if 0 | |
1270 else | |
1271 OLE_CALL_ARGS(pIAMixer, put_MixLevel, 1.0); | |
1272 #endif | |
1273 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_InputSelected); | |
1274 } else { | |
1275 OLE_CALL_ARGS(pIAMixer, put_Enable, FALSE); | |
1276 #if 0 | |
1277 OLE_CALL_ARGS(pIAMixer, put_MixLevel, 0.0); | |
1278 #endif | |
1279 } | |
1280 OLE_RELEASE_SAFE(pIAMixer); | |
1281 } | |
1282 mp_msg(MSGT_TV, MSGL_V, ";"); | |
1283 OLE_RELEASE_SAFE(pPin); | |
1284 i++; | |
1285 } | |
1286 } | |
1287 mp_msg(MSGT_TV, MSGL_INFO, "\n"); | |
1288 OLE_RELEASE_SAFE(pEnum); | |
1289 } | |
1290 } | |
1291 | |
1292 /* | |
1293 *--------------------------------------------------------------------------------------- | |
1294 * | |
1295 * Filter related methods | |
1296 * | |
1297 *--------------------------------------------------------------------------------------- | |
1298 */ | |
1299 /** | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1300 * \brief routine for reconnecting two pins with new media type |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1301 * \param pGraph IGraphBuilder interface |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1302 * \param chan chain data |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1303 * \param pmt [in/out] new mediatype for pin connection |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1304 * |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1305 * \return S_OK if operation successfult, error code otherwise |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1306 * will also return media type of new connection into pmt variable |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1307 */ |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1308 static HRESULT reconnect_pins(IGraphBuilder *pGraph, chain_t *chain, AM_MEDIA_TYPE *pmt) |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1309 { |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1310 AM_MEDIA_TYPE old_mt; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1311 HRESULT hr; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1312 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1313 do { |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1314 /* save old media type for reconnection in case of error */ |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1315 hr = OLE_CALL_ARGS(chain->pCapturePin, ConnectionMediaType, &old_mt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1316 if(FAILED(hr)) |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1317 return hr; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1318 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1319 hr = OLE_CALL(chain->pCapturePin, Disconnect); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1320 if(FAILED(hr)) |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1321 return hr; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1322 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1323 hr = OLE_CALL_ARGS(chain->pSG, SetMediaType, pmt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1324 if(FAILED(hr)) |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1325 return hr; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1326 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1327 hr = OLE_CALL_ARGS(pGraph, Connect, chain->pCapturePin, chain->pSGIn); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1328 if(FAILED(hr)) |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1329 { |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1330 OLE_CALL_ARGS(chain->pSG, SetMediaType, &old_mt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1331 OLE_CALL_ARGS(pGraph, Connect, chain->pCapturePin, chain->pSGIn); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1332 break; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1333 } |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1334 hr = OLE_CALL_ARGS(chain->pCapturePin, ConnectionMediaType, &old_mt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1335 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1336 hr = S_OK; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1337 } while(0); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1338 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1339 FreeMediaType(pmt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1340 CopyMediaType(pmt, &old_mt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1341 FreeMediaType(&old_mt); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1342 return hr; |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1343 } |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1344 |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1345 /** |
24744 | 1346 * \brief building in graph audio/video capture chain |
1347 * | |
1348 * \param priv driver's private data | |
1349 * \param pCaptureFilter pointer to capture device's IBaseFilter interface | |
1350 * \param pbuf ringbuffer data structure | |
1351 * \param pmt media type for chain (AM_MEDIA_TYPE) | |
1352 * | |
1353 * \note routine does not frees memory, allocated for grabber_rinbuffer_s structure | |
1354 */ | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1355 static HRESULT build_sub_graph(priv_t * priv, chain_t * chain, const GUID* ppin_category) |
24744 | 1356 { |
1357 HRESULT hr; | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1358 int nFormatProbed = 0; |
25029
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1359 |
24744 | 1360 IPin *pSGOut; |
1361 IPin *pNRIn=NULL; | |
1362 | |
1363 IBaseFilter *pNR = NULL; | |
1364 | |
1365 hr=S_OK; | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1366 |
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1367 //No supported formats |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1368 if(!chain->arpmt[0]) |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1369 return E_FAIL; |
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1370 |
24744 | 1371 do{ |
1372 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
|
1373 (IUnknown *) chain->pCaptureFilter, |
24744 | 1374 PINDIR_OUTPUT, ppin_category, |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1375 chain->majortype, FALSE, 0, &chain->pCapturePin); |
24744 | 1376 if(FAILED(hr)){ |
1377 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: FindPin(pCapturePin) call failed. Error:0x%x\n", (unsigned int)hr); | |
1378 break; | |
1379 } | |
1380 /* Addinf SampleGrabber filter for video stream */ | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1381 hr = CoCreateInstance((GUID *) & CLSID_SampleGrabber, NULL,CLSCTX_INPROC_SERVER, &IID_IBaseFilter,(void *) &chain->pSGF); |
24744 | 1382 if(FAILED(hr)){ |
1383 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CoCreateInstance(SampleGrabber) call failed. Error:0x%x\n", (unsigned int)hr); | |
1384 break; | |
1385 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1386 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, chain->pSGF, L"Sample Grabber"); |
24744 | 1387 if(FAILED(hr)){ |
1388 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: AddFilter(SampleGrabber) call failed. Error:0x%x\n", (unsigned int)hr); | |
1389 break; | |
1390 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1391 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, (IUnknown *) chain->pSGF,PINDIR_INPUT, NULL, NULL, FALSE, 0, &chain->pSGIn); |
24744 | 1392 if(FAILED(hr)){ |
1393 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pSGIn) call failed. Error:0x%x\n", (unsigned int)hr); | |
1394 break; | |
1395 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1396 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, (IUnknown *) chain->pSGF,PINDIR_OUTPUT, NULL, NULL, FALSE, 0, &pSGOut); |
24744 | 1397 if(FAILED(hr)){ |
1398 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pSGOut) call failed. Error:0x%x\n", (unsigned int)hr); | |
1399 break; | |
1400 } | |
1401 | |
1402 /* creating ringbuffer for video samples */ | |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
1403 chain->pCSGCB = CSampleGrabberCB_Create(chain->rbuf); |
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
1404 if(!chain->pCSGCB){ |
24744 | 1405 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CSampleGrabberCB_Create(pbuf) call failed. Error:0x%x\n", (unsigned int)E_OUTOFMEMORY); |
1406 break; | |
1407 } | |
1408 | |
1409 /* initializing SampleGrabber filter */ | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1410 hr = OLE_QUERYINTERFACE(chain->pSGF, IID_ISampleGrabber, chain->pSG); |
24744 | 1411 if(FAILED(hr)){ |
1412 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: QueryInterface(IID_ISampleGrabber) call failed. Error:0x%x\n", (unsigned int)hr); | |
1413 break; | |
1414 } | |
1415 // 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
|
1416 hr = OLE_CALL_ARGS(chain->pSG, SetCallback, (ISampleGrabberCB *) chain->pCSGCB, 0); //we want to receive sample |
24744 | 1417 |
1418 if(FAILED(hr)){ | |
1419 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetCallback(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1420 break; | |
1421 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1422 hr = OLE_CALL_ARGS(chain->pSG, SetOneShot, FALSE); //... for all frames |
24744 | 1423 if(FAILED(hr)){ |
1424 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetOneShot(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1425 break; | |
1426 } | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1427 hr = OLE_CALL_ARGS(chain->pSG, SetBufferSamples, FALSE); //... do not buffer samples in sample grabber |
24744 | 1428 if(FAILED(hr)){ |
1429 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetBufferSamples(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1430 break; | |
1431 } | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1432 |
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1433 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
|
1434 set_buffer_preference(20,(WAVEFORMATEX*)(chain->arpmt[nFormatProbed]->pbFormat),chain->pCapturePin,chain->pSGIn); |
25048 | 1435 } |
24744 | 1436 |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1437 for(nFormatProbed=0; chain->arpmt[nFormatProbed]; nFormatProbed++) |
25065 | 1438 { |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1439 DisplayMediaType("Probing format", chain->arpmt[nFormatProbed]); |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1440 hr = OLE_CALL_ARGS(chain->pSG, SetMediaType, chain->arpmt[nFormatProbed]); //set desired mediatype |
25066 | 1441 if(FAILED(hr)){ |
1442 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetMediaType(pSG) call failed. Error:0x%x\n", (unsigned int)hr); | |
1443 continue; | |
1444 } | |
1445 /* connecting filters together: VideoCapture --> SampleGrabber */ | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1446 hr = OLE_CALL_ARGS(priv->pGraph, Connect, chain->pCapturePin, chain->pSGIn); |
25066 | 1447 if(FAILED(hr)){ |
1448 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: Unable to create pCapturePin<->pSGIn connection. Error:0x%x\n", (unsigned int)hr); | |
1449 continue; | |
1450 } | |
25065 | 1451 break; |
1452 } | |
1453 | |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
1454 if(!chain->arpmt[nFormatProbed]) |
25065 | 1455 { |
1456 mp_msg(MSGT_TV, MSGL_WARN, "tvi_dshow: Unable to negotiate media format\n"); | |
1457 hr = E_FAIL; | |
24744 | 1458 break; |
1459 } | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1460 |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1461 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
|
1462 if(FAILED(hr)) |
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1463 { |
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1464 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
|
1465 } |
24744 | 1466 |
1467 if(priv->tv_param->hidden_video_renderer){ | |
1468 IEnumFilters* pEnum; | |
1469 IBaseFilter* pFilter; | |
1470 | |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
1471 hr=OLE_CALL_ARGS(priv->pBuilder,RenderStream,NULL,NULL,(IUnknown*)chain->pCapturePin,NULL,NULL); |
24744 | 1472 |
1473 OLE_CALL_ARGS(priv->pGraph, EnumFilters, &pEnum); | |
1474 while (OLE_CALL_ARGS(pEnum, Next, 1, &pFilter, NULL) == S_OK) { | |
1475 LPVIDEOWINDOW pVideoWindow; | |
1476 hr = OLE_QUERYINTERFACE(pFilter, IID_IVideoWindow, pVideoWindow); | |
1477 if (SUCCEEDED(hr)) | |
1478 { | |
1479 OLE_CALL_ARGS(pVideoWindow,put_Visible,/* OAFALSE*/ 0); | |
1480 OLE_CALL_ARGS(pVideoWindow,put_AutoShow,/* OAFALSE*/ 0); | |
1481 OLE_RELEASE_SAFE(pVideoWindow); | |
1482 } | |
1483 OLE_RELEASE_SAFE(pFilter); | |
1484 } | |
1485 OLE_RELEASE_SAFE(pEnum); | |
1486 }else | |
1487 { | |
25052
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1488 #if 0 |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1489 /* |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1490 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
|
1491 Perhaps, this happens because NullRenderer filter discards each received |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1492 frame while discarded frames causes live source filter to dramatically reduce frame rate. |
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1493 */ |
24744 | 1494 /* adding sink for video stream */ |
1495 hr = CoCreateInstance((GUID *) & CLSID_NullRenderer, NULL,CLSCTX_INPROC_SERVER, &IID_IBaseFilter,(void *) &pNR); | |
1496 if(FAILED(hr)){ | |
1497 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: CoCreateInstance(NullRenderer) call failed. Error:0x%x\n", (unsigned int)hr); | |
1498 break; | |
1499 } | |
1500 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, pNR, L"Null Renderer"); | |
1501 if(FAILED(hr)){ | |
1502 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: AddFilter(NullRenderer) call failed. Error:0x%x\n", (unsigned int)hr); | |
1503 break; | |
1504 } | |
1505 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, (IUnknown *) pNR,PINDIR_INPUT, NULL, NULL, FALSE, 0, &pNRIn); | |
1506 if(FAILED(hr)){ | |
1507 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pNRIn) call failed. Error:0x%x\n", (unsigned int)hr); | |
1508 break; | |
1509 } | |
1510 /* | |
1511 Prevent ending VBI chain with NullRenderer filter, because this causes VBI pin disconnection | |
1512 */ | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
1513 if(memcmp(&(arpmt[nFormatProbed]->majortype),&MEDIATYPE_VBI,16)){ |
24744 | 1514 /* connecting filters together: SampleGrabber --> NullRenderer */ |
1515 hr = OLE_CALL_ARGS(priv->pGraph, Connect, pSGOut, pNRIn); | |
1516 if(FAILED(hr)){ | |
1517 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: Unable to create pSGOut<->pNRIn connection. Error:0x%x\n", (unsigned int)hr); | |
1518 break; | |
1519 } | |
1520 } | |
25052
7b2b17b57cf7
Disable terminating directshow chains with NullRenderer filter,
voroshil
parents:
25051
diff
changeset
|
1521 #endif |
24744 | 1522 } |
1523 | |
1524 hr = S_OK; | |
1525 } while(0); | |
25029
c9f20e41bc13
Make sure that mplayer will receive actual media type
voroshil
parents:
25028
diff
changeset
|
1526 |
24744 | 1527 OLE_RELEASE_SAFE(pSGOut); |
1528 OLE_RELEASE_SAFE(pNR); | |
1529 OLE_RELEASE_SAFE(pNRIn); | |
1530 | |
1531 return hr; | |
1532 } | |
1533 | |
1534 /** | |
1535 * \brief configures crossbar for grabbing video stream from given input | |
1536 * | |
1537 * \param priv driver's private data | |
1538 * \param input index of available video input to get data from | |
1539 * | |
1540 * \return TVI_CONTROL_TRUE success | |
1541 * \return TVI_CONTROL_FALSE error | |
1542 */ | |
1543 static int set_crossbar_input(priv_t * priv, int input) | |
1544 { | |
1545 HRESULT hr; | |
1546 int i, nVideoDecoder, nAudioDecoder; | |
1547 long lInput, lInputRelated, lRelated, lPhysicalType, lOutputPins, | |
1548 lInputPins; | |
1549 | |
1550 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: Configuring crossbar\n"); | |
1551 if (!priv->pCrossbar || input < 0 | |
1552 || input >= tv_available_inputs_count) | |
1553 return TVI_CONTROL_FALSE; | |
1554 | |
1555 OLE_CALL_ARGS(priv->pCrossbar, get_PinCounts, &lOutputPins, &lInputPins); | |
1556 | |
1557 lInput = tv_available_inputs[input]; | |
1558 | |
1559 if (lInput < 0 || lInput >= lInputPins) | |
1560 return TVI_CONTROL_FALSE; | |
1561 | |
1562 OLE_CALL_ARGS(priv->pCrossbar, get_CrossbarPinInfo, 1 /* input */ , lInput, | |
1563 &lInputRelated, &lPhysicalType); | |
1564 | |
1565 nVideoDecoder = nAudioDecoder = -1; | |
1566 for (i = 0; i < lOutputPins; i++) { | |
1567 OLE_CALL_ARGS(priv->pCrossbar, get_CrossbarPinInfo, 0 /*output */ , i, | |
1568 &lRelated, &lPhysicalType); | |
1569 if (lPhysicalType == PhysConn_Video_VideoDecoder) | |
1570 nVideoDecoder = i; | |
1571 if (lPhysicalType == PhysConn_Audio_AudioDecoder) | |
1572 nAudioDecoder = i; | |
1573 } | |
1574 if (nVideoDecoder >= 0) { | |
1575 //connecting given input with video decoder | |
1576 hr = OLE_CALL_ARGS(priv->pCrossbar, Route, nVideoDecoder, lInput); | |
1577 if (hr != S_OK) { | |
1578 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableConnectInputVideoDecoder, (unsigned int)hr); | |
1579 return TVI_CONTROL_FALSE; | |
1580 } | |
1581 } | |
1582 if (nAudioDecoder >= 0 && lInputRelated >= 0) { | |
1583 hr = OLE_CALL_ARGS(priv->pCrossbar, Route, nAudioDecoder, | |
1584 lInputRelated); | |
1585 if (hr != S_OK) { | |
1586 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableConnectInputAudioDecoder, (unsigned int)hr); | |
1587 return TVI_CONTROL_FALSE; | |
1588 } | |
1589 } | |
1590 return TVI_CONTROL_TRUE; | |
1591 } | |
1592 | |
1593 /** | |
1594 * \brief adjusts video control (hue,saturation,contrast,brightess) | |
1595 * | |
1596 * \param priv driver's private data | |
1597 * \param control which control to adjust | |
1598 * \param value new value for control (0-100) | |
1599 * | |
1600 * \return TVI_CONTROL_TRUE success | |
1601 * \return TVI_CONTROL_FALSE error | |
1602 */ | |
1603 static int set_control(priv_t * priv, int control, int value) | |
1604 { | |
1605 long lMin, lMax, lStepping, lDefault, lFlags, lValue; | |
1606 HRESULT hr; | |
1607 | |
1608 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: set_control called\n"); | |
1609 if (value < -100 || value > 100 || !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) || lFlags != VideoProcAmp_Flags_Manual) | |
1615 return TVI_CONTROL_FALSE; | |
1616 | |
1617 lValue = lMin + (value + 100) * (lMax - lMin) / 200; | |
1618 /* | |
1619 Workaround for ATI AIW 7500. The driver reports: max=255, stepping=256 | |
1620 */ | |
1621 if (lStepping > lMax) { | |
1622 mp_msg(MSGT_TV, MSGL_DBG3, | |
1623 "tvi_dshow: Stepping (%ld) is bigger than max value (%ld) for control %d. Assuming 1\n", | |
1624 lStepping, lMax,control); | |
1625 lStepping = 1; | |
1626 } | |
1627 lValue -= lValue % lStepping; | |
1628 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, Set, control, lValue, | |
1629 VideoProcAmp_Flags_Manual); | |
1630 if (FAILED(hr)) | |
1631 return TVI_CONTROL_FALSE; | |
1632 | |
1633 return TVI_CONTROL_TRUE; | |
1634 } | |
1635 | |
1636 /** | |
1637 * \brief get current value of video control (hue,saturation,contrast,brightess) | |
1638 * | |
1639 * \param priv driver's private data | |
1640 * \param control which control to adjust | |
1641 * \param pvalue address of variable thar receives current value | |
1642 * | |
1643 * \return TVI_CONTROL_TRUE success | |
1644 * \return TVI_CONTROL_FALSE error | |
1645 */ | |
1646 static int get_control(priv_t * priv, int control, int *pvalue) | |
1647 { | |
1648 long lMin, lMax, lStepping, lDefault, lFlags, lValue; | |
1649 HRESULT hr; | |
1650 | |
1651 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: get_control called\n"); | |
1652 if (!pvalue || !priv->pVideoProcAmp) | |
1653 return TVI_CONTROL_FALSE; | |
1654 | |
1655 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, GetRange, control, | |
1656 &lMin, &lMax, &lStepping, &lDefault, &lFlags); | |
1657 if (FAILED(hr)) | |
1658 return TVI_CONTROL_FALSE; | |
1659 if (lMin == lMax) { | |
1660 *pvalue = lMin; | |
1661 return TVI_CONTROL_TRUE; | |
1662 } | |
1663 | |
1664 hr = OLE_CALL_ARGS(priv->pVideoProcAmp, Get, control, &lValue, &lFlags); | |
1665 if (FAILED(hr)) | |
1666 return TVI_CONTROL_FALSE; | |
1667 | |
1668 *pvalue = 200 * (lValue - lMin) / (lMax - lMin) - 100; | |
1669 | |
1670 return TVI_CONTROL_TRUE; | |
1671 } | |
1672 | |
1673 /** | |
25053
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1674 * \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
|
1675 * \param fcc FourCC code for video format |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1676 * \param width picture width |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1677 * \param height pciture height |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1678 * \param fps frames per second (required for bitrate calculation) |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1679 * |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1680 * \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
|
1681 */ |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1682 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
|
1683 { |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1684 int i; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1685 AM_MEDIA_TYPE mt; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1686 VIDEOINFOHEADER vHdr; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1687 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1688 /* Check given fcc in lookup table*/ |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1689 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
|
1690 if(!img_fmt_list[i].fmt) |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1691 return NULL; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1692 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1693 memset(&mt, 0, sizeof(AM_MEDIA_TYPE)); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1694 memset(&vHdr, 0, sizeof(VIDEOINFOHEADER)); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1695 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1696 vHdr.bmiHeader.biSize = sizeof(vHdr.bmiHeader); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1697 vHdr.bmiHeader.biWidth = width; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1698 vHdr.bmiHeader.biHeight = height; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1699 //FIXME: is biPlanes required too? |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1700 //vHdr.bmiHeader.biPlanes = img_fmt_list[i].nPlanes; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1701 vHdr.bmiHeader.biBitCount = img_fmt_list[i].nBits; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1702 vHdr.bmiHeader.biCompression = img_fmt_list[i].nCompression; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1703 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
|
1704 vHdr.dwBitRate = vHdr.bmiHeader.biSizeImage * 8 * fps; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1705 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1706 mt.pbFormat = (char*)&vHdr; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1707 mt.cbFormat = sizeof(vHdr); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1708 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1709 mt.majortype = MEDIATYPE_Video; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1710 mt.subtype = *img_fmt_list[i].subtype; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1711 mt.formattype = FORMAT_VideoInfo; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1712 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1713 mt.bFixedSizeSamples = 1; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1714 mt.bTemporalCompression = 0; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1715 mt.lSampleSize = vHdr.bmiHeader.biSizeImage; |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1716 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1717 return CreateMediaType(&mt); |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1718 } |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1719 |
086c2accaaa2
Service routine for constructing AM_MEDIA_TYPE structure from
voroshil
parents:
25052
diff
changeset
|
1720 /** |
24744 | 1721 * \brief extracts fcc,width,height from AM_MEDIA_TYPE |
1722 * | |
1723 * \param pmt pointer to AM_MEDIA_TYPE to extract data from | |
1724 * \param pfcc address of variable that receives FourCC | |
1725 * \param pwidth address of variable that receives width | |
1726 * \param pheight address of variable that recevies height | |
1727 * | |
1728 * \return 1 if data extracted successfully, 0 - otherwise | |
1729 */ | |
1730 static int extract_video_format(AM_MEDIA_TYPE * pmt, int *pfcc, | |
1731 int *pwidth, int *pheight) | |
1732 { | |
1733 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: extract_video_format called\n"); | |
1734 if (!pmt) | |
1735 return 0; | |
1736 if (!pmt->pbFormat) | |
1737 return 0; | |
1738 if (memcmp(&(pmt->formattype), &FORMAT_VideoInfo, 16) != 0) | |
1739 return 0; | |
1740 if (pfcc) | |
1741 *pfcc = subtype2imgfmt(&(pmt->subtype)); | |
1742 if (pwidth) | |
1743 *pwidth = ((VIDEOINFOHEADER *) pmt->pbFormat)->bmiHeader.biWidth; | |
1744 if (pheight) | |
1745 *pheight = ((VIDEOINFOHEADER *) pmt->pbFormat)->bmiHeader.biHeight; | |
1746 return 1; | |
1747 } | |
1748 | |
1749 /** | |
1750 * \brief extracts samplerate,bits,channels from AM_MEDIA_TYPE | |
1751 * | |
1752 * \param pmt pointer to AM_MEDIA_TYPE to extract data from | |
1753 * \param pfcc address of variable that receives samplerate | |
1754 * \param pwidth address of variable that receives number of bits per sample | |
1755 * \param pheight address of variable that recevies number of channels | |
1756 * | |
1757 * \return 1 if data extracted successfully, 0 - otherwise | |
1758 */ | |
1759 static int extract_audio_format(AM_MEDIA_TYPE * pmt, int *psamplerate, | |
1760 int *pbits, int *pchannels) | |
1761 { | |
1762 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: extract_audio_format called\n"); | |
1763 if (!pmt) | |
1764 return 0; | |
1765 if (!pmt->pbFormat) | |
1766 return 0; | |
1767 if (memcmp(&(pmt->formattype), &FORMAT_WaveFormatEx, 16) != 0) | |
1768 return 0; | |
1769 if (psamplerate) | |
1770 *psamplerate = ((WAVEFORMATEX *) pmt->pbFormat)->nSamplesPerSec; | |
1771 if (pbits) | |
1772 *pbits = ((WAVEFORMATEX *) pmt->pbFormat)->wBitsPerSample; | |
1773 if (pchannels) | |
1774 *pchannels = ((WAVEFORMATEX *) pmt->pbFormat)->nChannels; | |
1775 return 1; | |
1776 } | |
1777 | |
1778 /** | |
1779 * \brief checks if AM_MEDIA_TYPE compatible with given samplerate,bits,channels | |
1780 * | |
1781 * \param pmt pointer to AM_MEDIA_TYPE for check | |
1782 * \param samplerate audio samplerate | |
1783 * \param bits bits per sample | |
1784 * \param channels number of audio channels | |
1785 * | |
1786 * \return 1 if AM_MEDIA_TYPE compatible | |
1787 * \return 0 if not | |
1788 */ | |
1789 static int check_audio_format(AM_MEDIA_TYPE * pmt, int samplerate, | |
1790 int bits, int channels) | |
1791 { | |
1792 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: check_audio_format called\n"); | |
1793 if (!pmt) | |
1794 return 0; | |
1795 if (memcmp(&(pmt->majortype), &MEDIATYPE_Audio, 16) != 0) | |
1796 return 0; | |
1797 if (memcmp(&(pmt->subtype), &MEDIASUBTYPE_PCM, 16) != 0) | |
1798 return 0; | |
1799 if (memcmp(&(pmt->formattype), &FORMAT_WaveFormatEx, 16) != 0) | |
1800 return 0; | |
1801 if (!pmt->pbFormat) | |
1802 return 0; | |
1803 if (((WAVEFORMATEX *) pmt->pbFormat)->nSamplesPerSec != samplerate) | |
1804 return 0; | |
1805 if (((WAVEFORMATEX *) pmt->pbFormat)->wBitsPerSample != bits) | |
1806 return 0; | |
1807 if (channels > 0 | |
1808 && ((WAVEFORMATEX *) pmt->pbFormat)->nChannels != channels) | |
1809 return 0; | |
1810 | |
1811 return 1; | |
1812 } | |
1813 | |
1814 /** | |
1815 * \brief checks if AM_MEDIA_TYPE compatible with given fcc,width,height | |
1816 * | |
1817 * \param pmt pointer to AM_MEDIA_TYPE for check | |
1818 * \param fcc FourCC (compression) | |
1819 * \param width width of picture | |
1820 * \param height height of picture | |
1821 * | |
1822 * \return 1 if AM_MEDIA_TYPE compatible | |
1823 & \return 0 if not | |
1824 * | |
1825 * \note | |
1826 * width and height are currently not used | |
1827 * | |
1828 * \todo | |
1829 * add width/height check | |
1830 */ | |
1831 static int check_video_format(AM_MEDIA_TYPE * pmt, int fcc, int width, | |
1832 int height) | |
1833 { | |
1834 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: check_video_format called\n"); | |
1835 if (!pmt) | |
1836 return 0; | |
1837 if (memcmp(&(pmt->majortype), &MEDIATYPE_Video, 16) != 0) | |
1838 return 0; | |
1839 if (subtype2imgfmt(&(pmt->subtype)) != fcc) | |
1840 return 0; | |
1841 return 1; | |
1842 } | |
1843 | |
1844 /** | |
1845 * \brief converts DirectShow subtype to MPlayer's IMGFMT | |
1846 * | |
1847 * \param subtype DirectShow subtype for video format | |
1848 * | |
1849 * \return MPlayer's IMGFMT or 0 if error occured | |
1850 */ | |
1851 static int subtype2imgfmt(const GUID * subtype) | |
1852 { | |
1853 int i; | |
1854 for (i = 0; img_fmt_list[i].fmt; i++) { | |
1855 if (memcmp(subtype, img_fmt_list[i].subtype, 16) == 0) | |
1856 return img_fmt_list[i].fmt; | |
1857 } | |
1858 return 0; | |
1859 } | |
1860 | |
1861 /** | |
1862 * \brief prints filter name and it pins | |
1863 * | |
1864 * \param pFilter - IBaseFilter to get data from | |
1865 * | |
1866 * \return S_OK if success, error code otherwise | |
1867 */ | |
1868 static HRESULT show_filter_info(IBaseFilter * pFilter) | |
1869 { | |
1870 char tmp[200]; | |
1871 FILTER_INFO fi; | |
1872 LPENUMPINS pEnum = 0; | |
1873 IPin *pPin = 0; | |
1874 PIN_DIRECTION ThisPinDir; | |
1875 PIN_INFO pi; | |
1876 HRESULT hr; | |
1877 int i; | |
1878 | |
1879 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: show_filter_info called\n"); | |
1880 memset(&fi, 0, sizeof(fi)); | |
1881 memset(tmp, 0, 200); | |
1882 | |
1883 OLE_CALL_ARGS(pFilter, QueryFilterInfo, &fi); | |
1884 OLE_RELEASE_SAFE(fi.pGraph); | |
1885 wtoa(fi.achName, tmp, 200); | |
1886 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: BaseFilter (%p): Name=%s, Graph=%p output pins:", | |
1887 pFilter, tmp, fi.pGraph); | |
1888 hr = OLE_CALL_ARGS(pFilter, EnumPins, &pEnum); | |
1889 if (FAILED(hr)) | |
1890 return hr; | |
1891 i = 0; | |
1892 while (OLE_CALL_ARGS(pEnum, Next, 1, &pPin, NULL) == S_OK) { | |
1893 memset(&pi, 0, sizeof(pi)); | |
1894 memset(tmp, 0, 200); | |
1895 OLE_CALL_ARGS(pPin, QueryDirection, &ThisPinDir); | |
1896 if (ThisPinDir == PINDIR_OUTPUT) { | |
1897 OLE_CALL_ARGS(pPin, QueryPinInfo, &pi); | |
1898 wtoa(pi.achName, tmp, 200); | |
1899 OLE_RELEASE_SAFE(pi.pFilter); | |
1900 mp_msg(MSGT_TV, MSGL_DBG2, " %d=%s", i, tmp); | |
1901 mp_msg(MSGT_TV, MSGL_DBG3, " (%p)", pPin); | |
1902 mp_msg(MSGT_TV, MSGL_DBG2, ";"); | |
1903 OLE_RELEASE_SAFE(pPin); | |
1904 i++; | |
1905 } | |
1906 } | |
1907 mp_msg(MSGT_TV, MSGL_DBG2, "\n"); | |
1908 OLE_RELEASE_SAFE(pEnum); | |
1909 return S_OK; | |
1910 } | |
1911 | |
1912 /** | |
1913 * \brief gets device's frendly in ANSI encoding | |
1914 * | |
1915 * \param pM IMoniker interface, got in enumeration process | |
1916 * \param category device category | |
1917 * | |
1918 * \return TVI_CONTROL_TRUE if operation succeded, TVI_CONTROL_FALSE - otherwise | |
1919 */ | |
1920 static int get_device_name(IMoniker * pM, char *pBuf, int nLen) | |
1921 { | |
1922 HRESULT hr; | |
1923 VARIANT var; | |
1924 IPropertyBag *pPropBag; | |
1925 hr = OLE_CALL_ARGS(pM, BindToStorage, 0, 0, &IID_IPropertyBag,(void *) &pPropBag); | |
1926 if (FAILED(hr)) { | |
1927 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Call to BindToStorage failed\n"); | |
1928 return TVI_CONTROL_FALSE; | |
1929 } | |
1930 var.vt = VT_BSTR; | |
1931 hr = OLE_CALL_ARGS(pPropBag, Read, L"Description", (LPVARIANT) & var, | |
1932 NULL); | |
1933 if (FAILED(hr)) { | |
1934 hr = OLE_CALL_ARGS(pPropBag, Read, L"FriendlyName", (LPVARIANT) & var, | |
1935 NULL); | |
1936 } | |
1937 OLE_RELEASE_SAFE(pPropBag); | |
1938 if (SUCCEEDED(hr)) { | |
1939 wtoa(var.bstrVal, pBuf, nLen); | |
1940 return TVI_CONTROL_TRUE; | |
1941 } | |
1942 return TVI_CONTROL_FALSE; | |
1943 } | |
1944 | |
1945 /** | |
1946 * \brief find capture device at given index | |
1947 * | |
1948 * \param index device index to search for (-1 mean only print available) | |
1949 * \param category device category | |
1950 * | |
1951 * \return IBaseFilter interface for capture device with given index | |
1952 * | |
1953 * Sample values for category: | |
1954 * CLSID_VideoInputDeviceCategory - Video Capture Sources | |
1955 * CLSID_AudioInputDeviceCategory - Audio Capture Sources | |
1956 * See DirectShow SDK documentation for other possible values | |
1957 */ | |
1958 static IBaseFilter *find_capture_device(int index, REFCLSID category) | |
1959 { | |
1960 IBaseFilter *pFilter = NULL; | |
1961 ICreateDevEnum *pDevEnum = NULL; | |
1962 IEnumMoniker *pClassEnum = NULL; | |
1963 IMoniker *pM; | |
1964 HRESULT hr; | |
1965 ULONG cFetched; | |
1966 int i; | |
1967 char tmp[DEVICE_NAME_MAX_LEN + 1]; | |
1968 hr = CoCreateInstance((GUID *) & CLSID_SystemDeviceEnum, NULL, | |
1969 CLSCTX_INPROC_SERVER, &IID_ICreateDevEnum, | |
1970 (void *) &pDevEnum); | |
1971 if (FAILED(hr)) { | |
1972 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to create device enumerator\n"); | |
1973 return NULL; | |
1974 } | |
1975 | |
1976 hr = OLE_CALL_ARGS(pDevEnum, CreateClassEnumerator, category, &pClassEnum, 0); | |
1977 OLE_RELEASE_SAFE(pDevEnum); | |
1978 if (FAILED(hr)) { | |
1979 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to create class enumerator\n"); | |
1980 return NULL; | |
1981 } | |
1982 if (hr == S_FALSE) { | |
1983 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: No capture devices found\n"); | |
1984 return NULL; | |
1985 } | |
1986 | |
1987 OLE_CALL(pClassEnum,Reset); | |
1988 for (i = 0; OLE_CALL_ARGS(pClassEnum, Next, 1, &pM, &cFetched) == S_OK; i++) { | |
1989 if(get_device_name(pM, tmp, DEVICE_NAME_MAX_LEN)!=TVI_CONTROL_TRUE) | |
1990 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableGetDeviceName, i); | |
1991 else | |
1992 mp_msg(MSGT_TV, MSGL_V, MSGTR_TVI_DS_DeviceName, i, tmp); | |
1993 if (index != -1 && i == index) { | |
1994 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_UsingDevice, index, tmp); | |
1995 hr = OLE_CALL_ARGS(pM, BindToObject, 0, 0, &IID_IBaseFilter,(void *) &pFilter); | |
1996 if (FAILED(hr)) | |
1997 pFilter = NULL; | |
1998 } | |
1999 OLE_RELEASE_SAFE(pM); | |
2000 } | |
2001 if (index != -1 && !pFilter) { | |
2002 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_DeviceNotFound, | |
2003 index); | |
2004 } | |
2005 OLE_RELEASE_SAFE(pClassEnum); | |
2006 | |
2007 return pFilter; | |
2008 } | |
2009 | |
2010 /** | |
2011 * \brief get array of available formats through call to IAMStreamConfig::GetStreamCaps | |
2012 * | |
2013 * \param[in] pVideoStreamConfig IAMStreamConfig of used capture device's output pin | |
2014 * \param[in] pMediaType MEDIATYPE_Video or MEDIATYPE_Audio | |
2015 * \param[out] parpmtMedia address of variable that receives pointer to array of AM_MEDIA_TYPE structures | |
2016 * \param[out] parCaps address of variable thar receives pointer to array of VIDEOSTREAM_CONFIG_CAPS or AUDIO_STREAM_CONFIG_CAPS | |
2017 * | |
2018 * \return S_OK success | |
2019 * \return E_POINTER one of parameters is NULL | |
2020 * \return E_FAIL required size of buffer is unknown for given media type | |
2021 * \return E_OUTOFMEMORY not enough memory | |
2022 * \return other error code from called methods | |
2023 * | |
2024 * \remarks | |
2025 * last item or returned arrays will be NULL | |
2026 */ | |
2027 static HRESULT get_available_formats_stream(IAMStreamConfig * | |
2028 pStreamConfig, | |
2029 const GUID * pMediaType, | |
2030 AM_MEDIA_TYPE *** parpmtMedia, | |
2031 void ***parCaps) | |
2032 { | |
2033 AM_MEDIA_TYPE **arpmt; | |
2034 void **pBuf=NULL; | |
2035 | |
2036 HRESULT hr; | |
2037 int i, count, size; | |
2038 int done; | |
2039 | |
2040 mp_msg(MSGT_TV, MSGL_DBG4, | |
2041 "tvi_dshow: get_available_formats_stream called\n"); | |
2042 | |
2043 if (!pStreamConfig || !pMediaType || !parpmtMedia || !parCaps) | |
2044 return E_POINTER; | |
2045 | |
2046 hr=OLE_CALL_ARGS(pStreamConfig, GetNumberOfCapabilities, &count, &size); | |
2047 if (FAILED(hr)) { | |
2048 mp_msg(MSGT_TV, MSGL_DBG4, | |
2049 "tvi_dshow: Call to GetNumberOfCapabilities failed (get_available_formats_stream)\n"); | |
2050 return hr; | |
2051 } | |
2052 if (memcmp(pMediaType, &MEDIATYPE_Video, 16) == 0){ | |
2053 if (size != sizeof(VIDEO_STREAM_CONFIG_CAPS)) { | |
2054 mp_msg(MSGT_TV, MSGL_DBG4, | |
2055 "tvi_dshow: Wrong video structure size for GetNumberOfCapabilities (get_available_formats_stream)\n"); | |
2056 return E_FAIL; | |
2057 } else if (memcmp(pMediaType, &MEDIATYPE_Audio, 16) == 0){ | |
2058 if (size != sizeof(AUDIO_STREAM_CONFIG_CAPS)) { | |
2059 mp_msg(MSGT_TV, MSGL_DBG4, | |
2060 "tvi_dshow: Wrong audio structure size for GetNumberOfCapabilities (get_available_formats_stream)\n"); | |
2061 return E_FAIL; | |
2062 } else { | |
2063 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnsupportedMediaType,"get_available_formats_stream"); | |
2064 return E_FAIL; | |
2065 } | |
2066 } | |
2067 } | |
2068 done = 0; | |
2069 | |
2070 arpmt = (AM_MEDIA_TYPE **) malloc((count + 1) * sizeof(AM_MEDIA_TYPE *)); | |
2071 if (arpmt) { | |
2072 memset(arpmt, 0, (count + 1) * sizeof(AM_MEDIA_TYPE *)); | |
2073 | |
2074 pBuf = (void **) malloc((count + 1) * sizeof(void *)); | |
2075 if (pBuf) { | |
25061
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2076 int dst = 0; |
24744 | 2077 memset(pBuf, 0, (count + 1) * sizeof(void *)); |
2078 | |
2079 for (i = 0; i < count; i++) { | |
25061
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2080 pBuf[dst] = malloc(size); |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2081 |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2082 if (!pBuf[dst]) |
24744 | 2083 break; |
2084 | |
2085 hr = OLE_CALL_ARGS(pStreamConfig, GetStreamCaps, i, | |
25061
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2086 &(arpmt[dst]), pBuf[dst]); |
24744 | 2087 if (FAILED(hr)) |
2088 break; | |
25061
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2089 if(!memcmp(&(arpmt[dst]->majortype), &MEDIATYPE_Video, 16) && !subtype2imgfmt(&(arpmt[dst]->subtype))) |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2090 { |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2091 DisplayMediaType("Skipping unsupported video format", arpmt[dst]); |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2092 DeleteMediaType(arpmt[dst]); |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2093 free(pBuf[dst]); |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2094 arpmt[dst]=NULL; |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2095 pBuf[dst]=NULL; |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2096 continue; |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2097 } |
1f0eb7aa3206
Ignore video formats which are supported by device
voroshil
parents:
25060
diff
changeset
|
2098 dst++; |
24744 | 2099 } |
2100 if (i == count) { | |
2101 *parpmtMedia = arpmt; | |
2102 *parCaps = pBuf; | |
2103 done = 1; | |
2104 } | |
2105 } | |
2106 } | |
2107 if (!done) { | |
2108 for (i = 0; i < count; i++) { | |
2109 if (pBuf && pBuf[i]) | |
2110 free(pBuf[i]); | |
2111 if (arpmt && arpmt[i]) | |
2112 DeleteMediaType(arpmt[i]); | |
2113 } | |
2114 if (pBuf) | |
2115 free(pBuf); | |
2116 if (arpmt) | |
2117 free(arpmt); | |
2118 if (hr != S_OK) { | |
2119 mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: Call to GetStreamCaps failed (get_available_formats_stream)\n"); | |
2120 return hr; | |
2121 } else | |
2122 return E_OUTOFMEMORY; | |
2123 } | |
2124 return S_OK; | |
2125 } | |
2126 | |
2127 /** | |
2128 * \brief returns allocates an array and store available media formats for given pin type to it | |
2129 * | |
2130 * \param pBuilder ICaptureGraphBuilder2 interface of graph builder | |
2131 * \param pFilter IBaseFilter interface of capture device | |
2132 * \param pMediaType media type for search (MEDIATYPE_Video or MEDIATYPE_Audio) | |
2133 * \param[out] parpmtMediaType address of variable that receives pointer to array | |
2134 * | |
2135 * \return S_OK success | |
2136 * \return E_POINTER one of given pointers is null | |
2137 * \return apropriate error code otherwise | |
2138 */ | |
2139 static HRESULT get_available_formats_pin(ICaptureGraphBuilder2 * pBuilder, | |
2140 IBaseFilter * pFilter, | |
2141 const GUID * pMediaType, | |
2142 AM_MEDIA_TYPE *** parpmtMedia, | |
2143 void ***parCaps) | |
2144 { | |
2145 IEnumMediaTypes *pEnum; | |
2146 IPin *pPin; | |
2147 int i, count, size; | |
2148 ULONG cFetched; | |
2149 AM_MEDIA_TYPE *pmt; | |
2150 HRESULT hr; | |
2151 void **pBuf; | |
2152 AM_MEDIA_TYPE **arpmt; //This will be real array | |
2153 int isvideo; | |
2154 VIDEO_STREAM_CONFIG_CAPS *pVideoCaps; | |
2155 AUDIO_STREAM_CONFIG_CAPS *pAudioCaps; | |
2156 int p1, p2, p3; | |
2157 | |
2158 mp_msg(MSGT_TV, MSGL_DBG4, | |
2159 "tvi_dshow: get_available_formats_pin called\n"); | |
2160 if (!pBuilder || !pFilter || !pMediaType || !parpmtMedia) | |
2161 return E_POINTER; | |
2162 | |
2163 hr = OLE_CALL_ARGS(pBuilder, FindPin, (IUnknown *) pFilter, | |
2164 PINDIR_OUTPUT, NULL, pMediaType, FALSE, 0, &pPin); | |
2165 if (FAILED(hr)) { | |
2166 mp_msg(MSGT_TV, MSGL_DBG4, | |
2167 "tvi_dshow: Call to FindPin failed (get_available_formats_pin)\n"); | |
2168 return hr; | |
2169 } | |
2170 if (memcmp(pMediaType, &MEDIATYPE_Video, 16) == 0) { | |
2171 isvideo = 1; | |
2172 size = sizeof(VIDEO_STREAM_CONFIG_CAPS); | |
2173 } else if (memcmp(pMediaType, &MEDIATYPE_Audio, 16) == 0) { | |
2174 isvideo = 0; | |
2175 size = sizeof(AUDIO_STREAM_CONFIG_CAPS); | |
2176 } else { | |
2177 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnsupportedMediaType,"get_available_formats_pin"); | |
2178 return E_FAIL; | |
2179 } | |
2180 | |
2181 hr = OLE_CALL_ARGS(pPin, EnumMediaTypes, &pEnum); | |
2182 OLE_RELEASE_SAFE(pPin); | |
2183 if (FAILED(hr)) { | |
2184 mp_msg(MSGT_TV, MSGL_DBG4, | |
2185 "tvi_dshow: Call to EnumMediaTypes failed (get_available_formats_pin)\n"); | |
2186 return hr; | |
2187 } | |
2188 for (i = 0; OLE_CALL_ARGS(pEnum, Next, 1, &pmt, &cFetched) == S_OK; i++) { | |
2189 if (!pmt) | |
2190 break; | |
2191 } | |
2192 OLE_CALL(pEnum,Reset); | |
2193 | |
2194 count = i; | |
2195 arpmt = | |
2196 (AM_MEDIA_TYPE **) malloc((count + 1) * sizeof(AM_MEDIA_TYPE *)); | |
2197 if (!arpmt) | |
2198 return E_OUTOFMEMORY; | |
2199 memset(arpmt, 0, (count + 1) * sizeof(AM_MEDIA_TYPE *)); | |
2200 | |
2201 for (i = 0; | |
2202 i < count | |
2203 && OLE_CALL_ARGS(pEnum, Next, 1, &(arpmt[i]), &cFetched) == S_OK; | |
2204 i++); | |
2205 | |
2206 OLE_RELEASE_SAFE(pEnum); | |
2207 | |
2208 | |
2209 pBuf = (void **) malloc((count + 1) * sizeof(void *)); | |
2210 if (!pBuf) { | |
2211 for (i = 0; i < count; i++) | |
2212 if (arpmt[i]) | |
2213 DeleteMediaType(arpmt[i]); | |
2214 free(arpmt); | |
2215 return E_OUTOFMEMORY; | |
2216 } | |
2217 memset(pBuf, 0, (count + 1) * sizeof(void *)); | |
2218 | |
2219 for (i = 0; i < count; i++) { | |
2220 pBuf[i] = malloc(size); | |
2221 if (!pBuf[i]) | |
2222 break; | |
2223 memset(pBuf[i], 0, size); | |
2224 | |
2225 if (isvideo) { | |
2226 pVideoCaps = (VIDEO_STREAM_CONFIG_CAPS *) pBuf[i]; | |
2227 extract_video_format(arpmt[i], NULL, &p1, &p2); | |
2228 pVideoCaps->MaxOutputSize.cx = pVideoCaps->MinOutputSize.cx = | |
2229 p1; | |
2230 pVideoCaps->MaxOutputSize.cy = pVideoCaps->MinOutputSize.cy = | |
2231 p2; | |
2232 } else { | |
2233 pAudioCaps = (AUDIO_STREAM_CONFIG_CAPS *) pBuf[i]; | |
2234 extract_audio_format(arpmt[i], &p1, &p2, &p3); | |
2235 pAudioCaps->MaximumSampleFrequency = | |
2236 pAudioCaps->MinimumSampleFrequency = p1; | |
2237 pAudioCaps->MaximumBitsPerSample = | |
2238 pAudioCaps->MinimumBitsPerSample = p2; | |
2239 pAudioCaps->MaximumChannels = pAudioCaps->MinimumChannels = p3; | |
2240 } | |
2241 | |
2242 } | |
2243 if (i != count) { | |
2244 for (i = 0; i < count; i++) { | |
2245 if (arpmt[i]) | |
2246 DeleteMediaType(arpmt[i]); | |
2247 if (pBuf[i]) | |
2248 free(pBuf[i]); | |
2249 } | |
2250 free(arpmt); | |
2251 free(pBuf); | |
2252 return E_OUTOFMEMORY; | |
2253 } | |
2254 *parpmtMedia = arpmt; | |
2255 *parCaps = pBuf; | |
2256 | |
2257 return S_OK; | |
2258 } | |
2259 | |
2260 /* | |
2261 *--------------------------------------------------------------------------------------- | |
2262 * | |
2263 * Public methods | |
2264 * | |
2265 *--------------------------------------------------------------------------------------- | |
2266 */ | |
2267 /** | |
2268 * \brief fills given buffer with audio data (usually one block) | |
2269 * | |
2270 * \param priv driver's private data structure | |
2271 * \param buffer buffer to store data to | |
2272 * \param len buffer's size in bytes (usually one block size) | |
2273 * | |
2274 * \return audio pts if audio present, 1 - otherwise | |
2275 */ | |
2276 static double grab_audio_frame(priv_t * priv, char *buffer, int len) | |
2277 { | |
2278 int bytes = 0; | |
2279 int i; | |
2280 double pts; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2281 grabber_ringbuffer_t *rb = priv->chains[1]->rbuf; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2282 grabber_ringbuffer_t *vrb = priv->chains[0]->rbuf; |
24744 | 2283 |
2284 if (!rb || !rb->ringbuffer) | |
2285 return 1; | |
2286 | |
2287 if(vrb && vrb->tStart<0){ | |
2288 memset(buffer,0,len); | |
2289 return 0; | |
2290 } | |
2291 if(vrb && rb->tStart<0) | |
2292 rb->tStart=vrb->tStart; | |
2293 | |
2294 if (len < rb->blocksize) | |
2295 bytes = len; | |
2296 else | |
2297 bytes = rb->blocksize; | |
2298 | |
2299 mp_msg(MSGT_TV, MSGL_DBG3,"tvi_dshow: FillBuffer (audio) called. %d blocks in buffer, %d bytes requested\n", | |
2300 rb->count, len); | |
2301 if(!rb->count){ | |
2302 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting for frame\n"); | |
2303 for(i=0;i<1000 && !rb->count;i++) usec_sleep(1000); | |
2304 if(!rb->count){ | |
2305 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting timeout\n"); | |
2306 return 0; | |
2307 } | |
2308 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: got frame!\n"); | |
2309 } | |
2310 | |
2311 EnterCriticalSection(rb->pMutex); | |
2312 pts=rb->dpts[rb->head]-rb->tStart; | |
2313 memcpy(buffer, rb->ringbuffer[rb->head], bytes); | |
2314 rb->head = (rb->head + 1) % rb->buffersize; | |
2315 rb->count--; | |
2316 LeaveCriticalSection(rb->pMutex); | |
2317 return pts; | |
2318 } | |
2319 | |
2320 /** | |
2321 * \brief returns audio frame size | |
2322 * | |
2323 * \param priv driver's private data structure | |
2324 * | |
2325 * \return audio block size if audio enabled and 1 - otherwise | |
2326 */ | |
2327 static int get_audio_framesize(priv_t * priv) | |
2328 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2329 if (!priv->chains[1]->rbuf) |
24744 | 2330 return 1; //no audio |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2331 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
|
2332 return priv->chains[1]->rbuf->blocksize; |
24744 | 2333 } |
2334 | |
2335 #ifdef HAVE_TV_TELETEXT | |
2336 static int vbi_get_props(priv_t* priv,tt_stream_props* ptsp) | |
2337 { | |
2338 if(!priv || !ptsp) | |
2339 return TVI_CONTROL_FALSE; | |
2340 | |
2341 //STUBS!!! | |
2342 ptsp->interlaced=0; | |
2343 ptsp->offset=256; | |
2344 | |
2345 ptsp->sampling_rate=27e6; | |
2346 ptsp->samples_per_line=720; | |
2347 | |
2348 ptsp->count[0]=16; | |
2349 ptsp->count[1]=16; | |
2350 //END STUBS!!! | |
2351 ptsp->bufsize = ptsp->samples_per_line * (ptsp->count[0] + ptsp->count[1]); | |
2352 | |
2353 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", | |
2354 ptsp->sampling_rate, | |
2355 ptsp->offset, | |
2356 ptsp->samples_per_line, | |
2357 ptsp->interlaced?"Yes":"No", | |
2358 ptsp->count[0], | |
2359 ptsp->count[1]); | |
2360 | |
2361 return TVI_CONTROL_TRUE; | |
2362 } | |
2363 | |
2364 static void vbi_grabber(priv_t* priv) | |
2365 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2366 grabber_ringbuffer_t *rb = priv->chains[2]->rbuf; |
24744 | 2367 int i; |
2368 unsigned char* buf; | |
2369 if (!rb || !rb->ringbuffer) | |
2370 return; | |
2371 | |
2372 buf=calloc(1,rb->blocksize); | |
2373 for(i=0; i<23 && rb->count; i++){ | |
2374 memcpy(buf,rb->ringbuffer[rb->head],rb->blocksize); | |
2375 teletext_control(priv->priv_vbi,TV_VBI_CONTROL_DECODE_PAGE,&buf); | |
2376 rb->head = (rb->head + 1) % rb->buffersize; | |
2377 rb->count--; | |
2378 } | |
2379 free(buf); | |
2380 } | |
2381 #endif //HAVE_TV_TELETEXT | |
2382 | |
2383 /** | |
2384 * \brief fills given buffer with video data (usually one frame) | |
2385 * | |
2386 * \param priv driver's private data structure | |
2387 * \param buffer buffer to store data to | |
2388 * \param len buffer's size in bytes (usually one frame size) | |
2389 * | |
2390 * \return frame size if video present, 0 - otherwise | |
2391 */ | |
2392 static double grab_video_frame(priv_t * priv, char *buffer, int len) | |
2393 { | |
2394 int bytes = 0; | |
2395 int i; | |
2396 double pts; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2397 grabber_ringbuffer_t *rb = priv->chains[0]->rbuf; |
24744 | 2398 |
2399 if (!rb || !rb->ringbuffer) | |
2400 return 1; | |
2401 if (len < rb->blocksize) | |
2402 bytes = len; | |
2403 else | |
2404 bytes = rb->blocksize; | |
2405 | |
2406 mp_msg(MSGT_TV, MSGL_DBG3,"tvi_dshow: FillBuffer (video) called. %d blocks in buffer, %d bytes requested\n", | |
2407 rb->count, len); | |
2408 if(!rb->count){ | |
2409 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting for frame\n"); | |
2410 for(i=0;i<1000 && !rb->count;i++) usec_sleep(1000); | |
2411 if(!rb->count){ | |
2412 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: waiting timeout\n"); | |
2413 return 0; | |
2414 } | |
2415 mp_msg(MSGT_TV,MSGL_DBG4,"tvi_dshow: got frame!\n"); | |
2416 } | |
2417 EnterCriticalSection(rb->pMutex); | |
2418 if(rb->tStart<0) | |
2419 rb->tStart=rb->dpts[rb->head]; | |
2420 pts=rb->dpts[rb->head]-rb->tStart; | |
2421 memcpy(buffer, rb->ringbuffer[rb->head], bytes); | |
2422 rb->head = (rb->head + 1) % rb->buffersize; | |
2423 rb->count--; | |
2424 LeaveCriticalSection(rb->pMutex); | |
2425 | |
2426 #ifdef HAVE_TV_TELETEXT | |
2427 vbi_grabber(priv); | |
2428 #endif | |
2429 return pts; | |
2430 } | |
2431 | |
2432 /** | |
2433 * \brief returns frame size | |
2434 * | |
2435 * \param priv driver's private data structure | |
2436 * | |
2437 * \return frame size if video present, 0 - otherwise | |
2438 */ | |
2439 static int get_video_framesize(priv_t * priv) | |
2440 { | |
2441 // if(!priv->pmtVideo) return 1; //no video | |
2442 // return(priv->pmtVideo->lSampleSize); | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2443 if (!priv->chains[0]->rbuf) |
24744 | 2444 return 1; //no video |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2445 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
|
2446 return priv->chains[0]->rbuf->blocksize; |
24744 | 2447 } |
2448 | |
2449 /** | |
2450 * \brief calculate audio buffer size | |
2451 * \param video_buf_size size of video buffer in bytes | |
2452 * \param video_bitrate video bit rate | |
2453 * \param audio_bitrate audio bit rate | |
2454 * \return audio buffer isze in bytes | |
2455 * | |
2456 * \remarks length of video buffer and resulted audio buffer calculated in | |
2457 * seconds will be the same. | |
2458 */ | |
2459 static inline int audio_buf_size_from_video(int video_buf_size, int video_bitrate, int audio_bitrate) | |
2460 { | |
2461 int audio_buf_size = audio_bitrate * (video_buf_size / video_bitrate); | |
2462 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: Audio capture buffer: %d * %d / %d = %d\n", | |
2463 audio_bitrate,video_buf_size,video_bitrate,audio_buf_size); | |
2464 return audio_buf_size; | |
2465 } | |
2466 | |
2467 /** | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2468 * \brief build video stream chain in graph |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2469 * \param priv private data structure |
24744 | 2470 * |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2471 * \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
|
2472 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2473 static HRESULT build_video_chain(priv_t *priv) |
24744 | 2474 { |
2475 HRESULT hr; | |
2476 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2477 if(priv->chains[0]->rbuf) |
25059 | 2478 return S_OK; |
2479 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2480 if (priv->chains[0]->pStreamConfig) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2481 hr = OLE_CALL_ARGS(priv->chains[0]->pStreamConfig, SetFormat, priv->chains[0]->pmt); |
24744 | 2482 if (FAILED(hr)) { |
2483 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableSelectVideoFormat, (unsigned int)hr); | |
2484 } | |
2485 } | |
2486 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2487 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
|
2488 if(!priv->chains[0]->rbuf) |
25058 | 2489 return E_OUTOFMEMORY; |
24744 | 2490 |
2491 if (priv->tv_param->buffer_size >= 0) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2492 priv->chains[0]->rbuf->buffersize = priv->tv_param->buffer_size; |
24744 | 2493 } else { |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2494 priv->chains[0]->rbuf->buffersize = 16; |
24744 | 2495 } |
2496 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2497 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
|
2498 hr=build_sub_graph(priv, priv->chains[0], &PIN_CATEGORY_CAPTURE); |
24744 | 2499 if(FAILED(hr)){ |
2500 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
|
2501 return hr; |
24744 | 2502 } |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2503 return S_OK; |
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 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2506 /** |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2507 * \brief build audio stream chain in graph |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2508 * \param priv private data structure |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2509 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2510 * \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
|
2511 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2512 static HRESULT build_audio_chain(priv_t *priv) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2513 { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2514 HRESULT hr; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2515 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2516 if(priv->chains[1]->rbuf) |
25059 | 2517 return S_OK; |
2518 | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2519 if(priv->immediate_mode) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2520 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2521 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2522 if (priv->chains[1]->pStreamConfig) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2523 hr = OLE_CALL_ARGS(priv->chains[1]->pStreamConfig, SetFormat, |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2524 priv->chains[1]->pmt); |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2525 if (FAILED(hr)) { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2526 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
|
2527 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2528 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2529 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2530 if(priv->chains[1]->pmt){ |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2531 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
|
2532 if(!priv->chains[1]->rbuf) |
25058 | 2533 return E_OUTOFMEMORY; |
24744 | 2534 |
2535 /* 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
|
2536 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
|
2537 priv->chains[0]->rbuf->buffersize, |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2538 (((VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat)->dwBitRate), |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2539 (((WAVEFORMATEX *) (priv->chains[1]->pmt->pbFormat))->nAvgBytesPerSec)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2540 |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
2541 hr=build_sub_graph(priv, priv->chains[1],&PIN_CATEGORY_CAPTURE); |
24744 | 2542 if(FAILED(hr)){ |
2543 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildAudioSubGraph,(unsigned int)hr); | |
2544 return 0; | |
2545 } | |
2546 } | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2547 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2548 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2549 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2550 /** |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2551 * \brief build VBI stream chain in graph |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2552 * \param priv private data structure |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2553 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2554 * \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
|
2555 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2556 static HRESULT build_vbi_chain(priv_t *priv) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2557 { |
24744 | 2558 #ifdef HAVE_TV_TELETEXT |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2559 HRESULT hr; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2560 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2561 if(priv->chains[2]->rbuf) |
25059 | 2562 return S_OK; |
2563 | |
24744 | 2564 if(priv->tv_param->tdevice) |
2565 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2566 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
|
2567 if(!priv->chains[2]->rbuf) |
25058 | 2568 return E_OUTOFMEMORY; |
2569 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2570 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
|
2571 |
25084
f72ebba1e6d1
pass chain structure instead of several variables to build_sub_graph
voroshil
parents:
25083
diff
changeset
|
2572 hr=build_sub_graph(priv, priv->chains[2],&PIN_CATEGORY_VBI); |
24744 | 2573 if(FAILED(hr)){ |
2574 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVBISubGraph,(unsigned int)hr); | |
2575 return 0; | |
2576 } | |
2577 } | |
2578 #endif | |
25057
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2579 return S_OK; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2580 } |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2581 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2582 /** |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2583 * \brief playback/capture real start |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2584 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2585 * \param priv driver's private data structure |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2586 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2587 * \return 1 if success, 0 - otherwise |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2588 * |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2589 * TODO: move some code from init() here |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2590 */ |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2591 static int start(priv_t * priv) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2592 { |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2593 HRESULT hr; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2594 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2595 hr = build_video_chain(priv); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2596 if(FAILED(hr)) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2597 return 0; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2598 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2599 hr = build_audio_chain(priv); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2600 if(FAILED(hr)) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2601 return 0; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2602 |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2603 hr = build_vbi_chain(priv); |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2604 if(FAILED(hr)) |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2605 return 0; |
7d74c1a2c840
Move chains building code into separate routines.
voroshil
parents:
25054
diff
changeset
|
2606 |
24744 | 2607 /* |
2608 Graph is ready to capture. Starting graph. | |
2609 */ | |
2610 if (mp_msg_test(MSGT_TV, MSGL_DBG2)) { | |
2611 mp_msg(MSGT_TV, MSGL_DBG2, "Debug pause 10sec\n"); | |
2612 usec_sleep(10000000); | |
2613 mp_msg(MSGT_TV, MSGL_DBG2, "Debug pause end\n"); | |
2614 } | |
2615 if (!priv->pMediaControl) { | |
2616 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableGetMediaControlInterface,(unsigned int)E_POINTER); | |
2617 return 0; | |
2618 } | |
2619 hr = OLE_CALL(priv->pMediaControl, Run); | |
2620 if (FAILED(hr)) { | |
2621 mp_msg(MSGT_TV,MSGL_ERR,MSGTR_TVI_DS_UnableStartGraph, (unsigned int)hr); | |
2622 return 0; | |
2623 } | |
2624 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Graph is started.\n"); | |
2625 priv->state = 1; | |
2626 | |
2627 return (1); | |
2628 } | |
2629 | |
2630 /** | |
2631 * \brief driver initialization | |
2632 * | |
2633 * \param priv driver's private data structure | |
2634 * | |
2635 * \return 1 if success, 0 - otherwise | |
2636 */ | |
2637 static int init(priv_t * priv) | |
2638 { | |
2639 HRESULT hr; | |
2640 int result = 0; | |
2641 long lInput, lTunerInput; | |
2642 IEnumFilters *pEnum; | |
2643 IBaseFilter *pFilter; | |
2644 IPin *pVPOutPin; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2645 int i; |
24744 | 2646 |
2647 priv->state=0; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2648 |
24744 | 2649 CoInitialize(NULL); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2650 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2651 for(i=0; i<3;i++) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2652 priv->chains[i] = calloc(1, sizeof(chain_t)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2653 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2654 priv->chains[0]->type=video; |
25080 | 2655 priv->chains[0]->majortype=&MEDIATYPE_Video; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2656 priv->chains[1]->type=audio; |
25080 | 2657 priv->chains[1]->majortype=&MEDIATYPE_Audio; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2658 priv->chains[2]->type=vbi; |
25080 | 2659 priv->chains[2]->majortype=&MEDIATYPE_VBI; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2660 |
24744 | 2661 do{ |
2662 hr = CoCreateInstance((GUID *) & CLSID_FilterGraph, NULL, | |
2663 CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, | |
2664 (void **) &priv->pGraph); | |
2665 if(FAILED(hr)){ | |
2666 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CoCreateInstance(FilterGraph) call failed. Error:0x%x\n", (unsigned int)hr); | |
2667 break; | |
2668 } | |
2669 //Debug | |
2670 if (mp_msg_test(MSGT_TV, MSGL_DBG2)) { | |
2671 AddToRot((IUnknown *) priv->pGraph, &(priv->dwRegister)); | |
2672 } | |
2673 | |
2674 hr = CoCreateInstance((GUID *) & CLSID_CaptureGraphBuilder2, NULL, | |
2675 CLSCTX_INPROC_SERVER, &IID_ICaptureGraphBuilder2, | |
2676 (void **) &priv->pBuilder); | |
2677 if(FAILED(hr)){ | |
2678 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CoCreateInstance(CaptureGraphBuilder) call failed. Error:0x%x\n", (unsigned int)hr); | |
2679 break; | |
2680 } | |
2681 | |
2682 hr = OLE_CALL_ARGS(priv->pBuilder, SetFiltergraph, priv->pGraph); | |
2683 if(FAILED(hr)){ | |
2684 mp_msg(MSGT_TV,MSGL_ERR, "tvi_dshow: SetFiltergraph call failed. Error:0x%x\n",(unsigned int)hr); | |
2685 break; | |
2686 } | |
2687 | |
2688 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
|
2689 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
|
2690 if(!priv->chains[0]->pCaptureFilter){ |
24744 | 2691 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_NoVideoCaptureDevice); |
2692 break; | |
2693 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2694 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, priv->chains[0]->pCaptureFilter, NULL); |
24744 | 2695 if(FAILED(hr)){ |
2696 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to add video capture device to Directshow graph. Error:0x%x\n", (unsigned int)hr); | |
2697 break; | |
2698 } | |
2699 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Searching for available audio capture devices\n"); | |
2700 if (priv->adev_index != -1) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2701 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
|
2702 if(!priv->chains[1]->pCaptureFilter){ |
24744 | 2703 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_NoAudioCaptureDevice); |
2704 break; | |
2705 } | |
2706 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2707 hr = OLE_CALL_ARGS(priv->pGraph, AddFilter, priv->chains[1]->pCaptureFilter, NULL); |
24744 | 2708 if(FAILED(hr)){ |
2709 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Unable to add audio capture device to Directshow graph. Error:0x%x\n", (unsigned int)hr); | |
2710 break; | |
2711 } | |
2712 } else | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2713 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
|
2714 |
25082
b63b4b599cbe
Add capture filter's pointer to vbi chain structure too.
voroshil
parents:
25081
diff
changeset
|
2715 /* 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
|
2716 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
|
2717 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2718 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter, IID_IAMVideoProcAmp,priv->pVideoProcAmp); |
24744 | 2719 if (FAILED(hr) && hr != E_NOINTERFACE) |
2720 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get IID_IAMVideoProcAmp failed (0x%x).\n", (unsigned int)hr); | |
2721 | |
2722 if (hr != S_OK) { | |
2723 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_VideoAdjustigNotSupported); | |
2724 priv->pVideoProcAmp = NULL; | |
2725 } | |
2726 | |
2727 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, | |
2728 &PIN_CATEGORY_CAPTURE, | |
25080 | 2729 priv->chains[0]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2730 priv->chains[0]->pCaptureFilter, |
24744 | 2731 &IID_IAMCrossbar, (void **) &(priv->pCrossbar)); |
2732 if (FAILED(hr)) { | |
2733 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TVI_DS_SelectingInputNotSupported); | |
2734 priv->pCrossbar = NULL; | |
2735 } | |
2736 | |
2737 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, | |
2738 &PIN_CATEGORY_CAPTURE, | |
25083 | 2739 priv->chains[0]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2740 priv->chains[0]->pCaptureFilter, |
24744 | 2741 &IID_IAMStreamConfig, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2742 (void **) &(priv->chains[0]->pStreamConfig)); |
24744 | 2743 if (FAILED(hr)) { |
2744 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
|
2745 priv->chains[0]->pStreamConfig = NULL; |
24744 | 2746 } |
2747 | |
2748 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, | |
2749 &PIN_CATEGORY_CAPTURE, | |
25080 | 2750 priv->chains[1]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2751 priv->chains[1]->pCaptureFilter, |
24744 | 2752 &IID_IAMStreamConfig, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2753 (void **) &(priv->chains[1]->pStreamConfig)); |
24744 | 2754 if (FAILED(hr)) { |
2755 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Get IAMStreamConfig(audio) failed (0x%x).\n", (unsigned int)hr); | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2756 priv->chains[1]->pStreamConfig = NULL; |
24744 | 2757 } |
2758 | |
2759 if (priv->tv_param->amode >= 0) { | |
2760 IAMTVAudio *pTVAudio; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2761 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, NULL, NULL,priv->chains[0]->pCaptureFilter,&IID_IAMTVAudio, (void *) &pTVAudio); |
24744 | 2762 if (hr == S_OK) { |
2763 switch (priv->tv_param->amode) { | |
2764 case 0: | |
2765 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, AMTVAUDIO_MODE_MONO); | |
2766 break; | |
2767 case 1: | |
2768 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, AMTVAUDIO_MODE_STEREO); | |
2769 break; | |
2770 case 2: | |
2771 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, | |
2772 AMTVAUDIO_MODE_LANG_A); | |
2773 break; | |
2774 case 3: | |
2775 hr = OLE_CALL_ARGS(pTVAudio, put_TVAudioMode, | |
2776 AMTVAUDIO_MODE_LANG_B); | |
2777 break; | |
2778 } | |
2779 OLE_RELEASE_SAFE(pTVAudio); | |
2780 if (FAILED(hr)) | |
2781 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_UnableSetAudioMode, priv->tv_param->amode,(unsigned int)hr); | |
2782 } | |
2783 } | |
2784 /* | |
2785 Getting available video formats (last pointer in array will be NULL) | |
2786 First tryin to call IAMStreamConfig::GetStreamCaos. this will give us additional information such as | |
2787 min/max picture dimensions, etc. If this call fails trying IPIn::EnumMediaTypes with default | |
2788 min/max values. | |
2789 */ | |
2790 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2791 hr = get_available_formats_stream(priv->chains[0]->pStreamConfig, |
25080 | 2792 priv->chains[0]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2793 &(priv->chains[0]->arpmt), |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2794 (void ***) &(priv->chains[0]->arStreamCaps)); |
24744 | 2795 if (FAILED(hr)) { |
2796 mp_msg(MSGT_TV, MSGL_DBG2, "Unable to use IAMStreamConfig for retriving available video formats (Error:0x%x). Using EnumMediaTypes instead\n", (unsigned int)hr); | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2797 hr = get_available_formats_pin(priv->pBuilder, priv->chains[0]->pCaptureFilter, |
25080 | 2798 priv->chains[0]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2799 &(priv->chains[0]->arpmt), |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2800 (void ***) &(priv->chains[0]->arStreamCaps)); |
24744 | 2801 if(FAILED(hr)){ |
2802 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableGetsupportedVideoFormats, (unsigned int)hr); | |
2803 break; | |
2804 } | |
2805 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2806 priv->chains[0]->nFormatUsed = 0; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2807 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2808 if (!priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed] |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2809 || !extract_video_format(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed], |
24744 | 2810 &(priv->fcc), &(priv->width), |
2811 &(priv->height))) { | |
2812 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_ErrorParsingVideoFormatStruct); | |
2813 break; | |
2814 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2815 priv->chains[0]->pmt = CreateMediaType(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed]); |
24744 | 2816 /* |
2817 Getting available audio formats (last pointer in array will be NULL) | |
2818 */ | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2819 hr = get_available_formats_stream(priv->chains[1]->pStreamConfig, |
25080 | 2820 priv->chains[1]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2821 &(priv->chains[1]->arpmt), |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2822 (void ***) &(priv->chains[1]->arStreamCaps)); |
24744 | 2823 if (FAILED(hr)) { |
2824 mp_msg(MSGT_TV, MSGL_DBG2, "Unable to use IAMStreamConfig for retriving available audio formats (Error:0x%x). Using EnumMediaTypes instead\n", (unsigned int)hr); | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2825 hr = get_available_formats_pin(priv->pBuilder, priv->chains[1]->pCaptureFilter, |
25080 | 2826 priv->chains[1]->majortype, |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2827 &(priv->chains[1]->arpmt), |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2828 (void ***) &(priv->chains[1]->arStreamCaps)); |
24744 | 2829 if (FAILED(hr)) { |
2830 mp_msg(MSGT_TV,MSGL_WARN, MSGTR_TVI_DS_UnableGetsupportedAudioFormats, (unsigned int)hr); | |
2831 /* | |
2832 Following combination will disable sound | |
2833 */ | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2834 priv->chains[1]->arpmt = (AM_MEDIA_TYPE **) malloc(sizeof(AM_MEDIA_TYPE *)); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2835 priv->chains[1]->arpmt[0] = NULL; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2836 priv->chains[1]->pmt = NULL; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2837 priv->chains[1]->pStreamConfig = NULL; |
24744 | 2838 } |
2839 } | |
25081
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2840 /* |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2841 Getting formats for VBI stream |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2842 */ |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2843 priv->chains[2]->nFormatUsed = 0; |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2844 priv->chains[2]->arpmt = calloc(2, sizeof(AM_MEDIA_TYPE*)); |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2845 priv->chains[2]->arpmt[0] = calloc(1, sizeof(AM_MEDIA_TYPE)); |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2846 priv->chains[2]->arpmt[0]->majortype = MEDIATYPE_VBI; |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2847 |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2848 priv->chains[2]->pmt = CreateMediaType(priv->chains[2]->arpmt[priv->chains[2]->nFormatUsed]); |
ceaf17d27966
Code unification: get rid of local variable arpmtVBI
voroshil
parents:
25080
diff
changeset
|
2849 |
24744 | 2850 /* debug */ |
2851 { | |
2852 int i; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2853 for (i = 0; priv->chains[0]->arpmt[i]; i++) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2854 DisplayMediaType("Available video format", priv->chains[0]->arpmt[i]); |
24744 | 2855 } |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2856 for (i = 0; priv->chains[1]->arpmt[i]; i++) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2857 DisplayMediaType("Available audio format", priv->chains[1]->arpmt[i]); |
24744 | 2858 } |
2859 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2860 priv->chains[1]->nFormatUsed = 0; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2861 if (priv->chains[1]->arpmt[priv->chains[1]->nFormatUsed]) { |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2862 priv->chains[1]->pmt = CreateMediaType(priv->chains[1]->arpmt[priv->chains[1]->nFormatUsed]); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2863 if (!extract_audio_format(priv->chains[1]->pmt, &(priv->samplerate), NULL, NULL)) { |
24744 | 2864 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
|
2865 DisplayMediaType("audio format failed",priv->chains[1]->arpmt[priv->chains[1]->nFormatUsed]); |
24744 | 2866 break; |
2867 } | |
2868 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2869 show_filter_info(priv->chains[0]->pCaptureFilter); |
24744 | 2870 |
2871 hr = OLE_QUERYINTERFACE(priv->pGraph, IID_IMediaControl,priv->pMediaControl); | |
2872 if(FAILED(hr)){ | |
2873 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableGetMediaControlInterface,(unsigned int)hr); | |
2874 break; | |
2875 } | |
2876 hr = OLE_CALL_ARGS(priv->pBuilder, FindInterface, | |
2877 &PIN_CATEGORY_CAPTURE, NULL, | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2878 priv->chains[0]->pCaptureFilter, |
24744 | 2879 &IID_IAMTVTuner, (void **) &(priv->pTVTuner)); |
2880 | |
2881 if (!priv->pTVTuner) { | |
2882 mp_msg(MSGT_TV, MSGL_DBG2, "tvi_dshow: Unable to access IAMTVTuner (0x%x)\n", (unsigned int)hr); | |
2883 } | |
2884 | |
2885 // shows Tuner capabilities | |
2886 get_capabilities(priv); | |
2887 | |
2888 if (priv->pTVTuner) { | |
2889 hr = OLE_CALL_ARGS(priv->pTVTuner, put_CountryCode, | |
2890 chanlist2country(priv->tv_param->chanlist)); | |
2891 if(FAILED(hr)){ | |
2892 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to put_CountryCode failed. Error:0x%x\n",(unsigned int)hr); | |
2893 } | |
2894 | |
2895 hr = OLE_CALL_ARGS(priv->pTVTuner, put_Mode, AMTUNER_MODE_TV); | |
2896 if(FAILED(hr)){ | |
2897 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to put_Mode failed. Error:0x%x\n",(unsigned int)hr); | |
2898 break; | |
2899 } | |
2900 | |
2901 hr = OLE_CALL_ARGS(priv->pTVTuner, get_ConnectInput, &lInput); | |
2902 if(FAILED(hr)){ | |
2903 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to get_ConnectInput failed. Error:0x%x\n",(unsigned int)hr); | |
2904 break; | |
2905 } | |
2906 | |
2907 /* small hack */ | |
2908 lTunerInput = strstr(priv->tv_param->chanlist, "cable") ? TunerInputCable : TunerInputAntenna; | |
2909 | |
2910 hr = OLE_CALL_ARGS(priv->pTVTuner, put_InputType, lInput, lTunerInput); | |
2911 if(FAILED(hr)){ | |
2912 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: Call to put_InputType failed. Error:0x%x\n",(unsigned int)hr); | |
2913 break; | |
2914 } | |
2915 | |
2916 } | |
2917 | |
2918 /** | |
2919 for VIVO cards we should check if preview pin is available on video capture device. | |
2920 If it is not, we have to connect Video Port Manager filter to VP pin of capture device filter. | |
2921 Otherwise we will get 0x8007001f (Device is not functioning properly) when attempting to start graph | |
2922 */ | |
2923 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
2924 (IUnknown *) priv->chains[0]->pCaptureFilter, |
24744 | 2925 PINDIR_OUTPUT, |
2926 &PIN_CATEGORY_VIDEOPORT, NULL, FALSE, | |
2927 0, (IPin **) & pVPOutPin); | |
2928 if (SUCCEEDED(hr)) { | |
2929 hr = OLE_CALL_ARGS(priv->pGraph, Render, pVPOutPin); | |
2930 OLE_RELEASE_SAFE(pVPOutPin); | |
2931 | |
2932 if (FAILED(hr)) { | |
2933 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_UnableTerminateVPPin, (unsigned int)hr); | |
2934 break; | |
2935 } | |
2936 } | |
2937 | |
2938 OLE_CALL_ARGS(priv->pGraph, EnumFilters, &pEnum); | |
2939 while (OLE_CALL_ARGS(pEnum, Next, 1, &pFilter, NULL) == S_OK) { | |
2940 LPVIDEOWINDOW pVideoWindow; | |
2941 hr = OLE_QUERYINTERFACE(pFilter, IID_IVideoWindow, pVideoWindow); | |
2942 if (SUCCEEDED(hr)) | |
2943 { | |
2944 if(priv->tv_param->hidden_vp_renderer){ | |
2945 OLE_CALL_ARGS(pVideoWindow,put_Visible,/* OAFALSE*/ 0); | |
2946 OLE_CALL_ARGS(pVideoWindow,put_AutoShow,/* OAFALSE*/ 0); | |
2947 }else | |
2948 { | |
2949 OLE_CALL_ARGS(priv->pGraph, RemoveFilter, pFilter); | |
2950 } | |
2951 OLE_RELEASE_SAFE(pVideoWindow); | |
2952 } | |
2953 OLE_RELEASE_SAFE(pFilter); | |
2954 } | |
2955 OLE_RELEASE_SAFE(pEnum); | |
2956 if(priv->tv_param->system_clock) | |
2957 { | |
2958 LPREFERENCECLOCK rc; | |
2959 IBaseFilter* pBF; | |
2960 hr = CoCreateInstance((GUID *) & CLSID_SystemClock, NULL, | |
2961 CLSCTX_INPROC_SERVER, &IID_IReferenceClock, | |
2962 (void *) &rc); | |
2963 | |
2964 OLE_QUERYINTERFACE(priv->pBuilder,IID_IBaseFilter,pBF); | |
2965 OLE_CALL_ARGS(pBF,SetSyncSource,rc); | |
2966 } | |
2967 #ifdef HAVE_TV_TELETEXT | |
2968 if(vbi_get_props(priv,&(priv->tsp))!=TVI_CONTROL_TRUE) | |
2969 break; | |
2970 #endif | |
2971 result = 1; | |
2972 } while(0); | |
2973 | |
2974 if (!result){ | |
2975 mp_msg(MSGT_TV,MSGL_ERR, MSGTR_TVI_DS_GraphInitFailure); | |
2976 uninit(priv); | |
2977 } | |
2978 return result; | |
2979 } | |
2980 | |
2981 /** | |
25085
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2982 * \brief chain uninitialization |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2983 * \param chain chain data structure |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2984 */ |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2985 static void destroy_chain(chain_t *chain) |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2986 { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2987 int i; |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2988 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2989 if(!chain) |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2990 return; |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2991 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2992 OLE_RELEASE_SAFE(chain->pStreamConfig); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
2993 OLE_RELEASE_SAFE(chain->pCaptureFilter); |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
2994 OLE_RELEASE_SAFE(chain->pCSGCB); |
25087
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2995 OLE_RELEASE_SAFE(chain->pCapturePin); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2996 OLE_RELEASE_SAFE(chain->pSGIn); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2997 OLE_RELEASE_SAFE(chain->pSG); |
edc7391db7f5
New routine for reconnecting two pins with new media type
voroshil
parents:
25086
diff
changeset
|
2998 OLE_RELEASE_SAFE(chain->pSGF); |
25086
e91503fbf524
Move pointer to SampleGrabber filter into chain structure.
voroshil
parents:
25085
diff
changeset
|
2999 |
25085
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3000 if (chain->pmt) |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3001 DeleteMediaType(chain->pmt); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3002 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3003 if (chain->arpmt) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3004 for (i = 0; chain->arpmt[i]; i++) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3005 DeleteMediaType(chain->arpmt[i]); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3006 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3007 free(chain->arpmt); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3008 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3009 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3010 if (chain->arStreamCaps) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3011 for (i = 0; chain->arStreamCaps[i]; i++) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3012 free(chain->arStreamCaps[i]); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3013 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3014 free(chain->arStreamCaps); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3015 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3016 |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3017 if (chain->rbuf) { |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3018 destroy_ringbuffer(chain->rbuf); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3019 free(chain->rbuf); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3020 chain->rbuf = NULL; |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3021 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3022 free(chain); |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3023 } |
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3024 /** |
24744 | 3025 * \brief driver uninitialization |
3026 * | |
3027 * \param priv driver's private data structure | |
3028 * | |
3029 * \return always 1 | |
3030 */ | |
3031 static int uninit(priv_t * priv) | |
3032 { | |
3033 int i; | |
3034 if (!priv) | |
3035 return (1); | |
3036 //Debug | |
3037 if (priv->dwRegister) { | |
3038 RemoveFromRot(priv->dwRegister); | |
3039 } | |
3040 #ifdef HAVE_TV_TELETEXT | |
3041 teletext_control(priv->priv_vbi,TV_VBI_CONTROL_STOP,(void*)1); | |
3042 #endif | |
3043 //stop audio grabber thread | |
3044 | |
3045 if (priv->state && priv->pMediaControl) { | |
3046 OLE_CALL(priv->pMediaControl, Stop); | |
3047 } | |
3048 OLE_RELEASE_SAFE(priv->pMediaControl); | |
3049 priv->state = 0; | |
3050 | |
3051 if (priv->pGraph) { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3052 if (priv->chains[0]->pCaptureFilter) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3053 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
|
3054 if (priv->chains[1]->pCaptureFilter) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3055 OLE_CALL_ARGS(priv->pGraph, RemoveFilter, priv->chains[1]->pCaptureFilter); |
24744 | 3056 } |
3057 OLE_RELEASE_SAFE(priv->pCrossbar); | |
3058 OLE_RELEASE_SAFE(priv->pVideoProcAmp); | |
3059 OLE_RELEASE_SAFE(priv->pGraph); | |
3060 OLE_RELEASE_SAFE(priv->pBuilder); | |
3061 if(priv->freq_table){ | |
3062 priv->freq_table_len=-1; | |
3063 free(priv->freq_table); | |
3064 priv->freq_table=NULL; | |
3065 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3066 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3067 for(i=0; i<3;i++) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3068 { |
25085
da7c8d1b7a36
Move common chain uninit code into separate routine.
voroshil
parents:
25084
diff
changeset
|
3069 destroy_chain(priv->chains[i]); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3070 priv->chains[i] = NULL; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3071 } |
24744 | 3072 CoUninitialize(); |
3073 return (1); | |
3074 } | |
3075 | |
3076 /** | |
3077 * \brief driver pre-initialization | |
3078 * | |
3079 * \param device string, containing device name in form "x[.y]", where x is video capture device | |
3080 * (default: 0, first available); y (if given) sets audio capture device | |
3081 * | |
3082 * \return 1 if success,0 - otherwise | |
3083 */ | |
3084 static tvi_handle_t *tvi_init_dshow(tv_param_t* tv_param) | |
3085 { | |
3086 tvi_handle_t *h; | |
3087 priv_t *priv; | |
3088 int a; | |
3089 | |
3090 h = new_handle(); | |
3091 if (!h) | |
3092 return (NULL); | |
3093 | |
3094 priv = h->priv; | |
3095 | |
3096 memset(priv, 0, sizeof(priv_t)); | |
3097 priv->direct_setfreq_call = 1; //first using direct call. if it fails, workaround will be enabled | |
3098 priv->direct_getfreq_call = 1; //first using direct call. if it fails, workaround will be enabled | |
3099 priv->adev_index = -1; | |
3100 priv->freq_table_len=-1; | |
3101 priv->tv_param=tv_param; | |
3102 | |
3103 if (tv_param->device) { | |
3104 if (sscanf(tv_param->device, "%d", &a) == 1) { | |
3105 priv->dev_index = a; | |
3106 } else { | |
3107 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongDeviceParam, tv_param->device); | |
3108 free_handle(h); | |
3109 return NULL; | |
3110 } | |
3111 if (priv->dev_index < 0) { | |
3112 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongDeviceIndex, a); | |
3113 free_handle(h); | |
3114 return NULL; | |
3115 } | |
3116 } | |
3117 if (tv_param->adevice) { | |
3118 if (sscanf(tv_param->adevice, "%d", &a) == 1) { | |
3119 priv->adev_index = a; | |
3120 } else { | |
3121 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongADeviceParam, tv_param->adevice); | |
3122 free_handle(h); | |
3123 return NULL; | |
3124 } | |
3125 if (priv->dev_index < 0) { | |
3126 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_WrongADeviceIndex, a); | |
3127 free_handle(h); | |
3128 return NULL; | |
3129 } | |
3130 } | |
3131 return h; | |
3132 } | |
3133 | |
3134 /** | |
3135 * \brief driver's ioctl handler | |
3136 * | |
3137 * \param priv driver's private data structure | |
3138 * \param cmd ioctl command | |
3139 * \param arg ioct command's parameter | |
3140 * | |
3141 * \return TVI_CONTROL_TRUE if success | |
3142 * \return TVI_CONTROL_FALSE if failure | |
3143 * \return TVI_CONTROL_UNKNOWN if unknowm cmd called | |
3144 */ | |
3145 static int control(priv_t * priv, int cmd, void *arg) | |
3146 { | |
3147 switch (cmd) { | |
3148 /* need rewrite */ | |
3149 case TVI_CONTROL_VID_SET_FORMAT: | |
3150 { | |
3151 int fcc, i; | |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
3152 void* tmp; |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3153 int result = TVI_CONTROL_TRUE; |
25063
29260745e4fa
Pass all available formats to chain building routine and
voroshil
parents:
25061
diff
changeset
|
3154 |
24744 | 3155 if (priv->state) |
3156 return TVI_CONTROL_FALSE; | |
3157 fcc = *(int *) arg; | |
3158 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3159 if(!priv->chains[0]->arpmt) |
24744 | 3160 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3161 for (i = 0; priv->chains[0]->arpmt[i]; i++) |
24744 | 3162 if (check_video_format |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3163 (priv->chains[0]->arpmt[i], fcc, priv->width, priv->height)) |
24744 | 3164 break; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3165 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
|
3166 { |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3167 int fps = 0; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3168 VIDEOINFOHEADER* Vhdr = NULL; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3169 AM_MEDIA_TYPE *pmt; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3170 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3171 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
|
3172 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3173 if (priv->chains[0]->arpmt[0]) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3174 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
|
3175 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3176 if(Vhdr && Vhdr->bmiHeader.biSizeImage) |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3177 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
|
3178 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3179 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
|
3180 if(!pmt) |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3181 { |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3182 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
|
3183 return TVI_CONTROL_FALSE; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3184 } |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3185 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
|
3186 priv->chains[0]->arpmt[i+1] = NULL; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3187 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
|
3188 |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3189 result = TVI_CONTROL_FALSE; |
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3190 } |
24744 | 3191 |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3192 tmp = priv->chains[0]->arpmt[0]; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3193 priv->chains[0]->arpmt[0] = priv->chains[0]->arpmt[i]; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3194 priv->chains[0]->arpmt[i] = tmp; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3195 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3196 tmp = priv->chains[0]->arStreamCaps[0]; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3197 priv->chains[0]->arStreamCaps[0] = priv->chains[0]->arStreamCaps[i]; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3198 priv->chains[0]->arStreamCaps[i] = tmp; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3199 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3200 priv->chains[0]->nFormatUsed = 0; |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3201 |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3202 if (priv->chains[0]->pmt) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3203 DeleteMediaType(priv->chains[0]->pmt); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3204 priv->chains[0]->pmt = |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3205 CreateMediaType(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed]); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3206 DisplayMediaType("VID_SET_FORMAT", priv->chains[0]->pmt); |
24744 | 3207 /* |
3208 Setting width & height to preferred by driver values | |
3209 */ | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3210 extract_video_format(priv->chains[0]->arpmt[priv->chains[0]->nFormatUsed], |
24744 | 3211 &(priv->fcc), &(priv->width), |
3212 &(priv->height)); | |
25068
4b14d188ed34
Add all passed to VID_SET_FORMAT formats to the end of
voroshil
parents:
25067
diff
changeset
|
3213 return result; |
24744 | 3214 } |
3215 case TVI_CONTROL_VID_GET_FORMAT: | |
3216 { | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3217 if(!priv->chains[0]->pmt) |
24744 | 3218 return TVI_CONTROL_FALSE; |
25067
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3219 /* |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3220 Build video chain (for video format negotiation). |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3221 If this was done before, routine will do nothing. |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3222 */ |
5abe2c29b7d8
Ensure that when VID_GET_FORMAT ioctl is called,
voroshil
parents:
25066
diff
changeset
|
3223 build_video_chain(priv); |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3224 DisplayMediaType("VID_GET_FORMAT", priv->chains[0]->pmt); |
24744 | 3225 if (priv->fcc) { |
3226 *(int *) arg = priv->fcc; | |
3227 return (TVI_CONTROL_TRUE); | |
3228 } else | |
3229 return (TVI_CONTROL_FALSE); | |
3230 } | |
3231 case TVI_CONTROL_VID_SET_WIDTH: | |
3232 { | |
3233 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3234 VIDEOINFOHEADER *Vhdr; | |
3235 int width = *(int *) arg; | |
3236 if (priv->state) | |
3237 return TVI_CONTROL_FALSE; | |
3238 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3239 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3240 if (!pCaps) |
3241 return TVI_CONTROL_FALSE; | |
3242 if (width < pCaps->MinOutputSize.cx | |
3243 || width > pCaps->MaxOutputSize.cx) | |
3244 return TVI_CONTROL_FALSE; | |
3245 | |
3246 if (width % pCaps->OutputGranularityX) | |
3247 return TVI_CONTROL_FALSE; | |
3248 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3249 if (!priv->chains[0]->pmt || !priv->chains[0]->pmt->pbFormat) |
24744 | 3250 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3251 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat; |
24744 | 3252 Vhdr->bmiHeader.biWidth = width; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3253 priv->chains[0]->pmt->lSampleSize = Vhdr->bmiHeader.biSizeImage = |
24744 | 3254 labs(Vhdr->bmiHeader.biBitCount * Vhdr->bmiHeader.biWidth * |
3255 Vhdr->bmiHeader.biHeight) >> 3; | |
3256 | |
3257 priv->width = width; | |
3258 | |
3259 return (TVI_CONTROL_TRUE); | |
3260 } | |
3261 case TVI_CONTROL_VID_GET_WIDTH: | |
3262 { | |
3263 if (priv->width) { | |
3264 *(int *) arg = priv->width; | |
3265 return (TVI_CONTROL_TRUE); | |
3266 } else | |
3267 return TVI_CONTROL_FALSE; | |
3268 } | |
3269 case TVI_CONTROL_VID_CHK_WIDTH: | |
3270 { | |
3271 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3272 int width = *(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 (width < pCaps->MinOutputSize.cx | |
3277 || width > pCaps->MaxOutputSize.cx) | |
3278 return TVI_CONTROL_FALSE; | |
3279 | |
3280 if (width % pCaps->OutputGranularityX) | |
3281 return TVI_CONTROL_FALSE; | |
3282 return (TVI_CONTROL_TRUE); | |
3283 } | |
3284 case TVI_CONTROL_VID_SET_HEIGHT: | |
3285 { | |
3286 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3287 VIDEOINFOHEADER *Vhdr; | |
3288 int height = *(int *) arg; | |
3289 if (priv->state) | |
3290 return TVI_CONTROL_FALSE; | |
3291 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3292 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3293 if (!pCaps) |
3294 return TVI_CONTROL_FALSE; | |
3295 if (height < pCaps->MinOutputSize.cy | |
3296 || height > pCaps->MaxOutputSize.cy) | |
3297 return TVI_CONTROL_FALSE; | |
3298 | |
3299 if (height % pCaps->OutputGranularityY) | |
3300 return TVI_CONTROL_FALSE; | |
3301 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3302 if (!priv->chains[0]->pmt || !priv->chains[0]->pmt->pbFormat) |
24744 | 3303 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3304 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat; |
24744 | 3305 |
3306 if (Vhdr->bmiHeader.biHeight < 0) | |
3307 Vhdr->bmiHeader.biHeight = -height; | |
3308 else | |
3309 Vhdr->bmiHeader.biHeight = height; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3310 priv->chains[0]->pmt->lSampleSize = Vhdr->bmiHeader.biSizeImage = |
24744 | 3311 labs(Vhdr->bmiHeader.biBitCount * Vhdr->bmiHeader.biWidth * |
3312 Vhdr->bmiHeader.biHeight) >> 3; | |
3313 | |
3314 priv->height = height; | |
3315 return (TVI_CONTROL_TRUE); | |
3316 } | |
3317 case TVI_CONTROL_VID_GET_HEIGHT: | |
3318 { | |
3319 if (priv->height) { | |
3320 *(int *) arg = priv->height; | |
3321 return (TVI_CONTROL_TRUE); | |
3322 } else | |
3323 return TVI_CONTROL_FALSE; | |
3324 } | |
3325 case TVI_CONTROL_VID_CHK_HEIGHT: | |
3326 { | |
3327 VIDEO_STREAM_CONFIG_CAPS *pCaps; | |
3328 int height = *(int *) arg; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3329 pCaps = priv->chains[0]->arStreamCaps[priv->chains[0]->nFormatUsed]; |
24744 | 3330 if (!pCaps) |
3331 return TVI_CONTROL_FALSE; | |
3332 if (height < pCaps->MinOutputSize.cy | |
3333 || height > pCaps->MaxOutputSize.cy) | |
3334 return TVI_CONTROL_FALSE; | |
3335 | |
3336 if (height % pCaps->OutputGranularityY) | |
3337 return TVI_CONTROL_FALSE; | |
3338 | |
3339 return (TVI_CONTROL_TRUE); | |
3340 } | |
3341 case TVI_CONTROL_IS_AUDIO: | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3342 if (!priv->chains[1]->pmt) |
24744 | 3343 return TVI_CONTROL_FALSE; |
3344 else | |
3345 return TVI_CONTROL_TRUE; | |
3346 case TVI_CONTROL_IS_VIDEO: | |
3347 return TVI_CONTROL_TRUE; | |
3348 case TVI_CONTROL_AUD_GET_FORMAT: | |
3349 { | |
3350 *(int *) arg = AF_FORMAT_S16_LE; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3351 if (!priv->chains[1]->pmt) |
24744 | 3352 return TVI_CONTROL_FALSE; |
3353 else | |
3354 return TVI_CONTROL_TRUE; | |
3355 } | |
3356 case TVI_CONTROL_AUD_GET_CHANNELS: | |
3357 { | |
3358 *(int *) arg = priv->channels; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3359 if (!priv->chains[1]->pmt) |
24744 | 3360 return TVI_CONTROL_FALSE; |
3361 else | |
3362 return TVI_CONTROL_TRUE; | |
3363 } | |
3364 case TVI_CONTROL_AUD_SET_SAMPLERATE: | |
3365 { | |
3366 int i, samplerate; | |
3367 if (priv->state) | |
3368 return TVI_CONTROL_FALSE; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3369 if (!priv->chains[1]->arpmt[0]) |
24744 | 3370 return TVI_CONTROL_FALSE; |
3371 | |
3372 samplerate = *(int *) arg;; | |
3373 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3374 for (i = 0; priv->chains[1]->arpmt[i]; i++) |
24744 | 3375 if (check_audio_format |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3376 (priv->chains[1]->arpmt[i], samplerate, 16, priv->channels)) |
24744 | 3377 break; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3378 if (!priv->chains[1]->arpmt[i]) { |
24744 | 3379 //request not found. failing back to first available |
3380 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_SamplerateNotsupported, samplerate); | |
3381 i = 0; | |
3382 } | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3383 if (priv->chains[1]->pmt) |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3384 DeleteMediaType(priv->chains[1]->pmt); |
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3385 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
|
3386 extract_audio_format(priv->chains[1]->arpmt[i], &(priv->samplerate), |
24744 | 3387 NULL, &(priv->channels)); |
3388 return TVI_CONTROL_TRUE; | |
3389 } | |
3390 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
3391 { | |
3392 *(int *) arg = priv->samplerate; | |
3393 if (!priv->samplerate) | |
3394 return TVI_CONTROL_FALSE; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3395 if (!priv->chains[1]->pmt) |
24744 | 3396 return TVI_CONTROL_FALSE; |
3397 else | |
3398 return TVI_CONTROL_TRUE; | |
3399 } | |
3400 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
3401 { | |
3402 WAVEFORMATEX *pWF; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3403 if (!priv->chains[1]->pmt) |
24744 | 3404 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3405 if (!priv->chains[1]->pmt->pbFormat) |
24744 | 3406 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3407 pWF = (WAVEFORMATEX *) priv->chains[1]->pmt->pbFormat; |
24744 | 3408 *(int *) arg = pWF->wBitsPerSample / 8; |
3409 return TVI_CONTROL_TRUE; | |
3410 } | |
3411 case TVI_CONTROL_IS_TUNER: | |
3412 { | |
3413 if (!priv->pTVTuner) | |
3414 return TVI_CONTROL_FALSE; | |
3415 | |
3416 return (TVI_CONTROL_TRUE); | |
3417 } | |
3418 case TVI_CONTROL_TUN_SET_NORM: | |
3419 { | |
3420 IAMAnalogVideoDecoder *pVD; | |
3421 long lAnalogFormat; | |
3422 int i; | |
3423 HRESULT hr; | |
3424 | |
3425 i = *(int *) arg; | |
3426 i--; | |
3427 if (i < 0 || i >= tv_available_norms_count) | |
3428 return TVI_CONTROL_FALSE; | |
3429 lAnalogFormat = tv_norms[tv_available_norms[i]].index; | |
3430 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3431 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter,IID_IAMAnalogVideoDecoder, pVD); |
24744 | 3432 if (hr != S_OK) |
3433 return TVI_CONTROL_FALSE; | |
25077 | 3434 hr = OLE_CALL_ARGS(pVD, put_TVFormat, lAnalogFormat); |
24744 | 3435 OLE_RELEASE_SAFE(pVD); |
3436 if (FAILED(hr)) | |
3437 return (TVI_CONTROL_FALSE); | |
3438 else | |
3439 return (TVI_CONTROL_TRUE); | |
3440 } | |
3441 case TVI_CONTROL_TUN_GET_NORM: | |
3442 { | |
3443 long lAnalogFormat; | |
3444 int i; | |
3445 HRESULT hr; | |
3446 IAMAnalogVideoDecoder *pVD; | |
3447 | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3448 hr = OLE_QUERYINTERFACE(priv->chains[0]->pCaptureFilter,IID_IAMAnalogVideoDecoder, pVD); |
24744 | 3449 if (hr == S_OK) { |
3450 hr = OLE_CALL_ARGS(pVD, get_TVFormat, &lAnalogFormat); | |
3451 OLE_RELEASE_SAFE(pVD); | |
3452 } | |
3453 | |
3454 if (FAILED(hr)) { //trying another method | |
3455 if (!priv->pTVTuner) | |
3456 return TVI_CONTROL_FALSE; | |
3457 hr=OLE_CALL_ARGS(priv->pTVTuner, get_TVFormat, &lAnalogFormat); | |
3458 if (FAILED(hr)) | |
3459 return TVI_CONTROL_FALSE; | |
3460 } | |
3461 for (i = 0; i < tv_available_norms_count; i++) { | |
3462 if (tv_norms[tv_available_norms[i]].index == lAnalogFormat) { | |
3463 *(int *) arg = i + 1; | |
3464 return TVI_CONTROL_TRUE; | |
3465 } | |
3466 } | |
3467 return (TVI_CONTROL_FALSE); | |
3468 } | |
3469 case TVI_CONTROL_SPC_GET_NORMID: | |
3470 { | |
3471 int i; | |
3472 if (!priv->pTVTuner) | |
3473 return TVI_CONTROL_FALSE; | |
3474 for (i = 0; i < tv_available_norms_count; i++) { | |
3475 if (!strcasecmp | |
3476 (tv_norms[tv_available_norms[i]].name, (char *) arg)) { | |
3477 *(int *) arg = i + 1; | |
3478 return TVI_CONTROL_TRUE; | |
3479 } | |
3480 } | |
3481 return TVI_CONTROL_FALSE; | |
3482 } | |
3483 case TVI_CONTROL_SPC_SET_INPUT: | |
3484 { | |
3485 return set_crossbar_input(priv, *(int *) arg); | |
3486 } | |
3487 case TVI_CONTROL_TUN_GET_FREQ: | |
3488 { | |
3489 unsigned long lFreq; | |
3490 int ret; | |
3491 if (!priv->pTVTuner) | |
3492 return TVI_CONTROL_FALSE; | |
3493 | |
3494 ret = get_frequency(priv, &lFreq); | |
3495 lFreq = lFreq * 16 / 1000000; //convert from Hz to 1/16 MHz units | |
3496 | |
3497 *(unsigned long *) arg = lFreq; | |
3498 return ret; | |
3499 } | |
3500 case TVI_CONTROL_TUN_SET_FREQ: | |
3501 { | |
3502 unsigned long nFreq = *(unsigned long *) arg; | |
3503 if (!priv->pTVTuner) | |
3504 return TVI_CONTROL_FALSE; | |
3505 //convert to Hz | |
3506 nFreq = 1000000 * nFreq / 16; //convert from 1/16 MHz units to Hz | |
3507 return set_frequency(priv, nFreq); | |
3508 } | |
3509 case TVI_CONTROL_VID_SET_HUE: | |
3510 return set_control(priv, VideoProcAmp_Hue, *(int *) arg); | |
3511 case TVI_CONTROL_VID_GET_HUE: | |
3512 return get_control(priv, VideoProcAmp_Hue, (int *) arg); | |
3513 case TVI_CONTROL_VID_SET_CONTRAST: | |
3514 return set_control(priv, VideoProcAmp_Contrast, *(int *) arg); | |
3515 case TVI_CONTROL_VID_GET_CONTRAST: | |
3516 return get_control(priv, VideoProcAmp_Contrast, (int *) arg); | |
3517 case TVI_CONTROL_VID_SET_SATURATION: | |
3518 return set_control(priv, VideoProcAmp_Saturation, *(int *) arg); | |
3519 case TVI_CONTROL_VID_GET_SATURATION: | |
3520 return get_control(priv, VideoProcAmp_Saturation, (int *) arg); | |
3521 case TVI_CONTROL_VID_SET_BRIGHTNESS: | |
3522 return set_control(priv, VideoProcAmp_Brightness, *(int *) arg); | |
3523 case TVI_CONTROL_VID_GET_BRIGHTNESS: | |
3524 return get_control(priv, VideoProcAmp_Brightness, (int *) arg); | |
3525 | |
3526 case TVI_CONTROL_VID_GET_FPS: | |
3527 { | |
3528 VIDEOINFOHEADER *Vhdr; | |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3529 if (!priv->chains[0]->pmt) |
24744 | 3530 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3531 if (!priv->chains[0]->pmt->pbFormat) |
24744 | 3532 return TVI_CONTROL_FALSE; |
25079
3dcf8e3e65d9
One step of code cleanup: move all variables, related
voroshil
parents:
25077
diff
changeset
|
3533 Vhdr = (VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat; |
24744 | 3534 *(float *) arg = |
25028
2cae9470f53b
Fix FPS from bitrate calculation (was 8 times larger than real value).
voroshil
parents:
25019
diff
changeset
|
3535 (1.0 * Vhdr->dwBitRate) / (Vhdr->bmiHeader.biSizeImage * 8); |
24744 | 3536 return TVI_CONTROL_TRUE; |
3537 } | |
3538 case TVI_CONTROL_IMMEDIATE: | |
3539 priv->immediate_mode = 1; | |
3540 return TVI_CONTROL_TRUE; | |
3541 #ifdef HAVE_TV_TELETEXT | |
3542 case TVI_CONTROL_VBI_INIT: | |
3543 { | |
3544 void* ptr; | |
3545 ptr=&(priv->tsp); | |
3546 if(teletext_control(NULL,TV_VBI_CONTROL_START,&ptr)==TVI_CONTROL_TRUE) | |
3547 priv->priv_vbi=ptr; | |
3548 else | |
3549 priv->priv_vbi=NULL; | |
3550 return TVI_CONTROL_TRUE; | |
3551 } | |
3552 default: | |
3553 return teletext_control(priv->priv_vbi,cmd,arg); | |
3554 #endif | |
3555 } | |
3556 return (TVI_CONTROL_UNKNOWN); | |
3557 } |