2001-11-10 23:32:10 +00:00
|
|
|
/*
|
2001-12-03 16:38:40 +00:00
|
|
|
Video 4 Linux input
|
2001-11-10 23:32:10 +00:00
|
|
|
|
|
|
|
(C) Alex Beregszaszi <alex@naxine.org>
|
|
|
|
|
|
|
|
Some ideas are based on xawtv/libng's grab-v4l.c written by
|
|
|
|
Gerd Knorr <kraxel@bytesex.org>
|
|
|
|
|
|
|
|
CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE!
|
|
|
|
*/
|
|
|
|
|
2001-11-09 23:46:06 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-12-01 15:05:40 +00:00
|
|
|
#if defined(USE_TV) && defined(HAVE_TV_V4L)
|
2001-11-09 23:46:06 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2001-11-10 23:32:10 +00:00
|
|
|
#include <signal.h>
|
2001-11-09 23:46:06 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <linux/videodev.h>
|
2001-12-27 23:52:48 +00:00
|
|
|
#include <linux/soundcard.h>
|
2001-11-09 23:46:06 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
2001-11-16 21:30:10 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-11 13:47:42 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "../libao2/afmt.h"
|
|
|
|
#include "../libvo/img_format.h"
|
|
|
|
#include "../libvo/fastmemcpy.h"
|
|
|
|
|
2001-11-09 23:46:06 +00:00
|
|
|
#include "tv.h"
|
|
|
|
|
|
|
|
static tvi_info_t info = {
|
2001-12-27 23:52:48 +00:00
|
|
|
"Video 4 Linux input",
|
2001-11-09 23:46:06 +00:00
|
|
|
"v4l",
|
2001-11-10 23:32:10 +00:00
|
|
|
"Alex Beregszaszi <alex@naxine.org>",
|
|
|
|
"under development"
|
|
|
|
};
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
#define MAX_AUDIO_CHANNELS 10
|
|
|
|
|
2001-11-09 23:46:06 +00:00
|
|
|
typedef struct {
|
2001-11-10 23:32:10 +00:00
|
|
|
/* general */
|
2001-11-09 23:46:06 +00:00
|
|
|
char *video_device;
|
2001-12-27 23:52:48 +00:00
|
|
|
int video_fd;
|
2001-11-09 23:46:06 +00:00
|
|
|
struct video_capability capability;
|
|
|
|
struct video_channel *channels;
|
2001-11-11 16:28:12 +00:00
|
|
|
int act_channel;
|
2001-11-09 23:46:06 +00:00
|
|
|
struct video_tuner tuner;
|
2001-11-10 23:32:10 +00:00
|
|
|
|
|
|
|
/* video */
|
2001-11-09 23:46:06 +00:00
|
|
|
struct video_picture picture;
|
2001-11-10 23:32:10 +00:00
|
|
|
int format; /* output format */
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int bytesperline;
|
2001-11-09 23:46:06 +00:00
|
|
|
|
|
|
|
struct video_mbuf mbuf;
|
2001-11-10 23:32:10 +00:00
|
|
|
unsigned char *mmap;
|
2001-11-09 23:46:06 +00:00
|
|
|
struct video_mmap *buf;
|
2001-11-10 23:32:10 +00:00
|
|
|
int nbuf;
|
|
|
|
int queue;
|
2002-03-15 16:08:14 +00:00
|
|
|
int currentframe;
|
2001-11-10 23:32:10 +00:00
|
|
|
|
|
|
|
/* audio */
|
2001-12-27 23:52:48 +00:00
|
|
|
int audio_id;
|
|
|
|
char *audio_device;
|
|
|
|
struct video_audio audio[MAX_AUDIO_CHANNELS];
|
|
|
|
int audio_fd;
|
|
|
|
int audio_channels[MAX_AUDIO_CHANNELS];
|
|
|
|
int audio_format[MAX_AUDIO_CHANNELS];
|
|
|
|
int audio_samplesize[MAX_AUDIO_CHANNELS];
|
|
|
|
int audio_samplerate[MAX_AUDIO_CHANNELS];
|
|
|
|
int audio_blocksize;
|
2001-11-09 23:46:06 +00:00
|
|
|
} priv_t;
|
|
|
|
|
|
|
|
#include "tvi_def.h"
|
|
|
|
|
2001-11-11 16:28:12 +00:00
|
|
|
static const char *device_cap2name[] = {
|
2001-11-09 23:46:06 +00:00
|
|
|
"capture", "tuner", "teletext", "overlay", "chromakey", "clipping",
|
2001-11-10 23:32:10 +00:00
|
|
|
"frameram", "scales", "monochrome", "subcapture", "mpeg-decoder",
|
|
|
|
"mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL
|
2001-11-09 23:46:06 +00:00
|
|
|
};
|
|
|
|
|
2001-11-11 16:28:12 +00:00
|
|
|
static const char *device_palette2name[] = {
|
2001-11-10 23:32:10 +00:00
|
|
|
"-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422",
|
|
|
|
"yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p",
|
|
|
|
"yuv420p", "yuv410p", NULL
|
|
|
|
};
|
|
|
|
#define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN")
|
|
|
|
|
2001-11-11 16:28:12 +00:00
|
|
|
static const char *audio_mode2name[] = {
|
|
|
|
"unknown", "mono", "stereo", "language1", "language2", NULL
|
|
|
|
};
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
static int palette2depth(int palette)
|
|
|
|
{
|
2001-11-11 01:44:54 +00:00
|
|
|
switch(palette)
|
|
|
|
{
|
2001-11-30 16:59:02 +00:00
|
|
|
/* component */
|
2001-11-11 01:44:54 +00:00
|
|
|
case VIDEO_PALETTE_RGB555:
|
|
|
|
return(15);
|
|
|
|
case VIDEO_PALETTE_RGB565:
|
|
|
|
return(16);
|
|
|
|
case VIDEO_PALETTE_RGB24:
|
|
|
|
return(24);
|
|
|
|
case VIDEO_PALETTE_RGB32:
|
|
|
|
return(32);
|
2001-11-30 16:59:02 +00:00
|
|
|
/* planar */
|
|
|
|
case VIDEO_PALETTE_YUV411P:
|
2001-11-11 01:44:54 +00:00
|
|
|
case VIDEO_PALETTE_YUV420P:
|
2001-11-30 16:59:02 +00:00
|
|
|
case VIDEO_PALETTE_YUV410P:
|
2001-11-11 01:44:54 +00:00
|
|
|
return(12);
|
2001-11-30 16:59:02 +00:00
|
|
|
/* packed */
|
2001-12-27 23:52:48 +00:00
|
|
|
case VIDEO_PALETTE_YUV422P:
|
2001-11-11 01:44:54 +00:00
|
|
|
case VIDEO_PALETTE_YUV422:
|
2001-11-30 16:59:02 +00:00
|
|
|
case VIDEO_PALETTE_YUYV:
|
2001-11-11 01:44:54 +00:00
|
|
|
case VIDEO_PALETTE_UYVY:
|
2001-11-30 16:59:02 +00:00
|
|
|
case VIDEO_PALETTE_YUV420:
|
|
|
|
case VIDEO_PALETTE_YUV411:
|
2001-11-11 01:44:54 +00:00
|
|
|
return(16);
|
|
|
|
}
|
|
|
|
return(-1);
|
2001-11-10 23:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int format2palette(int format)
|
|
|
|
{
|
2001-11-11 01:44:54 +00:00
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case IMGFMT_RGB15:
|
|
|
|
return(VIDEO_PALETTE_RGB555);
|
|
|
|
case IMGFMT_RGB16:
|
|
|
|
return(VIDEO_PALETTE_RGB565);
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
return(VIDEO_PALETTE_RGB24);
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
return(VIDEO_PALETTE_RGB32);
|
|
|
|
case IMGFMT_YV12:
|
2001-12-24 11:01:16 +00:00
|
|
|
case IMGFMT_I420:
|
2001-11-11 01:44:54 +00:00
|
|
|
return(VIDEO_PALETTE_YUV420P);
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
return(VIDEO_PALETTE_YUV422);
|
2001-12-27 23:52:48 +00:00
|
|
|
case IMGFMT_YUY2:
|
|
|
|
return(VIDEO_PALETTE_YUYV);
|
2001-11-11 01:44:54 +00:00
|
|
|
}
|
|
|
|
return(-1);
|
2001-11-10 23:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int one = 1, zero = 0;
|
|
|
|
|
2001-11-09 23:46:06 +00:00
|
|
|
tvi_handle_t *tvi_init_v4l(char *device)
|
|
|
|
{
|
|
|
|
tvi_handle_t *h;
|
|
|
|
priv_t *priv;
|
|
|
|
|
|
|
|
h = new_handle();
|
|
|
|
if (!h)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
priv = h->priv;
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
/* set video device name */
|
2001-11-09 23:46:06 +00:00
|
|
|
if (!device)
|
2002-03-15 16:08:14 +00:00
|
|
|
priv->video_device = strdup("/dev/video");
|
2001-11-09 23:46:06 +00:00
|
|
|
else
|
2001-12-19 12:54:06 +00:00
|
|
|
priv->video_device = strdup(device);
|
|
|
|
|
|
|
|
/* allocation failed */
|
|
|
|
if (!priv->video_device) {
|
|
|
|
free_handle(h);
|
|
|
|
return(NULL);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
/* set audio device name */
|
2002-03-15 16:08:14 +00:00
|
|
|
priv->audio_device = "/dev/dsp";
|
2001-12-27 23:52:48 +00:00
|
|
|
|
2001-11-09 23:46:06 +00:00
|
|
|
return(h);
|
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
static int init(priv_t *priv)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
priv->video_fd = open(priv->video_device, O_RDWR);
|
2002-03-15 16:08:14 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %x\n", priv->video_fd,
|
|
|
|
priv->video_device);
|
2001-12-27 23:52:48 +00:00
|
|
|
if (priv->video_fd == -1)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->video_device, strerror(errno));
|
2001-11-09 23:46:06 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, "Video fd: %d\n", priv->video_fd);
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
/* get capabilities (priv->capability is needed!) */
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno));
|
2001-11-09 23:46:06 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC);
|
2001-11-10 23:32:10 +00:00
|
|
|
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name);
|
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: ");
|
2001-11-11 16:28:12 +00:00
|
|
|
for (i = 0; device_cap2name[i] != NULL; i++)
|
2001-11-09 23:46:06 +00:00
|
|
|
if (priv->capability.type & (1 << i))
|
2001-11-11 16:28:12 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]);
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "\n");
|
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type);
|
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n",
|
2001-11-09 23:46:06 +00:00
|
|
|
priv->capability.minwidth, priv->capability.minheight,
|
|
|
|
priv->capability.maxwidth, priv->capability.maxheight);
|
|
|
|
priv->width = priv->capability.minwidth;
|
|
|
|
priv->height = priv->capability.minheight;
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-11 03:53:42 +00:00
|
|
|
priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels);
|
2001-12-19 12:54:06 +00:00
|
|
|
if (!priv->channels)
|
|
|
|
goto malloc_failed;
|
2001-11-09 23:46:06 +00:00
|
|
|
memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels);
|
|
|
|
for (i = 0; i < priv->capability.channels; i++)
|
|
|
|
{
|
|
|
|
priv->channels[i].channel = i;
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
|
2001-11-11 16:28:12 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%d)\n", i,
|
2001-11-09 23:46:06 +00:00
|
|
|
priv->channels[i].name,
|
|
|
|
(priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "",
|
|
|
|
(priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "",
|
|
|
|
(priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "",
|
2001-11-10 23:32:10 +00:00
|
|
|
(priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "",
|
|
|
|
priv->channels[i].tuners,
|
|
|
|
priv->channels[i].norm);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
/* audio chanlist */
|
2001-11-11 16:28:12 +00:00
|
|
|
if (priv->capability.audios)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Audio devices: %d\n", priv->capability.audios);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->capability.audios; i++)
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
if (i >= MAX_AUDIO_CHANNELS)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "no space for more audio channels (incrase in source!) (%d > %d)\n",
|
|
|
|
i, MAX_AUDIO_CHANNELS);
|
|
|
|
i = priv->capability.audios;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-03 16:38:40 +00:00
|
|
|
priv->audio[i].audio = i;
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1)
|
2001-11-11 16:28:12 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (priv->audio[i].volume <= 0)
|
|
|
|
priv->audio[i].volume = 100;
|
|
|
|
priv->audio[i].flags &= ~VIDEO_AUDIO_MUTE;
|
|
|
|
ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[i]);
|
|
|
|
|
|
|
|
switch(priv->audio[i].mode)
|
|
|
|
{
|
|
|
|
case VIDEO_SOUND_MONO:
|
|
|
|
case VIDEO_SOUND_LANG1:
|
|
|
|
case VIDEO_SOUND_LANG2:
|
|
|
|
priv->audio_channels[i] = 1;
|
|
|
|
break;
|
|
|
|
case VIDEO_SOUND_STEREO:
|
|
|
|
priv->audio_channels[i] = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->audio_format[i] = AFMT_S16_LE;
|
|
|
|
priv->audio_samplerate[i] = 44100;
|
|
|
|
priv->audio_samplesize[i] = /*76000*/priv->audio_channels[i]*
|
|
|
|
16*priv->audio_samplerate[i]/8;
|
|
|
|
|
|
|
|
/* display stuff */
|
2001-12-03 16:38:40 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio,
|
|
|
|
priv->audio[i].name);
|
|
|
|
if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE)
|
2001-11-11 16:28:12 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, "muted=%s ",
|
2001-12-03 16:38:40 +00:00
|
|
|
(priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no");
|
2001-11-11 16:28:12 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, "volume=%d bass=%d treble=%d balance=%d mode=%s\n",
|
2001-12-03 16:38:40 +00:00
|
|
|
priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble,
|
|
|
|
priv->audio[i].balance, audio_mode2name[priv->audio[i].mode]);
|
2001-12-27 23:52:48 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, " channels: %d, samplerate: %d, samplesize: %d, format: %s\n",
|
|
|
|
priv->audio_channels[i], priv->audio_samplerate[i], priv->audio_samplesize[i],
|
|
|
|
audio_out_format_name(priv->audio_format[i]));
|
2001-11-11 16:28:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
if (!(priv->capability.type & VID_TYPE_CAPTURE))
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n");
|
2001-11-10 23:32:10 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* map grab buffer */
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->mbuf.size, priv->mbuf.frames);
|
|
|
|
priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
|
2001-12-27 23:52:48 +00:00
|
|
|
MAP_SHARED, priv->video_fd, 0);
|
2001-11-11 03:53:42 +00:00
|
|
|
if (priv->mmap == (unsigned char *)-1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
|
2001-11-10 23:32:10 +00:00
|
|
|
|
|
|
|
/* num of buffers */
|
|
|
|
priv->nbuf = priv->mbuf.frames;
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
/* video buffers */
|
2001-11-11 03:53:42 +00:00
|
|
|
priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap));
|
2001-12-19 12:54:06 +00:00
|
|
|
if (!priv->buf)
|
|
|
|
goto malloc_failed;
|
2001-11-10 23:32:10 +00:00
|
|
|
memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
/* audio init */
|
2002-03-15 16:08:14 +00:00
|
|
|
#if 1
|
2001-12-27 23:52:48 +00:00
|
|
|
priv->audio_fd = open(priv->audio_device, O_RDONLY);
|
|
|
|
if (priv->audio_fd < 0)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
|
|
|
|
priv->audio_device, strerror(errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ioctl_param;
|
|
|
|
|
|
|
|
fcntl(priv->audio_fd, F_SETFL, O_NONBLOCK);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
ioctl_param = 0x7fff000d; /* 8k */
|
|
|
|
printf("ioctl dsp setfragment: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_SETFRAGMENT, &ioctl_param));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ioctl_param = 0 ;
|
|
|
|
printf("ioctl dsp getfmt: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param));
|
|
|
|
|
|
|
|
printf("Supported formats: %x\n", ioctl_param);
|
|
|
|
if (!(ioctl_param & priv->audio_format[priv->audio_id]))
|
|
|
|
printf("notsupported format\n");
|
|
|
|
|
|
|
|
ioctl_param = priv->audio_format[priv->audio_id];
|
|
|
|
printf("ioctl dsp setfmt: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param));
|
|
|
|
|
|
|
|
// ioctl(priv->audio_fd, SNDCTL_DSP_GETISPACE, &ioctl_param);
|
|
|
|
// printf("getispace: %d\n", ioctl_param);
|
|
|
|
|
|
|
|
if (priv->audio_channels[priv->audio_id] > 2)
|
|
|
|
{
|
|
|
|
ioctl_param = priv->audio_channels[priv->audio_id];
|
|
|
|
printf("ioctl dsp channels: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if (priv->audio_channels[priv->audio_id] == 2)
|
|
|
|
// ioctl_param = 1;
|
|
|
|
// else
|
|
|
|
// ioctl_param = 0;
|
|
|
|
|
|
|
|
ioctl_param = (priv->audio_channels[priv->audio_id] == 2);
|
|
|
|
printf("ioctl dsp stereo: %d (req: %d)\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_STEREO, &ioctl_param),
|
|
|
|
ioctl_param);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioctl_param = priv->audio_samplerate[priv->audio_id];
|
|
|
|
printf("ioctl dsp speed: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_SPEED, &ioctl_param));
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
ioctl_param = 0;
|
|
|
|
ioctl_param = ~PCM_ENABLE_INPUT;
|
|
|
|
printf("ioctl dsp trigger: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
|
|
|
|
ioctl_param = PCM_ENABLE_INPUT;
|
|
|
|
printf("ioctl dsp trigger: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("ioctl dsp trigger: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param));
|
|
|
|
printf("trigger: %x\n", ioctl_param);
|
|
|
|
ioctl_param = PCM_ENABLE_INPUT;
|
|
|
|
printf("ioctl dsp trigger: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
|
|
|
|
|
|
|
|
printf("ioctl dsp getblocksize: %d\n",
|
|
|
|
ioctl(priv->audio_fd, SNDCTL_DSP_GETBLKSIZE, &priv->audio_blocksize));
|
|
|
|
printf("blocksize: %d\n", priv->audio_blocksize);
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-09 23:46:06 +00:00
|
|
|
return(1);
|
|
|
|
|
2001-12-19 12:54:06 +00:00
|
|
|
|
|
|
|
malloc_failed:
|
|
|
|
if (priv->channels)
|
|
|
|
free(priv->channels);
|
|
|
|
if (priv->buf)
|
|
|
|
free(priv->buf);
|
2001-11-09 23:46:06 +00:00
|
|
|
err:
|
2001-12-27 23:52:48 +00:00
|
|
|
if (priv->video_fd != -1)
|
|
|
|
close(priv->video_fd);
|
2001-11-09 23:46:06 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
static int uninit(priv_t *priv)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
close(priv->video_fd);
|
|
|
|
|
|
|
|
priv->audio[priv->audio_id].volume = 0;
|
|
|
|
priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE;
|
|
|
|
ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
|
|
|
|
close(priv->audio_fd);
|
2001-11-10 23:32:10 +00:00
|
|
|
#warning "Implement uninit!"
|
2001-11-16 21:30:10 +00:00
|
|
|
|
|
|
|
return(1);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
static int start(priv_t *priv)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-10 23:32:10 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(0);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->picture.palette = format2palette(priv->format);
|
|
|
|
priv->picture.depth = palette2depth(priv->picture.palette);
|
|
|
|
priv->bytesperline = priv->width * priv->picture.depth / 8;
|
2001-12-27 23:52:48 +00:00
|
|
|
// if (IMGFMT_IS_BGR(priv->format) || IMGFMT_IS_RGB(priv->format))
|
|
|
|
// priv->bytesperline = priv->width * priv->picture.depth / 8;
|
|
|
|
// if ((priv->format == IMGFMT_YV12) || (priv->format == IMGFMT_I420) || (priv->format == IMGFMT_IYUV))
|
|
|
|
// priv->bytesperline = priv->width * 3 / 2;
|
|
|
|
|
|
|
|
printf("palette: %d, depth: %d, bytesperline: %d\n",
|
|
|
|
priv->picture.palette, priv->picture.depth, priv->bytesperline);
|
|
|
|
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n");
|
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Depth: %d, Palette: %d (Format: %s)\n", priv->picture.depth,
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->picture.palette, vo_format_name(priv->format));
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->picture.brightness, priv->picture.hue,
|
|
|
|
priv->picture.colour, priv->picture.contrast);
|
|
|
|
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(0);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->nbuf = priv->mbuf.frames;
|
|
|
|
for (i=0; i < priv->nbuf; i++)
|
|
|
|
{
|
|
|
|
priv->buf[i].format = priv->picture.palette;
|
|
|
|
priv->buf[i].frame = i;
|
|
|
|
priv->buf[i].width = priv->width;
|
|
|
|
priv->buf[i].height = priv->height;
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
|
2001-11-10 23:32:10 +00:00
|
|
|
}
|
2001-11-11 15:45:23 +00:00
|
|
|
|
2001-11-16 21:30:10 +00:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
struct video_play_mode pmode;
|
|
|
|
|
|
|
|
pmode.mode = VID_PLAY_NORMAL;
|
|
|
|
pmode.p1 = 1;
|
|
|
|
pmode.p2 = 0;
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1)
|
2001-11-16 21:30:10 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno));
|
|
|
|
// return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-11 15:45:23 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
struct video_window win;
|
|
|
|
|
|
|
|
win.x = 0;
|
|
|
|
win.y = 0;
|
|
|
|
win.width = priv->width;
|
|
|
|
win.height = priv->height;
|
|
|
|
win.chromakey = -1;
|
|
|
|
win.flags = 0;
|
2002-03-15 16:08:14 +00:00
|
|
|
//win.clipcount = 0;
|
2001-11-11 15:45:23 +00:00
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
ioctl(priv->video_fd, VIDIOCSWIN, &win);
|
2001-11-11 15:45:23 +00:00
|
|
|
}
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
/* start capture */
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2001-11-11 15:45:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return(1);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int control(priv_t *priv, int cmd, void *arg)
|
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
priv, cmd, arg);
|
2001-11-09 23:46:06 +00:00
|
|
|
switch(cmd)
|
|
|
|
{
|
2001-11-10 23:32:10 +00:00
|
|
|
/* ========== GENERIC controls =========== */
|
|
|
|
case TVI_CONTROL_IS_VIDEO:
|
|
|
|
{
|
|
|
|
if (priv->capability.type & VID_TYPE_CAPTURE)
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_IS_AUDIO:
|
2002-03-15 16:08:14 +00:00
|
|
|
// return(TVI_CONTROL_FALSE);
|
2001-12-27 23:52:48 +00:00
|
|
|
/* also disable audio for as it's not working! */
|
2001-11-11 16:28:12 +00:00
|
|
|
if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
|
2001-12-27 23:52:48 +00:00
|
|
|
{
|
|
|
|
// printf("yeah, audio csennel!!");
|
2001-11-11 16:28:12 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
2001-12-27 23:52:48 +00:00
|
|
|
}
|
|
|
|
return(TVI_CONTROL_TRUE);
|
2001-11-10 23:32:10 +00:00
|
|
|
case TVI_CONTROL_IS_TUNER:
|
|
|
|
{
|
2001-11-11 16:28:12 +00:00
|
|
|
// if (priv->capability.type & VID_TYPE_TUNER)
|
|
|
|
if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========== VIDEO controls =========== */
|
2001-11-09 23:46:06 +00:00
|
|
|
case TVI_CONTROL_VID_GET_FORMAT:
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
|
|
|
int output_fmt = -1;
|
|
|
|
|
|
|
|
output_fmt = priv->format;
|
|
|
|
(int)*(void **)arg = output_fmt;
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Output format: %s\n", vo_format_name(output_fmt));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_VID_SET_FORMAT:
|
|
|
|
priv->format = (int)*(void **)arg;
|
2001-11-09 23:46:06 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_GET_PLANES:
|
2001-11-30 16:59:02 +00:00
|
|
|
(int)*(void **)arg = 1; /* FIXME, also not needed at this time */
|
2001-11-09 23:46:06 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_GET_BITS:
|
2001-11-11 01:44:54 +00:00
|
|
|
(int)*(void **)arg = palette2depth(format2palette(priv->format));
|
2001-11-09 23:46:06 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_GET_WIDTH:
|
|
|
|
(int)*(void **)arg = priv->width;
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_CHK_WIDTH:
|
|
|
|
{
|
|
|
|
int req_width = (int)*(void **)arg;
|
|
|
|
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Requested width: %d\n", req_width);
|
2001-11-11 01:44:54 +00:00
|
|
|
if ((req_width >= priv->capability.minwidth) &&
|
|
|
|
(req_width <= priv->capability.maxwidth))
|
2001-11-09 23:46:06 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_VID_SET_WIDTH:
|
|
|
|
priv->width = (int)*(void **)arg;
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_GET_HEIGHT:
|
|
|
|
(int)*(void **)arg = priv->height;
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_CHK_HEIGHT:
|
|
|
|
{
|
|
|
|
int req_height = (int)*(void **)arg;
|
|
|
|
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Requested height: %d\n", req_height);
|
2001-11-11 01:44:54 +00:00
|
|
|
if ((req_height >= priv->capability.minheight) &&
|
|
|
|
(req_height <= priv->capability.maxheight))
|
2001-11-09 23:46:06 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_VID_SET_HEIGHT:
|
|
|
|
priv->height = (int)*(void **)arg;
|
|
|
|
return(TVI_CONTROL_TRUE);
|
2001-11-16 22:59:07 +00:00
|
|
|
case TVI_CONTROL_VID_GET_PICTURE:
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
|
2001-11-16 22:59:07 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_SET_PICTURE:
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
|
2001-11-16 22:59:07 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_SET_BRIGHTNESS:
|
|
|
|
priv->picture.brightness = (int)*(void **)arg;
|
|
|
|
control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_SET_HUE:
|
|
|
|
priv->picture.hue = (int)*(void **)arg;
|
|
|
|
control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_SET_SATURATION:
|
|
|
|
priv->picture.colour = (int)*(void **)arg;
|
|
|
|
control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
case TVI_CONTROL_VID_SET_CONTRAST:
|
|
|
|
priv->picture.contrast = (int)*(void **)arg;
|
|
|
|
control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
/* ========== TUNER controls =========== */
|
|
|
|
case TVI_CONTROL_TUN_GET_FREQ:
|
|
|
|
{
|
|
|
|
unsigned long freq;
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGFREQ, &freq) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tuner uses khz not mhz ! */
|
2001-11-11 15:45:23 +00:00
|
|
|
// if (priv->tuner.flags & VIDEO_TUNER_LOW)
|
|
|
|
// freq /= 1000;
|
2001-11-10 23:32:10 +00:00
|
|
|
(unsigned long)*(void **)arg = freq;
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
2001-11-09 23:46:06 +00:00
|
|
|
case TVI_CONTROL_TUN_SET_FREQ:
|
|
|
|
{
|
2001-11-10 23:32:10 +00:00
|
|
|
/* argument is in MHz ! */
|
|
|
|
unsigned long freq = (unsigned long)*(void **)arg;
|
2001-11-09 23:46:06 +00:00
|
|
|
|
2001-11-11 15:45:23 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16);
|
2001-11-10 23:32:10 +00:00
|
|
|
|
|
|
|
/* tuner uses khz not mhz ! */
|
2001-11-11 15:45:23 +00:00
|
|
|
// if (priv->tuner.flags & VIDEO_TUNER_LOW)
|
|
|
|
// freq *= 1000;
|
|
|
|
// mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16);
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCSFREQ, &freq) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_TUN_GET_TUNER:
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name,
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->tuner.rangelow, priv->tuner.rangehigh);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_TUN_SET_TUNER:
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCSTUNER, &priv->tuner) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_TUN_SET_NORM:
|
|
|
|
{
|
|
|
|
int req_mode = (int)*(void **)arg;
|
|
|
|
|
|
|
|
if ((!(priv->tuner.flags & VIDEO_TUNER_NORM)) ||
|
|
|
|
((req_mode == VIDEO_MODE_PAL) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) ||
|
|
|
|
((req_mode == VIDEO_MODE_NTSC) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) ||
|
|
|
|
((req_mode == VIDEO_MODE_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM)))
|
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n");
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->tuner.mode = req_mode;
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (control(priv->video_fd, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE)
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_TUN_GET_NORM:
|
|
|
|
{
|
|
|
|
(int)*(void **)arg = priv->tuner.mode;
|
|
|
|
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========== AUDIO controls =========== */
|
|
|
|
case TVI_CONTROL_AUD_GET_FORMAT:
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
(int)*(void **)arg = priv->audio_format[priv->audio_id];
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_AUD_GET_CHANNELS:
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
(int)*(void **)arg = priv->audio_channels[priv->audio_id];
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_AUD_GET_SAMPLERATE:
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
(int)*(void **)arg = priv->audio_samplerate[priv->audio_id];
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
case TVI_CONTROL_AUD_GET_SAMPLESIZE:
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
(int)*(void **)arg = priv->audio_samplesize[priv->audio_id];
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========== SPECIFIC controls =========== */
|
|
|
|
case TVI_CONTROL_SPC_GET_INPUT:
|
|
|
|
{
|
|
|
|
int req_chan = (int)*(void **)arg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->capability.channels; i++)
|
|
|
|
{
|
|
|
|
if (priv->channels[i].channel == req_chan)
|
|
|
|
break;
|
|
|
|
}
|
2001-11-11 16:28:12 +00:00
|
|
|
|
|
|
|
priv->act_channel = i;
|
2001-11-10 23:32:10 +00:00
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
return(TVI_CONTROL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
case TVI_CONTROL_SPC_SET_INPUT:
|
|
|
|
{
|
|
|
|
struct video_channel chan;
|
|
|
|
int req_chan = (int)*(void **)arg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (req_chan >= priv->capability.channels)
|
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
req_chan, priv->capability.channels);
|
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < priv->capability.channels; i++)
|
|
|
|
{
|
|
|
|
if (priv->channels[i].channel == req_chan)
|
|
|
|
chan = priv->channels[i];
|
|
|
|
}
|
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1)
|
2001-11-10 23:32:10 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(TVI_CONTROL_FALSE);
|
|
|
|
}
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name);
|
2001-11-10 23:32:10 +00:00
|
|
|
|
2001-11-11 16:28:12 +00:00
|
|
|
priv->act_channel = i;
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
/* update tuner state */
|
2001-11-11 16:28:12 +00:00
|
|
|
// if (priv->capability.type & VID_TYPE_TUNER)
|
|
|
|
if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
|
2001-11-10 23:32:10 +00:00
|
|
|
control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
|
|
|
|
|
|
|
|
/* update local channel list */
|
|
|
|
control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan);
|
|
|
|
return(TVI_CONTROL_TRUE);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TVI_CONTROL_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int grab_video_frame(priv_t *priv, char *buffer, int len)
|
|
|
|
{
|
2001-11-10 23:32:10 +00:00
|
|
|
int frame = priv->queue % priv->nbuf;
|
2001-11-11 02:20:39 +00:00
|
|
|
int nextframe = (priv->queue+1) % priv->nbuf;
|
2001-11-10 23:32:10 +00:00
|
|
|
|
2002-03-15 16:08:14 +00:00
|
|
|
priv->currentframe++;
|
|
|
|
|
2001-12-03 16:38:40 +00:00
|
|
|
mp_dbg(MSGT_TV, MSGL_DBG2, "grab_video_frame(priv=%p, buffer=%p, len=%d)\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
priv, buffer, len);
|
|
|
|
|
2001-11-16 21:30:10 +00:00
|
|
|
mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n",
|
2001-11-11 02:20:39 +00:00
|
|
|
priv->buf, nextframe, &priv->buf[nextframe]);
|
2001-12-27 23:52:48 +00:00
|
|
|
if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1)
|
2001-11-09 23:46:06 +00:00
|
|
|
{
|
2001-11-11 03:40:16 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno));
|
2001-11-10 23:32:10 +00:00
|
|
|
return(0);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
2001-12-24 13:56:43 +00:00
|
|
|
|
2001-12-27 23:52:48 +00:00
|
|
|
while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 &&
|
2001-12-24 13:56:43 +00:00
|
|
|
(errno == EAGAIN || errno == EINTR));
|
|
|
|
mp_dbg(MSGT_TV, MSGL_DBG3, "picture sync failed\n");
|
|
|
|
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->queue++;
|
|
|
|
|
2001-11-16 21:30:10 +00:00
|
|
|
mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n",
|
2001-11-10 23:32:10 +00:00
|
|
|
priv->mmap, priv->mbuf.offsets[frame],
|
|
|
|
priv->mmap+priv->mbuf.offsets[frame]);
|
2001-11-16 21:30:10 +00:00
|
|
|
|
|
|
|
/* XXX also directrendering would be nicer! */
|
|
|
|
/* 3 times copying the same picture to other buffer :( */
|
|
|
|
|
|
|
|
/* copy the actual frame */
|
2001-11-10 23:32:10 +00:00
|
|
|
memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len);
|
|
|
|
|
2002-03-15 16:08:14 +00:00
|
|
|
return(priv->currentframe);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_video_framesize(priv_t *priv)
|
|
|
|
{
|
2001-11-16 21:30:10 +00:00
|
|
|
return(priv->bytesperline * priv->height);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int grab_audio_frame(priv_t *priv, char *buffer, int len)
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
int in_len = 0;
|
2002-03-15 16:08:14 +00:00
|
|
|
// int max_tries = 128;
|
2001-12-27 23:52:48 +00:00
|
|
|
|
2002-03-15 16:08:14 +00:00
|
|
|
mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n",
|
2001-12-27 23:52:48 +00:00
|
|
|
priv, buffer, len);
|
|
|
|
|
2002-03-15 16:08:14 +00:00
|
|
|
// while (--max_tries > 0)
|
2001-12-27 23:52:48 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
in_len = read(priv->audio_fd, buffer, len);
|
|
|
|
// printf("in_len: %d\n", in_len);
|
|
|
|
// fflush(NULL);
|
|
|
|
|
|
|
|
if (in_len > 0)
|
|
|
|
break;
|
|
|
|
if (!((in_len == 0) || (in_len == -1 && (errno == EAGAIN || errno == EINTR))))
|
|
|
|
{
|
|
|
|
in_len = 0; /* -EIO */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-03-15 16:08:14 +00:00
|
|
|
// printf("tries: %d\n", 128-max_tries);
|
2001-12-27 23:52:48 +00:00
|
|
|
|
|
|
|
return(in_len);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_audio_framesize(priv_t *priv)
|
|
|
|
{
|
2001-12-27 23:52:48 +00:00
|
|
|
return(priv->audio_blocksize);
|
|
|
|
// return(priv->audio_samplesize[priv->audio_id]);
|
2001-11-09 23:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_TV */
|