2 TV Interface for MPlayer
6 API idea based on libvo2
8 Feb 19, 2002: Significant rewrites by Charles R. Henrich (henrich@msu.edu)
9 to add support for audio, and bktr *BSD support.
28 #include "libmpdemux/demuxer.h"
29 #include "libmpdemux/stheader.h"
31 #include "libaf/af_format.h"
32 #include "libmpcodecs/img_format.h"
33 #include "libvo/fastmemcpy.h"
37 #include "frequencies.h"
39 /* some default values */
40 int tv_param_audiorate
= 44100;
41 int tv_param_noaudio
= 0;
42 int tv_param_immediate
= 0;
43 char *tv_param_freq
= NULL
;
44 char *tv_param_channel
= NULL
;
45 char *tv_param_norm
= "pal";
47 int tv_param_normid
= -1;
49 char *tv_param_chanlist
= "europe-east";
50 char *tv_param_device
= NULL
;
51 char *tv_param_driver
= "dummy";
52 int tv_param_width
= -1;
53 int tv_param_height
= -1;
54 int tv_param_input
= 0; /* used in v4l and bttv */
55 int tv_param_outfmt
= -1;
56 float tv_param_fps
= -1.0;
57 char **tv_param_channels
= NULL
;
58 int tv_param_audio_id
= 0;
59 #if defined(HAVE_TV_V4L)
60 int tv_param_amode
= -1;
61 int tv_param_volume
= -1;
62 int tv_param_bass
= -1;
63 int tv_param_treble
= -1;
64 int tv_param_balance
= -1;
65 int tv_param_forcechan
= -1;
66 int tv_param_force_audio
= 0;
67 int tv_param_buffer_size
= -1;
68 int tv_param_mjpeg
= 0;
69 int tv_param_decimation
= 2;
70 int tv_param_quality
= 90;
71 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
72 int tv_param_alsa
= 0;
74 char* tv_param_adevice
= NULL
;
76 int tv_param_brightness
= 0;
77 int tv_param_contrast
= 0;
79 int tv_param_saturation
= 0;
80 tv_channels_t
*tv_channel_list
;
81 tv_channels_t
*tv_channel_current
, *tv_channel_last
;
82 char *tv_channel_last_real
;
84 /* ================== DEMUX_TV ===================== */
87 0 = EOF(?) or no stream
88 1 = successfully read a packet
90 /* fill demux->video and demux->audio */
92 static int demux_tv_fill_buffer(demuxer_t
*demux
, demux_stream_t
*ds
)
94 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demux
->priv
);
98 /* ================== ADD AUDIO PACKET =================== */
100 if (ds
==demux
->audio
&& tv_param_noaudio
== 0 &&
101 tvh
->functions
->control(tvh
->priv
,
102 TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
104 len
= tvh
->functions
->get_audio_framesize(tvh
->priv
);
106 dp
=new_demux_packet(len
);
107 dp
->flags
|=1; /* Keyframe */
108 dp
->pts
=tvh
->functions
->grab_audio_frame(tvh
->priv
, dp
->buffer
,len
);
109 ds_add_packet(demux
->audio
,dp
);
112 /* ================== ADD VIDEO PACKET =================== */
114 if (ds
==demux
->video
&& tvh
->functions
->control(tvh
->priv
,
115 TVI_CONTROL_IS_VIDEO
, 0) == TVI_CONTROL_TRUE
)
117 len
= tvh
->functions
->get_video_framesize(tvh
->priv
);
118 dp
=new_demux_packet(len
);
119 dp
->flags
|=1; /* Keyframe */
120 dp
->pts
=tvh
->functions
->grab_video_frame(tvh
->priv
, dp
->buffer
, len
);
121 ds_add_packet(demux
->video
,dp
);
127 static int norm_from_string(tvi_handle_t
*tvh
, char* norm
)
130 if (strcmp(tv_param_driver
, "v4l2") != 0) {
132 if (!strcasecmp(norm
, "pal"))
134 else if (!strcasecmp(norm
, "ntsc"))
136 else if (!strcasecmp(norm
, "secam"))
137 return TV_NORM_SECAM
;
138 else if (!strcasecmp(norm
, "palnc"))
139 return TV_NORM_PALNC
;
140 else if (!strcasecmp(norm
, "palm"))
142 else if (!strcasecmp(norm
, "paln"))
144 else if (!strcasecmp(norm
, "ntscjp"))
145 return TV_NORM_NTSCJP
;
147 mp_msg(MSGT_TV
, MSGL_V
, "tv.c: norm_from_string(%s): Bogus norm parameter, setting PAL.\n", norm
);
152 tvi_functions_t
*funcs
= tvh
->functions
;
154 strncpy(str
, norm
, sizeof(str
)-1);
155 str
[sizeof(str
)-1] = '\0';
156 if (funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_GET_NORMID
, str
) != TVI_CONTROL_TRUE
)
163 static int open_tv(tvi_handle_t
*tvh
)
166 tvi_functions_t
*funcs
= tvh
->functions
;
167 int tv_fmt_list
[] = {
178 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
180 mp_msg(MSGT_TV
, MSGL_ERR
, "Error: No video input present!\n");
184 if (tv_param_outfmt
== -1)
185 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
187 tv_param_outfmt
= tv_fmt_list
[i
];
188 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
189 &tv_param_outfmt
) == TVI_CONTROL_TRUE
)
194 switch(tv_param_outfmt
)
208 mp_msg(MSGT_TV
, MSGL_ERR
, "==================================================================\n");
209 mp_msg(MSGT_TV
, MSGL_ERR
, " WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n", tv_param_outfmt
);
210 mp_msg(MSGT_TV
, MSGL_ERR
, " This may cause buggy playback or program crash! Bug reports will\n");
211 mp_msg(MSGT_TV
, MSGL_ERR
, " be ignored! You should try again with YV12 (which is the default\n");
212 mp_msg(MSGT_TV
, MSGL_ERR
, " colorspace) and read the documentation!\n");
213 mp_msg(MSGT_TV
, MSGL_ERR
, "==================================================================\n");
215 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tv_param_outfmt
);
218 /* set some params got from cmdline */
219 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tv_param_input
);
222 if (!strcmp(tv_param_driver
, "v4l2") && tv_param_normid
>= 0) {
223 mp_msg(MSGT_TV
, MSGL_V
, "Selected norm id: %d\n", tv_param_normid
);
224 if (funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tv_param_normid
) != TVI_CONTROL_TRUE
) {
225 mp_msg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
229 /* select video norm */
230 tvh
->norm
= norm_from_string(tvh
, tv_param_norm
);
232 mp_msg(MSGT_TV
, MSGL_V
, "Selected norm: %s\n", tv_param_norm
);
233 if (funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
234 mp_msg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
241 if ( tv_param_mjpeg
)
243 /* set width to expected value */
244 if (tv_param_width
== -1)
246 tv_param_width
= 704/tv_param_decimation
;
248 if (tv_param_height
== -1)
250 if ( tvh
->norm
!= TV_NORM_NTSC
)
251 tv_param_height
= 576/tv_param_decimation
;
253 tv_param_height
= 480/tv_param_decimation
;
255 mp_msg(MSGT_TV
, MSGL_INFO
,
256 " MJP: width %d height %d\n", tv_param_width
, tv_param_height
);
260 /* limits on w&h are norm-dependent -- JM */
262 if (tv_param_width
!= -1)
264 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tv_param_width
) == TVI_CONTROL_TRUE
)
265 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tv_param_width
);
268 mp_msg(MSGT_TV
, MSGL_ERR
, "Unable to set requested width: %d\n", tv_param_width
);
269 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tv_param_width
);
274 if (tv_param_height
!= -1)
276 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tv_param_height
) == TVI_CONTROL_TRUE
)
277 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tv_param_height
);
280 mp_msg(MSGT_TV
, MSGL_ERR
, "Unable to set requested height: %d\n", tv_param_height
);
281 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tv_param_height
);
285 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
287 mp_msg(MSGT_TV
, MSGL_WARN
, "Selected input hasn't got a tuner!\n");
291 /* select channel list */
292 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
294 if (!strcasecmp(chanlists
[i
].name
, tv_param_chanlist
))
297 tvh
->chanlist_s
= chanlists
[i
].list
;
302 if (tvh
->chanlist
== -1)
303 mp_msg(MSGT_TV
, MSGL_WARN
, "Unable to find selected channel list! (%s)\n",
306 mp_msg(MSGT_TV
, MSGL_V
, "Selected channel list: %s (including %d channels)\n",
307 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
309 if (tv_param_freq
&& tv_param_channel
)
311 mp_msg(MSGT_TV
, MSGL_WARN
, "You can't set frequency and channel simultaneously!\n");
315 /* Handle channel names */
316 if (tv_param_channels
) {
317 char** channels
= tv_param_channels
;
318 mp_msg(MSGT_TV
, MSGL_INFO
, "TV channel names detected.\n");
319 tv_channel_list
= malloc(sizeof(tv_channels_t
));
320 tv_channel_list
->index
=1;
321 tv_channel_list
->next
=NULL
;
322 tv_channel_list
->prev
=NULL
;
323 tv_channel_current
= tv_channel_list
;
326 char* tmp
= *(channels
++);
327 char* sep
= strchr(tmp
,'-');
331 if (!sep
) continue; // Wrong syntax, but mplayer should not crash
333 strlcpy(tv_channel_current
->name
, sep
+ 1,
334 sizeof(tv_channel_current
->name
));
336 strncpy(tv_channel_current
->number
, tmp
, 5);
338 while ((sep
=strchr(tv_channel_current
->name
, '_')))
341 tv_channel_current
->freq
= 0;
342 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++) {
343 cl
= tvh
->chanlist_s
[i
];
344 if (!strcasecmp(cl
.name
, tv_channel_current
->number
)) {
345 tv_channel_current
->freq
=cl
.freq
;
349 if (tv_channel_current
->freq
== 0)
350 mp_msg(MSGT_TV
, MSGL_ERR
, "Couldn't find frequency for channel %s (%s)\n",
351 tv_channel_current
->number
, tv_channel_current
->name
);
353 sep
= strchr(tv_channel_current
->name
, '-');
354 if ( !sep
) sep
= strchr(tv_channel_current
->name
, '+');
358 if ( sep
[0] == '+' ) tv_channel_current
->freq
+= i
* 100;
359 if ( sep
[0] == '-' ) tv_channel_current
->freq
-= i
* 100;
364 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
365 tv_channel_current->number, tv_channel_current->name,
366 (float)tv_channel_current->freq/1000);*/
368 tv_channel_current
->next
= malloc(sizeof(tv_channels_t
));
369 tv_channel_current
->next
->index
= tv_channel_current
->index
+ 1;
370 tv_channel_current
->next
->prev
= tv_channel_current
;
371 tv_channel_current
->next
->next
= NULL
;
372 tv_channel_current
= tv_channel_current
->next
;
374 if (tv_channel_current
->prev
)
375 tv_channel_current
->prev
->next
= NULL
;
376 free(tv_channel_current
);
378 tv_channel_last_real
= malloc(5);
380 if (tv_channel_list
) {
383 if (tv_param_channel
)
385 if (isdigit(*tv_param_channel
))
386 /* if tv_param_channel begins with a digit interpret it as a number */
387 channel
= atoi(tv_param_channel
);
390 /* if tv_param_channel does not begin with a digit
391 set the first channel that contains tv_param_channel in its name */
393 tv_channel_current
= tv_channel_list
;
394 while ( tv_channel_current
) {
395 if ( strstr(tv_channel_current
->name
, tv_param_channel
) )
397 tv_channel_current
= tv_channel_current
->next
;
399 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
406 tv_channel_current
= tv_channel_list
;
407 for (i
= 1; i
< channel
; i
++)
408 if (tv_channel_current
->next
)
409 tv_channel_current
= tv_channel_current
->next
;
412 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
413 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
414 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
415 tv_channel_last
= tv_channel_current
;
417 /* we need to set frequency */
420 unsigned long freq
= atof(tv_param_freq
)*16;
422 /* set freq in MHz */
423 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
425 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
426 mp_msg(MSGT_TV
, MSGL_V
, "Selected frequency: %lu (%.3f)\n",
427 freq
, (float)freq
/16);
430 if (tv_param_channel
) {
433 mp_msg(MSGT_TV
, MSGL_V
, "Requested channel: %s\n", tv_param_channel
);
434 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
436 cl
= tvh
->chanlist_s
[i
];
437 // printf("count%d: name: %s, freq: %d\n",
438 // i, cl.name, cl.freq);
439 if (!strcasecmp(cl
.name
, tv_param_channel
))
441 strcpy(tv_channel_last_real
, cl
.name
);
443 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
444 cl
.name
, (float)cl
.freq
/1000);
445 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
452 /* grep frequency in chanlist */
457 tv_get_freq(tvh
, &i2
);
459 freq
= (int) (((float)(i2
/16))*1000)+250;
461 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
463 if (tvh
->chanlist_s
[i
].freq
== freq
)
472 /* also start device! */
476 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
479 sh_video_t
*sh_video
;
480 sh_audio_t
*sh_audio
= NULL
;
481 tvi_functions_t
*funcs
;
484 if(!(tvh
=tv_begin())) return NULL
;
485 if (!tv_init(tvh
)) return NULL
;
490 funcs
= tvh
->functions
;
493 sh_video
= new_sh_video(demuxer
, 0);
495 /* get IMAGE FORMAT */
496 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
497 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
498 // sh_video->format = 0x0;
500 /* set FPS and FRAMETIME */
505 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
506 sh_video
->fps
= 25.0f
; /* on PAL */
507 else sh_video
->fps
= tmp
;
510 if (tv_param_fps
!= -1.0f
)
511 sh_video
->fps
= tv_param_fps
;
513 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
515 /* If playback only mode, go to immediate mode, fail silently */
516 if(tv_param_immediate
== 1)
518 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
519 tv_param_noaudio
= 1;
522 /* disable TV audio if -nosound is present */
523 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
524 tv_param_noaudio
= 1;
528 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
531 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
533 demuxer
->video
->sh
= sh_video
;
534 sh_video
->ds
= demuxer
->video
;
535 demuxer
->video
->id
= 0;
536 demuxer
->seekable
= 0;
538 /* here comes audio init */
539 if (tv_param_noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
545 /* yeah, audio is present */
547 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
548 &tv_param_audiorate
);
550 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
557 case AF_FORMAT_U16_LE
:
558 case AF_FORMAT_U16_BE
:
559 case AF_FORMAT_S16_LE
:
560 case AF_FORMAT_S16_BE
:
561 case AF_FORMAT_S32_LE
:
562 case AF_FORMAT_S32_BE
:
563 sh_audio_format
= 0x1; /* PCM */
565 case AF_FORMAT_IMA_ADPCM
:
566 case AF_FORMAT_MU_LAW
:
567 case AF_FORMAT_A_LAW
:
568 case AF_FORMAT_MPEG2
:
571 mp_msg(MSGT_TV
, MSGL_ERR
, "Audio type '%s (%x)' unsupported!\n",
572 af_fmt2str(audio_format
, buf
, 128), audio_format
);
576 sh_audio
= new_sh_audio(demuxer
, 0);
578 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
579 &sh_audio
->samplerate
);
580 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
581 &sh_audio
->samplesize
);
582 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
583 &sh_audio
->channels
);
585 sh_audio
->format
= sh_audio_format
;
586 sh_audio
->sample_format
= audio_format
;
588 sh_audio
->i_bps
= sh_audio
->o_bps
=
589 sh_audio
->samplerate
* sh_audio
->samplesize
*
592 // emulate WF for win32 codecs:
593 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
594 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
595 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
596 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
597 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
598 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
599 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
601 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " TV audio: %d channels, %d bits, %d Hz\n",
602 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
603 sh_audio
->wf
->nSamplesPerSec
);
605 demuxer
->audio
->sh
= sh_audio
;
606 sh_audio
->ds
= demuxer
->audio
;
607 demuxer
->audio
->id
= 0;
611 if(!(funcs
->start(tvh
->priv
))){
618 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tv_param_brightness
);
619 tv_set_color_options(tvh
, TV_COLOR_HUE
, tv_param_hue
);
620 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tv_param_saturation
);
621 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tv_param_contrast
);
626 static void demux_close_tv(demuxer_t
*demuxer
)
628 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
630 tvh
->functions
->uninit(tvh
->priv
);
634 /* ================== STREAM_TV ===================== */
635 tvi_handle_t
*tvi_init_dummy(char *device
);
636 tvi_handle_t
*tvi_init_v4l(char *device
, char *adevice
);
637 tvi_handle_t
*tvi_init_v4l2(char *device
, char *adevice
);
638 tvi_handle_t
*tvi_init_bsdbt848(char *device
);
640 tvi_handle_t
*tv_begin(void)
642 if (!strcmp(tv_param_driver
, "dummy"))
643 return tvi_init_dummy(tv_param_device
);
645 if (!strcmp(tv_param_driver
, "v4l"))
646 return tvi_init_v4l(tv_param_device
, tv_param_adevice
);
649 if (!strcmp(tv_param_driver
, "v4l2"))
650 return tvi_init_v4l2(tv_param_device
, tv_param_adevice
);
652 #ifdef HAVE_TV_BSDBT848
653 if (!strcmp(tv_param_driver
, "bsdbt848"))
654 return tvi_init_bsdbt848(tv_param_device
);
657 mp_msg(MSGT_TV
, MSGL_ERR
, "No such driver: %s\n", tv_param_driver
);
661 int tv_init(tvi_handle_t
*tvh
)
663 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected driver: %s\n", tvh
->info
->short_name
);
664 mp_msg(MSGT_TV
, MSGL_INFO
, " name: %s\n", tvh
->info
->name
);
665 mp_msg(MSGT_TV
, MSGL_INFO
, " author: %s\n", tvh
->info
->author
);
666 if (tvh
->info
->comment
)
667 mp_msg(MSGT_TV
, MSGL_INFO
, " comment: %s\n", tvh
->info
->comment
);
669 return(tvh
->functions
->init(tvh
->priv
));
672 int tv_uninit(tvi_handle_t
*tvh
)
676 if (!tvh
->priv
) return 1;
677 res
=tvh
->functions
->uninit(tvh
->priv
);
678 if(res
) tvh
->priv
=NULL
;
682 /* utilities for mplayer (not mencoder!!) */
683 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
685 tvi_functions_t
*funcs
= tvh
->functions
;
689 case TV_COLOR_BRIGHTNESS
:
690 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
692 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
693 case TV_COLOR_SATURATION
:
694 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
695 case TV_COLOR_CONTRAST
:
696 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
698 mp_msg(MSGT_TV
, MSGL_WARN
, "Unknown color option (%d) specified!\n", opt
);
701 return(TVI_CONTROL_UNKNOWN
);
704 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
706 tvi_functions_t
*funcs
= tvh
->functions
;
710 case TV_COLOR_BRIGHTNESS
:
711 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
713 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
714 case TV_COLOR_SATURATION
:
715 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
716 case TV_COLOR_CONTRAST
:
717 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
719 mp_msg(MSGT_TV
, MSGL_WARN
, "Unknown color option (%d) specified!\n", opt
);
722 return(TVI_CONTROL_UNKNOWN
);
725 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
727 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
729 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
730 mp_msg(MSGT_TV
, MSGL_V
, "Current frequency: %lu (%.3f)\n",
731 *freq
, (float)*freq
/16);
736 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
738 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
740 // unsigned long freq = atof(tv_param_freq)*16;
742 /* set freq in MHz */
743 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
745 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
746 mp_msg(MSGT_TV
, MSGL_V
, "Current frequency: %lu (%.3f)\n",
747 freq
, (float)freq
/16);
752 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
756 if (direction
== TV_CHANNEL_LOWER
)
758 if (tvh
->channel
-1 >= 0)
760 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
761 cl
= tvh
->chanlist_s
[--tvh
->channel
];
762 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
763 cl
.name
, (float)cl
.freq
/1000);
764 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
768 if (direction
== TV_CHANNEL_HIGHER
)
770 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
772 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
773 cl
= tvh
->chanlist_s
[++tvh
->channel
];
774 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
775 cl
.name
, (float)cl
.freq
/1000);
776 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
782 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
783 if (tv_channel_list
) {
784 if (direction
== TV_CHANNEL_HIGHER
) {
785 tv_channel_last
= tv_channel_current
;
786 if (tv_channel_current
->next
)
787 tv_channel_current
= tv_channel_current
->next
;
789 tv_channel_current
= tv_channel_list
;
790 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
791 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n",
792 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
794 if (direction
== TV_CHANNEL_LOWER
) {
795 tv_channel_last
= tv_channel_current
;
796 if (tv_channel_current
->prev
)
797 tv_channel_current
= tv_channel_current
->prev
;
799 while (tv_channel_current
->next
)
800 tv_channel_current
= tv_channel_current
->next
;
801 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
802 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n",
803 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
805 } else tv_step_channel_real(tvh
, direction
);
809 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
813 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
814 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
816 cl
= tvh
->chanlist_s
[i
];
817 // printf("count%d: name: %s, freq: %d\n",
818 // i, cl.name, cl.freq);
819 if (!strcasecmp(cl
.name
, channel
))
822 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
823 cl
.name
, (float)cl
.freq
/1000);
824 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
831 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
834 if (tv_channel_list
) {
835 tv_channel_last
= tv_channel_current
;
836 channel_int
= atoi(channel
);
837 tv_channel_current
= tv_channel_list
;
838 for (i
= 1; i
< channel_int
; i
++)
839 if (tv_channel_current
->next
)
840 tv_channel_current
= tv_channel_current
->next
;
841 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
842 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
843 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
844 } else tv_set_channel_real(tvh
, channel
);
848 int tv_last_channel(tvi_handle_t
*tvh
) {
850 if (tv_channel_list
) {
853 tmp
= tv_channel_last
;
854 tv_channel_last
= tv_channel_current
;
855 tv_channel_current
= tmp
;
857 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
858 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
859 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
864 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
866 cl
= tvh
->chanlist_s
[i
];
867 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
869 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
871 mp_msg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
872 cl
.name
, (float)cl
.freq
/1000);
873 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
881 int tv_step_norm(tvi_handle_t
*tvh
)
884 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
885 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
887 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
888 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
889 mp_msg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
896 int tv_step_chanlist(tvi_handle_t
*tvh
)
901 int tv_set_norm(tvi_handle_t
*tvh
, char* norm
)
903 tvh
->norm
= norm_from_string(tvh
, norm
);
905 mp_msg(MSGT_TV
, MSGL_V
, "Selected norm: %s\n", tv_param_norm
);
906 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
907 mp_msg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
913 demuxer_desc_t demuxer_desc_tv
= {
917 "Alex Beregszaszi, Charles R. Henrich",
922 demux_tv_fill_buffer
,