2006-07-10 21:32:19 +00:00
|
|
|
/*
|
2008-05-14 17:20:42 +00:00
|
|
|
* stream layer for hardware MPEG 1/2/4 encoders a.k.a PVR
|
|
|
|
* (such as WinTV PVR-150/250/350/500 (a.k.a IVTV), pvrusb2 and cx88)
|
|
|
|
* See http://ivtvdriver.org/index.php/Main_Page for more details on the
|
|
|
|
* cards supported by the ivtv driver.
|
2006-07-10 21:32:19 +00:00
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* Copyright (C) 2006 Benjamin Zores
|
|
|
|
* Copyright (C) 2007 Sven Gothel (channel navigation)
|
2006-07-10 21:32:19 +00:00
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* This file is part of MPlayer.
|
2006-07-10 21:32:19 +00:00
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-07-10 21:32:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
2011-06-11 16:21:54 +00:00
|
|
|
#include <fcntl.h>
|
2006-07-10 21:32:19 +00:00
|
|
|
#include <inttypes.h>
|
2008-08-14 15:54:53 +00:00
|
|
|
#include <poll.h>
|
2006-07-10 21:32:19 +00:00
|
|
|
#include <linux/videodev2.h>
|
|
|
|
|
2013-07-12 20:04:44 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
#include <libavutil/avstring.h>
|
|
|
|
|
2013-11-30 21:40:51 +00:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2014-06-09 21:54:45 +00:00
|
|
|
#include "options/options.h"
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
#include "stream.h"
|
2014-06-10 18:12:19 +00:00
|
|
|
#include "tv.h"
|
2007-05-08 12:20:46 +00:00
|
|
|
#include "frequencies.h"
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
#define PVR_DEFAULT_DEVICE "/dev/video0"
|
2006-09-27 20:26:38 +00:00
|
|
|
#define PVR_MAX_CONTROLS 10
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* logging mechanisms */
|
|
|
|
#define LOG_LEVEL_PVR "[pvr]"
|
|
|
|
#define LOG_LEVEL_V4L2 "[v4l2]"
|
2006-09-25 20:36:45 +00:00
|
|
|
#define LOG_LEVEL_ENCODER "[encoder]"
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* audio codec mode */
|
|
|
|
#define PVR_AUDIO_MODE_ARG_STEREO "stereo"
|
|
|
|
#define PVR_AUDIO_MODE_ARG_JOINT_STEREO "joint_stereo"
|
|
|
|
#define PVR_AUDIO_MODE_ARG_DUAL "dual"
|
|
|
|
#define PVR_AUDIO_MODE_ARG_MONO "mono"
|
|
|
|
|
|
|
|
/* video codec bitrate mode */
|
|
|
|
#define PVR_VIDEO_BITRATE_MODE_ARG_VBR "vbr"
|
|
|
|
#define PVR_VIDEO_BITRATE_MODE_ARG_CBR "cbr"
|
|
|
|
|
|
|
|
/* video codec stream type */
|
|
|
|
#define PVR_VIDEO_STREAM_TYPE_PS "ps"
|
|
|
|
#define PVR_VIDEO_STREAM_TYPE_TS "ts"
|
|
|
|
#define PVR_VIDEO_STREAM_TYPE_MPEG1 "mpeg1"
|
|
|
|
#define PVR_VIDEO_STREAM_TYPE_DVD "dvd"
|
|
|
|
#define PVR_VIDEO_STREAM_TYPE_VCD "vcd"
|
|
|
|
#define PVR_VIDEO_STREAM_TYPE_SVCD "svcd"
|
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
#define PVR_STATION_NAME_SIZE 256
|
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* command line arguments */
|
2014-06-10 18:12:19 +00:00
|
|
|
struct pvr_params {
|
|
|
|
int aspect_ratio;
|
|
|
|
int sample_rate;
|
|
|
|
int audio_layer;
|
|
|
|
int audio_bitrate;
|
|
|
|
char *audio_mode;
|
|
|
|
int bitrate;
|
|
|
|
char *bitrate_mode;
|
|
|
|
int bitrate_peak;
|
|
|
|
char *stream_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OPT_BASE_STRUCT struct pvr_params
|
|
|
|
const struct m_sub_options stream_pvr_conf = {
|
|
|
|
.opts = (const m_option_t[]) {
|
|
|
|
OPT_INT("aspect", aspect_ratio, 0),
|
|
|
|
OPT_INT("arate", sample_rate, 0),
|
|
|
|
OPT_INT("alayer", audio_layer, 0),
|
|
|
|
OPT_INT("abitrate", audio_bitrate, 0),
|
|
|
|
OPT_STRING("amode", audio_mode, 0),
|
|
|
|
OPT_INT("vbitrate", bitrate, 0),
|
|
|
|
OPT_STRING("vmode", bitrate_mode, 0),
|
|
|
|
OPT_INT("vpeak", bitrate_peak, 0),
|
|
|
|
OPT_STRING("fmt", stream_type, 0),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.size = sizeof(struct pvr_params),
|
|
|
|
};
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2012-05-13 18:58:32 +00:00
|
|
|
#define BUFSTRCPY(d, s) av_strlcpy(d, s, sizeof(d))
|
|
|
|
#define BUFPRINTF(d, ...) snprintf(d, sizeof(d), __VA_ARGS__)
|
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
typedef struct station_elem_s {
|
2012-04-10 15:53:25 +00:00
|
|
|
char name[PVR_STATION_NAME_SIZE];
|
2007-05-08 12:20:46 +00:00
|
|
|
int freq;
|
|
|
|
char station[PVR_STATION_NAME_SIZE];
|
|
|
|
int enabled;
|
|
|
|
} station_elem_t;
|
|
|
|
|
|
|
|
typedef struct stationlist_s {
|
|
|
|
char name[PVR_STATION_NAME_SIZE];
|
|
|
|
station_elem_t *list;
|
|
|
|
int total; /* total number */
|
|
|
|
int used; /* used number */
|
|
|
|
int enabled; /* enabled number */
|
|
|
|
} stationlist_t;
|
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
struct pvr_t {
|
2013-12-21 19:36:45 +00:00
|
|
|
struct mp_log *log;
|
2014-06-09 21:54:45 +00:00
|
|
|
tv_param_t *tv_params;
|
2014-06-10 18:12:19 +00:00
|
|
|
struct pvr_params *params;
|
2006-07-10 21:32:19 +00:00
|
|
|
int dev_fd;
|
|
|
|
char *video_dev;
|
2014-06-10 18:12:19 +00:00
|
|
|
int chantab;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* v4l2 params */
|
|
|
|
int mute;
|
|
|
|
int input;
|
|
|
|
int normid;
|
|
|
|
int brightness;
|
|
|
|
int contrast;
|
|
|
|
int hue;
|
|
|
|
int saturation;
|
|
|
|
int width;
|
|
|
|
int height;
|
2007-05-08 12:20:46 +00:00
|
|
|
int freq;
|
|
|
|
int chan_idx;
|
|
|
|
int chan_idx_last;
|
|
|
|
stationlist_t stationlist;
|
|
|
|
/* dups the tv_param_channel, or the url's channel param */
|
|
|
|
char *param_channel;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2006-09-25 20:36:45 +00:00
|
|
|
/* encoder params */
|
2006-07-10 21:32:19 +00:00
|
|
|
int aspect;
|
|
|
|
int samplerate;
|
|
|
|
int layer;
|
|
|
|
int audio_rate;
|
|
|
|
int audio_mode;
|
|
|
|
int bitrate;
|
|
|
|
int bitrate_mode;
|
|
|
|
int bitrate_peak;
|
|
|
|
int stream_type;
|
|
|
|
};
|
|
|
|
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
static int pvr_stream_control(struct stream *s, int cmd, void *arg);
|
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
static struct pvr_t *
|
|
|
|
pvr_init (void)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = NULL;
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
pvr = calloc (1, sizeof (struct pvr_t));
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr->dev_fd = -1;
|
|
|
|
pvr->video_dev = strdup (PVR_DEFAULT_DEVICE);
|
2014-06-10 18:12:19 +00:00
|
|
|
pvr->chantab = 5;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* v4l2 params */
|
|
|
|
pvr->mute = 0;
|
|
|
|
pvr->input = 0;
|
|
|
|
pvr->normid = -1;
|
|
|
|
pvr->brightness = 0;
|
|
|
|
pvr->contrast = 0;
|
|
|
|
pvr->hue = 0;
|
|
|
|
pvr->saturation = 0;
|
|
|
|
pvr->width = -1;
|
|
|
|
pvr->height = -1;
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr->freq = -1;
|
|
|
|
pvr->chan_idx = -1;
|
|
|
|
pvr->chan_idx_last = -1;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
/* set default encoding settings
|
|
|
|
* may be overlapped by user parameters
|
|
|
|
* Use VBR MPEG_PS encoding at 6 Mbps (peak at 9.6 Mbps)
|
|
|
|
* with 48 KHz L2 384 kbps audio.
|
|
|
|
*/
|
|
|
|
pvr->aspect = V4L2_MPEG_VIDEO_ASPECT_4x3;
|
|
|
|
pvr->samplerate = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
|
|
|
|
pvr->layer = V4L2_MPEG_AUDIO_ENCODING_LAYER_2;
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
|
|
|
|
pvr->audio_mode = V4L2_MPEG_AUDIO_MODE_STEREO;
|
|
|
|
pvr->bitrate = 6000000;
|
|
|
|
pvr->bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
|
|
|
|
pvr->bitrate_peak = 9600000;
|
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG2_PS;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
return pvr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pvr_uninit (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
if (!pvr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* close device */
|
2014-01-20 22:08:47 +00:00
|
|
|
if (pvr->dev_fd != -1)
|
2006-07-10 21:32:19 +00:00
|
|
|
close (pvr->dev_fd);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2010-11-07 12:47:40 +00:00
|
|
|
free (pvr->video_dev);
|
|
|
|
free (pvr->stationlist.list);
|
|
|
|
free (pvr->param_channel);
|
2006-07-10 21:32:19 +00:00
|
|
|
free (pvr);
|
|
|
|
}
|
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
/**
|
|
|
|
* @brief Copy Constructor for stationlist
|
|
|
|
*
|
|
|
|
* @see parse_setup_stationlist
|
|
|
|
*/
|
|
|
|
static int
|
2013-12-21 19:36:45 +00:00
|
|
|
copycreate_stationlist (struct pvr_t *pvr, stationlist_t *stationlist, int num)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->chantab < 0 || !stationlist)
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
num = FFMAX (num, chanlists[pvr->chantab].count);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
2010-11-07 12:47:40 +00:00
|
|
|
free (stationlist->list);
|
|
|
|
stationlist->list = NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
stationlist->total = 0;
|
|
|
|
stationlist->enabled = 0;
|
|
|
|
stationlist->used = 0;
|
|
|
|
stationlist->list = calloc (num, sizeof (station_elem_t));
|
|
|
|
|
|
|
|
if (!stationlist->list)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s No memory allocated for station list, giving up\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
/* transport the channel list data to our extented struct */
|
|
|
|
stationlist->total = num;
|
2014-06-10 18:12:19 +00:00
|
|
|
BUFSTRCPY(stationlist->name, chanlists[pvr->chantab].name);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
for (i = 0; i < chanlists[pvr->chantab].count; i++)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
|
|
|
stationlist->list[i].station[0]= '\0'; /* no station name yet */
|
2014-06-10 18:12:19 +00:00
|
|
|
BUFSTRCPY(stationlist->list[i].name, chanlists[pvr->chantab].list[i].name);
|
|
|
|
stationlist->list[i].freq = chanlists[pvr->chantab].list[i].freq;
|
2007-05-08 12:20:46 +00:00
|
|
|
stationlist->list[i].enabled = 1; /* default enabled */
|
|
|
|
stationlist->enabled++;
|
|
|
|
stationlist->used++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_all_stations (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if (!pvr || !pvr->stationlist.list)
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < pvr->stationlist.total; i++)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(pvr, "%s %3d: [%c] channel: %8s - freq: %8d - station: %s\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, i, (pvr->stationlist.list[i].enabled) ? 'X' : ' ',
|
|
|
|
pvr->stationlist.list[i].name, pvr->stationlist.list[i].freq,
|
|
|
|
pvr->stationlist.list[i].station);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables all stations
|
|
|
|
*
|
|
|
|
* @see parse_setup_stationlist
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
disable_all_stations (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < pvr->stationlist.total; i++)
|
|
|
|
pvr->stationlist.list[i].enabled = 0;
|
|
|
|
pvr->stationlist.enabled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update or add a station
|
|
|
|
*
|
|
|
|
* @see parse_setup_stationlist
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
set_station (struct pvr_t *pvr, const char *station,
|
|
|
|
const char *channel, int freq)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if (!pvr || !pvr->stationlist.list)
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (0 >= pvr->stationlist.total || (!channel && !freq))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* select channel */
|
|
|
|
for (i = 0; i < pvr->stationlist.used; i++)
|
|
|
|
{
|
|
|
|
if (channel && !strcasecmp (pvr->stationlist.list[i].name, channel))
|
|
|
|
break; /* found existing channel entry */
|
|
|
|
|
|
|
|
if (freq > 0 && pvr->stationlist.list[i].freq == freq)
|
|
|
|
break; /* found existing frequency entry */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < pvr->stationlist.used)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* found an existing entry,
|
|
|
|
* which is about to change with the user data.
|
|
|
|
* it is also enabled ..
|
|
|
|
*/
|
|
|
|
if (!pvr->stationlist.list[i].enabled)
|
|
|
|
{
|
|
|
|
pvr->stationlist.list[i].enabled = 1;
|
|
|
|
pvr->stationlist.enabled++;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
if (station)
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFSTRCPY(pvr->stationlist.list[i].station, station);
|
2007-05-08 12:20:46 +00:00
|
|
|
else if (channel)
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFSTRCPY(pvr->stationlist.list[i].station, channel);
|
2007-05-08 12:20:46 +00:00
|
|
|
else
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFPRINTF(pvr->stationlist.list[i].station, "F %d", freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_DBG(pvr, "%s Set user station channel: %8s - freq: %8d - station: %s\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->stationlist.list[i].name,
|
|
|
|
pvr->stationlist.list[i].freq,
|
|
|
|
pvr->stationlist.list[i].station);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* from here on, we have to create a new entry, frequency is mandatory */
|
|
|
|
if (freq < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s Cannot add new station/channel without frequency\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pvr->stationlist.total < i)
|
|
|
|
{
|
|
|
|
/**
|
2009-07-06 23:26:13 +00:00
|
|
|
* we have to extend the stationlist about
|
2007-05-08 12:20:46 +00:00
|
|
|
* an arbitrary size, even though this path is not performance critical
|
|
|
|
*/
|
|
|
|
pvr->stationlist.total += 10;
|
|
|
|
pvr->stationlist.list =
|
|
|
|
realloc (pvr->stationlist.list,
|
|
|
|
pvr->stationlist.total * sizeof (station_elem_t));
|
|
|
|
|
|
|
|
if (!pvr->stationlist.list)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s No memory allocated for station list, giving up\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the new space ..*/
|
|
|
|
memset (&(pvr->stationlist.list[pvr->stationlist.used]), 0,
|
|
|
|
(pvr->stationlist.total - pvr->stationlist.used)
|
|
|
|
* sizeof (station_elem_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* here we go, our actual new entry */
|
|
|
|
pvr->stationlist.used++;
|
|
|
|
pvr->stationlist.list[i].enabled = 1;
|
|
|
|
pvr->stationlist.enabled++;
|
|
|
|
|
|
|
|
if (station)
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFSTRCPY(pvr->stationlist.list[i].station, station);
|
2007-05-08 12:20:46 +00:00
|
|
|
if (channel)
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFSTRCPY(pvr->stationlist.list[i].name, channel);
|
2007-05-08 12:20:46 +00:00
|
|
|
else
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFPRINTF(pvr->stationlist.list[i].name, "F %d", freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
pvr->stationlist.list[i].freq = freq;
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_DBG(pvr, "%s Add user station channel: %8s - freq: %8d - station: %s\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->stationlist.list[i].name,
|
|
|
|
pvr->stationlist.list[i].freq,
|
|
|
|
pvr->stationlist.list[i].station);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Here we set our stationlist, as follow
|
|
|
|
* - choose the frequency channel table, e.g. ntsc-cable
|
|
|
|
* - create our stationlist, same element size as the channellist
|
|
|
|
* - copy the channellist content to our stationlist
|
|
|
|
* - IF the user provides his channel-mapping, THEN:
|
|
|
|
* - disable all stations
|
|
|
|
* - update and/or create entries in the stationlist and enable them
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
parse_setup_stationlist (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if (!pvr)
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Create our station/channel list */
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->chanlist)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
|
|
|
/* select channel list */
|
|
|
|
for (i = 0; chanlists[i].name != NULL; i++)
|
|
|
|
{
|
2014-06-09 21:54:45 +00:00
|
|
|
if (!strcasecmp (chanlists[i].name, pvr->tv_params->chanlist))
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
pvr->chantab = i;
|
2007-05-08 12:20:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!chanlists[i].name)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s unable to find channel list %s, using default %s\n",
|
2014-06-10 18:12:19 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->tv_params->chanlist, chanlists[pvr->chantab].name);
|
2007-05-08 12:20:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s select channel list %s, entries %d\n", LOG_LEVEL_V4L2,
|
2014-06-10 18:12:19 +00:00
|
|
|
chanlists[pvr->chantab].name, chanlists[pvr->chantab].count);
|
2007-05-08 12:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
if (0 > pvr->chantab)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_FATAL(pvr, "%s No channel list selected, giving up\n", LOG_LEVEL_V4L2);
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
if (copycreate_stationlist (pvr,&(pvr->stationlist), -1) < 0)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_FATAL(pvr, "%s No memory allocated for station list, giving up\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle user channel mappings */
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->channels)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
|
|
|
char channel[PVR_STATION_NAME_SIZE];
|
|
|
|
char station[PVR_STATION_NAME_SIZE];
|
2014-06-09 21:54:45 +00:00
|
|
|
char **channels = pvr->tv_params->channels;
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
disable_all_stations (pvr);
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
while (*channels)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
|
|
|
char *tmp = *(channels++);
|
|
|
|
char *sep = strchr (tmp, '-');
|
|
|
|
int freq=-1;
|
|
|
|
|
|
|
|
if (!sep)
|
|
|
|
continue; /* Wrong syntax, but mplayer should not crash */
|
|
|
|
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFSTRCPY(station, sep + 1);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
sep[0] = '\0';
|
2012-05-13 18:58:32 +00:00
|
|
|
BUFSTRCPY(channel, tmp);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
while ((sep = strchr (station, '_')))
|
|
|
|
sep[0] = ' ';
|
|
|
|
|
|
|
|
/* if channel number is a number and larger than 1000 treat it as
|
|
|
|
* frequency tmp still contain pointer to null-terminated string with
|
|
|
|
* channel number here
|
|
|
|
*/
|
|
|
|
if ((freq = atoi (channel)) <= 1000)
|
2009-07-06 23:26:13 +00:00
|
|
|
freq = -1;
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
if (set_station (pvr, station, (freq <= 0) ? channel : NULL, freq) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s Unable to set user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
channel, freq, station);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
return print_all_stations (pvr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_v4l2_freq (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
int freq;
|
|
|
|
struct v4l2_frequency vf;
|
|
|
|
struct v4l2_tuner vt;
|
|
|
|
|
|
|
|
if (!pvr)
|
|
|
|
return -1;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
if (pvr->dev_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset (&vt, 0, sizeof (vt));
|
|
|
|
memset (&vf, 0, sizeof (vf));
|
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_TUNER, &vt) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set tuner (%s).\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_FREQUENCY, &vf) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get frequency %d.\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
freq = vf.frequency;
|
|
|
|
if (!(vt.capability & V4L2_TUNER_CAP_LOW))
|
|
|
|
freq *= 1000;
|
|
|
|
freq /= 16;
|
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_v4l2_freq (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
struct v4l2_frequency vf;
|
|
|
|
struct v4l2_tuner vt;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
if (!pvr)
|
|
|
|
return -1;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
if (0 >= pvr->freq)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s Frequency invalid %d !!!\n", LOG_LEVEL_V4L2, pvr->freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't set the frequency, if it's already set.
|
|
|
|
* setting it here would interrupt the stream.
|
|
|
|
*/
|
|
|
|
if (get_v4l2_freq (pvr) == pvr->freq)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Frequency %d already set.\n", LOG_LEVEL_V4L2, pvr->freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pvr->dev_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset (&vf, 0, sizeof (vf));
|
|
|
|
memset (&vt, 0, sizeof (vt));
|
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_TUNER, &vt) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get tuner (%s).\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf.type = vt.type;
|
|
|
|
vf.frequency = pvr->freq * 16;
|
|
|
|
|
|
|
|
if (!(vt.capability & V4L2_TUNER_CAP_LOW))
|
|
|
|
vf.frequency /= 1000;
|
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_FREQUENCY, &vf) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set frequency (%s).\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset (&vt, 0, sizeof(vt));
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_TUNER, &vt) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set tuner (%s).\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* just a notification */
|
|
|
|
if (!vt.signal)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s NO SIGNAL at frequency %d (%d)\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->freq, vf.frequency);
|
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Got signal at frequency %d (%d)\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->freq, vf.frequency);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-06 23:26:13 +00:00
|
|
|
set_station_by_step (struct pvr_t *pvr, int step, int v4lAction)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2009-07-06 23:26:13 +00:00
|
|
|
if (!pvr || !pvr->stationlist.list)
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pvr->stationlist.enabled >= abs (step))
|
|
|
|
{
|
|
|
|
int gotcha = 0;
|
|
|
|
int chidx = pvr->chan_idx + step;
|
|
|
|
|
|
|
|
while (!gotcha)
|
|
|
|
{
|
|
|
|
chidx = (chidx + pvr->stationlist.used) % pvr->stationlist.used;
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_DBG(pvr, "%s Offset switch: current %d, enabled %d, step %d -> %d\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->chan_idx,
|
|
|
|
pvr->stationlist.enabled, step, chidx);
|
|
|
|
|
|
|
|
if (!pvr->stationlist.list[chidx].enabled)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_DBG(pvr, "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr->stationlist.list[chidx].name,
|
|
|
|
pvr->stationlist.list[chidx].freq,
|
|
|
|
pvr->stationlist.list[chidx].station);
|
|
|
|
chidx += FFSIGN (step);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gotcha = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pvr->freq = pvr->stationlist.list[chidx].freq;
|
|
|
|
pvr->chan_idx_last = pvr->chan_idx;
|
|
|
|
pvr->chan_idx = chidx;
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Switch to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr->stationlist.list[chidx].name,
|
|
|
|
pvr->stationlist.list[chidx].freq,
|
|
|
|
pvr->stationlist.list[chidx].station);
|
|
|
|
|
|
|
|
if (v4lAction)
|
|
|
|
return set_v4l2_freq (pvr);
|
|
|
|
|
|
|
|
return (pvr->freq > 0) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s Ooops couldn't set freq by channel entry step %d to current %d, enabled %d\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
step, pvr->chan_idx, pvr->stationlist.enabled);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_station_by_channelname_or_freq (struct pvr_t *pvr, const char *channel,
|
|
|
|
int freq, int v4lAction)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if (!pvr || !pvr->stationlist.list)
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (0 >= pvr->stationlist.enabled)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_WARN(pvr, "%s No enabled station, cannot switch channel/frequency\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel)
|
|
|
|
{
|
|
|
|
/* select by channel */
|
|
|
|
for (i = 0; i < pvr->stationlist.used ; i++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp (pvr->stationlist.list[i].name, channel))
|
|
|
|
{
|
|
|
|
if (!pvr->stationlist.list[i].enabled)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_WARN(pvr, "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr->stationlist.list[i].name,
|
|
|
|
pvr->stationlist.list[i].freq,
|
|
|
|
pvr->stationlist.list[i].station);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pvr->freq = pvr->stationlist.list[i].freq;
|
|
|
|
pvr->chan_idx_last = pvr->chan_idx;
|
|
|
|
pvr->chan_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (freq >= 0)
|
|
|
|
{
|
|
|
|
/* select by freq */
|
|
|
|
for (i = 0; i < pvr->stationlist.used; i++)
|
|
|
|
{
|
|
|
|
if (pvr->stationlist.list[i].freq == freq)
|
|
|
|
{
|
|
|
|
if (!pvr->stationlist.list[i].enabled)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_WARN(pvr, "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr->stationlist.list[i].name,
|
|
|
|
pvr->stationlist.list[i].freq,
|
|
|
|
pvr->stationlist.list[i].station);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pvr->freq = pvr->stationlist.list[i].freq;
|
|
|
|
pvr->chan_idx_last = pvr->chan_idx;
|
|
|
|
pvr->chan_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= pvr->stationlist.used)
|
|
|
|
{
|
|
|
|
if (channel)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_WARN(pvr, "%s unable to find channel %s\n", LOG_LEVEL_V4L2, channel);
|
2007-05-08 12:20:46 +00:00
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_WARN(pvr, "%s unable to find frequency %d\n", LOG_LEVEL_V4L2, freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Switch to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr->stationlist.list[i].name,
|
|
|
|
pvr->stationlist.list[i].freq,
|
|
|
|
pvr->stationlist.list[i].station);
|
|
|
|
|
|
|
|
if (v4lAction)
|
|
|
|
return set_v4l2_freq (pvr);
|
|
|
|
|
|
|
|
return (pvr->freq > 0) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
static void
|
2006-09-25 20:36:45 +00:00
|
|
|
parse_encoder_options (struct pvr_t *pvr)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
|
|
|
if (!pvr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* -pvr aspect=digit */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->aspect_ratio >= 0 && pvr->params->aspect_ratio <= 3)
|
|
|
|
pvr->aspect = pvr->params->aspect_ratio;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* -pvr arate=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->sample_rate != 0)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
switch (pvr->params->sample_rate)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
|
|
|
case 32000:
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->samplerate = V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000;
|
2006-07-10 21:32:19 +00:00
|
|
|
break;
|
|
|
|
case 44100:
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->samplerate = V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100;
|
2006-07-10 21:32:19 +00:00
|
|
|
break;
|
|
|
|
case 48000:
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->samplerate = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
|
2006-07-10 21:32:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -pvr alayer=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->audio_layer == 1)
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->layer = V4L2_MPEG_AUDIO_ENCODING_LAYER_1;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (pvr->params->audio_layer == 2)
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->layer = V4L2_MPEG_AUDIO_ENCODING_LAYER_2;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (pvr->params->audio_layer == 3)
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->layer = V4L2_MPEG_AUDIO_ENCODING_LAYER_3;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* -pvr abitrate=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->audio_bitrate != 0)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2006-09-27 20:26:38 +00:00
|
|
|
if (pvr->layer == V4L2_MPEG_AUDIO_ENCODING_LAYER_1)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
switch (pvr->params->audio_bitrate)
|
2006-09-27 20:26:38 +00:00
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_32K;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_64K;
|
|
|
|
break;
|
|
|
|
case 96:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_96K;
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_128K;
|
|
|
|
break;
|
|
|
|
case 160:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_160K;
|
|
|
|
break;
|
|
|
|
case 192:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_192K;
|
|
|
|
break;
|
|
|
|
case 224:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_224K;
|
|
|
|
break;
|
|
|
|
case 256:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_256K;
|
|
|
|
break;
|
|
|
|
case 288:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_288K;
|
|
|
|
break;
|
|
|
|
case 320:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_320K;
|
|
|
|
break;
|
|
|
|
case 352:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_352K;
|
|
|
|
break;
|
|
|
|
case 384:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_384K;
|
|
|
|
break;
|
|
|
|
case 416:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_416K;
|
|
|
|
break;
|
|
|
|
case 448:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L1_BITRATE_448K;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
else if (pvr->layer == V4L2_MPEG_AUDIO_ENCODING_LAYER_2)
|
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
switch (pvr->params->audio_bitrate)
|
2006-09-27 20:26:38 +00:00
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_32K;
|
|
|
|
break;
|
|
|
|
case 48:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_48K;
|
|
|
|
break;
|
|
|
|
case 56:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_56K;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_64K;
|
|
|
|
break;
|
|
|
|
case 80:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_80K;
|
|
|
|
break;
|
|
|
|
case 96:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_96K;
|
|
|
|
break;
|
|
|
|
case 112:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_112K;
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_128K;
|
|
|
|
break;
|
|
|
|
case 160:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_160K;
|
|
|
|
break;
|
|
|
|
case 192:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_192K;
|
|
|
|
break;
|
|
|
|
case 224:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_224K;
|
|
|
|
break;
|
|
|
|
case 256:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_256K;
|
|
|
|
break;
|
|
|
|
case 320:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_320K;
|
|
|
|
break;
|
|
|
|
case 384:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (pvr->layer == V4L2_MPEG_AUDIO_ENCODING_LAYER_3)
|
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
switch (pvr->params->audio_bitrate)
|
2006-09-27 20:26:38 +00:00
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_32K;
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_40K;
|
|
|
|
break;
|
|
|
|
case 48:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_48K;
|
|
|
|
break;
|
|
|
|
case 56:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_56K;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_64K;
|
|
|
|
break;
|
|
|
|
case 80:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_80K;
|
|
|
|
break;
|
|
|
|
case 96:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_96K;
|
|
|
|
break;
|
|
|
|
case 112:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_112K;
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_128K;
|
|
|
|
break;
|
|
|
|
case 160:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_160K;
|
|
|
|
break;
|
|
|
|
case 192:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_192K;
|
|
|
|
break;
|
|
|
|
case 224:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_224K;
|
|
|
|
break;
|
|
|
|
case 256:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_256K;
|
|
|
|
break;
|
|
|
|
case 320:
|
|
|
|
pvr->audio_rate = V4L2_MPEG_AUDIO_L3_BITRATE_320K;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* -pvr amode=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->audio_mode)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
if (!strcmp (pvr->params->audio_mode, PVR_AUDIO_MODE_ARG_STEREO))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->audio_mode = V4L2_MPEG_AUDIO_MODE_STEREO;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->audio_mode, PVR_AUDIO_MODE_ARG_JOINT_STEREO))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->audio_mode = V4L2_MPEG_AUDIO_MODE_JOINT_STEREO;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->audio_mode, PVR_AUDIO_MODE_ARG_DUAL))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->audio_mode = V4L2_MPEG_AUDIO_MODE_DUAL;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->audio_mode, PVR_AUDIO_MODE_ARG_MONO))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->audio_mode = V4L2_MPEG_AUDIO_MODE_MONO;
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -pvr vbitrate=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->bitrate)
|
|
|
|
pvr->bitrate = pvr->params->bitrate;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* -pvr vmode=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->bitrate_mode)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
if (!strcmp (pvr->params->bitrate_mode, PVR_VIDEO_BITRATE_MODE_ARG_VBR))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->bitrate_mode, PVR_VIDEO_BITRATE_MODE_ARG_CBR))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -pvr vpeak=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->bitrate_peak)
|
|
|
|
pvr->bitrate_peak = pvr->params->bitrate_peak;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* -pvr fmt=x */
|
2014-06-10 18:12:19 +00:00
|
|
|
if (pvr->params->stream_type)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2014-06-10 18:12:19 +00:00
|
|
|
if (!strcmp (pvr->params->stream_type, PVR_VIDEO_STREAM_TYPE_PS))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG2_PS;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->stream_type, PVR_VIDEO_STREAM_TYPE_TS))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->stream_type, PVR_VIDEO_STREAM_TYPE_MPEG1))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG1_SS;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->stream_type, PVR_VIDEO_STREAM_TYPE_DVD))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG2_DVD;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->stream_type, PVR_VIDEO_STREAM_TYPE_VCD))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG1_VCD;
|
2014-06-10 18:12:19 +00:00
|
|
|
else if (!strcmp (pvr->params->stream_type, PVR_VIDEO_STREAM_TYPE_SVCD))
|
2006-09-27 20:26:38 +00:00
|
|
|
pvr->stream_type = V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD;
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
static void
|
|
|
|
add_v4l2_ext_control (struct v4l2_ext_control *ctrl,
|
|
|
|
uint32_t id, int32_t value)
|
|
|
|
{
|
2009-07-06 23:26:13 +00:00
|
|
|
ctrl->id = id;
|
2006-09-27 20:26:38 +00:00
|
|
|
ctrl->value = value;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
static int
|
2006-09-25 20:36:45 +00:00
|
|
|
set_encoder_settings (struct pvr_t *pvr)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2006-09-27 20:26:38 +00:00
|
|
|
struct v4l2_ext_control *ext_ctrl = NULL;
|
|
|
|
struct v4l2_ext_controls ctrls;
|
|
|
|
uint32_t count = 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (!pvr)
|
|
|
|
return -1;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (pvr->dev_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
ext_ctrl = (struct v4l2_ext_control *)
|
2009-07-06 23:26:13 +00:00
|
|
|
malloc (PVR_MAX_CONTROLS * sizeof (struct v4l2_ext_control));
|
2006-09-27 20:26:38 +00:00
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_VIDEO_ASPECT,
|
|
|
|
pvr->aspect);
|
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
|
|
|
|
pvr->samplerate);
|
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_AUDIO_ENCODING,
|
|
|
|
pvr->layer);
|
|
|
|
|
|
|
|
switch (pvr->layer)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2006-09-27 20:26:38 +00:00
|
|
|
case V4L2_MPEG_AUDIO_ENCODING_LAYER_1:
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_AUDIO_L1_BITRATE,
|
|
|
|
pvr->audio_rate);
|
|
|
|
break;
|
|
|
|
case V4L2_MPEG_AUDIO_ENCODING_LAYER_2:
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_AUDIO_L2_BITRATE,
|
|
|
|
pvr->audio_rate);
|
|
|
|
break;
|
|
|
|
case V4L2_MPEG_AUDIO_ENCODING_LAYER_3:
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_AUDIO_L3_BITRATE,
|
|
|
|
pvr->audio_rate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
2006-09-27 20:26:38 +00:00
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_AUDIO_MODE,
|
|
|
|
pvr->audio_mode);
|
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_VIDEO_BITRATE,
|
|
|
|
pvr->bitrate);
|
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
|
|
|
|
pvr->bitrate_peak);
|
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
|
|
|
|
pvr->bitrate_mode);
|
|
|
|
|
|
|
|
add_v4l2_ext_control (&ext_ctrl[count++], V4L2_CID_MPEG_STREAM_TYPE,
|
|
|
|
pvr->stream_type);
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* set new encoding settings */
|
2009-07-06 23:26:13 +00:00
|
|
|
ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
|
|
|
|
ctrls.count = count;
|
2006-09-27 20:26:38 +00:00
|
|
|
ctrls.controls = ext_ctrl;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_EXT_CTRLS, &ctrls) < 0)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s Error setting MPEG controls (%s).\n",
|
2006-09-27 20:26:38 +00:00
|
|
|
LOG_LEVEL_ENCODER, strerror (errno));
|
2009-07-06 23:26:13 +00:00
|
|
|
free (ext_ctrl);
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
free (ext_ctrl);
|
2006-09-27 20:26:38 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_v4l2_tv_options (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
if (!pvr)
|
|
|
|
return;
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
/* Create our station/channel list */
|
|
|
|
parse_setup_stationlist (pvr);
|
|
|
|
|
|
|
|
if (pvr->param_channel)
|
|
|
|
{
|
|
|
|
if (set_station_by_channelname_or_freq (pvr, pvr->param_channel,
|
|
|
|
-1, 0) >= 0)
|
|
|
|
{
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->freq)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s tv param freq %s is overwritten by channel setting freq %d\n", LOG_LEVEL_V4L2,
|
2014-06-09 21:54:45 +00:00
|
|
|
pvr->tv_params->freq, pvr->freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->freq < 0 && pvr->tv_params->freq)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s tv param freq %s is used directly\n",
|
2014-06-09 21:54:45 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->tv_params->freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
|
|
|
|
if (set_station_by_channelname_or_freq (pvr, NULL,
|
2014-06-09 21:54:45 +00:00
|
|
|
atoi (pvr->tv_params->freq), 0)<0)
|
2007-05-08 12:20:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_WARN(pvr, "%s tv param freq %s invalid to set station\n",
|
2014-06-09 21:54:45 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->tv_params->freq);
|
2007-05-08 12:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->device)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2010-11-07 12:47:40 +00:00
|
|
|
free (pvr->video_dev);
|
2014-06-09 21:54:45 +00:00
|
|
|
pvr->video_dev = strdup (pvr->tv_params->device);
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (!pvr->tv_params->audio)
|
|
|
|
pvr->mute = !pvr->tv_params->audio;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->input)
|
|
|
|
pvr->input = pvr->tv_params->input;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->normid)
|
|
|
|
pvr->normid = pvr->tv_params->normid;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->brightness)
|
|
|
|
pvr->brightness = pvr->tv_params->brightness;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->contrast)
|
|
|
|
pvr->contrast = pvr->tv_params->contrast;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->hue)
|
|
|
|
pvr->hue = pvr->tv_params->hue;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->saturation)
|
|
|
|
pvr->saturation = pvr->tv_params->saturation;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->width)
|
|
|
|
pvr->width = pvr->tv_params->width;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2014-06-09 21:54:45 +00:00
|
|
|
if (pvr->tv_params->height)
|
|
|
|
pvr->height = pvr->tv_params->height;
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_v4l2_settings (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
if (!pvr)
|
|
|
|
return -1;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (pvr->dev_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* -tv noaudio */
|
|
|
|
if (pvr->mute)
|
|
|
|
{
|
|
|
|
struct v4l2_control ctrl;
|
|
|
|
ctrl.id = V4L2_CID_AUDIO_MUTE;
|
|
|
|
ctrl.value = 1;
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't mute (%s).\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -tv input=x */
|
|
|
|
if (pvr->input != 0)
|
|
|
|
{
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_INPUT, &pvr->input) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set input (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* -tv normid=x */
|
|
|
|
if (pvr->normid != -1)
|
|
|
|
{
|
|
|
|
struct v4l2_standard std;
|
|
|
|
std.index = pvr->normid;
|
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_ENUMSTD, &std) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set norm (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(pvr, "%s set norm to %s\n", LOG_LEVEL_V4L2, std.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_STD, &std.id) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set norm (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* -tv brightness=x */
|
|
|
|
if (pvr->brightness != 0)
|
|
|
|
{
|
|
|
|
struct v4l2_control ctrl;
|
|
|
|
ctrl.id = V4L2_CID_BRIGHTNESS;
|
|
|
|
ctrl.value = pvr->brightness;
|
|
|
|
|
|
|
|
if (ctrl.value < 0)
|
|
|
|
ctrl.value = 0;
|
|
|
|
if (ctrl.value > 255)
|
|
|
|
ctrl.value = 255;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set brightness to %d (%s).\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -tv contrast=x */
|
|
|
|
if (pvr->contrast != 0)
|
|
|
|
{
|
|
|
|
struct v4l2_control ctrl;
|
|
|
|
ctrl.id = V4L2_CID_CONTRAST;
|
|
|
|
ctrl.value = pvr->contrast;
|
|
|
|
|
|
|
|
if (ctrl.value < 0)
|
|
|
|
ctrl.value = 0;
|
|
|
|
if (ctrl.value > 127)
|
|
|
|
ctrl.value = 127;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set contrast to %d (%s).\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -tv hue=x */
|
|
|
|
if (pvr->hue != 0)
|
|
|
|
{
|
|
|
|
struct v4l2_control ctrl;
|
|
|
|
ctrl.id = V4L2_CID_HUE;
|
|
|
|
ctrl.value = pvr->hue;
|
|
|
|
|
|
|
|
if (ctrl.value < -128)
|
|
|
|
ctrl.value = -128;
|
|
|
|
if (ctrl.value > 127)
|
|
|
|
ctrl.value = 127;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set hue to %d (%s).\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* -tv saturation=x */
|
|
|
|
if (pvr->saturation != 0)
|
|
|
|
{
|
|
|
|
struct v4l2_control ctrl;
|
|
|
|
ctrl.id = V4L2_CID_SATURATION;
|
|
|
|
ctrl.value = pvr->saturation;
|
|
|
|
|
|
|
|
if (ctrl.value < 0)
|
|
|
|
ctrl.value = 0;
|
|
|
|
if (ctrl.value > 127)
|
|
|
|
ctrl.value = 127;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set saturation to %d (%s).\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* -tv width=x:height=y */
|
|
|
|
if (pvr->width && pvr->height)
|
|
|
|
{
|
|
|
|
struct v4l2_format vfmt;
|
|
|
|
vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
vfmt.fmt.pix.width = pvr->width;
|
|
|
|
vfmt.fmt.pix.height = pvr->height;
|
|
|
|
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_S_FMT, &vfmt) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set resolution to %dx%d (%s).\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_V4L2, pvr->width, pvr->height, strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
if (pvr->freq < 0)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2007-05-08 12:20:46 +00:00
|
|
|
int freq = get_v4l2_freq (pvr);
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Using current set frequency %d, to set channel\n",
|
2007-05-08 12:20:46 +00:00
|
|
|
LOG_LEVEL_V4L2, freq);
|
|
|
|
|
|
|
|
if (0 < freq)
|
|
|
|
return set_station_by_channelname_or_freq (pvr, NULL, freq, 1);
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
if (0 < pvr->freq)
|
|
|
|
return set_v4l2_freq (pvr) ;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
v4l2_list_capabilities (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
struct v4l2_audio vaudio;
|
|
|
|
struct v4l2_standard vs;
|
|
|
|
struct v4l2_input vin;
|
|
|
|
int err = 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (!pvr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pvr->dev_fd < 0)
|
|
|
|
return -1;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* list available video inputs */
|
|
|
|
vin.index = 0;
|
|
|
|
err = 1;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Available video inputs: ", LOG_LEVEL_V4L2);
|
2006-07-10 21:32:19 +00:00
|
|
|
while (ioctl (pvr->dev_fd, VIDIOC_ENUMINPUT, &vin) >= 0)
|
|
|
|
{
|
|
|
|
err = 0;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "'#%d, %s' ", vin.index, vin.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
vin.index++;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "none\n");
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "\n");
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* list available audio inputs */
|
|
|
|
vaudio.index = 0;
|
|
|
|
err = 1;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Available audio inputs: ", LOG_LEVEL_V4L2);
|
2006-07-10 21:32:19 +00:00
|
|
|
while (ioctl (pvr->dev_fd, VIDIOC_ENUMAUDIO, &vaudio) >= 0)
|
|
|
|
{
|
|
|
|
err = 0;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "'#%d, %s' ", vaudio.index, vaudio.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
vaudio.index++;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "none\n");
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "\n");
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
/* list available norms */
|
|
|
|
vs.index = 0;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Available norms: ", LOG_LEVEL_V4L2);
|
2006-07-10 21:32:19 +00:00
|
|
|
while (ioctl (pvr->dev_fd, VIDIOC_ENUMSTD, &vs) >= 0)
|
|
|
|
{
|
|
|
|
err = 0;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "'#%d, %s' ", vs.index, vs.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
vs.index++;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "none\n");
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "\n");
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
v4l2_display_settings (struct pvr_t *pvr)
|
|
|
|
{
|
|
|
|
struct v4l2_audio vaudio;
|
|
|
|
struct v4l2_standard vs;
|
|
|
|
struct v4l2_input vin;
|
|
|
|
v4l2_std_id std;
|
|
|
|
int input;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (!pvr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pvr->dev_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* get current video input */
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_INPUT, &input) == 0)
|
|
|
|
{
|
|
|
|
vin.index = input;
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_ENUMINPUT, &vin) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get input (%s).\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Video input: %s\n", LOG_LEVEL_V4L2, vin.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get input (%s).\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get current audio input */
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_AUDIO, &vaudio) == 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Audio input: %s\n", LOG_LEVEL_V4L2, vaudio.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get input (%s).\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get current video format */
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_STD, &std) == 0)
|
|
|
|
{
|
|
|
|
vs.index = 0;
|
|
|
|
|
|
|
|
while (ioctl (pvr->dev_fd, VIDIOC_ENUMSTD, &vs) >= 0)
|
|
|
|
{
|
|
|
|
if (vs.id == std)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Norm: %s.\n", LOG_LEVEL_V4L2, vs.name);
|
2006-07-10 21:32:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
vs.index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get norm (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
|
2006-07-10 21:32:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stream layer */
|
|
|
|
|
|
|
|
static void
|
|
|
|
pvr_stream_close (stream_t *stream)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr;
|
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
return;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr = (struct pvr_t *) stream->priv;
|
|
|
|
pvr_uninit (pvr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pvr_stream_read (stream_t *stream, char *buffer, int size)
|
|
|
|
{
|
|
|
|
struct pollfd pfds[1];
|
|
|
|
struct pvr_t *pvr;
|
|
|
|
int rk, fd, pos;
|
|
|
|
|
|
|
|
if (!stream || !buffer)
|
|
|
|
return 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr = (struct pvr_t *) stream->priv;
|
|
|
|
fd = pvr->dev_fd;
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
while (pos < size)
|
|
|
|
{
|
|
|
|
pfds[0].fd = fd;
|
|
|
|
pfds[0].events = POLLIN | POLLPRI;
|
|
|
|
|
|
|
|
rk = size - pos;
|
|
|
|
|
|
|
|
if (poll (pfds, 1, 500) <= 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s failed with errno %d when reading %d bytes\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_PVR, errno, size-pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rk = read (fd, &buffer[pos], rk);
|
|
|
|
if (rk > 0)
|
|
|
|
{
|
|
|
|
pos += rk;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_TRACE(pvr, "%s read (%d) bytes\n", LOG_LEVEL_PVR, pos);
|
2006-07-10 21:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
if (!pos)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s read %d bytes\n", LOG_LEVEL_PVR, pos);
|
2006-07-10 21:32:19 +00:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-05-24 12:06:13 +00:00
|
|
|
pvr_stream_open (stream_t *stream)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
|
|
|
struct v4l2_capability vcap;
|
2006-09-27 20:26:38 +00:00
|
|
|
struct v4l2_ext_controls ctrls;
|
2006-07-10 21:32:19 +00:00
|
|
|
struct pvr_t *pvr = NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr = pvr_init ();
|
2014-06-09 21:54:45 +00:00
|
|
|
pvr->tv_params = stream->opts->tv_params;
|
2014-01-03 15:44:44 +00:00
|
|
|
pvr->log = stream->log;
|
2014-06-10 18:12:19 +00:00
|
|
|
pvr->params = stream->opts->stream_pvr_opts;
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
/**
|
|
|
|
* if the url, i.e. 'pvr://8', contains the channel, use it,
|
|
|
|
* else use the tv parameter.
|
|
|
|
*/
|
|
|
|
if (stream->url && strlen (stream->url) > 6 && stream->url[6] != '\0')
|
|
|
|
pvr->param_channel = strdup (stream->url + 6);
|
2014-06-09 21:54:45 +00:00
|
|
|
else if (pvr->tv_params->channel && strlen (pvr->tv_params->channel))
|
|
|
|
pvr->param_channel = strdup (pvr->tv_params->channel);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
parse_v4l2_tv_options (pvr);
|
2006-09-25 20:36:45 +00:00
|
|
|
parse_encoder_options (pvr);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* open device */
|
2013-11-30 21:40:51 +00:00
|
|
|
pvr->dev_fd = open (pvr->video_dev, O_RDWR | O_CLOEXEC);
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Using device %s\n", LOG_LEVEL_PVR, pvr->video_dev);
|
2006-07-10 21:32:19 +00:00
|
|
|
if (pvr->dev_fd == -1)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s error opening device %s\n", LOG_LEVEL_PVR, pvr->video_dev);
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* query capabilities (i.e test V4L2 support) */
|
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_QUERYCAP, &vcap) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s device is not V4L2 compliant (%s).\n",
|
2006-07-10 21:32:19 +00:00
|
|
|
LOG_LEVEL_PVR, strerror (errno));
|
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
else
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(pvr, "%s Detected %s\n", LOG_LEVEL_PVR, vcap.card);
|
2006-07-10 21:32:19 +00:00
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
/* check for a valid V4L2 capture device */
|
|
|
|
if (!(vcap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s device is not a valid V4L2 capture device.\n",
|
2006-09-27 20:26:38 +00:00
|
|
|
LOG_LEVEL_PVR);
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2006-09-27 20:26:38 +00:00
|
|
|
|
|
|
|
/* check for device hardware MPEG encoding capability */
|
2009-07-06 23:26:13 +00:00
|
|
|
ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
|
|
|
|
ctrls.count = 0;
|
2006-09-27 20:26:38 +00:00
|
|
|
ctrls.controls = NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-09-27 20:26:38 +00:00
|
|
|
if (ioctl (pvr->dev_fd, VIDIOC_G_EXT_CTRLS, &ctrls) < 0)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s device do not support MPEG input.\n", LOG_LEVEL_ENCODER);
|
2006-07-10 21:32:19 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* list V4L2 capabilities */
|
|
|
|
if (v4l2_list_capabilities (pvr) == -1)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get v4l2 capabilities\n", LOG_LEVEL_PVR);
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* apply V4L2 settings */
|
|
|
|
if (set_v4l2_settings (pvr) == -1)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set v4l2 settings\n", LOG_LEVEL_PVR);
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-09-25 20:36:45 +00:00
|
|
|
/* apply encoder settings */
|
|
|
|
if (set_encoder_settings (pvr) == -1)
|
2006-07-10 21:32:19 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't set encoder settings\n", LOG_LEVEL_PVR);
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
/* display current V4L2 settings */
|
|
|
|
if (v4l2_display_settings (pvr) == -1)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(pvr, "%s can't get v4l2 settings\n", LOG_LEVEL_PVR);
|
2006-07-10 21:32:19 +00:00
|
|
|
pvr_uninit (pvr);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->priv = pvr;
|
|
|
|
stream->fill_buffer = pvr_stream_read;
|
|
|
|
stream->close = pvr_stream_close;
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
stream->control = pvr_stream_control;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-10 21:32:19 +00:00
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
/* PVR Public API access */
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
#if 0
|
|
|
|
static const char *
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_get_current_stationname (stream_t *stream)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr;
|
|
|
|
|
|
|
|
if (!stream || stream->type != STREAMTYPE_PVR)
|
|
|
|
return NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
if (pvr->stationlist.list &&
|
|
|
|
pvr->stationlist.used > pvr->chan_idx &&
|
|
|
|
pvr->chan_idx >= 0)
|
|
|
|
return pvr->stationlist.list[pvr->chan_idx].station;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
static const char *
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_get_current_channelname (stream_t *stream)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
if (pvr->stationlist.list &&
|
|
|
|
pvr->stationlist.used > pvr->chan_idx &&
|
|
|
|
pvr->chan_idx >= 0)
|
|
|
|
return pvr->stationlist.list[pvr->chan_idx].name;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-06-10 18:12:19 +00:00
|
|
|
#endif
|
2007-05-08 12:20:46 +00:00
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
static int
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_get_current_frequency (stream_t *stream)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
return pvr->freq;
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
static int
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_set_channel (stream_t *stream, const char * channel)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
return set_station_by_channelname_or_freq (pvr, channel, -1, 1);
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
static int
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_set_lastchannel (stream_t *stream)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
if (pvr->stationlist.list &&
|
|
|
|
pvr->stationlist.used > pvr->chan_idx_last &&
|
|
|
|
pvr->chan_idx_last >= 0)
|
|
|
|
return set_station_by_channelname_or_freq (pvr, pvr->stationlist.list[pvr->chan_idx_last].name, -1, 1);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
static int
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_set_freq (stream_t *stream, int freq)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
return set_station_by_channelname_or_freq (pvr, NULL, freq, 1);
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:12:19 +00:00
|
|
|
static int
|
2007-05-08 12:20:46 +00:00
|
|
|
pvr_set_channel_step (stream_t *stream, int step)
|
|
|
|
{
|
|
|
|
struct pvr_t *pvr = (struct pvr_t *) stream->priv;
|
|
|
|
|
|
|
|
return set_station_by_step (pvr, step, 1);
|
|
|
|
}
|
|
|
|
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
static int pvr_stream_control(struct stream *s, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case STREAM_CTRL_SET_TV_FREQ:
|
|
|
|
pvr_set_freq(s, (int)(*(float *)arg + 0.5f));
|
|
|
|
return STREAM_OK;
|
|
|
|
case STREAM_CTRL_GET_TV_FREQ:
|
|
|
|
*(float *)arg = pvr_get_current_frequency(s);
|
|
|
|
return STREAM_OK;
|
|
|
|
case STREAM_CTRL_TV_SET_CHAN:
|
|
|
|
pvr_set_channel(s, (char *)arg);
|
|
|
|
return STREAM_OK;
|
|
|
|
case STREAM_CTRL_TV_STEP_CHAN:
|
|
|
|
pvr_set_channel_step(s, *(int *)arg);
|
|
|
|
return STREAM_OK;
|
|
|
|
case STREAM_CTRL_TV_LAST_CHAN:
|
|
|
|
pvr_set_lastchannel(s);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2007-12-02 13:22:53 +00:00
|
|
|
const stream_info_t stream_info_pvr = {
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 20:49:27 +00:00
|
|
|
.name = "pvr",
|
|
|
|
.open = pvr_stream_open,
|
2014-06-10 21:56:05 +00:00
|
|
|
.protocols = (const char*const[]){ "pvr", NULL },
|
2006-07-10 21:32:19 +00:00
|
|
|
};
|