summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-09 23:54:45 +0200
committerwm4 <wm4@nowhere>2014-06-11 00:34:42 +0200
commit383cf207859485c4516d29053dafab0bb2d8c347 (patch)
tree5eb5775fd1b3cc8b94c679f55defeeea9fb46746 /stream
parent98c0930f9b69122996cc725a08336ee6bd9abc7e (diff)
downloadmpv-383cf207859485c4516d29053dafab0bb2d8c347.tar.bz2
mpv-383cf207859485c4516d29053dafab0bb2d8c347.tar.xz
tv: remove global option variables
Pretty much nothing changes, but using -tv-scan with suboptions doesn't work anymore (instead of "-tv-scan x" it's "-tv scan-x" now). Flat options ("-tv-scan-x") stay compatible.
Diffstat (limited to 'stream')
-rw-r--r--stream/stream_pvr.c69
-rw-r--r--stream/stream_tv.c48
-rw-r--r--stream/tv.c277
-rw-r--r--stream/tv.h22
-rw-r--r--stream/tvi_v4l2.c22
5 files changed, 244 insertions, 194 deletions
diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index c19e9f05cb..9cdf509325 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -45,6 +45,7 @@
#include "osdep/io.h"
#include "common/msg.h"
+#include "options/options.h"
#include "stream.h"
#include "pvr.h"
@@ -110,6 +111,7 @@ typedef struct stationlist_s {
struct pvr_t {
struct mp_log *log;
+ tv_param_t *tv_params;
int dev_fd;
char *video_dev;
@@ -408,12 +410,12 @@ parse_setup_stationlist (struct pvr_t *pvr)
return -1;
/* Create our station/channel list */
- if (stream_tv_defaults.chanlist)
+ if (pvr->tv_params->chanlist)
{
/* select channel list */
for (i = 0; chanlists[i].name != NULL; i++)
{
- if (!strcasecmp (chanlists[i].name, stream_tv_defaults.chanlist))
+ if (!strcasecmp (chanlists[i].name, pvr->tv_params->chanlist))
{
chantab = i;
break;
@@ -422,7 +424,7 @@ parse_setup_stationlist (struct pvr_t *pvr)
if (!chanlists[i].name)
{
MP_ERR(pvr, "%s unable to find channel list %s, using default %s\n",
- LOG_LEVEL_V4L2, stream_tv_defaults.chanlist, chanlists[chantab].name);
+ LOG_LEVEL_V4L2, pvr->tv_params->chanlist, chanlists[chantab].name);
}
else
{
@@ -445,11 +447,11 @@ parse_setup_stationlist (struct pvr_t *pvr)
}
/* Handle user channel mappings */
- if (stream_tv_defaults.channels)
+ if (pvr->tv_params->channels)
{
char channel[PVR_STATION_NAME_SIZE];
char station[PVR_STATION_NAME_SIZE];
- char **channels = stream_tv_defaults.channels;
+ char **channels = pvr->tv_params->channels;
disable_all_stations (pvr);
@@ -1094,59 +1096,59 @@ parse_v4l2_tv_options (struct pvr_t *pvr)
if (set_station_by_channelname_or_freq (pvr, pvr->param_channel,
-1, 0) >= 0)
{
- if (stream_tv_defaults.freq)
+ if (pvr->tv_params->freq)
{
MP_INFO(pvr, "%s tv param freq %s is overwritten by channel setting freq %d\n", LOG_LEVEL_V4L2,
- stream_tv_defaults.freq, pvr->freq);
+ pvr->tv_params->freq, pvr->freq);
}
}
}
- if (pvr->freq < 0 && stream_tv_defaults.freq)
+ if (pvr->freq < 0 && pvr->tv_params->freq)
{
MP_INFO(pvr, "%s tv param freq %s is used directly\n",
- LOG_LEVEL_V4L2, stream_tv_defaults.freq);
+ LOG_LEVEL_V4L2, pvr->tv_params->freq);
if (set_station_by_channelname_or_freq (pvr, NULL,
- atoi (stream_tv_defaults.freq), 0)<0)
+ atoi (pvr->tv_params->freq), 0)<0)
{
MP_WARN(pvr, "%s tv param freq %s invalid to set station\n",
- LOG_LEVEL_V4L2, stream_tv_defaults.freq);
+ LOG_LEVEL_V4L2, pvr->tv_params->freq);
}
}
- if (stream_tv_defaults.device)
+ if (pvr->tv_params->device)
{
free (pvr->video_dev);
- pvr->video_dev = strdup (stream_tv_defaults.device);
+ pvr->video_dev = strdup (pvr->tv_params->device);
}
- if (stream_tv_defaults.noaudio)
- pvr->mute = stream_tv_defaults.noaudio;
+ if (!pvr->tv_params->audio)
+ pvr->mute = !pvr->tv_params->audio;
- if (stream_tv_defaults.input)
- pvr->input = stream_tv_defaults.input;
+ if (pvr->tv_params->input)
+ pvr->input = pvr->tv_params->input;
- if (stream_tv_defaults.normid)
- pvr->normid = stream_tv_defaults.normid;
+ if (pvr->tv_params->normid)
+ pvr->normid = pvr->tv_params->normid;
- if (stream_tv_defaults.brightness)
- pvr->brightness = stream_tv_defaults.brightness;
+ if (pvr->tv_params->brightness)
+ pvr->brightness = pvr->tv_params->brightness;
- if (stream_tv_defaults.contrast)
- pvr->contrast = stream_tv_defaults.contrast;
+ if (pvr->tv_params->contrast)
+ pvr->contrast = pvr->tv_params->contrast;
- if (stream_tv_defaults.hue)
- pvr->hue = stream_tv_defaults.hue;
+ if (pvr->tv_params->hue)
+ pvr->hue = pvr->tv_params->hue;
- if (stream_tv_defaults.saturation)
- pvr->saturation = stream_tv_defaults.saturation;
+ if (pvr->tv_params->saturation)
+ pvr->saturation = pvr->tv_params->saturation;
- if (stream_tv_defaults.width)
- pvr->width = stream_tv_defaults.width;
+ if (pvr->tv_params->width)
+ pvr->width = pvr->tv_params->width;
- if (stream_tv_defaults.height)
- pvr->height = stream_tv_defaults.height;
+ if (pvr->tv_params->height)
+ pvr->height = pvr->tv_params->height;
}
static int
@@ -1519,6 +1521,7 @@ pvr_stream_open (stream_t *stream)
struct pvr_t *pvr = NULL;
pvr = pvr_init ();
+ pvr->tv_params = stream->opts->tv_params;
pvr->log = stream->log;
/**
@@ -1527,8 +1530,8 @@ pvr_stream_open (stream_t *stream)
*/
if (stream->url && strlen (stream->url) > 6 && stream->url[6] != '\0')
pvr->param_channel = strdup (stream->url + 6);
- else if (stream_tv_defaults.channel && strlen (stream_tv_defaults.channel))
- pvr->param_channel = strdup (stream_tv_defaults.channel);
+ else if (pvr->tv_params->channel && strlen (pvr->tv_params->channel))
+ pvr->param_channel = strdup (pvr->tv_params->channel);
parse_v4l2_tv_options (pvr);
parse_encoder_options (pvr);
diff --git a/stream/stream_tv.c b/stream/stream_tv.c
index e54fe4bded..3ca4973d1e 100644
--- a/stream/stream_tv.c
+++ b/stream/stream_tv.c
@@ -32,49 +32,7 @@
#include <stdio.h>
-tv_param_t stream_tv_defaults = {
- NULL, //freq
- NULL, //channel
- "europe-east", //chanlist
- "pal", //norm
- 0, //automute
- -1, //normid
- NULL, //device
- NULL, //driver
- -1, //width
- -1, //height
- 0, //input, used in v4l and bttv
- -1, //outfmt
- -1.0, //fps
- NULL, //channels
- 0, //noaudio;
- 1, //immediate;
- 44100, //audiorate;
- 0, //audio_id
- -1, //amode
- -1, //volume
- -1, //bass
- -1, //treble
- -1, //balance
- -1, //forcechan
- 0, //force_audio
- -1, //buffer_size
- 0, //mjpeg
- 2, //decimation
- 90, //quality
- 0, //alsa
- NULL, //adevice
- 0, //brightness
- 0, //contrast
- 0, //hue
- 0, //saturation
- -1, //gain
- 0, //scan_autostart
- 50, //scan_threshold
- 0.5, //scan_period
-};
-
-#define OPT_BASE_STRUCT tv_param_t
+#define OPT_BASE_STRUCT struct tv_stream_params
static const m_option_t stream_opts_fields[] = {
OPT_STRING("channel", channel, 0),
OPT_INT("input", input, 0),
@@ -102,7 +60,9 @@ const stream_info_t stream_info_tv = {
.open = tv_stream_open,
.protocols = (const char*[]){ "tv", NULL },
.priv_size = sizeof(tv_param_t),
- .priv_defaults = &stream_tv_defaults,
+ .priv_defaults = &(const struct tv_stream_params){
+ .input = -1,
+ },
.options = stream_opts_fields,
.url_options = (const char*[]){
"hostname=channel",
diff --git a/stream/tv.c b/stream/tv.c
index c42a81fde1..1e71c08742 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -31,6 +31,7 @@
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
+#include <assert.h>
#include <libavutil/avstring.h>
#include "config.h"
@@ -38,6 +39,10 @@
#include "common/msg.h"
+#include "options/m_option.h"
+#include "options/m_config.h"
+#include "options/options.h"
+
#include "stream.h"
#include "demux/demux.h"
#include "demux/stheader.h"
@@ -50,10 +55,6 @@
#include "frequencies.h"
-tv_channels_t *tv_channel_list;
-tv_channels_t *tv_channel_current, *tv_channel_last;
-char *tv_channel_last_real;
-
/* enumerating drivers (like in stream.c) */
extern const tvi_info_t tvi_info_dummy;
extern const tvi_info_t tvi_info_v4l2;
@@ -67,6 +68,83 @@ static const tvi_info_t* tvi_driver_list[]={
NULL
};
+#define OPT_BASE_STRUCT tv_param_t
+const struct m_sub_options tv_params_conf = {
+ .opts = (const m_option_t[]) {
+ OPT_FLAG("immediatemode", immediate, 0),
+ OPT_FLAG("audio", audio, 0),
+ OPT_INT("audiorate", audiorate, 0),
+ OPT_STRING("driver", driver, 0),
+ OPT_STRING("device", device, 0),
+ OPT_STRING("freq", freq, 0),
+ OPT_STRING("channel", channel, 0),
+ OPT_STRING("chanlist", chanlist, 0),
+ OPT_STRING("norm", norm, 0),
+ OPT_INTRANGE("automute", automute, 0, 0, 255),
+#if HAVE_TV_V4L2
+ OPT_INT("normid", normid, 0),
+#endif
+ OPT_INTRANGE("width", width, 0, 0, 4096),
+ OPT_INTRANGE("height", height, 0, 0, 4096),
+ OPT_INT("input", input, 0),
+ OPT_GENERAL(int, "outfmt", outfmt, 0, .type = &m_option_type_fourcc),
+ OPT_FLOAT("fps", fps, 0),
+ OPT_STRINGLIST("channels", channels, 0),
+ OPT_INTRANGE("brightness", brightness, 0, -100, 100),
+ OPT_INTRANGE("contrast", contrast, 0, -100, 100),
+ OPT_INTRANGE("hue", hue, 0, -100, 100),
+ OPT_INTRANGE("saturation", saturation, 0, -100, 100),
+ OPT_INTRANGE("gain", gain, 0, -1, 100),
+#if HAVE_TV_V4L2
+ OPT_INTRANGE("amode", amode, 0, 0, 3),
+ OPT_INTRANGE("volume", volume, 0, 0, 65535),
+ OPT_INTRANGE("bass", bass, 0, 0, 65535),
+ OPT_INTRANGE("treble", treble, 0, 0, 65535),
+ OPT_INTRANGE("balance", balance, 0, 0, 65535),
+ OPT_INTRANGE("forcechan", forcechan, 0, 1, 2),
+ OPT_FLAG("forceaudio", force_audio, 0),
+ OPT_INTRANGE("buffersize", buffer_size, 0, 16, 1024),
+ OPT_FLAG("mjpeg", mjpeg, 0),
+ OPT_INTRANGE("decimation", decimation, 0, 1, 4),
+ OPT_INTRANGE("quality", quality, 0, 0, 100),
+#if HAVE_ALSA
+ OPT_FLAG("alsa", alsa, 0),
+#endif /* HAVE_ALSA */
+#endif /* HAVE_TV_V4L2 */
+ OPT_STRING("adevice", adevice, 0),
+ OPT_INTRANGE("audioid", audio_id, 0, 0, 9),
+ OPT_FLAG("scan-autostart", scan, 0),
+ OPT_INTRANGE("scan-threshold", scan_threshold, 0, 1, 100),
+ OPT_FLOATRANGE("scan-period", scan_period, 0, 0.1, 2.0),
+ {0}
+ },
+ .size = sizeof(tv_param_t),
+ .defaults = &(const tv_param_t){
+ .chanlist = "europe-east",
+ .norm = "pal",
+ .normid = -1,
+ .width = -1,
+ .height = -1,
+ .outfmt = -1,
+ .fps = -1.0,
+ .audio = 1,
+ .immediate = 1,
+ .audiorate = 44100,
+ .amode = -1,
+ .volume = -1,
+ .bass = -1,
+ .treble = -1,
+ .balance = -1,
+ .forcechan = -1,
+ .buffer_size = -1,
+ .decimation = 2,
+ .quality = 90,
+ .gain = -1,
+ .scan_threshold = 50,
+ .scan_period = 0.5,
+ },
+};
+
tvi_handle_t *tv_new_handle(int size, struct mp_log *log, const tvi_functions_t *functions)
{
tvi_handle_t *h = malloc(sizeof(*h));
@@ -144,7 +222,7 @@ static void tv_scan(tvi_handle_t *tvh)
if (tv_get_signal(tvh)>tvh->tv_param->scan_threshold) {
cl = tvh->chanlist_s[scan->channel_num];
- tv_channel_tmp=tv_channel_list;
+ tv_channel_tmp=tvh->tv_channel_list;
while (tv_channel_tmp) {
index++;
if (cl.freq==tv_channel_tmp->freq){
@@ -165,11 +243,11 @@ static void tv_scan(tvi_handle_t *tvh)
snprintf(tv_channel_tmp->name,sizeof(tv_channel_tmp->name),"ch%d",index);
strncpy(tv_channel_tmp->number, cl.name, 5);
tv_channel_tmp->number[4]='\0';
- if (!tv_channel_list)
- tv_channel_list=tv_channel_tmp;
+ if (!tvh->tv_channel_list)
+ tvh->tv_channel_list=tv_channel_tmp;
else {
tv_channel_add->next=tv_channel_tmp;
- tv_channel_list->prev=tv_channel_tmp;
+ tvh->tv_channel_list->prev=tv_channel_tmp;
}
}else
MP_INFO(tvh, "Found existing channel: %s-%s.\n",
@@ -180,7 +258,7 @@ static void tv_scan(tvi_handle_t *tvh)
if (scan->channel_num>=chanlists[tvh->chanlist].count) {
tvh->tv_param->scan=0;
MP_INFO(tvh, "TV scan end. Found %d new channels.\n", scan->new_channels);
- tv_channel_tmp=tv_channel_list;
+ tv_channel_tmp=tvh->tv_channel_list;
if(tv_channel_tmp){
MP_INFO(tvh, "channels=");
while(tv_channel_tmp){
@@ -191,9 +269,9 @@ static void tv_scan(tvi_handle_t *tvh)
}
MP_INFO(tvh, "\n");
}
- if (!tv_channel_current) tv_channel_current=tv_channel_list;
- if (tv_channel_current)
- tv_set_freq_float(tvh, tv_channel_current->freq);
+ if (!tvh->tv_channel_current) tvh->tv_channel_current=tvh->tv_channel_list;
+ if (tvh->tv_channel_current)
+ tv_set_freq_float(tvh, tvh->tv_channel_current->freq);
free(tvh->scan);
tvh->scan=NULL;
}else{
@@ -232,7 +310,7 @@ static int demux_tv_fill_buffer(demuxer_t *demux)
/* ================== ADD AUDIO PACKET =================== */
- if (want_audio && tvh->tv_param->noaudio == 0 &&
+ if (want_audio && tvh->tv_param->audio &&
tvh->functions->control(tvh->priv,
TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
{
@@ -306,12 +384,12 @@ static void parse_channels(tvi_handle_t *tvh)
char** channels = tvh->tv_param->channels;
MP_INFO(tvh, "TV channel names detected.\n");
- tv_channel_list = malloc(sizeof(tv_channels_t));
- tv_channel_list->index=1;
- tv_channel_list->next=NULL;
- tv_channel_list->prev=NULL;
- tv_channel_current = tv_channel_list;
- tv_channel_current->norm = tvh->norm;
+ tvh->tv_channel_list = malloc(sizeof(tv_channels_t));
+ tvh->tv_channel_list->index=1;
+ tvh->tv_channel_list->next=NULL;
+ tvh->tv_channel_list->prev=NULL;
+ tvh->tv_channel_current = tvh->tv_channel_list;
+ tvh->tv_channel_current->norm = tvh->norm;
while (*channels) {
char* tmp = *(channels++);
@@ -321,64 +399,64 @@ static void parse_channels(tvi_handle_t *tvh)
if (!sep) continue; // Wrong syntax, but mplayer should not crash
- av_strlcpy(tv_channel_current->name, sep + 1,
- sizeof(tv_channel_current->name));
+ av_strlcpy(tvh->tv_channel_current->name, sep + 1,
+ sizeof(tvh->tv_channel_current->name));
sep[0] = '\0';
- strncpy(tv_channel_current->number, tmp, 5);
- tv_channel_current->number[4]='\0';
+ strncpy(tvh->tv_channel_current->number, tmp, 5);
+ tvh->tv_channel_current->number[4]='\0';
- while ((sep=strchr(tv_channel_current->name, '_')))
+ while ((sep=strchr(tvh->tv_channel_current->name, '_')))
sep[0] = ' ';
// if channel number is a number and larger than 1000 threat it as frequency
// tmp still contain pointer to null-terminated string with channel number here
if (atoi(tmp)>1000){
- tv_channel_current->freq=atoi(tmp);
+ tvh->tv_channel_current->freq=atoi(tmp);
}else{
- tv_channel_current->freq = 0;
+ tvh->tv_channel_current->freq = 0;
for (i = 0; i < chanlists[tvh->chanlist].count; i++) {
cl = tvh->chanlist_s[i];
- if (!strcasecmp(cl.name, tv_channel_current->number)) {
- tv_channel_current->freq=cl.freq;
+ if (!strcasecmp(cl.name, tvh->tv_channel_current->number)) {
+ tvh->tv_channel_current->freq=cl.freq;
break;
}
}
}
- if (tv_channel_current->freq == 0)
+ if (tvh->tv_channel_current->freq == 0)
MP_ERR(tvh, "Couldn't find frequency for channel %s (%s)\n",
- tv_channel_current->number, tv_channel_current->name);
+ tvh->tv_channel_current->number, tvh->tv_channel_current->name);
else {
- sep = strchr(tv_channel_current->name, '-');
- if ( !sep ) sep = strchr(tv_channel_current->name, '+');
+ sep = strchr(tvh->tv_channel_current->name, '-');
+ if ( !sep ) sep = strchr(tvh->tv_channel_current->name, '+');
if ( sep ) {
i = atoi (sep+1);
- if ( sep[0] == '+' ) tv_channel_current->freq += i * 100;
- if ( sep[0] == '-' ) tv_channel_current->freq -= i * 100;
+ if ( sep[0] == '+' ) tvh->tv_channel_current->freq += i * 100;
+ if ( sep[0] == '-' ) tvh->tv_channel_current->freq -= i * 100;
sep[0] = '\0';
}
- sep = strchr(tv_channel_current->name, '=');
+ sep = strchr(tvh->tv_channel_current->name, '=');
if ( sep ) {
- tv_channel_current->norm = norm_from_string(tvh, sep+1);
+ tvh->tv_channel_current->norm = norm_from_string(tvh, sep+1);
sep[0] = '\0';
}
}
/*MP_INFO(tvh, "-- Detected channel %s - %s (%5.3f)\n",
- tv_channel_current->number, tv_channel_current->name,
- (float)tv_channel_current->freq/1000);*/
-
- tv_channel_current->next = malloc(sizeof(tv_channels_t));
- tv_channel_current->next->index = tv_channel_current->index + 1;
- tv_channel_current->next->prev = tv_channel_current;
- tv_channel_current->next->next = NULL;
- tv_channel_current = tv_channel_current->next;
- tv_channel_current->norm = tvh->norm;
+ tvh->tv_channel_current->number, tvh->tv_channel_current->name,
+ (float)tvh->tv_channel_current->freq/1000);*/
+
+ tvh->tv_channel_current->next = malloc(sizeof(tv_channels_t));
+ tvh->tv_channel_current->next->index = tvh->tv_channel_current->index + 1;
+ tvh->tv_channel_current->next->prev = tvh->tv_channel_current;
+ tvh->tv_channel_current->next->next = NULL;
+ tvh->tv_channel_current = tvh->tv_channel_current->next;
+ tvh->tv_channel_current->norm = tvh->norm;
}
- if (tv_channel_current->prev)
- tv_channel_current->prev->next = NULL;
- free(tv_channel_current);
+ if (tvh->tv_channel_current->prev)
+ tvh->tv_channel_current->prev->next = NULL;
+ free(tvh->tv_channel_current);
}
int tv_set_norm(tvi_handle_t *tvh, char* norm)
@@ -544,9 +622,9 @@ static int open_tv(tvi_handle_t *tvh)
if (tvh->tv_param->channels) {
parse_channels(tvh);
} else
- tv_channel_last_real = malloc(5);
+ tvh->tv_channel_last_real = malloc(5);
- if (tv_channel_list) {
+ if (tvh->tv_channel_list) {
int channel = 0;
if (tvh->tv_param->channel)
{
@@ -558,27 +636,27 @@ static int open_tv(tvi_handle_t *tvh)
/* if tvh->tv_param->channel does not begin with a digit
set the first channel that contains tvh->tv_param->channel in its name */
- tv_channel_current = tv_channel_list;
- while ( tv_channel_current ) {
- if ( strstr(tv_channel_current->name, tvh->tv_param->channel) )
+ tvh->tv_channel_current = tvh->tv_channel_list;
+ while ( tvh->tv_channel_current ) {
+ if ( strstr(tvh->tv_channel_current->name, tvh->tv_param->channel) )
break;
- tv_channel_current = tv_channel_current->next;
+ tvh->tv_channel_current = tvh->tv_channel_current->next;
}
- if ( !tv_channel_current ) tv_channel_current = tv_channel_list;
+ if ( !tvh->tv_channel_current ) tvh->tv_channel_current = tvh->tv_channel_list;
}
}
else
channel = 1;
if ( channel ) {
- tv_channel_current = tv_channel_list;
+ tvh->tv_channel_current = tvh->tv_channel_list;
for (int n = 1; n < channel; n++)
- if (tv_channel_current->next)
- tv_channel_current = tv_channel_current->next;
+ if (tvh->tv_channel_current->next)
+ tvh->tv_channel_current = tvh->tv_channel_current->next;
}
- set_norm_and_freq(tvh, tv_channel_current);
- tv_channel_last = tv_channel_current;
+ set_norm_and_freq(tvh, tvh->tv_channel_current);
+ tvh->tv_channel_last = tvh->tv_channel_current;
} else {
/* we need to set frequency */
if (tvh->tv_param->freq)
@@ -604,7 +682,7 @@ static int open_tv(tvi_handle_t *tvh)
// i, cl.name, cl.freq);
if (!strcasecmp(cl.name, tvh->tv_param->channel))
{
- strcpy(tv_channel_last_real, cl.name);
+ strcpy(tvh->tv_channel_last_real, cl.name);
tvh->channel = i;
MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n",
cl.name, cl.freq/1000.0);
@@ -669,7 +747,8 @@ static tvi_handle_t *tv_begin(tv_param_t* tv_param, struct mp_log *log)
tvi_driver_list[i]->name,
tvi_driver_list[i]->author,
tvi_driver_list[i]->comment?tvi_driver_list[i]->comment:"");
- tv_param->driver=strdup(tvi_driver_list[i]->short_name);
+ talloc_free(tv_param->driver);
+ tv_param->driver=talloc_strdup(NULL, tvi_driver_list[i]->short_name);
return h;
}
}
@@ -704,8 +783,18 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
if (check > DEMUX_CHECK_REQUEST || demuxer->stream->type != STREAMTYPE_TV)
return -1;
- demuxer->priv=NULL;
- if(!(tvh=tv_begin(demuxer->stream->priv, demuxer->log))) return -1;
+ tv_param_t *params = m_sub_options_copy(demuxer, &tv_params_conf,
+ demuxer->opts->tv_params);
+ struct tv_stream_params *sparams = demuxer->stream->priv;
+ if (sparams->channel && sparams->channel[0]) {
+ talloc_free(params->channel);
+ params->channel = talloc_strdup(NULL, sparams->channel);
+ }
+ if (sparams->input >= 0)
+ params->input = sparams->input;
+
+ assert(demuxer->priv==NULL);
+ if(!(tvh=tv_begin(params, demuxer->log))) return -1;
if (!tvh->functions->init(tvh->priv)) return -1;
tvh->demuxer = demuxer;
@@ -747,7 +836,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
if(tvh->tv_param->immediate == 1)
{
funcs->control(tvh->priv, TVI_CONTROL_IMMEDIATE, 0);
- tvh->tv_param->noaudio = 1;
+ tvh->tv_param->audio = 0;
}
/* set width */
@@ -759,7 +848,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
demuxer->seekable = 0;
/* here comes audio init */
- if (tvh->tv_param->noaudio == 0 && funcs->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
+ if (tvh->tv_param->audio && funcs->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
{
int audio_format;
@@ -955,7 +1044,7 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction)
{
if (tvh->channel-1 >= 0)
{
- strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
+ strcpy(tvh->tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
cl = tvh->chanlist_s[--tvh->channel];
MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n",
cl.name, cl.freq/1000.0);
@@ -967,7 +1056,7 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction)
{
if (tvh->channel+1 < chanlists[tvh->chanlist].count)
{
- strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
+ strcpy(tvh->tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
cl = tvh->chanlist_s[++tvh->channel];
MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n",
cl.name, cl.freq/1000.0);
@@ -979,23 +1068,23 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction)
int tv_step_channel(tvi_handle_t *tvh, int direction) {
tvh->tv_param->scan=0;
- if (tv_channel_list) {
+ if (tvh->tv_channel_list) {
if (direction == TV_CHANNEL_HIGHER) {
- tv_channel_last = tv_channel_current;
- if (tv_channel_current->next)
- tv_channel_current = tv_channel_current->next;
+ tvh->tv_channel_last = tvh->tv_channel_current;
+ if (tvh->tv_channel_current->next)
+ tvh->tv_channel_current = tvh->tv_channel_current->next;
else
- tv_channel_current = tv_channel_list;
- set_norm_and_freq(tvh, tv_channel_current);
+ tvh->tv_channel_current = tvh->tv_channel_list;
+ set_norm_and_freq(tvh, tvh->tv_channel_current);
}
if (direction == TV_CHANNEL_LOWER) {
- tv_channel_last = tv_channel_current;
- if (tv_channel_current->prev)
- tv_channel_current = tv_channel_current->prev;
+ tvh->tv_channel_last = tvh->tv_channel_current;
+ if (tvh->tv_channel_current->prev)
+ tvh->tv_channel_current = tvh->tv_channel_current->prev;
else
- while (tv_channel_current->next)
- tv_channel_current = tv_channel_current->next;
- set_norm_and_freq(tvh, tv_channel_current);
+ while (tvh->tv_channel_current->next)
+ tvh->tv_channel_current = tvh->tv_channel_current->next;
+ set_norm_and_freq(tvh, tvh->tv_channel_current);
}
} else tv_step_channel_real(tvh, direction);
return 1;
@@ -1006,7 +1095,7 @@ int tv_set_channel_real(tvi_handle_t *tvh, char *channel) {
struct CHANLIST cl;
tvh->tv_param->scan=0;
- strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
+ strcpy(tvh->tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
for (i = 0; i < chanlists[tvh->chanlist].count; i++)
{
cl = tvh->chanlist_s[i];
@@ -1028,14 +1117,14 @@ int tv_set_channel(tvi_handle_t *tvh, char *channel) {
int i, channel_int;
tvh->tv_param->scan=0;
- if (tv_channel_list) {
- tv_channel_last = tv_channel_current;
+ if (tvh->tv_channel_list) {
+ tvh->tv_channel_last = tvh->tv_channel_current;
channel_int = atoi(channel);
- tv_channel_current = tv_channel_list;
+ tvh->tv_channel_current = tvh->tv_channel_list;
for (i = 1; i < channel_int; i++)
- if (tv_channel_current->next)
- tv_channel_current = tv_channel_current->next;
- set_norm_and_freq(tvh, tv_channel_current);
+ if (tvh->tv_channel_current->next)
+ tvh->tv_channel_current = tvh->tv_channel_current->next;
+ set_norm_and_freq(tvh, tvh->tv_channel_current);
} else tv_set_channel_real(tvh, channel);
return 1;
}
@@ -1043,14 +1132,14 @@ int tv_set_channel(tvi_handle_t *tvh, char *channel) {
int tv_last_channel(tvi_handle_t *tvh) {
tvh->tv_param->scan=0;
- if (tv_channel_list) {
+ if (tvh->tv_channel_list) {
tv_channels_t *tmp;
- tmp = tv_channel_last;
- tv_channel_last = tv_channel_current;
- tv_channel_current = tmp;
+ tmp = tvh->tv_channel_last;
+ tvh->tv_channel_last = tvh->tv_channel_current;
+ tvh->tv_channel_current = tmp;
- set_norm_and_freq(tvh, tv_channel_current);
+ set_norm_and_freq(tvh, tvh->tv_channel_current);
} else {
int i;
struct CHANLIST cl;
@@ -1058,9 +1147,9 @@ int tv_last_channel(tvi_handle_t *tvh) {
for (i = 0; i < chanlists[tvh->chanlist].count; i++)
{
cl = tvh->chanlist_s[i];
- if (!strcasecmp(cl.name, tv_channel_last_real))
+ if (!strcasecmp(cl.name, tvh->tv_channel_last_real))
{
- strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
+ strcpy(tvh->tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
tvh->channel = i;
MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n",
cl.name, cl.freq/1000.0);
diff --git a/stream/tv.h b/stream/tv.h
index c5e8aba91f..74363ae846 100644
--- a/stream/tv.h
+++ b/stream/tv.h
@@ -27,7 +27,7 @@
struct mp_log;
-typedef struct tv_param_s {
+typedef struct tv_params {
char *freq;
char *channel;
char *chanlist;
@@ -42,7 +42,7 @@ typedef struct tv_param_s {
int outfmt;
float fps;
char **channels;
- int noaudio;
+ int audio;
int immediate;
int audiorate;
int audio_id;
@@ -68,14 +68,12 @@ typedef struct tv_param_s {
int scan;
int scan_threshold;
float scan_period;
- /**
- Terminate stream with video renderer instead of Null renderer
- Will help if video freezes but audio does not.
- May not work with -vo directx and -vf crop combination.
- */
} tv_param_t;
-extern tv_param_t stream_tv_defaults;
+struct tv_stream_params {
+ char *channel;
+ int input;
+};
typedef struct tvi_info_s
{
@@ -115,6 +113,10 @@ typedef struct tvi_handle_s {
int channel;
tv_param_t * tv_param;
void * scan;
+
+ struct tv_channels_s *tv_channel_list;
+ struct tv_channels_s *tv_channel_current, *tv_channel_last;
+ char *tv_channel_last_real;
} tvi_handle_t;
typedef struct tv_channels_s {
@@ -127,10 +129,6 @@ typedef struct tv_channels_s {
struct tv_channels_s *prev;
} tv_channels_t;
-extern tv_channels_t *tv_channel_list;
-extern tv_channels_t *tv_channel_current, *tv_channel_last;
-extern char *tv_channel_last_real;
-
typedef struct {
unsigned int scan_timer;
int channel_num;
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index 4aafbed557..04725bfca1 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -401,7 +401,7 @@ static void init_audio(priv_t *priv)
{
if (priv->audio_initialized) return;
- if (!priv->tv_param->noaudio) {
+ if (priv->tv_param->audio) {
#if HAVE_ALSA
if (priv->tv_param->alsa)
audio_in_init(&priv->audio_in, priv->log, AUDIO_IN_ALSA);
@@ -995,7 +995,7 @@ static int uninit(priv_t *priv)
}
/* stop audio thread */
- if (!priv->tv_param->noaudio && priv->audio_grabber_thread) {
+ if (priv->tv_param->audio && priv->audio_grabber_thread) {
pthread_join(priv->audio_grabber_thread, NULL);
pthread_mutex_destroy(&priv->skew_mutex);
pthread_mutex_destroy(&priv->audio_mutex);
@@ -1015,7 +1015,7 @@ static int uninit(priv_t *priv)
}
free(priv->video_ringbuffer);
}
- if (!priv->tv_param->noaudio) {
+ if (priv->tv_param->audio) {
free(priv->audio_ringbuffer);
free(priv->audio_skew_buffer);
free(priv->audio_skew_delta_buffer);
@@ -1245,7 +1245,7 @@ static int start(priv_t *priv)
/* setup audio parameters */
init_audio(priv);
- if (!priv->tv_param->noaudio && !priv->audio_initialized) return 0;
+ if (priv->tv_param->audio && !priv->audio_initialized) return 0;
/* we need this to size the audio buffer properly */
if (priv->immediate_mode) {
@@ -1254,7 +1254,7 @@ static int start(priv_t *priv)
priv->video_buffer_size_max = get_capture_buffer_size(priv);
}
- if (!priv->tv_param->noaudio) {
+ if (priv->tv_param->audio) {
setup_audio_buffer_sizes(priv);
priv->audio_skew_buffer = calloc(priv->aud_skew_cnt, sizeof(long long));
if (!priv->audio_skew_buffer) {
@@ -1296,7 +1296,7 @@ static int start(priv_t *priv)
}
/* setup video parameters */
- if (!priv->tv_param->noaudio) {
+ if (priv->tv_param->audio) {
if (priv->video_buffer_size_max < 3*getfps(priv)*priv->audio_secs_per_block) {
MP_ERR(priv, "Video buffer shorter than 3 times audio frame duration.\n"
"You will probably experience heavy framedrops.\n");
@@ -1433,7 +1433,7 @@ static void *video_grabber(void *data)
}
priv->streamon = 1;
- if (!priv->tv_param->noaudio) {
+ if (priv->tv_param->audio) {
pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv);
}
@@ -1510,9 +1510,9 @@ static void *video_grabber(void *data)
/* store