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