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 HAVE_TV_BSDBT848
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
;
259 char* tmp
= *(channels
++);
260 char* sep
= strchr(tmp
,'-');
264 if (!sep
) continue; // Wrong syntax, but mplayer should not crash
266 av_strlcpy(tv_channel_current
->name
, sep
+ 1,
267 sizeof(tv_channel_current
->name
));
269 strncpy(tv_channel_current
->number
, tmp
, 5);
270 tv_channel_current
->number
[4]='\0';
272 while ((sep
=strchr(tv_channel_current
->name
, '_')))
275 // if channel number is a number and larger than 1000 threat it as frequency
276 // tmp still contain pointer to null-terminated string with channel number here
278 tv_channel_current
->freq
=atoi(tmp
);
280 tv_channel_current
->freq
= 0;
281 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++) {
282 cl
= tvh
->chanlist_s
[i
];
283 if (!strcasecmp(cl
.name
, tv_channel_current
->number
)) {
284 tv_channel_current
->freq
=cl
.freq
;
289 if (tv_channel_current
->freq
== 0)
290 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoFreqForChannel
,
291 tv_channel_current
->number
, tv_channel_current
->name
);
293 sep
= strchr(tv_channel_current
->name
, '-');
294 if ( !sep
) sep
= strchr(tv_channel_current
->name
, '+');
298 if ( sep
[0] == '+' ) tv_channel_current
->freq
+= i
* 100;
299 if ( sep
[0] == '-' ) tv_channel_current
->freq
-= i
* 100;
304 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
305 tv_channel_current->number, tv_channel_current->name,
306 (float)tv_channel_current->freq/1000);*/
308 tv_channel_current
->next
= malloc(sizeof(tv_channels_t
));
309 tv_channel_current
->next
->index
= tv_channel_current
->index
+ 1;
310 tv_channel_current
->next
->prev
= tv_channel_current
;
311 tv_channel_current
->next
->next
= NULL
;
312 tv_channel_current
= tv_channel_current
->next
;
314 if (tv_channel_current
->prev
)
315 tv_channel_current
->prev
->next
= NULL
;
316 free(tv_channel_current
);
318 static int open_tv(tvi_handle_t
*tvh
)
321 const tvi_functions_t
*funcs
= tvh
->functions
;
322 int tv_fmt_list
[] = {
333 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
335 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoVideoInputPresent
);
339 if (tvh
->tv_param
->outfmt
== -1)
340 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
342 tvh
->tv_param
->outfmt
= tv_fmt_list
[i
];
343 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
344 &tvh
->tv_param
->outfmt
) == TVI_CONTROL_TRUE
)
349 switch(tvh
->tv_param
->outfmt
)
363 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnknownImageFormat
,tvh
->tv_param
->outfmt
);
365 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
368 /* set some params got from cmdline */
369 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
371 #if defined(HAVE_TV_V4L2) || defined(HAVE_TV_DSHOW)
374 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
377 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
380 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNormId
, tvh
->tv_param
->normid
);
381 if (funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->tv_param
->normid
) != TVI_CONTROL_TRUE
) {
382 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
386 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
389 if ( tvh
->tv_param
->mjpeg
)
391 /* set width to expected value */
392 if (tvh
->tv_param
->width
== -1)
394 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
396 if (tvh
->tv_param
->height
== -1)
398 if ( tvh
->norm
!= TV_NORM_NTSC
)
399 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
401 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
403 mp_msg(MSGT_TV
, MSGL_INFO
,
404 MSGTR_TV_MJP_WidthHeight
, tvh
->tv_param
->width
, tvh
->tv_param
->height
);
408 /* limits on w&h are norm-dependent -- JM */
410 if (tvh
->tv_param
->width
!= -1)
412 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
413 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
416 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetWidth
, tvh
->tv_param
->width
);
417 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
422 if (tvh
->tv_param
->height
!= -1)
424 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
425 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
428 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetHeight
, tvh
->tv_param
->height
);
429 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
433 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
435 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_NoTuner
);
439 /* select channel list */
440 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
442 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
445 tvh
->chanlist_s
= chanlists
[i
].list
;
450 if (tvh
->chanlist
== -1)
451 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnableFindChanlist
,
452 tvh
->tv_param
->chanlist
);
454 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedChanlist
,
455 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
457 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
459 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ChannelFreqParamConflict
);
463 /* Handle channel names */
464 if (tvh
->tv_param
->channels
) {
467 tv_channel_last_real
= malloc(5);
469 if (tv_channel_list
) {
472 if (tvh
->tv_param
->channel
)
474 if (isdigit(*tvh
->tv_param
->channel
))
475 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
476 channel
= atoi(tvh
->tv_param
->channel
);
479 /* if tvh->tv_param->channel does not begin with a digit
480 set the first channel that contains tvh->tv_param->channel in its name */
482 tv_channel_current
= tv_channel_list
;
483 while ( tv_channel_current
) {
484 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
486 tv_channel_current
= tv_channel_current
->next
;
488 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
495 tv_channel_current
= tv_channel_list
;
496 for (i
= 1; i
< channel
; i
++)
497 if (tv_channel_current
->next
)
498 tv_channel_current
= tv_channel_current
->next
;
501 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
502 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
503 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
504 tv_channel_last
= tv_channel_current
;
506 /* we need to set frequency */
507 if (tvh
->tv_param
->freq
)
509 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
511 /* set freq in MHz */
512 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
514 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
515 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedFrequency
,
516 freq
, (float)freq
/16);
519 if (tvh
->tv_param
->channel
) {
522 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_RequestedChannel
, tvh
->tv_param
->channel
);
523 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
525 cl
= tvh
->chanlist_s
[i
];
526 // printf("count%d: name: %s, freq: %d\n",
527 // i, cl.name, cl.freq);
528 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
530 strcpy(tv_channel_last_real
, cl
.name
);
532 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
533 cl
.name
, (float)cl
.freq
/1000);
534 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
541 /* grep frequency in chanlist */
546 tv_get_freq(tvh
, &i2
);
548 freq
= (int) (((float)(i2
/16))*1000)+250;
550 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
552 if (tvh
->chanlist_s
[i
].freq
== freq
)
561 /* also start device! */
565 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
569 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
570 mp_msg(MSGT_TV
,MSGL_INFO
,MSGTR_TV_AvailableDrivers
);
571 for(i
=0;tvi_driver_list
[i
];i
++){
572 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
573 if(tvi_driver_list
[i
]->comment
)
574 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
575 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
580 for(i
=0;tvi_driver_list
[i
];i
++){
581 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
582 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
583 //Requested driver initialization failed
584 if (!h
&& tv_param
->driver
)
586 //Driver initialization failed during autodetection process.
590 h
->tv_param
=tv_param
;
591 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_DriverInfo
, tvi_driver_list
[i
]->short_name
,
592 tvi_driver_list
[i
]->name
,
593 tvi_driver_list
[i
]->author
,
594 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
595 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
601 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoSuchDriver
, tv_param
->driver
);
603 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_DriverAutoDetectionFailed
);
607 static int tv_uninit(tvi_handle_t
*tvh
)
611 if (!tvh
->priv
) return 1;
612 res
=tvh
->functions
->uninit(tvh
->priv
);
620 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
623 sh_video_t
*sh_video
;
624 sh_audio_t
*sh_audio
= NULL
;
625 const tvi_functions_t
*funcs
;
628 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
629 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
631 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,&(tvh
->tv_param
->tdevice
));
637 funcs
= tvh
->functions
;
640 sh_video
= new_sh_video(demuxer
, 0);
642 /* get IMAGE FORMAT */
643 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
644 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
645 // sh_video->format = 0x0;
647 /* set FPS and FRAMETIME */
652 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
653 sh_video
->fps
= 25.0f
; /* on PAL */
654 else sh_video
->fps
= tmp
;
657 if (tvh
->tv_param
->fps
!= -1.0f
)
658 sh_video
->fps
= tvh
->tv_param
->fps
;
660 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
662 /* If playback only mode, go to immediate mode, fail silently */
663 if(tvh
->tv_param
->immediate
== 1)
665 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
666 tvh
->tv_param
->noaudio
= 1;
669 /* disable TV audio if -nosound is present */
670 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
671 tvh
->tv_param
->noaudio
= 1;
675 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
678 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
680 demuxer
->video
->sh
= sh_video
;
681 sh_video
->ds
= demuxer
->video
;
682 demuxer
->video
->id
= 0;
683 demuxer
->seekable
= 0;
685 /* here comes audio init */
686 if (tvh
->tv_param
->noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
692 /* yeah, audio is present */
694 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
695 &tvh
->tv_param
->audiorate
);
697 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
704 case AF_FORMAT_U16_LE
:
705 case AF_FORMAT_U16_BE
:
706 case AF_FORMAT_S16_LE
:
707 case AF_FORMAT_S16_BE
:
708 case AF_FORMAT_S32_LE
:
709 case AF_FORMAT_S32_BE
:
710 sh_audio_format
= 0x1; /* PCM */
712 case AF_FORMAT_IMA_ADPCM
:
713 case AF_FORMAT_MU_LAW
:
714 case AF_FORMAT_A_LAW
:
715 case AF_FORMAT_MPEG2
:
718 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnsupportedAudioType
,
719 af_fmt2str(audio_format
, buf
, 128), audio_format
);
723 sh_audio
= new_sh_audio(demuxer
, 0);
725 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
726 &sh_audio
->samplerate
);
727 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
728 &sh_audio
->samplesize
);
729 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
730 &sh_audio
->channels
);
732 sh_audio
->format
= sh_audio_format
;
733 sh_audio
->sample_format
= audio_format
;
735 sh_audio
->i_bps
= sh_audio
->o_bps
=
736 sh_audio
->samplerate
* sh_audio
->samplesize
*
739 // emulate WF for win32 codecs:
740 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
741 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
742 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
743 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
744 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
745 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
746 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
748 mp_msg(MSGT_DECVIDEO
, MSGL_V
, MSGTR_TV_AudioFormat
,
749 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
750 sh_audio
->wf
->nSamplesPerSec
);
752 demuxer
->audio
->sh
= sh_audio
;
753 sh_audio
->ds
= demuxer
->audio
;
754 demuxer
->audio
->id
= 0;
758 if(!(funcs
->start(tvh
->priv
))){
765 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
766 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
767 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
768 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
770 if(tvh
->tv_param
->gain
!=-1)
771 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
772 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
774 funcs
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
779 static void demux_close_tv(demuxer_t
*demuxer
)
781 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
788 /* utilities for mplayer (not mencoder!!) */
789 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
791 const tvi_functions_t
*funcs
= tvh
->functions
;
795 case TV_COLOR_BRIGHTNESS
:
796 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
798 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
799 case TV_COLOR_SATURATION
:
800 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
801 case TV_COLOR_CONTRAST
:
802 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
804 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
807 return(TVI_CONTROL_UNKNOWN
);
810 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
812 const tvi_functions_t
*funcs
= tvh
->functions
;
816 case TV_COLOR_BRIGHTNESS
:
817 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
819 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
820 case TV_COLOR_SATURATION
:
821 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
822 case TV_COLOR_CONTRAST
:
823 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
825 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
828 return(TVI_CONTROL_UNKNOWN
);
831 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
833 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
835 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
836 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
837 *freq
, (float)*freq
/16);
842 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
844 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
846 // unsigned long freq = atof(tvh->tv_param->freq)*16;
848 /* set freq in MHz */
849 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
851 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
852 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
853 freq
, (float)freq
/16);
855 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
859 int tv_get_signal(tvi_handle_t
*tvh
)
862 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
863 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
869 /*****************************************************************
870 * \brief tune current frequency by step_interval value
871 * \parameter step_interval increment value in 1/16 MHz
872 * \note frequency is rounded to 1/16 MHz value
876 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
877 unsigned long frequency
;
879 tvh
->tv_param
->scan
=0;
880 tv_get_freq(tvh
,&frequency
);
881 frequency
+=step_interval
;
882 return tv_set_freq(tvh
,frequency
);
885 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
889 tvh
->tv_param
->scan
=0;
890 if (direction
== TV_CHANNEL_LOWER
)
892 if (tvh
->channel
-1 >= 0)
894 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
895 cl
= tvh
->chanlist_s
[--tvh
->channel
];
896 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
897 cl
.name
, (float)cl
.freq
/1000);
898 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
902 if (direction
== TV_CHANNEL_HIGHER
)
904 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
906 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
907 cl
= tvh
->chanlist_s
[++tvh
->channel
];
908 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
909 cl
.name
, (float)cl
.freq
/1000);
910 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
916 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
917 tvh
->tv_param
->scan
=0;
918 if (tv_channel_list
) {
919 if (direction
== TV_CHANNEL_HIGHER
) {
920 tv_channel_last
= tv_channel_current
;
921 if (tv_channel_current
->next
)
922 tv_channel_current
= tv_channel_current
->next
;
924 tv_channel_current
= tv_channel_list
;
925 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
926 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
927 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
929 if (direction
== TV_CHANNEL_LOWER
) {
930 tv_channel_last
= tv_channel_current
;
931 if (tv_channel_current
->prev
)
932 tv_channel_current
= tv_channel_current
->prev
;
934 while (tv_channel_current
->next
)
935 tv_channel_current
= tv_channel_current
->next
;
936 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
937 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
938 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
940 } else tv_step_channel_real(tvh
, direction
);
944 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
948 tvh
->tv_param
->scan
=0;
949 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
950 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
952 cl
= tvh
->chanlist_s
[i
];
953 // printf("count%d: name: %s, freq: %d\n",
954 // i, cl.name, cl.freq);
955 if (!strcasecmp(cl
.name
, 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));
967 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
970 tvh
->tv_param
->scan
=0;
971 if (tv_channel_list
) {
972 tv_channel_last
= tv_channel_current
;
973 channel_int
= atoi(channel
);
974 tv_channel_current
= tv_channel_list
;
975 for (i
= 1; i
< channel_int
; i
++)
976 if (tv_channel_current
->next
)
977 tv_channel_current
= tv_channel_current
->next
;
978 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
979 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
980 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
981 } else tv_set_channel_real(tvh
, channel
);
985 int tv_last_channel(tvi_handle_t
*tvh
) {
987 tvh
->tv_param
->scan
=0;
988 if (tv_channel_list
) {
991 tmp
= tv_channel_last
;
992 tv_channel_last
= tv_channel_current
;
993 tv_channel_current
= tmp
;
995 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
996 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
997 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1002 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1004 cl
= tvh
->chanlist_s
[i
];
1005 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1007 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1009 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1010 cl
.name
, (float)cl
.freq
/1000);
1011 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1019 int tv_step_norm(tvi_handle_t
*tvh
)
1022 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1023 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1025 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1026 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1027 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1031 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1035 int tv_step_chanlist(tvi_handle_t
*tvh
)
1040 int tv_set_norm(tvi_handle_t
*tvh
, char* norm
)
1042 tvh
->norm
= norm_from_string(tvh
, norm
);
1044 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNorm
, norm
);
1045 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1046 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1049 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1053 demuxer_desc_t demuxer_desc_tv
= {
1057 "Alex Beregszaszi, Charles R. Henrich",
1062 demux_tv_fill_buffer
,