]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/v4l2.c
update to libnut API, changes to frame_table_input
[ffmpeg] / libavformat / v4l2.c
index a445c6da1178e25ed792f67a1437ff0f68c41a77..00adccaa8054013497fc75f540170636fca19df5 100644 (file)
  * V4L2_PIX_FMT_* and PIX_FMT_*
  *
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg 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
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
@@ -30,8 +32,8 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/time.h>
-#define _LINUX_TIME_H 1
-#include <linux/videodev.h>
+#include <asm/types.h>
+#include <linux/videodev2.h>
 #include <time.h>
 
 static const int desired_video_buffers = 256;
@@ -306,7 +308,12 @@ static int mmap_read_frame(struct video_data *s, void *frame, int64_t *ts)
         return -1;
     }
     assert (buf.index < s->buffers);
-    assert(buf.bytesused == s->frame_size);
+    if (buf.bytesused != s->frame_size) {
+        av_log(NULL, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size);
+
+        return -1;
+    }
+
     /* Image is at s->buff_start[buf.index] */
     memcpy(frame, s->buf_start[buf.index], buf.bytesused);
     *ts = buf.timestamp.tv_sec * int64_t_C(1000000) + buf.timestamp.tv_usec;
@@ -384,7 +391,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
     uint32_t desired_format, capabilities;
     const char *video_device;
 
-    if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
+    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
         av_log(s1, AV_LOG_ERROR, "Missing/Wrong parameters\n");
 
         return -1;
@@ -423,7 +430,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
 
         return AVERROR_IO;
     }
-    av_log(s1, AV_LOG_ERROR, "[%d]Capabilities: %x\n", s->fd, capabilities);
+    av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities);
 
     desired_format = fmt_ff2v4l(ap->pix_fmt);
     if (desired_format == 0 || (device_init(s->fd, &width, &height, desired_format) < 0)) {
@@ -457,7 +464,9 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
     if (capabilities & V4L2_CAP_STREAMING) {
         s->io_method = io_mmap;
         res = mmap_init(s);
-        res = mmap_start(s);
+        if (res == 0) {
+            res = mmap_start(s);
+        }
     } else {
         s->io_method = io_read;
         res = read_init(s);
@@ -520,7 +529,7 @@ static int v4l2_read_close(AVFormatContext *s1)
     return 0;
 }
 
-static AVInputFormat v4l2_format = {
+AVInputFormat v4l2_demuxer = {
     "video4linux2",
     "video grab",
     sizeof(struct video_data),
@@ -530,9 +539,3 @@ static AVInputFormat v4l2_format = {
     v4l2_read_close,
     .flags = AVFMT_NOFILE,
 };
-
-int v4l2_init(void)
-{
-    av_register_input_format(&v4l2_format);
-    return 0;
-}