Re: [FFmpeg-devel] [PATCH]lavf/shortendec: Autodetect raw Shorten streams.
On Fri, Oct 02, 2015 at 01:05:50PM +0200, Carl Eugen Hoyos wrote: > On Friday 02 October 2015 12:48:17 pm Paul B Mahol wrote: > > On 10/2/15, Carl Eugen Hoyoswrote: > > > Hi! > > > > > > Attached patch implements Shorten auto-detection. > > > > > > Please comment, Carl Eugen > > > > You do not check byte size > > I thought both the safe bitstream reader and the minimal > probe buffer size avoid an overread here. > Is that wrong? > > > and not using init_get_bits8. > > Fixed, thank you! > > New patch attached, Carl Eugen > Makefile |2 - > rawdec.c | 12 - > shortendec.c | 71 > +++ > version.h|2 - > 4 files changed, 73 insertions(+), 14 deletions(-) > 5c59131e01c4a4e864963890fdebf635eeb1df3c patchshn.diff LGTM [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH]lavf/shortendec: Autodetect raw Shorten streams.
On Saturday 03 October 2015 06:51:26 pm Michael Niedermayer wrote: > > Makefile |2 - > > rawdec.c | 12 - > > shortendec.c | 71 > > +++ version.h > > |2 - > > 4 files changed, 73 insertions(+), 14 deletions(-) > > 5c59131e01c4a4e864963890fdebf635eeb1df3c patchshn.diff > > LGTM Patch applied. Thank you, Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH]lavf/shortendec: Autodetect raw Shorten streams.
On 10/2/15, Carl Eugen Hoyoswrote: > Hi! > > Attached patch implements Shorten auto-detection. > > Please comment, Carl Eugen > You do not check byte size. and not using init_get_bits8. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH]lavf/shortendec: Autodetect raw Shorten streams.
Hi! Attached patch implements Shorten auto-detection. Please comment, Carl Eugen diff --git a/libavformat/Makefile b/libavformat/Makefile index 466da51..a9af797 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -403,7 +403,7 @@ OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o OBJS-$(CONFIG_SDR2_DEMUXER) += sdr2.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SEGMENT_MUXER) += segment.o -OBJS-$(CONFIG_SHORTEN_DEMUXER) += rawdec.o +OBJS-$(CONFIG_SHORTEN_DEMUXER) += shortendec.o rawdec.o OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o OBJS-$(CONFIG_SINGLEJPEG_MUXER) += rawenc.o OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index ef84d37..46ee21e 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -266,18 +266,6 @@ AVInputFormat ff_truehd_demuxer = { }; #endif -#if CONFIG_SHORTEN_DEMUXER -AVInputFormat ff_shorten_demuxer = { -.name = "shn", -.long_name = NULL_IF_CONFIG_SMALL("raw Shorten"), -.read_header= ff_raw_audio_read_header, -.read_packet= ff_raw_read_partial_packet, -.flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK|AVFMT_NOTIMESTAMPS, -.extensions = "shn", -.raw_codec_id = AV_CODEC_ID_SHORTEN, -}; -#endif - #if CONFIG_VC1_DEMUXER FF_DEF_RAWVIDEO_DEMUXER2(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS) #endif diff --git a/libavformat/shortendec.c b/libavformat/shortendec.c index e69de29..2b13fb7 100644 --- a/libavformat/shortendec.c +++ b/libavformat/shortendec.c @@ -0,0 +1,70 @@ +/* + * Shorten demuxer + * Copyright (c) 2001 Fabrice Bellard + * Copyright (c) 2005 Alex Beregszaszi + * Copyright (c) 2015 Carl Eugen Hoyos + * + * 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 + */ + +#include "avformat.h" +#include "rawdec.h" +#include "libavcodec/golomb.h" + +static int shn_probe(AVProbeData *p) +{ +GetBitContext gb; +int version, internal_ftype, channels, blocksize; + +if (AV_RB32(p->buf) != 0x616a6b67) +return 0; +version = p->buf[4]; +init_get_bits(, p->buf + 5, p->buf_size - 5); +if (!version) { +internal_ftype = get_ur_golomb_shorten(, 4); +channels = get_ur_golomb_shorten(, 0); +blocksize = 256; +} else { +int k; +k = get_ur_golomb_shorten(, 2); +internal_ftype = get_ur_golomb_shorten(, k); +k = get_ur_golomb_shorten(, 2); +channels = get_ur_golomb_shorten(, k); +k = get_ur_golomb_shorten(, 2); +blocksize = get_ur_golomb_shorten(, k); +} + +if (internal_ftype != 2 && internal_ftype != 3 && internal_ftype != 5) +return 0; +if (channels < 1 || channels > 8) +return 0; +if (blocksize < 1 || blocksize > 65535) +return 0; + +return AVPROBE_SCORE_EXTENSION + 1; +} + +AVInputFormat ff_shorten_demuxer = { +.name = "shn", +.long_name = NULL_IF_CONFIG_SMALL("raw Shorten"), +.read_probe = shn_probe, +.read_header= ff_raw_audio_read_header, +.read_packet= ff_raw_read_partial_packet, +.flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS, +.extensions = "shn", +.raw_codec_id = AV_CODEC_ID_SHORTEN, +}; diff --git a/libavformat/version.h b/libavformat/version.h index 4c60e50..b4c4d23 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 2 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MICRO 103 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH]lavf/shortendec: Autodetect raw Shorten streams.
On Friday 02 October 2015 12:48:17 pm Paul B Mahol wrote: > On 10/2/15, Carl Eugen Hoyoswrote: > > Hi! > > > > Attached patch implements Shorten auto-detection. > > > > Please comment, Carl Eugen > > You do not check byte size I thought both the safe bitstream reader and the minimal probe buffer size avoid an overread here. Is that wrong? > and not using init_get_bits8. Fixed, thank you! New patch attached, Carl Eugen diff --git a/libavformat/Makefile b/libavformat/Makefile index 466da51..a9af797 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -403,7 +403,7 @@ OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o OBJS-$(CONFIG_SDR2_DEMUXER) += sdr2.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SEGMENT_MUXER) += segment.o -OBJS-$(CONFIG_SHORTEN_DEMUXER) += rawdec.o +OBJS-$(CONFIG_SHORTEN_DEMUXER) += shortendec.o rawdec.o OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o OBJS-$(CONFIG_SINGLEJPEG_MUXER) += rawenc.o OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index ef84d37..46ee21e 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -266,18 +266,6 @@ AVInputFormat ff_truehd_demuxer = { }; #endif -#if CONFIG_SHORTEN_DEMUXER -AVInputFormat ff_shorten_demuxer = { -.name = "shn", -.long_name = NULL_IF_CONFIG_SMALL("raw Shorten"), -.read_header= ff_raw_audio_read_header, -.read_packet= ff_raw_read_partial_packet, -.flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK|AVFMT_NOTIMESTAMPS, -.extensions = "shn", -.raw_codec_id = AV_CODEC_ID_SHORTEN, -}; -#endif - #if CONFIG_VC1_DEMUXER FF_DEF_RAWVIDEO_DEMUXER2(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS) #endif diff --git a/libavformat/shortendec.c b/libavformat/shortendec.c index e69de29..42fcdf7 100644 --- a/libavformat/shortendec.c +++ b/libavformat/shortendec.c @@ -0,0 +1,71 @@ +/* + * Shorten demuxer + * Copyright (c) 2001 Fabrice Bellard + * Copyright (c) 2005 Alex Beregszaszi + * Copyright (c) 2015 Carl Eugen Hoyos + * + * 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 + */ + +#include "avformat.h" +#include "rawdec.h" +#include "libavcodec/golomb.h" + +static int shn_probe(AVProbeData *p) +{ +GetBitContext gb; +int version, internal_ftype, channels, blocksize; + +if (AV_RB32(p->buf) != 0x616a6b67) +return 0; +version = p->buf[4]; +if (init_get_bits8(, p->buf + 5, p->buf_size - 5 - AV_INPUT_BUFFER_PADDING_SIZE) < 0) +return 0; +if (!version) { +internal_ftype = get_ur_golomb_shorten(, 4); +channels = get_ur_golomb_shorten(, 0); +blocksize = 256; +} else { +int k; +k = get_ur_golomb_shorten(, 2); +internal_ftype = get_ur_golomb_shorten(, k); +k = get_ur_golomb_shorten(, 2); +channels = get_ur_golomb_shorten(, k); +k = get_ur_golomb_shorten(, 2); +blocksize = get_ur_golomb_shorten(, k); +} + +if (internal_ftype != 2 && internal_ftype != 3 && internal_ftype != 5) +return 0; +if (channels < 1 || channels > 8) +return 0; +if (blocksize < 1 || blocksize > 65535) +return 0; + +return AVPROBE_SCORE_EXTENSION + 1; +} + +AVInputFormat ff_shorten_demuxer = { +.name = "shn", +.long_name = NULL_IF_CONFIG_SMALL("raw Shorten"), +.read_probe = shn_probe, +.read_header= ff_raw_audio_read_header, +.read_packet= ff_raw_read_partial_packet, +.flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS, +.extensions = "shn", +.raw_codec_id = AV_CODEC_ID_SHORTEN, +}; diff --git a/libavformat/version.h b/libavformat/version.h index 4c60e50..b4c4d23 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 2 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MICRO 103 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \