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.
27 #include "libmpdemux/demuxer.h"
28 #include "libmpdemux/stheader.h"
30 #include "libaf/af_format.h"
31 #include "libmpcodecs/img_format.h"
32 #include "libavutil/avstring.h"
33 #include "osdep/timer.h"
37 #include "frequencies.h"
39 tv_channels_t
*tv_channel_list
;
40 tv_channels_t
*tv_channel_current
, *tv_channel_last
;
41 char *tv_channel_last_real
;
43 /* enumerating drivers (like in stream.c) */
44 extern const tvi_info_t tvi_info_dummy
;
45 extern const tvi_info_t tvi_info_dshow
;
46 extern const tvi_info_t tvi_info_v4l
;
47 extern const tvi_info_t tvi_info_v4l2
;
48 extern const tvi_info_t tvi_info_bsdbt848
;
50 /** List of drivers in autodetection order */
51 static const tvi_info_t
* tvi_driver_list
[]={
58 #ifdef CONFIG_TV_BSDBT848
61 #ifdef CONFIG_TV_DSHOW
68 void tv_start_scan(tvi_handle_t
*tvh
, int start
)
70 mp_msg(MSGT_TV
,MSGL_INFO
,"start scan\n");
71 tvh
->tv_param
->scan
=start
?1:0;
74 static void tv_scan(tvi_handle_t
*tvh
)
78 tv_channels_t
*tv_channel_tmp
=NULL
;
79 tv_channels_t
*tv_channel_add
=NULL
;
83 //Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s
84 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
86 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Channel scanner is not available without tuner\n");
87 tvh
->tv_param
->scan
=0;
94 scan
=calloc(1,sizeof(tv_scan_t
));
96 cl
= tvh
->chanlist_s
[scan
->channel_num
];
97 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
98 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
100 if(scan
->scan_timer
>now
)
103 if (tv_get_signal(tvh
)>tvh
->tv_param
->scan_threshold
) {
104 cl
= tvh
->chanlist_s
[scan
->channel_num
];
105 tv_channel_tmp
=tv_channel_list
;
106 while (tv_channel_tmp
) {
108 if (cl
.freq
==tv_channel_tmp
->freq
){
112 tv_channel_add
=tv_channel_tmp
;
113 tv_channel_tmp
=tv_channel_tmp
->next
;
116 mp_msg(MSGT_TV
, MSGL_INFO
, "Found new channel: %s (#%d). \n",cl
.name
,index
);
117 scan
->new_channels
++;
118 tv_channel_tmp
= malloc(sizeof(tv_channels_t
));
119 tv_channel_tmp
->index
=index
;
120 tv_channel_tmp
->next
=NULL
;
121 tv_channel_tmp
->prev
=tv_channel_add
;
122 tv_channel_tmp
->freq
=cl
.freq
;
123 snprintf(tv_channel_tmp
->name
,sizeof(tv_channel_tmp
->name
),"ch%d",index
);
124 strncpy(tv_channel_tmp
->number
, cl
.name
, 5);
125 tv_channel_tmp
->number
[4]='\0';
126 if (!tv_channel_list
)
127 tv_channel_list
=tv_channel_tmp
;
129 tv_channel_add
->next
=tv_channel_tmp
;
130 tv_channel_list
->prev
=tv_channel_tmp
;
133 mp_msg(MSGT_TV
, MSGL_INFO
, "Found existing channel: %s-%s.\n",
134 tv_channel_tmp
->number
,tv_channel_tmp
->name
);
137 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
138 if (scan
->channel_num
>=chanlists
[tvh
->chanlist
].count
) {
139 tvh
->tv_param
->scan
=0;
140 mp_msg(MSGT_TV
, MSGL_INFO
, "TV scan end. Found %d new channels.\n", scan
->new_channels
);
141 tv_channel_tmp
=tv_channel_list
;
143 mp_msg(MSGT_TV
,MSGL_INFO
,"channels=");
144 while(tv_channel_tmp
){
145 mp_msg(MSGT_TV
,MSGL_INFO
,"%s-%s",tv_channel_tmp
->number
,tv_channel_tmp
->name
);
146 if(tv_channel_tmp
->next
)
147 mp_msg(MSGT_TV
,MSGL_INFO
,",");
148 tv_channel_tmp
=tv_channel_tmp
->next
;
150 mp_msg(MSGT_TV
, MSGL_INFO
, "\n");
152 if (!tv_channel_current
) tv_channel_current
=tv_channel_list
;
153 if (tv_channel_current
)
154 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
158 cl
= tvh
->chanlist_s
[scan
->channel_num
];
159 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
160 mp_msg(MSGT_TV
, MSGL_INFO
, "Trying: %s (%.2f). \n",cl
.name
,1e-3*cl
.freq
);
164 /* ================== DEMUX_TV ===================== */
167 0 = EOF(?) or no stream
168 1 = successfully read a packet
170 /* fill demux->video and demux->audio */
172 static int demux_tv_fill_buffer(demuxer_t
*demux
, demux_stream_t
*ds
)
174 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demux
->priv
);
178 /* ================== ADD AUDIO PACKET =================== */
180 if (ds
==demux
->audio
&& tvh
->tv_param
->noaudio
== 0 &&
181 tvh
->functions
->control(tvh
->priv
,
182 TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
184 len
= tvh
->functions
->get_audio_framesize(tvh
->priv
);
186 dp
=new_demux_packet(len
);
187 dp
->flags
|=1; /* Keyframe */
188 dp
->pts
=tvh
->functions
->grab_audio_frame(tvh
->priv
, dp
->buffer
,len
);
189 ds_add_packet(demux
->audio
,dp
);
192 /* ================== ADD VIDEO PACKET =================== */
194 if (ds
==demux
->video
&& tvh
->functions
->control(tvh
->priv
,
195 TVI_CONTROL_IS_VIDEO
, 0) == TVI_CONTROL_TRUE
)
197 len
= tvh
->functions
->get_video_framesize(tvh
->priv
);
198 dp
=new_demux_packet(len
);
199 dp
->flags
|=1; /* Keyframe */
200 dp
->pts
=tvh
->functions
->grab_video_frame(tvh
->priv
, dp
->buffer
, len
);
201 ds_add_packet(demux
->video
,dp
);
204 if (tvh
->tv_param
->scan
) tv_scan(tvh
);
208 static int norm_from_string(tvi_handle_t
*tvh
, char* norm
)
210 const tvi_functions_t
*funcs
= tvh
->functions
;
214 strncpy(str
, norm
, sizeof(str
)-1);
215 str
[sizeof(str
)-1] = '\0';
216 ret
=funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_GET_NORMID
, str
);
218 if(ret
==TVI_CONTROL_TRUE
)
221 if(ret
!=TVI_CONTROL_UNKNOWN
)
223 mp_tmsg(MSGT_TV
, MSGL_WARN
, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm
,"default");
227 if (!strcasecmp(norm
, "pal"))
229 else if (!strcasecmp(norm
, "ntsc"))
231 else if (!strcasecmp(norm
, "secam"))
232 return TV_NORM_SECAM
;
233 else if (!strcasecmp(norm
, "palnc"))
234 return TV_NORM_PALNC
;
235 else if (!strcasecmp(norm
, "palm"))
237 else if (!strcasecmp(norm
, "paln"))
239 else if (!strcasecmp(norm
, "ntscjp"))
240 return TV_NORM_NTSCJP
;
242 mp_tmsg(MSGT_TV
, MSGL_WARN
, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm
, "PAL");
247 static void parse_channels(tvi_handle_t
*tvh
)
249 char** channels
= tvh
->tv_param
->channels
;
251 mp_tmsg(MSGT_TV
, MSGL_INFO
, "TV channel names detected.\n");
252 tv_channel_list
= malloc(sizeof(tv_channels_t
));
253 tv_channel_list
->index
=1;
254 tv_channel_list
->next
=NULL
;
255 tv_channel_list
->prev
=NULL
;
256 tv_channel_current
= tv_channel_list
;
257 tv_channel_current
->norm
= tvh
->norm
;
260 char* tmp
= *(channels
++);
261 char* sep
= strchr(tmp
,'-');
265 if (!sep
) continue; // Wrong syntax, but mplayer should not crash
267 av_strlcpy(tv_channel_current
->name
, sep
+ 1,
268 sizeof(tv_channel_current
->name
));
270 strncpy(tv_channel_current
->number
, tmp
, 5);
271 tv_channel_current
->number
[4]='\0';
273 while ((sep
=strchr(tv_channel_current
->name
, '_')))
276 // if channel number is a number and larger than 1000 threat it as frequency
277 // tmp still contain pointer to null-terminated string with channel number here
279 tv_channel_current
->freq
=atoi(tmp
);
281 tv_channel_current
->freq
= 0;
282 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++) {
283 cl
= tvh
->chanlist_s
[i
];
284 if (!strcasecmp(cl
.name
, tv_channel_current
->number
)) {
285 tv_channel_current
->freq
=cl
.freq
;
290 if (tv_channel_current
->freq
== 0)
291 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Couldn't find frequency for channel %s (%s)\n",
292 tv_channel_current
->number
, tv_channel_current
->name
);
294 sep
= strchr(tv_channel_current
->name
, '-');
295 if ( !sep
) sep
= strchr(tv_channel_current
->name
, '+');
299 if ( sep
[0] == '+' ) tv_channel_current
->freq
+= i
* 100;
300 if ( sep
[0] == '-' ) tv_channel_current
->freq
-= i
* 100;
304 sep
= strchr(tv_channel_current
->name
, '=');
306 tv_channel_current
->norm
= norm_from_string(tvh
, sep
+1);
311 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
312 tv_channel_current->number, tv_channel_current->name,
313 (float)tv_channel_current->freq/1000);*/
315 tv_channel_current
->next
= malloc(sizeof(tv_channels_t
));
316 tv_channel_current
->next
->index
= tv_channel_current
->index
+ 1;
317 tv_channel_current
->next
->prev
= tv_channel_current
;
318 tv_channel_current
->next
->next
= NULL
;
319 tv_channel_current
= tv_channel_current
->next
;
320 tv_channel_current
->norm
= tvh
->norm
;
322 if (tv_channel_current
->prev
)
323 tv_channel_current
->prev
->next
= NULL
;
324 free(tv_channel_current
);
327 int tv_set_norm(tvi_handle_t
*tvh
, char* norm
)
329 tvh
->norm
= norm_from_string(tvh
, norm
);
331 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected norm : %s\n", norm
);
332 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
333 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
336 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
340 static int tv_set_norm_i(tvi_handle_t
*tvh
, int norm
)
344 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected norm id: %d\n", norm
);
345 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
346 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
350 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
354 static int open_tv(tvi_handle_t
*tvh
)
357 const tvi_functions_t
*funcs
= tvh
->functions
;
358 int tv_fmt_list
[] = {
369 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
371 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: No video input present!\n");
375 if (tvh
->tv_param
->outfmt
== -1)
376 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
378 tvh
->tv_param
->outfmt
= tv_fmt_list
[i
];
379 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
380 &tvh
->tv_param
->outfmt
) == TVI_CONTROL_TRUE
)
385 switch(tvh
->tv_param
->outfmt
)
399 mp_tmsg(MSGT_TV
, MSGL_ERR
,
400 "==================================================================\n"\
401 " WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\
402 " This may cause buggy playback or program crash! Bug reports will\n"\
403 " be ignored! You should try again with YV12 (which is the default\n"\
404 " colorspace) and read the documentation!\n"\
405 "==================================================================\n"
406 ,tvh
->tv_param
->outfmt
);
408 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
411 /* set some params got from cmdline */
412 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
414 #if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
416 #ifdef CONFIG_TV_V4L2
417 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
419 #ifdef CONFIG_TV_DSHOW
420 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
423 tv_set_norm_i(tvh
, tvh
->tv_param
->normid
);
426 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
428 #ifdef CONFIG_TV_V4L1
429 if ( tvh
->tv_param
->mjpeg
)
431 /* set width to expected value */
432 if (tvh
->tv_param
->width
== -1)
434 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
436 if (tvh
->tv_param
->height
== -1)
438 if ( tvh
->norm
!= TV_NORM_NTSC
)
439 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
441 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
443 mp_tmsg(MSGT_TV
, MSGL_INFO
,
444 " MJP: width %d height %d\n", tvh
->tv_param
->width
, tvh
->tv_param
->height
);
448 /* limits on w&h are norm-dependent -- JM */
449 if (tvh
->tv_param
->width
!= -1 && tvh
->tv_param
->height
!= -1) {
450 // first tell the driver both width and height, some drivers do not support setting them independently.
452 dim
[0] = tvh
->tv_param
->width
; dim
[1] = tvh
->tv_param
->height
;
453 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH_HEIGHT
, dim
);
456 if (tvh
->tv_param
->width
!= -1)
458 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
459 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
462 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Unable to set requested width: %d\n", tvh
->tv_param
->width
);
463 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
468 if (tvh
->tv_param
->height
!= -1)
470 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
471 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
474 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Unable to set requested height: %d\n", tvh
->tv_param
->height
);
475 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
479 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
481 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Selected input hasn't got a tuner!\n");
485 /* select channel list */
486 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
488 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
491 tvh
->chanlist_s
= chanlists
[i
].list
;
496 if (tvh
->chanlist
== -1)
497 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Unable to find selected channel list! (%s)\n",
498 tvh
->tv_param
->chanlist
);
500 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected channel list: %s (including %d channels)\n",
501 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
503 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
505 mp_tmsg(MSGT_TV
, MSGL_WARN
, "You can't set frequency and channel simultaneously!\n");
509 /* Handle channel names */
510 if (tvh
->tv_param
->channels
) {
513 tv_channel_last_real
= malloc(5);
515 if (tv_channel_list
) {
518 if (tvh
->tv_param
->channel
)
520 if (isdigit(*tvh
->tv_param
->channel
))
521 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
522 channel
= atoi(tvh
->tv_param
->channel
);
525 /* if tvh->tv_param->channel does not begin with a digit
526 set the first channel that contains tvh->tv_param->channel in its name */
528 tv_channel_current
= tv_channel_list
;
529 while ( tv_channel_current
) {
530 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
532 tv_channel_current
= tv_channel_current
->next
;
534 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
541 tv_channel_current
= tv_channel_list
;
542 for (i
= 1; i
< channel
; i
++)
543 if (tv_channel_current
->next
)
544 tv_channel_current
= tv_channel_current
->next
;
547 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
548 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
549 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
550 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
551 tv_channel_last
= tv_channel_current
;
553 /* we need to set frequency */
554 if (tvh
->tv_param
->freq
)
556 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
558 /* set freq in MHz */
559 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
561 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
562 mp_tmsg(MSGT_TV
, MSGL_V
, "Selected frequency: %lu (%.3f)\n",
563 freq
, (float)freq
/16);
566 if (tvh
->tv_param
->channel
) {
569 mp_tmsg(MSGT_TV
, MSGL_V
, "Requested channel: %s\n", tvh
->tv_param
->channel
);
570 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
572 cl
= tvh
->chanlist_s
[i
];
573 // printf("count%d: name: %s, freq: %d\n",
574 // i, cl.name, cl.freq);
575 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
577 strcpy(tv_channel_last_real
, cl
.name
);
579 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
580 cl
.name
, (float)cl
.freq
/1000);
581 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
588 /* grep frequency in chanlist */
593 tv_get_freq(tvh
, &i2
);
595 freq
= (int) (((float)(i2
/16))*1000)+250;
597 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
599 if (tvh
->chanlist_s
[i
].freq
== freq
)
608 /* also start device! */
612 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
616 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
617 mp_tmsg(MSGT_TV
,MSGL_INFO
,"Available drivers:\n");
618 for(i
=0;tvi_driver_list
[i
];i
++){
619 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
620 if(tvi_driver_list
[i
]->comment
)
621 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
622 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
627 for(i
=0;tvi_driver_list
[i
];i
++){
628 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
629 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
630 //Requested driver initialization failed
631 if (!h
&& tv_param
->driver
)
633 //Driver initialization failed during autodetection process.
637 h
->tv_param
=tv_param
;
638 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
,
639 tvi_driver_list
[i
]->name
,
640 tvi_driver_list
[i
]->author
,
641 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
642 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
648 mp_tmsg(MSGT_TV
, MSGL_ERR
, "No such driver: %s\n", tv_param
->driver
);
650 mp_tmsg(MSGT_TV
, MSGL_ERR
, "TV driver autodetection failed.\n");
654 static int tv_uninit(tvi_handle_t
*tvh
)
658 if (!tvh
->priv
) return 1;
659 res
=tvh
->functions
->uninit(tvh
->priv
);
667 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
670 sh_video_t
*sh_video
;
671 sh_audio_t
*sh_audio
= NULL
;
672 const tvi_functions_t
*funcs
;
675 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
676 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
678 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,&(tvh
->tv_param
->tdevice
));
684 funcs
= tvh
->functions
;
687 sh_video
= new_sh_video(demuxer
, 0);
689 /* get IMAGE FORMAT */
690 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
691 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
692 // sh_video->format = 0x0;
694 /* set FPS and FRAMETIME */
699 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
700 sh_video
->fps
= 25.0f
; /* on PAL */
701 else sh_video
->fps
= tmp
;
704 if (tvh
->tv_param
->fps
!= -1.0f
)
705 sh_video
->fps
= tvh
->tv_param
->fps
;
707 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
709 /* If playback only mode, go to immediate mode, fail silently */
710 if(tvh
->tv_param
->immediate
== 1)
712 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
713 tvh
->tv_param
->noaudio
= 1;
716 /* disable TV audio if -nosound is present */
717 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
718 tvh
->tv_param
->noaudio
= 1;
722 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
725 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
727 demuxer
->video
->sh
= sh_video
;
728 sh_video
->ds
= demuxer
->video
;
729 demuxer
->video
->id
= 0;
730 demuxer
->seekable
= 0;
732 /* here comes audio init */
733 if (tvh
->tv_param
->noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
739 /* yeah, audio is present */
741 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
742 &tvh
->tv_param
->audiorate
);
744 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
751 case AF_FORMAT_U16_LE
:
752 case AF_FORMAT_U16_BE
:
753 case AF_FORMAT_S16_LE
:
754 case AF_FORMAT_S16_BE
:
755 case AF_FORMAT_S32_LE
:
756 case AF_FORMAT_S32_BE
:
757 sh_audio_format
= 0x1; /* PCM */
759 case AF_FORMAT_IMA_ADPCM
:
760 case AF_FORMAT_MU_LAW
:
761 case AF_FORMAT_A_LAW
:
762 case AF_FORMAT_MPEG2
:
765 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Audio type '%s (%x)' unsupported!\n",
766 af_fmt2str(audio_format
, buf
, 128), audio_format
);
770 sh_audio
= new_sh_audio(demuxer
, 0);
772 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
773 &sh_audio
->samplerate
);
774 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
775 &sh_audio
->samplesize
);
776 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
777 &sh_audio
->channels
);
779 sh_audio
->format
= sh_audio_format
;
780 sh_audio
->sample_format
= audio_format
;
782 sh_audio
->i_bps
= sh_audio
->o_bps
=
783 sh_audio
->samplerate
* sh_audio
->samplesize
*
786 // emulate WF for win32 codecs:
787 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
788 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
789 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
790 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
791 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
792 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
793 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
795 mp_tmsg(MSGT_DECVIDEO
, MSGL_V
, " TV audio: %d channels, %d bits, %d Hz\n",
796 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
797 sh_audio
->wf
->nSamplesPerSec
);
799 demuxer
->audio
->sh
= sh_audio
;
800 sh_audio
->ds
= demuxer
->audio
;
801 demuxer
->audio
->id
= 0;
805 if(!(funcs
->start(tvh
->priv
))){
812 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
813 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
814 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
815 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
817 if(tvh
->tv_param
->gain
!=-1)
818 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
819 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
821 funcs
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
826 static void demux_close_tv(demuxer_t
*demuxer
)
828 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
835 /* utilities for mplayer (not mencoder!!) */
836 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
838 const tvi_functions_t
*funcs
= tvh
->functions
;
842 case TV_COLOR_BRIGHTNESS
:
843 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
845 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
846 case TV_COLOR_SATURATION
:
847 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
848 case TV_COLOR_CONTRAST
:
849 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
851 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Unknown color option (%d) specified!\n", opt
);
854 return TVI_CONTROL_UNKNOWN
;
857 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
859 const tvi_functions_t
*funcs
= tvh
->functions
;
863 case TV_COLOR_BRIGHTNESS
:
864 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
866 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
867 case TV_COLOR_SATURATION
:
868 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
869 case TV_COLOR_CONTRAST
:
870 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
872 mp_tmsg(MSGT_TV
, MSGL_WARN
, "Unknown color option (%d) specified!\n", opt
);
875 return TVI_CONTROL_UNKNOWN
;
878 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
880 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
882 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
883 mp_tmsg(MSGT_TV
, MSGL_V
, "Current frequency: %lu (%.3f)\n",
884 *freq
, (float)*freq
/16);
889 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
891 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
893 // unsigned long freq = atof(tvh->tv_param->freq)*16;
895 /* set freq in MHz */
896 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
898 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
899 mp_tmsg(MSGT_TV
, MSGL_V
, "Current frequency: %lu (%.3f)\n",
900 freq
, (float)freq
/16);
902 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
906 int tv_get_signal(tvi_handle_t
*tvh
)
909 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
910 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
916 /*****************************************************************
917 * \brief tune current frequency by step_interval value
918 * \parameter step_interval increment value in 1/16 MHz
919 * \note frequency is rounded to 1/16 MHz value
923 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
924 unsigned long frequency
;
926 tvh
->tv_param
->scan
=0;
927 tv_get_freq(tvh
,&frequency
);
928 frequency
+=step_interval
;
929 return tv_set_freq(tvh
,frequency
);
932 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
936 tvh
->tv_param
->scan
=0;
937 if (direction
== TV_CHANNEL_LOWER
)
939 if (tvh
->channel
-1 >= 0)
941 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
942 cl
= tvh
->chanlist_s
[--tvh
->channel
];
943 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
944 cl
.name
, (float)cl
.freq
/1000);
945 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
949 if (direction
== TV_CHANNEL_HIGHER
)
951 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
953 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
954 cl
= tvh
->chanlist_s
[++tvh
->channel
];
955 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
956 cl
.name
, (float)cl
.freq
/1000);
957 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
963 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
964 tvh
->tv_param
->scan
=0;
965 if (tv_channel_list
) {
966 if (direction
== TV_CHANNEL_HIGHER
) {
967 tv_channel_last
= tv_channel_current
;
968 if (tv_channel_current
->next
)
969 tv_channel_current
= tv_channel_current
->next
;
971 tv_channel_current
= tv_channel_list
;
973 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
974 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
975 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n",
976 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
978 if (direction
== TV_CHANNEL_LOWER
) {
979 tv_channel_last
= tv_channel_current
;
980 if (tv_channel_current
->prev
)
981 tv_channel_current
= tv_channel_current
->prev
;
983 while (tv_channel_current
->next
)
984 tv_channel_current
= tv_channel_current
->next
;
985 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
986 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
987 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n",
988 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
990 } else tv_step_channel_real(tvh
, direction
);
994 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
998 tvh
->tv_param
->scan
=0;
999 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1000 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1002 cl
= tvh
->chanlist_s
[i
];
1003 // printf("count%d: name: %s, freq: %d\n",
1004 // i, cl.name, cl.freq);
1005 if (!strcasecmp(cl
.name
, channel
))
1008 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
1009 cl
.name
, (float)cl
.freq
/1000);
1010 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1017 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
1020 tvh
->tv_param
->scan
=0;
1021 if (tv_channel_list
) {
1022 tv_channel_last
= tv_channel_current
;
1023 channel_int
= atoi(channel
);
1024 tv_channel_current
= tv_channel_list
;
1025 for (i
= 1; i
< channel_int
; i
++)
1026 if (tv_channel_current
->next
)
1027 tv_channel_current
= tv_channel_current
->next
;
1028 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
1029 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1030 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1031 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1032 } else tv_set_channel_real(tvh
, channel
);
1036 int tv_last_channel(tvi_handle_t
*tvh
) {
1038 tvh
->tv_param
->scan
=0;
1039 if (tv_channel_list
) {
1042 tmp
= tv_channel_last
;
1043 tv_channel_last
= tv_channel_current
;
1044 tv_channel_current
= tmp
;
1046 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current
->number
,
1047 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1048 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1049 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1054 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1056 cl
= tvh
->chanlist_s
[i
];
1057 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1059 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1061 mp_tmsg(MSGT_TV
, MSGL_INFO
, "Selected channel: %s (freq: %.3f)\n",
1062 cl
.name
, (float)cl
.freq
/1000);
1063 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1071 int tv_step_norm(tvi_handle_t
*tvh
)
1074 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1075 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1077 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1078 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1079 mp_tmsg(MSGT_TV
, MSGL_ERR
, "Error: Cannot set norm!\n");
1083 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1087 int tv_step_chanlist(tvi_handle_t
*tvh
)
1092 demuxer_desc_t demuxer_desc_tv
= {
1096 "Alex Beregszaszi, Charles R. Henrich",
1101 demux_tv_fill_buffer
,