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 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
341 int tv_set_norm_i(tvi_handle_t
*tvh
, int norm
)
345 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNormId
, norm
);
346 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
347 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
351 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
355 static int open_tv(tvi_handle_t
*tvh
)
358 const tvi_functions_t
*funcs
= tvh
->functions
;
359 int tv_fmt_list
[] = {
370 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
372 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoVideoInputPresent
);
376 if (tvh
->tv_param
->outfmt
== -1)
377 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
379 tvh
->tv_param
->outfmt
= tv_fmt_list
[i
];
380 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
381 &tvh
->tv_param
->outfmt
) == TVI_CONTROL_TRUE
)
386 switch(tvh
->tv_param
->outfmt
)
400 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnknownImageFormat
,tvh
->tv_param
->outfmt
);
402 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
405 /* set some params got from cmdline */
406 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
408 #if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
410 #ifdef CONFIG_TV_V4L2
411 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
413 #ifdef CONFIG_TV_DSHOW
414 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
417 tv_set_norm_i(tvh
, tvh
->tv_param
->normid
);
420 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
422 #ifdef CONFIG_TV_V4L1
423 if ( tvh
->tv_param
->mjpeg
)
425 /* set width to expected value */
426 if (tvh
->tv_param
->width
== -1)
428 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
430 if (tvh
->tv_param
->height
== -1)
432 if ( tvh
->norm
!= TV_NORM_NTSC
)
433 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
435 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
437 mp_msg(MSGT_TV
, MSGL_INFO
,
438 MSGTR_TV_MJP_WidthHeight
, tvh
->tv_param
->width
, tvh
->tv_param
->height
);
442 /* limits on w&h are norm-dependent -- JM */
443 if (tvh
->tv_param
->width
!= -1 && tvh
->tv_param
->height
!= -1) {
444 // first tell the driver both width and height, some drivers do not support setting them independently.
446 dim
[0] = tvh
->tv_param
->width
; dim
[1] = tvh
->tv_param
->height
;
447 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH_HEIGHT
, dim
);
450 if (tvh
->tv_param
->width
!= -1)
452 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
453 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
456 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetWidth
, tvh
->tv_param
->width
);
457 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
462 if (tvh
->tv_param
->height
!= -1)
464 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
465 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
468 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetHeight
, tvh
->tv_param
->height
);
469 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
473 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
475 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_NoTuner
);
479 /* select channel list */
480 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
482 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
485 tvh
->chanlist_s
= chanlists
[i
].list
;
490 if (tvh
->chanlist
== -1)
491 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnableFindChanlist
,
492 tvh
->tv_param
->chanlist
);
494 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedChanlist
,
495 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
497 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
499 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ChannelFreqParamConflict
);
503 /* Handle channel names */
504 if (tvh
->tv_param
->channels
) {
507 tv_channel_last_real
= malloc(5);
509 if (tv_channel_list
) {
512 if (tvh
->tv_param
->channel
)
514 if (isdigit(*tvh
->tv_param
->channel
))
515 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
516 channel
= atoi(tvh
->tv_param
->channel
);
519 /* if tvh->tv_param->channel does not begin with a digit
520 set the first channel that contains tvh->tv_param->channel in its name */
522 tv_channel_current
= tv_channel_list
;
523 while ( tv_channel_current
) {
524 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
526 tv_channel_current
= tv_channel_current
->next
;
528 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
535 tv_channel_current
= tv_channel_list
;
536 for (i
= 1; i
< channel
; i
++)
537 if (tv_channel_current
->next
)
538 tv_channel_current
= tv_channel_current
->next
;
541 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
542 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
543 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
544 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
545 tv_channel_last
= tv_channel_current
;
547 /* we need to set frequency */
548 if (tvh
->tv_param
->freq
)
550 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
552 /* set freq in MHz */
553 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
555 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
556 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedFrequency
,
557 freq
, (float)freq
/16);
560 if (tvh
->tv_param
->channel
) {
563 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_RequestedChannel
, tvh
->tv_param
->channel
);
564 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
566 cl
= tvh
->chanlist_s
[i
];
567 // printf("count%d: name: %s, freq: %d\n",
568 // i, cl.name, cl.freq);
569 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
571 strcpy(tv_channel_last_real
, cl
.name
);
573 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
574 cl
.name
, (float)cl
.freq
/1000);
575 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
582 /* grep frequency in chanlist */
587 tv_get_freq(tvh
, &i2
);
589 freq
= (int) (((float)(i2
/16))*1000)+250;
591 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
593 if (tvh
->chanlist_s
[i
].freq
== freq
)
602 /* also start device! */
606 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
610 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
611 mp_msg(MSGT_TV
,MSGL_INFO
,MSGTR_TV_AvailableDrivers
);
612 for(i
=0;tvi_driver_list
[i
];i
++){
613 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
614 if(tvi_driver_list
[i
]->comment
)
615 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
616 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
621 for(i
=0;tvi_driver_list
[i
];i
++){
622 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
623 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
624 //Requested driver initialization failed
625 if (!h
&& tv_param
->driver
)
627 //Driver initialization failed during autodetection process.
631 h
->tv_param
=tv_param
;
632 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_DriverInfo
, tvi_driver_list
[i
]->short_name
,
633 tvi_driver_list
[i
]->name
,
634 tvi_driver_list
[i
]->author
,
635 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
636 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
642 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoSuchDriver
, tv_param
->driver
);
644 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_DriverAutoDetectionFailed
);
648 static int tv_uninit(tvi_handle_t
*tvh
)
652 if (!tvh
->priv
) return 1;
653 res
=tvh
->functions
->uninit(tvh
->priv
);
661 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
664 sh_video_t
*sh_video
;
665 sh_audio_t
*sh_audio
= NULL
;
666 const tvi_functions_t
*funcs
;
669 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
670 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
672 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,&(tvh
->tv_param
->tdevice
));
678 funcs
= tvh
->functions
;
681 sh_video
= new_sh_video(demuxer
, 0);
683 /* get IMAGE FORMAT */
684 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
685 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
686 // sh_video->format = 0x0;
688 /* set FPS and FRAMETIME */
693 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
694 sh_video
->fps
= 25.0f
; /* on PAL */
695 else sh_video
->fps
= tmp
;
698 if (tvh
->tv_param
->fps
!= -1.0f
)
699 sh_video
->fps
= tvh
->tv_param
->fps
;
701 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
703 /* If playback only mode, go to immediate mode, fail silently */
704 if(tvh
->tv_param
->immediate
== 1)
706 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
707 tvh
->tv_param
->noaudio
= 1;
710 /* disable TV audio if -nosound is present */
711 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
712 tvh
->tv_param
->noaudio
= 1;
716 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
719 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
721 demuxer
->video
->sh
= sh_video
;
722 sh_video
->ds
= demuxer
->video
;
723 demuxer
->video
->id
= 0;
724 demuxer
->seekable
= 0;
726 /* here comes audio init */
727 if (tvh
->tv_param
->noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
733 /* yeah, audio is present */
735 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
736 &tvh
->tv_param
->audiorate
);
738 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
745 case AF_FORMAT_U16_LE
:
746 case AF_FORMAT_U16_BE
:
747 case AF_FORMAT_S16_LE
:
748 case AF_FORMAT_S16_BE
:
749 case AF_FORMAT_S32_LE
:
750 case AF_FORMAT_S32_BE
:
751 sh_audio_format
= 0x1; /* PCM */
753 case AF_FORMAT_IMA_ADPCM
:
754 case AF_FORMAT_MU_LAW
:
755 case AF_FORMAT_A_LAW
:
756 case AF_FORMAT_MPEG2
:
759 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnsupportedAudioType
,
760 af_fmt2str(audio_format
, buf
, 128), audio_format
);
764 sh_audio
= new_sh_audio(demuxer
, 0);
766 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
767 &sh_audio
->samplerate
);
768 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
769 &sh_audio
->samplesize
);
770 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
771 &sh_audio
->channels
);
773 sh_audio
->format
= sh_audio_format
;
774 sh_audio
->sample_format
= audio_format
;
776 sh_audio
->i_bps
= sh_audio
->o_bps
=
777 sh_audio
->samplerate
* sh_audio
->samplesize
*
780 // emulate WF for win32 codecs:
781 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
782 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
783 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
784 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
785 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
786 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
787 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
789 mp_msg(MSGT_DECVIDEO
, MSGL_V
, MSGTR_TV_AudioFormat
,
790 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
791 sh_audio
->wf
->nSamplesPerSec
);
793 demuxer
->audio
->sh
= sh_audio
;
794 sh_audio
->ds
= demuxer
->audio
;
795 demuxer
->audio
->id
= 0;
799 if(!(funcs
->start(tvh
->priv
))){
806 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
807 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
808 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
809 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
811 if(tvh
->tv_param
->gain
!=-1)
812 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
813 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
815 funcs
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
820 static void demux_close_tv(demuxer_t
*demuxer
)
822 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
829 /* utilities for mplayer (not mencoder!!) */
830 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
832 const tvi_functions_t
*funcs
= tvh
->functions
;
836 case TV_COLOR_BRIGHTNESS
:
837 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
839 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
840 case TV_COLOR_SATURATION
:
841 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
842 case TV_COLOR_CONTRAST
:
843 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
845 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
848 return TVI_CONTROL_UNKNOWN
;
851 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
853 const tvi_functions_t
*funcs
= tvh
->functions
;
857 case TV_COLOR_BRIGHTNESS
:
858 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
860 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
861 case TV_COLOR_SATURATION
:
862 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
863 case TV_COLOR_CONTRAST
:
864 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
866 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
869 return TVI_CONTROL_UNKNOWN
;
872 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
874 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
876 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
877 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
878 *freq
, (float)*freq
/16);
883 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
885 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
887 // unsigned long freq = atof(tvh->tv_param->freq)*16;
889 /* set freq in MHz */
890 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
892 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
893 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
894 freq
, (float)freq
/16);
896 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
900 int tv_get_signal(tvi_handle_t
*tvh
)
903 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
904 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
910 /*****************************************************************
911 * \brief tune current frequency by step_interval value
912 * \parameter step_interval increment value in 1/16 MHz
913 * \note frequency is rounded to 1/16 MHz value
917 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
918 unsigned long frequency
;
920 tvh
->tv_param
->scan
=0;
921 tv_get_freq(tvh
,&frequency
);
922 frequency
+=step_interval
;
923 return tv_set_freq(tvh
,frequency
);
926 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
930 tvh
->tv_param
->scan
=0;
931 if (direction
== TV_CHANNEL_LOWER
)
933 if (tvh
->channel
-1 >= 0)
935 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
936 cl
= tvh
->chanlist_s
[--tvh
->channel
];
937 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
938 cl
.name
, (float)cl
.freq
/1000);
939 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
943 if (direction
== TV_CHANNEL_HIGHER
)
945 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
947 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
948 cl
= tvh
->chanlist_s
[++tvh
->channel
];
949 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
950 cl
.name
, (float)cl
.freq
/1000);
951 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
957 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
958 tvh
->tv_param
->scan
=0;
959 if (tv_channel_list
) {
960 if (direction
== TV_CHANNEL_HIGHER
) {
961 tv_channel_last
= tv_channel_current
;
962 if (tv_channel_current
->next
)
963 tv_channel_current
= tv_channel_current
->next
;
965 tv_channel_current
= tv_channel_list
;
967 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
968 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
969 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
970 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
972 if (direction
== TV_CHANNEL_LOWER
) {
973 tv_channel_last
= tv_channel_current
;
974 if (tv_channel_current
->prev
)
975 tv_channel_current
= tv_channel_current
->prev
;
977 while (tv_channel_current
->next
)
978 tv_channel_current
= tv_channel_current
->next
;
979 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
980 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
981 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
982 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
984 } else tv_step_channel_real(tvh
, direction
);
988 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
992 tvh
->tv_param
->scan
=0;
993 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
994 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
996 cl
= tvh
->chanlist_s
[i
];
997 // printf("count%d: name: %s, freq: %d\n",
998 // i, cl.name, cl.freq);
999 if (!strcasecmp(cl
.name
, channel
))
1002 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1003 cl
.name
, (float)cl
.freq
/1000);
1004 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1011 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
1014 tvh
->tv_param
->scan
=0;
1015 if (tv_channel_list
) {
1016 tv_channel_last
= tv_channel_current
;
1017 channel_int
= atoi(channel
);
1018 tv_channel_current
= tv_channel_list
;
1019 for (i
= 1; i
< channel_int
; i
++)
1020 if (tv_channel_current
->next
)
1021 tv_channel_current
= tv_channel_current
->next
;
1022 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1023 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1024 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1025 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1026 } else tv_set_channel_real(tvh
, channel
);
1030 int tv_last_channel(tvi_handle_t
*tvh
) {
1032 tvh
->tv_param
->scan
=0;
1033 if (tv_channel_list
) {
1036 tmp
= tv_channel_last
;
1037 tv_channel_last
= tv_channel_current
;
1038 tv_channel_current
= tmp
;
1040 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1041 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1042 tv_set_norm_i(tvh
, tv_channel_current
->norm
);
1043 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1048 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1050 cl
= tvh
->chanlist_s
[i
];
1051 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1053 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1055 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1056 cl
.name
, (float)cl
.freq
/1000);
1057 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1065 int tv_step_norm(tvi_handle_t
*tvh
)
1068 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1069 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1071 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1072 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1073 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1077 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1081 int tv_step_chanlist(tvi_handle_t
*tvh
)
1086 demuxer_desc_t demuxer_desc_tv
= {
1090 "Alex Beregszaszi, Charles R. Henrich",
1095 demux_tv_fill_buffer
,