2 * TV Interface for MPlayer
4 * API idea based on libvo2
6 * Copyright (C) 2001 Alex Beregszaszi
8 * Feb 19, 2002: Significant rewrites by Charles R. Henrich (henrich@msu.edu)
9 * to add support for audio, and bktr *BSD support.
11 * This file is part of MPlayer.
13 * MPlayer is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * MPlayer is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
41 #include "libmpdemux/demuxer.h"
42 #include "libmpdemux/stheader.h"
44 #include "libaf/af_format.h"
45 #include "libmpcodecs/img_format.h"
46 #include "libmpcodecs/dec_teletext.h"
47 #include "libavutil/avstring.h"
48 #include "osdep/timer.h"
52 #include "frequencies.h"
54 tv_channels_t
*tv_channel_list
;
55 tv_channels_t
*tv_channel_current
, *tv_channel_last
;
56 char *tv_channel_last_real
;
58 /* enumerating drivers (like in stream.c) */
59 extern const tvi_info_t tvi_info_dummy
;
60 extern const tvi_info_t tvi_info_dshow
;
61 extern const tvi_info_t tvi_info_v4l
;
62 extern const tvi_info_t tvi_info_v4l2
;
63 extern const tvi_info_t tvi_info_bsdbt848
;
65 /** List of drivers in autodetection order */
66 static const tvi_info_t
* tvi_driver_list
[]={
73 #ifdef CONFIG_TV_BSDBT848
76 #ifdef CONFIG_TV_DSHOW
83 void tv_free_handle(tvi_handle_t
*h
)
94 void tv_start_scan(tvi_handle_t
*tvh
, int start
)
96 mp_msg(MSGT_TV
,MSGL_INFO
,"start scan\n");
97 tvh
->tv_param
->scan
=start
?1:0;
100 static void tv_scan(tvi_handle_t
*tvh
)
104 tv_channels_t
*tv_channel_tmp
=NULL
;
105 tv_channels_t
*tv_channel_add
=NULL
;
107 int found
=0, index
=1;
109 //Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s
110 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
112 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Channel scanner is not available without tuner\n");
113 tvh
->tv_param
->scan
=0;
120 scan
=calloc(1,sizeof(tv_scan_t
));
122 cl
= tvh
->chanlist_s
[scan
->channel_num
];
123 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
124 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
126 if(scan
->scan_timer
>now
)
129 if (tv_get_signal(tvh
)>tvh
->tv_param
->scan_threshold
) {
130 cl
= tvh
->chanlist_s
[scan
->channel_num
];
131 tv_channel_tmp
=tv_channel_list
;
132 while (tv_channel_tmp
) {
134 if (cl
.freq
==tv_channel_tmp
->freq
){
138 tv_channel_add
=tv_channel_tmp
;
139 tv_channel_tmp
=tv_channel_tmp
->next
;
142 mp_msg(MSGT_TV
, MSGL_INFO
, "Found new channel: %s (#%d). \n",cl
.name
,index
);
143 scan
->new_channels
++;
144 tv_channel_tmp
= malloc(sizeof(tv_channels_t
));
145 tv_channel_tmp
->index
=index
;
146 tv_channel_tmp
->next
=NULL
;
147 tv_channel_tmp
->prev
=tv_channel_add
;
148 tv_channel_tmp
->freq
=cl
.freq
;
149 snprintf(tv_channel_tmp
->name
,sizeof(tv_channel_tmp
->name
),"ch%d",index
);
150 strncpy(tv_channel_tmp
->number
, cl
.name
, 5);
151 tv_channel_tmp
->number
[4]='\0';
152 if (!tv_channel_list
)
153 tv_channel_list
=tv_channel_tmp
;
155 tv_channel_add
->next
=tv_channel_tmp
;
156 tv_channel_list
->prev
=tv_channel_tmp
;
159 mp_msg(MSGT_TV
, MSGL_INFO
, "Found existing channel: %s-%s.\n",
160 tv_channel_tmp
->number
,tv_channel_tmp
->name
);
163 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
164 if (scan
->channel_num
>=chanlists
[tvh
->chanlist
].count
) {
165 tvh
->tv_param
->scan
=0;
166 mp_msg(MSGT_TV
, MSGL_INFO
, "TV scan end. Found %d new channels.\n", scan
->new_channels
);
167 tv_channel_tmp
=tv_channel_list
;
169 mp_msg(MSGT_TV
,MSGL_INFO
,"channels=");
170 while(tv_channel_tmp
){
171 mp_msg(MSGT_TV
,MSGL_INFO
,"%s-%s",tv_channel_tmp
->number
,tv_channel_tmp
->name
);
172 if(tv_channel_tmp
->next
)
173 mp_msg(MSGT_TV
,MSGL_INFO
,",");
174 tv_channel_tmp
=tv_channel_tmp
->next
;
176 mp_msg(MSGT_TV
, MSGL_INFO
, "\n");
178 if (!tv_channel_current
) tv_channel_current
=tv_channel_list
;
179 if (tv_channel_current
)
180 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
184 cl
= tvh
->chanlist_s
[scan
->channel_num
];
185 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
186 mp_msg(MSGT_TV
, MSGL_INFO
, "Trying: %s (%.2f). \n",cl
.name
,1e-3*cl
.freq
);
190 /* ================== DEMUX_TV ===================== */
193 0 = EOF(?) or no stream
194 1 = successfully read a packet
196 /* fill demux->video and demux->audio */
198 static int demux_tv_fill_buffer(demuxer_t
*demux
, demux_stream_t
*ds
)
200 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demux
->priv
);
204 /* ================== ADD AUDIO PACKET =================== */
206 if (ds
==demux
->audio
&& tvh
->tv_param
->noaudio
== 0 &&
207 tvh
->functions
->control(tvh
->priv
,
208 TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
210 len
= tvh
->functions
->get_audio_framesize(tvh
->priv
);
212 dp
=new_demux_packet(len
);
213 dp
->flags
|=1; /* Keyframe */
214 dp
->pts
=tvh
->functions
->grab_audio_frame(tvh
->priv
, dp
->buffer
,len
);
215 ds_add_packet(demux
->audio
,dp
);
218 /* ================== ADD VIDEO PACKET =================== */
220 if (ds
==demux
->video
&& tvh
->functions
->control(tvh
->priv
,
221 TVI_CONTROL_IS_VIDEO
, 0) == TVI_CONTROL_TRUE
)
223 len
= tvh
->functions
->get_video_framesize(tvh
->priv
);
224 dp
=new_demux_packet(len
);
225 dp
->flags
|=1; /* Keyframe */
226 dp
->pts
=tvh
->functions
->grab_video_frame(tvh
->priv
, dp
->buffer
, len
);
227 ds_add_packet(demux
->video
,dp
);
230 if (tvh
->tv_param
->scan
) tv_scan(tvh
);
234 static int norm_from_string(tvi_handle_t
*tvh
, char* norm
)
236 const tvi_functions_t
*funcs
= tvh
->functions
;
240 strncpy(str
, norm
, sizeof(str
)-1);
241 str
[sizeof(str
)-1] = '\0';
242 ret
=funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_GET_NORMID
, str
);
244 if(ret
==TVI_CONTROL_TRUE
)
247 if(ret
!=TVI_CONTROL_UNKNOWN
)
249 mp_tmsg(MSGT_TV
, MSGL_WARN
, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm
,"default");
253 if (!strcasecmp(norm
, "pal"))
255 else if (!strcasecmp(norm
, "ntsc"))
257 else if (!strcasecmp(norm
, "secam"))
258 return TV_NORM_SECAM
;
259 else if (!strcasecmp(norm
, "palnc"))
260 return TV_NORM_PALNC
;
261 else if (!strcasecmp(norm
, "palm"))
263 else if (!strcasecmp(norm
, "paln"))
265 else if (!strcasecmp(norm
, "ntscjp"))
266 return TV_NORM_NTSCJP
;
268 mp_tmsg(MSGT_TV
, MSGL_WARN
, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm
, "PAL");
273 static void parse_channels(tvi_handle_t
*tvh
)
275 char** channels
= tvh
->tv_param
->channels
;
277 mp_tmsg(MSGT_TV
, MSGL_INFO
, "TV channel names detected.\n");
278 tv_channel_list
= malloc(sizeof(tv_channels_t
));
279 tv_channel_list
->index
=1;
280 tv_channel_list
->next
=NULL
;
281 tv_channel_list
->prev
=NULL
;
282 tv_channel_current
= tv_channel_list
;
283 tv_channel_current
->norm
= tvh
->norm
;
286 char* tmp
= *(channels
++);
287 char* sep
= strchr(tmp
,'-');
291 if (!sep
) continue; // Wrong syntax, but mplayer should not crash
293 av_strlcpy(tv_channel_current
->name
, sep
+ 1,
294 sizeof(tv_channel_current
->name
));
296 strncpy(tv_channel_current
->number
, tmp
, 5);
297 tv_channel_current
->number
[4]='\0';
299 while ((sep
=strchr(tv_channel_current
->name
, '_')))
302 // if channel number is a number and larger than 1000 threat it as frequency
303 // tmp still contain pointer to null-terminated string with channel number here
305 tv_channel_current
->freq
=atoi(tmp
);
307 tv_channel_current
->freq
= 0;
308 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++) {
309 cl
= tvh
->chanlist_s
[i
];
310 if (!strcasecmp(cl
.name
, tv_channel_current
->number
)) {
311 tv_channel_current
->freq
=cl
.freq
;
316 if (tv_channel_current
->freq
== 0)
317 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Couldn't find frequency for channel %s (%s)\n",
318 tv_channel_current
->number
, tv_channel_current
->name
);
320 sep
= strchr(tv_channel_current
->name
, '-');
321 if ( !sep
) sep
= strchr(tv_channel_current
->name
, '+');
325 if ( sep
[0] == '+' ) tv_channel_current
->freq
+= i
* 100;
326 if ( sep
[0] == '-' ) tv_channel_current
->freq
-= i
* 100;
330 sep
= strchr(tv_channel_current
->name
, '=');
332 tv_channel_current
->norm
= norm_from_string(tvh
, sep
+1);
337 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
338 tv_channel_current->number, tv_channel_current->name,
339 (float)tv_channel_current->freq/1000);*/
341 tv_channel_current
->next
= malloc(sizeof(tv_channels_t
));
342 tv_channel_current
->next
->index
= tv_channel_current
->index
+ 1;
343 tv_channel_current
->next
->prev
= tv_channel_current
;
344 tv_channel_current
->next
->next
= NULL
;
345 tv_channel_current
= tv_channel_current
->next
;
346 tv_channel_current
->norm
= tvh
->norm
;
348 if (tv_channel_current
->prev
)
349 tv_channel_current
->prev
->next
= NULL
;
350 free(tv_channel_current
);
353 int tv_set_norm(tvi_handle_t
*tvh
, char* norm
)
355 tvh
->norm
= norm_from_string(tvh
, norm
);
357 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected norm : %s\n", norm
);
358 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
359 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
362 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
363 &tvh
->tv_param
->teletext
);
367 static int tv_set_norm_i(tvi_handle_t
*tvh
, int norm
)
371 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected norm id: %d\n", norm
);
372 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
373 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
377 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
378 &tvh
->tv_param
->teletext
);
382 static int open_tv(tvi_handle_t
*tvh
)
385 const tvi_functions_t
*funcs
= tvh
->functions
;
386 int tv_fmt_list
[] = {
397 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
399 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: No video input present!\n");
403 if (tvh
->tv_param
->outfmt
== -1)
404 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
406 tvh
->tv_param
->outfmt
= tv_fmt_list
[i
];
407 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
408 &tvh
->tv_param
->outfmt
) == TVI_CONTROL_TRUE
)
413 switch(tvh
->tv_param
->outfmt
)
427 mp_tmsg(MSGT_TV
, MSGL_ERR
,
428 "==================================================================\n"\
429 " WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\
430 " This may cause buggy playback or program crash! Bug reports will\n"\
431 " be ignored! You should try again with YV12 (which is the default\n"\
432 " colorspace) and read the documentation!\n"\
433 "==================================================================\n"
434 ,tvh
->tv_param
->outfmt
);
436 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
439 /* set some params got from cmdline */
440 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
442 #if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
444 #ifdef CONFIG_TV_V4L2
445 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
447 #ifdef CONFIG_TV_DSHOW
448 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
451 tv_set_norm_i(tvh
, tvh
->tv_param
->normid
);
454 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
456 #ifdef CONFIG_TV_V4L1
457 if ( tvh
->tv_param
->mjpeg
)
459 /* set width to expected value */
460 if (tvh
->tv_param
->width
== -1)
462 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
464 if (tvh
->tv_param
->height
== -1)
466 if ( tvh
->norm
!= TV_NORM_NTSC
)
467 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
469 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
471 mp_tmsg(MSGT_TV
, MSGL_INFO
,
472 " MJP: width %d height %d\n", tvh
->tv_param
->width
, tvh
->tv_param
->height
);
476 /* limits on w&h are norm-dependent -- JM */
477 if (tvh
->tv_param
->width
!= -1 && tvh
->tv_param
->height
!= -1) {
478 // first tell the driver both width and height, some drivers do not support setting them independently.
480 dim
[0] = tvh
->tv_param
->width
; dim
[1] = tvh
->tv_param
->height
;
481 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH_HEIGHT
, dim
);
484 if (tvh
->tv_param
->width
!= -1)
486 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
487 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
490 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Unable to set requested width: %d\n", tvh
->tv_param
->width
);
491 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
496 if (tvh
->tv_param
->height
!= -1)
498 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
499 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
502 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Unable to set requested height: %d\n", tvh
->tv_param
->height
);
503 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
507 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
509 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Selected input hasn't got a tuner!\n");
513 /* select channel list */
514 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
516 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
519 tvh
->chanlist_s
= chanlists
[i
].list
;
524 if (tvh
->chanlist
== -1)
525 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Unable to find selected channel list! (%s)\n",
526 tvh
->tv_param
->chanlist
);
528 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected channel list: %s (including %d channels)\n",
529 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
531 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
533 mp_tmsg(MSGT_TV
, MSGL_WARN
, "You can't set frequency and channel simultaneously!\n");
537 /* Handle channel names */
538 if (tvh
->tv_param
->channels
) {
541 tv_channel_last_real
= malloc(5);
543 if (tv_channel_list
) {
546 if (tvh
->tv_param
->channel
)
548 if (isdigit(*tvh
->tv_param
->channel
))
549 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
550 channel
= atoi(tvh
->tv_param
->channel
);
553 /* if tvh->tv_param->channel does not begin with a digit
554 set the first channel that contains tvh->tv_param->channel in its name */
556 tv_channel_current
= tv_channel_list
;
557 while ( tv_channel_current
) {
558 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
560 tv_channel_current
= tv_channel_current
->next
;
562 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
569 tv_channel_current
= tv_channel_list
;
570 for (i
= 1; i
< channel
; i
++)
571 if (tv_channel_current
->next
)
572 tv_channel_current
= tv_channel_current
->next
;
575 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
576 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
577 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
578 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
579 tv_channel_last
= tv_channel_current
;
581 /* we need to set frequency */
582 if (tvh
->tv_param
->freq
)
584 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
586 /* set freq in MHz */
587 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
589 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
590 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected frequency: %lu (%.3f)\n",
591 freq
, (float)freq
/16);
594 if (tvh
->tv_param
->channel
) {
597 mp_tmsg(MSGT_TV
, MSGL_V
, "Requested channel: %s\n", tvh
->tv_param
->channel
);
598 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
600 cl
= tvh
->chanlist_s
[i
];
601 // printf("count%d: name: %s, freq: %d\n",
602 // i, cl.name, cl.freq);
603 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
605 strcpy(tv_channel_last_real
, cl
.name
);
607 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
608 cl
.name
, (float)cl
.freq
/1000);
609 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
616 /* grep frequency in chanlist */
621 tv_get_freq(tvh
, &i2
);
623 freq
= (int) (((float)(i2
/16))*1000)+250;
625 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
627 if (tvh
->chanlist_s
[i
].freq
== freq
)
636 /* also start device! */
640 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
644 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
645 mp_tmsg(MSGT_TV
,MSGL_INFO
,"Available drivers:\n");
646 for(i
=0;tvi_driver_list
[i
];i
++){
647 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
648 if(tvi_driver_list
[i
]->comment
)
649 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
650 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
655 for(i
=0;tvi_driver_list
[i
];i
++){
656 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
657 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
658 //Requested driver initialization failed
659 if (!h
&& tv_param
->driver
)
661 //Driver initialization failed during autodetection process.
665 h
->tv_param
=tv_param
;
666 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n", tvi_driver_list
[i
]->short_name
,
667 tvi_driver_list
[i
]->name
,
668 tvi_driver_list
[i
]->author
,
669 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
670 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
676 mp_tmsg(MSGT_TV
, MSGL_ERR
, "No such driver: %s\n", tv_param
->driver
);
678 mp_tmsg(MSGT_TV
, MSGL_ERR
, "TV driver autodetection failed.\n");
682 static int tv_uninit(tvi_handle_t
*tvh
)
686 if (!tvh
->priv
) return 1;
687 res
=tvh
->functions
->uninit(tvh
->priv
);
695 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
698 sh_video_t
*sh_video
;
699 sh_audio_t
*sh_audio
= NULL
;
700 const tvi_functions_t
*funcs
;
703 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
704 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
706 tvh
->demuxer
= demuxer
;
707 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,
708 &(tvh
->tv_param
->teletext
.device
));
709 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_GET_VBI_PTR
,
716 funcs
= tvh
->functions
;
719 sh_video
= new_sh_video(demuxer
, 0);
721 /* get IMAGE FORMAT */
722 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
723 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
724 // sh_video->format = 0x0;
726 /* set FPS and FRAMETIME */
731 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
732 sh_video
->fps
= 25.0f
; /* on PAL */
733 else sh_video
->fps
= tmp
;
736 if (tvh
->tv_param
->fps
!= -1.0f
)
737 sh_video
->fps
= tvh
->tv_param
->fps
;
739 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
741 /* If playback only mode, go to immediate mode, fail silently */
742 if(tvh
->tv_param
->immediate
== 1)
744 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
745 tvh
->tv_param
->noaudio
= 1;
748 /* disable TV audio if -nosound is present */
749 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
750 tvh
->tv_param
->noaudio
= 1;
754 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
757 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
759 demuxer
->video
->sh
= sh_video
;
760 sh_video
->ds
= demuxer
->video
;
761 demuxer
->video
->id
= 0;
762 demuxer
->seekable
= 0;
764 /* here comes audio init */
765 if (tvh
->tv_param
->noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
771 /* yeah, audio is present */
773 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
774 &tvh
->tv_param
->audiorate
);
776 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
783 case AF_FORMAT_U16_LE
:
784 case AF_FORMAT_U16_BE
:
785 case AF_FORMAT_S16_LE
:
786 case AF_FORMAT_S16_BE
:
787 case AF_FORMAT_S32_LE
:
788 case AF_FORMAT_S32_BE
:
789 sh_audio_format
= 0x1; /* PCM */
791 case AF_FORMAT_IMA_ADPCM
:
792 case AF_FORMAT_MU_LAW
:
793 case AF_FORMAT_A_LAW
:
794 case AF_FORMAT_MPEG2
:
796 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Audio type '%s (%x)' unsupported!\n",
797 af_fmt2str(audio_format
, buf
, 128), audio_format
);
801 sh_audio
= new_sh_audio(demuxer
, 0);
803 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
804 &sh_audio
->samplerate
);
805 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
806 &sh_audio
->samplesize
);
807 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
808 &sh_audio
->channels
);
810 sh_audio
->format
= sh_audio_format
;
811 sh_audio
->sample_format
= audio_format
;
813 sh_audio
->i_bps
= sh_audio
->o_bps
=
814 sh_audio
->samplerate
* sh_audio
->samplesize
*
817 // emulate WF for win32 codecs:
818 sh_audio
->wf
= malloc(sizeof(*sh_audio
->wf
));
819 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
820 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
821 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
822 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
823 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
824 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
826 mp_tmsg(MSGT_DECVIDEO
, MSGL_V
, " TV audio: %d channels, %d bits, %d Hz\n",
827 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
828 sh_audio
->wf
->nSamplesPerSec
);
830 demuxer
->audio
->sh
= sh_audio
;
831 sh_audio
->ds
= demuxer
->audio
;
832 demuxer
->audio
->id
= 0;
836 if(!(funcs
->start(tvh
->priv
))){
843 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
844 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
845 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
846 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
848 if(tvh
->tv_param
->gain
!=-1)
849 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
850 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
852 teletext_control(demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
853 &tvh
->tv_param
->teletext
);
858 static void demux_close_tv(demuxer_t
*demuxer
)
860 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
865 demuxer
->teletext
=NULL
;
868 /* utilities for mplayer (not mencoder!!) */
869 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
871 const tvi_functions_t
*funcs
= tvh
->functions
;
875 case TV_COLOR_BRIGHTNESS
:
876 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
878 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
879 case TV_COLOR_SATURATION
:
880 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
881 case TV_COLOR_CONTRAST
:
882 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
884 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Unknown color option (%d) specified!\n", opt
);
887 return TVI_CONTROL_UNKNOWN
;
890 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
892 const tvi_functions_t
*funcs
= tvh
->functions
;
896 case TV_COLOR_BRIGHTNESS
:
897 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
899 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
900 case TV_COLOR_SATURATION
:
901 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
902 case TV_COLOR_CONTRAST
:
903 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
905 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Unknown color option (%d) specified!\n", opt
);
908 return TVI_CONTROL_UNKNOWN
;
911 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
913 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
915 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
916 mp_tmsg(MSGT_TV
, MSGL_V
, "Current frequency: %lu (%.3f)\n",
917 *freq
, (float)*freq
/16);
922 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
924 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
926 // unsigned long freq = atof(tvh->tv_param->freq)*16;
928 /* set freq in MHz */
929 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
931 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
932 mp_tmsg(MSGT_TV
, MSGL_V
, "Current frequency: %lu (%.3f)\n",
933 freq
, (float)freq
/16);
935 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
936 &tvh
->tv_param
->teletext
);
940 int tv_get_signal(tvi_handle_t
*tvh
)
943 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
944 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
950 /*****************************************************************
951 * \brief tune current frequency by step_interval value
952 * \parameter step_interval increment value in 1/16 MHz
953 * \note frequency is rounded to 1/16 MHz value
957 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
958 unsigned long frequency
;
960 tvh
->tv_param
->scan
=0;
961 tv_get_freq(tvh
,&frequency
);
962 frequency
+=step_interval
;
963 return tv_set_freq(tvh
,frequency
);
966 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
970 tvh
->tv_param
->scan
=0;
971 if (direction
== TV_CHANNEL_LOWER
)
973 if (tvh
->channel
-1 >= 0)
975 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
976 cl
= tvh
->chanlist_s
[--tvh
->channel
];
977 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
978 cl
.name
, (float)cl
.freq
/1000);
979 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
983 if (direction
== TV_CHANNEL_HIGHER
)
985 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
987 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
988 cl
= tvh
->chanlist_s
[++tvh
->channel
];
989 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
990 cl
.name
, (float)cl
.freq
/1000);
991 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
997 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
998 tvh
->tv_param
->scan
=0;
999 if (tv_channel_list
) {
1000 if (direction
== TV_CHANNEL_HIGHER
) {
1001 tv_channel_last
= tv_channel_current
;
1002 if (tv_channel_current
->next
)
1003 tv_channel_current
= tv_channel_current
->next
;
1005 tv_channel_current
= tv_channel_list
;
1007 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1008 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1009 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n",
1010 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1012 if (direction
== TV_CHANNEL_LOWER
) {
1013 tv_channel_last
= tv_channel_current
;
1014 if (tv_channel_current
->prev
)
1015 tv_channel_current
= tv_channel_current
->prev
;
1017 while (tv_channel_current
->next
)
1018 tv_channel_current
= tv_channel_current
->next
;
1019 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1020 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1021 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n",
1022 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1024 } else tv_step_channel_real(tvh
, direction
);
1028 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
1032 tvh
->tv_param
->scan
=0;
1033 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1034 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1036 cl
= tvh
->chanlist_s
[i
];
1037 // printf("count%d: name: %s, freq: %d\n",
1038 // i, cl.name, cl.freq);
1039 if (!strcasecmp(cl
.name
, channel
))
1042 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
1043 cl
.name
, (float)cl
.freq
/1000);
1044 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1051 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
1054 tvh
->tv_param
->scan
=0;
1055 if (tv_channel_list
) {
1056 tv_channel_last
= tv_channel_current
;
1057 channel_int
= atoi(channel
);
1058 tv_channel_current
= tv_channel_list
;
1059 for (i
= 1; i
< channel_int
; i
++)
1060 if (tv_channel_current
->next
)
1061 tv_channel_current
= tv_channel_current
->next
;
1062 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
1063 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1064 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1065 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1066 } else tv_set_channel_real(tvh
, channel
);
1070 int tv_last_channel(tvi_handle_t
*tvh
) {
1072 tvh
->tv_param
->scan
=0;
1073 if (tv_channel_list
) {
1076 tmp
= tv_channel_last
;
1077 tv_channel_last
= tv_channel_current
;
1078 tv_channel_current
= tmp
;
1080 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
1081 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1082 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1083 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1088 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1090 cl
= tvh
->chanlist_s
[i
];
1091 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1093 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1095 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
1096 cl
.name
, (float)cl
.freq
/1000);
1097 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1105 int tv_step_norm(tvi_handle_t
*tvh
)
1108 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1109 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1111 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1112 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1113 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
1117 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
1118 &tvh
->tv_param
->teletext
);
1122 int tv_step_chanlist(tvi_handle_t
*tvh
)
1127 demuxer_desc_t demuxer_desc_tv
= {
1131 "Alex Beregszaszi, Charles R. Henrich",
1136 demux_tv_fill_buffer
,