Commit c57a8fef authored by Stefano Sabatini's avatar Stefano Sabatini

Return meaningful error codes, rather than always -1.

Originally committed as revision 22966 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 2d0525c2
...@@ -164,7 +164,7 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities) ...@@ -164,7 +164,7 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n", av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
ctx->filename, strerror(errno)); ctx->filename, strerror(errno));
return -1; return AVERROR(errno);
} }
res = ioctl(fd, VIDIOC_QUERYCAP, &cap); res = ioctl(fd, VIDIOC_QUERYCAP, &cap);
...@@ -174,20 +174,20 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities) ...@@ -174,20 +174,20 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n"); av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n");
close(fd); close(fd);
return -1; return AVERROR(errno);
} }
if (res < 0) { if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
strerror(errno)); strerror(errno));
close(fd); close(fd);
return -1; return AVERROR(errno);
} }
if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n"); av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n");
close(fd); close(fd);
return -1; return AVERROR(ENODEV);
} }
*capabilities = cap.capabilities; *capabilities = cap.capabilities;
...@@ -299,27 +299,27 @@ static int mmap_init(AVFormatContext *ctx) ...@@ -299,27 +299,27 @@ static int mmap_init(AVFormatContext *ctx)
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n"); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
} }
return -1; return AVERROR(errno);
} }
if (req.count < 2) { if (req.count < 2) {
av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n"); av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
return -1; return AVERROR(ENOMEM);
} }
s->buffers = req.count; s->buffers = req.count;
s->buf_start = av_malloc(sizeof(void *) * s->buffers); s->buf_start = av_malloc(sizeof(void *) * s->buffers);
if (s->buf_start == NULL) { if (s->buf_start == NULL) {
av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n"); av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
return -1; return AVERROR(ENOMEM);
} }
s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers); s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers);
if (s->buf_len == NULL) { if (s->buf_len == NULL) {
av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n"); av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
av_free(s->buf_start); av_free(s->buf_start);
return -1; return AVERROR(ENOMEM);
} }
for (i = 0; i < req.count; i++) { for (i = 0; i < req.count; i++) {
...@@ -333,7 +333,7 @@ static int mmap_init(AVFormatContext *ctx) ...@@ -333,7 +333,7 @@ static int mmap_init(AVFormatContext *ctx)
if (res < 0) { if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n"); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
return -1; return AVERROR(errno);
} }
s->buf_len[i] = buf.length; s->buf_len[i] = buf.length;
...@@ -347,7 +347,7 @@ static int mmap_init(AVFormatContext *ctx) ...@@ -347,7 +347,7 @@ static int mmap_init(AVFormatContext *ctx)
if (s->buf_start[i] == MAP_FAILED) { if (s->buf_start[i] == MAP_FAILED) {
av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));
return -1; return AVERROR(errno);
} }
} }
...@@ -405,13 +405,13 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) ...@@ -405,13 +405,13 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
} }
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno)); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));
return -1; return AVERROR(errno);
} }
assert (buf.index < s->buffers); assert (buf.index < s->buffers);
if (s->frame_size > 0 && buf.bytesused != s->frame_size) { if (s->frame_size > 0 && buf.bytesused != s->frame_size) {
av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size); av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size);
return -1; return AVERROR_INVALIDDATA;
} }
/* Image is at s->buff_start[buf.index] */ /* Image is at s->buff_start[buf.index] */
...@@ -427,7 +427,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) ...@@ -427,7 +427,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n"); av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n");
res = ioctl (s->fd, VIDIOC_QBUF, &buf); res = ioctl (s->fd, VIDIOC_QBUF, &buf);
return -1; return AVERROR(ENOMEM);
} }
buf_descriptor->fd = s->fd; buf_descriptor->fd = s->fd;
buf_descriptor->index = buf.index; buf_descriptor->index = buf.index;
...@@ -459,7 +459,7 @@ static int mmap_start(AVFormatContext *ctx) ...@@ -459,7 +459,7 @@ static int mmap_start(AVFormatContext *ctx)
if (res < 0) { if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno)); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno));
return -1; return AVERROR(errno);
} }
} }
...@@ -468,7 +468,7 @@ static int mmap_start(AVFormatContext *ctx) ...@@ -468,7 +468,7 @@ static int mmap_start(AVFormatContext *ctx)
if (res < 0) { if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno)); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno));
return -1; return AVERROR(errno);
} }
return 0; return 0;
...@@ -588,11 +588,11 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) ...@@ -588,11 +588,11 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
if (ap->width <= 0 || ap->height <= 0) { if (ap->width <= 0 || ap->height <= 0) {
av_log(s1, AV_LOG_ERROR, "Wrong size (%dx%d)\n", ap->width, ap->height); av_log(s1, AV_LOG_ERROR, "Wrong size (%dx%d)\n", ap->width, ap->height);
return -1; return AVERROR(EINVAL);
} }
if(avcodec_check_dimensions(s1, ap->width, ap->height) < 0) if(avcodec_check_dimensions(s1, ap->width, ap->height) < 0)
return -1; return AVERROR(EINVAL);
st = av_new_stream(s1, 0); st = av_new_stream(s1, 0);
if (!st) { if (!st) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment