Merge commit 'a1a259881fa7b23e2ffc0c2a43d4923fe42d0478'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 10 Nov 2014 00:17:38 +0000 (01:17 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 10 Nov 2014 00:19:24 +0000 (01:19 +0100)
* commit 'a1a259881fa7b23e2ffc0c2a43d4923fe42d0478':
  v4l2: Use av_strerror

Conflicts:
libavdevice/v4l2.c

See: 60950adc18fe145a235211e75da68ab07123fcaa
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavdevice/v4l2.c

@@@ -496,18 -452,30 +496,19 @@@ static int mmap_read_frame(AVFormatCont
          .type   = V4L2_BUF_TYPE_VIDEO_CAPTURE,
          .memory = V4L2_MEMORY_MMAP
      };
 -    struct pollfd p = { .fd = s->fd, .events = POLLIN };
      int res;
  
 -    res = poll(&p, 1, s->timeout);
 -    if (res < 0)
 -        return AVERROR(errno);
 -
 -    if (!(p.revents & (POLLIN | POLLERR | POLLHUP)))
 -        return AVERROR(EAGAIN);
 -
      /* FIXME: Some special treatment might be needed in case of loss of signal... */
 -    while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
 +    while ((res = v4l2_ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
      if (res < 0) {
 -        char errbuf[128];
          if (errno == EAGAIN) {
              pkt->size = 0;
 -
              return AVERROR(EAGAIN);
          }
 -        av_strerror(AVERROR(errno), errbuf, sizeof(errbuf));
 +        res = AVERROR(errno);
-         av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", av_err2str(res));
+         av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
 -               errbuf);
 -
 -        return AVERROR(errno);
++               av_err2str(res));
 +        return res;
      }
  
      if (buf.index >= s->buffers) {
@@@ -600,19 -562,27 +601,21 @@@ static int mmap_start(AVFormatContext *
              .memory = V4L2_MEMORY_MMAP
          };
  
 -        res = ioctl(s->fd, VIDIOC_QBUF, &buf);
 -        if (res < 0) {
 -            err = AVERROR(errno);
 -            av_strerror(err, errbuf, sizeof(errbuf));
 +        if (v4l2_ioctl(s->fd, VIDIOC_QBUF, &buf) < 0) {
 +            res = AVERROR(errno);
-             av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", av_err2str(res));
+             av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n",
 -                   errbuf);
 -
 -            return err;
++                   av_err2str(res));
 +            return res;
          }
      }
      s->buffers_queued = s->buffers;
  
      type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 -    res = ioctl(s->fd, VIDIOC_STREAMON, &type);
 -    if (res < 0) {
 -        err = AVERROR(errno);
 -        av_strerror(err, errbuf, sizeof(errbuf));
 +    if (v4l2_ioctl(s->fd, VIDIOC_STREAMON, &type) < 0) {
 +        res = AVERROR(errno);
-         av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", av_err2str(res));
+         av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n",
 -               errbuf);
 -
 -        return err;
++               av_err2str(res));
 +        return res;
      }
  
      return 0;
@@@ -718,39 -670,41 +721,40 @@@ static int v4l2_set_parameters(AVFormat
      }
  
      if (framerate_q.num && framerate_q.den) {
 -        av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
 -               framerate_q.den, framerate_q.num);
 -        tpf->numerator   = framerate_q.den;
 -        tpf->denominator = framerate_q.num;
 -
 -        if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {
 -            av_log(s1, AV_LOG_ERROR,
 -                   "ioctl set time per frame(%d/%d) failed\n",
 +        if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) {
 +            tpf = &streamparm.parm.capture.timeperframe;
 +
 +            av_log(ctx, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
                     framerate_q.den, framerate_q.num);
 -            return AVERROR(EIO);
 -        }
 +            tpf->numerator   = framerate_q.den;
 +            tpf->denominator = framerate_q.num;
 +
 +            if (v4l2_ioctl(s->fd, VIDIOC_S_PARM, &streamparm) < 0) {
 +                ret = AVERROR(errno);
-                 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_S_PARM): %s\n", av_err2str(ret));
++                av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_S_PARM): %s\n",
++                       av_err2str(ret));
 +                return ret;
 +            }
  
 -        if (framerate_q.num != tpf->denominator ||
 -            framerate_q.den != tpf->numerator) {
 -            av_log(s1, AV_LOG_INFO,
 -                   "The driver changed the time per frame from "
 -                   "%d/%d to %d/%d\n",
 -                   framerate_q.den, framerate_q.num,
 -                   tpf->numerator, tpf->denominator);
 -        }
 -    } else {
 -        if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {
 -            char errbuf[128];
 -            av_strerror(AVERROR(errno), errbuf, sizeof(errbuf));
 -            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n",
 -                   errbuf);
 -            return AVERROR(errno);
 +            if (framerate_q.num != tpf->denominator ||
 +                framerate_q.den != tpf->numerator) {
 +                av_log(ctx, AV_LOG_INFO,
 +                       "The driver changed the time per frame from "
 +                       "%d/%d to %d/%d\n",
 +                       framerate_q.den, framerate_q.num,
 +                       tpf->numerator, tpf->denominator);
 +            }
 +        } else {
 +            av_log(ctx, AV_LOG_WARNING,
 +                   "The driver does not allow to change time per frame\n");
          }
      }
 -    s1->streams[0]->avg_frame_rate.num = tpf->denominator;
 -    s1->streams[0]->avg_frame_rate.den = tpf->numerator;
 -
 -    s->timeout = 100 +
 -        av_rescale_q(1, s1->streams[0]->avg_frame_rate,
 -                        (AVRational){1, 1000});
 +    if (tpf->denominator > 0 && tpf->numerator > 0) {
 +        ctx->streams[0]->avg_frame_rate.num = tpf->denominator;
 +        ctx->streams[0]->avg_frame_rate.den = tpf->numerator;
 +        ctx->streams[0]->r_frame_rate = ctx->streams[0]->avg_frame_rate;
 +    } else
 +        av_log(ctx, AV_LOG_WARNING, "Time per frame unknown\n");
  
      return 0;
  }