implement new grabbing interface, as described here:

ttp://thread.gmane.org/gmane.comp.video.ffmpeg.devel/42920
patch by Ramiro Polla % ramiro A lisha P ufsc P br %
Original thread:
Date: Jan 31, 2007 8:56 PM
Subject: [Ffmpeg-devel] [PATCH] New grabbing interface

Originally committed as revision 7983 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Ramiro Polla 2007-02-14 17:01:32 +00:00 committed by Guillaume Poirier
parent 2012121363
commit cc58300e30
11 changed files with 25 additions and 212 deletions

View file

@ -53,14 +53,6 @@ static int audio_open(AudioData *s, int is_output, const char *audio_device)
int tmp, err;
char *flip = getenv("AUDIO_FLIP_LEFT");
/* open linux audio device */
if (!audio_device)
#ifdef __OpenBSD__
audio_device = "/dev/sound";
#else
audio_device = "/dev/dsp";
#endif
if (is_output)
audio_fd = open(audio_device, O_WRONLY);
else
@ -229,7 +221,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s->sample_rate = ap->sample_rate;
s->channels = ap->channels;
ret = audio_open(s, 0, ap->device);
ret = audio_open(s, 0, s1->filename);
if (ret < 0) {
av_free(st);
return AVERROR_IO;

View file

@ -117,7 +117,9 @@ typedef struct AVFormatParameters {
int height;
enum PixelFormat pix_fmt;
int channel; /* used to select dv channel */
#if LIBAVFORMAT_VERSION_INT < (52<<16)
const char *device; /* video, audio or DV device */
#endif
const char *standard; /* tv standard, NTSC, PAL, SECAM */
int mpeg2ts_raw:1; /* force raw MPEG2 transport stream output, if possible */
int mpeg2ts_compute_pcr:1; /* compute exact PCR for each transport

View file

@ -361,7 +361,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s->sample_rate = ap->sample_rate;
s->channels = ap->channels;
ret = audio_open(s, 0, ap->device);
ret = audio_open(s, 0, s1->filename);
if (ret < 0) {
av_free(st);
return AVERROR(EIO);

View file

@ -118,7 +118,7 @@ static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap)
fmt->frame_size_id,
SPEED_400,
fps->frame_rate_id, 8, 1,
ap->device,
c->filename,
&dc1394->camera);
dc1394_free_camera_nodes(camera_nodes);
if (res != DC1394_SUCCESS) {

View file

@ -83,7 +83,6 @@ static int dv1394_start(struct dv1394_data *dv)
static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap)
{
struct dv1394_data *dv = context->priv_data;
const char *video_device;
dv->dv_demux = dv_init_demux(context);
if (!dv->dv_demux)
@ -100,10 +99,7 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
dv->channel = DV1394_DEFAULT_CHANNEL;
/* Open and initialize DV1394 device */
video_device = ap->device;
if (!video_device)
video_device = "/dev/dv1394/0";
dv->fd = open(video_device, O_RDONLY);
dv->fd = open(context->filename, O_RDONLY);
if (dv->fd < 0) {
perror("Failed to open DV interface");
goto failed;

View file

@ -68,7 +68,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
struct video_tuner tuner;
struct video_audio audio;
struct video_picture pict;
const char *video_device;
int j;
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
@ -100,12 +99,9 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s->frame_rate = frame_rate;
s->frame_rate_base = frame_rate_base;
video_device = ap->device;
if (!video_device)
video_device = "/dev/video";
video_fd = open(video_device, O_RDWR);
video_fd = open(s1->filename, O_RDWR);
if (video_fd < 0) {
perror(video_device);
perror(s1->filename);
goto fail;
}

View file

@ -243,7 +243,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
int frame_rate;
int frame_rate_base;
int format = -1;
const char *video_device;
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
return -1;
@ -253,10 +252,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
frame_rate = ap->time_base.den;
frame_rate_base = ap->time_base.num;
video_device = ap->device;
if (!video_device)
video_device = "/dev/bktr0";
st = av_new_stream(s1, 0);
if (!st)
return AVERROR(ENOMEM);
@ -285,7 +280,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
format = NTSC;
}
if (bktr_init(video_device, width, height, format,
if (bktr_init(s1->filename, width, height, format,
&(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0)
return AVERROR(EIO);

View file

@ -114,16 +114,16 @@ static struct fmt_map fmt_conversion_table[] = {
},
};
static int device_open(AVFormatContext *ctx, const char *devname, uint32_t *capabilities)
static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
{
struct v4l2_capability cap;
int fd;
int res;
fd = open(devname, O_RDWR /*| O_NONBLOCK*/, 0);
fd = open(ctx->filename, O_RDWR /*| O_NONBLOCK*/, 0);
if (fd < 0) {
av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
devname, strerror(errno));
ctx->filename, strerror(errno));
return -1;
}
@ -429,7 +429,6 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
int width, height;
int res, frame_rate, frame_rate_base;
uint32_t desired_format, capabilities;
const char *video_device;
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
av_log(s1, AV_LOG_ERROR, "Missing/Wrong parameters\n");
@ -459,12 +458,8 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s->frame_rate = frame_rate;
s->frame_rate_base = frame_rate_base;
video_device = ap->device;
if (!video_device) {
video_device = "/dev/video";
}
capabilities = 0;
s->fd = device_open(s1, video_device, &capabilities);
s->fd = device_open(s1, &capabilities);
if (s->fd < 0) {
av_free(st);

View file

@ -97,25 +97,14 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
int use_shm;
char *param, *offset;
if (!ap->device) {
av_log(s1, AV_LOG_ERROR, "AVParameters don't specify any device. Use -vd.\n");
return AVERROR_IO;
}
param = strchr(ap->device, ':');
if (!param) {
av_free(st);
return AVERROR_IO;
}
param = av_strdup(param);
param = av_strdup(s1->filename);
offset = strchr(param, '+');
if (offset) {
sscanf(offset, "%d,%d", &x_off, &y_off);
*offset= 0;
}
av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", ap->device, param, x_off, y_off, ap->width, ap->height);
av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, param, x_off, y_off, ap->width, ap->height);
dpy = XOpenDisplay(param);
if(!dpy) {