changeset 1795:62792a60f740 libavformat

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
author gpoirier
date Wed, 14 Feb 2007 17:01:32 +0000
parents 11c57b75bccd
children 29962f054bd0
files audio.c avformat.h beosaudio.cpp dc1394.c dv1394.c grab.c grab_bktr.c v4l2.c x11grab.c
diffstat 9 files changed, 15 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/audio.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/audio.c	Wed Feb 14 17:01:32 2007 +0000
@@ -53,14 +53,6 @@
     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 @@
     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;
--- a/avformat.h	Wed Feb 14 14:54:20 2007 +0000
+++ b/avformat.h	Wed Feb 14 17:01:32 2007 +0000
@@ -117,7 +117,9 @@
     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
--- a/beosaudio.cpp	Wed Feb 14 14:54:20 2007 +0000
+++ b/beosaudio.cpp	Wed Feb 14 17:01:32 2007 +0000
@@ -361,7 +361,7 @@
     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);
--- a/dc1394.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/dc1394.c	Wed Feb 14 17:01:32 2007 +0000
@@ -118,7 +118,7 @@
                                    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) {
--- a/dv1394.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/dv1394.c	Wed Feb 14 17:01:32 2007 +0000
@@ -83,7 +83,6 @@
 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 @@
         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;
--- a/grab.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/grab.c	Wed Feb 14 17:01:32 2007 +0000
@@ -68,7 +68,6 @@
     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 @@
     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;
     }
 
--- a/grab_bktr.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/grab_bktr.c	Wed Feb 14 17:01:32 2007 +0000
@@ -243,7 +243,6 @@
     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 @@
     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 @@
             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);
 
--- a/v4l2.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/v4l2.c	Wed Feb 14 17:01:32 2007 +0000
@@ -114,16 +114,16 @@
     },
 };
 
-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 @@
     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 @@
     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);
 
--- a/x11grab.c	Wed Feb 14 14:54:20 2007 +0000
+++ b/x11grab.c	Wed Feb 14 17:01:32 2007 +0000
@@ -97,25 +97,14 @@
     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) {