diff options
Diffstat (limited to 'libavdevice')
-rw-r--r-- | libavdevice/Makefile | 1 | ||||
-rw-r--r-- | libavdevice/alldevices.c | 9 | ||||
-rw-r--r-- | libavdevice/alsa-audio-common.c | 98 | ||||
-rw-r--r-- | libavdevice/alsa-audio-dec.c | 8 | ||||
-rw-r--r-- | libavdevice/alsa-audio-enc.c | 18 | ||||
-rw-r--r-- | libavdevice/alsa-audio.h | 15 | ||||
-rw-r--r-- | libavdevice/avdevice.c | 12 | ||||
-rw-r--r-- | libavdevice/avdevice.h | 8 | ||||
-rw-r--r-- | libavdevice/bktr.c | 8 | ||||
-rw-r--r-- | libavdevice/dv1394.c | 8 | ||||
-rw-r--r-- | libavdevice/dv1394.h | 8 | ||||
-rw-r--r-- | libavdevice/fbdev.c | 252 | ||||
-rw-r--r-- | libavdevice/jack_audio.c | 8 | ||||
-rw-r--r-- | libavdevice/libdc1394.c | 8 | ||||
-rw-r--r-- | libavdevice/oss_audio.c | 8 | ||||
-rw-r--r-- | libavdevice/v4l.c | 8 | ||||
-rw-r--r-- | libavdevice/v4l2.c | 8 | ||||
-rw-r--r-- | libavdevice/vfwcap.c | 8 | ||||
-rw-r--r-- | libavdevice/x11grab.c | 10 |
19 files changed, 431 insertions, 72 deletions
diff --git a/libavdevice/Makefile b/libavdevice/Makefile index efc18cbcbd..5cfc5e8ecc 100644 --- a/libavdevice/Makefile +++ b/libavdevice/Makefile @@ -14,6 +14,7 @@ OBJS-$(CONFIG_ALSA_OUTDEV) += alsa-audio-common.o \ alsa-audio-enc.o OBJS-$(CONFIG_BKTR_INDEV) += bktr.o OBJS-$(CONFIG_DV1394_INDEV) += dv1394.o +OBJS-$(CONFIG_FBDEV_INDEV) += fbdev.o OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o OBJS-$(CONFIG_OSS_INDEV) += oss_audio.o OBJS-$(CONFIG_OSS_OUTDEV) += oss_audio.o diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c index 9cbb977813..a0c9b08c6f 100644 --- a/libavdevice/alldevices.c +++ b/libavdevice/alldevices.c @@ -1,20 +1,20 @@ /* * Register all the grabbing devices. * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ @@ -42,6 +42,7 @@ void avdevice_register_all(void) REGISTER_INOUTDEV (ALSA, alsa); REGISTER_INDEV (BKTR, bktr); REGISTER_INDEV (DV1394, dv1394); + REGISTER_INDEV (FBDEV, fbdev); REGISTER_INDEV (JACK, jack); REGISTER_INOUTDEV (OSS, oss); REGISTER_INOUTDEV (SNDIO, sndio); diff --git a/libavdevice/alsa-audio-common.c b/libavdevice/alsa-audio-common.c index ff6c9f875d..4edd25bcd7 100644 --- a/libavdevice/alsa-audio-common.c +++ b/libavdevice/alsa-audio-common.c @@ -3,20 +3,20 @@ * Copyright (c) 2007 Luca Abeni ( lucabe72 email it ) * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr ) * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ @@ -43,6 +43,59 @@ static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id) } } +static void alsa_reorder_s16_out_51(const void *in_v, void *out_v, int n) +{ + const int16_t *in = in_v; + int16_t *out = out_v; + + while (n-- > 0) { + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[4]; + out[3] = in[5]; + out[4] = in[2]; + out[5] = in[3]; + in += 6; + out += 6; + } +} + +static void alsa_reorder_s16_out_71(const void *in_v, void *out_v, int n) +{ + const int16_t *in = in_v; + int16_t *out = out_v; + + while (n-- > 0) { + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[4]; + out[3] = in[5]; + out[4] = in[2]; + out[5] = in[3]; + out[6] = in[6]; + out[7] = in[7]; + in += 8; + out += 8; + } +} + +#define REORDER_DUMMY ((void *)1) + +static av_cold ff_reorder_func find_reorder_func(int codec_id, + int64_t layout, + int out) +{ + return + codec_id == CODEC_ID_PCM_S16LE || codec_id == CODEC_ID_PCM_S16BE ? + layout == AV_CH_LAYOUT_QUAD ? REORDER_DUMMY : + layout == AV_CH_LAYOUT_5POINT1_BACK ? + out ? alsa_reorder_s16_out_51 : NULL : + layout == AV_CH_LAYOUT_7POINT1 ? + out ? alsa_reorder_s16_out_71 : NULL : + NULL : + NULL; +} + av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, unsigned int *sample_rate, int channels, enum CodecID *codec_id) @@ -54,6 +107,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, snd_pcm_t *h; snd_pcm_hw_params_t *hw_params; snd_pcm_uframes_t buffer_size, period_size; + int64_t layout = ctx->streams[0]->codec->channel_layout; if (ctx->filename[0] == 0) audio_device = "default"; else audio_device = ctx->filename; @@ -146,6 +200,26 @@ 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) { + 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[16]; + 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"); + } + } + s->h = h; return 0; @@ -160,6 +234,7 @@ av_cold int ff_alsa_close(AVFormatContext *s1) { AlsaData *s = s1->priv_data; + av_freep(s->reorder_buf); snd_pcm_close(s->h); return 0; } @@ -184,3 +259,18 @@ int ff_alsa_xrun_recover(AVFormatContext *s1, int err) } return err; } + +int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size) +{ + int size = s->reorder_buf_size; + void *r; + + while (size < min_size) + size *= 2; + r = av_realloc(s->reorder_buf, size * s->frame_size); + if (!r) + return AVERROR(ENOMEM); + s->reorder_buf = r; + s->reorder_buf_size = size; + return 0; +} diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c index c467fc097f..8ee0e52642 100644 --- a/libavdevice/alsa-audio-dec.c +++ b/libavdevice/alsa-audio-dec.c @@ -3,20 +3,20 @@ * Copyright (c) 2007 Luca Abeni ( lucabe72 email it ) * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr ) * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/alsa-audio-enc.c b/libavdevice/alsa-audio-enc.c index ebe598c86f..0bc53b6f54 100644 --- a/libavdevice/alsa-audio-enc.c +++ b/libavdevice/alsa-audio-enc.c @@ -3,20 +3,20 @@ * Copyright (c) 2007 Luca Abeni ( lucabe72 email it ) * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr ) * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ @@ -76,7 +76,15 @@ static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt) int size = pkt->size; uint8_t *buf = pkt->data; - while((res = snd_pcm_writei(s->h, buf, size / s->frame_size)) < 0) { + size /= s->frame_size; + if (s->reorder_func) { + if (size > s->reorder_buf_size) + if (ff_alsa_extend_reorder_buf(s, size)) + return AVERROR(ENOMEM); + s->reorder_func(buf, s->reorder_buf, size); + buf = s->reorder_buf; + } + while ((res = snd_pcm_writei(s->h, buf, size)) < 0) { if (res == -EAGAIN) { return AVERROR(EAGAIN); diff --git a/libavdevice/alsa-audio.h b/libavdevice/alsa-audio.h index 7a1b01811b..8c7c516585 100644 --- a/libavdevice/alsa-audio.h +++ b/libavdevice/alsa-audio.h @@ -3,20 +3,20 @@ * Copyright (c) 2007 Luca Abeni ( lucabe72 email it ) * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr ) * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ @@ -39,10 +39,15 @@ other formats */ #define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE) +typedef void (*ff_reorder_func)(const void *, void *, int); + 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 } AlsaData; /** @@ -82,4 +87,6 @@ int ff_alsa_close(AVFormatContext *s1); */ int ff_alsa_xrun_recover(AVFormatContext *s1, int err); +int ff_alsa_extend_reorder_buf(AlsaData *s, int size); + #endif /* AVDEVICE_ALSA_AUDIO_H */ diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 4813a3dd18..3d67b4b8be 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -1,18 +1,18 @@ /* - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ @@ -25,11 +25,11 @@ unsigned avdevice_version(void) const char * avdevice_configuration(void) { - return LIBAV_CONFIGURATION; + return FFMPEG_CONFIGURATION; } const char * avdevice_license(void) { #define LICENSE_PREFIX "libavdevice license: " - return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1; + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; } diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 28c12f2ecd..23e3f3132b 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -1,18 +1,18 @@ /* - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index 3e705a0247..cec79a4989 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -7,20 +7,20 @@ * and * simple_grab.c Copyright (c) 1999 Roger Hardiman * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c index 70f928ed80..588f35662b 100644 --- a/libavdevice/dv1394.c +++ b/libavdevice/dv1394.c @@ -2,20 +2,20 @@ * Linux DV1394 interface * Copyright (c) 2003 Max Krasnyansky <maxk@qualcomm.com> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/dv1394.h b/libavdevice/dv1394.h index 5ccc68a259..00706f7541 100644 --- a/libavdevice/dv1394.h +++ b/libavdevice/dv1394.h @@ -8,20 +8,20 @@ * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au> * Peter Schlaile <udbz@rz.uni-karlsruhe.de> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c new file mode 100644 index 0000000000..121f02ccff --- /dev/null +++ b/libavdevice/fbdev.c @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2011 Stefano Sabatini + * Copyright (c) 2009 Giliard B. de Freitas <giliarde@gmail.com> + * Copyright (C) 2002 Gunnar Monell <gmo@linux.nu> + * + * 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.1 of the License, or (at your option) any later version. + * + * 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Linux framebuffer input device, + * inspired by code from fbgrab.c by Gunnar Monell. + * See also http://linux-fbdev.sourceforge.net/. + */ + +/* #define DEBUG */ + +#include <unistd.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <sys/mman.h> +#include <time.h> +#include <linux/fb.h> + +#include "libavutil/mem.h" +#include "libavutil/pixdesc.h" +#include "libavformat/avformat.h" + +struct rgb_pixfmt_map_entry { + int bits_per_pixel; + int red_offset, green_offset, blue_offset, alpha_offset; + enum PixelFormat pixfmt; +}; + +static struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = { + // bpp, red_offset, green_offset, blue_offset, alpha_offset, pixfmt + { 32, 0, 8, 16, 24, PIX_FMT_RGBA }, + { 32, 16, 8, 0, 24, PIX_FMT_BGRA }, + { 32, 8, 16, 24, 0, PIX_FMT_ARGB }, + { 32, 3, 2, 8, 0, PIX_FMT_ABGR }, + { 24, 0, 8, 16, 0, PIX_FMT_RGB24 }, + { 24, 16, 8, 0, 0, PIX_FMT_BGR24 }, +}; + +static enum PixelFormat +get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo) +{ + int i; + + for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) { + struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i]; + if (entry->bits_per_pixel == varinfo->bits_per_pixel && + entry->red_offset == varinfo->red.offset && + entry->green_offset == varinfo->green.offset && + entry->blue_offset == varinfo->blue.offset) + return entry->pixfmt; + } + + return PIX_FMT_NONE; +} + +typedef struct { + int frame_size; ///< size in bytes of a grabbed frame + AVRational time_base; ///< time base + int64_t time_frame; ///< time for the next frame to output (in 1/1000000 units) + + int fd; ///< framebuffer device file descriptor + int width, heigth; ///< assumed frame resolution + int frame_linesize; ///< linesize of the output frame, it is assumed to be constant + int bytes_per_pixel; + + struct fb_var_screeninfo varinfo; ///< variable info; + struct fb_fix_screeninfo fixinfo; ///< fixed info; + + uint8_t *data; ///< framebuffer data +} FBDevContext; + +av_cold static int fbdev_read_header(AVFormatContext *avctx, + AVFormatParameters *ap) +{ + FBDevContext *fbdev = avctx->priv_data; + AVStream *st = NULL; + enum PixelFormat pix_fmt; + int ret, flags = O_RDONLY; + + if (!(st = av_new_stream(avctx, 0))) + return AVERROR(ENOMEM); + av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in microseconds */ + + if (ap->time_base.den <= 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid time base %d/%d\n", + ap->time_base.num, ap->time_base.den); + return AVERROR(EINVAL); + } + + /* NONBLOCK is ignored by the fbdev driver, only set for consistency */ + if (avctx->flags & AVFMT_FLAG_NONBLOCK) + flags |= O_NONBLOCK; + + if ((fbdev->fd = open(avctx->filename, flags)) == -1) { + ret = AVERROR(errno); + av_log(avctx, AV_LOG_ERROR, + "Could not open framebuffer device '%s': %s\n", + avctx->filename, strerror(ret)); + return ret; + } + + if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) { + ret = AVERROR(errno); + av_log(avctx, AV_LOG_ERROR, + "FBIOGET_VSCREENINFO: %s\n", strerror(errno)); + goto fail; + } + + if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) { + ret = AVERROR(errno); + av_log(avctx, AV_LOG_ERROR, + "FBIOGET_FSCREENINFO: %s\n", strerror(errno)); + goto fail; + } + + pix_fmt = get_pixfmt_from_fb_varinfo(&fbdev->varinfo); + if (pix_fmt == PIX_FMT_NONE) { + ret = AVERROR(EINVAL); + av_log(avctx, AV_LOG_ERROR, + "Framebuffer pixel format not supported.\n"); + goto fail; + } + + fbdev->width = fbdev->varinfo.xres; + fbdev->heigth = fbdev->varinfo.yres; + fbdev->bytes_per_pixel = (fbdev->varinfo.bits_per_pixel + 7) >> 3; + fbdev->frame_linesize = fbdev->width * fbdev->bytes_per_pixel; + fbdev->frame_size = fbdev->frame_linesize * fbdev->heigth; + fbdev->time_base = ap->time_base; + fbdev->time_frame = AV_NOPTS_VALUE; + fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_READ, MAP_SHARED, fbdev->fd, 0); + if (fbdev->data == MAP_FAILED) { + ret = AVERROR(errno); + av_log(avctx, AV_LOG_ERROR, "Error in mmap(): %s\n", strerror(errno)); + goto fail; + } + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->width = fbdev->width; + st->codec->height = fbdev->heigth; + st->codec->pix_fmt = pix_fmt; + st->codec->time_base = ap->time_base; + st->codec->bit_rate = + fbdev->width * fbdev->heigth * fbdev->bytes_per_pixel / av_q2d(ap->time_base) * 8; + + av_log(avctx, AV_LOG_INFO, + "w:%d h:%d bpp:%d pixfmt:%s tb:%d/%d bit_rate:%d\n", + fbdev->width, fbdev->heigth, fbdev->varinfo.bits_per_pixel, + av_pix_fmt_descriptors[pix_fmt].name, + ap->time_base.num, ap->time_base.den, + st->codec->bit_rate); + return 0; + +fail: + close(fbdev->fd); + return ret; +} + +static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt) +{ + FBDevContext *fbdev = avctx->priv_data; + int64_t curtime, delay; + struct timespec ts; + int i, ret; + uint8_t *pin, *pout; + + if (fbdev->time_frame == AV_NOPTS_VALUE) + fbdev->time_frame = av_gettime(); + + /* wait based on the frame rate */ + while (1) { + curtime = av_gettime(); + delay = fbdev->time_frame - curtime; + av_dlog(avctx, + "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->time_base); + break; + } + if (avctx->flags & AVFMT_FLAG_NONBLOCK) + return AVERROR(EAGAIN); + ts.tv_sec = delay / 1000000; + ts.tv_nsec = (delay % 1000000) * 1000; + while (nanosleep(&ts, &ts) < 0 && errno == EINTR); + } + + if ((ret = av_new_packet(pkt, fbdev->frame_size)) < 0) + return ret; + + /* refresh fbdev->varinfo, visible data position may change at each call */ + if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) + av_log(avctx, AV_LOG_WARNING, + "Error refreshing variable info: %s\n", strerror(errno)); + + pkt->pts = curtime; + + /* compute visible data offset */ + pin = fbdev->data + fbdev->bytes_per_pixel * fbdev->varinfo.xoffset + + fbdev->varinfo.yoffset * fbdev->fixinfo.line_length; + pout = pkt->data; + + for (i = 0; i < fbdev->heigth; i++) { + memcpy(pout, pin, fbdev->frame_linesize); + pin += fbdev->fixinfo.line_length; + pout += fbdev->frame_linesize; + } + + return fbdev->frame_size; +} + +av_cold static int fbdev_read_close(AVFormatContext *avctx) +{ + FBDevContext *fbdev = avctx->priv_data; + + munmap(fbdev->data, fbdev->frame_size); + close(fbdev->fd); + + return 0; +} + +AVInputFormat ff_fbdev_demuxer = { + .name = "fbdev", + .long_name = NULL_IF_CONFIG_SMALL("Linux framebuffer"), + .priv_data_size = sizeof(FBDevContext), + .read_header = fbdev_read_header, + .read_packet = fbdev_read_packet, + .read_close = fbdev_read_close, + .flags = AVFMT_NOFILE, +}; diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c index 4af89bda9e..9062e7f2dd 100644 --- a/libavdevice/jack_audio.c +++ b/libavdevice/jack_audio.c @@ -3,20 +3,20 @@ * Copyright (c) 2009 Samalyse * Author: Olivier Guilyardi <olivier samalyse com> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index e637af5f74..abd82dc981 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -3,20 +3,20 @@ * Copyright (c) 2004 Roman Shaposhnik * Copyright (c) 2008 Alessandro Sappia * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c index 7c4a65dda2..d2ba601f7a 100644 --- a/libavdevice/oss_audio.c +++ b/libavdevice/oss_audio.c @@ -2,20 +2,20 @@ * Linux audio play and grab interface * Copyright (c) 2000, 2001 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/v4l.c b/libavdevice/v4l.c index b3725eb0f2..9a155f9df6 100644 --- a/libavdevice/v4l.c +++ b/libavdevice/v4l.c @@ -2,20 +2,20 @@ * Linux video grab interface * Copyright (c) 2000,2001 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 8e0a6e64db..1f1a4bcfb8 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -10,20 +10,20 @@ * V4L2_PIX_FMT_* and PIX_FMT_* * * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index 8eecf5bdff..2155db6ece 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -2,20 +2,20 @@ * VFW capture interface * Copyright (c) 2006-2008 Ramiro Polla * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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.1 of the License, or (at your option) any later version. * - * Libav 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 Libav; 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 */ diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c index aaad7292c6..be0586a7db 100644 --- a/libavdevice/x11grab.c +++ b/libavdevice/x11grab.c @@ -1,9 +1,9 @@ /* * X11 video grab interface * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav integration: + * FFmpeg integration: * Copyright (C) 2006 Clemens Fruhwirth <clemens@endorphin.org> * Edouard Gomez <ed.gomez@free.fr> * @@ -14,18 +14,18 @@ * Copyright (C) 1997-1998 Rasca, Berlin * 2003-2004 Karl H. Beckers, Frankfurt * - * Libav is free software; you can redistribute it and/or modify + * FFmpeg is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * Libav 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 General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Libav; if not, write to the Free Software + * along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |