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_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ScannerNotAvailableWithoutTuner
);
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_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_BogusNormParameter
, 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_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_BogusNormParameter
, norm
, "PAL");
247 static void parse_channels(tvi_handle_t
*tvh
)
249 char** channels
= tvh
->tv_param
->channels
;
251 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_ChannelNamesDetected
);
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_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoFreqForChannel
,
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_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNorm
, norm
);
332 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
333 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
336 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
340 int tv_set_norm_i(tvi_handle_t
*tvh
, int norm
)
344 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNormId
, norm
);
345 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
346 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
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_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoVideoInputPresent
);
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_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnknownImageFormat
,tvh
->tv_param
->outfmt
);
401 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
404 /* set some params got from cmdline */
405 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
407 #if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
409 #ifdef CONFIG_TV_V4L2
410 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
412 #ifdef CONFIG_TV_DSHOW
413 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
416 tv_set_norm_i(tvh
, tvh
->tv_param
->normid
);
419 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
421 #ifdef CONFIG_TV_V4L1
422 if ( tvh
->tv_param
->mjpeg
)
424 /* set width to expected value */
425 if (tvh
->tv_param
->width
== -1)
427 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
429 if (tvh
->tv_param
->height
== -1)
431 if ( tvh
->norm
!= TV_NORM_NTSC
)
432 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
434 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
436 mp_msg(MSGT_TV
, MSGL_INFO
,
437 MSGTR_TV_MJP_WidthHeight
, tvh
->tv_param
->width
, tvh
->tv_param
->height
);
441 /* limits on w&h are norm-dependent -- JM */
443 if (tvh
->tv_param
->width
!= -1)
445 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
446 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
449 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetWidth
, tvh
->tv_param
->width
);
450 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
455 if (tvh
->tv_param
->height
!= -1)
457 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
458 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
461 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetHeight
, tvh
->tv_param
->height
);
462 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
466 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
468 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_NoTuner
);
472 /* select channel list */
473 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
475 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
478 tvh
->chanlist_s
= chanlists
[i
].list
;
483 if (tvh
->chanlist
== -1)
484 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnableFindChanlist
,
485 tvh
->tv_param
->chanlist
);
487 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedChanlist
,
488 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
490 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
492 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ChannelFreqParamConflict
);
496 /* Handle channel names */
497 if (tvh
->tv_param
->channels
) {
500 tv_channel_last_real
= malloc(5);
502 if (tv_channel_list
) {
505 if (tvh
->tv_param
->channel
)
507 if (isdigit(*tvh
->tv_param
->channel
))
508 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
509 channel
= atoi(tvh
->tv_param
->channel
);
512 /* if tvh->tv_param->channel does not begin with a digit
513 set the first channel that contains tvh->tv_param->channel in its name */
515 tv_channel_current
= tv_channel_list
;
516 while ( tv_channel_current
) {
517 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
519 tv_channel_current
= tv_channel_current
->next
;
521 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
528 tv_channel_current
= tv_channel_list
;
529 for (i
= 1; i
< channel
; i
++)
530 if (tv_channel_current
->next
)
531 tv_channel_current
= tv_channel_current
->next
;
534 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
535 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
536 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
537 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
538 tv_channel_last
= tv_channel_current
;
540 /* we need to set frequency */
541 if (tvh
->tv_param
->freq
)
543 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
545 /* set freq in MHz */
546 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
548 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
549 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedFrequency
,
550 freq
, (float)freq
/16);
553 if (tvh
->tv_param
->channel
) {
556 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_RequestedChannel
, tvh
->tv_param
->channel
);
557 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
559 cl
= tvh
->chanlist_s
[i
];
560 // printf("count%d: name: %s, freq: %d\n",
561 // i, cl.name, cl.freq);
562 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
564 strcpy(tv_channel_last_real
, cl
.name
);
566 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
567 cl
.name
, (float)cl
.freq
/1000);
568 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
575 /* grep frequency in chanlist */
580 tv_get_freq(tvh
, &i2
);
582 freq
= (int) (((float)(i2
/16))*1000)+250;
584 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
586 if (tvh
->chanlist_s
[i
].freq
== freq
)
595 /* also start device! */
599 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
603 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
604 mp_msg(MSGT_TV
,MSGL_INFO
,MSGTR_TV_AvailableDrivers
);
605 for(i
=0;tvi_driver_list
[i
];i
++){
606 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
607 if(tvi_driver_list
[i
]->comment
)
608 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
609 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
614 for(i
=0;tvi_driver_list
[i
];i
++){
615 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
616 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
617 //Requested driver initialization failed
618 if (!h
&& tv_param
->driver
)
620 //Driver initialization failed during autodetection process.
624 h
->tv_param
=tv_param
;
625 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_DriverInfo
, tvi_driver_list
[i
]->short_name
,
626 tvi_driver_list
[i
]->name
,
627 tvi_driver_list
[i
]->author
,
628 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
629 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
635 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoSuchDriver
, tv_param
->driver
);
637 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_DriverAutoDetectionFailed
);
641 static int tv_uninit(tvi_handle_t
*tvh
)
645 if (!tvh
->priv
) return 1;
646 res
=tvh
->functions
->uninit(tvh
->priv
);
654 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
657 sh_video_t
*sh_video
;
658 sh_audio_t
*sh_audio
= NULL
;
659 const tvi_functions_t
*funcs
;
662 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
663 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
665 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,&(tvh
->tv_param
->tdevice
));
671 funcs
= tvh
->functions
;
674 sh_video
= new_sh_video(demuxer
, 0);
676 /* get IMAGE FORMAT */
677 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
678 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
679 // sh_video->format = 0x0;
681 /* set FPS and FRAMETIME */
686 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
687 sh_video
->fps
= 25.0f
; /* on PAL */
688 else sh_video
->fps
= tmp
;
691 if (tvh
->tv_param
->fps
!= -1.0f
)
692 sh_video
->fps
= tvh
->tv_param
->fps
;
694 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
696 /* If playback only mode, go to immediate mode, fail silently */
697 if(tvh
->tv_param
->immediate
== 1)
699 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
700 tvh
->tv_param
->noaudio
= 1;
703 /* disable TV audio if -nosound is present */
704 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
705 tvh
->tv_param
->noaudio
= 1;
709 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
712 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
714 demuxer
->video
->sh
= sh_video
;
715 sh_video
->ds
= demuxer
->video
;
716 demuxer
->video
->id
= 0;
717 demuxer
->seekable
= 0;
719 /* here comes audio init */
720 if (tvh
->tv_param
->noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
726 /* yeah, audio is present */
728 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
729 &tvh
->tv_param
->audiorate
);
731 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
738 case AF_FORMAT_U16_LE
:
739 case AF_FORMAT_U16_BE
:
740 case AF_FORMAT_S16_LE
:
741 case AF_FORMAT_S16_BE
:
742 case AF_FORMAT_S32_LE
:
743 case AF_FORMAT_S32_BE
:
744 sh_audio_format
= 0x1; /* PCM */
746 case AF_FORMAT_IMA_ADPCM
:
747 case AF_FORMAT_MU_LAW
:
748 case AF_FORMAT_A_LAW
:
749 case AF_FORMAT_MPEG2
:
752 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnsupportedAudioType
,
753 af_fmt2str(audio_format
, buf
, 128), audio_format
);
757 sh_audio
= new_sh_audio(demuxer
, 0);
759 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
760 &sh_audio
->samplerate
);
761 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
762 &sh_audio
->samplesize
);
763 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
764 &sh_audio
->channels
);
766 sh_audio
->format
= sh_audio_format
;
767 sh_audio
->sample_format
= audio_format
;
769 sh_audio
->i_bps
= sh_audio
->o_bps
=
770 sh_audio
->samplerate
* sh_audio
->samplesize
*
773 // emulate WF for win32 codecs:
774 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
775 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
776 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
777 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
778 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
779 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
780 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
782 mp_msg(MSGT_DECVIDEO
, MSGL_V
, MSGTR_TV_AudioFormat
,
783 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
784 sh_audio
->wf
->nSamplesPerSec
);
786 demuxer
->audio
->sh
= sh_audio
;
787 sh_audio
->ds
= demuxer
->audio
;
788 demuxer
->audio
->id
= 0;
792 if(!(funcs
->start(tvh
->priv
))){
799 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
800 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
801 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
802 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
804 if(tvh
->tv_param
->gain
!=-1)
805 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
806 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
808 funcs
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
813 static void demux_close_tv(demuxer_t
*demuxer
)
815 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
822 /* utilities for mplayer (not mencoder!!) */
823 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
825 const tvi_functions_t
*funcs
= tvh
->functions
;
829 case TV_COLOR_BRIGHTNESS
:
830 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
832 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
833 case TV_COLOR_SATURATION
:
834 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
835 case TV_COLOR_CONTRAST
:
836 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
838 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
841 return TVI_CONTROL_UNKNOWN
;
844 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
846 const tvi_functions_t
*funcs
= tvh
->functions
;
850 case TV_COLOR_BRIGHTNESS
:
851 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
853 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
854 case TV_COLOR_SATURATION
:
855 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
856 case TV_COLOR_CONTRAST
:
857 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
859 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
862 return TVI_CONTROL_UNKNOWN
;
865 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
867 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
869 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
870 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
871 *freq
, (float)*freq
/16);
876 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
878 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
880 // unsigned long freq = atof(tvh->tv_param->freq)*16;
882 /* set freq in MHz */
883 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
885 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
886 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
887 freq
, (float)freq
/16);
889 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
893 int tv_get_signal(tvi_handle_t
*tvh
)
896 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
897 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
903 /*****************************************************************
904 * \brief tune current frequency by step_interval value
905 * \parameter step_interval increment value in 1/16 MHz
906 * \note frequency is rounded to 1/16 MHz value
910 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
911 unsigned long frequency
;
913 tvh
->tv_param
->scan
=0;
914 tv_get_freq(tvh
,&frequency
);
915 frequency
+=step_interval
;
916 return tv_set_freq(tvh
,frequency
);
919 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
923 tvh
->tv_param
->scan
=0;
924 if (direction
== TV_CHANNEL_LOWER
)
926 if (tvh
->channel
-1 >= 0)
928 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
929 cl
= tvh
->chanlist_s
[--tvh
->channel
];
930 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
931 cl
.name
, (float)cl
.freq
/1000);
932 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
936 if (direction
== TV_CHANNEL_HIGHER
)
938 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
940 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
941 cl
= tvh
->chanlist_s
[++tvh
->channel
];
942 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
943 cl
.name
, (float)cl
.freq
/1000);
944 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
950 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
951 tvh
->tv_param
->scan
=0;
952 if (tv_channel_list
) {
953 if (direction
== TV_CHANNEL_HIGHER
) {
954 tv_channel_last
= tv_channel_current
;
955 if (tv_channel_current
->next
)
956 tv_channel_current
= tv_channel_current
->next
;
958 tv_channel_current
= tv_channel_list
;
960 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
961 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
962 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
963 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
965 if (direction
== TV_CHANNEL_LOWER
) {
966 tv_channel_last
= tv_channel_current
;
967 if (tv_channel_current
->prev
)
968 tv_channel_current
= tv_channel_current
->prev
;
970 while (tv_channel_current
->next
)
971 tv_channel_current
= tv_channel_current
->next
;
972 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
973 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
974 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
975 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
977 } else tv_step_channel_real(tvh
, direction
);
981 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
985 tvh
->tv_param
->scan
=0;
986 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
987 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
989 cl
= tvh
->chanlist_s
[i
];
990 // printf("count%d: name: %s, freq: %d\n",
991 // i, cl.name, cl.freq);
992 if (!strcasecmp(cl
.name
, channel
))
995 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
996 cl
.name
, (float)cl
.freq
/1000);
997 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1004 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
1007 tvh
->tv_param
->scan
=0;
1008 if (tv_channel_list
) {
1009 tv_channel_last
= tv_channel_current
;
1010 channel_int
= atoi(channel
);
1011 tv_channel_current
= tv_channel_list
;
1012 for (i
= 1; i
< channel_int
; i
++)
1013 if (tv_channel_current
->next
)
1014 tv_channel_current
= tv_channel_current
->next
;
1015 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1016 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1017 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1018 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1019 } else tv_set_channel_real(tvh
, channel
);
1023 int tv_last_channel(tvi_handle_t
*tvh
) {
1025 tvh
->tv_param
->scan
=0;
1026 if (tv_channel_list
) {
1029 tmp
= tv_channel_last
;
1030 tv_channel_last
= tv_channel_current
;
1031 tv_channel_current
= tmp
;
1033 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1034 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1035 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1036 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1041 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1043 cl
= tvh
->chanlist_s
[i
];
1044 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1046 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1048 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1049 cl
.name
, (float)cl
.freq
/1000);
1050 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1058 int tv_step_norm(tvi_handle_t
*tvh
)
1061 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1062 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1064 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1065 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1066 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1070 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1074 int tv_step_chanlist(tvi_handle_t
*tvh
)
1079 demuxer_desc_t demuxer_desc_tv
= {
1083 "Alex Beregszaszi, Charles R. Henrich",
1088 demux_tv_fill_buffer
,