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
:
765 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnsupportedAudioType
,
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_msg(MSGT_DECVIDEO
, MSGL_V
, MSGTR_TV_AudioFormat
,
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 teletext_control(demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
822 &tvh
->tv_param
->teletext
);
827 static void demux_close_tv(demuxer_t
*demuxer
)
829 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
834 demuxer
->teletext
=NULL
;
837 /* utilities for mplayer (not mencoder!!) */
838 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
840 const tvi_functions_t
*funcs
= tvh
->functions
;
844 case TV_COLOR_BRIGHTNESS
:
845 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
847 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
848 case TV_COLOR_SATURATION
:
849 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
850 case TV_COLOR_CONTRAST
:
851 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
853 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
856 return TVI_CONTROL_UNKNOWN
;
859 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
861 const tvi_functions_t
*funcs
= tvh
->functions
;
865 case TV_COLOR_BRIGHTNESS
:
866 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
868 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
869 case TV_COLOR_SATURATION
:
870 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
871 case TV_COLOR_CONTRAST
:
872 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
874 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
877 return TVI_CONTROL_UNKNOWN
;
880 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
882 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
884 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
885 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
886 *freq
, (float)*freq
/16);
891 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
893 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
895 // unsigned long freq = atof(tvh->tv_param->freq)*16;
897 /* set freq in MHz */
898 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
900 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
901 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
902 freq
, (float)freq
/16);
904 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
905 &tvh
->tv_param
->teletext
);
909 int tv_get_signal(tvi_handle_t
*tvh
)
912 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
913 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
919 /*****************************************************************
920 * \brief tune current frequency by step_interval value
921 * \parameter step_interval increment value in 1/16 MHz
922 * \note frequency is rounded to 1/16 MHz value
926 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
927 unsigned long frequency
;
929 tvh
->tv_param
->scan
=0;
930 tv_get_freq(tvh
,&frequency
);
931 frequency
+=step_interval
;
932 return tv_set_freq(tvh
,frequency
);
935 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
939 tvh
->tv_param
->scan
=0;
940 if (direction
== TV_CHANNEL_LOWER
)
942 if (tvh
->channel
-1 >= 0)
944 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
945 cl
= tvh
->chanlist_s
[--tvh
->channel
];
946 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
947 cl
.name
, (float)cl
.freq
/1000);
948 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
952 if (direction
== TV_CHANNEL_HIGHER
)
954 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
956 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
957 cl
= tvh
->chanlist_s
[++tvh
->channel
];
958 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
959 cl
.name
, (float)cl
.freq
/1000);
960 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
966 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
967 tvh
->tv_param
->scan
=0;
968 if (tv_channel_list
) {
969 if (direction
== TV_CHANNEL_HIGHER
) {
970 tv_channel_last
= tv_channel_current
;
971 if (tv_channel_current
->next
)
972 tv_channel_current
= tv_channel_current
->next
;
974 tv_channel_current
= tv_channel_list
;
976 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
977 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
978 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
979 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
981 if (direction
== TV_CHANNEL_LOWER
) {
982 tv_channel_last
= tv_channel_current
;
983 if (tv_channel_current
->prev
)
984 tv_channel_current
= tv_channel_current
->prev
;
986 while (tv_channel_current
->next
)
987 tv_channel_current
= tv_channel_current
->next
;
988 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
989 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
990 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
991 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
993 } else tv_step_channel_real(tvh
, direction
);
997 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
1001 tvh
->tv_param
->scan
=0;
1002 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1003 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1005 cl
= tvh
->chanlist_s
[i
];
1006 // printf("count%d: name: %s, freq: %d\n",
1007 // i, cl.name, cl.freq);
1008 if (!strcasecmp(cl
.name
, channel
))
1011 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1012 cl
.name
, (float)cl
.freq
/1000);
1013 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1020 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
1023 tvh
->tv_param
->scan
=0;
1024 if (tv_channel_list
) {
1025 tv_channel_last
= tv_channel_current
;
1026 channel_int
= atoi(channel
);
1027 tv_channel_current
= tv_channel_list
;
1028 for (i
= 1; i
< channel_int
; i
++)
1029 if (tv_channel_current
->next
)
1030 tv_channel_current
= tv_channel_current
->next
;
1031 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1032 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1033 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1034 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1035 } else tv_set_channel_real(tvh
, channel
);
1039 int tv_last_channel(tvi_handle_t
*tvh
) {
1041 tvh
->tv_param
->scan
=0;
1042 if (tv_channel_list
) {
1045 tmp
= tv_channel_last
;
1046 tv_channel_last
= tv_channel_current
;
1047 tv_channel_current
= tmp
;
1049 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1050 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1051 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1052 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1057 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1059 cl
= tvh
->chanlist_s
[i
];
1060 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1062 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1064 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1065 cl
.name
, (float)cl
.freq
/1000);
1066 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1074 int tv_step_norm(tvi_handle_t
*tvh
)
1077 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1078 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1080 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1081 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1082 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1086 teletext_control(tvh
->demuxer
->teletext
,TV_VBI_CONTROL_RESET
,
1087 &tvh
->tv_param
->teletext
);
1091 int tv_step_chanlist(tvi_handle_t
*tvh
)
1096 demuxer_desc_t demuxer_desc_tv
= {
1100 "Alex Beregszaszi, Charles R. Henrich",
1105 demux_tv_fill_buffer
,