diff options
author | Michael Niedermayer | 2011-06-24 02:54:12 +0200 |
---|---|---|
committer | Michael Niedermayer | 2011-06-24 03:07:04 +0200 |
commit | 686959e87e377c0494da636640e36779dd985c30 (patch) | |
tree | 8c4674c56f291638686e6bc3efafe0ef2b921327 /libavdevice | |
parent | ffc6c8a4305d25db8a5af72389a2453b17f43646 (diff) | |
parent | adbfc605f6bbe87b292c82cd1f5d4d974fa6b73c (diff) |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
doxygen: Consistently use '@' instead of '\' for Doxygen markup.
Use av_printf_format to check the usage of printf style functions
Add av_printf_format, for marking printf style format strings and their parameters
ARM: enable thumb for Cortex-M* CPUs
nsvdec: Propagate error values instead of returning 0 in nsv_read_header().
build: remove SRC_PATH_BARE variable
build: move basic rules and variables to main Makefile
build: move special targets to end of main Makefile
lavdev: improve feedback in case of invalid frame rate/size
vfwcap: prefer "framerate_q" over "fps" in vfw_read_header()
v4l2: prefer "framerate_q" over "fps" in v4l2_set_parameters()
fbdev: prefer "framerate_q" over "fps" in device context
bktr: prefer "framerate" over "fps" for grab_read_header()
ALSA: implement channel layout for playback.
alsa: support unsigned variants of already supported signed formats.
alsa: add support for more formats.
ARM: allow building in Thumb2 mode
Conflicts:
common.mak
doc/APIchanges
libavcodec/vdpau.h
libavdevice/alsa-audio-common.c
libavdevice/fbdev.c
libavdevice/libdc1394.c
libavutil/avutil.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavdevice')
-rw-r--r-- | libavdevice/alsa-audio-common.c | 125 | ||||
-rw-r--r-- | libavdevice/alsa-audio.h | 6 | ||||
-rw-r--r-- | libavdevice/bktr.c | 16 | ||||
-rw-r--r-- | libavdevice/fbdev.c | 16 | ||||
-rw-r--r-- | libavdevice/v4l2.c | 26 | ||||
-rw-r--r-- | libavdevice/vfwcap.c | 8 |
6 files changed, 97 insertions, 100 deletions
diff --git a/libavdevice/alsa-audio-common.c b/libavdevice/alsa-audio-common.c index 668ca02201..8c5be3c864 100644 --- a/libavdevice/alsa-audio-common.c +++ b/libavdevice/alsa-audio-common.c @@ -30,6 +30,7 @@ #include <alsa/asoundlib.h> #include "avdevice.h" +#include "libavutil/avassert.h" #include "alsa-audio.h" @@ -64,7 +65,7 @@ static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id) static void alsa_reorder_ ## NAME ## _out_50(const void *in_v, void *out_v, int n) \ { \ const TYPE *in = in_v; \ - TYPE * out = out_v; \ + TYPE *out = out_v; \ \ while (n-- > 0) { \ out[0] = in[0]; \ @@ -81,7 +82,7 @@ static void alsa_reorder_ ## NAME ## _out_50(const void *in_v, void *out_v, int static void alsa_reorder_ ## NAME ## _out_51(const void *in_v, void *out_v, int n) \ { \ const TYPE *in = in_v; \ - TYPE * out = out_v; \ + TYPE *out = out_v; \ \ while (n-- > 0) { \ out[0] = in[0]; \ @@ -99,7 +100,7 @@ static void alsa_reorder_ ## NAME ## _out_51(const void *in_v, void *out_v, int static void alsa_reorder_ ## NAME ## _out_71(const void *in_v, void *out_v, int n) \ { \ const TYPE *in = in_v; \ - TYPE * out = out_v; \ + TYPE *out = out_v; \ \ while (n-- > 0) { \ out[0] = in[0]; \ @@ -128,57 +129,57 @@ REORDER_OUT_50(f32, float) REORDER_OUT_51(f32, float) REORDER_OUT_71(f32, float) -#define REORDER_DUMMY ((void *)1) +#define FORMAT_I8 0 +#define FORMAT_I16 1 +#define FORMAT_I32 2 +#define FORMAT_F32 3 + +#define PICK_REORDER(layout)\ +switch(format) {\ + case FORMAT_I8: s->reorder_func = alsa_reorder_int8_out_ ##layout; break;\ + case FORMAT_I16: s->reorder_func = alsa_reorder_int16_out_ ##layout; break;\ + case FORMAT_I32: s->reorder_func = alsa_reorder_int32_out_ ##layout; break;\ + case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout; break;\ +} -static av_cold ff_reorder_func find_reorder_func(int codec_id, - int64_t layout, - int out) +static av_cold int find_reorder_func(AlsaData *s, int codec_id, int64_t layout, int out) { - return - codec_id == CODEC_ID_PCM_U8 || codec_id == CODEC_ID_PCM_S8 || - codec_id == CODEC_ID_PCM_ALAW || codec_id == CODEC_ID_PCM_MULAW ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_int8_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_int8_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_int8_out_71 : NULL : - NULL : - codec_id == CODEC_ID_PCM_U16LE || codec_id == CODEC_ID_PCM_U16BE || - codec_id == CODEC_ID_PCM_S16LE || codec_id == CODEC_ID_PCM_S16BE ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_int16_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_int16_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_int16_out_71 : NULL : - NULL : - codec_id == CODEC_ID_PCM_U32LE || codec_id == CODEC_ID_PCM_U32BE || - codec_id == CODEC_ID_PCM_S32LE || codec_id == CODEC_ID_PCM_S32BE ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_int32_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_int32_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_int32_out_71 : NULL : - NULL : - codec_id == CODEC_ID_PCM_F32LE || codec_id == CODEC_ID_PCM_F32BE ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_f32_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_f32_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_f32_out_71 : NULL : - NULL : - NULL; + int format; + + /* reordering input is not currently supported */ + if (!out) + return AVERROR(ENOSYS); + + /* reordering is not needed for QUAD or 2_2 layout */ + if (layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2) + return 0; + + switch (codec_id) { + case CODEC_ID_PCM_S8: + case CODEC_ID_PCM_U8: + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_MULAW: format = FORMAT_I8; break; + case CODEC_ID_PCM_S16LE: + case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_U16LE: + case CODEC_ID_PCM_U16BE: format = FORMAT_I16; break; + case CODEC_ID_PCM_S32LE: + case CODEC_ID_PCM_S32BE: + case CODEC_ID_PCM_U32LE: + case CODEC_ID_PCM_U32BE: format = FORMAT_I32; break; + case CODEC_ID_PCM_F32LE: + case CODEC_ID_PCM_F32BE: format = FORMAT_F32; break; + default: return AVERROR(ENOSYS); + } + + if (layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0) + PICK_REORDER(50) + else if (layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1) + PICK_REORDER(51) + else if (layout == AV_CH_LAYOUT_7POINT1) + PICK_REORDER(71) + + return s->reorder_func ? 0 : AVERROR(ENOSYS); } av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, @@ -286,22 +287,17 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, snd_pcm_hw_params_free(hw_params); if (channels > 2 && layout) { - s->reorder_func = find_reorder_func(*codec_id, layout, - mode == SND_PCM_STREAM_PLAYBACK); - if (s->reorder_func == REORDER_DUMMY) { - s->reorder_func = NULL; - } else if (s->reorder_func) { + if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) { + char name[128]; + av_get_channel_layout_string(name, sizeof(name), channels, layout); + av_log(ctx, AV_LOG_WARNING, "ALSA channel layout unknown or unimplemented for %s %s.\n", + name, mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); + } + if (s->reorder_func) { s->reorder_buf_size = buffer_size; s->reorder_buf = av_malloc(s->reorder_buf_size * s->frame_size); if (!s->reorder_buf) goto fail1; - } else { - char name[32]; - av_get_channel_layout_string(name, sizeof(name), channels, layout); - av_log(ctx, AV_LOG_WARNING, - "ALSA channel layout unknown or unimplemented for %s %s.\n", - name, - mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); } } @@ -350,6 +346,7 @@ int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size) int size = s->reorder_buf_size; void *r; + av_assert0(size != 0); while (size < min_size) size *= 2; r = av_realloc(s->reorder_buf, size * s->frame_size); diff --git a/libavdevice/alsa-audio.h b/libavdevice/alsa-audio.h index 431401bb13..0f467e34c9 100644 --- a/libavdevice/alsa-audio.h +++ b/libavdevice/alsa-audio.h @@ -47,11 +47,11 @@ typedef struct { snd_pcm_t *h; int frame_size; ///< preferred size for reads and writes int period_size; ///< bytes per sample * channels - ff_reorder_func reorder_func; - void *reorder_buf; - int reorder_buf_size; ///< in frames int sample_rate; ///< sample rate set by user int channels; ///< number of channels set by user + void (*reorder_func)(const void *, void *, int); + void *reorder_buf; + int reorder_buf_size; ///< in frames } AlsaData; /** diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index f6216e0aa3..9c1afe518b 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -248,7 +248,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) VideoData *s = s1->priv_data; AVStream *st; int width, height; - AVRational fps; + AVRational framerate; int ret = 0; #if FF_API_FORMAT_PARAMETERS @@ -263,7 +263,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) #endif if ((ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { - av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); + av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n", s->video_size); goto out; } @@ -277,8 +277,8 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) ret = AVERROR(EINVAL); goto out; } - if ((ret = av_parse_video_rate(&fps, s->framerate)) < 0) { - av_log(s1, AV_LOG_ERROR, "Couldn't parse framerate.\n"); + if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { + av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", s->framerate); goto out; } #if FF_API_FORMAT_PARAMETERS @@ -287,7 +287,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) if (ap->height > 0) height = ap->height; if (ap->time_base.num) - fps = (AVRational){ap->time_base.den, ap->time_base.num}; + framerate = (AVRational){ap->time_base.den, ap->time_base.num}; #endif st = av_new_stream(s1, 0); @@ -299,15 +299,15 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) s->width = width; s->height = height; - s->per_frame = ((uint64_t)1000000 * fps.den) / fps.num; + s->per_frame = ((uint64_t)1000000 * framerate.den) / framerate.num; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->pix_fmt = PIX_FMT_YUV420P; st->codec->codec_id = CODEC_ID_RAWVIDEO; st->codec->width = width; st->codec->height = height; - st->codec->time_base.den = fps.num; - st->codec->time_base.num = fps.den; + st->codec->time_base.den = framerate.num; + st->codec->time_base.num = framerate.den; if (bktr_init(s1->filename, width, height, s->standard, diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c index d5ba561db8..a10d8c48c1 100644 --- a/libavdevice/fbdev.c +++ b/libavdevice/fbdev.c @@ -79,7 +79,7 @@ static enum PixelFormat get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *var typedef struct { AVClass *class; ///< class for private options int frame_size; ///< size in bytes of a grabbed frame - AVRational fps; ///< framerate + AVRational framerate_q; ///< framerate char *framerate; ///< framerate string set by a private option int64_t time_frame; ///< time for the next frame to output (in 1/1000000 units) @@ -102,14 +102,14 @@ av_cold static int fbdev_read_header(AVFormatContext *avctx, enum PixelFormat pix_fmt; int ret, flags = O_RDONLY; - ret = av_parse_video_rate(&fbdev->fps, fbdev->framerate); + ret = av_parse_video_rate(&fbdev->framerate_q, fbdev->framerate); if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Couldn't parse framerate.\n"); + av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", fbdev->framerate); return ret; } #if FF_API_FORMAT_PARAMETERS if (ap->time_base.num) - fbdev->fps = (AVRational){ap->time_base.den, ap->time_base.num}; + fbdev->framerate_q = (AVRational){ap->time_base.den, ap->time_base.num}; #endif if (!(st = av_new_stream(avctx, 0))) @@ -168,15 +168,15 @@ av_cold static int fbdev_read_header(AVFormatContext *avctx, st->codec->width = fbdev->width; st->codec->height = fbdev->heigth; st->codec->pix_fmt = pix_fmt; - st->codec->time_base = (AVRational){fbdev->fps.den, fbdev->fps.num}; + st->codec->time_base = (AVRational){fbdev->framerate_q.den, fbdev->framerate_q.num}; st->codec->bit_rate = - fbdev->width * fbdev->heigth * fbdev->bytes_per_pixel * av_q2d(fbdev->fps) * 8; + fbdev->width * fbdev->heigth * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8; av_log(avctx, AV_LOG_INFO, "w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n", fbdev->width, fbdev->heigth, fbdev->varinfo.bits_per_pixel, av_pix_fmt_descriptors[pix_fmt].name, - fbdev->fps.num, fbdev->fps.den, + fbdev->framerate_q.num, fbdev->framerate_q.den, st->codec->bit_rate); return 0; @@ -204,7 +204,7 @@ static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt) "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n", fbdev->time_frame, curtime, delay); if (delay <= 0) { - fbdev->time_frame += INT64_C(1000000) / av_q2d(fbdev->fps); + fbdev->time_frame += INT64_C(1000000) / av_q2d(fbdev->framerate_q); break; } if (avctx->flags & AVFMT_FLAG_NONBLOCK) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 7223654891..468c133f60 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -439,19 +439,19 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) struct v4l2_streamparm streamparm = {0}; struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe; int i, ret; - AVRational fps; + AVRational framerate_q; streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (s->framerate && (ret = av_parse_video_rate(&fps, s->framerate)) < 0) { - av_log(s1, AV_LOG_ERROR, "Couldn't parse framerate.\n"); + if (s->framerate && (ret = av_parse_video_rate(&framerate_q, s->framerate)) < 0) { + av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", s->framerate); return ret; } #if FF_API_FORMAT_PARAMETERS if (ap->channel > 0) s->channel = ap->channel; if (ap->time_base.num) - fps = (AVRational){ap->time_base.den, ap->time_base.num}; + framerate_q = (AVRational){ap->time_base.den, ap->time_base.num}; #endif /* set tv video input */ @@ -500,23 +500,23 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) } } - if (fps.num && fps.den) { + if (framerate_q.num && framerate_q.den) { av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n", - fps.den, fps.num); - tpf->numerator = fps.den; - tpf->denominator = fps.num; + 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", - fps.den, fps.num); + framerate_q.den, framerate_q.num); return AVERROR(EIO); } - if (fps.num != tpf->denominator || - fps.den != tpf->numerator) { + 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", - fps.den, fps.num, + framerate_q.den, framerate_q.num, tpf->numerator, tpf->denominator); } } else { @@ -581,7 +581,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ if (s->video_size && (res = av_parse_video_size(&s->width, &s->height, s->video_size)) < 0) { - av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); + av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n", s->video_size); goto out; } if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) { diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index a8e67e7dda..7279817529 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -247,7 +247,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) DWORD biCompression; WORD biBitCount; int ret; - AVRational fps; + AVRational framerate_q; if (!strcmp(s->filename, "list")) { for (devnum = 0; devnum <= 9; devnum++) { @@ -267,7 +267,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) #if FF_API_FORMAT_PARAMETERS if (ap->time_base.num) - fps = (AVRational){ap->time_base.den, ap->time_base.num}; + framerate_q = (AVRational){ap->time_base.den, ap->time_base.num}; #endif ctx->hwnd = capCreateCaptureWindow(NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0); @@ -367,7 +367,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) cparms.fYield = 1; // Spawn a background thread cparms.dwRequestMicroSecPerFrame = - (fps.den*1000000) / fps.num; + (framerate_q.den*1000000) / framerate_q.num; cparms.fAbortLeftMouse = 0; cparms.fAbortRightMouse = 0; cparms.fCaptureAudio = 0; @@ -379,7 +379,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) goto fail_io; codec = st->codec; - codec->time_base = (AVRational){fps.den, fps.num}; + codec->time_base = (AVRational){framerate_q.den, framerate_q.num}; codec->codec_type = AVMEDIA_TYPE_VIDEO; codec->width = bi->bmiHeader.biWidth; codec->height = bi->bmiHeader.biHeight; |