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 tvi_info_t tvi_info_dummy
;
46 extern tvi_info_dshow
;
49 extern tvi_info_t tvi_info_v4l
;
52 extern tvi_info_t tvi_info_v4l2
;
54 #ifdef HAVE_TV_BSDBT848
55 extern tvi_info_t tvi_info_bsdbt848
;
58 /** List of drivers in autodetection order */
59 static const tvi_info_t
* tvi_driver_list
[]={
66 #ifdef HAVE_TV_BSDBT848
76 void tv_start_scan(tvi_handle_t
*tvh
, int start
)
78 mp_msg(MSGT_TV
,MSGL_INFO
,"start scan\n");
79 tvh
->tv_param
->scan
=start
?1:0;
82 static void tv_scan(tvi_handle_t
*tvh
)
86 tv_channels_t
*tv_channel_tmp
=NULL
;
87 tv_channels_t
*tv_channel_add
=NULL
;
91 //Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s
92 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
94 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ScannerNotAvailableWithoutTuner
);
95 tvh
->tv_param
->scan
=0;
102 scan
=calloc(1,sizeof(tv_scan_t
));
104 cl
= tvh
->chanlist_s
[scan
->channel_num
];
105 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
106 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
108 if(scan
->scan_timer
>now
)
111 if (tv_get_signal(tvh
)>tvh
->tv_param
->scan_threshold
) {
112 cl
= tvh
->chanlist_s
[scan
->channel_num
];
113 tv_channel_tmp
=tv_channel_list
;
114 while (tv_channel_tmp
) {
116 if (cl
.freq
==tv_channel_tmp
->freq
){
120 tv_channel_add
=tv_channel_tmp
;
121 tv_channel_tmp
=tv_channel_tmp
->next
;
124 mp_msg(MSGT_TV
, MSGL_INFO
, "Found new channel: %s (#%d). \n",cl
.name
,index
);
125 scan
->new_channels
++;
126 tv_channel_tmp
= malloc(sizeof(tv_channels_t
));
127 tv_channel_tmp
->index
=index
;
128 tv_channel_tmp
->next
=NULL
;
129 tv_channel_tmp
->prev
=tv_channel_add
;
130 tv_channel_tmp
->freq
=cl
.freq
;
131 snprintf(tv_channel_tmp
->name
,sizeof(tv_channel_tmp
->name
),"ch%d",index
);
132 strncpy(tv_channel_tmp
->number
, cl
.name
, 5);
133 tv_channel_tmp
->number
[4]='\0';
134 if (!tv_channel_list
)
135 tv_channel_list
=tv_channel_tmp
;
137 tv_channel_add
->next
=tv_channel_tmp
;
138 tv_channel_list
->prev
=tv_channel_tmp
;
141 mp_msg(MSGT_TV
, MSGL_INFO
, "Found existing channel: %s-%s.\n",
142 tv_channel_tmp
->number
,tv_channel_tmp
->name
);
145 scan
->scan_timer
=now
+1e6
*tvh
->tv_param
->scan_period
;
146 if (scan
->channel_num
>=chanlists
[tvh
->chanlist
].count
) {
147 tvh
->tv_param
->scan
=0;
148 mp_msg(MSGT_TV
, MSGL_INFO
, "TV scan end. Found %d new channels.\n", scan
->new_channels
);
149 tv_channel_tmp
=tv_channel_list
;
151 mp_msg(MSGT_TV
,MSGL_INFO
,"channels=");
152 while(tv_channel_tmp
){
153 mp_msg(MSGT_TV
,MSGL_INFO
,"%s-%s",tv_channel_tmp
->number
,tv_channel_tmp
->name
);
154 if(tv_channel_tmp
->next
)
155 mp_msg(MSGT_TV
,MSGL_INFO
,",");
156 tv_channel_tmp
=tv_channel_tmp
->next
;
158 mp_msg(MSGT_TV
, MSGL_INFO
, "\n");
160 if (!tv_channel_current
) tv_channel_current
=tv_channel_list
;
161 if (tv_channel_current
)
162 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
166 cl
= tvh
->chanlist_s
[scan
->channel_num
];
167 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
168 mp_msg(MSGT_TV
, MSGL_INFO
, "Trying: %s (%.2f). \n",cl
.name
,1e-3*cl
.freq
);
172 /* ================== DEMUX_TV ===================== */
175 0 = EOF(?) or no stream
176 1 = successfully read a packet
178 /* fill demux->video and demux->audio */
180 static int demux_tv_fill_buffer(demuxer_t
*demux
, demux_stream_t
*ds
)
182 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demux
->priv
);
186 /* ================== ADD AUDIO PACKET =================== */
188 if (ds
==demux
->audio
&& tvh
->tv_param
->noaudio
== 0 &&
189 tvh
->functions
->control(tvh
->priv
,
190 TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
192 len
= tvh
->functions
->get_audio_framesize(tvh
->priv
);
194 dp
=new_demux_packet(len
);
195 dp
->flags
|=1; /* Keyframe */
196 dp
->pts
=tvh
->functions
->grab_audio_frame(tvh
->priv
, dp
->buffer
,len
);
197 ds_add_packet(demux
->audio
,dp
);
200 /* ================== ADD VIDEO PACKET =================== */
202 if (ds
==demux
->video
&& tvh
->functions
->control(tvh
->priv
,
203 TVI_CONTROL_IS_VIDEO
, 0) == TVI_CONTROL_TRUE
)
205 len
= tvh
->functions
->get_video_framesize(tvh
->priv
);
206 dp
=new_demux_packet(len
);
207 dp
->flags
|=1; /* Keyframe */
208 dp
->pts
=tvh
->functions
->grab_video_frame(tvh
->priv
, dp
->buffer
, len
);
209 ds_add_packet(demux
->video
,dp
);
212 if (tvh
->tv_param
->scan
) tv_scan(tvh
);
216 static int norm_from_string(tvi_handle_t
*tvh
, char* norm
)
218 tvi_functions_t
*funcs
= tvh
->functions
;
222 strncpy(str
, norm
, sizeof(str
)-1);
223 str
[sizeof(str
)-1] = '\0';
224 ret
=funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_GET_NORMID
, str
);
226 if(ret
==TVI_CONTROL_TRUE
)
229 if(ret
!=TVI_CONTROL_UNKNOWN
)
231 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_BogusNormParameter
, norm
,"default");
235 if (!strcasecmp(norm
, "pal"))
237 else if (!strcasecmp(norm
, "ntsc"))
239 else if (!strcasecmp(norm
, "secam"))
240 return TV_NORM_SECAM
;
241 else if (!strcasecmp(norm
, "palnc"))
242 return TV_NORM_PALNC
;
243 else if (!strcasecmp(norm
, "palm"))
245 else if (!strcasecmp(norm
, "paln"))
247 else if (!strcasecmp(norm
, "ntscjp"))
248 return TV_NORM_NTSCJP
;
250 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_BogusNormParameter
, norm
, "PAL");
255 static void parse_channels(tvi_handle_t
*tvh
)
257 char** channels
= tvh
->tv_param
->channels
;
259 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_ChannelNamesDetected
);
260 tv_channel_list
= malloc(sizeof(tv_channels_t
));
261 tv_channel_list
->index
=1;
262 tv_channel_list
->next
=NULL
;
263 tv_channel_list
->prev
=NULL
;
264 tv_channel_current
= tv_channel_list
;
267 char* tmp
= *(channels
++);
268 char* sep
= strchr(tmp
,'-');
272 if (!sep
) continue; // Wrong syntax, but mplayer should not crash
274 av_strlcpy(tv_channel_current
->name
, sep
+ 1,
275 sizeof(tv_channel_current
->name
));
277 strncpy(tv_channel_current
->number
, tmp
, 5);
278 tv_channel_current
->number
[4]='\0';
280 while ((sep
=strchr(tv_channel_current
->name
, '_')))
283 // if channel number is a number and larger than 1000 threat it as frequency
284 // tmp still contain pointer to null-terminated string with channel number here
286 tv_channel_current
->freq
=atoi(tmp
);
288 tv_channel_current
->freq
= 0;
289 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++) {
290 cl
= tvh
->chanlist_s
[i
];
291 if (!strcasecmp(cl
.name
, tv_channel_current
->number
)) {
292 tv_channel_current
->freq
=cl
.freq
;
297 if (tv_channel_current
->freq
== 0)
298 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoFreqForChannel
,
299 tv_channel_current
->number
, tv_channel_current
->name
);
301 sep
= strchr(tv_channel_current
->name
, '-');
302 if ( !sep
) sep
= strchr(tv_channel_current
->name
, '+');
306 if ( sep
[0] == '+' ) tv_channel_current
->freq
+= i
* 100;
307 if ( sep
[0] == '-' ) tv_channel_current
->freq
-= i
* 100;
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
;
322 if (tv_channel_current
->prev
)
323 tv_channel_current
->prev
->next
= NULL
;
324 free(tv_channel_current
);
326 static int open_tv(tvi_handle_t
*tvh
)
329 tvi_functions_t
*funcs
= tvh
->functions
;
330 int tv_fmt_list
[] = {
341 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_VIDEO
, 0) != TVI_CONTROL_TRUE
)
343 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoVideoInputPresent
);
347 if (tvh
->tv_param
->outfmt
== -1)
348 for (i
= 0; i
< sizeof (tv_fmt_list
) / sizeof (*tv_fmt_list
); i
++)
350 tvh
->tv_param
->outfmt
= tv_fmt_list
[i
];
351 if (funcs
->control (tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
,
352 &tvh
->tv_param
->outfmt
) == TVI_CONTROL_TRUE
)
357 switch(tvh
->tv_param
->outfmt
)
371 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnknownImageFormat
,tvh
->tv_param
->outfmt
);
373 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_FORMAT
, &tvh
->tv_param
->outfmt
);
376 /* set some params got from cmdline */
377 funcs
->control(tvh
->priv
, TVI_CONTROL_SPC_SET_INPUT
, &tvh
->tv_param
->input
);
379 #if defined(HAVE_TV_V4L2) || defined(HAVE_TV_DSHOW)
382 || (!strcmp(tvh
->tv_param
->driver
, "v4l2") && tvh
->tv_param
->normid
>= 0)
385 || (!strcmp(tvh
->tv_param
->driver
, "dshow") && tvh
->tv_param
->normid
>= 0)
388 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNormId
, tvh
->tv_param
->normid
);
389 if (funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->tv_param
->normid
) != TVI_CONTROL_TRUE
) {
390 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
394 tv_set_norm(tvh
,tvh
->tv_param
->norm
);
397 if ( tvh
->tv_param
->mjpeg
)
399 /* set width to expected value */
400 if (tvh
->tv_param
->width
== -1)
402 tvh
->tv_param
->width
= 704/tvh
->tv_param
->decimation
;
404 if (tvh
->tv_param
->height
== -1)
406 if ( tvh
->norm
!= TV_NORM_NTSC
)
407 tvh
->tv_param
->height
= 576/tvh
->tv_param
->decimation
;
409 tvh
->tv_param
->height
= 480/tvh
->tv_param
->decimation
;
411 mp_msg(MSGT_TV
, MSGL_INFO
,
412 MSGTR_TV_MJP_WidthHeight
, tvh
->tv_param
->width
, tvh
->tv_param
->height
);
416 /* limits on w&h are norm-dependent -- JM */
418 if (tvh
->tv_param
->width
!= -1)
420 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_WIDTH
, &tvh
->tv_param
->width
) == TVI_CONTROL_TRUE
)
421 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_WIDTH
, &tvh
->tv_param
->width
);
424 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetWidth
, tvh
->tv_param
->width
);
425 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &tvh
->tv_param
->width
);
430 if (tvh
->tv_param
->height
!= -1)
432 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_CHK_HEIGHT
, &tvh
->tv_param
->height
) == TVI_CONTROL_TRUE
)
433 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HEIGHT
, &tvh
->tv_param
->height
);
436 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnableToSetHeight
, tvh
->tv_param
->height
);
437 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &tvh
->tv_param
->height
);
441 if (funcs
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
)
443 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_NoTuner
);
447 /* select channel list */
448 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
450 if (!strcasecmp(chanlists
[i
].name
, tvh
->tv_param
->chanlist
))
453 tvh
->chanlist_s
= chanlists
[i
].list
;
458 if (tvh
->chanlist
== -1)
459 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnableFindChanlist
,
460 tvh
->tv_param
->chanlist
);
462 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedChanlist
,
463 chanlists
[tvh
->chanlist
].name
, chanlists
[tvh
->chanlist
].count
);
465 if (tvh
->tv_param
->freq
&& tvh
->tv_param
->channel
)
467 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_ChannelFreqParamConflict
);
471 /* Handle channel names */
472 if (tvh
->tv_param
->channels
) {
475 tv_channel_last_real
= malloc(5);
477 if (tv_channel_list
) {
480 if (tvh
->tv_param
->channel
)
482 if (isdigit(*tvh
->tv_param
->channel
))
483 /* if tvh->tv_param->channel begins with a digit interpret it as a number */
484 channel
= atoi(tvh
->tv_param
->channel
);
487 /* if tvh->tv_param->channel does not begin with a digit
488 set the first channel that contains tvh->tv_param->channel in its name */
490 tv_channel_current
= tv_channel_list
;
491 while ( tv_channel_current
) {
492 if ( strstr(tv_channel_current
->name
, tvh
->tv_param
->channel
) )
494 tv_channel_current
= tv_channel_current
->next
;
496 if ( !tv_channel_current
) tv_channel_current
= tv_channel_list
;
503 tv_channel_current
= tv_channel_list
;
504 for (i
= 1; i
< channel
; i
++)
505 if (tv_channel_current
->next
)
506 tv_channel_current
= tv_channel_current
->next
;
509 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
510 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
511 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
512 tv_channel_last
= tv_channel_current
;
514 /* we need to set frequency */
515 if (tvh
->tv_param
->freq
)
517 unsigned long freq
= atof(tvh
->tv_param
->freq
)*16;
519 /* set freq in MHz */
520 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
522 funcs
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
523 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedFrequency
,
524 freq
, (float)freq
/16);
527 if (tvh
->tv_param
->channel
) {
530 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_RequestedChannel
, tvh
->tv_param
->channel
);
531 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
533 cl
= tvh
->chanlist_s
[i
];
534 // printf("count%d: name: %s, freq: %d\n",
535 // i, cl.name, cl.freq);
536 if (!strcasecmp(cl
.name
, tvh
->tv_param
->channel
))
538 strcpy(tv_channel_last_real
, cl
.name
);
540 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
541 cl
.name
, (float)cl
.freq
/1000);
542 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
549 /* grep frequency in chanlist */
554 tv_get_freq(tvh
, &i2
);
556 freq
= (int) (((float)(i2
/16))*1000)+250;
558 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
560 if (tvh
->chanlist_s
[i
].freq
== freq
)
569 /* also start device! */
573 static tvi_handle_t
*tv_begin(tv_param_t
* tv_param
)
577 if(tv_param
->driver
&& !strcmp(tv_param
->driver
,"help")){
578 mp_msg(MSGT_TV
,MSGL_INFO
,MSGTR_TV_AvailableDrivers
);
579 for(i
=0;tvi_driver_list
[i
];i
++){
580 mp_msg(MSGT_TV
,MSGL_INFO
," %s\t%s",tvi_driver_list
[i
]->short_name
,tvi_driver_list
[i
]->name
);
581 if(tvi_driver_list
[i
]->comment
)
582 mp_msg(MSGT_TV
,MSGL_INFO
," (%s)",tvi_driver_list
[i
]->comment
);
583 mp_msg(MSGT_TV
,MSGL_INFO
,"\n");
588 for(i
=0;tvi_driver_list
[i
];i
++){
589 if (!tv_param
->driver
|| !strcmp(tvi_driver_list
[i
]->short_name
, tv_param
->driver
)){
590 h
=tvi_driver_list
[i
]->tvi_init(tv_param
);
591 //Requested driver initialization failed
592 if (!h
&& tv_param
->driver
)
594 //Driver initialization failed during autodetection process.
598 h
->tv_param
=tv_param
;
599 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_DriverInfo
, tvi_driver_list
[i
]->short_name
,
600 tvi_driver_list
[i
]->name
,
601 tvi_driver_list
[i
]->author
,
602 tvi_driver_list
[i
]->comment
?tvi_driver_list
[i
]->comment
:"");
603 tv_param
->driver
=strdup(tvi_driver_list
[i
]->short_name
);
609 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_NoSuchDriver
, tv_param
->driver
);
611 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_DriverAutoDetectionFailed
);
615 static int tv_uninit(tvi_handle_t
*tvh
)
619 if (!tvh
->priv
) return 1;
620 res
=tvh
->functions
->uninit(tvh
->priv
);
628 static demuxer_t
* demux_open_tv(demuxer_t
*demuxer
)
631 sh_video_t
*sh_video
;
632 sh_audio_t
*sh_audio
= NULL
;
633 tvi_functions_t
*funcs
;
636 if(!(tvh
=tv_begin(demuxer
->stream
->priv
))) return NULL
;
637 if (!tvh
->functions
->init(tvh
->priv
)) return NULL
;
639 tvh
->functions
->control(tvh
->priv
,TVI_CONTROL_VBI_INIT
,&(tvh
->tv_param
->tdevice
));
645 funcs
= tvh
->functions
;
648 sh_video
= new_sh_video(demuxer
, 0);
650 /* get IMAGE FORMAT */
651 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FORMAT
, &sh_video
->format
);
652 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
653 // sh_video->format = 0x0;
655 /* set FPS and FRAMETIME */
660 if (funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_FPS
, &tmp
) != TVI_CONTROL_TRUE
)
661 sh_video
->fps
= 25.0f
; /* on PAL */
662 else sh_video
->fps
= tmp
;
665 if (tvh
->tv_param
->fps
!= -1.0f
)
666 sh_video
->fps
= tvh
->tv_param
->fps
;
668 sh_video
->frametime
= 1.0f
/sh_video
->fps
;
670 /* If playback only mode, go to immediate mode, fail silently */
671 if(tvh
->tv_param
->immediate
== 1)
673 funcs
->control(tvh
->priv
, TVI_CONTROL_IMMEDIATE
, 0);
674 tvh
->tv_param
->noaudio
= 1;
677 /* disable TV audio if -nosound is present */
678 if (!demuxer
->audio
|| demuxer
->audio
->id
== -2) {
679 tvh
->tv_param
->noaudio
= 1;
683 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_WIDTH
, &sh_video
->disp_w
);
686 funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HEIGHT
, &sh_video
->disp_h
);
688 demuxer
->video
->sh
= sh_video
;
689 sh_video
->ds
= demuxer
->video
;
690 demuxer
->video
->id
= 0;
691 demuxer
->seekable
= 0;
693 /* here comes audio init */
694 if (tvh
->tv_param
->noaudio
== 0 && funcs
->control(tvh
->priv
, TVI_CONTROL_IS_AUDIO
, 0) == TVI_CONTROL_TRUE
)
700 /* yeah, audio is present */
702 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_SET_SAMPLERATE
,
703 &tvh
->tv_param
->audiorate
);
705 if (funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_FORMAT
, &audio_format
) != TVI_CONTROL_TRUE
)
712 case AF_FORMAT_U16_LE
:
713 case AF_FORMAT_U16_BE
:
714 case AF_FORMAT_S16_LE
:
715 case AF_FORMAT_S16_BE
:
716 case AF_FORMAT_S32_LE
:
717 case AF_FORMAT_S32_BE
:
718 sh_audio_format
= 0x1; /* PCM */
720 case AF_FORMAT_IMA_ADPCM
:
721 case AF_FORMAT_MU_LAW
:
722 case AF_FORMAT_A_LAW
:
723 case AF_FORMAT_MPEG2
:
726 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_UnsupportedAudioType
,
727 af_fmt2str(audio_format
, buf
, 128), audio_format
);
731 sh_audio
= new_sh_audio(demuxer
, 0);
733 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLERATE
,
734 &sh_audio
->samplerate
);
735 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_SAMPLESIZE
,
736 &sh_audio
->samplesize
);
737 funcs
->control(tvh
->priv
, TVI_CONTROL_AUD_GET_CHANNELS
,
738 &sh_audio
->channels
);
740 sh_audio
->format
= sh_audio_format
;
741 sh_audio
->sample_format
= audio_format
;
743 sh_audio
->i_bps
= sh_audio
->o_bps
=
744 sh_audio
->samplerate
* sh_audio
->samplesize
*
747 // emulate WF for win32 codecs:
748 sh_audio
->wf
= malloc(sizeof(WAVEFORMATEX
));
749 sh_audio
->wf
->wFormatTag
= sh_audio
->format
;
750 sh_audio
->wf
->nChannels
= sh_audio
->channels
;
751 sh_audio
->wf
->wBitsPerSample
= sh_audio
->samplesize
* 8;
752 sh_audio
->wf
->nSamplesPerSec
= sh_audio
->samplerate
;
753 sh_audio
->wf
->nBlockAlign
= sh_audio
->samplesize
* sh_audio
->channels
;
754 sh_audio
->wf
->nAvgBytesPerSec
= sh_audio
->i_bps
;
756 mp_msg(MSGT_DECVIDEO
, MSGL_V
, MSGTR_TV_AudioFormat
,
757 sh_audio
->wf
->nChannels
, sh_audio
->wf
->wBitsPerSample
,
758 sh_audio
->wf
->nSamplesPerSec
);
760 demuxer
->audio
->sh
= sh_audio
;
761 sh_audio
->ds
= demuxer
->audio
;
762 demuxer
->audio
->id
= 0;
766 if(!(funcs
->start(tvh
->priv
))){
773 tv_set_color_options(tvh
, TV_COLOR_BRIGHTNESS
, tvh
->tv_param
->brightness
);
774 tv_set_color_options(tvh
, TV_COLOR_HUE
, tvh
->tv_param
->hue
);
775 tv_set_color_options(tvh
, TV_COLOR_SATURATION
, tvh
->tv_param
->saturation
);
776 tv_set_color_options(tvh
, TV_COLOR_CONTRAST
, tvh
->tv_param
->contrast
);
778 if(tvh
->tv_param
->gain
!=-1)
779 if(funcs
->control(tvh
->priv
,TVI_CONTROL_VID_SET_GAIN
,&tvh
->tv_param
->gain
)!=TVI_CONTROL_TRUE
)
780 mp_msg(MSGT_TV
,MSGL_WARN
,"Unable to set gain control!\n");
782 funcs
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
787 static void demux_close_tv(demuxer_t
*demuxer
)
789 tvi_handle_t
*tvh
=(tvi_handle_t
*)(demuxer
->priv
);
796 /* utilities for mplayer (not mencoder!!) */
797 int tv_set_color_options(tvi_handle_t
*tvh
, int opt
, int value
)
799 tvi_functions_t
*funcs
= tvh
->functions
;
803 case TV_COLOR_BRIGHTNESS
:
804 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_BRIGHTNESS
, &value
);
806 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_HUE
, &value
);
807 case TV_COLOR_SATURATION
:
808 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_SATURATION
, &value
);
809 case TV_COLOR_CONTRAST
:
810 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_SET_CONTRAST
, &value
);
812 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
815 return(TVI_CONTROL_UNKNOWN
);
818 int tv_get_color_options(tvi_handle_t
*tvh
, int opt
, int* value
)
820 tvi_functions_t
*funcs
= tvh
->functions
;
824 case TV_COLOR_BRIGHTNESS
:
825 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_BRIGHTNESS
, value
);
827 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_HUE
, value
);
828 case TV_COLOR_SATURATION
:
829 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_SATURATION
, value
);
830 case TV_COLOR_CONTRAST
:
831 return funcs
->control(tvh
->priv
, TVI_CONTROL_VID_GET_CONTRAST
, value
);
833 mp_msg(MSGT_TV
, MSGL_WARN
, MSGTR_TV_UnknownColorOption
, opt
);
836 return(TVI_CONTROL_UNKNOWN
);
839 int tv_get_freq(tvi_handle_t
*tvh
, unsigned long *freq
)
841 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
843 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, freq
);
844 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
845 *freq
, (float)*freq
/16);
850 int tv_set_freq(tvi_handle_t
*tvh
, unsigned long freq
)
852 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) == TVI_CONTROL_TRUE
)
854 // unsigned long freq = atof(tvh->tv_param->freq)*16;
856 /* set freq in MHz */
857 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_FREQ
, &freq
);
859 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_FREQ
, &freq
);
860 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_CurrentFrequency
,
861 freq
, (float)freq
/16);
863 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
867 int tv_get_signal(tvi_handle_t
*tvh
)
870 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_IS_TUNER
, 0) != TVI_CONTROL_TRUE
||
871 tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_GET_SIGNAL
, &signal
)!=TVI_CONTROL_TRUE
)
877 /*****************************************************************
878 * \brief tune current frequency by step_interval value
879 * \parameter step_interval increment value in 1/16 MHz
880 * \note frequency is rounded to 1/16 MHz value
884 int tv_step_freq(tvi_handle_t
* tvh
, float step_interval
){
885 unsigned long frequency
;
887 tvh
->tv_param
->scan
=0;
888 tv_get_freq(tvh
,&frequency
);
889 frequency
+=step_interval
;
890 return tv_set_freq(tvh
,frequency
);
893 int tv_step_channel_real(tvi_handle_t
*tvh
, int direction
)
897 tvh
->tv_param
->scan
=0;
898 if (direction
== TV_CHANNEL_LOWER
)
900 if (tvh
->channel
-1 >= 0)
902 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
903 cl
= tvh
->chanlist_s
[--tvh
->channel
];
904 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
905 cl
.name
, (float)cl
.freq
/1000);
906 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
910 if (direction
== TV_CHANNEL_HIGHER
)
912 if (tvh
->channel
+1 < chanlists
[tvh
->chanlist
].count
)
914 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
915 cl
= tvh
->chanlist_s
[++tvh
->channel
];
916 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
917 cl
.name
, (float)cl
.freq
/1000);
918 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
924 int tv_step_channel(tvi_handle_t
*tvh
, int direction
) {
925 tvh
->tv_param
->scan
=0;
926 if (tv_channel_list
) {
927 if (direction
== TV_CHANNEL_HIGHER
) {
928 tv_channel_last
= tv_channel_current
;
929 if (tv_channel_current
->next
)
930 tv_channel_current
= tv_channel_current
->next
;
932 tv_channel_current
= tv_channel_list
;
933 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
934 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
935 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
937 if (direction
== TV_CHANNEL_LOWER
) {
938 tv_channel_last
= tv_channel_current
;
939 if (tv_channel_current
->prev
)
940 tv_channel_current
= tv_channel_current
->prev
;
942 while (tv_channel_current
->next
)
943 tv_channel_current
= tv_channel_current
->next
;
944 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
945 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
,
946 tv_channel_current
->number
, tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
948 } else tv_step_channel_real(tvh
, direction
);
952 int tv_set_channel_real(tvi_handle_t
*tvh
, char *channel
) {
956 tvh
->tv_param
->scan
=0;
957 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
958 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
960 cl
= tvh
->chanlist_s
[i
];
961 // printf("count%d: name: %s, freq: %d\n",
962 // i, cl.name, cl.freq);
963 if (!strcasecmp(cl
.name
, channel
))
966 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
967 cl
.name
, (float)cl
.freq
/1000);
968 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
975 int tv_set_channel(tvi_handle_t
*tvh
, char *channel
) {
978 tvh
->tv_param
->scan
=0;
979 if (tv_channel_list
) {
980 tv_channel_last
= tv_channel_current
;
981 channel_int
= atoi(channel
);
982 tv_channel_current
= tv_channel_list
;
983 for (i
= 1; i
< channel_int
; i
++)
984 if (tv_channel_current
->next
)
985 tv_channel_current
= tv_channel_current
->next
;
986 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
987 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
988 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
989 } else tv_set_channel_real(tvh
, channel
);
993 int tv_last_channel(tvi_handle_t
*tvh
) {
995 tvh
->tv_param
->scan
=0;
996 if (tv_channel_list
) {
999 tmp
= tv_channel_last
;
1000 tv_channel_last
= tv_channel_current
;
1001 tv_channel_current
= tmp
;
1003 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel3
, tv_channel_current
->number
,
1004 tv_channel_current
->name
, (float)tv_channel_current
->freq
/1000);
1005 tv_set_freq(tvh
, (unsigned long)(((float)tv_channel_current
->freq
/1000)*16));
1010 for (i
= 0; i
< chanlists
[tvh
->chanlist
].count
; i
++)
1012 cl
= tvh
->chanlist_s
[i
];
1013 if (!strcasecmp(cl
.name
, tv_channel_last_real
))
1015 strcpy(tv_channel_last_real
, tvh
->chanlist_s
[tvh
->channel
].name
);
1017 mp_msg(MSGT_TV
, MSGL_INFO
, MSGTR_TV_SelectedChannel2
,
1018 cl
.name
, (float)cl
.freq
/1000);
1019 tv_set_freq(tvh
, (unsigned long)(((float)cl
.freq
/1000)*16));
1027 int tv_step_norm(tvi_handle_t
*tvh
)
1030 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1031 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1033 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
,
1034 &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1035 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1039 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1043 int tv_step_chanlist(tvi_handle_t
*tvh
)
1048 int tv_set_norm(tvi_handle_t
*tvh
, char* norm
)
1050 tvh
->norm
= norm_from_string(tvh
, norm
);
1052 mp_msg(MSGT_TV
, MSGL_V
, MSGTR_TV_SelectedNorm
, norm
);
1053 if (tvh
->functions
->control(tvh
->priv
, TVI_CONTROL_TUN_SET_NORM
, &tvh
->norm
) != TVI_CONTROL_TRUE
) {
1054 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_TV_CannotSetNorm
);
1057 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_RESET
,tvh
->tv_param
);
1061 demuxer_desc_t demuxer_desc_tv
= {
1065 "Alex Beregszaszi, Charles R. Henrich",
1070 demux_tv_fill_buffer
,