2 * stream layer for hardware MPEG 1/2/4 encoders a.k.a PVR
3 * (such as WinTV PVR-150/250/350/500 (a.k.a IVTV), pvrusb2 and cx88)
4 * See http://ivtvdriver.org/index.php/Main_Page for more details on the
5 * cards supported by the ivtv driver.
7 * Copyright (C) 2006 Benjamin Zores
8 * Copyright (C) 2007 Sven Gothel (channel navigation)
10 * This file is part of MPlayer.
12 * MPlayer is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * MPlayer is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 #include <sys/ioctl.h>
37 #include <sys/fcntl.h>
40 #include <linux/types.h>
41 #include <linux/videodev2.h>
48 #include "frequencies.h"
49 #include "libavutil/common.h"
50 #include "libavutil/avstring.h"
52 #define PVR_DEFAULT_DEVICE "/dev/video0"
53 #define PVR_MAX_CONTROLS 10
55 /* logging mechanisms */
56 #define LOG_LEVEL_PVR "[pvr]"
57 #define LOG_LEVEL_V4L2 "[v4l2]"
58 #define LOG_LEVEL_ENCODER "[encoder]"
60 /* audio codec mode */
61 #define PVR_AUDIO_MODE_ARG_STEREO "stereo"
62 #define PVR_AUDIO_MODE_ARG_JOINT_STEREO "joint_stereo"
63 #define PVR_AUDIO_MODE_ARG_DUAL "dual"
64 #define PVR_AUDIO_MODE_ARG_MONO "mono"
66 /* video codec bitrate mode */
67 #define PVR_VIDEO_BITRATE_MODE_ARG_VBR "vbr"
68 #define PVR_VIDEO_BITRATE_MODE_ARG_CBR "cbr"
70 /* video codec stream type */
71 #define PVR_VIDEO_STREAM_TYPE_PS "ps"
72 #define PVR_VIDEO_STREAM_TYPE_TS "ts"
73 #define PVR_VIDEO_STREAM_TYPE_MPEG1 "mpeg1"
74 #define PVR_VIDEO_STREAM_TYPE_DVD "dvd"
75 #define PVR_VIDEO_STREAM_TYPE_VCD "vcd"
76 #define PVR_VIDEO_STREAM_TYPE_SVCD "svcd"
78 #define PVR_STATION_NAME_SIZE 256
80 /* command line arguments */
81 int pvr_param_aspect_ratio
= 0;
82 int pvr_param_sample_rate
= 0;
83 int pvr_param_audio_layer
= 0;
84 int pvr_param_audio_bitrate
= 0;
85 char *pvr_param_audio_mode
= NULL
;
86 int pvr_param_bitrate
= 0;
87 char *pvr_param_bitrate_mode
= NULL
;
88 int pvr_param_bitrate_peak
= 0;
89 char *pvr_param_stream_type
= NULL
;
91 typedef struct station_elem_s
{
94 char station
[PVR_STATION_NAME_SIZE
];
98 typedef struct stationlist_s
{
99 char name
[PVR_STATION_NAME_SIZE
];
100 station_elem_t
*list
;
101 int total
; /* total number */
102 int used
; /* used number */
103 int enabled
; /* enabled number */
123 stationlist_t stationlist
;
124 /* dups the tv_param_channel, or the url's channel param */
139 static struct pvr_t
*
142 struct pvr_t
*pvr
= NULL
;
144 pvr
= calloc (1, sizeof (struct pvr_t
));
146 pvr
->video_dev
= strdup (PVR_DEFAULT_DEVICE
);
160 pvr
->chan_idx_last
= -1;
162 /* set default encoding settings
163 * may be overlapped by user parameters
164 * Use VBR MPEG_PS encoding at 6 Mbps (peak at 9.6 Mbps)
165 * with 48 KHz L2 384 kbps audio.
167 pvr
->aspect
= V4L2_MPEG_VIDEO_ASPECT_4x3
;
168 pvr
->samplerate
= V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
;
169 pvr
->layer
= V4L2_MPEG_AUDIO_ENCODING_LAYER_2
;
170 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_384K
;
171 pvr
->audio_mode
= V4L2_MPEG_AUDIO_MODE_STEREO
;
172 pvr
->bitrate
= 6000000;
173 pvr
->bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
;
174 pvr
->bitrate_peak
= 9600000;
175 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_PS
;
181 pvr_uninit (struct pvr_t
*pvr
)
190 free (pvr
->video_dev
);
191 free (pvr
->stationlist
.list
);
192 free (pvr
->param_channel
);
197 * @brief Copy Constructor for stationlist
199 * @see parse_setup_stationlist
202 copycreate_stationlist (stationlist_t
*stationlist
, int num
)
206 if (chantab
< 0 || !stationlist
)
209 num
= FFMAX (num
, chanlists
[chantab
].count
);
211 free (stationlist
->list
);
212 stationlist
->list
= NULL
;
214 stationlist
->total
= 0;
215 stationlist
->enabled
= 0;
216 stationlist
->used
= 0;
217 stationlist
->list
= calloc (num
, sizeof (station_elem_t
));
219 if (!stationlist
->list
)
221 mp_msg (MSGT_OPEN
, MSGL_ERR
,
222 "%s No memory allocated for station list, giving up\n",
227 /* transport the channel list data to our extented struct */
228 stationlist
->total
= num
;
229 av_strlcpy (stationlist
->name
, chanlists
[chantab
].name
, PVR_STATION_NAME_SIZE
);
231 for (i
= 0; i
< chanlists
[chantab
].count
; i
++)
233 stationlist
->list
[i
].station
[0]= '\0'; /* no station name yet */
234 av_strlcpy (stationlist
->list
[i
].name
,
235 chanlists
[chantab
].list
[i
].name
, PVR_STATION_NAME_SIZE
);
236 stationlist
->list
[i
].freq
= chanlists
[chantab
].list
[i
].freq
;
237 stationlist
->list
[i
].enabled
= 1; /* default enabled */
238 stationlist
->enabled
++;
246 print_all_stations (struct pvr_t
*pvr
)
250 if (!pvr
|| !pvr
->stationlist
.list
)
253 for (i
= 0; i
< pvr
->stationlist
.total
; i
++)
255 mp_msg (MSGT_OPEN
, MSGL_V
,
256 "%s %3d: [%c] channel: %8s - freq: %8d - station: %s\n",
257 LOG_LEVEL_V4L2
, i
, (pvr
->stationlist
.list
[i
].enabled
) ? 'X' : ' ',
258 pvr
->stationlist
.list
[i
].name
, pvr
->stationlist
.list
[i
].freq
,
259 pvr
->stationlist
.list
[i
].station
);
266 * Disables all stations
268 * @see parse_setup_stationlist
271 disable_all_stations (struct pvr_t
*pvr
)
275 for (i
= 0; i
< pvr
->stationlist
.total
; i
++)
276 pvr
->stationlist
.list
[i
].enabled
= 0;
277 pvr
->stationlist
.enabled
= 0;
281 * Update or add a station
283 * @see parse_setup_stationlist
286 set_station (struct pvr_t
*pvr
, const char *station
,
287 const char *channel
, int freq
)
291 if (!pvr
|| !pvr
->stationlist
.list
)
294 if (0 >= pvr
->stationlist
.total
|| (!channel
&& !freq
))
298 for (i
= 0; i
< pvr
->stationlist
.used
; i
++)
300 if (channel
&& !strcasecmp (pvr
->stationlist
.list
[i
].name
, channel
))
301 break; /* found existing channel entry */
303 if (freq
> 0 && pvr
->stationlist
.list
[i
].freq
== freq
)
304 break; /* found existing frequency entry */
307 if (i
< pvr
->stationlist
.used
)
310 * found an existing entry,
311 * which is about to change with the user data.
312 * it is also enabled ..
314 if (!pvr
->stationlist
.list
[i
].enabled
)
316 pvr
->stationlist
.list
[i
].enabled
= 1;
317 pvr
->stationlist
.enabled
++;
321 av_strlcpy (pvr
->stationlist
.list
[i
].station
,
322 station
, PVR_STATION_NAME_SIZE
);
324 av_strlcpy (pvr
->stationlist
.list
[i
].station
,
325 channel
, PVR_STATION_NAME_SIZE
);
327 snprintf (pvr
->stationlist
.list
[i
].station
,
328 PVR_STATION_NAME_SIZE
, "F %d", freq
);
330 mp_msg (MSGT_OPEN
, MSGL_DBG2
,
331 "%s Set user station channel: %8s - freq: %8d - station: %s\n",
332 LOG_LEVEL_V4L2
, pvr
->stationlist
.list
[i
].name
,
333 pvr
->stationlist
.list
[i
].freq
,
334 pvr
->stationlist
.list
[i
].station
);
338 /* from here on, we have to create a new entry, frequency is mandatory */
341 mp_msg (MSGT_OPEN
, MSGL_ERR
,
342 "%s Cannot add new station/channel without frequency\n",
347 if (pvr
->stationlist
.total
< i
)
350 * we have to extend the stationlist about
351 * an arbitrary size, even though this path is not performance critical
353 pvr
->stationlist
.total
+= 10;
354 pvr
->stationlist
.list
=
355 realloc (pvr
->stationlist
.list
,
356 pvr
->stationlist
.total
* sizeof (station_elem_t
));
358 if (!pvr
->stationlist
.list
)
360 mp_msg (MSGT_OPEN
, MSGL_ERR
,
361 "%s No memory allocated for station list, giving up\n",
366 /* clear the new space ..*/
367 memset (&(pvr
->stationlist
.list
[pvr
->stationlist
.used
]), 0,
368 (pvr
->stationlist
.total
- pvr
->stationlist
.used
)
369 * sizeof (station_elem_t
));
372 /* here we go, our actual new entry */
373 pvr
->stationlist
.used
++;
374 pvr
->stationlist
.list
[i
].enabled
= 1;
375 pvr
->stationlist
.enabled
++;
378 av_strlcpy (pvr
->stationlist
.list
[i
].station
,
379 station
, PVR_STATION_NAME_SIZE
);
381 av_strlcpy (pvr
->stationlist
.list
[i
].name
, channel
, PVR_STATION_NAME_SIZE
);
383 snprintf (pvr
->stationlist
.list
[i
].name
,
384 PVR_STATION_NAME_SIZE
, "F %d", freq
);
386 pvr
->stationlist
.list
[i
].freq
= freq
;
388 mp_msg (MSGT_OPEN
, MSGL_DBG2
,
389 "%s Add user station channel: %8s - freq: %8d - station: %s\n",
390 LOG_LEVEL_V4L2
, pvr
->stationlist
.list
[i
].name
,
391 pvr
->stationlist
.list
[i
].freq
,
392 pvr
->stationlist
.list
[i
].station
);
398 * Here we set our stationlist, as follow
399 * - choose the frequency channel table, e.g. ntsc-cable
400 * - create our stationlist, same element size as the channellist
401 * - copy the channellist content to our stationlist
402 * - IF the user provides his channel-mapping, THEN:
403 * - disable all stations
404 * - update and/or create entries in the stationlist and enable them
407 parse_setup_stationlist (struct pvr_t
*pvr
)
414 /* Create our station/channel list */
415 if (stream_tv_defaults
.chanlist
)
417 /* select channel list */
418 for (i
= 0; chanlists
[i
].name
!= NULL
; i
++)
420 if (!strcasecmp (chanlists
[i
].name
, stream_tv_defaults
.chanlist
))
426 if (!chanlists
[i
].name
)
428 mp_msg (MSGT_OPEN
, MSGL_ERR
,
429 "%s unable to find channel list %s, using default %s\n",
430 LOG_LEVEL_V4L2
, stream_tv_defaults
.chanlist
, chanlists
[chantab
].name
);
434 mp_msg (MSGT_OPEN
, MSGL_INFO
,
435 "%s select channel list %s, entries %d\n", LOG_LEVEL_V4L2
,
436 chanlists
[chantab
].name
, chanlists
[chantab
].count
);
442 mp_msg (MSGT_OPEN
, MSGL_FATAL
,
443 "%s No channel list selected, giving up\n", LOG_LEVEL_V4L2
);
447 if (copycreate_stationlist (&(pvr
->stationlist
), -1) < 0)
449 mp_msg (MSGT_OPEN
, MSGL_FATAL
,
450 "%s No memory allocated for station list, giving up\n",
455 /* Handle user channel mappings */
456 if (stream_tv_defaults
.channels
)
458 char channel
[PVR_STATION_NAME_SIZE
];
459 char station
[PVR_STATION_NAME_SIZE
];
460 char **channels
= stream_tv_defaults
.channels
;
462 disable_all_stations (pvr
);
466 char *tmp
= *(channels
++);
467 char *sep
= strchr (tmp
, '-');
471 continue; /* Wrong syntax, but mplayer should not crash */
473 av_strlcpy (station
, sep
+ 1, PVR_STATION_NAME_SIZE
);
476 av_strlcpy (channel
, tmp
, PVR_STATION_NAME_SIZE
);
478 while ((sep
= strchr (station
, '_')))
481 /* if channel number is a number and larger than 1000 treat it as
482 * frequency tmp still contain pointer to null-terminated string with
483 * channel number here
485 if ((freq
= atoi (channel
)) <= 1000)
488 if (set_station (pvr
, station
, (freq
<= 0) ? channel
: NULL
, freq
) < 0)
490 mp_msg (MSGT_OPEN
, MSGL_ERR
,
491 "%s Unable to set user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2
,
492 channel
, freq
, station
);
497 return print_all_stations (pvr
);
501 get_v4l2_freq (struct pvr_t
*pvr
)
504 struct v4l2_frequency vf
;
505 struct v4l2_tuner vt
;
513 memset (&vt
, 0, sizeof (vt
));
514 memset (&vf
, 0, sizeof (vf
));
516 if (ioctl (pvr
->dev_fd
, VIDIOC_G_TUNER
, &vt
) < 0)
518 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s can't set tuner (%s).\n",
519 LOG_LEVEL_V4L2
, strerror (errno
));
523 if (ioctl (pvr
->dev_fd
, VIDIOC_G_FREQUENCY
, &vf
) < 0)
525 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s can't get frequency %d.\n",
526 LOG_LEVEL_V4L2
, errno
);
530 if (!(vt
.capability
& V4L2_TUNER_CAP_LOW
))
538 set_v4l2_freq (struct pvr_t
*pvr
)
540 struct v4l2_frequency vf
;
541 struct v4l2_tuner vt
;
548 mp_msg (MSGT_OPEN
, MSGL_ERR
,
549 "%s Frequency invalid %d !!!\n", LOG_LEVEL_V4L2
, pvr
->freq
);
553 /* don't set the frequency, if it's already set.
554 * setting it here would interrupt the stream.
556 if (get_v4l2_freq (pvr
) == pvr
->freq
)
558 mp_msg (MSGT_OPEN
, MSGL_STATUS
,
559 "%s Frequency %d already set.\n", LOG_LEVEL_V4L2
, pvr
->freq
);
566 memset (&vf
, 0, sizeof (vf
));
567 memset (&vt
, 0, sizeof (vt
));
569 if (ioctl (pvr
->dev_fd
, VIDIOC_G_TUNER
, &vt
) < 0)
571 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s can't get tuner (%s).\n",
572 LOG_LEVEL_V4L2
, strerror (errno
));
577 vf
.frequency
= pvr
->freq
* 16;
579 if (!(vt
.capability
& V4L2_TUNER_CAP_LOW
))
580 vf
.frequency
/= 1000;
582 if (ioctl (pvr
->dev_fd
, VIDIOC_S_FREQUENCY
, &vf
) < 0)
584 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s can't set frequency (%s).\n",
585 LOG_LEVEL_V4L2
, strerror (errno
));
589 memset (&vt
, 0, sizeof(vt
));
590 if (ioctl (pvr
->dev_fd
, VIDIOC_G_TUNER
, &vt
) < 0)
592 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s can't set tuner (%s).\n",
593 LOG_LEVEL_V4L2
, strerror (errno
));
597 /* just a notification */
599 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s NO SIGNAL at frequency %d (%d)\n",
600 LOG_LEVEL_V4L2
, pvr
->freq
, vf
.frequency
);
602 mp_msg (MSGT_OPEN
, MSGL_STATUS
, "%s Got signal at frequency %d (%d)\n",
603 LOG_LEVEL_V4L2
, pvr
->freq
, vf
.frequency
);
609 set_station_by_step (struct pvr_t
*pvr
, int step
, int v4lAction
)
611 if (!pvr
|| !pvr
->stationlist
.list
)
614 if (pvr
->stationlist
.enabled
>= abs (step
))
617 int chidx
= pvr
->chan_idx
+ step
;
621 chidx
= (chidx
+ pvr
->stationlist
.used
) % pvr
->stationlist
.used
;
623 mp_msg (MSGT_OPEN
, MSGL_DBG2
,
624 "%s Offset switch: current %d, enabled %d, step %d -> %d\n",
625 LOG_LEVEL_V4L2
, pvr
->chan_idx
,
626 pvr
->stationlist
.enabled
, step
, chidx
);
628 if (!pvr
->stationlist
.list
[chidx
].enabled
)
630 mp_msg (MSGT_OPEN
, MSGL_DBG2
,
631 "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2
,
632 pvr
->stationlist
.list
[chidx
].name
,
633 pvr
->stationlist
.list
[chidx
].freq
,
634 pvr
->stationlist
.list
[chidx
].station
);
635 chidx
+= FFSIGN (step
);
641 pvr
->freq
= pvr
->stationlist
.list
[chidx
].freq
;
642 pvr
->chan_idx_last
= pvr
->chan_idx
;
643 pvr
->chan_idx
= chidx
;
645 mp_msg (MSGT_OPEN
, MSGL_INFO
,
646 "%s Switch to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2
,
647 pvr
->stationlist
.list
[chidx
].name
,
648 pvr
->stationlist
.list
[chidx
].freq
,
649 pvr
->stationlist
.list
[chidx
].station
);
652 return set_v4l2_freq (pvr
);
654 return (pvr
->freq
> 0) ? 0 : -1;
657 mp_msg (MSGT_OPEN
, MSGL_ERR
,
658 "%s Ooops couldn't set freq by channel entry step %d to current %d, enabled %d\n", LOG_LEVEL_V4L2
,
659 step
, pvr
->chan_idx
, pvr
->stationlist
.enabled
);
665 set_station_by_channelname_or_freq (struct pvr_t
*pvr
, const char *channel
,
666 int freq
, int v4lAction
)
670 if (!pvr
|| !pvr
->stationlist
.list
)
673 if (0 >= pvr
->stationlist
.enabled
)
675 mp_msg (MSGT_OPEN
, MSGL_WARN
,
676 "%s No enabled station, cannot switch channel/frequency\n",
683 /* select by channel */
684 for (i
= 0; i
< pvr
->stationlist
.used
; i
++)
686 if (!strcasecmp (pvr
->stationlist
.list
[i
].name
, channel
))
688 if (!pvr
->stationlist
.list
[i
].enabled
)
690 mp_msg (MSGT_OPEN
, MSGL_WARN
,
691 "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2
,
692 pvr
->stationlist
.list
[i
].name
,
693 pvr
->stationlist
.list
[i
].freq
,
694 pvr
->stationlist
.list
[i
].station
);
699 pvr
->freq
= pvr
->stationlist
.list
[i
].freq
;
700 pvr
->chan_idx_last
= pvr
->chan_idx
;
709 for (i
= 0; i
< pvr
->stationlist
.used
; i
++)
711 if (pvr
->stationlist
.list
[i
].freq
== freq
)
713 if (!pvr
->stationlist
.list
[i
].enabled
)
715 mp_msg (MSGT_OPEN
, MSGL_WARN
,
716 "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2
,
717 pvr
->stationlist
.list
[i
].name
,
718 pvr
->stationlist
.list
[i
].freq
,
719 pvr
->stationlist
.list
[i
].station
);
724 pvr
->freq
= pvr
->stationlist
.list
[i
].freq
;
725 pvr
->chan_idx_last
= pvr
->chan_idx
;
732 if (i
>= pvr
->stationlist
.used
)
735 mp_msg (MSGT_OPEN
, MSGL_WARN
,
736 "%s unable to find channel %s\n", LOG_LEVEL_V4L2
, channel
);
738 mp_msg (MSGT_OPEN
, MSGL_WARN
,
739 "%s unable to find frequency %d\n", LOG_LEVEL_V4L2
, freq
);
743 mp_msg (MSGT_OPEN
, MSGL_INFO
,
744 "%s Switch to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2
,
745 pvr
->stationlist
.list
[i
].name
,
746 pvr
->stationlist
.list
[i
].freq
,
747 pvr
->stationlist
.list
[i
].station
);
750 return set_v4l2_freq (pvr
);
752 return (pvr
->freq
> 0) ? 0 : -1;
756 force_freq_step (struct pvr_t
*pvr
, int step
)
763 freq
= pvr
->freq
+step
;
767 mp_msg (MSGT_OPEN
, MSGL_INFO
,
768 "%s Force Frequency %d + %d = %d \n", LOG_LEVEL_V4L2
,
769 pvr
->freq
, step
, freq
);
773 return set_v4l2_freq (pvr
);
780 parse_encoder_options (struct pvr_t
*pvr
)
785 /* -pvr aspect=digit */
786 if (pvr_param_aspect_ratio
>= 0 && pvr_param_aspect_ratio
<= 3)
787 pvr
->aspect
= pvr_param_aspect_ratio
;
790 if (pvr_param_sample_rate
!= 0)
792 switch (pvr_param_sample_rate
)
795 pvr
->samplerate
= V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000
;
798 pvr
->samplerate
= V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100
;
801 pvr
->samplerate
= V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
;
809 if (pvr_param_audio_layer
== 1)
810 pvr
->layer
= V4L2_MPEG_AUDIO_ENCODING_LAYER_1
;
811 else if (pvr_param_audio_layer
== 2)
812 pvr
->layer
= V4L2_MPEG_AUDIO_ENCODING_LAYER_2
;
813 else if (pvr_param_audio_layer
== 3)
814 pvr
->layer
= V4L2_MPEG_AUDIO_ENCODING_LAYER_3
;
816 /* -pvr abitrate=x */
817 if (pvr_param_audio_bitrate
!= 0)
819 if (pvr
->layer
== V4L2_MPEG_AUDIO_ENCODING_LAYER_1
)
821 switch (pvr_param_audio_bitrate
)
824 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_32K
;
827 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_64K
;
830 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_96K
;
833 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_128K
;
836 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_160K
;
839 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_192K
;
842 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_224K
;
845 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_256K
;
848 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_288K
;
851 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_320K
;
854 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_352K
;
857 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_384K
;
860 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_416K
;
863 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L1_BITRATE_448K
;
870 else if (pvr
->layer
== V4L2_MPEG_AUDIO_ENCODING_LAYER_2
)
872 switch (pvr_param_audio_bitrate
)
875 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_32K
;
878 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_48K
;
881 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_56K
;
884 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_64K
;
887 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_80K
;
890 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_96K
;
893 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_112K
;
896 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_128K
;
899 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_160K
;
902 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_192K
;
905 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_224K
;
908 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_256K
;
911 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_320K
;
914 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L2_BITRATE_384K
;
921 else if (pvr
->layer
== V4L2_MPEG_AUDIO_ENCODING_LAYER_3
)
923 switch (pvr_param_audio_bitrate
)
926 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_32K
;
929 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_40K
;
932 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_48K
;
935 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_56K
;
938 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_64K
;
941 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_80K
;
944 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_96K
;
947 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_112K
;
950 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_128K
;
953 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_160K
;
956 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_192K
;
959 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_224K
;
962 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_256K
;
965 pvr
->audio_rate
= V4L2_MPEG_AUDIO_L3_BITRATE_320K
;
974 if (pvr_param_audio_mode
)
976 if (!strcmp (pvr_param_audio_mode
, PVR_AUDIO_MODE_ARG_STEREO
))
977 pvr
->audio_mode
= V4L2_MPEG_AUDIO_MODE_STEREO
;
978 else if (!strcmp (pvr_param_audio_mode
, PVR_AUDIO_MODE_ARG_JOINT_STEREO
))
979 pvr
->audio_mode
= V4L2_MPEG_AUDIO_MODE_JOINT_STEREO
;
980 else if (!strcmp (pvr_param_audio_mode
, PVR_AUDIO_MODE_ARG_DUAL
))
981 pvr
->audio_mode
= V4L2_MPEG_AUDIO_MODE_DUAL
;
982 else if (!strcmp (pvr_param_audio_mode
, PVR_AUDIO_MODE_ARG_MONO
))
983 pvr
->audio_mode
= V4L2_MPEG_AUDIO_MODE_MONO
;
986 /* -pvr vbitrate=x */
987 if (pvr_param_bitrate
)
988 pvr
->bitrate
= pvr_param_bitrate
;
991 if (pvr_param_bitrate_mode
)
993 if (!strcmp (pvr_param_bitrate_mode
, PVR_VIDEO_BITRATE_MODE_ARG_VBR
))
994 pvr
->bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
;
995 else if (!strcmp (pvr_param_bitrate_mode
, PVR_VIDEO_BITRATE_MODE_ARG_CBR
))
996 pvr
->bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
;
1000 if (pvr_param_bitrate_peak
)
1001 pvr
->bitrate_peak
= pvr_param_bitrate_peak
;
1004 if (pvr_param_stream_type
)
1006 if (!strcmp (pvr_param_stream_type
, PVR_VIDEO_STREAM_TYPE_PS
))
1007 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_PS
;
1008 else if (!strcmp (pvr_param_stream_type
, PVR_VIDEO_STREAM_TYPE_TS
))
1009 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_TS
;
1010 else if (!strcmp (pvr_param_stream_type
, PVR_VIDEO_STREAM_TYPE_MPEG1
))
1011 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG1_SS
;
1012 else if (!strcmp (pvr_param_stream_type
, PVR_VIDEO_STREAM_TYPE_DVD
))
1013 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_DVD
;
1014 else if (!strcmp (pvr_param_stream_type
, PVR_VIDEO_STREAM_TYPE_VCD
))
1015 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG1_VCD
;
1016 else if (!strcmp (pvr_param_stream_type
, PVR_VIDEO_STREAM_TYPE_SVCD
))
1017 pvr
->stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD
;
1022 add_v4l2_ext_control (struct v4l2_ext_control
*ctrl
,
1023 uint32_t id
, int32_t value
)
1026 ctrl
->value
= value
;
1030 set_encoder_settings (struct pvr_t
*pvr
)
1032 struct v4l2_ext_control
*ext_ctrl
= NULL
;
1033 struct v4l2_ext_controls ctrls
;
1039 if (pvr
->dev_fd
< 0)
1042 ext_ctrl
= (struct v4l2_ext_control
*)
1043 malloc (PVR_MAX_CONTROLS
* sizeof (struct v4l2_ext_control
));
1045 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_VIDEO_ASPECT
,
1048 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
1051 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_AUDIO_ENCODING
,
1056 case V4L2_MPEG_AUDIO_ENCODING_LAYER_1
:
1057 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_AUDIO_L1_BITRATE
,
1060 case V4L2_MPEG_AUDIO_ENCODING_LAYER_2
:
1061 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_AUDIO_L2_BITRATE
,
1064 case V4L2_MPEG_AUDIO_ENCODING_LAYER_3
:
1065 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_AUDIO_L3_BITRATE
,
1072 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_AUDIO_MODE
,
1075 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_VIDEO_BITRATE
,
1078 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
,
1081 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_VIDEO_BITRATE_MODE
,
1084 add_v4l2_ext_control (&ext_ctrl
[count
++], V4L2_CID_MPEG_STREAM_TYPE
,
1087 /* set new encoding settings */
1088 ctrls
.ctrl_class
= V4L2_CTRL_CLASS_MPEG
;
1089 ctrls
.count
= count
;
1090 ctrls
.controls
= ext_ctrl
;
1092 if (ioctl (pvr
->dev_fd
, VIDIOC_S_EXT_CTRLS
, &ctrls
) < 0)
1094 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s Error setting MPEG controls (%s).\n",
1095 LOG_LEVEL_ENCODER
, strerror (errno
));
1106 parse_v4l2_tv_options (struct pvr_t
*pvr
)
1111 /* Create our station/channel list */
1112 parse_setup_stationlist (pvr
);
1114 if (pvr
->param_channel
)
1116 if (set_station_by_channelname_or_freq (pvr
, pvr
->param_channel
,
1119 if (stream_tv_defaults
.freq
)
1121 mp_msg (MSGT_OPEN
, MSGL_HINT
,
1122 "%s tv param freq %s is overwritten by channel setting freq %d\n", LOG_LEVEL_V4L2
,
1123 stream_tv_defaults
.freq
, pvr
->freq
);
1128 if (pvr
->freq
< 0 && stream_tv_defaults
.freq
)
1130 mp_msg (MSGT_OPEN
, MSGL_HINT
, "%s tv param freq %s is used directly\n",
1131 LOG_LEVEL_V4L2
, stream_tv_defaults
.freq
);
1133 if (set_station_by_channelname_or_freq (pvr
, NULL
,
1134 atoi (stream_tv_defaults
.freq
), 0)<0)
1136 mp_msg (MSGT_OPEN
, MSGL_WARN
,
1137 "%s tv param freq %s invalid to set station\n",
1138 LOG_LEVEL_V4L2
, stream_tv_defaults
.freq
);
1142 if (stream_tv_defaults
.device
)
1144 free (pvr
->video_dev
);
1145 pvr
->video_dev
= strdup (stream_tv_defaults
.device
);
1148 if (stream_tv_defaults
.noaudio
)
1149 pvr
->mute
= stream_tv_defaults
.noaudio
;
1151 if (stream_tv_defaults
.input
)
1152 pvr
->input
= stream_tv_defaults
.input
;
1154 if (stream_tv_defaults
.normid
)
1155 pvr
->normid
= stream_tv_defaults
.normid
;
1157 if (stream_tv_defaults
.brightness
)
1158 pvr
->brightness
= stream_tv_defaults
.brightness
;
1160 if (stream_tv_defaults
.contrast
)
1161 pvr
->contrast
= stream_tv_defaults
.contrast
;
1163 if (stream_tv_defaults
.hue
)
1164 pvr
->hue
= stream_tv_defaults
.hue
;
1166 if (stream_tv_defaults
.saturation
)
1167 pvr
->saturation
= stream_tv_defaults
.saturation
;
1169 if (stream_tv_defaults
.width
)
1170 pvr
->width
= stream_tv_defaults
.width
;
1172 if (stream_tv_defaults
.height
)
1173 pvr
->height
= stream_tv_defaults
.height
;
1177 set_v4l2_settings (struct pvr_t
*pvr
)
1182 if (pvr
->dev_fd
< 0)
1188 struct v4l2_control ctrl
;
1189 ctrl
.id
= V4L2_CID_AUDIO_MUTE
;
1191 if (ioctl (pvr
->dev_fd
, VIDIOC_S_CTRL
, &ctrl
) < 0)
1193 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1194 "%s can't mute (%s).\n", LOG_LEVEL_V4L2
, strerror (errno
));
1200 if (pvr
->input
!= 0)
1202 if (ioctl (pvr
->dev_fd
, VIDIOC_S_INPUT
, &pvr
->input
) < 0)
1204 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1205 "%s can't set input (%s)\n", LOG_LEVEL_V4L2
, strerror (errno
));
1211 if (pvr
->normid
!= -1)
1213 struct v4l2_standard std
;
1214 std
.index
= pvr
->normid
;
1216 if (ioctl (pvr
->dev_fd
, VIDIOC_ENUMSTD
, &std
) < 0)
1218 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1219 "%s can't set norm (%s)\n", LOG_LEVEL_V4L2
, strerror (errno
));
1223 mp_msg (MSGT_OPEN
, MSGL_V
,
1224 "%s set norm to %s\n", LOG_LEVEL_V4L2
, std
.name
);
1226 if (ioctl (pvr
->dev_fd
, VIDIOC_S_STD
, &std
.id
) < 0)
1228 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1229 "%s can't set norm (%s)\n", LOG_LEVEL_V4L2
, strerror (errno
));
1234 /* -tv brightness=x */
1235 if (pvr
->brightness
!= 0)
1237 struct v4l2_control ctrl
;
1238 ctrl
.id
= V4L2_CID_BRIGHTNESS
;
1239 ctrl
.value
= pvr
->brightness
;
1243 if (ctrl
.value
> 255)
1246 if (ioctl (pvr
->dev_fd
, VIDIOC_S_CTRL
, &ctrl
) < 0)
1248 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1249 "%s can't set brightness to %d (%s).\n",
1250 LOG_LEVEL_V4L2
, ctrl
.value
, strerror (errno
));
1255 /* -tv contrast=x */
1256 if (pvr
->contrast
!= 0)
1258 struct v4l2_control ctrl
;
1259 ctrl
.id
= V4L2_CID_CONTRAST
;
1260 ctrl
.value
= pvr
->contrast
;
1264 if (ctrl
.value
> 127)
1267 if (ioctl (pvr
->dev_fd
, VIDIOC_S_CTRL
, &ctrl
) < 0)
1269 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1270 "%s can't set contrast to %d (%s).\n",
1271 LOG_LEVEL_V4L2
, ctrl
.value
, strerror (errno
));
1279 struct v4l2_control ctrl
;
1280 ctrl
.id
= V4L2_CID_HUE
;
1281 ctrl
.value
= pvr
->hue
;
1283 if (ctrl
.value
< -128)
1285 if (ctrl
.value
> 127)
1288 if (ioctl (pvr
->dev_fd
, VIDIOC_S_CTRL
, &ctrl
) < 0)
1290 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1291 "%s can't set hue to %d (%s).\n",
1292 LOG_LEVEL_V4L2
, ctrl
.value
, strerror (errno
));
1297 /* -tv saturation=x */
1298 if (pvr
->saturation
!= 0)
1300 struct v4l2_control ctrl
;
1301 ctrl
.id
= V4L2_CID_SATURATION
;
1302 ctrl
.value
= pvr
->saturation
;
1306 if (ctrl
.value
> 127)
1309 if (ioctl (pvr
->dev_fd
, VIDIOC_S_CTRL
, &ctrl
) < 0)
1311 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1312 "%s can't set saturation to %d (%s).\n",
1313 LOG_LEVEL_V4L2
, ctrl
.value
, strerror (errno
));
1318 /* -tv width=x:height=y */
1319 if (pvr
->width
&& pvr
->height
)
1321 struct v4l2_format vfmt
;
1322 vfmt
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1323 vfmt
.fmt
.pix
.width
= pvr
->width
;
1324 vfmt
.fmt
.pix
.height
= pvr
->height
;
1326 if (ioctl (pvr
->dev_fd
, VIDIOC_S_FMT
, &vfmt
) < 0)
1328 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1329 "%s can't set resolution to %dx%d (%s).\n",
1330 LOG_LEVEL_V4L2
, pvr
->width
, pvr
->height
, strerror (errno
));
1337 int freq
= get_v4l2_freq (pvr
);
1338 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1339 "%s Using current set frequency %d, to set channel\n",
1340 LOG_LEVEL_V4L2
, freq
);
1343 return set_station_by_channelname_or_freq (pvr
, NULL
, freq
, 1);
1347 return set_v4l2_freq (pvr
) ;
1353 v4l2_list_capabilities (struct pvr_t
*pvr
)
1355 struct v4l2_audio vaudio
;
1356 struct v4l2_standard vs
;
1357 struct v4l2_input vin
;
1363 if (pvr
->dev_fd
< 0)
1366 /* list available video inputs */
1369 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1370 "%s Available video inputs: ", LOG_LEVEL_V4L2
);
1371 while (ioctl (pvr
->dev_fd
, VIDIOC_ENUMINPUT
, &vin
) >= 0)
1374 mp_msg (MSGT_OPEN
, MSGL_INFO
, "'#%d, %s' ", vin
.index
, vin
.name
);
1379 mp_msg (MSGT_OPEN
, MSGL_INFO
, "none\n");
1383 mp_msg (MSGT_OPEN
, MSGL_INFO
, "\n");
1385 /* list available audio inputs */
1388 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1389 "%s Available audio inputs: ", LOG_LEVEL_V4L2
);
1390 while (ioctl (pvr
->dev_fd
, VIDIOC_ENUMAUDIO
, &vaudio
) >= 0)
1393 mp_msg (MSGT_OPEN
, MSGL_INFO
, "'#%d, %s' ", vaudio
.index
, vaudio
.name
);
1398 mp_msg (MSGT_OPEN
, MSGL_INFO
, "none\n");
1402 mp_msg (MSGT_OPEN
, MSGL_INFO
, "\n");
1404 /* list available norms */
1406 mp_msg (MSGT_OPEN
, MSGL_INFO
, "%s Available norms: ", LOG_LEVEL_V4L2
);
1407 while (ioctl (pvr
->dev_fd
, VIDIOC_ENUMSTD
, &vs
) >= 0)
1410 mp_msg (MSGT_OPEN
, MSGL_INFO
, "'#%d, %s' ", vs
.index
, vs
.name
);
1415 mp_msg (MSGT_OPEN
, MSGL_INFO
, "none\n");
1419 mp_msg (MSGT_OPEN
, MSGL_INFO
, "\n");
1425 v4l2_display_settings (struct pvr_t
*pvr
)
1427 struct v4l2_audio vaudio
;
1428 struct v4l2_standard vs
;
1429 struct v4l2_input vin
;
1436 if (pvr
->dev_fd
< 0)
1439 /* get current video input */
1440 if (ioctl (pvr
->dev_fd
, VIDIOC_G_INPUT
, &input
) == 0)
1443 if (ioctl (pvr
->dev_fd
, VIDIOC_ENUMINPUT
, &vin
) < 0)
1445 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1446 "%s can't get input (%s).\n", LOG_LEVEL_V4L2
, strerror (errno
));
1450 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1451 "%s Video input: %s\n", LOG_LEVEL_V4L2
, vin
.name
);
1455 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1456 "%s can't get input (%s).\n", LOG_LEVEL_V4L2
, strerror (errno
));
1460 /* get current audio input */
1461 if (ioctl (pvr
->dev_fd
, VIDIOC_G_AUDIO
, &vaudio
) == 0)
1463 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1464 "%s Audio input: %s\n", LOG_LEVEL_V4L2
, vaudio
.name
);
1468 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1469 "%s can't get input (%s).\n", LOG_LEVEL_V4L2
, strerror (errno
));
1473 /* get current video format */
1474 if (ioctl (pvr
->dev_fd
, VIDIOC_G_STD
, &std
) == 0)
1478 while (ioctl (pvr
->dev_fd
, VIDIOC_ENUMSTD
, &vs
) >= 0)
1482 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1483 "%s Norm: %s.\n", LOG_LEVEL_V4L2
, vs
.name
);
1491 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1492 "%s can't get norm (%s)\n", LOG_LEVEL_V4L2
, strerror (errno
));
1502 pvr_stream_close (stream_t
*stream
)
1509 pvr
= (struct pvr_t
*) stream
->priv
;
1514 pvr_stream_read (stream_t
*stream
, char *buffer
, int size
)
1516 struct pollfd pfds
[1];
1520 if (!stream
|| !buffer
)
1523 pvr
= (struct pvr_t
*) stream
->priv
;
1533 pfds
[0].events
= POLLIN
| POLLPRI
;
1537 if (poll (pfds
, 1, 500) <= 0)
1539 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1540 "%s failed with errno %d when reading %d bytes\n",
1541 LOG_LEVEL_PVR
, errno
, size
-pos
);
1545 rk
= read (fd
, &buffer
[pos
], rk
);
1549 mp_msg (MSGT_OPEN
, MSGL_DBG3
,
1550 "%s read (%d) bytes\n", LOG_LEVEL_PVR
, pos
);
1555 mp_msg (MSGT_OPEN
, MSGL_ERR
, "%s read %d bytes\n", LOG_LEVEL_PVR
, pos
);
1561 pvr_stream_open (stream_t
*stream
, int mode
, void *opts
, int *file_format
)
1563 struct v4l2_capability vcap
;
1564 struct v4l2_ext_controls ctrls
;
1565 struct pvr_t
*pvr
= NULL
;
1567 if (mode
!= STREAM_READ
)
1568 return STREAM_UNSUPPORTED
;
1573 * if the url, i.e. 'pvr://8', contains the channel, use it,
1574 * else use the tv parameter.
1576 if (stream
->url
&& strlen (stream
->url
) > 6 && stream
->url
[6] != '\0')
1577 pvr
->param_channel
= strdup (stream
->url
+ 6);
1578 else if (stream_tv_defaults
.channel
&& strlen (stream_tv_defaults
.channel
))
1579 pvr
->param_channel
= strdup (stream_tv_defaults
.channel
);
1581 parse_v4l2_tv_options (pvr
);
1582 parse_encoder_options (pvr
);
1585 pvr
->dev_fd
= open (pvr
->video_dev
, O_RDWR
);
1586 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1587 "%s Using device %s\n", LOG_LEVEL_PVR
, pvr
->video_dev
);
1588 if (pvr
->dev_fd
== -1)
1590 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1591 "%s error opening device %s\n", LOG_LEVEL_PVR
, pvr
->video_dev
);
1593 return STREAM_ERROR
;
1596 /* query capabilities (i.e test V4L2 support) */
1597 if (ioctl (pvr
->dev_fd
, VIDIOC_QUERYCAP
, &vcap
) < 0)
1599 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1600 "%s device is not V4L2 compliant (%s).\n",
1601 LOG_LEVEL_PVR
, strerror (errno
));
1603 return STREAM_ERROR
;
1606 mp_msg (MSGT_OPEN
, MSGL_INFO
,
1607 "%s Detected %s\n", LOG_LEVEL_PVR
, vcap
.card
);
1609 /* check for a valid V4L2 capture device */
1610 if (!(vcap
.capabilities
& V4L2_CAP_VIDEO_CAPTURE
))
1612 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1613 "%s device is not a valid V4L2 capture device.\n",
1616 return STREAM_ERROR
;
1619 /* check for device hardware MPEG encoding capability */
1620 ctrls
.ctrl_class
= V4L2_CTRL_CLASS_MPEG
;
1622 ctrls
.controls
= NULL
;
1624 if (ioctl (pvr
->dev_fd
, VIDIOC_G_EXT_CTRLS
, &ctrls
) < 0)
1626 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1627 "%s device do not support MPEG input.\n", LOG_LEVEL_ENCODER
);
1628 return STREAM_ERROR
;
1631 /* list V4L2 capabilities */
1632 if (v4l2_list_capabilities (pvr
) == -1)
1634 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1635 "%s can't get v4l2 capabilities\n", LOG_LEVEL_PVR
);
1637 return STREAM_ERROR
;
1640 /* apply V4L2 settings */
1641 if (set_v4l2_settings (pvr
) == -1)
1643 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1644 "%s can't set v4l2 settings\n", LOG_LEVEL_PVR
);
1646 return STREAM_ERROR
;
1649 /* apply encoder settings */
1650 if (set_encoder_settings (pvr
) == -1)
1652 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1653 "%s can't set encoder settings\n", LOG_LEVEL_PVR
);
1655 return STREAM_ERROR
;
1658 /* display current V4L2 settings */
1659 if (v4l2_display_settings (pvr
) == -1)
1661 mp_msg (MSGT_OPEN
, MSGL_ERR
,
1662 "%s can't get v4l2 settings\n", LOG_LEVEL_PVR
);
1664 return STREAM_ERROR
;
1668 stream
->type
= STREAMTYPE_PVR
;
1669 stream
->fill_buffer
= pvr_stream_read
;
1670 stream
->close
= pvr_stream_close
;
1675 /* PVR Public API access */
1678 pvr_get_current_stationname (stream_t
*stream
)
1682 if (!stream
|| stream
->type
!= STREAMTYPE_PVR
)
1685 pvr
= (struct pvr_t
*) stream
->priv
;
1687 if (pvr
->stationlist
.list
&&
1688 pvr
->stationlist
.used
> pvr
->chan_idx
&&
1690 return pvr
->stationlist
.list
[pvr
->chan_idx
].station
;
1696 pvr_get_current_channelname (stream_t
*stream
)
1698 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1700 if (pvr
->stationlist
.list
&&
1701 pvr
->stationlist
.used
> pvr
->chan_idx
&&
1703 return pvr
->stationlist
.list
[pvr
->chan_idx
].name
;
1709 pvr_get_current_frequency (stream_t
*stream
)
1711 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1717 pvr_set_channel (stream_t
*stream
, const char * channel
)
1719 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1721 return set_station_by_channelname_or_freq (pvr
, channel
, -1, 1);
1725 pvr_set_lastchannel (stream_t
*stream
)
1727 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1729 if (pvr
->stationlist
.list
&&
1730 pvr
->stationlist
.used
> pvr
->chan_idx_last
&&
1731 pvr
->chan_idx_last
>= 0)
1732 return set_station_by_channelname_or_freq (pvr
, pvr
->stationlist
.list
[pvr
->chan_idx_last
].name
, -1, 1);
1738 pvr_set_freq (stream_t
*stream
, int freq
)
1740 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1742 return set_station_by_channelname_or_freq (pvr
, NULL
, freq
, 1);
1746 pvr_set_channel_step (stream_t
*stream
, int step
)
1748 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1750 return set_station_by_step (pvr
, step
, 1);
1754 pvr_force_freq_step (stream_t
*stream
, int step
)
1756 struct pvr_t
*pvr
= (struct pvr_t
*) stream
->priv
;
1758 return force_freq_step (pvr
, step
);
1761 const stream_info_t stream_info_pvr
= {
1762 "V4L2 MPEG Input (a.k.a PVR)",