Remove classic Linux analog TV support, and DVB runtime controls

Linux analog TV support (via tv://) was excessively complex, and
whenever I attempted to use it (cameras or loopback devices), it didn't
work well, or would have required some major work to update it. It's
very much stuck in the analog past (my favorite are the frequency tables
in frequencies.c for analog TV channels which don't exist anymore).

Especially cameras and such work fine with libavdevice and better than
tv://, for example:

  mpv av://v4l2:/dev/video0

(adding --profile=low-latency --untimed even makes it mostly realtime)

Adding a new input layer that targets such "modern" uses would be
acceptable, if anyone is interested in it. The old TV code is just too
focused on actual analog TV.

DVB is rather obscure, but has an active maintainer, so don't remove it.
However, the demux/stream ctrl layer must go, so remove controls for
channel switching. Most of these could be reimplemented by using the
normal method for option runtime changes.
This commit is contained in:
wm4 2019-09-13 17:16:18 +02:00
parent 162e0f5ad9
commit b30e85508a
27 changed files with 13 additions and 6236 deletions

View File

@ -82,6 +82,8 @@ Interface changes
with the move to libplacebo as the back-end for vulkan rendering.
- Remove "disc-titles", "disc-title", "disc-title-list", and "angle"
properties. dvd:// does not support title ranges anymore.
- Remove all "tv-..." options and properties, along with the classic Linux
analog TV support.
--- mpv 0.29.0 ---
- drop --opensles-sample-rate, as --audio-samplerate should be used if desired
- drop deprecated --videotoolbox-format, --ff-aid, --ff-vid, --ff-sid,

View File

@ -921,8 +921,7 @@ Input Commands that are Possibly Subject to Change
``--glsl-shader=file.glsl``.
Undocumented commands: ``tv-last-channel`` (TV/DVB only),
``ao-reload`` (experimental/internal).
Undocumented commands: ``ao-reload`` (experimental/internal).
Hooks
~~~~~
@ -1815,15 +1814,6 @@ Property list
``program`` (W)
Switch TS program (write-only).
``dvb-channel`` (W)
Pair of integers: card,channel of current DVB stream.
Can be switched to switch to another channel on the same card.
``dvb-channel-name`` (RW)
Name of current DVB program.
On write, a channel-switch to the named channel on the same
card is performed. Can also be used for channel switching.
``sub-text``
Return the current subtitle text. Formatting is stripped. If a subtitle
is selected, but no text is currently visible, or the subtitle is not
@ -1831,9 +1821,6 @@ Property list
This property is experimental and might be removed in the future.
``tv-brightness``, ``tv-contrast``, ``tv-saturation``, ``tv-hue`` (RW)
TV stuff.
``playlist-pos`` (RW)
Current position on playlist. The first entry is on position 0. Writing
to the property will restart playback at the written entry.

View File

@ -3657,191 +3657,6 @@ Terminal
``--msg-time``
Prepend timing information to each console message.
TV
--
``--tv-...``
These options tune various properties of the TV capture module. For
watching TV with mpv, use ``tv://`` or ``tv://<channel_number>`` or
even ``tv://<channel_name>`` (see option ``tv-channels`` for ``channel_name``
below) as a media URL. You can also use ``tv:///<input_id>`` to start
watching a video from a composite or S-Video input (see option ``input`` for
details).
``--tv-device=<value>``
Specify TV device (default: ``/dev/video0``).
``--tv-channel=<value>``
Set tuner to <value> channel.
``--no-tv-audio``
no sound
``--tv-automute=<0-255> (v4l and v4l2 only)``
If signal strength reported by device is less than this value, audio
and video will be muted. In most cases automute=100 will be enough.
Default is 0 (automute disabled).
``--tv-driver=<value>``
See ``--tv=driver=help`` for a list of compiled-in TV input drivers.
available: dummy, v4l2 (default: autodetect)
``--tv-input=<value>``
Specify input (default: 0 (TV), see console output for available
inputs).
``--tv-freq=<value>``
Specify the frequency to set the tuner to (e.g. 511.250). Not
compatible with the channels parameter.
``--tv-outfmt=<value>``
Specify the output format of the tuner with a preset value supported
by the V4L driver (YV12, UYVY, YUY2, I420) or an arbitrary format given
as hex value.
``--tv-width=<value>``
output window width
``--tv-height=<value>``
output window height
``--tv-fps=<value>``
framerate at which to capture video (frames per second)
``--tv-buffersize=<value>``
maximum size of the capture buffer in megabytes (default: dynamical)
``--tv-norm=<value>``
See the console output for a list of all available norms.
See also: ``--tv-normid``.
``--tv-normid=<value> (v4l2 only)``
Sets the TV norm to the given numeric ID. The TV norm depends on the
capture card. See the console output for a list of available TV norms.
``--tv-chanlist=<value>``
available: argentina, australia, china-bcast, europe-east,
europe-west, france, ireland, italy, japan-bcast, japan-cable,
newzealand, russia, southafrica, us-bcast, us-cable, us-cable-hrc
``--tv-channels=<chan>-<name>[=<norm>],<chan>-<name>[=<norm>],...``
Set names for channels.
.. note::
If <chan> is an integer greater than 1000, it will be treated as
frequency (in kHz) rather than channel name from frequency table.
Use _ for spaces in names (or play with quoting ;-) ). The channel
names will then be written using OSD, and the input commands
``tv_step_channel``, ``tv_set_channel`` and ``tv_last_channel``
will be usable for a remote control. Not compatible with
the ``frequency`` parameter.
.. note::
The channel number will then be the position in the 'channels'
list, beginning with 1.
.. admonition:: Examples
``tv://1``, ``tv://TV1``, ``tv_set_channel 1``,
``tv_set_channel TV1``
``--tv-[brightness|contrast|hue|saturation]=<-100-100>``
Set the image equalizer on the card.
``--tv-audiorate=<value>``
Set input audio sample rate.
``--tv-forceaudio``
Capture audio even if there are no audio sources reported by v4l.
``--tv-alsa``
Capture from ALSA.
``--tv-amode=<0-3>``
Choose an audio mode:
:0: mono
:1: stereo
:2: language 1
:3: language 2
``--tv-forcechan=<1-2>``
By default, the count of recorded audio channels is determined
automatically by querying the audio mode from the TV card. This option
allows forcing stereo/mono recording regardless of the amode option
and the values returned by v4l. This can be used for troubleshooting
when the TV card is unable to report the current audio mode.
``--tv-adevice=<value>``
Set an audio device. <value> should be ``/dev/xxx`` for OSS and a
hardware ID for ALSA. You must replace any ':' by a '.' in the
hardware ID for ALSA.
``--tv-audioid=<value>``
Choose an audio output of the capture card, if it has more than one.
``--tv-[volume|bass|treble|balance]=<0-100>``
These options set parameters of the mixer on the video capture card.
They will have no effect, if your card does not have one. For v4l2 50
maps to the default value of the control, as reported by the driver.
``--tv-gain=<0-100>``
Set gain control for video devices (usually webcams) to the desired
value and switch off automatic control. A value of 0 enables automatic
control. If this option is omitted, gain control will not be modified.
``--tv-immediatemode=<bool>``
A value of 0 means capture and buffer audio and video together. A
value of 1 (default) means to do video capture only and let the audio
go through a loopback cable from the TV card to the sound card.
``--tv-mjpeg``
Use hardware MJPEG compression (if the card supports it). When using
this option, you do not need to specify the width and height of the
output window, because mpv will determine it automatically from
the decimation value (see below).
``--tv-decimation=<1|2|4>``
choose the size of the picture that will be compressed by hardware
MJPEG compression:
:1: full size
- 704x576 PAL
- 704x480 NTSC
:2: medium size
- 352x288 PAL
- 352x240 NTSC
:4: small size
- 176x144 PAL
- 176x120 NTSC
``--tv-quality=<0-100>``
Choose the quality of the JPEG compression (< 60 recommended for full
size).
``--tv-scan-autostart``
Begin channel scanning immediately after startup (default: disabled).
``--tv-scan-period=<0.1-2.0>``
Specify delay in seconds before switching to next channel (default:
0.5). Lower values will cause faster scanning, but can detect inactive
TV channels as active.
``--tv-scan-threshold=<1-100>``
Threshold value for the signal strength (in percent), as reported by
the device (default: 50). A signal strength higher than this value will
indicate that the currently scanning channel is active.
Cache
-----

View File

@ -52,7 +52,6 @@ extern const struct demuxer_desc demuxer_desc_edl;
extern const struct demuxer_desc demuxer_desc_cue;
extern const demuxer_desc_t demuxer_desc_rawaudio;
extern const demuxer_desc_t demuxer_desc_rawvideo;
extern const demuxer_desc_t demuxer_desc_tv;
extern const demuxer_desc_t demuxer_desc_mf;
extern const demuxer_desc_t demuxer_desc_matroska;
extern const demuxer_desc_t demuxer_desc_lavf;
@ -71,9 +70,6 @@ const demuxer_desc_t *const demuxer_list[] = {
&demuxer_desc_cue,
&demuxer_desc_rawaudio,
&demuxer_desc_rawvideo,
#if HAVE_TV
&demuxer_desc_tv,
#endif
&demuxer_desc_matroska,
#if HAVE_LIBARCHIVE
&demuxer_desc_libarchive,

View File

@ -202,7 +202,6 @@ typedef struct demuxer {
bool fully_read;
bool is_network; // opened directly from a network stream
bool access_references; // allow opening other files/URLs
bool extended_ctrls; // supports some of BD/DVD/DVB/TV controls
// Bitmask of DEMUX_EVENT_*
int events;

View File

@ -1,267 +0,0 @@
/*
* Copyright (C) 2001 Alex Beregszaszi
*
* Feb 19, 2002: Significant rewrites by Charles R. Henrich (henrich@msu.edu)
* to add support for audio, and bktr *BSD support.
*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include "common/common.h"
#include "common/msg.h"
#include "options/m_option.h"
#include "options/m_config.h"
#include "options/options.h"
#include "demux.h"
#include "codec_tags.h"
#include "audio/format.h"
#include "osdep/endian.h"
#include "stream/stream.h"
#include "stream/tv.h"
static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
{
tvi_handle_t *tvh;
const tvi_functions_t *funcs;
if (check > DEMUX_CHECK_REQUEST)
return -1;
if (!demuxer->stream->info || strcmp(demuxer->stream->info->name, "tv") != 0)
return -1;
tv_param_t *params = mp_get_config_group(demuxer, demuxer->global,
&tv_params_conf);
bstr urlparams = bstr0(demuxer->stream->path);
bstr channel, input;
bstr_split_tok(urlparams, "/", &channel, &input);
if (channel.len) {
talloc_free(params->channel);
params->channel = bstrto0(NULL, channel);
}
if (input.len) {
bstr r;
params->input = bstrtoll(input, &r, 0);
if (r.len) {
MP_ERR(demuxer->stream, "invalid input: '%.*s'\n", BSTR_P(input));
return -1;
}
}
assert(demuxer->priv==NULL);
if(!(tvh=tv_begin(params, demuxer->log))) return -1;
if (!tvh->functions->init(tvh->priv)) return -1;
tvh->demuxer = demuxer;
if (!open_tv(tvh)){
tv_uninit(tvh);
return -1;
}
funcs = tvh->functions;
demuxer->priv=tvh;
struct sh_stream *sh_v = demux_alloc_sh_stream(STREAM_VIDEO);
/* get IMAGE FORMAT */
int fourcc;
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc);
if (fourcc == MP_FOURCC_MJPEG || fourcc == MP_FOURCC_JPEG) {
sh_v->codec->codec = "mjpeg";
} else {
sh_v->codec->codec = "rawvideo";
sh_v->codec->codec_tag = fourcc;
}
/* set FPS and FRAMETIME */
if(!sh_v->codec->fps)
{
float tmp;
if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &tmp) != TVI_CONTROL_TRUE)
sh_v->codec->fps = 25.0f; /* on PAL */
else sh_v->codec->fps = tmp;
}
if (tvh->tv_param->fps != -1.0f)
sh_v->codec->fps = tvh->tv_param->fps;
/* If playback only mode, go to immediate mode, fail silently */
if(tvh->tv_param->immediate == 1)
{
funcs->control(tvh->priv, TVI_CONTROL_IMMEDIATE, 0);
tvh->tv_param->audio = 0;
}
/* set width */
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_v->codec->disp_w);
/* set height */
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_v->codec->disp_h);
demux_add_sh_stream(demuxer, sh_v);
demuxer->seekable = 0;
/* here comes audio init */
if (tvh->tv_param->audio && funcs->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
{
int audio_format;
/* yeah, audio is present */
funcs->control(tvh->priv, TVI_CONTROL_AUD_SET_SAMPLERATE,
&tvh->tv_param->audiorate);
if (funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_FORMAT, &audio_format) != TVI_CONTROL_TRUE)
goto no_audio;
switch(audio_format)
{
// This is the only format any of the current inputs generate.
case AF_FORMAT_S16:
break;
default:
MP_ERR(tvh, "Audio type '%s' unsupported!\n",
af_fmt_to_str(audio_format));
goto no_audio;
}
struct sh_stream *sh_a = demux_alloc_sh_stream(STREAM_AUDIO);
funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE,
&sh_a->codec->samplerate);
int nchannels = sh_a->codec->channels.num;
funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS,
&nchannels);
mp_chmap_from_channels(&sh_a->codec->channels, nchannels);
// s16ne
mp_set_pcm_codec(sh_a->codec, true, false, 16, BYTE_ORDER == BIG_ENDIAN);
demux_add_sh_stream(demuxer, sh_a);
MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n",
nchannels, 16, sh_a->codec->samplerate);
}
no_audio:
if(!(funcs->start(tvh->priv))){
// start failed :(
tv_uninit(tvh);
return -1;
}
/* set color eq */
tv_set_color_options(tvh, TV_COLOR_BRIGHTNESS, tvh->tv_param->brightness);
tv_set_color_options(tvh, TV_COLOR_HUE, tvh->tv_param->hue);
tv_set_color_options(tvh, TV_COLOR_SATURATION, tvh->tv_param->saturation);
tv_set_color_options(tvh, TV_COLOR_CONTRAST, tvh->tv_param->contrast);
if(tvh->tv_param->gain!=-1)
if(funcs->control(tvh->priv,TVI_CONTROL_VID_SET_GAIN,&tvh->tv_param->gain)!=TVI_CONTROL_TRUE)
MP_WARN(tvh, "Unable to set gain control!\n");
demuxer->extended_ctrls = true;
return 0;
}
static void demux_close_tv(demuxer_t *demuxer)
{
tvi_handle_t *tvh=(tvi_handle_t*)(demuxer->priv);
if (!tvh) return;
tv_uninit(tvh);
free(tvh);
demuxer->priv=NULL;
}
static int demux_tv_fill_buffer(demuxer_t *demux)
{
tvi_handle_t *tvh=(tvi_handle_t*)(demux->priv);
demux_packet_t* dp;
unsigned int len=0;
struct sh_stream *want_audio = NULL, *want_video = NULL;
int num_streams = demux_get_num_stream(demux);
for (int n = 0; n < num_streams; n++) {
struct sh_stream *sh = demux_get_stream(demux, n);
if (!demux_has_packet(sh) && demux_stream_is_selected(sh)) {
if (sh->type == STREAM_AUDIO)
want_audio = sh;
if (sh->type == STREAM_VIDEO)
want_video = sh;
}
}
/* ================== ADD AUDIO PACKET =================== */
if (want_audio && tvh->tv_param->audio &&
tvh->functions->control(tvh->priv,
TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
{
len = tvh->functions->get_audio_framesize(tvh->priv);
dp=new_demux_packet(len);
if (dp) {
dp->keyframe = true;
dp->pts=tvh->functions->grab_audio_frame(tvh->priv, dp->buffer,len);
demux_add_packet(want_audio, dp);
}
}
/* ================== ADD VIDEO PACKET =================== */
if (want_video && tvh->functions->control(tvh->priv,
TVI_CONTROL_IS_VIDEO, 0) == TVI_CONTROL_TRUE)
{
len = tvh->functions->get_video_framesize(tvh->priv);
dp=new_demux_packet(len);
if (dp) {
dp->keyframe = true;
dp->pts=tvh->functions->grab_video_frame(tvh->priv, dp->buffer, len);
demux_add_packet(want_video, dp);
}
}
if (tvh->tv_param->scan) tv_scan(tvh);
return 1;
}
static int demux_tv_control(demuxer_t *demuxer, int cmd, void *arg)
{
tvi_handle_t *tvh=(tvi_handle_t*)(demuxer->priv);
if (cmd != DEMUXER_CTRL_STREAM_CTRL)
return CONTROL_UNKNOWN;
struct demux_ctrl_stream_ctrl *ctrl = arg;
ctrl->res = tv_stream_control(tvh, ctrl->ctrl, ctrl->arg);
return CONTROL_OK;
}
const demuxer_desc_t demuxer_desc_tv = {
.name = "tv",
.desc = "TV card demuxer",
.fill_buffer = demux_tv_fill_buffer,
.control = demux_tv_control,
.open = demux_open_tv,
.close = demux_close_tv,
};

View File

@ -467,9 +467,6 @@ const m_option_t mp_opts[] = {
OPT_DOUBLE("mf-fps", mf_fps, 0),
OPT_STRING("mf-type", mf_type, 0),
#if HAVE_TV
OPT_SUBSTRUCT("tv", tv_params, tv_params_conf, 0),
#endif /* HAVE_TV */
#if HAVE_DVBIN
OPT_SUBSTRUCT("dvbin", stream_dvb_opts, stream_dvb_conf, 0),
#endif

View File

@ -284,8 +284,6 @@ typedef struct MPOpts {
int w32_priority;
struct tv_params *tv_params;
struct pvr_params *stream_pvr_opts;
struct cdda_params *stream_cdda_opts;
struct dvb_params *stream_dvb_opts;
struct stream_lavf_params *stream_lavf_opts;

View File

@ -2879,163 +2879,6 @@ static int mp_property_cursor_autohide(void *ctx, struct m_property *prop,
return r;
}
static int prop_stream_ctrl(struct MPContext *mpctx, int ctrl, void *arg)
{
if (!mpctx->demuxer || !mpctx->demuxer->extended_ctrls)
return M_PROPERTY_UNAVAILABLE;
int r = demux_stream_control(mpctx->demuxer, ctrl, arg);
switch (r) {
case STREAM_OK: return M_PROPERTY_OK;
case STREAM_UNSUPPORTED: return M_PROPERTY_UNAVAILABLE;
default: return M_PROPERTY_ERROR;
}
}
static int mp_property_tv_norm(void *ctx, struct m_property *prop,
int action, void *arg)
{
switch (action) {
case M_PROPERTY_SET:
return prop_stream_ctrl(ctx, STREAM_CTRL_TV_SET_NORM, *(char **)arg);
case M_PROPERTY_SWITCH:
return prop_stream_ctrl(ctx, STREAM_CTRL_TV_STEP_NORM, NULL);
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_tv_scan(void *ctx, struct m_property *prop,
int action, void *arg)
{
switch (action) {
case M_PROPERTY_SET:
return prop_stream_ctrl(ctx, STREAM_CTRL_TV_SET_SCAN, arg);
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// TV color settings (RW)
static int mp_property_tv_color(void *ctx, struct m_property *prop,
int action, void *arg)
{
int req[2] = {(intptr_t)prop->priv};
switch (action) {
case M_PROPERTY_SET:
req[1] = *(int *)arg;
return prop_stream_ctrl(ctx, STREAM_CTRL_SET_TV_COLORS, req);
case M_PROPERTY_GET: {
int r = prop_stream_ctrl(ctx, STREAM_CTRL_GET_TV_COLORS, req);
if (r == M_PROPERTY_OK)
*(int *)arg = req[1];
return r;
}
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){
.type = CONF_TYPE_INT,
.flags = M_OPT_RANGE,
.min = -100,
.max = 100,
};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_tv_freq(void *ctx, struct m_property *prop,
int action, void *arg)
{
switch (action) {
case M_PROPERTY_SET:
return prop_stream_ctrl(ctx, STREAM_CTRL_SET_TV_FREQ, arg);
case M_PROPERTY_GET:
return prop_stream_ctrl(ctx, STREAM_CTRL_GET_TV_FREQ, arg);
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLOAT};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_tv_channel(void *ctx, struct m_property *prop,
int action, void *arg)
{
switch (action) {
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING};
return M_PROPERTY_OK;
case M_PROPERTY_SET:
return prop_stream_ctrl(ctx, STREAM_CTRL_TV_SET_CHAN, *(char **)arg);
case M_PROPERTY_GET:
return prop_stream_ctrl(ctx, STREAM_CTRL_TV_GET_CHAN, arg);
case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sa = arg;
int dir = sa->inc >= 0 ? 1 : -1;
return prop_stream_ctrl(ctx, STREAM_CTRL_TV_STEP_CHAN, &dir);
}
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_dvb_channel(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
int r;
switch (action) {
case M_PROPERTY_SET:
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_SET_CHANNEL, arg);
if (r == M_PROPERTY_OK && !mpctx->stop_play)
mpctx->stop_play = PT_CURRENT_ENTRY;
return r;
case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sa = arg;
int dir = sa->inc >= 0 ? 1 : -1;
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_STEP_CHANNEL, &dir);
if (r == M_PROPERTY_OK && !mpctx->stop_play)
mpctx->stop_play = PT_CURRENT_ENTRY;
return r;
}
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = &m_option_type_intpair};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_dvb_channel_name(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
int r;
switch (action) {
case M_PROPERTY_SET:
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_SET_CHANNEL_NAME, arg);
if (r == M_PROPERTY_OK && !mpctx->stop_play)
mpctx->stop_play = PT_CURRENT_ENTRY;
return r;
case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sa = arg;
int dir = sa->inc >= 0 ? 1 : -1;
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_STEP_CHANNEL, &dir);
if (r == M_PROPERTY_OK && !mpctx->stop_play)
mpctx->stop_play = PT_CURRENT_ENTRY;
return r;
}
case M_PROPERTY_GET: {
return prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_GET_CHANNEL_NAME, arg);
}
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_playlist_pos_x(void *ctx, struct m_property *prop,
int action, void *arg, int base)
{
@ -3749,19 +3592,6 @@ static const struct m_property mp_properties_base[] = {
PROPERTY_BITRATE("audio-bitrate", false, STREAM_AUDIO),
PROPERTY_BITRATE("sub-bitrate", false, STREAM_SUB),
#define PROPERTY_TV_COLOR(name, type) \
{name, mp_property_tv_color, (void *)(intptr_t)type}
PROPERTY_TV_COLOR("tv-brightness", TV_COLOR_BRIGHTNESS),
PROPERTY_TV_COLOR("tv-contrast", TV_COLOR_CONTRAST),
PROPERTY_TV_COLOR("tv-saturation", TV_COLOR_SATURATION),
PROPERTY_TV_COLOR("tv-hue", TV_COLOR_HUE),
{"tv-freq", mp_property_tv_freq},
{"tv-norm", mp_property_tv_norm},
{"tv-scan", mp_property_tv_scan},
{"tv-channel", mp_property_tv_channel},
{"dvb-channel", mp_property_dvb_channel},
{"dvb-channel-name", mp_property_dvb_channel_name},
{"cursor-autohide", mp_property_cursor_autohide},
{"window-minimized", mp_property_win_minimized},
@ -5258,19 +5088,6 @@ static void cmd_show_progress(void *p)
mp_wakeup_core(mpctx);
}
static void cmd_tv_last_channel(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
if (!mpctx->demuxer || !mpctx->demuxer->extended_ctrls) {
cmd->success = false;
return;
}
demux_stream_control(mpctx->demuxer, STREAM_CTRL_TV_LAST_CHAN, NULL);
}
static void cmd_track_add(void *p)
{
struct mp_cmd_ctx *cmd = p;
@ -5905,8 +5722,6 @@ const struct mp_cmd_def mp_cmds[] = {
.abort_on_playback_end = true,
},
{ "tv-last-channel", cmd_tv_last_channel, },
{ "screenshot", cmd_screenshot,
{
OPT_FLAGS("flags", v.i, 0,

View File

@ -1,199 +0,0 @@
/*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "config.h"
#include <alsa/asoundlib.h>
#include "audio_in.h"
#include "common/msg.h"
int ai_alsa_setup(audio_in_t *ai)
{
snd_pcm_hw_params_t *params;
snd_pcm_sw_params_t *swparams;
snd_pcm_uframes_t buffer_size, period_size;
int err;
int dir;
unsigned int rate;
snd_pcm_hw_params_alloca(&params);
snd_pcm_sw_params_alloca(&swparams);
err = snd_pcm_hw_params_any(ai->alsa.handle, params);
if (err < 0) {
MP_ERR(ai, "Broken configuration for this PCM: no configurations available.\n");
return -1;
}
err = snd_pcm_hw_params_set_access(ai->alsa.handle, params,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
MP_ERR(ai, "Access type not available.\n");
return -1;
}
err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16);
if (err < 0) {
MP_ERR(ai, "Sample format not available.\n");
return -1;
}
err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels);
if (err < 0) {
snd_pcm_hw_params_get_channels(params, &ai->channels);
MP_ERR(ai, "Channel count not available - reverting to default: %d\n",
ai->channels);
} else {
ai->channels = ai->req_channels;
}
dir = 0;
rate = ai->req_samplerate;
err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir);
if (err < 0) {
MP_ERR(ai, "Cannot set samplerate.\n");
}
ai->samplerate = rate;
dir = 0;
ai->alsa.buffer_time = 1000000;
err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params,
&ai->alsa.buffer_time, &dir);
if (err < 0) {
MP_ERR(ai, "Cannot set buffer time.\n");
}
dir = 0;
ai->alsa.period_time = ai->alsa.buffer_time / 4;
err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params,
&ai->alsa.period_time, &dir);
if (err < 0) {
MP_ERR(ai, "Cannot set period time.\n");
}
err = snd_pcm_hw_params(ai->alsa.handle, params);
if (err < 0) {
MP_ERR(ai, "Unable to install hardware parameters: %s", snd_strerror(err));
snd_pcm_hw_params_dump(params, ai->alsa.log);
return -1;
}
dir = -1;
snd_pcm_hw_params_get_period_size(params, &period_size, &dir);
snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
ai->alsa.chunk_size = period_size;
if (period_size == buffer_size) {
MP_ERR(ai, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size);
return -1;
}
snd_pcm_sw_params_current(ai->alsa.handle, swparams);
err = snd_pcm_sw_params_set_avail_min(ai->alsa.handle, swparams, ai->alsa.chunk_size);
err = snd_pcm_sw_params_set_start_threshold(ai->alsa.handle, swparams, 0);
err = snd_pcm_sw_params_set_stop_threshold(ai->alsa.handle, swparams, buffer_size);
if (snd_pcm_sw_params(ai->alsa.handle, swparams) < 0) {
MP_ERR(ai, "Unable to install software parameters:\n");
snd_pcm_sw_params_dump(swparams, ai->alsa.log);
return -1;
}
if (mp_msg_test(ai->log, MSGL_V)) {
snd_pcm_dump(ai->alsa.handle, ai->alsa.log);
}
ai->alsa.bits_per_sample = snd_pcm_format_physical_width(SND_PCM_FORMAT_S16);
ai->alsa.bits_per_frame = ai->alsa.bits_per_sample * ai->channels;
ai->blocksize = ai->alsa.chunk_size * ai->alsa.bits_per_frame / 8;
ai->samplesize = ai->alsa.bits_per_sample;
ai->bytes_per_sample = ai->alsa.bits_per_sample/8;
return 0;
}
int ai_alsa_init(audio_in_t *ai)
{
int err;
const char *device = ai->alsa.device;
if (!device)
device = "default";
err = snd_pcm_open(&ai->alsa.handle, device, SND_PCM_STREAM_CAPTURE, 0);
if (err < 0) {
MP_ERR(ai, "Error opening audio: %s\n", snd_strerror(err));
return -1;
}
err = snd_output_stdio_attach(&ai->alsa.log, stderr, 0);
if (err < 0) {
return -1;
}
err = ai_alsa_setup(ai);
return err;
}
#ifndef timersub
#define timersub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#endif
int ai_alsa_xrun(audio_in_t *ai)
{
snd_pcm_status_t *status;
int res;
snd_pcm_status_alloca(&status);
if ((res = snd_pcm_status(ai->alsa.handle, status))<0) {
MP_ERR(ai, "ALSA status error: %s", snd_strerror(res));
return -1;
}
if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) {
struct timeval now, diff, tstamp;
gettimeofday(&now, 0);
snd_pcm_status_get_trigger_tstamp(status, &tstamp);
timersub(&now, &tstamp, &diff);
MP_ERR(ai, "ALSA xrun!!! (at least %.3f ms long)\n",
diff.tv_sec * 1000 + diff.tv_usec / 1000.0);
if (mp_msg_test(ai->log, MSGL_V)) {
MP_ERR(ai, "ALSA Status:\n");
snd_pcm_status_dump(status, ai->alsa.log);
}
if ((res = snd_pcm_prepare(ai->alsa.handle))<0) {
MP_ERR(ai, "ALSA xrun: prepare error: %s", snd_strerror(res));
return -1;
}
return 0; /* ok, data should be accepted again */
}
MP_ERR(ai, "ALSA read/write error");
return -1;
}

View File

@ -1,153 +0,0 @@
/*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include "osdep/io.h"
#include "audio_in.h"
#include "common/common.h"
#include "common/msg.h"
int ai_oss_set_samplerate(audio_in_t *ai)
{
int tmp = ai->req_samplerate;
if (ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &tmp) == -1) return -1;
ai->samplerate = tmp;
return 0;
}
int ai_oss_set_channels(audio_in_t *ai)
{
int err;
int ioctl_param;
if (ai->req_channels > 2)
{
ioctl_param = ai->req_channels;
MP_VERBOSE(ai, "ioctl dsp channels: %d\n",
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param));
if (err < 0) {
MP_ERR(ai, "Unable to set channel count: %d\n",
ai->req_channels);
return -1;
}
ai->channels = ioctl_param;
}
else
{
ioctl_param = (ai->req_channels == 2);
MP_VERBOSE(ai, "ioctl dsp stereo: %d (req: %d)\n",
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_STEREO, &ioctl_param),
ioctl_param);
if (err < 0) {
MP_ERR(ai, "Unable to set stereo: %d\n",
ai->req_channels == 2);
return -1;
}
ai->channels = ioctl_param ? 2 : 1;
}
return 0;
}
int ai_oss_init(audio_in_t *ai)
{
int err;
int ioctl_param;
const char *device = ai->oss.device;
if (!device)
device = "/dev/dsp";
ai->oss.audio_fd = open(device, O_RDONLY | O_CLOEXEC);
if (ai->oss.audio_fd < 0)
{
MP_ERR(ai, "Unable to open '%s': %s\n", device, mp_strerror(errno));
return -1;
}
ioctl_param = 0 ;
MP_VERBOSE(ai, "ioctl dsp getfmt: %d\n",
ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param));
MP_VERBOSE(ai, "Supported formats: %x\n", ioctl_param);
if (!(ioctl_param & AFMT_S16_NE))
MP_ERR(ai, "unsupported format\n");
ioctl_param = AFMT_S16_NE;
MP_VERBOSE(ai, "ioctl dsp setfmt: %d\n",
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param));
if (err < 0) {
MP_ERR(ai, "Unable to set audio format.");
return -1;
}
if (ai_oss_set_channels(ai) < 0) return -1;
ioctl_param = ai->req_samplerate;
MP_VERBOSE(ai, "ioctl dsp speed: %d\n",
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &ioctl_param));
if (err < 0) {
MP_ERR(ai, "Unable to set samplerate: %d\n",
ai->req_samplerate);
return -1;
}
ai->samplerate = ioctl_param;
MP_VERBOSE(ai, "ioctl dsp trigger: %d\n",
ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param));
MP_VERBOSE(ai, "trigger: %x\n", ioctl_param);
ioctl_param = PCM_ENABLE_INPUT;
MP_VERBOSE(ai, "ioctl dsp trigger: %d\n",
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
if (err < 0) {
MP_ERR(ai, "Unable to set trigger: %d\n",
PCM_ENABLE_INPUT);
}
ai->blocksize = 0;
MP_VERBOSE(ai, "ioctl dsp getblocksize: %d\n",
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETBLKSIZE, &ai->blocksize));
if (err < 0) {
MP_ERR(ai, "Unable to get block size!\n");
}
MP_VERBOSE(ai, "blocksize: %d\n", ai->blocksize);
// correct the blocksize to a reasonable value
if (ai->blocksize <= 0) {
ai->blocksize = 4096*ai->channels*2;
MP_ERR(ai, "Audio block size is zero, setting to %d!\n", ai->blocksize);
} else if (ai->blocksize < 4096*ai->channels*2) {
ai->blocksize *= 4096*ai->channels*2/ai->blocksize;
MP_ERR(ai, "Audio block size too low, setting to %d!\n", ai->blocksize);
}
ai->samplesize = 16;
ai->bytes_per_sample = 2;
return 0;
}

View File

@ -1,52 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include <sndio.h>
#include "audio_in.h"
#include "common/msg.h"
int ai_sndio_setup(audio_in_t *ai)
{
struct sio_par par;
sio_initpar(&par);
par.bits = 16;
par.sig = 1;
par.le = SIO_LE_NATIVE;
par.rchan = ai->req_channels;
par.rate = ai->req_samplerate;
par.appbufsz = ai->req_samplerate; /* 1 sec */
if (!sio_setpar(ai->sndio.hdl, &par) || !sio_getpar(ai->sndio.hdl, &par)) {
MP_ERR(ai, "could not configure sndio audio");
return -1;
}
ai->channels = par.rchan;
ai->samplerate = par.rate;
ai->samplesize = par.bits;
ai->bytes_per_sample = par.bps;
ai->blocksize = par.round * par.bps;
return 0;
}
int ai_sndio_init(audio_in_t *ai)
{
int err;
const char *device = ai->sndio.device;
if (!device)
device = "default";
if ((ai->sndio.hdl = sio_open(device, SIO_REC, 0)) == NULL) {
MP_ERR(ai, "could not open sndio audio");
return -1;
}
err = ai_sndio_setup(ai);
return err;
}

View File

@ -1,298 +0,0 @@
/*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "config.h"
#include "audio_in.h"
#include "common/common.h"
#include "common/msg.h"
#include <string.h>
#include <errno.h>
// sanitizes ai structure before calling other functions
int audio_in_init(audio_in_t *ai, struct mp_log *log, int type)
{
ai->type = type;
ai->setup = 0;
ai->log = log;
ai->channels = -1;
ai->samplerate = -1;
ai->blocksize = -1;
ai->bytes_per_sample = -1;
ai->samplesize = -1;
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
ai->alsa.handle = NULL;
ai->alsa.log = NULL;
ai->alsa.device = NULL;
return 0;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
ai->oss.audio_fd = -1;
ai->oss.device = NULL;
return 0;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
ai->sndio.hdl = NULL;
ai->sndio.device = NULL;
return 0;
#endif
default:
return -1;
}
}
int audio_in_setup(audio_in_t *ai)
{
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
if (ai_alsa_init(ai) < 0) return -1;
ai->setup = 1;
return 0;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
if (ai_oss_init(ai) < 0) return -1;
ai->setup = 1;
return 0;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
if (ai_sndio_init(ai) < 0) return -1;
ai->setup = 1;
return 0;
#endif
default:
return -1;
}
}
int audio_in_set_samplerate(audio_in_t *ai, int rate)
{
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
ai->req_samplerate = rate;
if (!ai->setup) return 0;
if (ai_alsa_setup(ai) < 0) return -1;
return ai->samplerate;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
ai->req_samplerate = rate;
if (!ai->setup) return 0;
if (ai_oss_set_samplerate(ai) < 0) return -1;
return ai->samplerate;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
ai->req_samplerate = rate;
if (!ai->setup) return 0;
if (ai_sndio_setup(ai) < 0) return -1;
return ai->samplerate;
#endif
default:
return -1;
}
}
int audio_in_set_channels(audio_in_t *ai, int channels)
{
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
ai->req_channels = channels;
if (!ai->setup) return 0;
if (ai_alsa_setup(ai) < 0) return -1;
return ai->channels;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
ai->req_channels = channels;
if (!ai->setup) return 0;
if (ai_oss_set_channels(ai) < 0) return -1;
return ai->channels;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
ai->req_channels = channels;
if (!ai->setup) return 0;
if (ai_sndio_setup(ai) < 0) return -1;
return ai->channels;
#endif
default:
return -1;
}
}
int audio_in_set_device(audio_in_t *ai, char *device)
{
#if HAVE_ALSA
int i;
#endif
if (ai->setup) return -1;
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
free(ai->alsa.device);
ai->alsa.device = strdup(device);
if (ai->alsa.device) {
/* mplayer could not handle colons in arguments */
for (i = 0; i < (int)strlen(ai->alsa.device); i++) {
if (ai->alsa.device[i] == '.') ai->alsa.device[i] = ':';
}
}
return 0;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
free(ai->oss.device);
ai->oss.device = strdup(device);
return 0;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
if (ai->sndio.device) free(ai->sndio.device);
ai->sndio.device = strdup(device);
return 0;
#endif
default:
return -1;
}
}
int audio_in_uninit(audio_in_t *ai)
{
if (ai->setup) {
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
if (ai->alsa.log)
snd_output_close(ai->alsa.log);
if (ai->alsa.handle) {
snd_pcm_close(ai->alsa.handle);
}
ai->setup = 0;
return 0;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
close(ai->oss.audio_fd);
ai->setup = 0;
return 0;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
if (ai->sndio.hdl)
sio_close(ai->sndio.hdl);
ai->setup = 0;
return 0;
#endif
}
}
return -1;
}
int audio_in_start_capture(audio_in_t *ai)
{
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
return snd_pcm_start(ai->alsa.handle);
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
return 0;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
if (!sio_start(ai->sndio.hdl))
return -1;
return 0;
#endif
default:
return -1;
}
}
int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer)
{
int ret;
switch (ai->type) {
#if HAVE_ALSA
case AUDIO_IN_ALSA:
ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size);
if (ret != ai->alsa.chunk_size) {
if (ret < 0) {
MP_ERR(ai, "\nError reading audio: %s\n", snd_strerror(ret));
if (ret == -EPIPE) {
if (ai_alsa_xrun(ai) == 0) {
MP_ERR(ai, "Recovered from cross-run, some frames may be left out!\n");
} else {
MP_ERR(ai, "Fatal error, cannot recover!\n");
}
}
} else {
MP_ERR(ai, "\nNot enough audio samples!\n");
}
return -1;
}
return ret;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
ret = read(ai->oss.audio_fd, buffer, ai->blocksize);
if (ret != ai->blocksize) {
if (ret < 0) {
MP_ERR(ai, "\nError reading audio: %s\n", mp_strerror(errno));
} else {
MP_ERR(ai, "\nNot enough audio samples!\n");
}
return -1;
}
return ret;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
ret = sio_read(ai->sndio.hdl, buffer, ai->blocksize);
if (ret != ai->blocksize) {
if (ret < 0) {
MP_ERR(ai, "\nError reading audio: %s\n", mp_strerror(errno));
} else {
MP_ERR(ai, "\nNot enough audio samples!\n");
}
return -1;
}
return ret;
#endif
default:
return -1;
}
}

View File

@ -1,118 +0,0 @@
/*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MPLAYER_AUDIO_IN_H
#define MPLAYER_AUDIO_IN_H
#define AUDIO_IN_ALSA 1
#define AUDIO_IN_OSS 2
#define AUDIO_IN_SNDIO 3
#include "config.h"
#if !HAVE_GPL
#error GPL only
#endif
struct mp_log;
#if HAVE_ALSA
#include <alsa/asoundlib.h>
typedef struct {
char *device;
snd_pcm_t *handle;
snd_output_t *log;
int buffer_time, period_time, chunk_size;
size_t bits_per_sample, bits_per_frame;
} ai_alsa_t;
#endif
#if HAVE_OSS_AUDIO
typedef struct {
char *device;
int audio_fd;
} ai_oss_t;
#endif
#if HAVE_SNDIO
#include <sndio.h>
typedef struct {
char *device;
struct sio_hdl *hdl;
} ai_sndio_t;
#endif
typedef struct
{
struct mp_log *log;
int type;
int setup;
/* requested values */
int req_channels;
int req_samplerate;
/* real values read-only */
int channels;
int samplerate;
int blocksize;
int bytes_per_sample;
int samplesize;
#if HAVE_ALSA
ai_alsa_t alsa;
#endif
#if HAVE_OSS_AUDIO
ai_oss_t oss;
#endif
#if HAVE_SNDIO
ai_sndio_t sndio;
#endif
} audio_in_t;
int audio_in_init(audio_in_t *ai, struct mp_log *log, int type);
int audio_in_setup(audio_in_t *ai);
int audio_in_set_device(audio_in_t *ai, char *device);
int audio_in_set_samplerate(audio_in_t *ai, int rate);
int audio_in_set_channels(audio_in_t *ai, int channels);
int audio_in_uninit(audio_in_t *ai);
int audio_in_start_capture(audio_in_t *ai);
int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer);
#if HAVE_ALSA
int ai_alsa_setup(audio_in_t *ai);
int ai_alsa_init(audio_in_t *ai);
int ai_alsa_xrun(audio_in_t *ai);
#endif
#if HAVE_OSS_AUDIO
int ai_oss_set_samplerate(audio_in_t *ai);
int ai_oss_set_channels(audio_in_t *ai);
int ai_oss_init(audio_in_t *ai);
#endif
#if HAVE_SNDIO
int ai_sndio_setup(audio_in_t *ai);
int ai_sndio_init(audio_in_t *ai);
#endif
#endif /* MPLAYER_AUDIO_IN_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,133 +0,0 @@
/*
* Worldwide channel/frequency list
*
* Nathan Laredo (laredo@broked.net)
*
* Frequencies are given in kHz
*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MPLAYER_FREQUENCIES_H
#define MPLAYER_FREQUENCIES_H
#define NTSC_AUDIO_CARRIER 4500
#define PAL_AUDIO_CARRIER_I 6000
#define PAL_AUDIO_CARRIER_BGHN 5500
#define PAL_AUDIO_CARRIER_MN 4500
#define PAL_AUDIO_CARRIER_D 6500
#define SEACAM_AUDIO_DKK1L 6500
#define SEACAM_AUDIO_BG 5500
/* NICAM 728 32-kHz, 14-bit digital stereo audio is transmitted in 1ms frames
containing 8 bits frame sync, 5 bits control, 11 bits additional data, and
704 bits audio data. The bit rate is reduced by transmitting only 10 bits
plus parity of each 14 bit sample, the largest sample in a frame determines
which 10 bits are transmitted. The parity bits for audio samples also
specify the scaling factor used for that channel during that frame. The
companeded audio data is interleaved to reduce the influence of dropouts
and the whole frame except for sync bits is scrambled for spectrum shaping.
Data is modulated using QPSK, at below following subcarrier freqs */
#define NICAM728_PAL_BGH 5850
#define NICAM728_PAL_I 6552
/* COMPREHENSIVE LIST OF FORMAT BY COUNTRY
(M) NTSC used in:
Antigua, Aruba, Bahamas, Barbados, Belize, Bermuda, Bolivia, Burma,
Canada, Chile, Colombia, Costa Rica, Cuba, Curacao, Dominican Republic,
Ecuador, El Salvador, Guam Guatemala, Honduras, Jamaica, Japan,
South Korea, Mexico, Montserrat, Myanmar, Nicaragua, Panama, Peru,
Philippines, Puerto Rico, St Christopher and Nevis, Samoa, Suriname,
Taiwan, Trinidad/Tobago, United States, Venezuela, Virgin Islands
(B) PAL used in:
Albania, Algeria, Australia, Austria, Bahrain, Bangladesh, Belgium,
Bosnia-Herzegovinia, Brunei Darussalam, Cambodia, Cameroon, Croatia,
Cyprus, Denmark, Egypt, Ethiopia, Equatorial Guinea, Finland, Germany,
Ghana, Gibraltar, Greenland, Iceland, India, Indonesia, Israel, Italy,
Jordan, Kenya, Kuwait, Liberia, Libya, Luxembourg, Malaysa, Maldives,
Malta, Nepal, Netherlands, New Zeland, Nigeria, Norway, Oman, Pakistan,
Papua New Guinea, Portugal, Qatar, Sao Tome and Principe, Saudi Arabia,
Seychelles, Sierra Leone, Singapore, Slovenia, Somali, Spain,
Sri Lanka, Sudan, Swaziland, Sweden, Switzeland, Syria, Thailand,
Tunisia, Turkey, Uganda, United Arab Emirates, Yemen
(N) PAL used in: (Combination N = 4.5MHz audio carrier, 3.58MHz burst)
Argentina (Combination N), Paraguay, Uruguay
(M) PAL (525/60, 3.57MHz burst) used in:
Brazil
(G) PAL used in:
Albania, Algeria, Austria, Bahrain, Bosnia/Herzegovinia, Cambodia,
Cameroon, Croatia, Cyprus, Denmark, Egypt, Ethiopia, Equatorial Guinea,
Finland, Germany, Gibraltar, Greenland, Iceland, Israel, Italy, Jordan,
Kenya, Kuwait, Liberia, Libya, Luxembourg, Malaysia, Monaco,
Mozambique, Netherlands, New Zealand, Norway, Oman, Pakistan,
Papa New Guinea, Portugal, Qatar, Romania, Sierra Leone, Singapore,
Slovenia, Somalia, Spain, Sri Lanka, Sudan, Swaziland, Sweeden,
Switzerland, Syria, Thailand, Tunisia, Turkey, United Arab Emirates,
Yemen, Zambia, Zimbabwe
(D) PAL used in:
China, North Korea, Romania, Czech Republic
(H) PAL used in:
Belgium
(I) PAL used in:
Angola, Botswana, Gambia, Guinea-Bissau, Hong Kong, Ireland, Lesotho,
Malawi, Nambia, Nigeria, South Africa, Tanzania, United Kingdom,
Zanzibar
(B) SECAM used in:
Djibouti, Greece, Iran, Iraq, Lebanon, Mali, Mauritania, Mauritus,
Morocco
(D) SECAM used in:
Afghanistan, Armenia, Azerbaijan, Belarus, Bulgaria,
Estonia, Georgia, Hungary, Zazakhstan, Lithuania, Mongolia, Moldova,
Russia, Slovak Republic, Ukraine, Vietnam
(G) SECAM used in:
Greecem Iran, Iraq, Mali, Mauritus, Morocco, Saudi Arabia
(K) SECAM used in:
Armenia, Azerbaijan, Bulgaria, Estonia, Georgia,
Hungary, Kazakhstan, Lithuania, Madagascar, Moldova, Poland, Russia,
Slovak Republic, Ukraine, Vietnam
(K1) SECAM used in:
Benin, Burkina Faso, Burundi, Chad, Cape Verde, Central African
Republic, Comoros, Congo, Gabon, Madagascar, Niger, Rwanda, Senegal,
Togo, Zaire
(L) SECAM used in:
France
*/
/* --------------------------------------------------------------------- */
struct CHANLIST {
char name[8];
int freq;
};
struct CHANLISTS {
const char *name;
const struct CHANLIST *list;
int count;
};
#define CHAN_COUNT(x) (sizeof(x)/sizeof(struct CHANLIST))
/* --------------------------------------------------------------------- */
extern const struct CHANLISTS chanlists[];
extern const int chancount;
#include "config.h"
#if !HAVE_GPL
#error GPL only
#endif
#endif /* MPLAYER_FREQUENCIES_H */

View File

@ -46,7 +46,6 @@
extern const stream_info_t stream_info_cdda;
extern const stream_info_t stream_info_dvb;
extern const stream_info_t stream_info_tv;
extern const stream_info_t stream_info_smb;
extern const stream_info_t stream_info_null;
extern const stream_info_t stream_info_memory;
@ -75,9 +74,6 @@ static const stream_info_t *const stream_list[] = {
#if HAVE_DVBIN
&stream_info_dvb,
#endif
#if HAVE_TV
&stream_info_tv,
#endif
#if HAVE_LIBSMBCLIENT
&stream_info_smb,
#endif

View File

@ -65,24 +65,6 @@ enum stream_ctrl {
// Garbage compatibility for obnoxious users
STREAM_CTRL_OPTICAL_CRAP_HACK1,
STREAM_CTRL_OPTICAL_CRAP_HACK2,
// TV
STREAM_CTRL_TV_SET_SCAN,
STREAM_CTRL_SET_TV_FREQ,
STREAM_CTRL_GET_TV_FREQ,
STREAM_CTRL_SET_TV_COLORS,
STREAM_CTRL_GET_TV_COLORS,
STREAM_CTRL_TV_SET_NORM,
STREAM_CTRL_TV_STEP_NORM,
STREAM_CTRL_TV_SET_CHAN,
STREAM_CTRL_TV_GET_CHAN,
STREAM_CTRL_TV_STEP_CHAN,
STREAM_CTRL_TV_LAST_CHAN,
STREAM_CTRL_DVB_SET_CHANNEL,
STREAM_CTRL_DVB_SET_CHANNEL_NAME,
STREAM_CTRL_DVB_GET_CHANNEL_NAME,
STREAM_CTRL_DVB_STEP_CHANNEL,
};
struct stream_lang_req {
@ -96,12 +78,6 @@ struct stream_dvd_info_req {
int num_subs;
};
// for STREAM_CTRL_SET_TV_COLORS
#define TV_COLOR_BRIGHTNESS 1
#define TV_COLOR_HUE 2
#define TV_COLOR_SATURATION 3
#define TV_COLOR_CONTRAST 4
// for STREAM_CTRL_AVSEEK
struct stream_avseek {
int stream_index;

View File

@ -901,6 +901,7 @@ static int dvbin_stream_control(struct stream *s, int cmd, void *arg)
dvb_channels_list_t *list = NULL;
#if 0
switch (cmd) {
case STREAM_CTRL_DVB_SET_CHANNEL: {
unsigned int *iarg = arg;
@ -926,13 +927,14 @@ static int dvbin_stream_control(struct stream *s, int cmd, void *arg)
return STREAM_ERROR;
}
}
#endif
if (state->cur_adapter >= state->adapters_count)
return STREAM_ERROR;
list = state->adapters[state->cur_adapter].list;
switch (cmd) {
#if 0
case STREAM_CTRL_GET_TV_FREQ:
(*(unsigned int*)arg) = list->channels[list->current].freq;
return STREAM_ERROR;
@ -966,6 +968,7 @@ static int dvbin_stream_control(struct stream *s, int cmd, void *arg)
*(char **)arg = talloc_strdup(NULL, progname);
return STREAM_OK;
}
#endif
case STREAM_CTRL_GET_METADATA: {
struct mp_tags *metadata = talloc_zero(NULL, struct mp_tags);
char *progname = list->channels[list->current].name;

View File

@ -1,52 +0,0 @@
/*
* stream layer for TV Input, based on previous work from Albeu
*
* Copyright (C) 2006 Benjamin Zores
* Original author: Albeu
*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "stream.h"
#include "options/m_option.h"
#include "tv.h"
#include <stdio.h>
static void
tv_stream_close (stream_t *stream)
{
}
static int
tv_stream_open (stream_t *stream)
{
stream->close=tv_stream_close;
stream->demuxer = "tv";
return STREAM_OK;
}
const stream_info_t stream_info_tv = {
.name = "tv",
.open = tv_stream_open,
.protocols = (const char*const[]){ "tv", NULL },
};

View File

@ -1,986 +0,0 @@
/*
* TV Interface for MPlayer
*
* API idea based on libvo2
*
* Copyright (C) 2001 Alex Beregszaszi
*
* Feb 19, 2002: Significant rewrites by Charles R. Henrich (henrich@msu.edu)
* to add support for audio, and bktr *BSD support.
*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>
#include <assert.h>
#include <libavutil/avstring.h>
#include "config.h"
#include "common/msg.h"
#include "misc/ctype.h"
#include "options/m_option.h"
#include "options/m_config.h"
#include "options/options.h"
#include "stream.h"
#include "audio/format.h"
#include "osdep/timer.h"
#include "tv.h"
#include "frequencies.h"
/* enumerating drivers (like in stream.c) */
extern const tvi_info_t tvi_info_dummy;
extern const tvi_info_t tvi_info_v4l2;
/** List of drivers in autodetection order */
static const tvi_info_t *const tvi_driver_list[]={
#if HAVE_TV_V4L2
&tvi_info_v4l2,
#endif
&tvi_info_dummy,
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_FLOAT("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 = calloc(1, sizeof(*h));
if (!h)
return NULL;
h->priv = calloc(1, size);
if (!h->priv) {
free(h);
return NULL;
}
h->log = log;
h->functions = functions;
h->chanlist = -1;
h->norm = -1;
h->channel = -1;
return h;
}
void tv_free_handle(tvi_handle_t *h)
{
if (!h)
return;
free(h->priv);
free(h->scan);
free(h);
}
void tv_start_scan(tvi_handle_t *tvh, int start)
{
MP_INFO(tvh, "start scan\n");
tvh->tv_param->scan=start?1:0;
}
static int tv_set_freq_float(tvi_handle_t *tvh, float freq)
{
return tv_set_freq(tvh, freq/1000.0*16);
}
void tv_scan(tvi_handle_t *tvh)
{
unsigned int now;
struct CHANLIST cl;
tv_channels_t *tv_channel_tmp=NULL;
tv_channels_t *tv_channel_add=NULL;
tv_scan_t* scan;
int found=0, index=1;
//Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s
if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE)
{
MP_WARN(tvh, "Channel scanner is not available without tuner\n");
tvh->tv_param->scan=0;
return;
}
scan = tvh->scan;
now=(unsigned int)mp_time_us();
if (!scan) {
scan=calloc(1,sizeof(tv_scan_t));
tvh->scan=scan;
cl = tvh->chanlist_s[scan->channel_num];
tv_set_freq_float(tvh, cl.freq);
scan->scan_timer=now+1e6*tvh->tv_param->scan_period;
}
if(scan->scan_timer>now)
return;
if (tv_get_signal(tvh)>tvh->tv_param->scan_threshold) {
cl = tvh->chanlist_s[scan->channel_num];
tv_channel_tmp=tvh->tv_channel_list;
while (tv_channel_tmp) {
index++;
if (cl.freq==tv_channel_tmp->freq){
found=1;
break;
}
tv_channel_add=tv_channel_tmp;
tv_channel_tmp=tv_channel_tmp->next;
}
if (!found) {
MP_INFO(tvh, "Found new channel: %s (#%d). \n",cl.name,index);
scan->new_channels++;
tv_channel_tmp = malloc(sizeof(tv_channels_t));
tv_channel_tmp->index=index;
tv_channel_tmp->next=NULL;
tv_channel_tmp->prev=tv_channel_add;
tv_channel_tmp->freq=cl.freq;
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 (!tvh->tv_channel_list)
tvh->tv_channel_list=tv_channel_tmp;
else {
tv_channel_add->next=tv_channel_tmp;
tvh->tv_channel_list->prev=tv_channel_tmp;
}
}else
MP_INFO(tvh, "Found existing channel: %s-%s.\n",
tv_channel_tmp->number,tv_channel_tmp->name);
}
scan->channel_num++;
scan->scan_timer=now+1e6*tvh->tv_param->scan_period;
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=tvh->tv_channel_list;
if(tv_channel_tmp){
MP_INFO(tvh, "channels=");
while(tv_channel_tmp){
MP_INFO(tvh, "%s-%s",tv_channel_tmp->number,tv_channel_tmp->name);
if(tv_channel_tmp->next)
MP_INFO(tvh, ",");
tv_channel_tmp=tv_channel_tmp->next;
}
MP_INFO(tvh, "\n");
}
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{
cl = tvh->chanlist_s[scan->channel_num];
tv_set_freq_float(tvh, cl.freq);
MP_INFO(tvh, "Trying: %s (%.2f). \n",cl.name,1e-3*cl.freq);
}
}
static int norm_from_string(tvi_handle_t *tvh, char* norm)
{
const tvi_functions_t *funcs = tvh->functions;
char str[20];
int ret;
strncpy(str, norm, sizeof(str)-1);
str[sizeof(str)-1] = '\0';
ret=funcs->control(tvh->priv, TVI_CONTROL_SPC_GET_NORMID, str);
if (ret == TVI_CONTROL_TRUE) {
int *v = (int *)str;
return *v;
}
if(ret!=TVI_CONTROL_UNKNOWN)
{
MP_WARN(tvh, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm,"default");
return 0;
}
if (!strcasecmp(norm, "pal"))
return TV_NORM_PAL;
else if (!strcasecmp(norm, "ntsc"))
return TV_NORM_NTSC;
else if (!strcasecmp(norm, "secam"))
return TV_NORM_SECAM;
else if (!strcasecmp(norm, "palnc"))
return TV_NORM_PALNC;
else if (!strcasecmp(norm, "palm"))
return TV_NORM_PALM;
else if (!strcasecmp(norm, "paln"))
return TV_NORM_PALN;
else if (!strcasecmp(norm, "ntscjp"))
return TV_NORM_NTSCJP;
else {
MP_WARN(tvh, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm, "PAL");
return TV_NORM_PAL;
}
}
static void parse_channels(tvi_handle_t *tvh)
{
char** channels = tvh->tv_param->channels;
MP_INFO(tvh, "TV channel names detected.\n");
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++);
char* sep = strchr(tmp,'-');
int i;
struct CHANLIST cl;
if (!sep) continue; // Wrong syntax, but mplayer should not crash
av_strlcpy(tvh->tv_channel_current->name, sep + 1,
sizeof(tvh->tv_channel_current->name));
sep[0] = '\0';
strncpy(tvh->tv_channel_current->number, tmp, 5);
tvh->tv_channel_current->number[4]='\0';
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){
tvh->tv_channel_current->freq=atoi(tmp);
}else{
tvh->tv_channel_current->freq = 0;
for (i = 0; i < chanlists[tvh->chanlist].count; i++) {
cl = tvh->chanlist_s[i];
if (!strcasecmp(cl.name, tvh->tv_channel_current->number)) {
tvh->tv_channel_current->freq=cl.freq;
break;
}
}
}
if (tvh->tv_channel_current->freq == 0)
MP_ERR(tvh, "Couldn't find frequency for channel %s (%s)\n",
tvh->tv_channel_current->number, tvh->tv_channel_current->name);
else {
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] == '+' ) tvh->tv_channel_current->freq += i * 100;
if ( sep[0] == '-' ) tvh->tv_channel_current->freq -= i * 100;
sep[0] = '\0';
}
sep = strchr(tvh->tv_channel_current->name, '=');
if ( sep ) {
tvh->tv_channel_current->norm = norm_from_string(tvh, sep+1);
sep[0] = '\0';
}
}
/*MP_INFO(tvh, "-- Detected channel %s - %s (%5.3f)\n",
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 (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)
{
tvh->norm = norm_from_string(tvh, norm);
MP_VERBOSE(tvh, "Selected norm : %s\n", norm);
if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) {
MP_ERR(tvh, "Error: Cannot set norm!\n");
return 0;
}
return 1;
}
static int tv_set_norm_i(tvi_handle_t *tvh, int norm)
{
tvh->norm = norm;
MP_VERBOSE(tvh, "Selected norm id: %d\n", norm);
if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) {
MP_ERR(tvh, "Error: Cannot set norm!\n");
return 0;
}
return 1;
}
static void set_norm_and_freq(tvi_handle_t *tvh, tv_channels_t *chan)
{
MP_INFO(tvh, "Selected channel: %s - %s (freq: %.3f)\n",
chan->number, chan->name, chan->freq/1000.0);
tv_set_norm_i(tvh, chan->norm);
tv_set_freq_float(tvh, chan->freq);
}
int open_tv(tvi_handle_t *tvh)
{
int i;
const tvi_functions_t *funcs = tvh->functions;
static const int tv_fmt_list[] = {
MP_FOURCC_YV12,
MP_FOURCC_I420,
MP_FOURCC_UYVY,
MP_FOURCC_YUY2,
MP_FOURCC_RGB32,
MP_FOURCC_RGB24,
MP_FOURCC_RGB16,
MP_FOURCC_RGB15
};
if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE)
{
MP_ERR(tvh, "Error: No video input present!\n");
return 0;
}
if (tvh->tv_param->outfmt == -1)
for (i = 0; i < sizeof (tv_fmt_list) / sizeof (*tv_fmt_list); i++)
{
tvh->tv_param->outfmt = tv_fmt_list[i];
if (funcs->control (tvh->priv, TVI_CONTROL_VID_SET_FORMAT,
&tvh->tv_param->outfmt) == TVI_CONTROL_TRUE)
break;
}
else
{
switch(tvh->tv_param->outfmt)
{
case MP_FOURCC_YV12:
case MP_FOURCC_I420:
case MP_FOURCC_UYVY:
case MP_FOURCC_YUY2:
case MP_FOURCC_RGB32:
case MP_FOURCC_RGB24:
case MP_FOURCC_BGR32:
case MP_FOURCC_BGR24:
case MP_FOURCC_BGR16:
case MP_FOURCC_BGR15:
break;
default:
MP_ERR(tvh, "==================================================================\n"\
" WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\
" This may cause buggy playback or program crash! Bug reports will\n"\
" be ignored! You should try again with YV12 (which is the default\n"\
" colorspace) and read the documentation!\n"\
"==================================================================\n"
,tvh->tv_param->outfmt);
}
funcs->control(tvh->priv, TVI_CONTROL_VID_SET_FORMAT, &tvh->tv_param->outfmt);
}
/* set some params got from cmdline */
funcs->control(tvh->priv, TVI_CONTROL_SPC_SET_INPUT, &tvh->tv_param->input);
if ((!strcmp(tvh->tv_param->driver, "v4l2") && tvh->tv_param->normid >= 0))
tv_set_norm_i(tvh, tvh->tv_param->normid);
else
tv_set_norm(tvh,tvh->tv_param->norm);
/* limits on w&h are norm-dependent -- JM */
if (tvh->tv_param->width != -1 && tvh->tv_param->height != -1) {
// first tell the driver both width and height, some drivers do not support setting them independently.
int dim[2];
dim[0] = tvh->tv_param->width; dim[1] = tvh->tv_param->height;
funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH_HEIGHT, dim);
}
/* set width */
if (tvh->tv_param->width != -1)
{
if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_WIDTH, &tvh->tv_param->width) == TVI_CONTROL_TRUE)
funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH, &tvh->tv_param->width);
else
{
MP_ERR(tvh, "Unable to set requested width: %d\n", tvh->tv_param->width);
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &tvh->tv_param->width);
}
}
/* set height */
if (tvh->tv_param->height != -1)
{
if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_HEIGHT, &tvh->tv_param->height) == TVI_CONTROL_TRUE)
funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HEIGHT, &tvh->tv_param->height);
else
{
MP_ERR(tvh, "Unable to set requested height: %d\n", tvh->tv_param->height);
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &tvh->tv_param->height);
}
}
if (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE)
{
MP_WARN(tvh, "Selected input hasn't got a tuner!\n");
goto done;
}
/* select channel list */
for (i = 0; chanlists[i].name != NULL; i++)
{
if (!strcasecmp(chanlists[i].name, tvh->tv_param->chanlist))
{
tvh->chanlist = i;
tvh->chanlist_s = chanlists[i].list;
break;
}
}
if (tvh->chanlist == -1) {
MP_WARN(tvh, "Unable to find selected channel list! (%s)\n",
tvh->tv_param->chanlist);
return 0;
} else
MP_VERBOSE(tvh, "Selected channel list: %s (including %d channels)\n",
chanlists[tvh->chanlist].name, chanlists[tvh->chanlist].count);
if (tvh->tv_param->freq && tvh->tv_param->channel)
{
MP_WARN(tvh, "You can't set frequency and channel simultaneously!\n");
goto done;
}
/* Handle channel names */
if (tvh->tv_param->channels) {
parse_channels(tvh);
} else
tvh->tv_channel_last_real = malloc(5);
if (tvh->tv_channel_list) {
int channel = 0;
if (tvh->tv_param->channel)
{
if (mp_isdigit(*tvh->tv_param->channel))
/* if tvh->tv_param->channel begins with a digit interpret it as a number */
channel = atoi(tvh->tv_param->channel);
else
{
/* if tvh->tv_param->channel does not begin with a digit
set the first channel that contains tvh->tv_param->channel in its name */
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;
tvh->tv_channel_current = tvh->tv_channel_current->next;
}
if ( !tvh->tv_channel_current ) tvh->tv_channel_current = tvh->tv_channel_list;
}
}
else
channel = 1;
if ( channel ) {
tvh->tv_channel_current = tvh->tv_channel_list;
for (int n = 1; n < channel; n++)
if (tvh->tv_channel_current->next)
tvh->tv_channel_current = tvh->tv_channel_current->next;
}
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)
{
unsigned long freq = tvh->tv_param->freq * 16;
/* set freq in MHz */
funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq);
funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
MP_VERBOSE(tvh, "Selected frequency: %lu (%.3f)\n",
freq, freq/16.0);
}
if (tvh->tv_param->channel) {
struct CHANLIST cl;
MP_VERBOSE(tvh, "Requested channel: %s\n", tvh->tv_param->channel);
for (i = 0; i < chanlists[tvh->chanlist].count; i++)
{
cl = tvh->chanlist_s[i];
// printf("count%d: name: %s, freq: %d\n",
// i, cl.name, cl.freq);
if (!strcasecmp(cl.name, tvh->tv_param->channel))
{
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);
tv_set_freq_float(tvh, cl.freq);
break;
}
}
}
}
/* grep frequency in chanlist */
{
unsigned long i2 = 0;
int freq;
tv_get_freq(tvh, &i2);
freq = (int) (((float)(i2/16))*1000)+250;
for (i = 0; i < chanlists[tvh->chanlist].count; i++)
{
if (tvh->chanlist_s[i].freq == freq)
{
tvh->channel = i+1;
break;
}
}
}
done:
/* also start device! */
return 1;
}
tvi_handle_t *tv_begin(tv_param_t* tv_param, struct mp_log *log)
{
int i;
tvi_handle_t* h;
if(tv_param->driver && !strcmp(tv_param->driver,"help")){
mp_info(log, "Available drivers:\n");
for(i=0;tvi_driver_list[i];i++){
mp_info(log, " %s\t%s\n",tvi_driver_list[i]->short_name,tvi_driver_list[i]->name);
}
return NULL;
}
for(i=0;tvi_driver_list[i];i++){
if (!tv_param->driver || !strcmp(tvi_driver_list[i]->short_name, tv_param->driver)){
h=tvi_driver_list[i]->tvi_init(log, tv_param);
//Requested driver initialization failed
if (!h && tv_param->driver)
return NULL;
//Driver initialization failed during autodetection process.
if (!h)
continue;
h->tv_param=tv_param;
MP_INFO(h, "Selected driver: %s\n name: %s\n", tvi_driver_list[i]->short_name,
tvi_driver_list[i]->name);
talloc_free(tv_param->driver);
tv_param->driver=talloc_strdup(NULL, tvi_driver_list[i]->short_name);
return h;
}
}
if(tv_param->driver)
mp_err(log, "No such driver: %s\n", tv_param->driver);
else
mp_err(log, "TV driver autodetection failed.\n");
return NULL;
}
int tv_uninit(tvi_handle_t *tvh)
{
int res;
if(!tvh) return 1;
if (!tvh->priv) return 1;
res=tvh->functions->uninit(tvh->priv);
if(res) {
free(tvh->priv);
tvh->priv=NULL;
}
return res;
}
int tv_set_color_options(tvi_handle_t *tvh, int opt, int value)
{
const tvi_functions_t *funcs = tvh->functions;
switch(opt)
{
case TV_COLOR_BRIGHTNESS:
return funcs->control(tvh->priv, TVI_CONTROL_VID_SET_BRIGHTNESS, &value);
case TV_COLOR_HUE:
return funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HUE, &value);
case TV_COLOR_SATURATION:
return funcs->control(tvh->priv, TVI_CONTROL_VID_SET_SATURATION, &value);
case TV_COLOR_CONTRAST:
return funcs->control(tvh->priv, TVI_CONTROL_VID_SET_CONTRAST, &value);
default:
MP_WARN(tvh, "Unknown color option (%d) specified!\n", opt);
}
return TVI_CONTROL_UNKNOWN;
}
int tv_get_color_options(tvi_handle_t *tvh, int opt, int* value)
{
const tvi_functions_t *funcs = tvh->functions;
switch(opt)
{
case TV_COLOR_BRIGHTNESS:
return funcs->control(tvh->priv, TVI_CONTROL_VID_GET_BRIGHTNESS, value);
case TV_COLOR_HUE:
return funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HUE, value);
case TV_COLOR_SATURATION:
return funcs->control(tvh->priv, TVI_CONTROL_VID_GET_SATURATION, value);
case TV_COLOR_CONTRAST:
return funcs->control(tvh->priv, TVI_CONTROL_VID_GET_CONTRAST, value);
default:
MP_WARN(tvh, "Unknown color option (%d) specified!\n", opt);
}
return TVI_CONTROL_UNKNOWN;
}
int tv_get_freq(tvi_handle_t *tvh, unsigned long *freq)
{
if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) == TVI_CONTROL_TRUE)
{
tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, freq);
MP_VERBOSE(tvh, "Current frequency: %lu (%.3f)\n",
*freq, *freq/16.0);
}
return 1;
}
int tv_set_freq(tvi_handle_t *tvh, unsigned long freq)
{
if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) == TVI_CONTROL_TRUE)
{
// unsigned long freq = atof(tvh->tv_param->freq)*16;
/* set freq in MHz */
tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq);
tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
MP_VERBOSE(tvh, "Current frequency: %lu (%.3f)\n",
freq, freq/16.0);
}
return 1;
}
int tv_get_signal(tvi_handle_t *tvh)
{
int signal=0;
if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE ||
tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_SIGNAL, &signal)!=TVI_CONTROL_TRUE)
return 0;
return signal;
}
/*****************************************************************
* \brief tune current frequency by step_interval value
* \parameter step_interval increment value in 1/16 MHz
* \note frequency is rounded to 1/16 MHz value
* \return 1
*
*/
int tv_step_freq(tvi_handle_t* tvh, float step_interval){
unsigned long frequency = 0;
tvh->tv_param->scan=0;
tv_get_freq(tvh,&frequency);
frequency+=step_interval;
return tv_set_freq(tvh,frequency);
}
int tv_step_channel_real(tvi_handle_t *tvh, int direction)
{
struct CHANLIST cl;
tvh->tv_param->scan=0;
if (direction == TV_CHANNEL_LOWER)
{
if (tvh->channel-1 >= 0)
{
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);
tv_set_freq_float(tvh, cl.freq);
}
}
if (direction == TV_CHANNEL_HIGHER)
{
if (tvh->channel+1 < chanlists[tvh->chanlist].count)
{
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);
tv_set_freq_float(tvh, cl.freq);
}
}
return 1;
}
int tv_step_channel(tvi_handle_t *tvh, int direction) {
tvh->tv_param->scan=0;
if (tvh->tv_channel_list) {
if (direction == TV_CHANNEL_HIGHER) {
tvh->tv_channel_last = tvh->tv_channel_current;
if (tvh->tv_channel_current->next)
tvh->tv_channel_current = tvh->tv_channel_current->next;
else
tvh->tv_channel_current = tvh->tv_channel_list;
set_norm_and_freq(tvh, tvh->tv_channel_current);
}
if (direction == TV_CHANNEL_LOWER) {
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 (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;
}
int tv_set_channel_real(tvi_handle_t *tvh, char *channel) {
int i;
struct CHANLIST cl;
tvh->tv_param->scan=0;
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];
// printf("count%d: name: %s, freq: %d\n",
// i, cl.name, cl.freq);
if (!strcasecmp(cl.name, channel))
{
tvh->channel = i;
MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n",
cl.name, cl.freq/1000.0);
tv_set_freq_float(tvh, cl.freq);
break;
}
}
return 1;
}
int tv_set_channel(tvi_handle_t *tvh, char *channel) {
int i, channel_int;
tvh->tv_param->scan=0;
if (tvh->tv_channel_list) {
tvh->tv_channel_last = tvh->tv_channel_current;
channel_int = atoi(channel);
tvh->tv_channel_current = tvh->tv_channel_list;
for (i = 1; i < channel_int; i++)
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;
}
int tv_last_channel(tvi_handle_t *tvh) {
tvh->tv_param->scan=0;
if (tvh->tv_channel_list) {
tv_channels_t *tmp;
tmp = tvh->tv_channel_last;
tvh->tv_channel_last = tvh->tv_channel_current;
tvh->tv_channel_current = tmp;
set_norm_and_freq(tvh, tvh->tv_channel_current);
} else {
int i;
struct CHANLIST cl;
for (i = 0; i < chanlists[tvh->chanlist].count; i++)
{
cl = tvh->chanlist_s[i];
if (!strcasecmp(cl.name, tvh->tv_channel_last_real))
{
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);
tv_set_freq_float(tvh, cl.freq);
break;
}
}
}
return 1;
}
int tv_step_norm(tvi_handle_t *tvh)
{
tvh->norm++;
if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM,
&tvh->norm) != TVI_CONTROL_TRUE) {
tvh->norm = 0;
if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM,
&tvh->norm) != TVI_CONTROL_TRUE) {
MP_ERR(tvh, "Error: Cannot set norm!\n");
return 0;
}
}
return 1;
}
int tv_stream_control(tvi_handle_t *tvh, int cmd, void *arg)
{
switch (cmd) {
case STREAM_CTRL_TV_SET_SCAN:
tv_start_scan(tvh, *(int *)arg);
return STREAM_OK;
case STREAM_CTRL_SET_TV_FREQ:
tv_set_freq(tvh, *(float *)arg * 16.0f);
return STREAM_OK;
case STREAM_CTRL_GET_TV_FREQ: {
unsigned long tmp = 0;
tv_get_freq(tvh, &tmp);
*(float *)arg = tmp / 16.0f;
return STREAM_OK;
}
case STREAM_CTRL_SET_TV_COLORS:
tv_set_color_options(tvh, ((int *)arg)[0], ((int *)arg)[1]);
return STREAM_OK;
case STREAM_CTRL_GET_TV_COLORS:
tv_get_color_options(tvh, ((int *)arg)[0], &((int *)arg)[1]);
return STREAM_OK;
case STREAM_CTRL_TV_SET_NORM:
tv_set_norm(tvh, (char *)arg);
return STREAM_OK;
case STREAM_CTRL_TV_STEP_NORM:
tv_step_norm(tvh);
return STREAM_OK;
case STREAM_CTRL_TV_SET_CHAN:
tv_set_channel(tvh, (char *)arg);
return STREAM_OK;
case STREAM_CTRL_TV_STEP_CHAN:
if (*(int *)arg >= 0) {
tv_step_channel(tvh, TV_CHANNEL_HIGHER);
} else {
tv_step_channel(tvh, TV_CHANNEL_LOWER);
}
return STREAM_OK;
case STREAM_CTRL_TV_LAST_CHAN:
tv_last_channel(tvh);
return STREAM_OK;
}
return STREAM_UNSUPPORTED;
}

View File

@ -1,285 +0,0 @@
/*
* TV interface
*
* Copyright (C) 2001 Alex Beregszászi
* Copyright (C) 2007 Attila Ötvös
* Copyright (C) 2007 Vladimir Voroshilov <voroshil@gmail.com>
*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MPLAYER_TV_H
#define MPLAYER_TV_H
#include "osdep/endian.h"
#include "config.h"
#if !HAVE_GPL
#error GPL only
#endif
struct mp_log;
typedef struct tv_params {
float freq;
char *channel;
char *chanlist;
char *norm;
int automute;
int normid;
char *device;
char *driver;
int width;
int height;
int input;
int outfmt;
float fps;
char **channels;
int audio;
int immediate;
int audiorate;
int audio_id;
int amode;
int volume;
int bass;
int treble;
int balance;
int forcechan;
int force_audio;
int buffer_size;
int mjpeg;
int decimation;
int quality;
int alsa;
char* adevice;
int brightness;
int contrast;
int hue;
int saturation;
int gain;
int scan;
int scan_threshold;
float scan_period;
} tv_param_t;
struct tv_stream_params {
char *channel;
int input;
};
typedef struct tvi_info_s
{
struct tvi_handle_s * (*tvi_init)(struct mp_log *log, tv_param_t* tv_param);
const char *name;
const char *short_name;
} tvi_info_t;
struct priv;
typedef struct tvi_functions_s
{
int (*init)(struct priv *priv);
int (*uninit)(struct priv *priv);
int (*control)(struct priv *priv, int cmd, void *arg);
int (*start)(struct priv *priv);
double (*grab_video_frame)(struct priv *priv, char *buffer, int len);
int (*get_video_framesize)(struct priv *priv);
double (*grab_audio_frame)(struct priv *priv, char *buffer, int len);
int (*get_audio_framesize)(struct priv *priv);
} tvi_functions_t;
typedef struct tvi_handle_s {
struct mp_log *log;
const tvi_functions_t *functions;
void *priv;
int seq;
struct demuxer *demuxer;
/* specific */
int norm;
int chanlist;
const struct CHANLIST *chanlist_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 {
int index;
char number[5];
char name[20];
int norm;
int freq;
struct tv_channels_s *next;
struct tv_channels_s *prev;
} tv_channels_t;
typedef struct {
unsigned int scan_timer;
int channel_num;
int new_channels;
} tv_scan_t;
#define TVI_CONTROL_FALSE 0
#define TVI_CONTROL_TRUE 1
#define TVI_CONTROL_NA -1
#define TVI_CONTROL_UNKNOWN -2
/* ======================== CONTROLS =========================== */
/* GENERIC controls */
#define TVI_CONTROL_IS_AUDIO 0x1
#define TVI_CONTROL_IS_VIDEO 0x2
#define TVI_CONTROL_IS_TUNER 0x3
#define TVI_CONTROL_IMMEDIATE 0x4
/* VIDEO controls */
#define TVI_CONTROL_VID_GET_FPS 0x101
#define TVI_CONTROL_VID_GET_PLANES 0x102
#define TVI_CONTROL_VID_GET_BITS 0x103
#define TVI_CONTROL_VID_CHK_BITS 0x104
#define TVI_CONTROL_VID_SET_BITS 0x105
#define TVI_CONTROL_VID_GET_FORMAT 0x106
#define TVI_CONTROL_VID_CHK_FORMAT 0x107
#define TVI_CONTROL_VID_SET_FORMAT 0x108
#define TVI_CONTROL_VID_GET_WIDTH 0x109
#define TVI_CONTROL_VID_CHK_WIDTH 0x110
#define TVI_CONTROL_VID_SET_WIDTH 0x111
#define TVI_CONTROL_VID_GET_HEIGHT 0x112
#define TVI_CONTROL_VID_CHK_HEIGHT 0x113
#define TVI_CONTROL_VID_SET_HEIGHT 0x114
#define TVI_CONTROL_VID_GET_BRIGHTNESS 0x115
#define TVI_CONTROL_VID_SET_BRIGHTNESS 0x116
#define TVI_CONTROL_VID_GET_HUE 0x117
#define TVI_CONTROL_VID_SET_HUE 0x118
#define TVI_CONTROL_VID_GET_SATURATION 0x119
#define TVI_CONTROL_VID_SET_SATURATION 0x11a
#define TVI_CONTROL_VID_GET_CONTRAST 0x11b
#define TVI_CONTROL_VID_SET_CONTRAST 0x11c
#define TVI_CONTROL_VID_GET_PICTURE 0x11d
#define TVI_CONTROL_VID_SET_PICTURE 0x11e
#define TVI_CONTROL_VID_SET_GAIN 0x11f
#define TVI_CONTROL_VID_GET_GAIN 0x120
#define TVI_CONTROL_VID_SET_WIDTH_HEIGHT 0x121
/* TUNER controls */
#define TVI_CONTROL_TUN_GET_FREQ 0x201
#define TVI_CONTROL_TUN_SET_FREQ 0x202
#define TVI_CONTROL_TUN_GET_TUNER 0x203 /* update priv->tuner struct for used input */
#define TVI_CONTROL_TUN_SET_TUNER 0x204 /* update priv->tuner struct for used input */
#define TVI_CONTROL_TUN_GET_NORM 0x205
#define TVI_CONTROL_TUN_SET_NORM 0x206
#define TVI_CONTROL_TUN_GET_SIGNAL 0x207
/* AUDIO controls */
#define TVI_CONTROL_AUD_GET_FORMAT 0x301
#define TVI_CONTROL_AUD_GET_SAMPLERATE 0x302
#define TVI_CONTROL_AUD_GET_CHANNELS 0x304
#define TVI_CONTROL_AUD_SET_SAMPLERATE 0x305
/* SPECIFIC controls */
#define TVI_CONTROL_SPC_GET_INPUT 0x401 /* set input channel (tv,s-video,composite..) */
#define TVI_CONTROL_SPC_SET_INPUT 0x402 /* set input channel (tv,s-video,composite..) */
#define TVI_CONTROL_SPC_GET_NORMID 0x403 /* get normid from norm name */
int tv_set_color_options(tvi_handle_t *tvh, int opt, int val);
int tv_get_color_options(tvi_handle_t *tvh, int opt, int* val);
int tv_step_channel_real(tvi_handle_t *tvh, int direction);
int tv_step_channel(tvi_handle_t *tvh, int direction);
#define TV_CHANNEL_LOWER 1
#define TV_CHANNEL_HIGHER 2
int tv_last_channel(tvi_handle_t *tvh);
int tv_set_channel_real(tvi_handle_t *tvh, char *channel);
int tv_set_channel(tvi_handle_t *tvh, char *channel);
int tv_step_norm(tvi_handle_t *tvh);
int tv_step_chanlist(tvi_handle_t *tvh);
int tv_set_freq(tvi_handle_t *tvh, unsigned long freq);
int tv_get_freq(tvi_handle_t *tvh, unsigned long *freq);
int tv_get_signal(tvi_handle_t *tvh);
int tv_step_freq(tvi_handle_t *tvh, float step_interval);
int tv_set_norm(tvi_handle_t *tvh, char* norm);
void tv_start_scan(tvi_handle_t *tvh, int start);
tvi_handle_t *tv_new_handle(int size, struct mp_log *log, const tvi_functions_t *functions);
void tv_free_handle(tvi_handle_t *h);
#define TV_NORM_PAL 1
#define TV_NORM_NTSC 2
#define TV_NORM_SECAM 3
#define TV_NORM_PALNC 4
#define TV_NORM_PALM 5
#define TV_NORM_PALN 6
#define TV_NORM_NTSCJP 7
int tv_uninit(tvi_handle_t *tvh);
void tv_scan(tvi_handle_t *tvh);
int open_tv(tvi_handle_t *tvh);
tvi_handle_t *tv_begin(tv_param_t* tv_param, struct mp_log *log);
int tv_stream_control(tvi_handle_t *tvh, int cmd, void *arg);
extern const struct m_sub_options tv_params_conf;
#define MP_FOURCC(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((unsigned)(d)<<24))
#if BYTE_ORDER == BIG_ENDIAN
#define MP_FOURCC_E(a,b,c,d) MP_FOURCC(a,b,c,d)
#else
#define MP_FOURCC_E(a,b,c,d) MP_FOURCC(d,c,b,a)
#endif
#define MP_FOURCC_RGB8 MP_FOURCC_E(8, 'B', 'G', 'R')
#define MP_FOURCC_RGB12 MP_FOURCC_E(12, 'B', 'G', 'R')
#define MP_FOURCC_RGB15 MP_FOURCC_E(15, 'B', 'G', 'R')
#define MP_FOURCC_RGB16 MP_FOURCC_E(16, 'B', 'G', 'R')
#define MP_FOURCC_RGB24 MP_FOURCC_E(24, 'B', 'G', 'R')
#define MP_FOURCC_RGB32 MP_FOURCC_E('A', 'B', 'G', 'R')
#define MP_FOURCC_BGR8 MP_FOURCC_E(8, 'R', 'G', 'B')
#define MP_FOURCC_BGR12 MP_FOURCC_E(12, 'R', 'G', 'B')
#define MP_FOURCC_BGR15 MP_FOURCC_E(15, 'R', 'G', 'B')
#define MP_FOURCC_BGR16 MP_FOURCC_E(16, 'R', 'G', 'B')
#define MP_FOURCC_BGR24 MP_FOURCC_E(24, 'R', 'G', 'B')
#define MP_FOURCC_BGR32 MP_FOURCC_E('A', 'R', 'G', 'B')
#define MP_FOURCC_YVU9 MP_FOURCC('Y', 'U', 'V', '9')
#define MP_FOURCC_YUV9 MP_FOURCC('Y', 'V', 'U', '9')
#define MP_FOURCC_YV12 MP_FOURCC('Y', 'V', '1', '2')
#define MP_FOURCC_I420 MP_FOURCC('I', '4', '2', '0')
#define MP_FOURCC_IYUV MP_FOURCC('I', 'Y', 'U', 'V')
#define MP_FOURCC_Y800 MP_FOURCC('Y', '8', '0', '0')
#define MP_FOURCC_NV12 MP_FOURCC('N', 'V', '1', '2')
#define MP_FOURCC_NV21 MP_FOURCC('N', 'V', '2', '1')
#define MP_FOURCC_UYVY MP_FOURCC('U', 'Y', 'V', 'Y')
#define MP_FOURCC_YUY2 MP_FOURCC('Y', 'U', 'Y', '2')
#define MP_FOURCC_MJPEG MP_FOURCC('M', 'J', 'P', 'G')
#define MP_FOURCC_JPEG MP_FOURCC('J', 'P', 'E', 'G')
#endif /* MPLAYER_TV_H */

View File

@ -1,93 +0,0 @@
/*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MPLAYER_TVI_DEF_H
#define MPLAYER_TVI_DEF_H
#include <stdlib.h> /* malloc */
#include <string.h> /* memset */
#include "tv.h"
static int init(priv_t *priv);
static int uninit(priv_t *priv);
static int do_control(priv_t *priv, int cmd, void *arg);
static int start(priv_t *priv);
static double grab_video_frame(priv_t *priv, char *buffer, int len);
static int get_video_framesize(priv_t *priv);
static double grab_audio_frame(priv_t *priv, char *buffer, int len);
static int get_audio_framesize(priv_t *priv);
static const tvi_functions_t functions =
{
init,
uninit,
do_control,
start,
grab_video_frame,
get_video_framesize,
grab_audio_frame,
get_audio_framesize
};
/**
Fills video frame in given buffer with blue color for yv12,i420,uyvy,yuy2.
Other formats will be filled with 0xC0
*/
static inline void fill_blank_frame(char* buffer,int len,int fmt){
int i;
// RGB(0,0,255) <-> YVU(41,110,240)
switch(fmt){
case MP_FOURCC_YV12:
memset(buffer, 41,4*len/6); //Y
memset(buffer+4*len/6, 110,len/6);//V
memset(buffer+5*len/6, 240,len/6);//U
break;
case MP_FOURCC_I420:
memset(buffer, 41,4*len/6); //Y
memset(buffer+4*len/6, 240,len/6);//U
memset(buffer+5*len/6, 110,len/6);//V
break;
case MP_FOURCC_UYVY:
for(i=0;i<len;i+=4){
buffer[i]=0xFF;
buffer[i+1]=0;
buffer[i+2]=0;
buffer[i+3]=0;
}
break;
case MP_FOURCC_YUY2:
for(i=0;i<len;i+=4){
buffer[i]=0;
buffer[i+1]=0xFF;
buffer[i+2]=0;
buffer[i+3]=0;
}
break;
case MP_FOURCC_MJPEG:
case MP_FOURCC_JPEG:
/*
This is compressed format. I don't know yet how to fill such frame with blue color.
Keeping frame unchanged.
*/
break;
default:
memset(buffer,0xC0,len);
}
}
#endif /* MPLAYER_TVI_DEF_H */

View File

@ -1,126 +0,0 @@
/*
* Only a sample!
*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include "common/common.h"
#include "tv.h"
static tvi_handle_t *tvi_init_dummy(struct mp_log *log, tv_param_t* tv_param);
/* information about this file */
const tvi_info_t tvi_info_dummy = {
tvi_init_dummy,
"NULL-TV",
"dummy",
};
/* private data's */
typedef struct priv {
int width;
int height;
} priv_t;
#include "tvi_def.h"
/* handler creator - entry point ! */
static tvi_handle_t *tvi_init_dummy(struct mp_log *log, tv_param_t* tv_param)
{
return tv_new_handle(sizeof(priv_t), log, &functions);
}
/* initialisation */
static int init(priv_t *priv)
{
priv->width = 320;
priv->height = 200;
return 1;
}
/* that's the real start, we'got the format parameters (checked with control) */
static int start(priv_t *priv)
{
return 1;
}
static int uninit(priv_t *priv)
{
return 1;
}
static int do_control(priv_t *priv, int cmd, void *arg)
{
switch(cmd)
{
case TVI_CONTROL_IS_VIDEO:
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_FORMAT:
*(int *)arg = MP_FOURCC_YV12;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_FORMAT:
{
// int req_fmt = *(int *)arg;
int req_fmt = *(int *)arg;
if (req_fmt != MP_FOURCC_YV12)
return TVI_CONTROL_FALSE;
return TVI_CONTROL_TRUE;
}
case TVI_CONTROL_VID_SET_WIDTH:
priv->width = *(int *)arg;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_WIDTH:
*(int *)arg = priv->width;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_HEIGHT:
priv->height = *(int *)arg;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_HEIGHT:
*(int *)arg = priv->height;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_CHK_WIDTH:
case TVI_CONTROL_VID_CHK_HEIGHT:
return TVI_CONTROL_TRUE;
case TVI_CONTROL_TUN_SET_NORM:
return TVI_CONTROL_TRUE;
}
return TVI_CONTROL_UNKNOWN;
}
static double grab_video_frame(priv_t *priv, char *buffer, int len)
{
memset(buffer, 0x42, len);
return MP_NOPTS_VALUE;
}
static int get_video_framesize(priv_t *priv)
{
/* YV12 */
return priv->width * priv->height * 12 / 8;
}
static double grab_audio_frame(priv_t *priv, char *buffer, int len)
{
memset(buffer, 0x42, len);
return MP_NOPTS_VALUE;
}
static int get_audio_framesize(priv_t *priv)
{
return 1;
}

File diff suppressed because it is too large Load Diff

49
wscript
View File

@ -409,6 +409,12 @@ iconv support use --disable-iconv.",
'name': '--libarchive',
'desc': 'libarchive wrapper for reading zip files and more',
'func': check_pkg_config('libarchive >= 3.0.0'),
}, {
'name': '--dvbin',
'desc': 'DVB input module',
'deps': 'gpl',
'func': check_true,
'default': 'disable',
}
]
@ -874,47 +880,6 @@ hwaccel_features = [
}
]
radio_and_tv_features = [
{
'name': '--tv',
'desc': 'TV interface',
'deps': 'gpl',
'func': check_true,
'default': 'disable',
}, {
'name': 'sys_videoio_h',
'desc': 'videoio.h',
'func': check_cc(header_name=['sys/time.h', 'sys/videoio.h']),
'deps': 'tv',
}, {
'name': 'videodev',
'desc': 'videodev2.h',
'func': check_cc(header_name=['sys/time.h', 'linux/videodev2.h']),
'deps': 'tv && !sys_videoio_h',
}, {
'name': '--tv-v4l2',
'desc': 'Video4Linux2 TV interface',
'deps': 'tv && (sys_videoio_h || videodev)',
'func': check_true,
}, {
'name': '--libv4l2',
'desc': 'libv4l2 support',
'func': check_pkg_config('libv4l2'),
'deps': 'tv-v4l2',
}, {
'name': '--audio-input',
'desc': 'audio input support',
'deps': 'tv-v4l2',
'func': check_true
} , {
'name': '--dvbin',
'desc': 'DVB input module',
'deps': 'gpl',
'func': check_true,
'default': 'disable',
}
]
standalone_features = [
{
'name': 'win32-executable',
@ -1003,7 +968,6 @@ def options(opt):
opt.parse_features('audio outputs', audio_output_features)
opt.parse_features('video outputs', video_output_features)
opt.parse_features('hwaccels', hwaccel_features)
opt.parse_features('tv features', radio_and_tv_features)
opt.parse_features('standalone app', standalone_features)
group = opt.get_option_group("optional features")
@ -1076,7 +1040,6 @@ def configure(ctx):
ctx.parse_dependencies(video_output_features)
ctx.parse_dependencies(libav_dependencies)
ctx.parse_dependencies(hwaccel_features)
ctx.parse_dependencies(radio_and_tv_features)
if ctx.options.LUA_VER:
ctx.options.enable_lua = True

View File

@ -286,7 +286,6 @@ def build(ctx):
( "demux/demux_rar.c" ),
( "demux/demux_raw.c" ),
( "demux/demux_timeline.c" ),
( "demux/demux_tv.c", "tv" ),
( "demux/ebml.c" ),
( "demux/packet.c" ),
( "demux/timeline.c" ),
@ -353,13 +352,8 @@ def build(ctx):
( "player/video.c" ),
## Streams
( "stream/ai_alsa1x.c", "alsa && audio-input" ),
( "stream/ai_oss.c", "oss-audio && audio-input" ),
( "stream/ai_sndio.c", "sndio && audio-input" ),
( "stream/audio_in.c", "audio-input" ),
( "stream/cookies.c" ),
( "stream/dvb_tune.c", "dvbin" ),
( "stream/frequencies.c", "tv" ),
( "stream/rar.c" ),
( "stream/stream.c" ),
( "stream/stream_avdevice.c" ),
@ -377,10 +371,6 @@ def build(ctx):
( "stream/stream_null.c" ),
( "stream/stream_rar.c" ),
( "stream/stream_smb.c", "libsmbclient" ),
( "stream/stream_tv.c", "tv" ),
( "stream/tv.c", "tv" ),
( "stream/tvi_dummy.c", "tv" ),
( "stream/tvi_v4l2.c", "tv-v4l2"),
## Subtitles
( "sub/ass_mp.c", "libass"),