#include "config.h"
#include "libavformat/avformat.h"
+#include "libavformat/internal.h"
#include "libavutil/log.h"
+#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
#if HAVE_LIBDC1394_2
#include <dc1394/dc1394.h>
#define DC1394_FRAMERATE_240 FRAMERATE_240
#endif
-#undef free
-
typedef struct dc1394_data {
AVClass *class;
#if HAVE_LIBDC1394_1
dc1394video_frame_t *frame;
#endif
int current_frame;
- int fps;
+ int frame_rate; /**< frames per 1000 seconds (fps * 1000) */
char *video_size; /**< String describing video size, set by a private option. */
+ char *pixel_format; /**< Set by a private option. */
+ char *framerate; /**< Set by a private option. */
AVPacket packet;
} dc1394_data;
struct dc1394_frame_format {
int width;
int height;
- enum PixelFormat pix_fmt;
+ enum AVPixelFormat pix_fmt;
int frame_size_id;
} dc1394_frame_formats[] = {
- { 320, 240, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 },
- { 640, 480, PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 },
- { 640, 480, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 },
+ { 320, 240, AV_PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 },
+ { 640, 480, AV_PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 },
+ { 640, 480, AV_PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 },
{ 0, 0, 0, 0 } /* gotta be the last one */
};
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
#if HAVE_LIBDC1394_1
- { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channel", "", offsetof(dc1394_data, channel), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
#endif
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
+ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
{ NULL },
};
};
-static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap,
+static inline int dc1394_read_common(AVFormatContext *c,
struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps)
{
dc1394_data* dc1394 = c->priv_data;
AVStream* vst;
struct dc1394_frame_format *fmt;
struct dc1394_frame_rate *fps;
- enum PixelFormat pix_fmt = ap->pix_fmt == PIX_FMT_NONE ? PIX_FMT_UYVY422 : ap->pix_fmt; /* defaults */
+ enum AVPixelFormat pix_fmt;
int width, height;
- int frame_rate = !ap->time_base.num ? 30000 : av_rescale(1000, ap->time_base.den, ap->time_base.num);
+ AVRational framerate;
int ret = 0;
+ if ((pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == AV_PIX_FMT_NONE) {
+ av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format);
+ ret = AVERROR(EINVAL);
+ goto out;
+ }
+
if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) {
- av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n");
+ av_log(c, AV_LOG_ERROR, "Could not parse video size '%s'.\n", dc1394->video_size);
goto out;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- width = ap->width;
- if (ap->height > 0)
- height = ap->height;
-#endif
+ if ((ret = av_parse_video_rate(&framerate, dc1394->framerate)) < 0) {
+ av_log(c, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", dc1394->framerate);
+ goto out;
+ }
+ dc1394->frame_rate = av_rescale(1000, framerate.num, framerate.den);
for (fmt = dc1394_frame_formats; fmt->width; fmt++)
if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height)
break;
for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
- if (fps->frame_rate == frame_rate)
+ if (fps->frame_rate == dc1394->frame_rate)
break;
if (!fps->frame_rate || !fmt->width) {
- av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", avcodec_get_pix_fmt_name(pix_fmt),
- width, height, frame_rate);
+ av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", av_get_pix_fmt_name(pix_fmt),
+ width, height, dc1394->frame_rate);
ret = AVERROR(EINVAL);
goto out;
}
/* create a video stream */
- vst = av_new_stream(c, 0);
+ vst = avformat_new_stream(c, NULL);
if (!vst) {
ret = AVERROR(ENOMEM);
goto out;
}
- av_set_pts_info(vst, 64, 1, 1000);
+ avpriv_set_pts_info(vst, 64, 1, 1000);
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- vst->codec->codec_id = CODEC_ID_RAWVIDEO;
- vst->codec->time_base.den = fps->frame_rate;
- vst->codec->time_base.num = 1000;
+ vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
+ vst->codec->time_base.den = framerate.num;
+ vst->codec->time_base.num = framerate.den;
vst->codec->width = fmt->width;
vst->codec->height = fmt->height;
vst->codec->pix_fmt = fmt->pix_fmt;
dc1394->packet.flags |= AV_PKT_FLAG_KEY;
dc1394->current_frame = 0;
- dc1394->fps = fps->frame_rate;
vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
*select_fps = fps;
*select_fmt = fmt;
out:
- av_freep(&dc1394->video_size);
return ret;
}
#if HAVE_LIBDC1394_1
-static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
+static int dc1394_v1_read_header(AVFormatContext *c)
{
dc1394_data* dc1394 = c->priv_data;
AVStream* vst;
struct dc1394_frame_format *fmt = NULL;
struct dc1394_frame_rate *fps = NULL;
- if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
+ if (dc1394_read_common(c, &fmt, &fps) != 0)
return -1;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->channel)
- dc1394->channel = ap->channel;
-#endif
-
/* Now let us prep the hardware. */
dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
if (!dc1394->handle) {
if (res == DC1394_SUCCESS) {
dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer);
- dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->fps;
+ dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->frame_rate;
res = dc1394->packet.size;
} else {
av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
}
#elif HAVE_LIBDC1394_2
-static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
+static int dc1394_v2_read_header(AVFormatContext *c)
{
dc1394_data* dc1394 = c->priv_data;
dc1394camera_list_t *list;
struct dc1394_frame_format *fmt = NULL;
struct dc1394_frame_rate *fps = NULL;
- if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
+ if (dc1394_read_common(c, &fmt, &fps) != 0)
return -1;
/* Now let us prep the hardware. */
res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame);
if (res == DC1394_SUCCESS) {
- dc1394->packet.data = (uint8_t *)(dc1394->frame->image);
- dc1394->packet.pts = (dc1394->current_frame * 1000000) / (dc1394->fps);
+ dc1394->packet.data = (uint8_t *) dc1394->frame->image;
+ dc1394->packet.pts = dc1394->current_frame * 1000000 / dc1394->frame_rate;
res = dc1394->frame->image_bytes;
} else {
av_log(c, AV_LOG_ERROR, "DMA capture failed\n");