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 "libmpcodecs/dec_teletext.h"
33 #include "libavutil/avstring.h"
34 #include "osdep/timer.h"
38 #include "frequencies.h"
40 tv_channels_t
*tv_channel_list
;
41 tv_channels_t
*tv_channel_current
, *tv_channel_last
;
42 char *tv_channel_last_real
;
44 /* enumerating drivers (like in stream.c) */
45 extern const tvi_info_t tvi_info_dummy
;
46 extern const tvi_info_t tvi_info_dshow
;
47 extern const tvi_info_t tvi_info_v4l
;
48 extern const tvi_info_t tvi_info_v4l2
;
49 extern const tvi_info_t tvi_info_bsdbt848
;
51 /** List of drivers in autodetection order */
52 static const tvi_info_t
* tvi_driver_list
[]={
59 #ifdef CONFIG_TV_BSDBT848
62 #ifdef CONFIG_TV_DSHOW
69 void tv_start_scan(tvi_handle_t
*tvh
, int start
)
71 mp_msg(MSGT_TV
,MSGL_INFO
,"start scan\n");
72 tvh
->tv_param
->scan
=start
?1:0;
75 static void tv_scan(tvi_handle_t
*tvh
)
79 tv_channels_t
*tv_channel_tmp
=NULL
;
80 tv_channels_t
*tv_channel_add
=NULL
;
84 //Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s
85 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
87 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ScannerNotAvailableWithoutTuner
);
88 tvh
->tv_param
->scan
=0;
95 scan
=calloc(1,sizeof(tv_scan_t
));
97 cl
= tvh
->chanlist_s
[scan
->channel_num
];
98 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
99 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
101 if(scan
->scan_timer
>now
)
104 if (tv_get_signal(tvh
)>tvh
->tv_param
->scan_threshold
) {
105 cl
= tvh
->chanlist_s
[scan
->channel_num
];
106 tv_channel_tmp
=tv_channel_list
;
107 while (tv_channel_tmp
) {
109 if (cl
.freq
==tv_channel_tmp
->freq
){
113 tv_channel_add
=tv_channel_tmp
;
114 tv_channel_tmp
=tv_channel_tmp
->next
;
117 mp_msg(MSGT_TV
, MSGL_INFO
, "Found new channel: %s (#%d). \n",cl
.name
,index
);
118 scan
->new_channels
++;
119 tv_channel_tmp
= malloc(sizeof(tv_channels_t
));
120 tv_channel_tmp
->index
=index
;
121 tv_channel_tmp
->next
=NULL
;
122 tv_channel_tmp
->prev
=tv_channel_add
;
123 tv_channel_tmp
->freq
=cl
.freq
;
124 snprintf(tv_channel_tmp
->name
,sizeof(tv_channel_tmp
->name
),"ch%d",index
);
125 strncpy(tv_channel_tmp
->number
, cl
.name
, 5);
126 tv_channel_tmp
->number
[4]='\0';
127 if (!tv_channel_list
)
128 tv_channel_list
=tv_channel_tmp
;
130 tv_channel_add
->next
=tv_channel_tmp
;
131 tv_channel_list
->prev
=tv_channel_tmp
;
134 mp_msg(MSGT_TV
, MSGL_INFO
, "Found existing channel: %s-%s.\n",
135 tv_channel_tmp
->number
,tv_channel_tmp
->name
);
138 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
139 if (scan
->channel_num
>=chanlists
[tvh
->chanlist
].count
) {
140 tvh
->tv_param
->scan
=0;
141 mp_msg(MSGT_TV
, MSGL_INFO
, "TV scan end. Found %d new channels.\n", scan
->new_channels
);
142 tv_channel_tmp
=tv_channel_list
;
144 mp_msg(MSGT_TV
,MSGL_INFO
,"channels=");
145 while(tv_channel_tmp
){
146 mp_msg(MSGT_TV
,MSGL_INFO
,"%s-%s",tv_channel_tmp
->number
,tv_channel_tmp
->name
);
147 if(tv_channel_tmp
->next
)
148 mp_msg(MSGT_TV
,MSGL_INFO
,",");
149 tv_channel_tmp
=tv_channel_tmp
->next
;
151 mp_msg(MSGT_TV
, MSGL_INFO
, "\n");
153 if (!tv_channel_current
) tv_channel_current
=tv_channel_list
;
154 if (tv_channel_current
)
155 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
159 cl
= tvh
->chanlist_s
[scan
->channel_num
];
160 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
161 mp_msg(MSGT_TV
, MSGL_INFO
, "Trying: %s (%.2f). \n",cl
.name
,1e-3*cl
.freq
);
165 /* ================== DEMUX_TV ===================== */
168 0 = EOF(?) or no stream
169 1 = successfully read a packet
171 /* fill demux->video and demux->audio */
173 static int demux_tv_fill_buffer(demuxer_t
*demux
, demux_stream_t
*ds
)
175 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demux
->priv
);
179 /* ================== ADD AUDIO PACKET =================== */
181 if (ds
==demux
->audio
&& tvh
->tv_param
->noaudio
== 0 &&
182 tvh
->functions
->control(tvh
->priv
,
183 TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
185 len
= tvh
->functions
->get_audio_framesize(tvh
->priv
);
187 dp
=new_demux_packet(len
);
188 dp
->flags
|=1; /* Keyframe */
189 dp
->pts
=tvh
->functions
->grab_audio_frame(tvh
->priv
, dp
->buffer
,len
);
190 ds_add_packet(demux
->audio
,dp
);
193 /* ================== ADD VIDEO PACKET =================== */
195 if (ds
==demux
->video
&& tvh
->functions
->control(tvh
->priv
,
196 TVI_CONTROL_IS_VIDEO
, 0) == TVI_CONTROL_TRUE
)
198 len
= tvh
->functions
->get_video_framesize(tvh
->priv
);
199 dp
=new_demux_packet(len
);
200 dp
->flags
|=1; /* Keyframe */
201 dp
->pts
=tvh
->functions
->grab_video_frame(tvh
->priv
, dp
->buffer
, len
);
202 ds_add_packet(demux
->video
,dp
);
205 if (tvh
->tv_param
->scan
) tv_scan(tvh
);
209 static int norm_from_string(tvi_handle_t
*tvh
, char* norm
)
211 const tvi_functions_t
*funcs
= tvh
->functions
;
215 strncpy(str
, norm
, sizeof(str
)-1);
216 str
[sizeof(str
)-1] = '\0';
217 ret
=funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_GET_NORMID
, str
);
219 if(ret
==TVI_CONTROL_TRUE
)
222 if(ret
!=TVI_CONTROL_UNKNOWN
)
224 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_BogusNormParameter
, norm
,"default");
228 if (!strcasecmp(norm
, "pal"))
230 else if (!strcasecmp(norm
, "ntsc"))
232 else if (!strcasecmp(norm
, "secam"))
233 return TV_NORM_SECAM
;
234 else if (!strcasecmp(norm
, "palnc"))
235 return TV_NORM_PALNC
;
236 else if (!strcasecmp(norm
, "palm"))
238 else if (!strcasecmp(norm
, "paln"))
240 else if (!strcasecmp(norm
, "ntscjp"))
241 return TV_NORM_NTSCJP
;
243 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_BogusNormParameter
, norm
, "PAL");
248 static void parse_channels(tvi_handle_t
*tvh
)
250 char** channels
= tvh
->tv_param
->channels
;
252 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_ChannelNamesDetected
);
253 tv_channel_list
= malloc(sizeof(tv_channels_t
));
254 tv_channel_list
->index
=1;
255 tv_channel_list
->next
=NULL
;
256 tv_channel_list
->prev
=NULL
;
257 tv_channel_current
= tv_channel_list
;
258 tv_channel_current
->norm
= tvh
->norm
;
261 char* tmp
= *(channels
++);
262 char* sep
= strchr(tmp
,'-');
266 if (!sep
) continue; // Wrong syntax, but mplayer should not crash
268 av_strlcpy(tv_channel_current
->name
, sep
+ 1,
269 sizeof(tv_channel_current
->name
));
271 strncpy(tv_channel_current
->number
, tmp
, 5);
272 tv_channel_current
->number
[4]='\0';
274 while ((sep
=strchr(tv_channel_current
->name
, '_')))
277 // if channel number is a number and larger than 1000 threat it as frequency
278 // tmp still contain pointer to null-terminated string with channel number here
280 tv_channel_current
->freq
=atoi(tmp
);
282 tv_channel_current
->freq
= 0;
283 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++) {
284 cl
= tvh
->chanlist_s
[i
];
285 if (!strcasecmp(cl
.name
, tv_channel_current
->number
)) {
286 tv_channel_current
->freq
=cl
.freq
;
291 if (tv_channel_current
->freq
== 0)
292 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoFreqForChannel
,
293 tv_channel_current
->number
, tv_channel_current
->name
);
295 sep
= strchr(tv_channel_current
->name
, '-');
296 if ( !sep
) sep
= strchr(tv_channel_current
->name
, '+');
300 if ( sep
[0] == '+' ) tv_channel_current
->freq
+= i
* 100;
301 if ( sep
[0] == '-' ) tv_channel_current
->freq
-= i
* 100;
305 sep
= strchr(tv_channel_current
->name
, '=');
307 tv_channel_current
->norm
= norm_from_string(tvh
, sep
+1);
312 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
313 tv_channel_current->number, tv_channel_current->name,
314 (float)tv_channel_current->freq/1000);*/
316 tv_channel_current
->next
= malloc(sizeof(tv_channels_t
));
317 tv_channel_current
->next
->index
= tv_channel_current
->index
+ 1;
318 tv_channel_current
->next
->prev
= tv_channel_current
;
319 tv_channel_current
->next
->next
= NULL
;
320 tv_channel_current
= tv_channel_current
->next
;
321 tv_channel_current
->norm
= tvh
->norm
;
323 if (tv_channel_current
->prev
)
324 tv_channel_current
->prev
->next
= NULL
;
325 free(tv_channel_current
);
328 int tv_set_norm(tvi_handle_t
*tvh
, char* norm
)
330 tvh
->norm
= norm_from_string(tvh
, norm
);
332 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNorm
, norm
);
333 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
334 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
337 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
338 &tvh
->tv_param
->teletext
);
342 int tv_set_norm_i(tvi_handle_t
*tvh
, int norm
)
346 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNormId
, norm
);
347 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
348 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
352 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
353 &tvh
->tv_param
->teletext
);
357 static int open_tv(tvi_handle_t
*tvh
)
360 const tvi_functions_t
*funcs
= tvh
->functions
;
361 int tv_fmt_list
[] = {
372 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
374 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoVideoInputPresent
);
378 if (tvh
->tv_param
->outfmt
== -1)
379 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
381 tvh
->tv_param
->outfmt
= tv_fmt_list
[i
];
382 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
383 &tvh
->tv_param
->outfmt
) == TVI_CONTROL_TRUE
)
388 switch(tvh
->tv_param
->outfmt
)
402 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnknownImageFormat
,tvh
->tv_param
->outfmt
);
404 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
407 /* set some params got from cmdline */
408 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
410 #if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
412 #ifdef CONFIG_TV_V4L2
413 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
415 #ifdef CONFIG_TV_DSHOW
416 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
419 tv_set_norm_i(tvh
, tvh
->tv_param
->normid
);
422 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
424 #ifdef CONFIG_TV_V4L1
425 if ( tvh
->tv_param
->mjpeg
)
427 /* set width to expected value */
428 if (tvh
->tv_param
->width
== -1)
430 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
432 if (tvh
->tv_param
->height
== -1)
434 if ( tvh
->norm
!= TV_NORM_NTSC
)
435 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
437 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
439 mp_msg(MSGT_TV
, MSGL_INFO
,
440 MSGTR_TV_MJP_WidthHeight
, tvh
->tv_param
->width
, tvh
->tv_param
->height
);
444 /* limits on w&h are norm-dependent -- JM */
445 if (tvh
->tv_param
->width
!= -1 && tvh
->tv_param
->height
!= -1) {
446 // first tell the driver both width and height, some drivers do not support setting them independently.
448 dim
[0] = tvh
->tv_param
->width
; dim
[1] = tvh
->tv_param
->height
;
449 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH_HEIGHT
, dim
);
452 if (tvh
->tv_param
->width
!= -1)
454 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
455 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
458 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetWidth
, tvh
->tv_param
->width
);
459 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
464 if (tvh
->tv_param
->height
!= -1)
466 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
467 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
470 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetHeight
, tvh
->tv_param
->height
);
471 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
475 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
477 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_NoTuner
);
481 /* select channel list */
482 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
484 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
487 tvh
->chanlist_s
= chanlists
[i
].list
;
492 if (tvh
->chanlist
== -1)
493 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnableFindChanlist
,
494 tvh
->tv_param
->chanlist
);
496 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedChanlist
,
497 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
499 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
501 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ChannelFreqParamConflict
);
505 /* Handle channel names */
506 if (tvh
->tv_param
->channels
) {
509 tv_channel_last_real
= malloc(5);
511 if (tv_channel_list
) {
514 if (tvh
->tv_param
->channel
)
516 if (isdigit(*tvh
->tv_param
->channel
))
517 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
518 channel
= atoi(tvh
->tv_param
->channel
);
521 /* if tvh->tv_param->channel does not begin with a digit
522 set the first channel that contains tvh->tv_param->channel in its name */
524 tv_channel_current
= tv_channel_list
;
525 while ( tv_channel_current
) {
526 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
528 tv_channel_current
= tv_channel_current
->next
;
530 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
537 tv_channel_current
= tv_channel_list
;
538 for (i
= 1; i
< channel
; i
++)
539 if (tv_channel_current
->next
)
540 tv_channel_current
= tv_channel_current
->next
;
543 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
544 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
545 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
546 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
547 tv_channel_last
= tv_channel_current
;
549 /* we need to set frequency */
550 if (tvh
->tv_param
->freq
)
552 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
554 /* set freq in MHz */
555 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
557 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
558 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedFrequency
,
559 freq
, (float)freq
/16);
562 if (tvh
->tv_param
->channel
) {
565 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_RequestedChannel
, tvh
->tv_param
->channel
);
566 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
568 cl
= tvh
->chanlist_s
[i
];
569 // printf("count%d: name: %s, freq: %d\n",
570 // i, cl.name, cl.freq);
571 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
573 strcpy(tv_channel_last_real
, cl
.name
);
575 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
576 cl
.name
, (float)cl
.freq
/1000);
577 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
584 /* grep frequency in chanlist */
589 tv_get_freq(tvh
, &i2
);
591 freq
= (int) (((float)(i2
/16))*1000)+250;
593 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
595 if (tvh
->chanlist_s
[i
].freq
== freq
)
604 /* also start device! */
608 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
612 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
613 mp_msg(MSGT_TV
,MSGL_INFO
,MSGTR_TV_AvailableDrivers
);
614 for(i
=0;tvi_driver_list
[i
];i
++){
615 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
616 if(tvi_driver_list
[i
]->comment
)
617 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
618 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
623 for(i
=0;tvi_driver_list
[i
];i
++){
624 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
625 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
626 //Requested driver initialization failed
627 if (!h
&& tv_param
->driver
)
629 //Driver initialization failed during autodetection process.
633 h
->tv_param
=tv_param
;
634 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_DriverInfo
, tvi_driver_list
[i
]->short_name
,
635 tvi_driver_list
[i
]->name
,
636 tvi_driver_list
[i
]->author
,
637 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
638 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
644 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoSuchDriver
, tv_param
->driver
);
646 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_DriverAutoDetectionFailed
);
650 static int tv_uninit(tvi_handle_t
*tvh
)
654 if (!tvh
->priv
) return 1;
655 res
=tvh
->functions
->uninit(tvh
->priv
);
663 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
666 sh_video_t
*sh_video
;
667 sh_audio_t
*sh_audio
= NULL
;
668 const tvi_functions_t
*funcs
;
671 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
672 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
674 tvh
->demuxer
= demuxer
;
675 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,
676 &(tvh
->tv_param
->teletext
.device
));
677 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_GET_VBI_PTR
,
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
:
764 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnsupportedAudioType
,
765 af_fmt2str(audio_format
, buf
, 128), audio_format
);
769 sh_audio
= new_sh_audio(demuxer
, 0);
771 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
772 &sh_audio
->samplerate
);
773 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
774 &sh_audio
->samplesize
);
775 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
776 &sh_audio
->channels
);
778 sh_audio
->format
= sh_audio_format
;
779 sh_audio
->sample_format
= audio_format
;
781 sh_audio
->i_bps
= sh_audio
->o_bps
=
782 sh_audio
->samplerate
* sh_audio
->samplesize
*
785 // emulate WF for win32 codecs:
786 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
787 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
788 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
789 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
790 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
791 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
792 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
794 mp_msg(MSGT_DECVIDEO
, MSGL_V
, MSGTR_TV_AudioFormat
,
795 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
796 sh_audio
->wf
->nSamplesPerSec
);
798 demuxer
->audio
->sh
= sh_audio
;
799 sh_audio
->ds
= demuxer
->audio
;
800 demuxer
->audio
->id
= 0;
804 if(!(funcs
->start(tvh
->priv
))){
811 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
812 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
813 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
814 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
816 if(tvh
->tv_param
->gain
!=-1)
817 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
818 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
820 teletext_control(demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
821 &tvh
->tv_param
->teletext
);
826 static void demux_close_tv(demuxer_t
*demuxer
)
828 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
833 demuxer
->teletext
=NULL
;
836 /* utilities for mplayer (not mencoder!!) */
837 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
839 const tvi_functions_t
*funcs
= tvh
->functions
;
843 case TV_COLOR_BRIGHTNESS
:
844 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
846 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
847 case TV_COLOR_SATURATION
:
848 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
849 case TV_COLOR_CONTRAST
:
850 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
852 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
855 return TVI_CONTROL_UNKNOWN
;
858 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
860 const tvi_functions_t
*funcs
= tvh
->functions
;
864 case TV_COLOR_BRIGHTNESS
:
865 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
867 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
868 case TV_COLOR_SATURATION
:
869 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
870 case TV_COLOR_CONTRAST
:
871 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
873 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
876 return TVI_CONTROL_UNKNOWN
;
879 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
881 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
883 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
884 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
885 *freq
, (float)*freq
/16);
890 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
892 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
894 // unsigned long freq = atof(tvh->tv_param->freq)*16;
896 /* set freq in MHz */
897 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
899 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
900 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
901 freq
, (float)freq
/16);
903 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
904 &tvh
->tv_param
->teletext
);
908 int tv_get_signal(tvi_handle_t
*tvh
)
911 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
912 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
918 /*****************************************************************
919 * \brief tune current frequency by step_interval value
920 * \parameter step_interval increment value in 1/16 MHz
921 * \note frequency is rounded to 1/16 MHz value
925 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
926 unsigned long frequency
;
928 tvh
->tv_param
->scan
=0;
929 tv_get_freq(tvh
,&frequency
);
930 frequency
+=step_interval
;
931 return tv_set_freq(tvh
,frequency
);
934 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
938 tvh
->tv_param
->scan
=0;
939 if (direction
== TV_CHANNEL_LOWER
)
941 if (tvh
->channel
-1 >= 0)
943 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
944 cl
= tvh
->chanlist_s
[--tvh
->channel
];
945 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
946 cl
.name
, (float)cl
.freq
/1000);
947 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
951 if (direction
== TV_CHANNEL_HIGHER
)
953 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
955 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
956 cl
= tvh
->chanlist_s
[++tvh
->channel
];
957 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
958 cl
.name
, (float)cl
.freq
/1000);
959 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
965 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
966 tvh
->tv_param
->scan
=0;
967 if (tv_channel_list
) {
968 if (direction
== TV_CHANNEL_HIGHER
) {
969 tv_channel_last
= tv_channel_current
;
970 if (tv_channel_current
->next
)
971 tv_channel_current
= tv_channel_current
->next
;
973 tv_channel_current
= tv_channel_list
;
975 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
976 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
977 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
978 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
980 if (direction
== TV_CHANNEL_LOWER
) {
981 tv_channel_last
= tv_channel_current
;
982 if (tv_channel_current
->prev
)
983 tv_channel_current
= tv_channel_current
->prev
;
985 while (tv_channel_current
->next
)
986 tv_channel_current
= tv_channel_current
->next
;
987 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
988 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
989 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
990 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
992 } else tv_step_channel_real(tvh
, direction
);
996 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
1000 tvh
->tv_param
->scan
=0;
1001 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1002 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1004 cl
= tvh
->chanlist_s
[i
];
1005 // printf("count%d: name: %s, freq: %d\n",
1006 // i, cl.name, cl.freq);
1007 if (!strcasecmp(cl
.name
, channel
))
1010 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1011 cl
.name
, (float)cl
.freq
/1000);
1012 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1019 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
1022 tvh
->tv_param
->scan
=0;
1023 if (tv_channel_list
) {
1024 tv_channel_last
= tv_channel_current
;
1025 channel_int
= atoi(channel
);
1026 tv_channel_current
= tv_channel_list
;
1027 for (i
= 1; i
< channel_int
; i
++)
1028 if (tv_channel_current
->next
)
1029 tv_channel_current
= tv_channel_current
->next
;
1030 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1031 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1032 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1033 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1034 } else tv_set_channel_real(tvh
, channel
);
1038 int tv_last_channel(tvi_handle_t
*tvh
) {
1040 tvh
->tv_param
->scan
=0;
1041 if (tv_channel_list
) {
1044 tmp
= tv_channel_last
;
1045 tv_channel_last
= tv_channel_current
;
1046 tv_channel_current
= tmp
;
1048 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1049 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1050 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1051 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1056 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1058 cl
= tvh
->chanlist_s
[i
];
1059 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1061 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1063 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1064 cl
.name
, (float)cl
.freq
/1000);
1065 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1073 int tv_step_norm(tvi_handle_t
*tvh
)
1076 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1077 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1079 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1080 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1081 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1085 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
1086 &tvh
->tv_param
->teletext
);
1090 int tv_step_chanlist(tvi_handle_t
*tvh
)
1095 demuxer_desc_t demuxer_desc_tv
= {
1099 "Alex Beregszaszi, Charles R. Henrich",
1104 demux_tv_fill_buffer
,