diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-20 09:47:09 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-07 11:15:42 +0000 |
commit | 189d4fd8fad9e3c776873be51938cd31a42b6177 (patch) | |
tree | 6497caeff5e383937996768766ab3bb2081a40b2 /chromium/third_party/ffmpeg/libavformat | |
parent | 8bc75099d364490b22f43a7ce366b366c08f4164 (diff) | |
download | qtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz |
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/ffmpeg/libavformat')
127 files changed, 2814 insertions, 1278 deletions
diff --git a/chromium/third_party/ffmpeg/libavformat/Makefile b/chromium/third_party/ffmpeg/libavformat/Makefile index 213004cb452..97d868081b6 100644 --- a/chromium/third_party/ffmpeg/libavformat/Makefile +++ b/chromium/third_party/ffmpeg/libavformat/Makefile @@ -71,6 +71,7 @@ OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o apetag.o img2.o rawdec.o OBJS-$(CONFIG_AAX_DEMUXER) += aaxdec.o OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o OBJS-$(CONFIG_AC3_MUXER) += rawenc.o +OBJS-$(CONFIG_ACE_DEMUXER) += acedec.o OBJS-$(CONFIG_ACM_DEMUXER) += acm.o rawdec.o OBJS-$(CONFIG_ACT_DEMUXER) += act.o OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o @@ -87,10 +88,12 @@ OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o pcm.o isom.o \ OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o id3v2enc.o OBJS-$(CONFIG_AIX_DEMUXER) += aixdec.o OBJS-$(CONFIG_ALP_DEMUXER) += alp.o +OBJS-$(CONFIG_ALP_MUXER) += alp.o OBJS-$(CONFIG_AMR_DEMUXER) += amr.o OBJS-$(CONFIG_AMR_MUXER) += amr.o rawenc.o OBJS-$(CONFIG_AMRNB_DEMUXER) += amr.o OBJS-$(CONFIG_AMRWB_DEMUXER) += amr.o +OBJS-$(CONFIG_AMV_MUXER) += amvenc.o OBJS-$(CONFIG_ANM_DEMUXER) += anm.o OBJS-$(CONFIG_APC_DEMUXER) += apc.o OBJS-$(CONFIG_APE_DEMUXER) += ape.o apetag.o img2.o @@ -122,8 +125,9 @@ OBJS-$(CONFIG_AVI_MUXER) += avienc.o mpegtsenc.o avlanguage.o ra OBJS-$(CONFIG_AVM2_MUXER) += swfenc.o swf.o OBJS-$(CONFIG_AVR_DEMUXER) += avr.o pcm.o OBJS-$(CONFIG_AVS_DEMUXER) += avs.o voc_packet.o vocdec.o voc.o -OBJS-$(CONFIG_AVS2_DEMUXER) += davs2.o rawdec.o +OBJS-$(CONFIG_AVS2_DEMUXER) += avs2dec.o rawdec.o OBJS-$(CONFIG_AVS2_MUXER) += rawenc.o +OBJS-$(CONFIG_AVS3_DEMUXER) += avs3dec.o rawdec.o OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o OBJS-$(CONFIG_BINK_DEMUXER) += bink.o @@ -353,6 +357,7 @@ OBJS-$(CONFIG_MPL2_DEMUXER) += mpl2dec.o subtitles.o OBJS-$(CONFIG_MSF_DEMUXER) += msf.o OBJS-$(CONFIG_MPSUB_DEMUXER) += mpsubdec.o subtitles.o OBJS-$(CONFIG_MSNWC_TCP_DEMUXER) += msnwc_tcp.o +OBJS-$(CONFIG_MSP_DEMUXER) += mspdec.o OBJS-$(CONFIG_MTAF_DEMUXER) += mtaf.o OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o OBJS-$(CONFIG_MUSX_DEMUXER) += musx.o diff --git a/chromium/third_party/ffmpeg/libavformat/acedec.c b/chromium/third_party/ffmpeg/libavformat/acedec.c new file mode 100644 index 00000000000..f1bc512d578 --- /dev/null +++ b/chromium/third_party/ffmpeg/libavformat/acedec.c @@ -0,0 +1,114 @@ +/* + * ACE demuxer + * Copyright (c) 2020 Paul B Mahol + * + * 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 "libavutil/intreadwrite.h" +#include "avformat.h" +#include "internal.h" + +static int ace_probe(const AVProbeData *p) +{ + uint32_t asc; + + if (AV_RB32(p->buf) != MKBETAG('A','A','C',' ')) + return 0; + if (p->buf_size < 0x44) + return 0; + asc = AV_RB32(p->buf + 0x40); + if (asc < 0x44 || asc > p->buf_size - 4) + return 0; + if (AV_RB32(p->buf + asc) != MKBETAG('A','S','C',' ')) + return 0; + + return AVPROBE_SCORE_MAX / 2 + 1; +} + +static int ace_read_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVCodecParameters *par; + int ret, codec, rate, nb_channels; + uint32_t asc_pos, size; + AVStream *st; + + avio_skip(pb, 0x40); + asc_pos = avio_rb32(pb); + if (asc_pos < 0x44) + return AVERROR_INVALIDDATA; + avio_skip(pb, asc_pos - 0x44); + if (avio_rb32(pb) != MKBETAG('A','S','C',' ')) + return AVERROR_INVALIDDATA; + avio_skip(pb, 0xec); + codec = avio_rb32(pb); + nb_channels = avio_rb32(pb); + if (nb_channels <= 0 || nb_channels > 8) + return AVERROR_INVALIDDATA; + size = avio_rb32(pb); + if (size == 0) + return AVERROR_INVALIDDATA; + rate = avio_rb32(pb); + if (rate <= 0) + return AVERROR_INVALIDDATA; + avio_skip(pb, 16); + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->start_time = 0; + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->channels = nb_channels; + par->sample_rate = rate; + par->block_align = (codec == 4 ? 0x60 : codec == 5 ? 0x98 : 0xC0) * nb_channels; + st->duration = (size / par->block_align) * 1024LL; + par->codec_id = AV_CODEC_ID_ATRAC3; + + ret = ff_alloc_extradata(par, 14); + if (ret < 0) + return ret; + + AV_WL16(st->codecpar->extradata, 1); + AV_WL16(st->codecpar->extradata+2, 2048 * par->channels); + AV_WL16(st->codecpar->extradata+4, 0); + AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0); + AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0); + AV_WL16(st->codecpar->extradata+10, 1); + AV_WL16(st->codecpar->extradata+12, 0); + + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + + return 0; +} + +static int ace_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVCodecParameters *par = s->streams[0]->codecpar; + + return av_get_packet(s->pb, pkt, par->block_align); +} + +AVInputFormat ff_ace_demuxer = { + .name = "ace", + .long_name = NULL_IF_CONFIG_SMALL("tri-Ace Audio Container"), + .read_probe = ace_probe, + .read_header = ace_read_header, + .read_packet = ace_read_packet, + .flags = AVFMT_GENERIC_INDEX, +}; diff --git a/chromium/third_party/ffmpeg/libavformat/adxdec.c b/chromium/third_party/ffmpeg/libavformat/adxdec.c index ccd5049acd0..a265c87dead 100644 --- a/chromium/third_party/ffmpeg/libavformat/adxdec.c +++ b/chromium/third_party/ffmpeg/libavformat/adxdec.c @@ -53,6 +53,9 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) AVCodecParameters *par = s->streams[0]->codecpar; int ret, size; + if (avio_feof(s->pb)) + return AVERROR_EOF; + if (par->channels <= 0) { av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels); return AVERROR_INVALIDDATA; @@ -63,16 +66,21 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pos = avio_tell(s->pb); pkt->stream_index = 0; - ret = av_get_packet(s->pb, pkt, size); - if (ret != size) { - return ret < 0 ? ret : AVERROR(EIO); - } - if (AV_RB16(pkt->data) & 0x8000) { - return AVERROR_EOF; + ret = av_get_packet(s->pb, pkt, size * 128); + if (ret < 0) + return ret; + if ((ret % size) && ret >= size) { + size = ret - (ret % size); + av_shrink_packet(pkt, size); + pkt->flags &= ~AV_PKT_FLAG_CORRUPT; + } else if (ret < size) { + return AVERROR(EIO); + } else { + size = ret; } - pkt->size = size; - pkt->duration = 1; - pkt->pts = (pkt->pos - c->header_size) / size; + + pkt->duration = size / (BLOCK_SIZE * par->channels); + pkt->pts = (pkt->pos - c->header_size) / (BLOCK_SIZE * par->channels); return 0; } diff --git a/chromium/third_party/ffmpeg/libavformat/aiffdec.c b/chromium/third_party/ffmpeg/libavformat/aiffdec.c index c650e9074d5..15733478e14 100644 --- a/chromium/third_party/ffmpeg/libavformat/aiffdec.c +++ b/chromium/third_party/ffmpeg/libavformat/aiffdec.c @@ -406,6 +406,8 @@ static int aiff_read_packet(AVFormatContext *s, break; default: size = st->codecpar->block_align ? (MAX_SIZE / st->codecpar->block_align) * st->codecpar->block_align : MAX_SIZE; + if (!size) + return AVERROR_INVALIDDATA; } size = FFMIN(max_size, size); res = av_get_packet(s->pb, pkt, size); diff --git a/chromium/third_party/ffmpeg/libavformat/allformats.c b/chromium/third_party/ffmpeg/libavformat/allformats.c index 3a6b8e6dac4..0e0caaad393 100644 --- a/chromium/third_party/ffmpeg/libavformat/allformats.c +++ b/chromium/third_party/ffmpeg/libavformat/allformats.c @@ -34,6 +34,7 @@ extern AVInputFormat ff_aac_demuxer; extern AVInputFormat ff_aax_demuxer; extern AVInputFormat ff_ac3_demuxer; extern AVOutputFormat ff_ac3_muxer; +extern AVInputFormat ff_ace_demuxer; extern AVInputFormat ff_acm_demuxer; extern AVInputFormat ff_act_demuxer; extern AVInputFormat ff_adf_demuxer; @@ -48,10 +49,12 @@ extern AVInputFormat ff_aiff_demuxer; extern AVOutputFormat ff_aiff_muxer; extern AVInputFormat ff_aix_demuxer; extern AVInputFormat ff_alp_demuxer; +extern AVOutputFormat ff_alp_muxer; extern AVInputFormat ff_amr_demuxer; extern AVOutputFormat ff_amr_muxer; extern AVInputFormat ff_amrnb_demuxer; extern AVInputFormat ff_amrwb_demuxer; +extern AVOutputFormat ff_amv_muxer; extern AVInputFormat ff_anm_demuxer; extern AVInputFormat ff_apc_demuxer; extern AVInputFormat ff_ape_demuxer; @@ -86,6 +89,7 @@ extern AVInputFormat ff_avr_demuxer; extern AVInputFormat ff_avs_demuxer; extern AVInputFormat ff_avs2_demuxer; extern AVOutputFormat ff_avs2_muxer; +extern AVInputFormat ff_avs3_demuxer; extern AVInputFormat ff_bethsoftvid_demuxer; extern AVInputFormat ff_bfi_demuxer; extern AVInputFormat ff_bintext_demuxer; @@ -282,6 +286,7 @@ extern AVInputFormat ff_mpl2_demuxer; extern AVInputFormat ff_mpsub_demuxer; extern AVInputFormat ff_msf_demuxer; extern AVInputFormat ff_msnwc_tcp_demuxer; +extern AVInputFormat ff_msp_demuxer; extern AVInputFormat ff_mtaf_demuxer; extern AVInputFormat ff_mtv_demuxer; extern AVInputFormat ff_musx_demuxer; @@ -487,6 +492,7 @@ extern AVInputFormat ff_yuv4mpegpipe_demuxer; extern AVOutputFormat ff_yuv4mpegpipe_muxer; /* image demuxers */ extern AVInputFormat ff_image_bmp_pipe_demuxer; +extern AVInputFormat ff_image_cri_pipe_demuxer; extern AVInputFormat ff_image_dds_pipe_demuxer; extern AVInputFormat ff_image_dpx_pipe_demuxer; extern AVInputFormat ff_image_exr_pipe_demuxer; diff --git a/chromium/third_party/ffmpeg/libavformat/alp.c b/chromium/third_party/ffmpeg/libavformat/alp.c index 4c2e8f0652f..f2b0c377305 100644 --- a/chromium/third_party/ffmpeg/libavformat/alp.c +++ b/chromium/third_party/ffmpeg/libavformat/alp.c @@ -1,5 +1,5 @@ /* - * LEGO Racers ALP (.tun & .pcm) demuxer + * LEGO Racers ALP (.tun & .pcm) (de)muxer * * Copyright (C) 2020 Zane van Iperen (zane@zanevaniperen.com) * @@ -21,8 +21,10 @@ */ #include "avformat.h" #include "internal.h" +#include "rawenc.h" #include "libavutil/intreadwrite.h" #include "libavutil/internal.h" +#include "libavutil/opt.h" #define ALP_TAG MKTAG('A', 'L', 'P', ' ') #define ALP_MAX_READ_SIZE 4096 @@ -36,6 +38,18 @@ typedef struct ALPHeader { uint32_t sample_rate; /*< Sample rate, only if header_size >= 12. */ } ALPHeader; +typedef enum ALPType { + ALP_TYPE_AUTO = 0, /*< Autodetect based on file extension. */ + ALP_TYPE_TUN = 1, /*< Force a .TUN file. */ + ALP_TYPE_PCM = 2, /*< Force a .PCM file. */ +} ALPType; + +typedef struct ALPMuxContext { + const AVClass *class; + ALPType type; +} ALPMuxContext; + +#if CONFIG_ALP_DEMUXER static int alp_probe(const AVProbeData *p) { uint32_t i; @@ -83,7 +97,7 @@ static int alp_read_header(AVFormatContext *s) if (hdr.header_size == 8) { /* .TUN music file */ - hdr.sample_rate = 11025 * hdr.num_channels; + hdr.sample_rate = 22050; } else { /* .PCM sound file */ hdr.sample_rate = avio_rl32(s->pb); @@ -144,3 +158,135 @@ AVInputFormat ff_alp_demuxer = { .read_header = alp_read_header, .read_packet = alp_read_packet }; +#endif + +#if CONFIG_ALP_MUXER + +static int alp_write_init(AVFormatContext *s) +{ + ALPMuxContext *alp = s->priv_data; + AVCodecParameters *par; + + if (alp->type == ALP_TYPE_AUTO) { + if (av_match_ext(s->url, "pcm")) + alp->type = ALP_TYPE_PCM; + else + alp->type = ALP_TYPE_TUN; + } + + if (s->nb_streams != 1) { + av_log(s, AV_LOG_ERROR, "Too many streams\n"); + return AVERROR(EINVAL); + } + + par = s->streams[0]->codecpar; + + if (par->codec_id != AV_CODEC_ID_ADPCM_IMA_ALP) { + av_log(s, AV_LOG_ERROR, "%s codec not supported\n", + avcodec_get_name(par->codec_id)); + return AVERROR(EINVAL); + } + + if (par->channels > 2) { + av_log(s, AV_LOG_ERROR, "A maximum of 2 channels are supported\n"); + return AVERROR(EINVAL); + } + + if (par->sample_rate > 44100) { + av_log(s, AV_LOG_ERROR, "Sample rate too large\n"); + return AVERROR(EINVAL); + } + + if (alp->type == ALP_TYPE_TUN && par->sample_rate != 22050) { + av_log(s, AV_LOG_ERROR, "Sample rate must be 22050 for TUN files\n"); + return AVERROR(EINVAL); + } + return 0; +} + +static int alp_write_header(AVFormatContext *s) +{ + ALPMuxContext *alp = s->priv_data; + AVCodecParameters *par = s->streams[0]->codecpar; + + avio_wl32(s->pb, ALP_TAG); + avio_wl32(s->pb, alp->type == ALP_TYPE_PCM ? 12 : 8); + avio_write(s->pb, "ADPCM", 6); + avio_w8(s->pb, 0); + avio_w8(s->pb, par->channels); + if (alp->type == ALP_TYPE_PCM) + avio_wl32(s->pb, par->sample_rate); + + return 0; +} + +enum { AE = AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }; + +static const AVOption alp_options[] = { + { + .name = "type", + .help = "set file type", + .offset = offsetof(ALPMuxContext, type), + .type = AV_OPT_TYPE_INT, + .default_val = {.i64 = ALP_TYPE_AUTO}, + .min = ALP_TYPE_AUTO, + .max = ALP_TYPE_PCM, + .flags = AE, + .unit = "type", + }, + { + .name = "auto", + .help = "autodetect based on file extension", + .offset = 0, + .type = AV_OPT_TYPE_CONST, + .default_val = {.i64 = ALP_TYPE_AUTO}, + .min = 0, + .max = 0, + .flags = AE, + .unit = "type" + }, + { + .name = "tun", + .help = "force .tun, used for music", + .offset = 0, + .type = AV_OPT_TYPE_CONST, + .default_val = {.i64 = ALP_TYPE_TUN}, + .min = 0, + .max = 0, + .flags = AE, + .unit = "type" + }, + { + .name = "pcm", + .help = "force .pcm, used for sfx", + .offset = 0, + .type = AV_OPT_TYPE_CONST, + .default_val = {.i64 = ALP_TYPE_PCM}, + .min = 0, + .max = 0, + .flags = AE, + .unit = "type" + }, + { NULL } +}; + +static const AVClass alp_muxer_class = { + .class_name = "alp", + .item_name = av_default_item_name, + .option = alp_options, + .version = LIBAVUTIL_VERSION_INT +}; + +AVOutputFormat ff_alp_muxer = { + .name = "alp", + .long_name = NULL_IF_CONFIG_SMALL("LEGO Racers ALP"), + .extensions = "tun,pcm", + .audio_codec = AV_CODEC_ID_ADPCM_IMA_ALP, + .video_codec = AV_CODEC_ID_NONE, + .init = alp_write_init, + .write_header = alp_write_header, + .write_packet = ff_raw_write_packet, + .priv_class = &alp_muxer_class, + .priv_data_size = sizeof(ALPMuxContext) +}; +#endif diff --git a/chromium/third_party/ffmpeg/libavformat/amvenc.c b/chromium/third_party/ffmpeg/libavformat/amvenc.c new file mode 100644 index 00000000000..4d4ec7a2b12 --- /dev/null +++ b/chromium/third_party/ffmpeg/libavformat/amvenc.c @@ -0,0 +1,413 @@ +/* + * AMV muxer + * + * Copyright (C) 2020 Zane van Iperen (zane@zanevaniperen.com) + * + * 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 "riff.h" +#include "internal.h" +#include "avio_internal.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/avassert.h" + +/* + * Things to note: + * - AMV is a hard-coded (and broken) subset of AVI. It's not worth sullying the + * existing AVI muxer with its filth. + * - No separate demuxer as the existing AVI demuxer can handle these. + * - The sizes of certain tags are deliberately set to 0 as some players break + * when they're set correctly. Ditto with some header fields. + * - There is no index. + * - Players are **very** sensitive to the frame order and sizes. + * - Frames must be strictly interleaved as V-A, any V-V or A-A will + * cause crashes. + * - Variable video frame sizes seem to be handled fine. + * - Variable audio frame sizes cause crashes. + * - If audio is shorter than video, it's padded with silence. + * - If video is shorter than audio, the most recent frame is repeated. + */ + +#define AMV_STREAM_COUNT 2 +#define AMV_STREAM_VIDEO 0 +#define AMV_STREAM_AUDIO 1 +#define AMV_VIDEO_STRH_SIZE 56 +#define AMV_VIDEO_STRF_SIZE 36 +#define AMV_AUDIO_STRH_SIZE 48 +#define AMV_AUDIO_STRF_SIZE 20 /* sizeof(WAVEFORMATEX) + 2 */ + +typedef struct AMVContext +{ + int64_t riff_start; + int64_t movi_list; + int64_t offset_duration; + int last_stream; + + int32_t us_per_frame; /* Microseconds per frame. */ + + int32_t aframe_size; /* Expected audio frame size. */ + int32_t ablock_align; /* Expected audio block align. */ + AVPacket apad; /* Dummy audio packet for padding. */ + AVPacket vpad; /* Most recent video frame, for padding. */ + + /* + * Cumulative PTS values for each stream, used for the final + * duration calculcation. + */ + int64_t lastpts[AMV_STREAM_COUNT]; +} AMVContext; + +/* ff_{start,end}_tag(), but sets the size to 0. */ +static int64_t amv_start_tag(AVIOContext *pb, const char *tag) +{ + ffio_wfourcc(pb, tag); + avio_wl32(pb, 0); + return avio_tell(pb); +} + +static void amv_end_tag(AVIOContext *pb, int64_t start) +{ + int64_t pos; + av_assert0((start&1) == 0); + + pos = avio_tell(pb); + if (pos & 1) + avio_w8(pb, 0); +} + +static av_cold int amv_init(AVFormatContext *s) +{ + AMVContext *amv = s->priv_data; + AVStream *vst, *ast; + int ret; + + amv->last_stream = -1; + + if (s->nb_streams != AMV_STREAM_COUNT) { + av_log(s, AV_LOG_ERROR, "AMV files only support 2 streams\n"); + return AVERROR(EINVAL); + } + + vst = s->streams[AMV_STREAM_VIDEO]; + ast = s->streams[AMV_STREAM_AUDIO]; + + if (vst->codecpar->codec_id != AV_CODEC_ID_AMV) { + av_log(s, AV_LOG_ERROR, "First AMV stream must be %s\n", + avcodec_get_name(AV_CODEC_ID_AMV)); + return AVERROR(EINVAL); + } + + if (ast->codecpar->codec_id != AV_CODEC_ID_ADPCM_IMA_AMV) { + av_log(s, AV_LOG_ERROR, "Second AMV stream must be %s\n", + avcodec_get_name(AV_CODEC_ID_ADPCM_IMA_AMV)); + return AVERROR(EINVAL); + } + + /* These files are broken-enough as they are. They shouldn't be streamed. */ + if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) { + av_log(s, AV_LOG_ERROR, "Stream not seekable, unable to write output file\n"); + return AVERROR(EINVAL); + } + + amv->us_per_frame = av_rescale(AV_TIME_BASE, vst->time_base.num, vst->time_base.den); + amv->aframe_size = av_rescale(ast->codecpar->sample_rate, amv->us_per_frame, AV_TIME_BASE); + amv->ablock_align = 8 + (FFALIGN(amv->aframe_size, 2) / 2); + + av_log(s, AV_LOG_TRACE, "us_per_frame = %d\n", amv->us_per_frame); + av_log(s, AV_LOG_TRACE, "aframe_size = %d\n", amv->aframe_size); + av_log(s, AV_LOG_TRACE, "ablock_align = %d\n", amv->ablock_align); + + /* + * Bail if the framerate's too high. Prevents the audio frame size from + * getting too small. 63fps is the closest value to 60fps that divides + * cleanly, so cap it there. + */ + if (amv->us_per_frame < 15873) { + av_log(s, AV_LOG_ERROR, "Refusing to mux >63fps video\n"); + return AVERROR(EINVAL); + } + + /* + * frame_size will be set if coming from the encoder. + * Make sure the its been configured correctly. The audio frame duration + * needs to match that of the video. + */ + if (ast->codecpar->frame_size) { + AVCodecParameters *par = ast->codecpar; + int bad = 0; + + if (par->frame_size != amv->aframe_size) { + av_log(s, AV_LOG_ERROR, "Invalid audio frame size. Got %d, wanted %d\n", + par->frame_size, amv->aframe_size); + bad = 1; + } + + if (par->block_align != amv->ablock_align) { + av_log(s, AV_LOG_ERROR, "Invalid audio block align. Got %d, wanted %d\n", + par->block_align, amv->ablock_align); + bad = 1; + } + + if (bad) { + av_log(s, AV_LOG_ERROR, "Try -block_size %d\n", amv->aframe_size); + return AVERROR(EINVAL); + } + + if (ast->codecpar->sample_rate % amv->aframe_size) { + av_log(s, AV_LOG_ERROR, "Audio sample rate not a multiple of the frame size.\n" + "Please change video frame rate. Suggested rates: 10,14,15,18,21,25,30\n"); + return AVERROR(EINVAL); + } + } else { + /* If remuxing from the same source, then this will match the video. */ + int32_t aus = av_rescale(AV_TIME_BASE, ast->time_base.num, ast->time_base.den); + if (aus != amv->us_per_frame) { + av_log(s, AV_LOG_ERROR, "Cannot remux streams with a different time base\n"); + return AVERROR(EINVAL); + } + } + + /* Allocate and fill dummy packet so we can pad the audio. */ + if ((ret = av_new_packet(&amv->apad, amv->ablock_align)) < 0) + return ret; + + amv->apad.stream_index = AMV_STREAM_AUDIO; + memset(amv->apad.data, 0, amv->ablock_align); + AV_WL32(amv->apad.data + 4, amv->aframe_size); + + av_init_packet(&amv->vpad); + amv->vpad.stream_index = AMV_STREAM_VIDEO; + amv->vpad.duration = 1; + return 0; +} + +static void amv_deinit(AVFormatContext *s) +{ + AMVContext *amv = s->priv_data; + + av_packet_unref(&amv->apad); + av_packet_unref(&amv->vpad); +} + +static void amv_write_vlist(AVFormatContext *s, AVCodecParameters *par) +{ + int64_t tag_list, tag_str; + + av_assert0(par->codec_id == AV_CODEC_ID_AMV); + + tag_list = amv_start_tag(s->pb, "LIST"); + ffio_wfourcc(s->pb, "strl"); + tag_str = ff_start_tag(s->pb, "strh"); + ffio_fill(s->pb, 0, AMV_VIDEO_STRH_SIZE); + ff_end_tag(s->pb, tag_str); + + tag_str = ff_start_tag(s->pb, "strf"); + ffio_fill(s->pb, 0, AMV_VIDEO_STRF_SIZE); + ff_end_tag(s->pb, tag_str); + + amv_end_tag(s->pb, tag_list); +} + +static void amv_write_alist(AVFormatContext *s, AVCodecParameters *par) +{ + uint8_t buf[AMV_AUDIO_STRF_SIZE]; + AVIOContext *pb = s->pb; + int64_t tag_list, tag_str; + + av_assert0(par->codec_id == AV_CODEC_ID_ADPCM_IMA_AMV); + + tag_list = amv_start_tag(pb, "LIST"); + ffio_wfourcc(pb, "strl"); + tag_str = ff_start_tag(pb, "strh"); + ffio_fill(s->pb, 0, AMV_AUDIO_STRH_SIZE); + ff_end_tag(pb, tag_str); + + /* Bodge an (incorrect) WAVEFORMATEX (+2 pad bytes) */ + tag_str = ff_start_tag(pb, "strf"); + AV_WL16(buf + 0, 1); + AV_WL16(buf + 2, par->channels); + AV_WL32(buf + 4, par->sample_rate); + AV_WL32(buf + 8, par->sample_rate * par->channels * 2); + AV_WL16(buf + 12, 2); + AV_WL16(buf + 14, 16); + AV_WL16(buf + 16, 0); + AV_WL16(buf + 18, 0); + avio_write(pb, buf, AMV_AUDIO_STRF_SIZE); + ff_end_tag(pb, tag_str); + + amv_end_tag(pb, tag_list); +} + +static int amv_write_header(AVFormatContext *s) +{ + AMVContext *amv = s->priv_data; + AVIOContext *pb = s->pb; + AVStream *vst = s->streams[AMV_STREAM_VIDEO]; + AVStream *ast = s->streams[AMV_STREAM_AUDIO]; + uint8_t amvh[56] = {0}; + int64_t list1; + + amv->riff_start = amv_start_tag(pb, "RIFF"); + ffio_wfourcc(pb, "AMV "); + list1 = amv_start_tag(pb, "LIST"); + ffio_wfourcc(pb, "hdrl"); + + ffio_wfourcc(pb, "amvh"); + avio_wl32(pb, 56); + + AV_WL32(amvh + 0, amv->us_per_frame); + AV_WL32(amvh + 32, vst->codecpar->width); + AV_WL32(amvh + 36, vst->codecpar->height); + AV_WL32(amvh + 40, vst->time_base.den); + AV_WL32(amvh + 44, vst->time_base.num); + AV_WL32(amvh + 48, 0); + AV_WL32(amvh + 52, 0); /* duration, filled in later. */ + + avio_write(pb, amvh, sizeof(amvh)); + amv->offset_duration = avio_tell(pb) - 4; + + amv_write_vlist(s, vst->codecpar); + amv_write_alist(s, ast->codecpar); + amv_end_tag(pb, list1); + + amv->movi_list = amv_start_tag(pb, "LIST"); + ffio_wfourcc(pb, "movi"); + return 0; +} + +static int amv_write_packet_internal(AVFormatContext *s, AVPacket *pkt) +{ + AMVContext *amv = s->priv_data; + + if (pkt->stream_index == AMV_STREAM_VIDEO) + ffio_wfourcc(s->pb, "00dc"); + else if (pkt->stream_index == AMV_STREAM_AUDIO) + ffio_wfourcc(s->pb, "01wb"); + else + av_assert0(0); + + if (pkt->stream_index == AMV_STREAM_AUDIO && pkt->size != amv->ablock_align) { + /* Can happen when remuxing files produced by another encoder. */ + av_log(s, AV_LOG_WARNING, "Invalid audio packet size (%d != %d)\n", + pkt->size, amv->ablock_align); + } + + avio_wl32(s->pb, pkt->size); + avio_write(s->pb, pkt->data, pkt->size); + + amv->lastpts[pkt->stream_index] += pkt->duration; + amv->last_stream = pkt->stream_index; + return 0; +} + +static int amv_pad(AVFormatContext *s, AVPacket *pkt) +{ + AMVContext *amv = s->priv_data; + int stream_index = pkt->stream_index; + + if (stream_index != amv->last_stream) + return 0; + + stream_index = (stream_index + 1) % s->nb_streams; + if (stream_index == AMV_STREAM_VIDEO) + return amv_write_packet_internal(s, &amv->vpad); + else if (stream_index == AMV_STREAM_AUDIO) + return amv_write_packet_internal(s, &amv->apad); + else + av_assert0(0); + + return AVERROR(EINVAL); +} + +static int amv_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + AMVContext *amv = s->priv_data; + int ret; + + /* Add a dummy frame if we've received two of the same index. */ + if ((ret = amv_pad(s, pkt)) < 0) + return ret; + + if ((ret = amv_write_packet_internal(s, pkt)) < 0) + return ret; + + if (pkt->stream_index == AMV_STREAM_VIDEO) { + /* Save the last packet for padding. */ + av_packet_unref(&amv->vpad); + if ((ret = av_packet_ref(&amv->vpad, pkt)) < 0) + return ret; + } + + return 0; +} + +static int amv_write_trailer(AVFormatContext *s) +{ + AMVContext *amv = s->priv_data; + AVStream *vst = s->streams[AMV_STREAM_VIDEO]; + AVStream *ast = s->streams[AMV_STREAM_AUDIO]; + int64_t maxpts, ret; + int hh, mm, ss; + + /* Pad-out one last audio frame if needed. */ + if (amv->last_stream == AMV_STREAM_VIDEO) { + if ((ret = amv_write_packet_internal(s, &amv->apad)) < 0) + return ret; + } + + amv_end_tag(s->pb, amv->movi_list); + amv_end_tag(s->pb, amv->riff_start); + + ffio_wfourcc(s->pb, "AMV_"); + ffio_wfourcc(s->pb, "END_"); + + if ((ret = avio_seek(s->pb, amv->offset_duration, SEEK_SET)) < 0) + return ret; + + /* Go back and write the duration. */ + maxpts = FFMAX( + av_rescale_q(amv->lastpts[AMV_STREAM_VIDEO], vst->time_base, AV_TIME_BASE_Q), + av_rescale_q(amv->lastpts[AMV_STREAM_AUDIO], ast->time_base, AV_TIME_BASE_Q) + ); + + ss = maxpts / AV_TIME_BASE; + mm = ss / 60; + hh = mm / 60; + ss %= 60; + mm %= 60; + + avio_w8(s->pb, ss); + avio_w8(s->pb, mm); + avio_wl16(s->pb, hh); + return 0; +} + +AVOutputFormat ff_amv_muxer = { + .name = "amv", + .long_name = NULL_IF_CONFIG_SMALL("AMV"), + .mime_type = "video/amv", + .extensions = "amv", + .priv_data_size = sizeof(AMVContext), + .audio_codec = AV_CODEC_ID_ADPCM_IMA_AMV, + .video_codec = AV_CODEC_ID_AMV, + .init = amv_init, + .deinit = amv_deinit, + .write_header = amv_write_header, + .write_packet = amv_write_packet, + .write_trailer = amv_write_trailer, +}; diff --git a/chromium/third_party/ffmpeg/libavformat/ape.c b/chromium/third_party/ffmpeg/libavformat/ape.c index d92cb2867dd..4c161235fe1 100644 --- a/chromium/third_party/ffmpeg/libavformat/ape.c +++ b/chromium/third_party/ffmpeg/libavformat/ape.c @@ -77,10 +77,6 @@ typedef struct APEContext { uint16_t bps; uint16_t channels; uint32_t samplerate; - - /* Seektable */ - uint32_t *seektable; - uint8_t *bittable; } APEContext; static int ape_read_close(AVFormatContext * s); @@ -130,20 +126,6 @@ static void ape_dumpinfo(AVFormatContext * s, APEContext * ape_ctx) av_log(s, AV_LOG_DEBUG, "\nSeektable\n\n"); if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) { av_log(s, AV_LOG_DEBUG, "No seektable\n"); - } else { - for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) { - if (i < ape_ctx->totalframes - 1) { - av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32" (%"PRIu32" bytes)", - i, ape_ctx->seektable[i], - ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]); - if (ape_ctx->bittable) - av_log(s, AV_LOG_DEBUG, " + %2d bits\n", - ape_ctx->bittable[i]); - av_log(s, AV_LOG_DEBUG, "\n"); - } else { - av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32"\n", i, ape_ctx->seektable[i]); - } - } } av_log(s, AV_LOG_DEBUG, "\nFrames\n\n"); @@ -262,10 +244,10 @@ static int ape_read_header(AVFormatContext * s) ape->totalframes); return AVERROR_INVALIDDATA; } - if (ape->seektablelength / sizeof(*ape->seektable) < ape->totalframes) { + if (ape->seektablelength / sizeof(uint32_t) < ape->totalframes) { av_log(s, AV_LOG_ERROR, "Number of seek entries is less than number of frames: %"SIZE_SPECIFIER" vs. %"PRIu32"\n", - ape->seektablelength / sizeof(*ape->seektable), ape->totalframes); + ape->seektablelength / sizeof(uint32_t), ape->totalframes); return AVERROR_INVALIDDATA; } ape->frames = av_malloc_array(ape->totalframes, sizeof(APEFrame)); @@ -281,39 +263,26 @@ static int ape_read_header(AVFormatContext * s) if (ape->totalframes > 1) ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1); - if (ape->seektablelength > 0) { - ape->seektable = av_mallocz(ape->seektablelength); - if (!ape->seektable) { - ret = AVERROR(ENOMEM); - goto fail; - } - for (i = 0; i < ape->seektablelength / sizeof(uint32_t) && !pb->eof_reached; i++) - ape->seektable[i] = avio_rl32(pb); - if (ape->fileversion < 3810) { - ape->bittable = av_mallocz(ape->totalframes); - if (!ape->bittable) { - ret = AVERROR(ENOMEM); - goto fail; - } - for (i = 0; i < ape->totalframes && !pb->eof_reached; i++) - ape->bittable[i] = avio_r8(pb); - } - if (pb->eof_reached) { - av_log(s, AV_LOG_ERROR, "File truncated\n"); - ret = AVERROR_INVALIDDATA; - goto fail; - } - } - ape->frames[0].pos = ape->firstframe; ape->frames[0].nblocks = ape->blocksperframe; ape->frames[0].skip = 0; + avio_rl32(pb); // seektable[0] for (i = 1; i < ape->totalframes; i++) { - ape->frames[i].pos = ape->seektable[i] + ape->junklength; + uint32_t seektable_entry = avio_rl32(pb); + ape->frames[i].pos = seektable_entry + ape->junklength; ape->frames[i].nblocks = ape->blocksperframe; ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos; ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3; + + if (pb->eof_reached) { + av_log(s, AV_LOG_ERROR, "seektable truncated\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } + ff_dlog(s, "seektable: %8d %"PRIu32"\n", i, seektable_entry); } + avio_skip(pb, ape->seektablelength / sizeof(uint32_t) - ape->totalframes); + ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks; /* calculate final packet size from total file size, if available */ file_size = avio_size(pb); @@ -335,10 +304,18 @@ static int ape_read_header(AVFormatContext * s) } if (ape->fileversion < 3810) { for (i = 0; i < ape->totalframes; i++) { - if (i < ape->totalframes - 1 && ape->bittable[i + 1]) - ape->frames[i].size += 4; + int bits = avio_r8(pb); + if (i && bits) + ape->frames[i - 1].size += 4; + ape->frames[i].skip <<= 3; - ape->frames[i].skip += ape->bittable[i]; + ape->frames[i].skip += bits; + ff_dlog(s, "bittable: %2d\n", bits); + if (pb->eof_reached) { + av_log(s, AV_LOG_ERROR, "bittable truncated\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } } } @@ -454,8 +431,6 @@ static int ape_read_close(AVFormatContext * s) APEContext *ape = s->priv_data; av_freep(&ape->frames); - av_freep(&ape->seektable); - av_freep(&ape->bittable); return 0; } @@ -469,7 +444,7 @@ static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if (index < 0) return -1; - if ((ret = avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET)) < 0) return ret; ape->currentframe = index; return 0; diff --git a/chromium/third_party/ffmpeg/libavformat/apngdec.c b/chromium/third_party/ffmpeg/libavformat/apngdec.c index 0f1d04a3655..bf8343faf3a 100644 --- a/chromium/third_party/ffmpeg/libavformat/apngdec.c +++ b/chromium/third_party/ffmpeg/libavformat/apngdec.c @@ -127,7 +127,7 @@ static int append_extradata(AVCodecParameters *par, AVIOContext *pb, int len) int new_size, ret; uint8_t *new_extradata; - if (previous_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - len) + if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - previous_size) return AVERROR_INVALIDDATA; new_size = previous_size + len; @@ -138,7 +138,7 @@ static int append_extradata(AVCodecParameters *par, AVIOContext *pb, int len) par->extradata = new_extradata; par->extradata_size = new_size; - if ((ret = avio_read(pb, par->extradata + previous_size, len)) < 0) + if ((ret = ffio_read_size(pb, par->extradata + previous_size, len)) < 0) return ret; return previous_size; @@ -151,17 +151,17 @@ static int apng_read_header(AVFormatContext *s) uint32_t len, tag; AVStream *st; int acTL_found = 0; - int64_t ret = AVERROR_INVALIDDATA; + int64_t ret; /* verify PNGSIG */ if (avio_rb64(pb) != PNGSIG) - return ret; + return AVERROR_INVALIDDATA; /* parse IHDR (must be first chunk) */ len = avio_rb32(pb); tag = avio_rl32(pb); if (len != 13 || tag != MKTAG('I', 'H', 'D', 'R')) - return ret; + return AVERROR_INVALIDDATA; st = avformat_new_stream(s, NULL); if (!st) @@ -185,19 +185,17 @@ static int apng_read_header(AVFormatContext *s) AV_WL32(st->codecpar->extradata+4, tag); AV_WB32(st->codecpar->extradata+8, st->codecpar->width); AV_WB32(st->codecpar->extradata+12, st->codecpar->height); - if ((ret = avio_read(pb, st->codecpar->extradata+16, 9)) < 0) - goto fail; + if ((ret = ffio_read_size(pb, st->codecpar->extradata + 16, 9)) < 0) + return ret; - while (!avio_feof(pb)) { + while (1) { if (acTL_found && ctx->num_play != 1) { int64_t size = avio_size(pb); int64_t offset = avio_tell(pb); if (size < 0) { - ret = size; - goto fail; + return size; } else if (offset < 0) { - ret = offset; - goto fail; + return offset; } else if ((ret = ffio_ensure_seekback(pb, size - offset)) < 0) { av_log(s, AV_LOG_WARNING, "Could not ensure seekback, will not loop\n"); ctx->num_play = 1; @@ -205,20 +203,18 @@ static int apng_read_header(AVFormatContext *s) } if ((ctx->num_play == 1 || !acTL_found) && ((ret = ffio_ensure_seekback(pb, 4 /* len */ + 4 /* tag */)) < 0)) - goto fail; + return ret; len = avio_rb32(pb); - if (len > 0x7fffffff) { - ret = AVERROR_INVALIDDATA; - goto fail; - } + if (len > INT_MAX - 12) + return AVERROR_INVALIDDATA; tag = avio_rl32(pb); switch (tag) { case MKTAG('a', 'c', 'T', 'L'): if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0 || (ret = append_extradata(st->codecpar, pb, len + 12)) < 0) - goto fail; + return ret; acTL_found = 1; ctx->num_frames = AV_RB32(st->codecpar->extradata + ret + 8); ctx->num_play = AV_RB32(st->codecpar->extradata + ret + 12); @@ -226,22 +222,18 @@ static int apng_read_header(AVFormatContext *s) ctx->num_frames, ctx->num_play); break; case MKTAG('f', 'c', 'T', 'L'): - if (!acTL_found) { - ret = AVERROR_INVALIDDATA; - goto fail; + if (!acTL_found || len != 26) { + return AVERROR_INVALIDDATA; } if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0) - goto fail; + return ret; return 0; default: if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0 || (ret = append_extradata(st->codecpar, pb, len + 12)) < 0) - goto fail; + return ret; } } - -fail: - return ret; } static int decode_fctl_chunk(AVFormatContext *s, APNGDemuxContext *ctx, AVPacket *pkt) diff --git a/chromium/third_party/ffmpeg/libavformat/argo_brp.c b/chromium/third_party/ffmpeg/libavformat/argo_brp.c index fdc552af140..6d6da851e90 100644 --- a/chromium/third_party/ffmpeg/libavformat/argo_brp.c +++ b/chromium/third_party/ffmpeg/libavformat/argo_brp.c @@ -218,6 +218,9 @@ static int argo_brp_read_header(AVFormatContext *s) bvid->height = AV_RL32(buf + 8); bvid->depth = AV_RL32(buf + 12); + if (bvid->num_frames == 0) + return AVERROR_INVALIDDATA; + /* These are from 1990's games, sanity check this. */ if (bvid->width >= 65536 || bvid->height >= 65536 || bvid->depth > 24 || bvid->depth % 8 != 0) { @@ -389,9 +392,6 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_INVALIDDATA; blk.size -= ASF_CHUNK_HEADER_SIZE; - - if (blk.size % st->codecpar->block_align != 0) - return AVERROR_INVALIDDATA; } if ((ret = av_get_packet(s->pb, pkt, blk.size)) < 0) diff --git a/chromium/third_party/ffmpeg/libavformat/asfdec_f.c b/chromium/third_party/ffmpeg/libavformat/asfdec_f.c index e9ddca7151d..8e48e457d9a 100644 --- a/chromium/third_party/ffmpeg/libavformat/asfdec_f.c +++ b/chromium/third_party/ffmpeg/libavformat/asfdec_f.c @@ -424,7 +424,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming... int64_t fsize = avio_size(pb); if (fsize <= 0 || (int64_t)asf->hdr.file_size <= 0 || - 20*FFABS(fsize - (int64_t)asf->hdr.file_size) < FFMIN(fsize, asf->hdr.file_size)) + FFABS(fsize - (int64_t)asf->hdr.file_size) < FFMIN(fsize, asf->hdr.file_size)/20) st->duration = asf->hdr.play_time / (10000000 / 1000) - start_time; } @@ -479,7 +479,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) if (is_dvr_ms_audio) { // codec_id and codec_tag are unreliable in dvr_ms // files. Set them later by probing stream. - st->request_probe = 1; + st->internal->request_probe = 1; st->codecpar->codec_tag = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_AAC) @@ -607,6 +607,8 @@ static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size) ff_get_guid(pb, &g); size = avio_rl16(pb); ext_len = avio_rl32(pb); + if (ext_len < 0) + return AVERROR_INVALIDDATA; avio_skip(pb, ext_len); if (stream_num < 128 && i < FF_ARRAY_ELEMS(asf->streams[stream_num].payload)) { ASFPayload *p = &asf->streams[stream_num].payload[i]; @@ -769,6 +771,8 @@ static int asf_read_marker(AVFormatContext *s, int64_t size) avio_rl32(pb); // send time avio_rl32(pb); // flags name_len = avio_rl32(pb); // name length + if ((unsigned)name_len > INT_MAX / 2) + return AVERROR_INVALIDDATA; if ((ret = avio_get_str16le(pb, name_len * 2, name, sizeof(name))) < name_len) avio_skip(pb, name_len - ret); @@ -1678,11 +1682,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, asf->index_read = -1; } - if (asf->index_read > 0 && st->index_entries) { + if (asf->index_read > 0 && st->internal->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index >= 0) { /* find the position */ - uint64_t pos = st->index_entries[index].pos; + uint64_t pos = st->internal->index_entries[index].pos; /* do the seek */ av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); diff --git a/chromium/third_party/ffmpeg/libavformat/asfdec_o.c b/chromium/third_party/ffmpeg/libavformat/asfdec_o.c index 1b10e47907a..655ba9f9ef0 100644 --- a/chromium/third_party/ffmpeg/libavformat/asfdec_o.c +++ b/chromium/third_party/ffmpeg/libavformat/asfdec_o.c @@ -357,7 +357,6 @@ static int asf_set_metadata(AVFormatContext *s, const uint8_t *name, * but in reality this is only loosely similar */ static int asf_read_picture(AVFormatContext *s, int len) { - ASFContext *asf = s->priv_data; AVPacket pkt = { 0 }; const CodecMime *mime = ff_id3v2_mime_tags; enum AVCodecID id = AV_CODEC_ID_NONE; @@ -365,7 +364,6 @@ static int asf_read_picture(AVFormatContext *s, int len) uint8_t *desc = NULL; AVStream *st = NULL; int ret, type, picsize, desc_len; - ASFStream *asf_st; /* type + picsize + mime + desc */ if (len < 1 + 4 + 2 + 2) { @@ -422,22 +420,14 @@ static int asf_read_picture(AVFormatContext *s, int len) ret = AVERROR(ENOMEM); goto fail; } - asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st)); - asf_st = asf->asf_st[asf->nb_streams]; - if (!asf_st) { - ret = AVERROR(ENOMEM); - goto fail; - } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = asf_st->type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = id; st->attached_pic = pkt; - st->attached_pic.stream_index = asf_st->index = st->index; + st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; - asf->nb_streams++; - if (*desc) { if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0) av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); @@ -606,7 +596,8 @@ static int asf_read_metadata_obj(AVFormatContext *s, const GUIDParseTable *g) } else { if (st_num < ASF_MAX_STREAMS) { if ((ret = process_metadata(s, name, name_len, val_len, type, - &asf->asf_sd[st_num].asf_met)) < 0) { + st_num ? &asf->asf_sd[st_num].asf_met + : &s->metadata)) < 0) { av_freep(&name); break; } @@ -1144,9 +1135,7 @@ static void reset_packet(ASFPacket *asf_pkt) asf_pkt->duration = 0; asf_pkt->flags = 0; asf_pkt->dts = 0; - asf_pkt->duration = 0; av_packet_unref(&asf_pkt->avpkt); - av_init_packet(&asf_pkt->avpkt); } static int asf_read_replicated_data(AVFormatContext *s, ASFPacket *asf_pkt) @@ -1553,14 +1542,7 @@ static void reset_packet_state(AVFormatContext *s) asf->sub_dts = 0; for (i = 0; i < asf->nb_streams; i++) { ASFPacket *pkt = &asf->asf_st[i]->pkt; - pkt->size_left = 0; - pkt->data_size = 0; - pkt->duration = 0; - pkt->flags = 0; - pkt->dts = 0; - pkt->duration = 0; - av_packet_unref(&pkt->avpkt); - av_init_packet(&pkt->avpkt); + reset_packet(pkt); } } @@ -1640,11 +1622,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, ASFContext *asf = s->priv_data; int idx, ret; - if (s->streams[stream_index]->nb_index_entries && asf->is_simple_index) { + if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) { idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags); - if (idx < 0 || idx >= s->streams[stream_index]->nb_index_entries) + if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries) return AVERROR_INVALIDDATA; - avio_seek(s->pb, s->streams[stream_index]->index_entries[idx].pos, SEEK_SET); + avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET); } else { if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0) return ret; diff --git a/chromium/third_party/ffmpeg/libavformat/au.c b/chromium/third_party/ffmpeg/libavformat/au.c index c09f4da4c96..4f2b81119fb 100644 --- a/chromium/third_party/ffmpeg/libavformat/au.c +++ b/chromium/third_party/ffmpeg/libavformat/au.c @@ -84,6 +84,11 @@ static int au_read_annotation(AVFormatContext *s, int size) av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED); while (size-- > 0) { + if (avio_feof(pb)) { + av_bprint_finalize(&bprint, NULL); + av_freep(&key); + return AVERROR_EOF; + } c = avio_r8(pb); switch(state) { case PARSE_KEY: diff --git a/chromium/third_party/ffmpeg/libavformat/av1.c b/chromium/third_party/ffmpeg/libavformat/av1.c index 0cbffb1fd8b..5512c4e0f77 100644 --- a/chromium/third_party/ffmpeg/libavformat/av1.c +++ b/chromium/third_party/ffmpeg/libavformat/av1.c @@ -375,6 +375,20 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size) if (size <= 0) return AVERROR_INVALIDDATA; + if (buf[0] & 0x80) { + // first bit is nonzero, the passed data does not consist purely of + // OBUs. Expect that the data is already in AV1CodecConfigurationRecord + // format. + int config_record_version = buf[0] & 0x7f; + if (config_record_version != 1 || size < 4) { + return AVERROR_INVALIDDATA; + } + + avio_write(pb, buf, size); + + return 0; + } + ret = avio_open_dyn_buf(&meta_pb); if (ret < 0) return ret; diff --git a/chromium/third_party/ffmpeg/libavformat/av1dec.c b/chromium/third_party/ffmpeg/libavformat/av1dec.c index 10c45609682..5ae81b34d4e 100644 --- a/chromium/third_party/ffmpeg/libavformat/av1dec.c +++ b/chromium/third_party/ffmpeg/libavformat/av1dec.c @@ -361,7 +361,7 @@ static int obu_probe(const AVProbeData *p) ret = read_obu_with_size(p->buf + cnt, p->buf_size - cnt, &obu_size, &type); if (ret < 0 || obu_size <= 0) return 0; - cnt += ret; + cnt += FFMIN(ret, p->buf_size - cnt); ret = get_score(type, &seq); if (ret >= 0) @@ -382,7 +382,7 @@ static int obu_read_header(AVFormatContext *s) static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) { ObuContext *c = s->priv_data; - uint8_t header[MAX_OBU_HEADER_SIZE]; + uint8_t header[MAX_OBU_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; int64_t obu_size; int size = av_fifo_space(c->fifo); int ret, len, type; diff --git a/chromium/third_party/ffmpeg/libavformat/avformat.h b/chromium/third_party/ffmpeg/libavformat/avformat.h index c8c0b6c08d0..4865c56cc3d 100644 --- a/chromium/third_party/ffmpeg/libavformat/avformat.h +++ b/chromium/third_party/ffmpeg/libavformat/avformat.h @@ -356,7 +356,7 @@ struct AVDeviceCapabilitiesQuery; * sorting will have '-sort' appended. E.g. artist="The Beatles", * artist-sort="Beatles, The". * - Some protocols and demuxers support metadata updates. After a successful - * call to av_read_packet(), AVFormatContext.event_flags or AVStream.event_flags + * call to av_read_frame(), AVFormatContext.event_flags or AVStream.event_flags * will be updated to indicate if metadata changed. In order to detect metadata * changes on a stream, you need to loop through all streams in the AVFormatContext * and check their individual event_flags. @@ -534,7 +534,9 @@ typedef struct AVOutputFormat { #else #define ff_const59 const #endif +#if FF_API_NEXT ff_const59 struct AVOutputFormat *next; +#endif /** * size of private data so that it can be allocated in the wrapper */ @@ -679,7 +681,9 @@ typedef struct AVInputFormat { * New public fields should be added right above. ***************************************************************** */ +#if FF_API_NEXT ff_const59 struct AVInputFormat *next; +#endif /** * Raw demuxers store their codec ID here. @@ -973,12 +977,30 @@ typedef struct AVStream { int nb_side_data; /** - * Flags for the user to detect events happening on the stream. Flags must - * be cleared by the user once the event has been handled. - * A combination of AVSTREAM_EVENT_FLAG_*. + * Flags indicating events happening on the stream, a combination of + * AVSTREAM_EVENT_FLAG_*. + * + * - demuxing: may be set by the demuxer in avformat_open_input(), + * avformat_find_stream_info() and av_read_frame(). Flags must be cleared + * by the user once the event has been handled. + * - muxing: may be set by the user after avformat_write_header(). to + * indicate a user-triggered event. The muxer will clear the flags for + * events it has handled in av_[interleaved]_write_frame(). */ int event_flags; -#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata. +/** + * - demuxing: the demuxer read new metadata from the file and updated + * AVStream.metadata accordingly + * - muxing: the user updated AVStream.metadata and wishes the muxer to write + * it into the file + */ +#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 +/** + * - demuxing: new packets for this stream were read from the file. This + * event is informational only and does not guarantee that new packets + * for this stream will necessarily be returned from av_read_frame(). + */ +#define AVSTREAM_EVENT_FLAG_NEW_PACKETS (1 << 1) /** * Real base framerate of the stream. @@ -1023,38 +1045,10 @@ typedef struct AVStream { ***************************************************************** */ -#define MAX_STD_TIMEBASES (30*12+30+3+6) - /** - * Stream information used internally by avformat_find_stream_info() - */ - struct { - int64_t last_dts; - int64_t duration_gcd; - int duration_count; - int64_t rfps_duration_sum; - double (*duration_error)[2][MAX_STD_TIMEBASES]; - int64_t codec_info_duration; - int64_t codec_info_duration_fields; - int frame_delay_evidence; - - /** - * 0 -> decoder has not been searched for yet. - * >0 -> decoder found - * <0 -> decoder with codec_id == -found_decoder has not been found - */ - int found_decoder; - - int64_t last_duration; - - /** - * Those are used for average framerate estimation. - */ - int64_t fps_first_dts; - int fps_first_dts_idx; - int64_t fps_last_dts; - int fps_last_dts_idx; - - } *info; +#if LIBAVFORMAT_VERSION_MAJOR < 59 + // kept for ABI compatibility only, do not access in any way + void *unused; +#endif int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ @@ -1085,18 +1079,15 @@ typedef struct AVStream { enum AVStreamParseType need_parsing; struct AVCodecParserContext *parser; - /** - * last packet in packet_buffer for this stream when muxing. - */ - struct AVPacketList *last_in_packet_buffer; - AVProbeData probe_data; -#define MAX_REORDER_DELAY 16 - int64_t pts_buffer[MAX_REORDER_DELAY+1]; - - AVIndexEntry *index_entries; /**< Only used if the format does not - support seeking natively. */ - int nb_index_entries; - unsigned int index_entries_allocated_size; +#if LIBAVFORMAT_VERSION_MAJOR < 59 + // kept for ABI compatibility only, do not access in any way + void *unused7; + AVProbeData unused6; + int64_t unused5[16+1]; + void *unused2; + int unused3; + unsigned int unused4; +#endif /** * Stream Identifier @@ -1112,109 +1103,6 @@ typedef struct AVStream { int pmt_version; int pmt_stream_idx; - int64_t interleaver_chunk_size; - int64_t interleaver_chunk_duration; - - /** - * stream probing state - * -1 -> probing finished - * 0 -> no probing requested - * rest -> perform probing with request_probe being the minimum score to accept. - */ - int request_probe; - /** - * Indicates that everything up to the next keyframe - * should be discarded. - */ - int skip_to_keyframe; - - /** - * Number of samples to skip at the start of the frame decoded from the next packet. - */ - int skip_samples; - - /** - * If not 0, the number of samples that should be skipped from the start of - * the stream (the samples are removed from packets with pts==0, which also - * assumes negative timestamps do not happen). - * Intended for use with formats such as mp3 with ad-hoc gapless audio - * support. - */ - int64_t start_skip_samples; - - /** - * If not 0, the first audio sample that should be discarded from the stream. - * This is broken by design (needs global sample count), but can't be - * avoided for broken by design formats such as mp3 with ad-hoc gapless - * audio support. - */ - int64_t first_discard_sample; - - /** - * The sample after last sample that is intended to be discarded after - * first_discard_sample. Works on frame boundaries only. Used to prevent - * early EOF if the gapless info is broken (considered concatenated mp3s). - */ - int64_t last_discard_sample; - - /** - * Number of internally decoded frames, used internally in libavformat, do not access - * its lifetime differs from info which is why it is not in that structure. - */ - int nb_decoded_frames; - - /** - * Timestamp offset added to timestamps before muxing - */ - int64_t mux_ts_offset; - - /** - * Internal data to check for wrapping of the time stamp - */ - int64_t pts_wrap_reference; - - /** - * Options for behavior, when a wrap is detected. - * - * Defined by AV_PTS_WRAP_ values. - * - * If correction is enabled, there are two possibilities: - * If the first time stamp is near the wrap point, the wrap offset - * will be subtracted, which will create negative time stamps. - * Otherwise the offset will be added. - */ - int pts_wrap_behavior; - - /** - * Internal data to prevent doing update_initial_durations() twice - */ - int update_initial_durations_done; - - /** - * Internal data to generate dts from pts - */ - int64_t pts_reorder_error[MAX_REORDER_DELAY+1]; - uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]; - - /** - * Internal data to analyze DTS and detect faulty mpeg streams - */ - int64_t last_dts_for_order_check; - uint8_t dts_ordered; - uint8_t dts_misordered; - - /** - * Internal data to inject global side data - */ - int inject_global_side_data; - - /** - * display aspect ratio (0 if unknown) - * - encoding: unused - * - decoding: Set by libavformat to calculate sample_aspect_ratio internally - */ - AVRational display_aspect_ratio; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. @@ -1645,12 +1533,24 @@ typedef struct AVFormatContext { int strict_std_compliance; /** - * Flags for the user to detect events happening on the file. Flags must - * be cleared by the user once the event has been handled. - * A combination of AVFMT_EVENT_FLAG_*. + * Flags indicating events happening on the file, a combination of + * AVFMT_EVENT_FLAG_*. + * + * - demuxing: may be set by the demuxer in avformat_open_input(), + * avformat_find_stream_info() and av_read_frame(). Flags must be cleared + * by the user once the event has been handled. + * - muxing: may be set by the user after avformat_write_header() to + * indicate a user-triggered event. The muxer will clear the flags for + * events it has handled in av_[interleaved]_write_frame(). */ int event_flags; -#define AVFMT_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata. +/** + * - demuxing: the demuxer read new metadata from the file and updated + * AVFormatContext.metadata accordingly + * - muxing: the user updated AVFormatContext.metadata and wishes the muxer to + * write it into the file + */ +#define AVFMT_EVENT_FLAG_METADATA_UPDATED 0x0001 /** * Maximum number of packets to read while waiting for the first timestamp. diff --git a/chromium/third_party/ffmpeg/libavformat/avidec.c b/chromium/third_party/ffmpeg/libavformat/avidec.c index 9765e5e7b2c..7e527e15eeb 100644 --- a/chromium/third_party/ffmpeg/libavformat/avidec.c +++ b/chromium/third_party/ffmpeg/libavformat/avidec.c @@ -110,6 +110,15 @@ static const char avi_headers[][8] = { static const AVMetadataConv avi_metadata_conv[] = { { "strn", "title" }, + { "isbj", "subject" }, + { "inam", "title" }, + { "iart", "artist" }, + { "icop", "copyright" }, + { "icmt", "comment" }, + { "ignr", "genre" }, + { "iprd", "product" }, + { "isft", "software" }, + { 0 }, }; @@ -272,7 +281,7 @@ static void clean_index(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AVIStream *ast = st->priv_data; - int n = st->nb_index_entries; + int n = st->internal->nb_index_entries; int max = ast->sample_size; int64_t pos, size, ts; @@ -282,9 +291,9 @@ static void clean_index(AVFormatContext *s) while (max < 1024) max += max; - pos = st->index_entries[0].pos; - size = st->index_entries[0].size; - ts = st->index_entries[0].timestamp; + pos = st->internal->index_entries[0].pos; + size = st->internal->index_entries[0].size; + ts = st->internal->index_entries[0].timestamp; for (j = 0; j < size; j += max) av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0, @@ -432,12 +441,12 @@ static int calculate_bitrate(AVFormatContext *s) int64_t len = 0; AVStream *st = s->streams[i]; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) continue; - for (j = 0; j < st->nb_index_entries; j++) - len += st->index_entries[j].size; - maxpos = FFMAX(maxpos, st->index_entries[j-1].pos); + for (j = 0; j < st->internal->nb_index_entries; j++) + len += st->internal->index_entries[j].size; + maxpos = FFMAX(maxpos, st->internal->index_entries[j-1].pos); lensum += len; } if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file @@ -451,12 +460,12 @@ static int calculate_bitrate(AVFormatContext *s) int64_t duration; int64_t bitrate; - for (j = 0; j < st->nb_index_entries; j++) - len += st->index_entries[j].size; + for (j = 0; j < st->internal->nb_index_entries; j++) + len += st->internal->index_entries[j].size; - if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0) + if (st->internal->nb_index_entries < 2 || st->codecpar->bit_rate > 0) continue; - duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp; + duration = st->internal->index_entries[j-1].timestamp - st->internal->index_entries[0].timestamp; bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num); if (bitrate > 0) { st->codecpar->bit_rate = bitrate; @@ -901,7 +910,7 @@ static int avi_read_header(AVFormatContext *s) break; case AVMEDIA_TYPE_SUBTITLE: st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->request_probe= 1; + st->internal->request_probe= 1; avio_skip(pb, size); break; default: @@ -979,6 +988,14 @@ static int avi_read_header(AVFormatContext *s) avio_skip(pb, size); break; case MKTAG('s', 't', 'r', 'n'): + case MKTAG('i', 's', 'b', 'j'): + case MKTAG('i', 'n', 'a', 'm'): + case MKTAG('i', 'a', 'r', 't'): + case MKTAG('i', 'c', 'o', 'p'): + case MKTAG('i', 'c', 'm', 't'): + case MKTAG('i', 'g', 'n', 'r'): + case MKTAG('i', 'p', 'o', 'd'): + case MKTAG('i', 's', 'o', 'f'): if (s->nb_streams) { ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size); if (ret < 0) @@ -1034,7 +1051,7 @@ end_of_header: for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->nb_index_entries) + if (st->internal->nb_index_entries) break; } // DV-in-AVI cannot be non-interleaved, if set this must be @@ -1072,11 +1089,15 @@ static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) ff_const59 AVInputFormat *sub_demuxer; AVRational time_base; int size; + AVProbeData pd; + unsigned int desc_len; AVIOContext *pb = avio_alloc_context(pkt->data + 7, pkt->size - 7, 0, NULL, NULL, NULL, NULL); - AVProbeData pd; - unsigned int desc_len = avio_rl32(pb); + if (!pb) + goto error; + + desc_len = avio_rl32(pb); if (desc_len > pb->buf_end - pb->buf_ptr) goto error; @@ -1316,8 +1337,8 @@ start_sync: if (size) { uint64_t pos = avio_tell(pb) - 8; - if (!st->index_entries || !st->nb_index_entries || - st->index_entries[st->nb_index_entries - 1].pos < pos) { + if (!st->internal->index_entries || !st->internal->nb_index_entries || + st->internal->index_entries[st->internal->nb_index_entries - 1].pos < pos) { av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); } @@ -1347,10 +1368,10 @@ static int ni_prepare_read(AVFormatContext *s) int64_t ts = ast->frame_offset; int64_t last_ts; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) continue; - last_ts = st->index_entries[st->nb_index_entries - 1].timestamp; + last_ts = st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp; if (!ast->remaining && ts > last_ts) continue; @@ -1379,11 +1400,11 @@ static int ni_prepare_read(AVFormatContext *s) } else { i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY); if (i >= 0) - best_ast->frame_offset = best_st->index_entries[i].timestamp; + best_ast->frame_offset = best_st->internal->index_entries[i].timestamp; } if (i >= 0) { - int64_t pos = best_st->index_entries[i].pos; + int64_t pos = best_st->internal->index_entries[i].pos; pos += best_ast->packet_size - best_ast->remaining; if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0) return AVERROR_EOF; @@ -1393,7 +1414,7 @@ static int ni_prepare_read(AVFormatContext *s) avi->stream_index = best_stream_index; if (!best_ast->remaining) best_ast->packet_size = - best_ast->remaining = best_st->index_entries[i].size; + best_ast->remaining = best_st->internal->index_entries[i].size; } else return AVERROR_EOF; @@ -1483,15 +1504,15 @@ resync: pkt->dts /= ast->sample_size; pkt->stream_index = avi->stream_index; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->index_entries) { AVIndexEntry *e; int index; index = av_index_search_timestamp(st, ast->frame_offset, AVSEEK_FLAG_ANY); - e = &st->index_entries[index]; + e = &st->internal->index_entries[index]; if (index >= 0 && e->timestamp == ast->frame_offset) { - if (index == st->nb_index_entries-1) { + if (index == st->internal->nb_index_entries-1) { int key=1; uint32_t state=-1; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { @@ -1527,7 +1548,7 @@ resync: } ast->seek_pos= 0; - if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) { + if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) { int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q); if (avi->dts_max < dts) { @@ -1627,8 +1648,8 @@ static int avi_read_idx1(AVFormatContext *s, int size) if (!anykey) { for (index = 0; index < s->nb_streams; index++) { st = s->streams[index]; - if (st->nb_index_entries) - st->index_entries[0].flags |= AVINDEX_KEYFRAME; + if (st->internal->nb_index_entries) + st->internal->index_entries[0].flags |= AVINDEX_KEYFRAME; } } return 0; @@ -1653,16 +1674,16 @@ static int check_stream_max_drift(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AVIStream *ast = st->priv_data; - int n = st->nb_index_entries; - while (idx[i] < n && st->index_entries[idx[i]].pos < pos) + int n = st->internal->nb_index_entries; + while (idx[i] < n && st->internal->index_entries[idx[i]].pos < pos) idx[i]++; if (idx[i] < n) { int64_t dts; - dts = av_rescale_q(st->index_entries[idx[i]].timestamp / + dts = av_rescale_q(st->internal->index_entries[idx[i]].timestamp / FFMAX(ast->sample_size, 1), st->time_base, AV_TIME_BASE_Q); min_dts = FFMIN(min_dts, dts); - min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos); + min_pos = FFMIN(min_pos, st->internal->index_entries[idx[i]].pos); } } for (i = 0; i < s->nb_streams; i++) { @@ -1671,7 +1692,7 @@ static int check_stream_max_drift(AVFormatContext *s) if (idx[i] && min_dts != INT64_MAX / 2) { int64_t dts; - dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp / + dts = av_rescale_q(st->internal->index_entries[idx[i] - 1].timestamp / FFMAX(ast->sample_size, 1), st->time_base, AV_TIME_BASE_Q); max_dts = FFMAX(max_dts, dts); @@ -1700,30 +1721,30 @@ static int guess_ni_flag(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - int n = st->nb_index_entries; + int n = st->internal->nb_index_entries; unsigned int size; if (n <= 0) continue; if (n >= 2) { - int64_t pos = st->index_entries[0].pos; + int64_t pos = st->internal->index_entries[0].pos; unsigned tag[2]; avio_seek(s->pb, pos, SEEK_SET); tag[0] = avio_r8(s->pb); tag[1] = avio_r8(s->pb); avio_rl16(s->pb); size = avio_rl32(s->pb); - if (get_stream_idx(tag) == i && pos + size > st->index_entries[1].pos) + if (get_stream_idx(tag) == i && pos + size > st->internal->index_entries[1].pos) last_start = INT64_MAX; - if (get_stream_idx(tag) == i && size == st->index_entries[0].size + 8) + if (get_stream_idx(tag) == i && size == st->internal->index_entries[0].size + 8) last_start = INT64_MAX; } - if (st->index_entries[0].pos > last_start) - last_start = st->index_entries[0].pos; - if (st->index_entries[n - 1].pos < first_end) - first_end = st->index_entries[n - 1].pos; + if (st->internal->index_entries[0].pos > last_start) + last_start = st->internal->index_entries[0].pos; + if (st->internal->index_entries[n - 1].pos < first_end) + first_end = st->internal->index_entries[n - 1].pos; } avio_seek(s->pb, oldpos, SEEK_SET); @@ -1811,20 +1832,20 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, timestamp * FFMAX(ast->sample_size, 1), flags); if (index < 0) { - if (st->nb_index_entries > 0) + if (st->internal->nb_index_entries > 0) av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n", timestamp * FFMAX(ast->sample_size, 1), - st->index_entries[0].timestamp, - st->index_entries[st->nb_index_entries - 1].timestamp); + st->internal->index_entries[0].timestamp, + st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp); return AVERROR_INVALIDDATA; } /* find the position */ - pos = st->index_entries[index].pos; - timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); + pos = st->internal->index_entries[index].pos; + timestamp = st->internal->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n", - timestamp, index, st->index_entries[index].timestamp); + timestamp, index, st->internal->index_entries[index].timestamp); if (CONFIG_DV_DEMUXER && avi->dv_demux) { /* One and only one real stream for DV in AVI, and it has video */ @@ -1855,7 +1876,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, continue; } - if (st2->nb_index_entries <= 0) + if (st2->internal->nb_index_entries <= 0) continue; // av_assert1(st2->codecpar->block_align); @@ -1869,14 +1890,14 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; - ast2->seek_pos = st2->index_entries[index].pos; + ast2->seek_pos = st2->internal->index_entries[index].pos; pos_min = FFMIN(pos_min,ast2->seek_pos); } for (i = 0; i < s->nb_streams; i++) { AVStream *st2 = s->streams[i]; AVIStream *ast2 = st2->priv_data; - if (ast2->sub_ctx || st2->nb_index_entries <= 0) + if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0) continue; index = av_index_search_timestamp( @@ -1885,9 +1906,9 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; - while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min) + while (!avi->non_interleaved && index>0 && st2->internal->index_entries[index-1].pos >= pos_min) index--; - ast2->frame_offset = st2->index_entries[index].timestamp; + ast2->frame_offset = st2->internal->index_entries[index].timestamp; } /* do the seek */ diff --git a/chromium/third_party/ffmpeg/libavformat/avio_internal.h b/chromium/third_party/ffmpeg/libavformat/avio_internal.h index c575df80352..fe87f2a2887 100644 --- a/chromium/third_party/ffmpeg/libavformat/avio_internal.h +++ b/chromium/third_party/ffmpeg/libavformat/avio_internal.h @@ -100,7 +100,9 @@ int ffio_realloc_buf(AVIOContext *s, int buf_size); * * Will ensure that when reading sequentially up to buf_size, seeking * within the current pos and pos+buf_size is possible. - * Once the stream position moves outside this window this guarantee is lost. + * Once the stream position moves outside this window or another + * ffio_ensure_seekback call requests a buffer outside this window this + * guarantee is lost. */ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size); diff --git a/chromium/third_party/ffmpeg/libavformat/aviobuf.c b/chromium/third_party/ffmpeg/libavformat/aviobuf.c index a77517d7121..78cc60b2ae9 100644 --- a/chromium/third_party/ffmpeg/libavformat/aviobuf.c +++ b/chromium/third_party/ffmpeg/libavformat/aviobuf.c @@ -40,7 +40,7 @@ * data instead of calling the protocol seek function, for seekable * protocols. */ -#define SHORT_SEEK_THRESHOLD 4096 +#define SHORT_SEEK_THRESHOLD 32768 static void *ff_avio_child_next(void *obj, void *prev) { @@ -540,7 +540,7 @@ static void fill_buffer(AVIOContext *s) { int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE; - uint8_t *dst = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ? + uint8_t *dst = s->buf_end - s->buffer + max_buffer_size <= s->buffer_size ? s->buf_end : s->buffer; int len = s->buffer_size - (dst - s->buffer); @@ -686,9 +686,11 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) int ffio_read_size(AVIOContext *s, unsigned char *buf, int size) { int ret = avio_read(s, buf, size); - if (ret != size) - return AVERROR_INVALIDDATA; - return ret; + if (ret == size) + return ret; + if (ret < 0 && ret != AVERROR_EOF) + return ret; + return AVERROR_INVALIDDATA; } int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data) @@ -719,13 +721,6 @@ int avio_read_partial(AVIOContext *s, unsigned char *buf, int size) len = s->buf_end - s->buf_ptr; if (len == 0) { - /* Reset the buf_end pointer to the start of the buffer, to make sure - * the fill_buffer call tries to read as much data as fits into the - * full buffer, instead of just what space is left after buf_end. - * This avoids returning partial packets at the end of the buffer, - * for packet based inputs. - */ - s->buf_end = s->buf_ptr = s->buffer; fill_buffer(s); len = s->buf_end - s->buf_ptr; } @@ -938,6 +933,11 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) } else { buffer_size = IO_BUFFER_SIZE; } + if (!(h->flags & AVIO_FLAG_WRITE) && h->is_streamed) { + if (buffer_size > INT_MAX/2) + return AVERROR(EINVAL); + buffer_size *= 2; + } buffer = av_malloc(buffer_size); if (!buffer) return AVERROR(ENOMEM); @@ -991,32 +991,46 @@ URLContext* ffio_geturlcontext(AVIOContext *s) return NULL; } +static void update_checksum(AVIOContext *s) +{ + if (s->update_checksum && s->buf_ptr > s->checksum_ptr) { + s->checksum = s->update_checksum(s->checksum, s->checksum_ptr, + s->buf_ptr - s->checksum_ptr); + } +} + int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size) { uint8_t *buffer; int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE; - int filled = s->buf_end - s->buffer; - ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1; + ptrdiff_t filled = s->buf_end - s->buf_ptr; + + if (buf_size <= s->buf_end - s->buf_ptr) + return 0; - buf_size += s->buf_ptr - s->buffer + max_buffer_size; + buf_size += max_buffer_size - 1; - if (buf_size < filled || s->seekable || !s->read_packet) + if (buf_size + s->buf_ptr - s->buffer <= s->buffer_size || s->seekable || !s->read_packet) return 0; av_assert0(!s->write_flag); - buffer = av_malloc(buf_size); - if (!buffer) - return AVERROR(ENOMEM); - - memcpy(buffer, s->buffer, filled); - av_free(s->buffer); - s->buf_ptr = buffer + (s->buf_ptr - s->buffer); - s->buf_end = buffer + (s->buf_end - s->buffer); - s->buffer = buffer; - s->buffer_size = buf_size; - if (checksum_ptr_offset >= 0) - s->checksum_ptr = s->buffer + checksum_ptr_offset; + if (buf_size <= s->buffer_size) { + update_checksum(s); + memmove(s->buffer, s->buf_ptr, filled); + } else { + buffer = av_malloc(buf_size); + if (!buffer) + return AVERROR(ENOMEM); + update_checksum(s); + memcpy(buffer, s->buf_ptr, filled); + av_free(s->buffer); + s->buffer = buffer; + s->buffer_size = buf_size; + } + s->buf_ptr = s->buffer; + s->buf_end = s->buffer + filled; + s->checksum_ptr = s->buffer; return 0; } diff --git a/chromium/third_party/ffmpeg/libavformat/avs.c b/chromium/third_party/ffmpeg/libavformat/avs.c index 54b2c3f2a97..097c1719082 100644 --- a/chromium/third_party/ffmpeg/libavformat/avs.c +++ b/chromium/third_party/ffmpeg/libavformat/avs.c @@ -128,7 +128,8 @@ avs_read_video_packet(AVFormatContext * s, AVPacket * pkt, static int avs_read_audio_packet(AVFormatContext * s, AVPacket * pkt) { AvsFormat *avs = s->priv_data; - int ret, size; + int ret; + int64_t size; size = avio_tell(s->pb); ret = ff_voc_get_packet(s, pkt, avs->st_audio, avs->remaining_audio_size); diff --git a/chromium/third_party/ffmpeg/libavformat/davs2.c b/chromium/third_party/ffmpeg/libavformat/avs2dec.c index 59f41fd4994..51908d2b63f 100644 --- a/chromium/third_party/ffmpeg/libavformat/davs2.c +++ b/chromium/third_party/ffmpeg/libavformat/avs2dec.c @@ -25,17 +25,17 @@ #include "libavcodec/internal.h" #include "libavutil/intreadwrite.h" -#define ISSQH(x) ((x) == 0xB0 ) -#define ISEND(x) ((x) == 0xB1 ) -#define ISPIC(x) ((x) == 0xB3 || (x) == 0xB6) -#define ISUNIT(x) ( ISSQH(x) || ISEND(x) || (x) == 0xB2 || ISPIC(x) || (x) == 0xB5 || (x) == 0xB7 ) -#define ISAVS2(x) ((x) == 0x20 || (x) == 0x22 || (x) == 0x30 || (x) == 0x32 ) +#define AVS2_ISSQH(x) ((x) == 0xB0) +#define AVS2_ISEND(x) ((x) == 0xB1) +#define AVS2_ISPIC(x) ((x) == 0xB3 || (x) == 0xB6) +#define AVS2_ISUNIT(x) (AVS2_ISSQH(x) || AVS2_ISEND(x) || (x) == 0xB2 || AVS2_ISPIC(x) || (x) == 0xB5 || (x) == 0xB7) +#define AVS2_ISPROFILE(x) ((x) == 0x20 || (x) == 0x22 || (x) == 0x30 || (x) == 0x32) static int avs2_probe(const AVProbeData *p) { - uint32_t code= -1, hds=0, pic=0, seq=0; - uint8_t state=0; - const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size, *sqb=0; + uint32_t code = -1, hds = 0, pic = 0, seq = 0; + uint8_t state = 0; + const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size, *sqb = 0; if (AV_RB32(p->buf) != 0x1B0){ return 0; } @@ -44,18 +44,18 @@ static int avs2_probe(const AVProbeData *p) ptr = avpriv_find_start_code(ptr, end, &code); state = code & 0xFF; if ((code & 0xffffff00) == 0x100) { - if (ISUNIT(state)) { + if (AVS2_ISUNIT(state)) { if (sqb && !hds) { hds = ptr - sqb; } - if (ISSQH(state)) { - if (!ISAVS2(*ptr)) + if (AVS2_ISSQH(state)) { + if (!AVS2_ISPROFILE(*ptr)) return 0; sqb = ptr; seq++; - } else if (ISPIC(state)) { + } else if (AVS2_ISPIC(state)) { pic++; - } else if (ISEND(state)) { + } else if (AVS2_ISEND(state)) { break; } } diff --git a/chromium/third_party/ffmpeg/libavformat/avs3dec.c b/chromium/third_party/ffmpeg/libavformat/avs3dec.c new file mode 100644 index 00000000000..253caa7c1d6 --- /dev/null +++ b/chromium/third_party/ffmpeg/libavformat/avs3dec.c @@ -0,0 +1,68 @@ +/* + * RAW AVS3-P2/IEEE1857.10 video demuxer + * Copyright (c) 2020 Zhenyu Wang <wangzhenyu@pkusz.edu.cn> + * Bingjie Han <hanbj@pkusz.edu.cn> + * Huiwen Ren <hwrenx@gmail.com> + * + * 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 "libavcodec/avs3.h" +#include "libavcodec/internal.h" +#include "avformat.h" +#include "rawdec.h" + +static int avs3video_probe(const AVProbeData *p) +{ + const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size; + uint32_t code = -1; + uint8_t state = 0; + int pic = 0, seq = 0, slice_pos = 0; + int ret = 0; + + while (ptr < end) { + ptr = avpriv_find_start_code(ptr, end, &code); + state = code & 0xFF; + if ((code & 0xFFFFFF00) == 0x100) { + if (state < AVS3_SEQ_START_CODE) { + if (code < slice_pos) + return 0; + slice_pos = code; + } else { + slice_pos = 0; + } + if (state == AVS3_SEQ_START_CODE) { + seq++; + if (*ptr != AVS3_PROFILE_BASELINE_MAIN && *ptr != AVS3_PROFILE_BASELINE_MAIN10) + return 0; + } else if (AVS3_ISPIC(state)) { + pic++; + } else if ((state == AVS3_UNDEF_START_CODE) || + (state > AVS3_VIDEO_EDIT_CODE)) { + return 0; + } + } + } + + if (seq && pic && av_match_ext(p->filename, "avs3")) { + ret = AVPROBE_SCORE_MAX; + } + + return ret; +} + +FF_DEF_RAWVIDEO_DEMUXER(avs3, "raw AVS3-P2/IEEE1857.10", avs3video_probe, "avs3", AV_CODEC_ID_AVS3) diff --git a/chromium/third_party/ffmpeg/libavformat/bethsoftvid.c b/chromium/third_party/ffmpeg/libavformat/bethsoftvid.c index 47a9a693303..709603daf5a 100644 --- a/chromium/third_party/ffmpeg/libavformat/bethsoftvid.c +++ b/chromium/third_party/ffmpeg/libavformat/bethsoftvid.c @@ -28,6 +28,7 @@ */ #include "libavutil/channel_layout.h" +#include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" #include "avformat.h" #include "internal.h" @@ -72,6 +73,7 @@ static int vid_read_header(AVFormatContext *s) { BVID_DemuxContext *vid = s->priv_data; AVIOContext *pb = s->pb; + int ret; /* load main header. Contents: * bytes: 'V' 'I' 'D' @@ -84,6 +86,10 @@ static int vid_read_header(AVFormatContext *s) vid->bethsoft_global_delay = avio_rl16(pb); avio_rl16(pb); + ret = av_image_check_size(vid->width, vid->height, 0, s); + if (ret < 0) + return ret; + // wait until the first packet to create each stream vid->video_index = -1; vid->audio_index = -1; diff --git a/chromium/third_party/ffmpeg/libavformat/bink.c b/chromium/third_party/ffmpeg/libavformat/bink.c index 08125ba8f14..99bbd27ef3a 100644 --- a/chromium/third_party/ffmpeg/libavformat/bink.c +++ b/chromium/third_party/ffmpeg/libavformat/bink.c @@ -225,8 +225,8 @@ static int read_header(AVFormatContext *s) return ret; } - if (vst->index_entries) - avio_seek(pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET); + if (vst->internal->index_entries) + avio_seek(pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET); else avio_skip(pb, 4); @@ -256,8 +256,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } - bink->remain_packet_size = st->index_entries[index_entry].size; - bink->flags = st->index_entries[index_entry].flags; + bink->remain_packet_size = st->internal->index_entries[index_entry].size; + bink->flags = st->internal->index_entries[index_entry].flags; bink->current_track = 0; } @@ -313,7 +313,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in return -1; /* seek to the first frame */ - ret = avio_seek(s->pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET); + ret = avio_seek(s->pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET); if (ret < 0) return ret; diff --git a/chromium/third_party/ffmpeg/libavformat/bintext.c b/chromium/third_party/ffmpeg/libavformat/bintext.c index 7dab5f377d5..bc0f6bd099f 100644 --- a/chromium/third_party/ffmpeg/libavformat/bintext.c +++ b/chromium/third_party/ffmpeg/libavformat/bintext.c @@ -293,6 +293,8 @@ static int adf_read_header(AVFormatContext *s) bin->fsize = avio_size(pb) - 1 - 192 - 4096; st->codecpar->width = 80<<3; ff_sauce_read(s, &bin->fsize, &got_width, 0); + if (st->codecpar->width < 8) + return AVERROR_INVALIDDATA; if (!bin->width) calculate_height(st->codecpar, bin->fsize); avio_seek(pb, 1 + 192 + 4096, SEEK_SET); @@ -344,6 +346,8 @@ static int idf_read_header(AVFormatContext *s) bin->fsize = avio_size(pb) - 12 - 4096 - 48; ff_sauce_read(s, &bin->fsize, &got_width, 0); + if (st->codecpar->width < 8) + return AVERROR_INVALIDDATA; if (!bin->width) calculate_height(st->codecpar, bin->fsize); avio_seek(pb, 12, SEEK_SET); diff --git a/chromium/third_party/ffmpeg/libavformat/boadec.c b/chromium/third_party/ffmpeg/libavformat/boadec.c index 495090c485e..74a6ceecb15 100644 --- a/chromium/third_party/ffmpeg/libavformat/boadec.c +++ b/chromium/third_party/ffmpeg/libavformat/boadec.c @@ -54,12 +54,12 @@ static int read_header(AVFormatContext *s) avio_rl32(s->pb); st->codecpar->sample_rate = avio_rl32(s->pb); st->codecpar->channels = avio_rl32(s->pb); - if (st->codecpar->channels > FF_SANE_NB_CHANNELS) + if (st->codecpar->channels > FF_SANE_NB_CHANNELS || st->codecpar->channels <= 0) return AVERROR(ENOSYS); s->internal->data_offset = avio_rl32(s->pb); avio_r8(s->pb); st->codecpar->block_align = avio_rl32(s->pb); - if (st->codecpar->block_align > INT_MAX / FF_SANE_NB_CHANNELS) + if (st->codecpar->block_align > INT_MAX / FF_SANE_NB_CHANNELS || st->codecpar->block_align <= 0) return AVERROR_INVALIDDATA; st->codecpar->block_align *= st->codecpar->channels; diff --git a/chromium/third_party/ffmpeg/libavformat/cafdec.c b/chromium/third_party/ffmpeg/libavformat/cafdec.c index d0f942f3e46..c188aad20f6 100644 --- a/chromium/third_party/ffmpeg/libavformat/cafdec.c +++ b/chromium/third_party/ffmpeg/libavformat/cafdec.c @@ -79,6 +79,9 @@ static int read_desc_chunk(AVFormatContext *s) st->codecpar->channels = avio_rb32(pb); st->codecpar->bits_per_coded_sample = avio_rb32(pb); + if (caf->bytes_per_packet < 0 || caf->frames_per_packet < 0) + return AVERROR_INVALIDDATA; + /* calculate bit rate for constant size packets */ if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) { st->codecpar->bit_rate = (uint64_t)st->codecpar->sample_rate * (uint64_t)caf->bytes_per_packet * 8 @@ -189,6 +192,7 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size) CafContext *caf = s->priv_data; int64_t pos = 0, ccount, num_packets; int i; + int ret; ccount = avio_tell(pb); @@ -202,7 +206,11 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size) st->duration = 0; for (i = 0; i < num_packets; i++) { - av_add_index_entry(s->streams[0], pos, st->duration, 0, 0, AVINDEX_KEYFRAME); + if (avio_feof(pb)) + return AVERROR_INVALIDDATA; + ret = av_add_index_entry(s->streams[0], pos, st->duration, 0, 0, AVINDEX_KEYFRAME); + if (ret < 0) + return ret; pos += caf->bytes_per_packet ? caf->bytes_per_packet : ff_mp4_read_descr_len(pb); st->duration += caf->frames_per_packet ? caf->frames_per_packet : ff_mp4_read_descr_len(pb); } @@ -329,7 +337,7 @@ found_data: if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) { if (caf->data_size > 0) st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet; - } else if (st->nb_index_entries && st->duration > 0) { + } else if (st->internal->nb_index_entries && st->duration > 0) { if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n", st->codecpar->sample_rate, caf->data_size / st->duration); @@ -382,13 +390,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size; pkt_size = FFMIN(pkt_size, left); pkt_frames = pkt_size / caf->bytes_per_packet; - } else if (st->nb_index_entries) { - if (caf->packet_cnt < st->nb_index_entries - 1) { - pkt_size = st->index_entries[caf->packet_cnt + 1].pos - st->index_entries[caf->packet_cnt].pos; - pkt_frames = st->index_entries[caf->packet_cnt + 1].timestamp - st->index_entries[caf->packet_cnt].timestamp; - } else if (caf->packet_cnt == st->nb_index_entries - 1) { - pkt_size = caf->num_bytes - st->index_entries[caf->packet_cnt].pos; - pkt_frames = st->duration - st->index_entries[caf->packet_cnt].timestamp; + } else if (st->internal->nb_index_entries) { + if (caf->packet_cnt < st->internal->nb_index_entries - 1) { + pkt_size = st->internal->index_entries[caf->packet_cnt + 1].pos - st->internal->index_entries[caf->packet_cnt].pos; + pkt_frames = st->internal->index_entries[caf->packet_cnt + 1].timestamp - st->internal->index_entries[caf->packet_cnt].timestamp; + } else if (caf->packet_cnt == st->internal->nb_index_entries - 1) { + pkt_size = caf->num_bytes - st->internal->index_entries[caf->packet_cnt].pos; + pkt_frames = st->duration - st->internal->index_entries[caf->packet_cnt].timestamp; } else { return AVERROR(EIO); } @@ -427,10 +435,10 @@ static int read_seek(AVFormatContext *s, int stream_index, pos = FFMIN(pos, caf->data_size); packet_cnt = pos / caf->bytes_per_packet; frame_cnt = caf->frames_per_packet * packet_cnt; - } else if (st->nb_index_entries) { + } else if (st->internal->nb_index_entries) { packet_cnt = av_index_search_timestamp(st, timestamp, flags); - frame_cnt = st->index_entries[packet_cnt].timestamp; - pos = st->index_entries[packet_cnt].pos; + frame_cnt = st->internal->index_entries[packet_cnt].timestamp; + pos = st->internal->index_entries[packet_cnt].pos; } else { return -1; } diff --git a/chromium/third_party/ffmpeg/libavformat/cinedec.c b/chromium/third_party/ffmpeg/libavformat/cinedec.c index 0f2453cdf59..c6c0d927ee9 100644 --- a/chromium/third_party/ffmpeg/libavformat/cinedec.c +++ b/chromium/third_party/ffmpeg/libavformat/cinedec.c @@ -291,7 +291,7 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt) if (cine->pts >= st->duration) return AVERROR_EOF; - avio_seek(pb, st->index_entries[cine->pts].pos, SEEK_SET); + avio_seek(pb, st->internal->index_entries[cine->pts].pos, SEEK_SET); n = avio_rl32(pb); if (n < 8) return AVERROR_INVALIDDATA; diff --git a/chromium/third_party/ffmpeg/libavformat/codec2.c b/chromium/third_party/ffmpeg/libavformat/codec2.c index 0d7c488587d..0c2ad3aa014 100644 --- a/chromium/third_party/ffmpeg/libavformat/codec2.c +++ b/chromium/third_party/ffmpeg/libavformat/codec2.c @@ -29,8 +29,8 @@ #include "rawenc.h" #include "pcm.h" -#define AVPRIV_CODEC2_HEADER_SIZE 7 -#define AVPRIV_CODEC2_MAGIC 0xC0DEC2 +#define CODEC2_HEADER_SIZE 7 +#define CODEC2_MAGIC 0xC0DEC2 //the lowest version we should ever run across is 0.8 //we may run across later versions as the format evolves @@ -46,7 +46,7 @@ typedef struct { static int codec2_probe(const AVProbeData *p) { //must start wih C0 DE C2 - if (AV_RB24(p->buf) != AVPRIV_CODEC2_MAGIC) { + if (AV_RB24(p->buf) != CODEC2_MAGIC) { return 0; } @@ -61,9 +61,69 @@ static int codec2_probe(const AVProbeData *p) return AVPROBE_SCORE_EXTENSION + 1; } +//Mimics codec2_samples_per_frame() +static int codec2_mode_frame_size(AVFormatContext *s, int mode) +{ + int frame_size_table[CODEC2_MODE_MAX+1] = { + 160, // 3200 + 160, // 2400 + 320, // 1600 + 320, // 1400 + 320, // 1300 + 320, // 1200 + 320, // 700 + 320, // 700B + 320, // 700C + }; + + if (mode < 0 || mode > CODEC2_MODE_MAX) { + av_log(s, AV_LOG_ERROR, "unknown codec2 mode %i, can't find frame_size\n", mode); + return 0; + } else { + return frame_size_table[mode]; + } +} + +//Mimics (codec2_bits_per_frame()+7)/8 +static int codec2_mode_block_align(AVFormatContext *s, int mode) +{ + int block_align_table[CODEC2_MODE_MAX+1] = { + 8, // 3200 + 6, // 2400 + 8, // 1600 + 7, // 1400 + 7, // 1300 + 6, // 1200 + 4, // 700 + 4, // 700B + 4, // 700C + }; + + if (mode < 0 || mode > CODEC2_MODE_MAX) { + av_log(s, AV_LOG_ERROR, "unknown codec2 mode %i, can't find block_align\n", mode); + return 0; + } else { + return block_align_table[mode]; + } +} + +//Computes bitrate from mode, with frames rounded up to the nearest octet. +//So 700 bit/s (28 bits/frame) becomes 800 bits/s (32 bits/frame). +static int codec2_mode_bit_rate(AVFormatContext *s, int mode) +{ + int frame_size = codec2_mode_frame_size(s, mode); + int block_align = codec2_mode_block_align(s, mode); + + if (frame_size <= 0 || block_align <= 0) { + return 0; + } + + return 8 * 8000 * block_align / frame_size; +} + static int codec2_read_header_common(AVFormatContext *s, AVStream *st) { - int mode = avpriv_codec2_mode_from_extradata(st->codecpar->extradata); + int mode = codec2_mode_from_extradata(st->codecpar->extradata); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_CODEC2; @@ -71,9 +131,9 @@ static int codec2_read_header_common(AVFormatContext *s, AVStream *st) st->codecpar->channels = 1; st->codecpar->format = AV_SAMPLE_FMT_S16; st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; - st->codecpar->bit_rate = avpriv_codec2_mode_bit_rate(s, mode); - st->codecpar->frame_size = avpriv_codec2_mode_frame_size(s, mode); - st->codecpar->block_align = avpriv_codec2_mode_block_align(s, mode); + st->codecpar->bit_rate = codec2_mode_bit_rate(s, mode); + st->codecpar->frame_size = codec2_mode_frame_size(s, mode); + st->codecpar->block_align = codec2_mode_block_align(s, mode); if (st->codecpar->bit_rate <= 0 || st->codecpar->frame_size <= 0 || @@ -95,28 +155,28 @@ static int codec2_read_header(AVFormatContext *s) return AVERROR(ENOMEM); } - if (avio_rb24(s->pb) != AVPRIV_CODEC2_MAGIC) { + if (avio_rb24(s->pb) != CODEC2_MAGIC) { av_log(s, AV_LOG_ERROR, "not a .c2 file\n"); return AVERROR_INVALIDDATA; } - ret = ff_alloc_extradata(st->codecpar, AVPRIV_CODEC2_EXTRADATA_SIZE); + ret = ff_alloc_extradata(st->codecpar, CODEC2_EXTRADATA_SIZE); if (ret) { return ret; } - ret = ffio_read_size(s->pb, st->codecpar->extradata, AVPRIV_CODEC2_EXTRADATA_SIZE); + ret = ffio_read_size(s->pb, st->codecpar->extradata, CODEC2_EXTRADATA_SIZE); if (ret < 0) { return ret; } - version = avpriv_codec2_version_from_extradata(st->codecpar->extradata); + version = AV_RB16(st->codecpar->extradata); if ((version >> 8) != EXPECTED_CODEC2_MAJOR_VERSION) { avpriv_report_missing_feature(s, "Major version %i", version >> 8); return AVERROR_PATCHWELCOME; } - s->internal->data_offset = AVPRIV_CODEC2_HEADER_SIZE; + s->internal->data_offset = CODEC2_HEADER_SIZE; return codec2_read_header_common(s, st); } @@ -160,14 +220,14 @@ static int codec2_write_header(AVFormatContext *s) st = s->streams[0]; - if (st->codecpar->extradata_size != AVPRIV_CODEC2_EXTRADATA_SIZE) { + if (st->codecpar->extradata_size != CODEC2_EXTRADATA_SIZE) { av_log(s, AV_LOG_ERROR, ".c2 files require exactly %i bytes of extradata (got %i)\n", - AVPRIV_CODEC2_EXTRADATA_SIZE, st->codecpar->extradata_size); + CODEC2_EXTRADATA_SIZE, st->codecpar->extradata_size); return AVERROR(EINVAL); } - avio_wb24(s->pb, AVPRIV_CODEC2_MAGIC); - avio_write(s->pb, st->codecpar->extradata, AVPRIV_CODEC2_EXTRADATA_SIZE); + avio_wb24(s->pb, CODEC2_MAGIC); + avio_write(s->pb, st->codecpar->extradata, CODEC2_EXTRADATA_SIZE); return 0; } @@ -189,13 +249,13 @@ static int codec2raw_read_header(AVFormatContext *s) return AVERROR(ENOMEM); } - ret = ff_alloc_extradata(st->codecpar, AVPRIV_CODEC2_EXTRADATA_SIZE); + ret = ff_alloc_extradata(st->codecpar, CODEC2_EXTRADATA_SIZE); if (ret) { return ret; } s->internal->data_offset = 0; - avpriv_codec2_make_extradata(st->codecpar->extradata, c2->mode); + codec2_make_extradata(st->codecpar->extradata, c2->mode); return codec2_read_header_common(s, st); } @@ -211,7 +271,7 @@ static const AVOption codec2_options[] = { }; static const AVOption codec2raw_options[] = { - AVPRIV_CODEC2_AVOPTIONS("codec2 mode [mandatory]", Codec2Context, -1, -1, AV_OPT_FLAG_DECODING_PARAM), + CODEC2_AVOPTIONS("codec2 mode [mandatory]", Codec2Context, -1, -1, AV_OPT_FLAG_DECODING_PARAM), FRAMES_PER_PACKET, { NULL }, }; diff --git a/chromium/third_party/ffmpeg/libavformat/concatdec.c b/chromium/third_party/ffmpeg/libavformat/concatdec.c index 4b56b61404f..6d5b9914f98 100644 --- a/chromium/third_party/ffmpeg/libavformat/concatdec.c +++ b/chromium/third_party/ffmpeg/libavformat/concatdec.c @@ -113,7 +113,8 @@ static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile, ConcatFile *file; char *url = NULL; const char *proto; - size_t url_len, proto_len; + const char *ptr; + size_t url_len; int ret; if (cat->safe > 0 && !safe_filename(filename)) { @@ -122,9 +123,8 @@ static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile, } proto = avio_find_protocol_name(filename); - proto_len = proto ? strlen(proto) : 0; - if (proto && !memcmp(filename, proto, proto_len) && - (filename[proto_len] == ':' || filename[proto_len] == ',')) { + if (proto && av_strstart(filename, proto, &ptr) && + (*ptr == ':' || *ptr == ',')) { url = filename; filename = NULL; } else { diff --git a/chromium/third_party/ffmpeg/libavformat/dashdec.c b/chromium/third_party/ffmpeg/libavformat/dashdec.c index 99b9c45439c..693fc7372be 100644 --- a/chromium/third_party/ffmpeg/libavformat/dashdec.c +++ b/chromium/third_party/ffmpeg/libavformat/dashdec.c @@ -771,7 +771,7 @@ static int resolve_content_path(AVFormatContext *s, const char *url, int *max_ur size = strlen(root_url); isRootHttp = ishttp(root_url); - if (root_url[size - 1] != token) { + if (size > 0 && root_url[size - 1] != token) { av_strlcat(root_url, "/", size + 2); size += 2; } @@ -1145,7 +1145,8 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, } err: - av_freep(&c->adaptionset_lang); + xmlFree(c->adaptionset_lang); + c->adaptionset_lang = NULL; return ret; } diff --git a/chromium/third_party/ffmpeg/libavformat/dhav.c b/chromium/third_party/ffmpeg/libavformat/dhav.c index 5e9abdb6113..53deaff77eb 100644 --- a/chromium/third_party/ffmpeg/libavformat/dhav.c +++ b/chromium/third_party/ffmpeg/libavformat/dhav.c @@ -359,7 +359,7 @@ retry: case 0x4: case 0x8: st->codecpar->codec_id = AV_CODEC_ID_H264; break; case 0xc: st->codecpar->codec_id = AV_CODEC_ID_HEVC; break; - default: avpriv_request_sample(s, "Unknown video codec %X\n", dhav->video_codec); + default: avpriv_request_sample(s, "Unknown video codec %X", dhav->video_codec); } st->duration = dhav->duration; st->codecpar->width = dhav->width; @@ -392,7 +392,7 @@ retry: case 0x1f: st->codecpar->codec_id = AV_CODEC_ID_MP2; break; case 0x21: st->codecpar->codec_id = AV_CODEC_ID_MP3; break; case 0x0d: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_MS; break; - default: avpriv_request_sample(s, "Unknown audio codec %X\n", dhav->audio_codec); + default: avpriv_request_sample(s, "Unknown audio codec %X", dhav->audio_codec); } st->duration = dhav->duration; st->codecpar->channels = dhav->audio_channels; @@ -441,10 +441,10 @@ static int dhav_read_seek(AVFormatContext *s, int stream_index, if (index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - pts = st->index_entries[index].timestamp; + pts = st->internal->index_entries[index].timestamp; for (int n = 0; n < s->nb_streams; n++) { AVStream *st = s->streams[n]; diff --git a/chromium/third_party/ffmpeg/libavformat/dsfdec.c b/chromium/third_party/ffmpeg/libavformat/dsfdec.c index c9740cf28f6..1df163e114c 100644 --- a/chromium/third_party/ffmpeg/libavformat/dsfdec.c +++ b/chromium/third_party/ffmpeg/libavformat/dsfdec.c @@ -124,8 +124,8 @@ static int dsf_read_header(AVFormatContext *s) dsf->audio_size = avio_rl64(pb) / 8 * st->codecpar->channels; st->codecpar->block_align = avio_rl32(pb); - if (st->codecpar->block_align > INT_MAX / st->codecpar->channels) { - avpriv_request_sample(s, "block_align overflow"); + if (st->codecpar->block_align > INT_MAX / st->codecpar->channels || st->codecpar->block_align <= 0) { + avpriv_request_sample(s, "block_align invalid"); return AVERROR_INVALIDDATA; } st->codecpar->block_align *= st->codecpar->channels; diff --git a/chromium/third_party/ffmpeg/libavformat/dv.c b/chromium/third_party/ffmpeg/libavformat/dv.c index 3e0d12c0e38..26a78139f5f 100644 --- a/chromium/third_party/ffmpeg/libavformat/dv.c +++ b/chromium/third_party/ffmpeg/libavformat/dv.c @@ -49,7 +49,6 @@ struct DVDemuxContext { uint8_t audio_buf[4][8192]; int ach; int frames; - uint64_t abytes; }; static inline uint16_t dv_audio_12to16(uint16_t sample) @@ -258,7 +257,7 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) c->ast[i] = avformat_new_stream(c->fctx, NULL); if (!c->ast[i]) break; - avpriv_set_pts_info(c->ast[i], 64, 1, 30000); + avpriv_set_pts_info(c->ast[i], 64, c->sys->time_base.num, c->sys->time_base.den); c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; @@ -387,8 +386,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, for (i = 0; i < c->ach; i++) { c->audio_pkt[i].pos = pos; c->audio_pkt[i].size = size; - c->audio_pkt[i].pts = c->abytes * 30000 * 8 / - c->ast[i]->codecpar->bit_rate; + c->audio_pkt[i].pts = (c->sys->height == 720) ? (c->frames & ~1) : c->frames; ppcm[i] = c->audio_buf[i]; } if (c->ach) @@ -401,10 +399,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, c->audio_pkt[2].size = c->audio_pkt[3].size = 0; } else { c->audio_pkt[0].size = c->audio_pkt[1].size = 0; - c->abytes += size; } - } else { - c->abytes += size; } /* Now it's time to return video packet */ @@ -444,13 +439,6 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset) { c->frames = frame_offset; - if (c->ach) { - if (c->sys) { - c->abytes = av_rescale_q(c->frames, c->sys->time_base, - (AVRational) { 8, c->ast[0]->codecpar->bit_rate }); - } else - av_log(c->fctx, AV_LOG_ERROR, "cannot adjust audio bytes\n"); - } c->audio_pkt[0].size = c->audio_pkt[1].size = 0; c->audio_pkt[2].size = c->audio_pkt[3].size = 0; } diff --git a/chromium/third_party/ffmpeg/libavformat/dvenc.c b/chromium/third_party/ffmpeg/libavformat/dvenc.c index b04d6044d76..6c0d40f819d 100644 --- a/chromium/third_party/ffmpeg/libavformat/dvenc.c +++ b/chromium/third_party/ffmpeg/libavformat/dvenc.c @@ -307,34 +307,34 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) /* We have to sort out where audio and where video stream is */ for (i=0; i<s->nb_streams; i++) { - switch (s->streams[i]->codecpar->codec_type) { + AVStream *st = s->streams[i]; + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: if (vst) return NULL; - vst = s->streams[i]; + if (st->codecpar->codec_id != AV_CODEC_ID_DVVIDEO) + goto bail_out; + vst = st; break; case AVMEDIA_TYPE_AUDIO: if (c->n_ast > 1) return NULL; - c->ast[c->n_ast++] = s->streams[i]; + /* Some checks -- DV format is very picky about its incoming streams */ + if(st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE || + st->codecpar->channels != 2) + goto bail_out; + if (st->codecpar->sample_rate != 48000 && + st->codecpar->sample_rate != 44100 && + st->codecpar->sample_rate != 32000 ) + goto bail_out; + c->ast[c->n_ast++] = st; break; default: goto bail_out; } } - /* Some checks -- DV format is very picky about its incoming streams */ - if (!vst || vst->codecpar->codec_id != AV_CODEC_ID_DVVIDEO) + if (!vst) goto bail_out; - for (i=0; i<c->n_ast; i++) { - if (c->ast[i]) { - if(c->ast[i]->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE || - c->ast[i]->codecpar->channels != 2) - goto bail_out; - if (c->ast[i]->codecpar->sample_rate != 48000 && - c->ast[i]->codecpar->sample_rate != 44100 && - c->ast[i]->codecpar->sample_rate != 32000 ) - goto bail_out; - } - } + c->sys = av_dv_codec_profile2(vst->codecpar->width, vst->codecpar->height, vst->codecpar->format, vst->time_base); if (!c->sys) diff --git a/chromium/third_party/ffmpeg/libavformat/dxa.c b/chromium/third_party/ffmpeg/libavformat/dxa.c index 27fa6afb6a0..909c5ba2baf 100644 --- a/chromium/third_party/ffmpeg/libavformat/dxa.c +++ b/chromium/third_party/ffmpeg/libavformat/dxa.c @@ -143,7 +143,7 @@ static int dxa_read_header(AVFormatContext *s) c->readvid = !c->has_sound; c->vidpos = avio_tell(pb); s->start_time = 0; - s->duration = (int64_t)c->frames * AV_TIME_BASE * num / den; + s->duration = av_rescale(c->frames, AV_TIME_BASE * (int64_t)num, den); av_log(s, AV_LOG_DEBUG, "%d frame(s)\n",c->frames); return 0; diff --git a/chromium/third_party/ffmpeg/libavformat/electronicarts.c b/chromium/third_party/ffmpeg/libavformat/electronicarts.c index d0f483aaf90..4c292f29a2b 100644 --- a/chromium/third_party/ffmpeg/libavformat/electronicarts.c +++ b/chromium/third_party/ffmpeg/libavformat/electronicarts.c @@ -582,6 +582,8 @@ static int ea_read_packet(AVFormatContext *s, AVPacket *pkt) int av_uninit(num_samples); while ((!packet_read && !hit_end) || partial_packet) { + if (avio_feof(pb)) + return AVERROR_EOF; chunk_type = avio_rl32(pb); chunk_size = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb); if (chunk_size < 8) diff --git a/chromium/third_party/ffmpeg/libavformat/ffmetadec.c b/chromium/third_party/ffmpeg/libavformat/ffmetadec.c index 0ea89fe3f34..9fcba084901 100644 --- a/chromium/third_party/ffmpeg/libavformat/ffmetadec.c +++ b/chromium/third_party/ffmpeg/libavformat/ffmetadec.c @@ -185,7 +185,7 @@ static int read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) - return AVERROR(ENOMEM); + goto nomem; st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_FFMETADATA; @@ -195,7 +195,7 @@ static int read_header(AVFormatContext *s) AVChapter *ch = read_chapter(s); if (!ch) - return AVERROR(ENOMEM); + goto nomem; m = &ch->metadata; } else @@ -211,6 +211,10 @@ static int read_header(AVFormatContext *s) AV_TIME_BASE_Q); return 0; +nomem: + av_bprint_finalize(&bp, NULL); + + return AVERROR(ENOMEM); } static int read_packet(AVFormatContext *s, AVPacket *pkt) diff --git a/chromium/third_party/ffmpeg/libavformat/flacdec.c b/chromium/third_party/ffmpeg/libavformat/flacdec.c index 79c05f14bf7..6aca4755a13 100644 --- a/chromium/third_party/ffmpeg/libavformat/flacdec.c +++ b/chromium/third_party/ffmpeg/libavformat/flacdec.c @@ -40,8 +40,8 @@ static void reset_index_position(int64_t metadata_head_size, AVStream *st) { /* the real seek index offset should be the size of metadata blocks with the offset in the frame blocks */ int i; - for(i=0; i<st->nb_index_entries; i++) { - st->index_entries[i].pos += metadata_head_size; + for(i=0; i<st->internal->nb_index_entries; i++) { + st->internal->index_entries[i].pos += metadata_head_size; } } @@ -319,10 +319,10 @@ static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in } index = av_index_search_timestamp(s->streams[0], timestamp, flags); - if(index<0 || index >= s->streams[0]->nb_index_entries) + if(index<0 || index >= s->streams[0]->internal->nb_index_entries) return -1; - e = s->streams[0]->index_entries[index]; + e = s->streams[0]->internal->index_entries[index]; pos = avio_seek(s->pb, e.pos, SEEK_SET); if (pos >= 0) { return 0; diff --git a/chromium/third_party/ffmpeg/libavformat/flacenc.c b/chromium/third_party/ffmpeg/libavformat/flacenc.c index 6b8ce8d7ee3..1c983486aa9 100644 --- a/chromium/third_party/ffmpeg/libavformat/flacenc.c +++ b/chromium/third_party/ffmpeg/libavformat/flacenc.c @@ -347,6 +347,8 @@ static void flac_deinit(struct AVFormatContext *s) FlacMuxerContext *c = s->priv_data; avpriv_packet_list_free(&c->queue, &c->queue_end); + for (unsigned i = 0; i < s->nb_streams; i++) + av_packet_free((AVPacket **)&s->streams[i]->priv_data); } static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) diff --git a/chromium/third_party/ffmpeg/libavformat/flic.c b/chromium/third_party/ffmpeg/libavformat/flic.c index 4552bff69c9..9a7b8081ed1 100644 --- a/chromium/third_party/ffmpeg/libavformat/flic.c +++ b/chromium/third_party/ffmpeg/libavformat/flic.c @@ -268,7 +268,7 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, int64_t pos, ts; int index; - if (!st->index_entries || stream_index != flic->video_stream_index) + if (!st->internal->index_entries || stream_index != flic->video_stream_index) return -1; index = av_index_search_timestamp(st, pts, flags); @@ -278,8 +278,8 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, if (index < 0) return -1; - pos = st->index_entries[index].pos; - ts = st->index_entries[index].timestamp; + pos = st->internal->index_entries[index].pos; + ts = st->internal->index_entries[index].timestamp; flic->frame_number = ts; avio_seek(s->pb, pos, SEEK_SET); return 0; diff --git a/chromium/third_party/ffmpeg/libavformat/flvdec.c b/chromium/third_party/ffmpeg/libavformat/flvdec.c index d480d0bc67a..ad6e7a3ca5a 100644 --- a/chromium/third_party/ffmpeg/libavformat/flvdec.c +++ b/chromium/third_party/ffmpeg/libavformat/flvdec.c @@ -140,7 +140,7 @@ static void add_keyframes_index(AVFormatContext *s) av_assert0(flv->last_keyframe_stream_index <= s->nb_streams); stream = s->streams[flv->last_keyframe_stream_index]; - if (stream->nb_index_entries == 0) { + if (stream->internal->nb_index_entries == 0) { for (i = 0; i < flv->keyframe_count; i++) { av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n", flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000); @@ -495,6 +495,8 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, num_val = 0; ioc = s->pb; + if (avio_feof(ioc)) + return AVERROR_EOF; amf_type = avio_r8(ioc); switch (amf_type) { @@ -828,10 +830,10 @@ static void clear_index_entries(AVFormatContext *s, int64_t pos) AVStream *st = s->streams[i]; /* Remove all index entries that point to >= pos */ out = 0; - for (j = 0; j < st->nb_index_entries; j++) - if (st->index_entries[j].pos < pos) - st->index_entries[out++] = st->index_entries[j]; - st->nb_index_entries = out; + for (j = 0; j < st->internal->nb_index_entries; j++) + if (st->internal->index_entries[j].pos < pos) + st->internal->index_entries[out++] = st->internal->index_entries[j]; + st->internal->nb_index_entries = out; } } diff --git a/chromium/third_party/ffmpeg/libavformat/framecrcenc.c b/chromium/third_party/ffmpeg/libavformat/framecrcenc.c index a567b5299c8..1fbe4aa4ee8 100644 --- a/chromium/third_party/ffmpeg/libavformat/framecrcenc.c +++ b/chromium/third_party/ffmpeg/libavformat/framecrcenc.c @@ -21,8 +21,11 @@ #include <inttypes.h> +#include "config.h" #include "libavutil/adler32.h" #include "libavutil/avstring.h" +#include "libavutil/intreadwrite.h" +#include "libavcodec/avcodec.h" #include "avformat.h" #include "internal.h" @@ -42,6 +45,17 @@ static int framecrc_write_header(struct AVFormatContext *s) return ff_framehash_write_header(s); } +static av_unused void inline bswap(char *buf, int offset, int size) +{ + if (size == 8) { + uint64_t val = AV_RN64(buf + offset); + AV_WN64(buf + offset, av_bswap64(val)); + } else if (size == 4) { + uint32_t val = AV_RN32(buf + offset); + AV_WN32(buf + offset, av_bswap32(val)); + } +} + static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) { uint32_t crc = av_adler32_update(0, pkt->data, pkt->size); @@ -52,21 +66,58 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) if (pkt->flags != AV_PKT_FLAG_KEY) av_strlcatf(buf, sizeof(buf), ", F=0x%0X", pkt->flags); if (pkt->side_data_elems) { - int i, j; + int i; av_strlcatf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems); for (i=0; i<pkt->side_data_elems; i++) { + const AVPacketSideData *const sd = &pkt->side_data[i]; + const uint8_t *data = sd->data; uint32_t side_data_crc = 0; - if (HAVE_BIGENDIAN && AV_PKT_DATA_PALETTE == pkt->side_data[i].type) { - for (j=0; j<pkt->side_data[i].size; j++) { - side_data_crc = av_adler32_update(side_data_crc, - pkt->side_data[i].data + (j^3), - 1); + + switch (sd->type) { +#if HAVE_BIGENDIAN + uint8_t bswap_buf[FFMAX(sizeof(AVCPBProperties), + sizeof(AVProducerReferenceTime))]; + case AV_PKT_DATA_PALETTE: + case AV_PKT_DATA_REPLAYGAIN: + case AV_PKT_DATA_DISPLAYMATRIX: + case AV_PKT_DATA_STEREO3D: + case AV_PKT_DATA_AUDIO_SERVICE_TYPE: + case AV_PKT_DATA_FALLBACK_TRACK: + case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: + case AV_PKT_DATA_SPHERICAL: + case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: + case AV_PKT_DATA_S12M_TIMECODE: + for (int j = 0; j < sd->size / 4; j++) { + uint8_t buf[4]; + AV_WL32(buf, AV_RB32(sd->data + 4 * j)); + side_data_crc = av_adler32_update(side_data_crc, buf, 4); + } + break; + case AV_PKT_DATA_CPB_PROPERTIES: +#define BSWAP(struct, field) bswap(bswap_buf, offsetof(struct, field), sizeof(((struct){0}).field)) + if (sd->size == sizeof(AVCPBProperties)) { + memcpy(bswap_buf, sd->data, sizeof(AVCPBProperties)); + data = bswap_buf; + BSWAP(AVCPBProperties, max_bitrate); + BSWAP(AVCPBProperties, min_bitrate); + BSWAP(AVCPBProperties, avg_bitrate); + BSWAP(AVCPBProperties, buffer_size); + BSWAP(AVCPBProperties, vbv_delay); + } + goto pod; + case AV_PKT_DATA_PRFT: + if (sd->size == sizeof(AVProducerReferenceTime)) { + memcpy(bswap_buf, sd->data, sizeof(AVProducerReferenceTime)); + data = bswap_buf; + BSWAP(AVProducerReferenceTime, wallclock); + BSWAP(AVProducerReferenceTime, flags); } - } else { - side_data_crc = av_adler32_update(0, - pkt->side_data[i].data, - pkt->side_data[i].size); + goto pod; + pod: +#endif + default: + side_data_crc = av_adler32_update(0, data, sd->size); } av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08"PRIx32, pkt->side_data[i].size, side_data_crc); } diff --git a/chromium/third_party/ffmpeg/libavformat/genh.c b/chromium/third_party/ffmpeg/libavformat/genh.c index 61adf499647..698104a9d61 100644 --- a/chromium/third_party/ffmpeg/libavformat/genh.c +++ b/chromium/third_party/ffmpeg/libavformat/genh.c @@ -87,7 +87,9 @@ static int genh_read_header(AVFormatContext *s) case 5: st->codecpar->codec_id = st->codecpar->block_align > 0 ? AV_CODEC_ID_PCM_S8_PLANAR : AV_CODEC_ID_PCM_S8; break; - case 6: st->codecpar->codec_id = AV_CODEC_ID_SDX2_DPCM; break; + case 6: if (st->codecpar->block_align > INT_MAX/1024) + return AVERROR_INVALIDDATA; + st->codecpar->codec_id = AV_CODEC_ID_SDX2_DPCM; break; case 7: ret = ff_alloc_extradata(st->codecpar, 2); if (ret < 0) return ret; @@ -144,6 +146,9 @@ static int genh_read_header(AVFormatContext *s) } } + if (st->codecpar->block_align <= 0) + return AVERROR_INVALIDDATA; + avio_skip(s->pb, start_offset - avio_tell(s->pb)); avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); diff --git a/chromium/third_party/ffmpeg/libavformat/gxf.c b/chromium/third_party/ffmpeg/libavformat/gxf.c index 49364b72058..b787d4f521f 100644 --- a/chromium/third_party/ffmpeg/libavformat/gxf.c +++ b/chromium/third_party/ffmpeg/libavformat/gxf.c @@ -285,9 +285,12 @@ static void gxf_track_tags(AVIOContext *pb, int *len, struct gxf_stream_info *si static void gxf_read_index(AVFormatContext *s, int pkt_len) { AVIOContext *pb = s->pb; AVStream *st; - uint32_t fields_per_map = avio_rl32(pb); - uint32_t map_cnt = avio_rl32(pb); + uint32_t fields_per_map, map_cnt; int i; + if (pkt_len < 8) + return; + fields_per_map = avio_rl32(pb); + map_cnt = avio_rl32(pb); pkt_len -= 8; if ((s->flags & AVFMT_FLAG_IGNIDX) || !s->streams) { avio_skip(pb, pkt_len); @@ -572,9 +575,9 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); if (idx < 0) return -1; - pos = st->index_entries[idx].pos; - if (idx < st->nb_index_entries - 2) - maxlen = st->index_entries[idx + 2].pos - pos; + pos = st->internal->index_entries[idx].pos; + if (idx < st->internal->nb_index_entries - 2) + maxlen = st->internal->index_entries[idx + 2].pos - pos; maxlen = FFMAX(maxlen, 200 * 1024); res = avio_seek(s->pb, pos, SEEK_SET); if (res < 0) diff --git a/chromium/third_party/ffmpeg/libavformat/hashenc.c b/chromium/third_party/ffmpeg/libavformat/hashenc.c index ce609f6efa1..5523dfd1cda 100644 --- a/chromium/third_party/ffmpeg/libavformat/hashenc.c +++ b/chromium/third_party/ffmpeg/libavformat/hashenc.c @@ -156,6 +156,7 @@ static int hash_write_trailer(struct AVFormatContext *s) return 0; } +#endif static void hash_free(struct AVFormatContext *s) { @@ -168,7 +169,6 @@ static void hash_free(struct AVFormatContext *s) } av_freep(&c->hashes); } -#endif #if CONFIG_HASH_MUXER static const AVClass hashenc_class = { @@ -326,14 +326,6 @@ static int framehash_write_packet(struct AVFormatContext *s, AVPacket *pkt) avio_printf(s->pb, "\n"); return 0; } - -static void framehash_free(struct AVFormatContext *s) -{ - struct HashContext *c = s->priv_data; - if (c->hashes) - av_hash_freep(&c->hashes[0]); - av_freep(&c->hashes); -} #endif #if CONFIG_FRAMEHASH_MUXER @@ -353,7 +345,7 @@ AVOutputFormat ff_framehash_muxer = { .init = framehash_init, .write_header = framehash_write_header, .write_packet = framehash_write_packet, - .deinit = framehash_free, + .deinit = hash_free, .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT | AVFMT_TS_NEGATIVE, .priv_class = &framehash_class, @@ -377,7 +369,7 @@ AVOutputFormat ff_framemd5_muxer = { .init = framehash_init, .write_header = framehash_write_header, .write_packet = framehash_write_packet, - .deinit = framehash_free, + .deinit = hash_free, .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT | AVFMT_TS_NEGATIVE, .priv_class = &framemd5_class, diff --git a/chromium/third_party/ffmpeg/libavformat/hls.c b/chromium/third_party/ffmpeg/libavformat/hls.c index 72e28ab94f4..0a522a4595e 100644 --- a/chromium/third_party/ffmpeg/libavformat/hls.c +++ b/chromium/third_party/ffmpeg/libavformat/hls.c @@ -1979,17 +1979,18 @@ static int hls_read_header(AVFormatContext *s) pls->ctx->interrupt_callback = s->interrupt_callback; url = av_strdup(pls->segments[0]->url); ret = av_probe_input_buffer(&pls->pb, &in_fmt, url, NULL, 0, 0); - av_free(url); if (ret < 0) { /* Free the ctx - it isn't initialized properly at this point, * so avformat_close_input shouldn't be called. If * avformat_open_input fails below, it frees and zeros the * context, so it doesn't need any special treatment like this. */ - av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", pls->segments[0]->url); + av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", url); avformat_free_context(pls->ctx); pls->ctx = NULL; + av_free(url); goto fail; } + av_free(url); pls->ctx->pb = &pls->pb; pls->ctx->io_open = nested_io_open; pls->ctx->flags |= s->flags & ~AVFMT_FLAG_CUSTOM_IO; diff --git a/chromium/third_party/ffmpeg/libavformat/hlsenc.c b/chromium/third_party/ffmpeg/libavformat/hlsenc.c index cb31d6aed7c..cafe0e8c692 100644 --- a/chromium/third_party/ffmpeg/libavformat/hlsenc.c +++ b/chromium/third_party/ffmpeg/libavformat/hlsenc.c @@ -46,6 +46,7 @@ #include "avformat.h" #include "avio_internal.h" +#include "avc.h" #if CONFIG_HTTP_PROTOCOL #include "http.h" #endif @@ -87,6 +88,7 @@ typedef struct HLSSegment { char iv_string[KEYSIZE*2 + 1]; struct HLSSegment *next; + double discont_program_date_time; } HLSSegment; typedef enum HLSFlags { @@ -258,6 +260,29 @@ typedef struct HLSContext { int has_video_m3u8; /* has video stream m3u8 list */ } HLSContext; +static int strftime_expand(const char *fmt, char **dest) +{ + int r = 1; + time_t now0; + struct tm *tm, tmpbuf; + char *buf; + + buf = av_mallocz(MAX_URL_SIZE); + if (!buf) + return AVERROR(ENOMEM); + + time(&now0); + tm = localtime_r(&now0, &tmpbuf); + r = strftime(buf, MAX_URL_SIZE, fmt, tm); + if (!r) { + av_free(buf); + return AVERROR(EINVAL); + } + *dest = buf; + + return r; +} + static int hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options) { @@ -337,6 +362,51 @@ static void write_codec_attr(AVStream *st, VariantStream *vs) } else { goto fail; } + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { + uint8_t *data = st->codecpar->extradata; + int profile = FF_PROFILE_UNKNOWN; + int level = FF_LEVEL_UNKNOWN; + + if (st->codecpar->profile != FF_PROFILE_UNKNOWN) + profile = st->codecpar->profile; + if (st->codecpar->level != FF_LEVEL_UNKNOWN) + level = st->codecpar->level; + + /* check the boundary of data which from current position is small than extradata_size */ + while (data && (data - st->codecpar->extradata + 19) < st->codecpar->extradata_size) { + /* get HEVC SPS NAL and seek to profile_tier_level */ + if (!(data[0] | data[1] | data[2]) && data[3] == 1 && ((data[4] & 0x7E) == 0x42)) { + uint8_t *rbsp_buf; + int remain_size = 0; + int rbsp_size = 0; + /* skip start code + nalu header */ + data += 6; + /* process by reference General NAL unit syntax */ + remain_size = st->codecpar->extradata_size - (data - st->codecpar->extradata); + rbsp_buf = ff_nal_unit_extract_rbsp(data, remain_size, &rbsp_size, 0); + if (!rbsp_buf) + return; + if (rbsp_size < 13) { + av_freep(&rbsp_buf); + break; + } + /* skip sps_video_parameter_set_id u(4), + * sps_max_sub_layers_minus1 u(3), + * and sps_temporal_id_nesting_flag u(1) */ + profile = rbsp_buf[1] & 0x1f; + /* skip 8 + 8 + 32 + 4 + 43 + 1 bit */ + level = rbsp_buf[12]; + av_freep(&rbsp_buf); + break; + } + data++; + } + if (st->codecpar->codec_tag == MKTAG('h','v','c','1') && + profile != FF_PROFILE_UNKNOWN && + level != FF_LEVEL_UNKNOWN) { + snprintf(attr, sizeof(attr), "%s.%d.4.L%d.B01", av_fourcc2str(st->codecpar->codec_tag), profile, level); + } else + goto fail; } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { snprintf(attr, sizeof(attr), "mp4a.40.33"); } else if (st->codecpar->codec_id == AV_CODEC_ID_MP3) { @@ -1078,6 +1148,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, en->keyframe_size = vs->video_keyframe_size; en->next = NULL; en->discont = 0; + en->discont_program_date_time = 0; if (vs->discontinuity) { en->discont = 1; @@ -1102,7 +1173,8 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, if (hls->max_nb_segments && vs->nb_entries >= hls->max_nb_segments) { en = vs->segments; - vs->initial_prog_date_time += en->duration; + if (!en->next->discont_program_date_time && !en->discont_program_date_time) + vs->initial_prog_date_time += en->duration; vs->segments = en->next; if (en && hls->flags & HLS_DELETE_SEGMENTS && #if FF_API_HLS_WRAP @@ -1136,6 +1208,7 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs char line[MAX_URL_SIZE]; const char *ptr; const char *end; + double discont_program_date_time = 0; if ((ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ, &s->interrupt_callback, NULL, @@ -1190,7 +1263,25 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs av_strlcpy(vs->iv_string, ptr, sizeof(vs->iv_string)); } } + } else if (av_strstart(line, "#EXT-X-PROGRAM-DATE-TIME:", &ptr)) { + struct tm program_date_time; + int y,M,d,h,m,s; + double ms; + if (sscanf(ptr, "%d-%d-%dT%d:%d:%d.%lf", &y, &M, &d, &h, &m, &s, &ms) != 7) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + program_date_time.tm_year = y - 1900; + program_date_time.tm_mon = M - 1; + program_date_time.tm_mday = d; + program_date_time.tm_hour = h; + program_date_time.tm_min = m; + program_date_time.tm_sec = s; + program_date_time.tm_isdst = -1; + + discont_program_date_time = mktime(&program_date_time); + discont_program_date_time += (double)(ms / 1000); } else if (av_strstart(line, "#", NULL)) { continue; } else if (line[0]) { @@ -1204,8 +1295,9 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs is_segment = 0; new_start_pos = avio_tell(vs->avf->pb); vs->size = new_start_pos - vs->start_pos; - vs->initial_prog_date_time -= vs->duration; // this is a previously existing segment ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size); + vs->last_segment->discont_program_date_time = discont_program_date_time; + discont_program_date_time += vs->duration; if (ret < 0) goto fail; vs->start_pos = new_start_pos; @@ -1526,7 +1618,11 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : vs->out, en->discont, byterange_mode, en->duration, hls->flags & HLS_ROUND_DURATIONS, en->size, en->pos, hls->baseurl, - en->filename, prog_date_time_p, en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY); + en->filename, + en->discont_program_date_time ? &en->discont_program_date_time : prog_date_time_p, + en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY); + if (en->discont_program_date_time) + en->discont_program_date_time -= en->duration; if (ret < 0) { av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); } @@ -1614,19 +1710,15 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) ff_format_set_url(oc, filename); } else { if (c->use_localtime) { - time_t now0; - struct tm *tm, tmpbuf; - int bufsize = strlen(vs->basename) + MAX_URL_SIZE; - char *buf = av_mallocz(bufsize); - if (!buf) - return AVERROR(ENOMEM); - time(&now0); - tm = localtime_r(&now0, &tmpbuf); - ff_format_set_url(oc, buf); - if (!strftime(oc->url, bufsize, vs->basename, tm)) { + int r; + char *expanded = NULL; + + r = strftime_expand(vs->basename, &expanded); + if (r < 0) { av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); - return AVERROR(EINVAL); + return r; } + ff_format_set_url(oc, expanded); err = sls_flag_use_localtime_filename(oc, c, vs); if (err < 0) { @@ -2247,6 +2339,10 @@ static int hls_write_header(AVFormatContext *s) continue; } avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, inner_st->time_base.num, inner_st->time_base.den); + if (outer_st->codecpar->codec_id == AV_CODEC_ID_HEVC && + outer_st->codecpar->codec_tag != MKTAG('h','v','c','1')) { + av_log(s, AV_LOG_WARNING, "Stream HEVC is not hvc1, you should use tag:v hvc1 to set it.\n"); + } write_codec_attr(outer_st, vs); } @@ -2398,9 +2494,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) vs->duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den; } } - } + can_split = can_split && (pkt->pts - vs->end_pts > 0); if (vs->packets_written && can_split && av_compare_ts(pkt->pts - vs->start_pts, st->time_base, end_pts, AV_TIME_BASE_Q) >= 0) { int64_t new_start_pos; @@ -2572,13 +2668,14 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) vs->packets_written++; if (oc->pb) { + int64_t keyframe_pre_pos = avio_tell(oc->pb); ret = ff_write_chained(oc, stream_index, pkt, s, 0); - vs->video_keyframe_size += pkt->size; - if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->flags & AV_PKT_FLAG_KEY)) { - vs->video_keyframe_size = avio_tell(oc->pb); - } else { - vs->video_keyframe_pos = avio_tell(vs->out); + if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && + (pkt->flags & AV_PKT_FLAG_KEY) && !keyframe_pre_pos) { + av_write_frame(oc, NULL); /* Flush any buffered data */ + vs->video_keyframe_size = avio_tell(oc->pb) - keyframe_pre_pos; } + vs->video_keyframe_pos = vs->start_pos; if (hls->ignore_io_errors) ret = 0; } @@ -2929,6 +3026,19 @@ static int hls_init(AVFormatContext *s) return ret; } + if (hls->use_localtime) { + int r; + char *expanded = NULL; + + r = strftime_expand(vs->fmp4_init_filename, &expanded); + if (r < 0) { + av_log(s, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); + return r; + } + av_free(vs->fmp4_init_filename); + vs->fmp4_init_filename = expanded; + } + p = strrchr(vs->m3u8_name, '/'); if (p) { char tmp = *(++p); diff --git a/chromium/third_party/ffmpeg/libavformat/http.c b/chromium/third_party/ffmpeg/libavformat/http.c index 3d25d652d31..2d24c00e183 100644 --- a/chromium/third_party/ffmpeg/libavformat/http.c +++ b/chromium/third_party/ffmpeg/libavformat/http.c @@ -1436,7 +1436,8 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) if ((!s->willclose || s->chunksize == UINT64_MAX) && s->off >= target_end) return AVERROR_EOF; len = ffurl_read(s->hd, buf, size); - if (!len && (!s->willclose || s->chunksize == UINT64_MAX) && s->off < target_end) { + if ((!len || len == AVERROR_EOF) && + (!s->willclose || s->chunksize == UINT64_MAX) && s->off < target_end) { av_log(h, AV_LOG_ERROR, "Stream ends prematurely at %"PRIu64", should be %"PRIu64"\n", s->off, target_end diff --git a/chromium/third_party/ffmpeg/libavformat/icodec.c b/chromium/third_party/ffmpeg/libavformat/icodec.c index b47fa98f800..93179bb41ee 100644 --- a/chromium/third_party/ffmpeg/libavformat/icodec.c +++ b/chromium/third_party/ffmpeg/libavformat/icodec.c @@ -84,6 +84,9 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4); ico->nb_images = avio_rl16(pb); + if (!ico->nb_images) + return AVERROR_INVALIDDATA; + ico->images = av_malloc_array(ico->nb_images, sizeof(IcoImage)); if (!ico->images) return AVERROR(ENOMEM); @@ -93,7 +96,7 @@ static int read_header(AVFormatContext *s) int tmp; if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0) - break; + goto fail; st = avformat_new_stream(s, NULL); if (!st) { @@ -113,13 +116,12 @@ static int read_header(AVFormatContext *s) ico->images[i].size = avio_rl32(pb); if (ico->images[i].size <= 0) { av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size); - av_freep(&ico->images); - return AVERROR_INVALIDDATA; + goto fail; } ico->images[i].offset = avio_rl32(pb); if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0) - break; + goto fail; codec = avio_rl32(pb); switch (codec) { @@ -130,8 +132,7 @@ static int read_header(AVFormatContext *s) break; case 40: if (ico->images[i].size < 40) { - av_freep(&ico->images); - return AVERROR_INVALIDDATA; + goto fail; } st->codecpar->codec_id = AV_CODEC_ID_BMP; tmp = avio_rl32(pb); @@ -143,12 +144,14 @@ static int read_header(AVFormatContext *s) break; default: avpriv_request_sample(s, "codec %d", codec); - av_freep(&ico->images); - return AVERROR_INVALIDDATA; + goto fail; } } return 0; +fail: + av_freep(&ico->images); + return AVERROR_INVALIDDATA; } static int read_packet(AVFormatContext *s, AVPacket *pkt) @@ -156,12 +159,14 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) IcoDemuxContext *ico = s->priv_data; IcoImage *image; AVIOContext *pb = s->pb; - AVStream *st = s->streams[0]; + AVStream *st; int ret; if (ico->current_image >= ico->nb_images) return AVERROR_EOF; + st = s->streams[0]; + image = &ico->images[ico->current_image]; if ((ret = avio_seek(pb, image->offset, SEEK_SET)) < 0) diff --git a/chromium/third_party/ffmpeg/libavformat/id3v2.c b/chromium/third_party/ffmpeg/libavformat/id3v2.c index cecd9b9f6d6..336a3964de9 100644 --- a/chromium/third_party/ffmpeg/libavformat/id3v2.c +++ b/chromium/third_party/ffmpeg/libavformat/id3v2.c @@ -993,6 +993,9 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata, av_log(s, AV_LOG_DEBUG, "Compresssed frame %s tlen=%d dlen=%ld\n", tag, tlen, dlen); + if (tlen <= 0) + goto seek; + av_fast_malloc(&uncompressed_buffer, &uncompressed_buffer_size, dlen); if (!uncompressed_buffer) { av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", dlen); diff --git a/chromium/third_party/ffmpeg/libavformat/iff.c b/chromium/third_party/ffmpeg/libavformat/iff.c index 04fe8be4eb8..f0176846207 100644 --- a/chromium/third_party/ffmpeg/libavformat/iff.c +++ b/chromium/third_party/ffmpeg/libavformat/iff.c @@ -223,6 +223,9 @@ static int parse_dsd_diin(AVFormatContext *s, AVStream *st, uint64_t eof) uint64_t orig_pos = avio_tell(pb); const char * metadata_tag = NULL; + if (size >= INT64_MAX) + return AVERROR_INVALIDDATA; + switch(tag) { case MKTAG('D','I','A','R'): metadata_tag = "artist"; break; case MKTAG('D','I','T','I'): metadata_tag = "title"; break; @@ -256,6 +259,9 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) uint64_t size = avio_rb64(pb); uint64_t orig_pos = avio_tell(pb); + if (size >= INT64_MAX) + return AVERROR_INVALIDDATA; + switch(tag) { case MKTAG('A','B','S','S'): if (size < 8) @@ -839,7 +845,7 @@ static int iff_read_packet(AVFormatContext *s, } else if (st->codecpar->codec_tag == ID_DST) { return read_dst_frame(s, pkt); } else { - if (iff->body_size > INT_MAX) + if (iff->body_size > INT_MAX || !iff->body_size) return AVERROR_INVALIDDATA; ret = av_get_packet(pb, pkt, iff->body_size); } @@ -875,6 +881,8 @@ static int iff_read_packet(AVFormatContext *s, pkt->flags |= AV_PKT_FLAG_KEY; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codecpar->codec_tag != ID_ANIM) { + if (iff->body_size > INT_MAX || !iff->body_size) + return AVERROR_INVALIDDATA; ret = av_get_packet(pb, pkt, iff->body_size); pkt->pos = pos; if (pos == iff->body_pos) diff --git a/chromium/third_party/ffmpeg/libavformat/ifv.c b/chromium/third_party/ffmpeg/libavformat/ifv.c index f95e9b0e52e..bca8f85d09b 100644 --- a/chromium/third_party/ffmpeg/libavformat/ifv.c +++ b/chromium/third_party/ffmpeg/libavformat/ifv.c @@ -195,21 +195,22 @@ static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt) if (ifv->next_video_index < ifv->total_vframes) { st = s->streams[ifv->video_stream_index]; - if (ifv->next_video_index < st->nb_index_entries) - e_next = ev = &st->index_entries[ifv->next_video_index]; + if (ifv->next_video_index < st->internal->nb_index_entries) + e_next = ev = &st->internal->index_entries[ifv->next_video_index]; } if (ifv->is_audio_present && ifv->next_audio_index < ifv->total_aframes) { st = s->streams[ifv->audio_stream_index]; - if (ifv->next_audio_index < st->nb_index_entries) { - ea = &st->index_entries[ifv->next_audio_index]; + if (ifv->next_audio_index < st->internal->nb_index_entries) { + ea = &st->internal->index_entries[ifv->next_audio_index]; if (!ev || ea->timestamp < ev->timestamp) e_next = ea; } } if (!ev) { + uint64_t vframes, aframes; if (ifv->is_audio_present && !ea) { /*read new video and audio indexes*/ @@ -217,8 +218,12 @@ static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt) ifv->next_audio_index = ifv->total_aframes; avio_skip(s->pb, 0x1c); - ifv->total_vframes += avio_rl32(s->pb); - ifv->total_aframes += avio_rl32(s->pb); + vframes = ifv->total_vframes + (uint64_t)avio_rl32(s->pb); + aframes = ifv->total_aframes + (uint64_t)avio_rl32(s->pb); + if (vframes > INT_MAX || aframes > INT_MAX) + return AVERROR_INVALIDDATA; + ifv->total_vframes = vframes; + ifv->total_aframes = aframes; avio_skip(s->pb, 0xc); if (avio_feof(s->pb)) @@ -240,7 +245,10 @@ static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt) ifv->next_video_index = ifv->total_vframes; avio_skip(s->pb, 0x1c); - ifv->total_vframes += avio_rl32(s->pb); + vframes = ifv->total_vframes + (uint64_t)avio_rl32(s->pb); + if (vframes > INT_MAX) + return AVERROR_INVALIDDATA; + ifv->total_vframes = vframes; avio_skip(s->pb, 0x10); if (avio_feof(s->pb)) diff --git a/chromium/third_party/ffmpeg/libavformat/img2.c b/chromium/third_party/ffmpeg/libavformat/img2.c index db37aa72283..6bdd7efe266 100644 --- a/chromium/third_party/ffmpeg/libavformat/img2.c +++ b/chromium/third_party/ffmpeg/libavformat/img2.c @@ -41,6 +41,7 @@ const IdStrMap ff_img_tags[] = { { AV_CODEC_ID_PBM, "pbm" }, { AV_CODEC_ID_PAM, "pam" }, { AV_CODEC_ID_PFM, "pfm" }, + { AV_CODEC_ID_CRI, "cri" }, { AV_CODEC_ID_ALIAS_PIX, "pix" }, { AV_CODEC_ID_DDS, "dds" }, { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" }, diff --git a/chromium/third_party/ffmpeg/libavformat/img2dec.c b/chromium/third_party/ffmpeg/libavformat/img2dec.c index 9a3c9fad020..ccb933ae33e 100644 --- a/chromium/third_party/ffmpeg/libavformat/img2dec.c +++ b/chromium/third_party/ffmpeg/libavformat/img2dec.c @@ -220,8 +220,10 @@ int ff_img_read_header(AVFormatContext *s1) avpriv_set_pts_info(st, 64, 1, 1000000000); } else if (s->ts_from_file) avpriv_set_pts_info(st, 64, 1, 1); - else + else { avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); + st->avg_frame_rate = s->framerate; + } if (s->width && s->height) { st->codecpar->width = s->width; @@ -587,7 +589,7 @@ static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if(index < 0) return -1; - s1->img_number = st->index_entries[index].pos; + s1->img_number = st->internal->index_entries[index].pos; return 0; } @@ -684,6 +686,17 @@ static int bmp_probe(const AVProbeData *p) return AVPROBE_SCORE_EXTENSION / 4; } +static int cri_probe(const AVProbeData *p) +{ + const uint8_t *b = p->buf; + + if ( AV_RL32(b) == 1 + && AV_RL32(b + 4) == 4 + && AV_RN32(b + 8) == AV_RN32("DVCC")) + return AVPROBE_SCORE_MAX - 1; + return 0; +} + static int dds_probe(const AVProbeData *p) { const uint8_t *b = p->buf; @@ -1101,6 +1114,7 @@ AVInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\ }; IMAGEAUTO_DEMUXER(bmp, AV_CODEC_ID_BMP) +IMAGEAUTO_DEMUXER(cri, AV_CODEC_ID_CRI) IMAGEAUTO_DEMUXER(dds, AV_CODEC_ID_DDS) IMAGEAUTO_DEMUXER(dpx, AV_CODEC_ID_DPX) IMAGEAUTO_DEMUXER(exr, AV_CODEC_ID_EXR) diff --git a/chromium/third_party/ffmpeg/libavformat/internal.h b/chromium/third_party/ffmpeg/libavformat/internal.h index f4174628e06..49e82bfbca1 100644 --- a/chromium/third_party/ffmpeg/libavformat/internal.h +++ b/chromium/third_party/ffmpeg/libavformat/internal.h @@ -191,6 +191,158 @@ struct AVStreamInternal { int is_intra_only; FFFrac *priv_pts; + +#define MAX_STD_TIMEBASES (30*12+30+3+6) + /** + * Stream information used internally by avformat_find_stream_info() + */ + struct { + int64_t last_dts; + int64_t duration_gcd; + int duration_count; + int64_t rfps_duration_sum; + double (*duration_error)[2][MAX_STD_TIMEBASES]; + int64_t codec_info_duration; + int64_t codec_info_duration_fields; + int frame_delay_evidence; + + /** + * 0 -> decoder has not been searched for yet. + * >0 -> decoder found + * <0 -> decoder with codec_id == -found_decoder has not been found + */ + int found_decoder; + + int64_t last_duration; + + /** + * Those are used for average framerate estimation. + */ + int64_t fps_first_dts; + int fps_first_dts_idx; + int64_t fps_last_dts; + int fps_last_dts_idx; + + } *info; + + AVIndexEntry *index_entries; /**< Only used if the format does not + support seeking natively. */ + int nb_index_entries; + unsigned int index_entries_allocated_size; + + int64_t interleaver_chunk_size; + int64_t interleaver_chunk_duration; + + /** + * stream probing state + * -1 -> probing finished + * 0 -> no probing requested + * rest -> perform probing with request_probe being the minimum score to accept. + */ + int request_probe; + /** + * Indicates that everything up to the next keyframe + * should be discarded. + */ + int skip_to_keyframe; + + /** + * Number of samples to skip at the start of the frame decoded from the next packet. + */ + int skip_samples; + + /** + * If not 0, the number of samples that should be skipped from the start of + * the stream (the samples are removed from packets with pts==0, which also + * assumes negative timestamps do not happen). + * Intended for use with formats such as mp3 with ad-hoc gapless audio + * support. + */ + int64_t start_skip_samples; + + /** + * If not 0, the first audio sample that should be discarded from the stream. + * This is broken by design (needs global sample count), but can't be + * avoided for broken by design formats such as mp3 with ad-hoc gapless + * audio support. + */ + int64_t first_discard_sample; + + /** + * The sample after last sample that is intended to be discarded after + * first_discard_sample. Works on frame boundaries only. Used to prevent + * early EOF if the gapless info is broken (considered concatenated mp3s). + */ + int64_t last_discard_sample; + + /** + * Number of internally decoded frames, used internally in libavformat, do not access + * its lifetime differs from info which is why it is not in that structure. + */ + int nb_decoded_frames; + + /** + * Timestamp offset added to timestamps before muxing + */ + int64_t mux_ts_offset; + + /** + * Internal data to check for wrapping of the time stamp + */ + int64_t pts_wrap_reference; + + /** + * Options for behavior, when a wrap is detected. + * + * Defined by AV_PTS_WRAP_ values. + * + * If correction is enabled, there are two possibilities: + * If the first time stamp is near the wrap point, the wrap offset + * will be subtracted, which will create negative time stamps. + * Otherwise the offset will be added. + */ + int pts_wrap_behavior; + + /** + * Internal data to prevent doing update_initial_durations() twice + */ + int update_initial_durations_done; + +#define MAX_REORDER_DELAY 16 + + /** + * Internal data to generate dts from pts + */ + int64_t pts_reorder_error[MAX_REORDER_DELAY+1]; + uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]; + + int64_t pts_buffer[MAX_REORDER_DELAY+1]; + + /** + * Internal data to analyze DTS and detect faulty mpeg streams + */ + int64_t last_dts_for_order_check; + uint8_t dts_ordered; + uint8_t dts_misordered; + + /** + * Internal data to inject global side data + */ + int inject_global_side_data; + + /** + * display aspect ratio (0 if unknown) + * - encoding: unused + * - decoding: Set by libavformat to calculate sample_aspect_ratio internally + */ + AVRational display_aspect_ratio; + + AVProbeData probe_data; + + /** + * last packet in packet_buffer for this stream when muxing. + */ + struct AVPacketList *last_in_packet_buffer; }; #ifdef __GNUC__ diff --git a/chromium/third_party/ffmpeg/libavformat/isom.c b/chromium/third_party/ffmpeg/libavformat/isom.c index 019175d8148..d1ef6e34079 100644 --- a/chromium/third_party/ffmpeg/libavformat/isom.c +++ b/chromium/third_party/ffmpeg/libavformat/isom.c @@ -316,6 +316,8 @@ const AVCodecTag ff_codec_movvideo_tags[] = { { AV_CODEC_ID_NOTCHLC, MKTAG('n', 'c', 'l', 'c') }, + { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'G', 'R') }, /* ASC Bayer BGGR */ + { AV_CODEC_ID_NONE, 0 }, }; diff --git a/chromium/third_party/ffmpeg/libavformat/isom.h b/chromium/third_party/ffmpeg/libavformat/isom.h index 78495fd3366..5a6d5040907 100644 --- a/chromium/third_party/ffmpeg/libavformat/isom.h +++ b/chromium/third_party/ffmpeg/libavformat/isom.h @@ -286,6 +286,10 @@ typedef struct MOVContext { int activation_bytes_size; void *audible_fixed_key; int audible_fixed_key_size; + void *audible_key; + int audible_key_size; + void *audible_iv; + int audible_iv_size; struct AVAES *aes_decrypt; uint8_t *decryption_key; int decryption_key_len; diff --git a/chromium/third_party/ffmpeg/libavformat/jacosubdec.c b/chromium/third_party/ffmpeg/libavformat/jacosubdec.c index 3414eb39386..14221b166c1 100644 --- a/chromium/third_party/ffmpeg/libavformat/jacosubdec.c +++ b/chromium/third_party/ffmpeg/libavformat/jacosubdec.c @@ -136,6 +136,7 @@ static int get_shift(int timeres, const char *buf) { int sign = 1; int a = 0, b = 0, c = 0, d = 0; + int64_t ret; #define SSEP "%*1[.:]" int n = sscanf(buf, "%d"SSEP"%d"SSEP"%d"SSEP"%d", &a, &b, &c, &d); #undef SSEP @@ -145,13 +146,22 @@ static int get_shift(int timeres, const char *buf) a = FFABS(a); } + ret = 0; switch (n) { - case 4: return sign * ((a*3600 + b*60 + c) * timeres + d); - case 3: return sign * (( a*60 + b) * timeres + c); - case 2: return sign * (( a) * timeres + b); + case 4: + ret = sign * (((int64_t)a*3600 + b*60 + c) * timeres + d); + break; + case 3: + ret = sign * (( (int64_t)a*60 + b) * timeres + c); + break; + case 2: + ret = sign * (( (int64_t)a) * timeres + b); + break; } + if ((int)ret != ret) + ret = 0; - return 0; + return ret; } static int jacosub_read_header(AVFormatContext *s) diff --git a/chromium/third_party/ffmpeg/libavformat/jvdec.c b/chromium/third_party/ffmpeg/libavformat/jvdec.c index 551f8069e6b..47d18e2beb7 100644 --- a/chromium/third_party/ffmpeg/libavformat/jvdec.c +++ b/chromium/third_party/ffmpeg/libavformat/jvdec.c @@ -92,7 +92,7 @@ static int read_header(AVFormatContext *s) vst->codecpar->height = avio_rl16(pb); vst->duration = vst->nb_frames = - ast->nb_index_entries = avio_rl16(pb); + ast->internal->nb_index_entries = avio_rl16(pb); avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000); avio_skip(pb, 4); @@ -107,19 +107,19 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 10); - ast->index_entries = av_malloc(ast->nb_index_entries * - sizeof(*ast->index_entries)); - if (!ast->index_entries) + ast->internal->index_entries = av_malloc(ast->internal->nb_index_entries * + sizeof(*ast->internal->index_entries)); + if (!ast->internal->index_entries) return AVERROR(ENOMEM); - jv->frames = av_malloc(ast->nb_index_entries * sizeof(JVFrame)); + jv->frames = av_malloc(ast->internal->nb_index_entries * sizeof(JVFrame)); if (!jv->frames) { - av_freep(&ast->index_entries); + av_freep(&ast->internal->index_entries); return AVERROR(ENOMEM); } - offset = 0x68 + ast->nb_index_entries * 16; - for (i = 0; i < ast->nb_index_entries; i++) { - AVIndexEntry *e = ast->index_entries + i; + offset = 0x68 + ast->internal->nb_index_entries * 16; + for (i = 0; i < ast->internal->nb_index_entries; i++) { + AVIndexEntry *e = ast->internal->index_entries + i; JVFrame *jvf = jv->frames + i; /* total frame size including audio, video, palette data and padding */ @@ -139,7 +139,7 @@ static int read_header(AVFormatContext *s) if (s->error_recognition & AV_EF_EXPLODE) { read_close(s); av_freep(&jv->frames); - av_freep(&ast->index_entries); + av_freep(&ast->internal->index_entries); return AVERROR_INVALIDDATA; } jvf->audio_size = @@ -170,8 +170,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *ast = s->streams[0]; int ret; - while (!avio_feof(s->pb) && jv->pts < ast->nb_index_entries) { - const AVIndexEntry *e = ast->index_entries + jv->pts; + while (!avio_feof(s->pb) && jv->pts < ast->internal->nb_index_entries) { + const AVIndexEntry *e = ast->internal->index_entries + jv->pts; const JVFrame *jvf = jv->frames + jv->pts; switch (jv->state) { @@ -244,9 +244,9 @@ static int read_seek(AVFormatContext *s, int stream_index, return 0; } - if (i < 0 || i >= ast->nb_index_entries) + if (i < 0 || i >= ast->internal->nb_index_entries) return 0; - if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ast->internal->index_entries[i].pos, SEEK_SET) < 0) return -1; jv->state = JV_AUDIO; diff --git a/chromium/third_party/ffmpeg/libavformat/kvag.c b/chromium/third_party/ffmpeg/libavformat/kvag.c index 0a11fc05562..8f641873b9b 100644 --- a/chromium/third_party/ffmpeg/libavformat/kvag.c +++ b/chromium/third_party/ffmpeg/libavformat/kvag.c @@ -83,7 +83,7 @@ static int kvag_read_header(AVFormatContext *s) par->bits_per_raw_sample = 16; par->block_align = 1; par->bit_rate = par->channels * - par->sample_rate * + (uint64_t)par->sample_rate * par->bits_per_coded_sample; avpriv_set_pts_info(st, 64, 1, par->sample_rate); diff --git a/chromium/third_party/ffmpeg/libavformat/latmenc.c b/chromium/third_party/ffmpeg/libavformat/latmenc.c index 5458ce2596b..701c3932c4c 100644 --- a/chromium/third_party/ffmpeg/libavformat/latmenc.c +++ b/chromium/third_party/ffmpeg/libavformat/latmenc.c @@ -101,6 +101,17 @@ static int latm_write_header(AVFormatContext *s) return 0; } +static void copy_bits(PutBitContext *pb, const uint8_t *src, int length) +{ + int words = length >> 4; + int bits = length & 15; + int i; + for (i = 0; i < words; i++) + put_bits(pb, 16, AV_RB16(src + 2 * i)); + if (bits) + put_bits(pb, bits, AV_RB16(src + 2 * words) >> (16 - bits)); +} + static void latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) { LATMContext *ctx = s->priv_data; @@ -120,12 +131,12 @@ static void latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) /* AudioSpecificConfig */ if (ctx->object_type == AOT_ALS) { - header_size = par->extradata_size-(ctx->off >> 3); - avpriv_copy_bits(bs, &par->extradata[ctx->off >> 3], header_size); + header_size = (par->extradata_size - (ctx->off >> 3)) * 8; + copy_bits(bs, &par->extradata[ctx->off >> 3], header_size); } else { // + 3 assumes not scalable and dependsOnCoreCoder == 0, // see decode_ga_specific_config in libavcodec/aacdec.c - avpriv_copy_bits(bs, par->extradata, ctx->off + 3); + copy_bits(bs, par->extradata, ctx->off + 3); if (!ctx->channel_conf) { GetBitContext gb; @@ -207,9 +218,9 @@ static int latm_write_packet(AVFormatContext *s, AVPacket *pkt) // This allows us to remux our FATE AAC samples into latm // files that are still playable with minimal effort. put_bits(&bs, 8, pkt->data[0] & 0xfe); - avpriv_copy_bits(&bs, pkt->data + 1, 8*pkt->size - 8); + copy_bits(&bs, pkt->data + 1, 8*pkt->size - 8); } else - avpriv_copy_bits(&bs, pkt->data, 8*pkt->size); + copy_bits(&bs, pkt->data, 8*pkt->size); flush_put_bits(&bs); diff --git a/chromium/third_party/ffmpeg/libavformat/libopenmpt.c b/chromium/third_party/ffmpeg/libavformat/libopenmpt.c index 52511aba56c..b07da5f078d 100644 --- a/chromium/third_party/ffmpeg/libavformat/libopenmpt.c +++ b/chromium/third_party/ffmpeg/libavformat/libopenmpt.c @@ -218,7 +218,7 @@ static int read_seek_openmpt(AVFormatContext *s, int stream_idx, int64_t ts, int return 0; } -static int probe_openmpt_extension(AVProbeData *p) +static int probe_openmpt_extension(const AVProbeData *p) { const char *ext; if (p->filename) { diff --git a/chromium/third_party/ffmpeg/libavformat/libsrt.c b/chromium/third_party/ffmpeg/libavformat/libsrt.c index 4025b249761..f73e7dbfa51 100644 --- a/chromium/third_party/ffmpeg/libavformat/libsrt.c +++ b/chromium/third_party/ffmpeg/libavformat/libsrt.c @@ -373,11 +373,6 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) int64_t open_timeout = 0; int eid; - eid = srt_epoll_create(); - if (eid < 0) - return libsrt_neterrno(h); - s->eid = eid; - av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); if (strcmp(proto, "srt")) @@ -413,6 +408,11 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) cur_ai = ai; + eid = srt_epoll_create(); + if (eid < 0) + return libsrt_neterrno(h); + s->eid = eid; + restart: fd = srt_socket(cur_ai->ai_family, cur_ai->ai_socktype, 0); @@ -495,6 +495,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) if (listen_fd >= 0) srt_close(listen_fd); freeaddrinfo(ai); + srt_epoll_release(s->eid); return ret; } @@ -584,7 +585,8 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) } else if (!strcmp(buf, "rendezvous")) { s->mode = SRT_MODE_RENDEZVOUS; } else { - return AVERROR(EIO); + ret = AVERROR(EINVAL); + goto err; } } if (av_find_info_tag(buf, sizeof(buf), "sndbuf", p)) { @@ -632,10 +634,15 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) s->linger = strtol(buf, NULL, 10); } } - return libsrt_setup(h, uri, flags); + ret = libsrt_setup(h, uri, flags); + if (ret < 0) + goto err; + return 0; + err: av_freep(&s->smoother); av_freep(&s->streamid); + srt_cleanup(); return ret; } diff --git a/chromium/third_party/ffmpeg/libavformat/lrcdec.c b/chromium/third_party/ffmpeg/libavformat/lrcdec.c index 46d5e2bc6a2..ca23a60f845 100644 --- a/chromium/third_party/ffmpeg/libavformat/lrcdec.c +++ b/chromium/third_party/ffmpeg/libavformat/lrcdec.c @@ -185,6 +185,8 @@ static int lrc_read_header(AVFormatContext *s) sscanf(comma_offset + 1, "%"SCNd64, &lrc->ts_offset) != 1) { av_dict_set(&s->metadata, line.str + 1, comma_offset + 1, 0); } + lrc->ts_offset = av_clip64(lrc->ts_offset, INT64_MIN/4, INT64_MAX/4); + *comma_offset = ':'; *right_bracket_offset = ']'; } @@ -198,6 +200,7 @@ static int lrc_read_header(AVFormatContext *s) while((ts_stroffset_incr = read_ts(line.str + ts_stroffset, &ts_start)) != 0) { + ts_start = av_clip64(ts_start, INT64_MIN/4, INT64_MAX/4); ts_stroffset += ts_stroffset_incr; sub = ff_subtitles_queue_insert(&lrc->q, line.str + ts_strlength, line.len - ts_strlength, 0); diff --git a/chromium/third_party/ffmpeg/libavformat/lvfdec.c b/chromium/third_party/ffmpeg/libavformat/lvfdec.c index 8b8d6f01b92..4c87728deff 100644 --- a/chromium/third_party/ffmpeg/libavformat/lvfdec.c +++ b/chromium/third_party/ffmpeg/libavformat/lvfdec.c @@ -106,6 +106,7 @@ static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt) unsigned size, flags, timestamp, id; int64_t pos; int ret, is_video = 0; + int stream_index; pos = avio_tell(s->pb); while (!avio_feof(s->pb)) { @@ -121,12 +122,15 @@ static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt) case MKTAG('0', '1', 'w', 'b'): if (size < 8) return AVERROR_INVALIDDATA; + stream_index = is_video ? 0 : 1; + if (stream_index >= s->nb_streams) + return AVERROR_INVALIDDATA; timestamp = avio_rl32(s->pb); flags = avio_rl32(s->pb); ret = av_get_packet(s->pb, pkt, size - 8); if (flags & (1 << 12)) pkt->flags |= AV_PKT_FLAG_KEY; - pkt->stream_index = is_video ? 0 : 1; + pkt->stream_index = stream_index; pkt->pts = timestamp; pkt->pos = pos; return ret; diff --git a/chromium/third_party/ffmpeg/libavformat/matroskadec.c b/chromium/third_party/ffmpeg/libavformat/matroskadec.c index ebfbd761b74..d266511b345 100644 --- a/chromium/third_party/ffmpeg/libavformat/matroskadec.c +++ b/chromium/third_party/ffmpeg/libavformat/matroskadec.c @@ -2322,6 +2322,15 @@ static int matroska_parse_tracks(AVFormatContext *s) if (!track->codec_id) continue; + if ( track->type == MATROSKA_TRACK_TYPE_AUDIO && track->codec_id[0] != 'A' + || track->type == MATROSKA_TRACK_TYPE_VIDEO && track->codec_id[0] != 'V' + || track->type == MATROSKA_TRACK_TYPE_SUBTITLE && track->codec_id[0] != 'D' && track->codec_id[0] != 'S' + || track->type == MATROSKA_TRACK_TYPE_METADATA && track->codec_id[0] != 'D' && track->codec_id[0] != 'S' + ) { + av_log(matroska->ctx, AV_LOG_INFO, "Inconsistent track type\n"); + continue; + } + if (track->audio.samplerate < 0 || track->audio.samplerate > INT_MAX || isnan(track->audio.samplerate)) { av_log(matroska->ctx, AV_LOG_WARNING, @@ -2680,8 +2689,12 @@ static int matroska_parse_tracks(AVFormatContext *s) av_log(matroska->ctx, AV_LOG_INFO, "Unknown/unsupported AVCodecID %s.\n", track->codec_id); - if (track->time_scale < 0.01) + if (track->time_scale < 0.01) { + av_log(matroska->ctx, AV_LOG_WARNING, + "Track TimestampScale too small %f, assuming 1.0.\n", + track->time_scale); track->time_scale = 1.0; + } avpriv_set_pts_info(st, 64, matroska->time_scale * track->time_scale, 1000 * 1000 * 1000); /* 64 bit pts in ns */ @@ -3556,7 +3569,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf uint32_t lace_size[256]; int n, flags, laces = 0; uint64_t num; - int trust_default_duration = 1; + int trust_default_duration; ffio_init_context(&pb, data, size, 0, NULL, NULL, NULL, NULL); @@ -3590,7 +3603,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf if (cluster_time != (uint64_t) -1 && (block_time >= 0 || cluster_time >= -block_time)) { - timecode = cluster_time + block_time - track->codec_delay_in_track_tb; + uint64_t timecode_cluster_in_track_tb = (double) cluster_time / track->time_scale; + timecode = timecode_cluster_in_track_tb + block_time - track->codec_delay_in_track_tb; if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE && timecode < track->end_timecode) is_keyframe = 0; /* overlapping subtitles are not key frame */ @@ -3610,7 +3624,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf return res; if (is_keyframe) matroska->skip_to_keyframe = 0; - else if (!st->skip_to_keyframe) { + else if (!st->internal->skip_to_keyframe) { av_log(matroska->ctx, AV_LOG_ERROR, "File is broken, keyframes not correctly marked!\n"); matroska->skip_to_keyframe = 0; } @@ -3623,7 +3637,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf return res; } - if (track->audio.samplerate == 8000) { + trust_default_duration = track->default_duration != 0; + if (track->audio.samplerate == 8000 && trust_default_duration) { // If this is needed for more codecs, then add them here if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { if (track->audio.samplerate != st->codecpar->sample_rate || !st->codecpar->frame_size) @@ -3780,13 +3795,13 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, matroska_parse_cues(matroska); } - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) goto err; - timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); + timestamp = FFMAX(timestamp, st->internal->index_entries[0].timestamp); - if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) { - matroska_reset_status(matroska, 0, st->index_entries[st->nb_index_entries - 1].pos); - while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) { + if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) { + matroska_reset_status(matroska, 0, st->internal->index_entries[st->internal->nb_index_entries - 1].pos); + while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) { matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break; @@ -3794,7 +3809,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } matroska_clear_queue(matroska); - if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1)) + if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->internal->nb_index_entries - 1)) goto err; tracks = matroska->tracks.elem; @@ -3806,17 +3821,17 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } /* We seek to a level 1 element, so set the appropriate status. */ - matroska_reset_status(matroska, 0, st->index_entries[index].pos); + matroska_reset_status(matroska, 0, st->internal->index_entries[index].pos); if (flags & AVSEEK_FLAG_ANY) { - st->skip_to_keyframe = 0; + st->internal->skip_to_keyframe = 0; matroska->skip_to_timecode = timestamp; } else { - st->skip_to_keyframe = 1; - matroska->skip_to_timecode = st->index_entries[index].timestamp; + st->internal->skip_to_keyframe = 1; + matroska->skip_to_timecode = st->internal->index_entries[index].timestamp; } matroska->skip_to_keyframe = 1; matroska->done = 0; - ff_update_cur_dts(s, st, st->index_entries[index].timestamp); + ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp); return 0; err: // slightly hackish but allows proper fallback to @@ -3824,7 +3839,7 @@ err: matroska_reset_status(matroska, 0, -1); matroska->resync_pos = -1; matroska_clear_queue(matroska); - st->skip_to_keyframe = + st->internal->skip_to_keyframe = matroska->skip_to_keyframe = 0; matroska->done = 0; return -1; @@ -3861,8 +3876,8 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) MatroskaDemuxContext *matroska = s->priv_data; CueDesc cue_desc; int i; - int nb_index_entries = s->streams[0]->nb_index_entries; - AVIndexEntry *index_entries = s->streams[0]->index_entries; + int nb_index_entries = s->streams[0]->internal->nb_index_entries; + AVIndexEntry *index_entries = s->streams[0]->internal->index_entries; if (ts >= matroska->duration * matroska->time_scale) return (CueDesc) {-1, -1, -1, -1}; for (i = 1; i < nb_index_entries; i++) { if (index_entries[i - 1].timestamp * matroska->time_scale <= ts && @@ -3892,11 +3907,11 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) uint32_t id = matroska->current_id; int64_t cluster_pos, before_pos; int index, rv = 1; - if (s->streams[0]->nb_index_entries <= 0) return 0; + if (s->streams[0]->internal->nb_index_entries <= 0) return 0; // seek to the first cluster using cues. index = av_index_search_timestamp(s->streams[0], 0, 0); if (index < 0) return 0; - cluster_pos = s->streams[0]->index_entries[index].pos; + cluster_pos = s->streams[0]->internal->index_entries[index].pos; before_pos = avio_tell(s->pb); while (1) { uint64_t cluster_id, cluster_length; @@ -4020,9 +4035,9 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t double bandwidth = 0.0; int i; - for (i = 0; i < st->nb_index_entries; i++) { + for (i = 0; i < st->internal->nb_index_entries; i++) { int64_t prebuffer_ns = 1000000000; - int64_t time_ns = st->index_entries[i].timestamp * matroska->time_scale; + int64_t time_ns = st->internal->index_entries[i].timestamp * matroska->time_scale; double nano_seconds_per_second = 1000000000.0; int64_t prebuffered_ns = time_ns + prebuffer_ns; double prebuffer_bytes = 0.0; @@ -4160,14 +4175,14 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) // store cue point timestamps as a comma separated list for checking subsegment alignment in // the muxer. assumes that each timestamp cannot be more than 20 characters long. - buf = av_malloc_array(s->streams[0]->nb_index_entries, 20); + buf = av_malloc_array(s->streams[0]->internal->nb_index_entries, 20); if (!buf) return -1; strcpy(buf, ""); - for (i = 0; i < s->streams[0]->nb_index_entries; i++) { + for (i = 0; i < s->streams[0]->internal->nb_index_entries; i++) { int ret = snprintf(buf + end, 20, - "%" PRId64"%s", s->streams[0]->index_entries[i].timestamp, - i != s->streams[0]->nb_index_entries - 1 ? "," : ""); - if (ret <= 0 || (ret == 20 && i == s->streams[0]->nb_index_entries - 1)) { + "%" PRId64"%s", s->streams[0]->internal->index_entries[i].timestamp, + i != s->streams[0]->internal->nb_index_entries - 1 ? "," : ""); + if (ret <= 0 || (ret == 20 && i == s->streams[0]->internal->nb_index_entries - 1)) { av_log(s, AV_LOG_ERROR, "timestamp too long.\n"); av_free(buf); return AVERROR_INVALIDDATA; diff --git a/chromium/third_party/ffmpeg/libavformat/mlvdec.c b/chromium/third_party/ffmpeg/libavformat/mlvdec.c index f08aabf4e0d..1ddef3461ea 100644 --- a/chromium/third_party/ffmpeg/libavformat/mlvdec.c +++ b/chromium/third_party/ffmpeg/libavformat/mlvdec.c @@ -191,12 +191,12 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f } } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) { uint64_t pts = avio_rl32(pb); - ff_add_index_entry(&vst->index_entries, &vst->nb_index_entries, &vst->index_entries_allocated_size, + ff_add_index_entry(&vst->internal->index_entries, &vst->internal->nb_index_entries, &vst->internal->index_entries_allocated_size, avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME); size -= 4; } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) { uint64_t pts = avio_rl32(pb); - ff_add_index_entry(&ast->index_entries, &ast->nb_index_entries, &ast->index_entries_allocated_size, + ff_add_index_entry(&ast->internal->index_entries, &ast->internal->nb_index_entries, &ast->internal->index_entries_allocated_size, avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME); size -= 4; } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) { @@ -374,22 +374,22 @@ static int read_header(AVFormatContext *avctx) } if (vst) - vst->duration = vst->nb_index_entries; + vst->duration = vst->internal->nb_index_entries; if (ast) - ast->duration = ast->nb_index_entries; + ast->duration = ast->internal->nb_index_entries; - if ((vst && !vst->nb_index_entries) || (ast && !ast->nb_index_entries)) { + if ((vst && !vst->internal->nb_index_entries) || (ast && !ast->internal->nb_index_entries)) { av_log(avctx, AV_LOG_ERROR, "no index entries found\n"); read_close(avctx); return AVERROR_INVALIDDATA; } if (vst && ast) - avio_seek(pb, FFMIN(vst->index_entries[0].pos, ast->index_entries[0].pos), SEEK_SET); + avio_seek(pb, FFMIN(vst->internal->index_entries[0].pos, ast->internal->index_entries[0].pos), SEEK_SET); else if (vst) - avio_seek(pb, vst->index_entries[0].pos, SEEK_SET); + avio_seek(pb, vst->internal->index_entries[0].pos, SEEK_SET); else if (ast) - avio_seek(pb, ast->index_entries[0].pos, SEEK_SET); + avio_seek(pb, ast->internal->index_entries[0].pos, SEEK_SET); return 0; } @@ -415,12 +415,12 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR(EIO); } - pb = mlv->pb[st->index_entries[index].size]; + pb = mlv->pb[st->internal->index_entries[index].size]; if (!pb) { ret = FFERROR_REDO; goto next_packet; } - avio_seek(pb, st->index_entries[index].pos, SEEK_SET); + avio_seek(pb, st->internal->index_entries[index].pos, SEEK_SET); avio_skip(pb, 4); // blockType size = avio_rl32(pb); diff --git a/chromium/third_party/ffmpeg/libavformat/moflex.c b/chromium/third_party/ffmpeg/libavformat/moflex.c index 937f63cb637..8142925adc9 100644 --- a/chromium/third_party/ffmpeg/libavformat/moflex.c +++ b/chromium/third_party/ffmpeg/libavformat/moflex.c @@ -316,6 +316,8 @@ static int moflex_read_packet(AVFormatContext *s, AVPacket *pkt) } pkt_size = pop_int(br, pb, 13) + 1; + if (pkt_size > m->size) + return AVERROR_INVALIDDATA; packet = s->streams[stream_index]->priv_data; if (!packet) { avio_skip(pb, pkt_size); @@ -342,8 +344,11 @@ static int moflex_read_packet(AVFormatContext *s, AVPacket *pkt) m->in_block = 0; - if (m->flags % 2 == 0) + if (m->flags % 2 == 0) { + if (m->size <= 0) + return AVERROR_INVALIDDATA; avio_seek(pb, m->pos + m->size, SEEK_SET); + } } return AVERROR_EOF; diff --git a/chromium/third_party/ffmpeg/libavformat/mov.c b/chromium/third_party/ffmpeg/libavformat/mov.c index 2689b196dea..1654c623c66 100644 --- a/chromium/third_party/ffmpeg/libavformat/mov.c +++ b/chromium/third_party/ffmpeg/libavformat/mov.c @@ -588,6 +588,11 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) entries >= UINT_MAX / sizeof(*sc->drefs)) return AVERROR_INVALIDDATA; + for (i = 0; i < sc->drefs_count; i++) { + MOVDref *dref = &sc->drefs[i]; + av_freep(&dref->path); + av_freep(&dref->dir); + } av_free(sc->drefs); sc->drefs_count = 0; sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); @@ -1075,6 +1080,30 @@ fail: return ret; } +static int mov_aaxc_crypto(MOVContext *c) +{ + if (c->audible_key_size != 16) { + av_log(c->fc, AV_LOG_FATAL, "[aaxc] audible_key value needs to be 16 bytes!\n"); + return AVERROR(EINVAL); + } + + if (c->audible_iv_size != 16) { + av_log(c->fc, AV_LOG_FATAL, "[aaxc] audible_iv value needs to be 16 bytes!\n"); + return AVERROR(EINVAL); + } + + c->aes_decrypt = av_aes_alloc(); + if (!c->aes_decrypt) { + return AVERROR(ENOMEM); + } + + memcpy(c->file_key, c->audible_key, 16); + memcpy(c->file_iv, c->audible_iv, 16); + c->aax_mode = 1; + + return 0; +} + // Audible AAX (and AAX+) bytestream decryption static int aax_filter(uint8_t *input, int size, MOVContext *c) { @@ -1123,6 +1152,11 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_dict_set(&c->fc->metadata, "compatible_brands", comp_brands_str, AV_DICT_DONT_STRDUP_VAL); + // Logic for handling Audible's .aaxc files + if (!strcmp(type, "aaxc")) { + mov_aaxc_crypto(c); + } + return 0; } @@ -1477,7 +1511,7 @@ static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) c->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */ // set the AVFormatContext duration because the duration of individual tracks // may be inaccurate - if (c->time_scale > 0 && !c->trex_data) + if (!c->trex_data) c->fc->duration = av_rescale(c->duration, AV_TIME_BASE, c->time_scale); avio_rb32(pb); /* preferred scale */ @@ -1767,8 +1801,8 @@ static int mov_read_ares(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; den *= 2; case 1: - c->fc->streams[c->fc->nb_streams-1]->display_aspect_ratio.num = num; - c->fc->streams[c->fc->nb_streams-1]->display_aspect_ratio.den = den; + c->fc->streams[c->fc->nb_streams-1]->internal->display_aspect_ratio.num = num; + c->fc->streams[c->fc->nb_streams-1]->internal->display_aspect_ratio.den = den; default: return 0; } @@ -2075,6 +2109,7 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, uint8_t codec_name[32] = { 0 }; int64_t stsd_start; unsigned int len; + uint32_t id = 0; /* The first 16 bytes of the video sample description are already * read in ff_mov_read_stsd_entries() */ @@ -2082,7 +2117,8 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, avio_rb16(pb); /* version */ avio_rb16(pb); /* revision level */ - avio_rb32(pb); /* vendor */ + id = avio_rl32(pb); /* vendor */ + av_dict_set(&st->metadata, "vendor_id", av_fourcc2str(id), 0); avio_rb32(pb); /* temporal quality */ avio_rb32(pb); /* spatial quality */ @@ -2130,10 +2166,12 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, { int bits_per_sample, flags; uint16_t version = avio_rb16(pb); + uint32_t id = 0; AVDictionaryEntry *compatible_brands = av_dict_get(c->fc->metadata, "compatible_brands", NULL, AV_DICT_MATCH_CASE); avio_rb16(pb); /* revision level */ - avio_rb32(pb); /* vendor */ + id = avio_rl32(pb); /* vendor */ + av_dict_set(&st->metadata, "vendor_id", av_fourcc2str(id), 0); st->codecpar->channels = avio_rb16(pb); /* channel count */ st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* sample size */ @@ -3196,8 +3234,8 @@ static int find_prev_closest_index(AVStream *st, int64_t* ctts_sample) { MOVStreamContext *msc = st->priv_data; - AVIndexEntry *e_keep = st->index_entries; - int nb_keep = st->nb_index_entries; + AVIndexEntry *e_keep = st->internal->index_entries; + int nb_keep = st->internal->nb_index_entries; int64_t i = 0; int64_t index_ctts_count; @@ -3210,8 +3248,8 @@ static int find_prev_closest_index(AVStream *st, timestamp_pts -= msc->dts_shift; } - st->index_entries = e_old; - st->nb_index_entries = nb_old; + st->internal->index_entries = e_old; + st->internal->nb_index_entries = nb_old; *index = av_index_search_timestamp(st, timestamp_pts, flag | AVSEEK_FLAG_BACKWARD); // Keep going backwards in the index entries until the timestamp is the same. @@ -3264,14 +3302,14 @@ static int find_prev_closest_index(AVStream *st, } /* restore AVStream state*/ - st->index_entries = e_keep; - st->nb_index_entries = nb_keep; + st->internal->index_entries = e_keep; + st->internal->nb_index_entries = nb_keep; return *index >= 0 ? 0 : -1; } /** - * Add index entry with the given values, to the end of st->index_entries. - * Returns the new size st->index_entries if successful, else returns -1. + * Add index entry with the given values, to the end of st->internal->index_entries. + * Returns the new size st->internal->index_entries if successful, else returns -1. * * This function is similar to ff_add_index_entry in libavformat/utils.c * except that here we are always unconditionally adding an index entry to @@ -3285,27 +3323,27 @@ static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, { AVIndexEntry *entries, *ie; int64_t index = -1; - const size_t min_size_needed = (st->nb_index_entries + 1) * sizeof(AVIndexEntry); + const size_t min_size_needed = (st->internal->nb_index_entries + 1) * sizeof(AVIndexEntry); // Double the allocation each time, to lower memory fragmentation. // Another difference from ff_add_index_entry function. const size_t requested_size = - min_size_needed > st->index_entries_allocated_size ? - FFMAX(min_size_needed, 2 * st->index_entries_allocated_size) : + min_size_needed > st->internal->index_entries_allocated_size ? + FFMAX(min_size_needed, 2 * st->internal->index_entries_allocated_size) : min_size_needed; - if (st->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) + if (st->internal->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) return -1; - entries = av_fast_realloc(st->index_entries, - &st->index_entries_allocated_size, + entries = av_fast_realloc(st->internal->index_entries, + &st->internal->index_entries_allocated_size, requested_size); if (!entries) return -1; - st->index_entries= entries; + st->internal->index_entries= entries; - index= st->nb_index_entries++; + index= st->internal->nb_index_entries++; ie= &entries[index]; ie->pos = pos; @@ -3324,10 +3362,10 @@ static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_ int64_t* frame_duration_buffer, int frame_duration_buffer_size) { int i = 0; - av_assert0(end_index >= 0 && end_index <= st->nb_index_entries); + av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries); for (i = 0; i < frame_duration_buffer_size; i++) { end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i]; - st->index_entries[end_index - 1 - i].timestamp = end_ts; + st->internal->index_entries[end_index - 1 - i].timestamp = end_ts; } } @@ -3379,14 +3417,14 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) if (st->codecpar->video_delay <= 0 && msc->ctts_data && st->codecpar->codec_id == AV_CODEC_ID_H264) { st->codecpar->video_delay = 0; - for (ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) { + for (ind = 0; ind < st->internal->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) { // Point j to the last elem of the buffer and insert the current pts there. j = buf_start; buf_start = (buf_start + 1); if (buf_start == MAX_REORDER_DELAY + 1) buf_start = 0; - pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; + pts_buf[j] = st->internal->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; // The timestamps that are already in the sorted buffer, and are greater than the // current pts, are exactly the timestamps that need to be buffered to output PTS @@ -3466,7 +3504,7 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample) } /** - * Fix st->index_entries, so that it contains only the entries (and the entries + * Fix st->internal->index_entries, so that it contains only the entries (and the entries * which are needed to decode them) that fall in the edit list time ranges. * Also fixes the timestamps of the index entries to match the timeline * specified the edit lists. @@ -3474,8 +3512,8 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample) static void mov_fix_index(MOVContext *mov, AVStream *st) { MOVStreamContext *msc = st->priv_data; - AVIndexEntry *e_old = st->index_entries; - int nb_old = st->nb_index_entries; + AVIndexEntry *e_old = st->internal->index_entries; + int nb_old = st->internal->nb_index_entries; const AVIndexEntry *e_old_end = e_old + nb_old; const AVIndexEntry *current = NULL; MOVStts *ctts_data_old = msc->ctts_data; @@ -3520,9 +3558,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) current_index_range = msc->index_ranges - 1; // Clean AVStream from traces of old index - st->index_entries = NULL; - st->index_entries_allocated_size = 0; - st->nb_index_entries = 0; + st->internal->index_entries = NULL; + st->internal->index_entries_allocated_size = 0; + st->internal->nb_index_entries = 0; // Clean ctts fields of MOVStreamContext msc->ctts_data = NULL; @@ -3567,7 +3605,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } if (first_non_zero_audio_edit > 0) - st->skip_samples = msc->start_pad = 0; + st->internal->skip_samples = msc->start_pad = 0; } // While reordering frame index according to edit list we must handle properly @@ -3642,7 +3680,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time && first_non_zero_audio_edit > 0) { packet_skip_samples = edit_list_media_time - curr_cts; - st->skip_samples += packet_skip_samples; + st->internal->skip_samples += packet_skip_samples; // Shift the index entry timestamp by packet_skip_samples to be correct. edit_list_dts_counter -= packet_skip_samples; @@ -3651,7 +3689,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for // discarded packets. if (frame_duration_buffer) { - fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter, + fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3675,7 +3713,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Increment skip_samples for the first non-zero audio edit list if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && first_non_zero_audio_edit > 0 && st->codecpar->codec_id != AV_CODEC_ID_VORBIS) { - st->skip_samples += frame_duration; + st->internal->skip_samples += frame_duration; } } } @@ -3690,7 +3728,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Make timestamps strictly monotonically increasing by rewriting timestamps for // discarded packets. if (frame_duration_buffer) { - fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter, + fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3751,8 +3789,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (msc->min_corrected_pts > 0) { av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts); - for (i = 0; i < st->nb_index_entries; ++i) { - st->index_entries[i].timestamp -= msc->min_corrected_pts; + for (i = 0; i < st->internal->nb_index_entries; ++i) { + st->internal->index_entries[i].timestamp -= msc->min_corrected_pts; } } } @@ -3761,7 +3799,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Update av stream length, if it ends up shorter than the track's media duration st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts); - msc->start_pad = st->skip_samples; + msc->start_pad = st->internal->skip_samples; // Free the old index and the old CTTS structures av_free(e_old); @@ -3845,17 +3883,17 @@ static void mov_build_index(MOVContext *mov, AVStream *st) current_dts -= sc->dts_shift; last_dts = current_dts; - if (!sc->sample_count || st->nb_index_entries) + if (!sc->sample_count || st->internal->nb_index_entries) return; - if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries) + if (sc->sample_count >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries) return; - if (av_reallocp_array(&st->index_entries, - st->nb_index_entries + sc->sample_count, - sizeof(*st->index_entries)) < 0) { - st->nb_index_entries = 0; + if (av_reallocp_array(&st->internal->index_entries, + st->internal->nb_index_entries + sc->sample_count, + sizeof(*st->internal->index_entries)) < 0) { + st->internal->nb_index_entries = 0; return; } - st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries); + st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + sc->sample_count) * sizeof(*st->internal->index_entries); if (ctts_data_old) { // Expand ctts entries such that we have a 1-1 mapping with samples @@ -3938,7 +3976,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", sample_size); return; } - e = &st->index_entries[st->nb_index_entries++]; + e = &st->internal->index_entries[st->internal->nb_index_entries++]; e->pos = current_offset; e->timestamp = current_dts; e->size = sample_size; @@ -3947,7 +3985,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", " "size %u, distance %u, keyframe %d\n", st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries < 100) ff_rfps_add_frame(mov->fc, st, current_dts); } @@ -4019,15 +4057,15 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } av_log(mov->fc, AV_LOG_TRACE, "chunk count %u\n", total); - if (total >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries) + if (total >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries) return; - if (av_reallocp_array(&st->index_entries, - st->nb_index_entries + total, - sizeof(*st->index_entries)) < 0) { - st->nb_index_entries = 0; + if (av_reallocp_array(&st->internal->index_entries, + st->internal->nb_index_entries + total, + sizeof(*st->internal->index_entries)) < 0) { + st->internal->nb_index_entries = 0; return; } - st->index_entries_allocated_size = (st->nb_index_entries + total) * sizeof(*st->index_entries); + st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + total) * sizeof(*st->internal->index_entries); // populate index for (i = 0; i < sc->chunk_count; i++) { @@ -4062,7 +4100,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } - if (st->nb_index_entries >= total) { + if (st->internal->nb_index_entries >= total) { av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %u\n", total); return; } @@ -4070,7 +4108,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", size); return; } - e = &st->index_entries[st->nb_index_entries++]; + e = &st->internal->index_entries[st->internal->nb_index_entries++]; e->pos = current_offset; e->timestamp = current_dts; e->size = size; @@ -4093,8 +4131,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } // Update start time of the stream. - if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) { - st->start_time = st->index_entries[0].timestamp + sc->dts_shift; + if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries > 0) { + st->start_time = st->internal->index_entries[0].timestamp + sc->dts_shift; if (sc->ctts_data) { st->start_time += sc->ctts_data[0].duration; } @@ -4397,7 +4435,7 @@ static int mov_read_keys(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_custom(MOVContext *c, AVIOContext *pb, MOVAtom atom) { - int64_t end = avio_tell(pb) + atom.size; + int64_t end = av_sat_add64(avio_tell(pb), atom.size); uint8_t *key = NULL, *val = NULL, *mean = NULL; int i; int ret = 0; @@ -4792,7 +4830,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // A valid index_entry means the trun for the fragment was read // and it's samples are in index_entries at the given position. // New index entries will be inserted before the index_entry found. - index_entry_pos = st->nb_index_entries; + index_entry_pos = st->internal->nb_index_entries; for (i = c->frag_index.current + 1; i < c->frag_index.nb_items; i++) { frag_stream_info = get_frag_stream_info(&c->frag_index, i, frag->track_id); if (frag_stream_info && frag_stream_info->index_entry >= 0) { @@ -4801,7 +4839,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) break; } } - av_assert0(index_entry_pos <= st->nb_index_entries); + av_assert0(index_entry_pos <= st->internal->nb_index_entries); avio_r8(pb); /* version */ flags = avio_rb24(pb); @@ -4852,22 +4890,22 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "first sample flags 0x%x\n", first_sample_flags); // realloc space for new index entries - if((uint64_t)st->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) { - entries = UINT_MAX / sizeof(AVIndexEntry) - st->nb_index_entries; + if((uint64_t)st->internal->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) { + entries = UINT_MAX / sizeof(AVIndexEntry) - st->internal->nb_index_entries; av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n"); } if (entries == 0) return 0; - requested_size = (st->nb_index_entries + entries) * sizeof(AVIndexEntry); - new_entries = av_fast_realloc(st->index_entries, - &st->index_entries_allocated_size, + requested_size = (st->internal->nb_index_entries + entries) * sizeof(AVIndexEntry); + new_entries = av_fast_realloc(st->internal->index_entries, + &st->internal->index_entries_allocated_size, requested_size); if (!new_entries) return AVERROR(ENOMEM); - st->index_entries= new_entries; + st->internal->index_entries= new_entries; - requested_size = (st->nb_index_entries + entries) * sizeof(*sc->ctts_data); + requested_size = (st->internal->nb_index_entries + entries) * sizeof(*sc->ctts_data); old_ctts_allocated_size = sc->ctts_allocated_size; ctts_data = av_fast_realloc(sc->ctts_data, &sc->ctts_allocated_size, requested_size); @@ -4881,12 +4919,12 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) memset((uint8_t*)(sc->ctts_data) + old_ctts_allocated_size, 0, sc->ctts_allocated_size - old_ctts_allocated_size); - if (index_entry_pos < st->nb_index_entries) { + if (index_entry_pos < st->internal->nb_index_entries) { // Make hole in index_entries and ctts_data for new samples - memmove(st->index_entries + index_entry_pos + entries, - st->index_entries + index_entry_pos, - sizeof(*st->index_entries) * - (st->nb_index_entries - index_entry_pos)); + memmove(st->internal->index_entries + index_entry_pos + entries, + st->internal->index_entries + index_entry_pos, + sizeof(*st->internal->index_entries) * + (st->internal->nb_index_entries - index_entry_pos)); memmove(sc->ctts_data + index_entry_pos + entries, sc->ctts_data + index_entry_pos, sizeof(*sc->ctts_data) * (sc->ctts_count - index_entry_pos)); @@ -4895,15 +4933,15 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) } } - st->nb_index_entries += entries; - sc->ctts_count = st->nb_index_entries; + st->internal->nb_index_entries += entries; + sc->ctts_count = st->internal->nb_index_entries; // Record the index_entry position in frag_index of this fragment if (frag_stream_info) frag_stream_info->index_entry = index_entry_pos; if (index_entry_pos > 0) - prev_dts = st->index_entries[index_entry_pos-1].timestamp; + prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp; for (i = 0; i < entries && !pb->eof_reached; i++) { unsigned sample_size = frag->size; @@ -4952,11 +4990,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (prev_dts >= dts) index_entry_flags |= AVINDEX_DISCARD_FRAME; - st->index_entries[index_entry_pos].pos = offset; - st->index_entries[index_entry_pos].timestamp = dts; - st->index_entries[index_entry_pos].size= sample_size; - st->index_entries[index_entry_pos].min_distance= distance; - st->index_entries[index_entry_pos].flags = index_entry_flags; + st->internal->index_entries[index_entry_pos].pos = offset; + st->internal->index_entries[index_entry_pos].timestamp = dts; + st->internal->index_entries[index_entry_pos].size= sample_size; + st->internal->index_entries[index_entry_pos].min_distance= distance; + st->internal->index_entries[index_entry_pos].flags = index_entry_flags; sc->ctts_data[index_entry_pos].count = 1; sc->ctts_data[index_entry_pos].duration = ctts_duration; @@ -4983,16 +5021,16 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // EOF found before reading all entries. Fix the hole this would // leave in index_entries and ctts_data int gap = entries - i; - memmove(st->index_entries + index_entry_pos, - st->index_entries + index_entry_pos + gap, - sizeof(*st->index_entries) * - (st->nb_index_entries - (index_entry_pos + gap))); + memmove(st->internal->index_entries + index_entry_pos, + st->internal->index_entries + index_entry_pos + gap, + sizeof(*st->internal->index_entries) * + (st->internal->nb_index_entries - (index_entry_pos + gap))); memmove(sc->ctts_data + index_entry_pos, sc->ctts_data + index_entry_pos + gap, sizeof(*sc->ctts_data) * (sc->ctts_count - (index_entry_pos + gap))); - st->nb_index_entries -= gap; + st->internal->nb_index_entries -= gap; sc->ctts_count -= gap; if (index_entry_pos < sc->current_sample) { sc->current_sample -= gap; @@ -5005,11 +5043,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // fragment that overlap with AVINDEX_DISCARD_FRAME prev_dts = AV_NOPTS_VALUE; if (index_entry_pos > 0) - prev_dts = st->index_entries[index_entry_pos-1].timestamp; - for (i = index_entry_pos; i < st->nb_index_entries; i++) { - if (prev_dts < st->index_entries[i].timestamp) + prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp; + for (i = index_entry_pos; i < st->internal->nb_index_entries; i++) { + if (prev_dts < st->internal->index_entries[i].timestamp) break; - st->index_entries[i].flags |= AVINDEX_DISCARD_FRAME; + st->internal->index_entries[i].flags |= AVINDEX_DISCARD_FRAME; } // If a hole was created to insert the new index_entries into, @@ -5035,7 +5073,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int64_t stream_size = avio_size(pb); - int64_t offset = avio_tell(pb) + atom.size, pts, timestamp; + int64_t offset = av_sat_add64(avio_tell(pb), atom.size), pts, timestamp; uint8_t version, is_complete; unsigned i, j, track_id, item_count; AVStream *st = NULL; @@ -7195,9 +7233,9 @@ static void mov_read_chapters(AVFormatContext *s) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS; - if (st->nb_index_entries) { + if (st->internal->nb_index_entries) { // Retrieve the first frame, if possible - AVIndexEntry *sample = &st->index_entries[0]; + AVIndexEntry *sample = &st->internal->index_entries[0]; if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { av_log(s, AV_LOG_ERROR, "Failed to retrieve first frame\n"); goto finish; @@ -7213,9 +7251,9 @@ static void mov_read_chapters(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; st->discard = AVDISCARD_ALL; - for (i = 0; i < st->nb_index_entries; i++) { - AVIndexEntry *sample = &st->index_entries[i]; - int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration; + for (i = 0; i < st->internal->nb_index_entries; i++) { + AVIndexEntry *sample = &st->internal->index_entries[i]; + int64_t end = i+1 < st->internal->nb_index_entries ? st->internal->index_entries[i+1].timestamp : st->duration; uint8_t *title; uint16_t ch; int len, title_len; @@ -7288,10 +7326,10 @@ static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st) int64_t cur_pos = avio_tell(sc->pb); int hh, mm, ss, ff, drop; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) return -1; - avio_seek(sc->pb, st->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); avio_skip(s->pb, 13); hh = avio_r8(s->pb); mm = avio_r8(s->pb); @@ -7313,10 +7351,10 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) int64_t cur_pos = avio_tell(sc->pb); uint32_t value; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) return -1; - avio_seek(sc->pb, st->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); value = avio_rb32(s->pb); if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME; @@ -7552,6 +7590,7 @@ static int mov_read_mfra(MOVContext *c, AVIOContext *f) goto fail; } while (!ret); ret = 0; + c->frag_index.complete = 1; fail: seek_ret = avio_seek(f, original_pos, SEEK_SET); if (seek_ret < 0) { @@ -7638,7 +7677,7 @@ static int mov_read_header(AVFormatContext *s) fix_timescale(mov, sc); if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id == AV_CODEC_ID_AAC) { - st->skip_samples = sc->start_pad; + st->internal->skip_samples = sc->start_pad; } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sc->nb_frames_for_fps > 0 && sc->duration_for_fps > 0) av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, @@ -7780,8 +7819,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; MOVStreamContext *msc = avst->priv_data; - if (msc->pb && msc->current_sample < avst->nb_index_entries) { - AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample]; + if (msc->pb && msc->current_sample < avst->internal->nb_index_entries) { + AVIndexEntry *current_sample = &avst->internal->index_entries[msc->current_sample]; int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) || @@ -7984,8 +8023,8 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) sc->ctts_sample = 0; } } else { - int64_t next_dts = (sc->current_sample < st->nb_index_entries) ? - st->index_entries[sc->current_sample].timestamp : st->duration; + int64_t next_dts = (sc->current_sample < st->internal->nb_index_entries) ? + st->internal->index_entries[sc->current_sample].timestamp : st->duration; if (next_dts >= pkt->dts) pkt->duration = next_dts - pkt->dts; @@ -8066,7 +8105,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); - if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) + if (sample < 0 && st->internal->nb_index_entries && timestamp < st->internal->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; @@ -8121,13 +8160,13 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti if (mc->seek_individually) { /* adjust seek timestamp to found sample timestamp */ - int64_t seek_timestamp = st->index_entries[sample].timestamp; + int64_t seek_timestamp = st->internal->index_entries[sample].timestamp; for (i = 0; i < s->nb_streams; i++) { int64_t timestamp; MOVStreamContext *sc = s->streams[i]->priv_data; st = s->streams[i]; - st->skip_samples = (sample_time <= 0) ? sc->start_pad : 0; + st->internal->skip_samples = (sample_time <= 0) ? sc->start_pad : 0; if (stream_index == i) continue; @@ -8192,6 +8231,10 @@ static const AVOption mov_options[] = { AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS }, { "activation_bytes", "Secret bytes for Audible AAX files", OFFSET(activation_bytes), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, + { "audible_key", "AES-128 Key for Audible AAXC files", OFFSET(audible_key), + AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, + { "audible_iv", "AES-128 IV for Audible AAXC files", OFFSET(audible_iv), + AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, { "audible_fixed_key", // extracted from libAAX_SDK.so and AAXSDKWin.dll files! "Fixed key used for handling Audible AAX files", OFFSET(audible_fixed_key), AV_OPT_TYPE_BINARY, {.str="77214d4b196a87cd520045fd20a51d67"}, diff --git a/chromium/third_party/ffmpeg/libavformat/movenc.c b/chromium/third_party/ffmpeg/libavformat/movenc.c index 265465f97b8..18fa3f9b5e9 100644 --- a/chromium/third_party/ffmpeg/libavformat/movenc.c +++ b/chromium/third_party/ffmpeg/libavformat/movenc.c @@ -641,10 +641,11 @@ struct mpeg4_bit_rate_values { static struct mpeg4_bit_rate_values calculate_mpeg4_bit_rates(MOVTrack *track) { - AVCPBProperties *props = + AVCPBProperties *props = track->st ? (AVCPBProperties*)av_stream_get_side_data(track->st, AV_PKT_DATA_CPB_PROPERTIES, - NULL); + NULL) : + NULL; struct mpeg4_bit_rate_values bit_rates = { 0 }; bit_rates.avg_bit_rate = compute_avg_bitrate(track); @@ -1652,6 +1653,10 @@ static unsigned int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) { unsigned int tag = track->par->codec_tag; + // "rtp " is used to distinguish internally created RTP-hint tracks + // (with rtp_ctx) from other tracks. + if (tag == MKTAG('r','t','p',' ')) + tag = 0; if (!tag || (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL && (track->par->codec_id == AV_CODEC_ID_DVVIDEO || track->par->codec_id == AV_CODEC_ID_RAWVIDEO || @@ -6160,11 +6165,12 @@ static int mov_check_timecode_track(AVFormatContext *s, AVTimecode *tc, int src_ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_index, AVTimecode tc) { - int ret; MOVMuxContext *mov = s->priv_data; MOVTrack *track = &mov->tracks[index]; AVStream *src_st = s->streams[src_index]; - AVPacket pkt = {.stream_index = index, .flags = AV_PKT_FLAG_KEY, .size = 4}; + uint8_t data[4]; + AVPacket pkt = { .data = data, .stream_index = index, + .flags = AV_PKT_FLAG_KEY, .size = 4 }; AVRational rate = find_fps(s, src_st); /* tmcd track based on video stream */ @@ -6187,13 +6193,8 @@ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde track->st->avg_frame_rate = av_inv_q(rate); /* the tmcd track just contains one packet with the frame number */ - pkt.data = av_malloc(pkt.size); - if (!pkt.data) - return AVERROR(ENOMEM); AV_WB32(pkt.data, tc.start); - ret = ff_mov_write_packet(s, &pkt); - av_free(pkt.data); - return ret; + return ff_mov_write_packet(s, &pkt); } /* @@ -6258,9 +6259,7 @@ static void mov_free(AVFormatContext *s) return; if (mov->chapter_track) { - if (mov->tracks[mov->chapter_track].par) - av_freep(&mov->tracks[mov->chapter_track].par->extradata); - av_freep(&mov->tracks[mov->chapter_track].par); + avcodec_parameters_free(&mov->tracks[mov->chapter_track].par); } for (i = 0; i < mov->nb_streams; i++) { @@ -6281,9 +6280,11 @@ static void mov_free(AVFormatContext *s) av_freep(&mov->tracks[i].vos_data); ff_mov_cenc_free(&mov->tracks[i].cenc); + ffio_free_dyn_buf(&mov->tracks[i].mdat_buf); } av_freep(&mov->tracks); + ffio_free_dyn_buf(&mov->mdat_buf); } static uint32_t rgb_to_yuv(uint32_t rgb) @@ -6980,6 +6981,7 @@ static int mov_write_trailer(AVFormatContext *s) AVCodecParameters *par = track->par; track->vos_len = par->extradata_size; + av_freep(&track->vos_data); track->vos_data = av_malloc(track->vos_len + AV_INPUT_BUFFER_PADDING_SIZE); if (!track->vos_data) return AVERROR(ENOMEM); @@ -7109,7 +7111,7 @@ static const AVCodecTag codec_3gp_tags[] = { { AV_CODEC_ID_NONE, 0 }, }; -const AVCodecTag codec_mp4_tags[] = { +static const AVCodecTag codec_mp4_tags[] = { { AV_CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') }, { AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, { AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '3') }, @@ -7126,6 +7128,7 @@ const AVCodecTag codec_mp4_tags[] = { { AV_CODEC_ID_VP9, MKTAG('v', 'p', '0', '9') }, { AV_CODEC_ID_AV1, MKTAG('a', 'v', '0', '1') }, { AV_CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, + { AV_CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, { AV_CODEC_ID_MP4ALS, MKTAG('m', 'p', '4', 'a') }, { AV_CODEC_ID_MP3, MKTAG('m', 'p', '4', 'a') }, { AV_CODEC_ID_MP2, MKTAG('m', 'p', '4', 'a') }, @@ -7145,7 +7148,7 @@ const AVCodecTag codec_mp4_tags[] = { { AV_CODEC_ID_NONE, 0 }, }; -const AVCodecTag codec_ism_tags[] = { +static const AVCodecTag codec_ism_tags[] = { { AV_CODEC_ID_WMAPRO , MKTAG('w', 'm', 'a', ' ') }, { AV_CODEC_ID_NONE , 0 }, }; diff --git a/chromium/third_party/ffmpeg/libavformat/mp3dec.c b/chromium/third_party/ffmpeg/libavformat/mp3dec.c index 958f77ce286..fe056a4c5d3 100644 --- a/chromium/third_party/ffmpeg/libavformat/mp3dec.c +++ b/chromium/third_party/ffmpeg/libavformat/mp3dec.c @@ -255,17 +255,17 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; - st->start_skip_samples = mp3->start_pad + 528 + 1; + st->internal->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { - st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; - st->last_discard_sample = mp3->frames * (int64_t)spf; + st->internal->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; + st->internal->last_discard_sample = mp3->frames * (int64_t)spf; } // TODO(dalecurtis): Chrome expects to handle this start time change // itself, instead of ffmpeg magically moving the start time into // the future. // // if (!st->start_time) - // st->start_time = av_rescale_q(st->start_skip_samples, + // st->start_time = av_rescale_q(st->internal->start_skip_samples, // (AVRational){1, c->sample_rate}, // st->time_base); av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3-> end_pad); @@ -440,8 +440,8 @@ static int mp3_read_header(AVFormatContext *s) } // the seek index is relative to the end of the xing vbr headers - for (i = 0; i < st->nb_index_entries; i++) - st->index_entries[i].pos += avio_tell(s->pb); + for (i = 0; i < st->internal->nb_index_entries; i++) + st->internal->index_entries[i].pos += avio_tell(s->pb); /* the parameters will be extracted from the compressed bitstream */ return 0; @@ -576,7 +576,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, if (ret < 0) return ret; - ie = &st->index_entries[ret]; + ie = &st->internal->index_entries[ret]; } else if (fast_seek && st->duration > 0 && filesize > 0) { if (!mp3->is_cbr) av_log(s, AV_LOG_WARNING, "Using scaling to seek VBR MP3; may be imprecise.\n"); diff --git a/chromium/third_party/ffmpeg/libavformat/mpc.c b/chromium/third_party/ffmpeg/libavformat/mpc.c index 6a94b5d1d03..31a2072406f 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpc.c +++ b/chromium/third_party/ffmpeg/libavformat/mpc.c @@ -194,8 +194,8 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp uint32_t lastframe; /* if found, seek there */ - if (index >= 0 && st->index_entries[st->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){ - c->curframe = st->index_entries[index].pos; + if (index >= 0 && st->internal->index_entries[st->internal->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){ + c->curframe = st->internal->index_entries[index].pos; return 0; } /* if timestamp is out of bounds, return error */ diff --git a/chromium/third_party/ffmpeg/libavformat/mpc8.c b/chromium/third_party/ffmpeg/libavformat/mpc8.c index dd13bbd0a49..447a8d4fdff 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpc8.c +++ b/chromium/third_party/ffmpeg/libavformat/mpc8.c @@ -178,12 +178,16 @@ static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) av_add_index_entry(s->streams[0], pos, i, 0, 0, AVINDEX_KEYFRAME); } for(; i < size; i++){ + if (get_bits_left(&gb) < 13) { + av_free(buf); + return; + } t = get_unary(&gb, 1, 33) << 12; t += get_bits(&gb, 12); if(t & 1) t = -(t & ~1); - pos = (t >> 1) + ppos[0]*2 - ppos[1]; - av_add_index_entry(s->streams[0], pos, i << seekd, 0, 0, AVINDEX_KEYFRAME); + pos = (t >> 1) + (uint64_t)ppos[0]*2 - ppos[1]; + av_add_index_entry(s->streams[0], pos, (int64_t)i << seekd, 0, 0, AVINDEX_KEYFRAME); ppos[1] = ppos[0]; ppos[0] = pos; } @@ -258,7 +262,7 @@ static int mpc8_read_header(AVFormatContext *s) st->codecpar->channels = (st->codecpar->extradata[1] >> 4) + 1; st->codecpar->sample_rate = mpc8_rate[st->codecpar->extradata[0] >> 5]; - avpriv_set_pts_info(st, 32, 1152 << (st->codecpar->extradata[1]&3)*2, st->codecpar->sample_rate); + avpriv_set_pts_info(st, 64, 1152 << (st->codecpar->extradata[1]&3)*2, st->codecpar->sample_rate); st->start_time = 0; st->duration = c->samples / (1152 << (st->codecpar->extradata[1]&3)*2); size -= avio_tell(pb) - pos; @@ -310,9 +314,9 @@ static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestam int index = av_index_search_timestamp(st, timestamp, flags); if(index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - ff_update_cur_dts(s, st, st->index_entries[index].timestamp); + ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp); return 0; } diff --git a/chromium/third_party/ffmpeg/libavformat/mpeg.c b/chromium/third_party/ffmpeg/libavformat/mpeg.c index a5e17925ce6..20d1e101684 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpeg.c +++ b/chromium/third_party/ffmpeg/libavformat/mpeg.c @@ -622,7 +622,7 @@ skip: st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; st->codecpar->sample_rate = 8000; } - st->request_probe = request_probe; + st->internal->request_probe = request_probe; st->need_parsing = AVSTREAM_PARSE_FULL; found: diff --git a/chromium/third_party/ffmpeg/libavformat/mpegts.c b/chromium/third_party/ffmpeg/libavformat/mpegts.c index 50d4d5e9bc6..7549fc91c93 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpegts.c +++ b/chromium/third_party/ffmpeg/libavformat/mpegts.c @@ -609,8 +609,9 @@ static int get_packet_size(AVFormatContext* s) /*init buffer to store stream for probing */ uint8_t buf[PROBE_PACKET_MAX_BUF] = {0}; int buf_size = 0; + int max_iterations = 16; - while (buf_size < PROBE_PACKET_MAX_BUF) { + while (buf_size < PROBE_PACKET_MAX_BUF && max_iterations--) { ret = avio_read_partial(s->pb, buf + buf_size, PROBE_PACKET_MAX_BUF - buf_size); if (ret < 0) return AVERROR_INVALIDDATA; @@ -882,7 +883,7 @@ static void mpegts_find_stream_type(AVStream *st, st->codecpar->codec_id = types->codec_id; st->internal->need_context_update = 1; } - st->request_probe = 0; + st->internal->request_probe = 0; return; } } @@ -915,7 +916,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, mpegts_find_stream_type(st, pes->stream_type, ISO_types); if (pes->stream_type == 4 || pes->stream_type == 0x0f) - st->request_probe = 50; + st->internal->request_probe = 50; if ((prog_reg_desc == AV_RL32("HDMV") || prog_reg_desc == AV_RL32("HDPR")) && st->codecpar->codec_id == AV_CODEC_ID_NONE) { @@ -952,12 +953,12 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, st->codecpar->codec_type = old_codec_type; } if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || - (st->request_probe > 0 && st->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && + (st->internal->request_probe > 0 && st->internal->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && st->probe_packets > 0 && stream_type == STREAM_TYPE_PRIVATE_DATA) { st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; - st->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; + st->internal->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; } /* queue a context update if properties changed */ @@ -1198,12 +1199,12 @@ static int mpegts_push_data(MpegTSFilter *filter, code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ pes->state = MPEGTS_PESHEADER; - if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) { + if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes->st->internal->request_probe) { av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_type=%x probing\n", pes->pid, pes->stream_type); - pes->st->request_probe = 1; + pes->st->internal->request_probe = 1; } } else { pes->pes_header_size = 6; @@ -1325,8 +1326,8 @@ skip: int64_t pcr = f->last_pcr / 300; pcr_found = 1; if (st) { - pes->st->pts_wrap_reference = st->pts_wrap_reference; - pes->st->pts_wrap_behavior = st->pts_wrap_behavior; + pes->st->internal->pts_wrap_reference = st->internal->pts_wrap_reference; + pes->st->internal->pts_wrap_behavior = st->internal->pts_wrap_behavior; } if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) { pes->pts = pes->dts = pcr; @@ -1799,17 +1800,17 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type av_log(fc, AV_LOG_TRACE, "tag: 0x%02x len=%d\n", desc_tag, desc_len); - if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) && + if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || st->internal->request_probe > 0) && stream_type == STREAM_TYPE_PRIVATE_DATA) mpegts_find_stream_type(st, desc_tag, DESC_types); switch (desc_tag) { - case 0x02: /* video stream descriptor */ + case VIDEO_STREAM_DESCRIPTOR: if (get8(pp, desc_end) & 0x1) { st->disposition |= AV_DISPOSITION_STILL_IMAGE; } break; - case 0x1E: /* SL descriptor */ + case SL_DESCRIPTOR: desc_es_id = get16(pp, desc_end); if (desc_es_id < 0) break; @@ -1832,13 +1833,13 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1); } break; - case 0x1F: /* FMC descriptor */ + case FMC_DESCRIPTOR: if (get16(pp, desc_end) < 0) break; if (mp4_descr_count > 0 && (st->codecpar->codec_id == AV_CODEC_ID_AAC_LATM || - (st->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || - st->request_probe > 0) && + (st->internal->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || + st->internal->request_probe > 0) && mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) { AVIOContext pb; ffio_init_context(&pb, mp4_descr->dec_config_descr, @@ -1847,7 +1848,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type ff_mp4_read_dec_config_descr(fc, st, &pb); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { - st->request_probe = st->need_parsing = 0; + st->internal->request_probe = st->need_parsing = 0; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->internal->need_context_update = 1; } @@ -1958,7 +1959,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type } } break; - case 0x0a: /* ISO 639 language descriptor */ + case ISO_639_LANGUAGE_DESCRIPTOR: for (i = 0; i + 4 <= desc_len; i += 4) { language[i + 0] = get8(pp, desc_end); language[i + 1] = get8(pp, desc_end); @@ -1984,19 +1985,19 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type av_dict_set(&st->metadata, "language", language, AV_DICT_DONT_OVERWRITE); } break; - case 0x05: /* registration descriptor */ + case REGISTRATION_DESCRIPTOR: st->codecpar->codec_tag = bytestream_get_le32(pp); av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codecpar->codec_tag); - if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->internal->request_probe > 0) { mpegts_find_stream_type(st, st->codecpar->codec_tag, REGD_types); if (st->codecpar->codec_tag == MKTAG('B', 'S', 'S', 'D')) - st->request_probe = 50; + st->internal->request_probe = 50; } break; case 0x52: /* stream identifier descriptor */ st->stream_identifier = 1 + get8(pp, desc_end); break; - case 0x26: /* metadata descriptor */ + case METADATA_DESCRIPTOR: if (get16(pp, desc_end) == 0xFFFF) *pp += 4; if (get8(pp, desc_end) == 0xFF) { @@ -2143,7 +2144,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_ARIB_CAPTION; st->codecpar->profile = picked_profile; - st->request_probe = 0; + st->internal->request_probe = 0; } break; case 0xb0: /* DOVI video stream descriptor */ @@ -2338,13 +2339,13 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len // something else is broken, exit the program_descriptors_loop break; program_info_length -= len + 2; - if (tag == 0x1d) { // IOD descriptor + if (tag == IOD_DESCRIPTOR) { get8(&p, p_end); // scope get8(&p, p_end); // label len -= 2; mp4_read_iods(ts->stream, p, len, mp4_descr + mp4_descr_count, &mp4_descr_count, MAX_MP4_DESCR_COUNT); - } else if (tag == 0x05 && len >= 4) { // registration descriptor + } else if (tag == REGISTRATION_DESCRIPTOR && len >= 4) { prog_reg_desc = bytestream_get_le32(&p); len -= 4; } @@ -2355,7 +2356,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len goto out; // stop parsing after pmt, we found header - if (!ts->stream->nb_streams) + if (!ts->pkt) ts->stop_parse = 2; set_pmt_found(ts, h->id); @@ -3051,10 +3052,11 @@ static int mpegts_read_header(AVFormatContext *s) MpegTSContext *ts = s->priv_data; AVIOContext *pb = s->pb; int64_t pos, probesize = s->probesize; + int64_t seekback = FFMAX(s->probesize, (int64_t)ts->resync_size + PROBE_PACKET_MAX_BUF); s->internal->prefer_codec_framerate = 1; - if (ffio_ensure_seekback(pb, probesize) < 0) + if (ffio_ensure_seekback(pb, seekback) < 0) av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n"); pos = avio_tell(pb); @@ -3168,7 +3170,7 @@ static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; } if (data != pkt->data) - memcpy(pkt->data, data, ts->raw_packet_size); + memcpy(pkt->data, data, TS_PACKET_SIZE); finished_reading_packet(s, ts->raw_packet_size); if (ts->mpeg2ts_compute_pcr) { /* compute exact PCR for each packet */ diff --git a/chromium/third_party/ffmpeg/libavformat/mpegts.h b/chromium/third_party/ffmpeg/libavformat/mpegts.h index d70b25d0181..04874e0f421 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpegts.h +++ b/chromium/third_party/ffmpeg/libavformat/mpegts.h @@ -144,6 +144,16 @@ #define STREAM_ID_METADATA_STREAM 0xfc #define STREAM_ID_EXTENDED_STREAM_ID 0xfd +/* ISO/IEC 13818-1 Table 2-45 */ +#define VIDEO_STREAM_DESCRIPTOR 0x02 +#define REGISTRATION_DESCRIPTOR 0x05 +#define ISO_639_LANGUAGE_DESCRIPTOR 0x0a +#define IOD_DESCRIPTOR 0x1d +#define SL_DESCRIPTOR 0x1e +#define FMC_DESCRIPTOR 0x1f +#define METADATA_DESCRIPTOR 0x26 +#define METADATA_STD_DESCRIPTOR 0x27 + typedef struct MpegTSContext MpegTSContext; MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext *s); diff --git a/chromium/third_party/ffmpeg/libavformat/mpegtsenc.c b/chromium/third_party/ffmpeg/libavformat/mpegtsenc.c index 1687de74adf..45f8d5f3733 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpegtsenc.c +++ b/chromium/third_party/ffmpeg/libavformat/mpegtsenc.c @@ -81,9 +81,11 @@ typedef struct MpegTSWrite { int64_t pat_period; /* PAT/PMT period in PCR time base */ int nb_services; int64_t first_pcr; + int first_dts_checked; int64_t next_pcr; int mux_rate; ///< set to 1 when VBR int pes_payload_size; + int64_t total_size; int transport_stream_id; int original_network_id; @@ -230,7 +232,7 @@ typedef struct MpegTSWriteStream { int cc; int discontinuity; int payload_size; - int first_pts_check; ///< first pts check needed + int first_timestamp_checked; ///< first pts/dts check needed int prev_payload_key; int64_t payload_pts; int64_t payload_dts; @@ -275,7 +277,7 @@ static void putbuf(uint8_t **q_ptr, const uint8_t *buf, size_t len) static void put_registration_descriptor(uint8_t **q_ptr, uint32_t tag) { uint8_t *q = *q_ptr; - *q++ = 0x05; /* MPEG-2 registration descriptor*/ + *q++ = REGISTRATION_DESCRIPTOR; *q++ = 4; *q++ = tag; *q++ = tag >> 8; @@ -600,7 +602,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) char *next = lang->value; uint8_t *len_ptr; - *q++ = 0x0a; /* ISO 639 language descriptor */ + *q++ = ISO_639_LANGUAGE_DESCRIPTOR; len_ptr = q++; *len_ptr = 0; @@ -728,7 +730,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) put_registration_descriptor(&q, MKTAG('K', 'L', 'V', 'A')); } else if (codec_id == AV_CODEC_ID_TIMED_ID3) { const char *tag = "ID3 "; - *q++ = 0x26; /* metadata descriptor */ + *q++ = METADATA_DESCRIPTOR; *q++ = 13; put16(&q, 0xffff); /* metadata application format */ putbuf(&q, tag, strlen(tag)); @@ -830,9 +832,9 @@ invalid: return 0; } -static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb) +static int64_t get_pcr(const MpegTSWrite *ts) { - return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) + + return av_rescale(ts->total_size + 11, 8 * PCR_TIME_BASE, ts->mux_rate) + ts->first_pcr; } @@ -840,13 +842,14 @@ static void write_packet(AVFormatContext *s, const uint8_t *packet) { MpegTSWrite *ts = s->priv_data; if (ts->m2ts_mode) { - int64_t pcr = get_pcr(s->priv_data, s->pb); + int64_t pcr = get_pcr(s->priv_data); uint32_t tp_extra_header = pcr % 0x3fffffff; tp_extra_header = AV_RB32(&tp_extra_header); avio_write(s->pb, (unsigned char *) &tp_extra_header, sizeof(tp_extra_header)); } avio_write(s->pb, packet, TS_PACKET_SIZE); + ts->total_size += TS_PACKET_SIZE; } static void section_write_packet(MpegTSSection *s, const uint8_t *packet) @@ -1098,7 +1101,6 @@ static int mpegts_init(AVFormatContext *s) } ts_st->payload_pts = AV_NOPTS_VALUE; ts_st->payload_dts = AV_NOPTS_VALUE; - ts_st->first_pts_check = 1; ts_st->cc = 15; ts_st->discontinuity = ts->flags & MPEGTS_FLAG_DISCONT; if (st->codecpar->codec_id == AV_CODEC_ID_AAC && @@ -1228,7 +1230,7 @@ static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st) } /* PCR coded into 6 bytes */ - q += write_pcr_bits(q, get_pcr(ts, s->pb)); + q += write_pcr_bits(q, get_pcr(ts)); /* stuffing bytes */ memset(q, 0xFF, TS_PACKET_SIZE - (q - buf)); @@ -1315,7 +1317,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, while (payload_size > 0) { int64_t pcr = AV_NOPTS_VALUE; if (ts->mux_rate > 1) - pcr = get_pcr(ts, s->pb); + pcr = get_pcr(ts); else if (dts != AV_NOPTS_VALUE) pcr = (dts - delay) * 300; @@ -1326,7 +1328,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, write_pcr = 0; if (ts->mux_rate > 1) { /* Send PCR packets for all PCR streams if needed */ - pcr = get_pcr(ts, s->pb); + pcr = get_pcr(ts); if (pcr >= ts->next_pcr) { int64_t next_pcr = INT64_MAX; for (int i = 0; i < s->nb_streams; i++) { @@ -1340,7 +1342,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, ts_st2->last_pcr = FFMAX(pcr - ts_st2->pcr_period, ts_st2->last_pcr + ts_st2->pcr_period); if (st2 != st) { mpegts_insert_pcr_only(s, st2); - pcr = get_pcr(ts, s->pb); + pcr = get_pcr(ts); } else { write_pcr = 1; } @@ -1686,17 +1688,22 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) stream_id = side_data[0]; if (ts->copyts < 1) { + if (!ts->first_dts_checked && dts != AV_NOPTS_VALUE) { + ts->first_pcr += dts * 300; + ts->first_dts_checked = 1; + } + if (pts != AV_NOPTS_VALUE) pts += delay; if (dts != AV_NOPTS_VALUE) dts += delay; } - if (ts_st->first_pts_check && pts == AV_NOPTS_VALUE) { - av_log(s, AV_LOG_ERROR, "first pts value must be set\n"); + if (!ts_st->first_timestamp_checked && (pts == AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE)) { + av_log(s, AV_LOG_ERROR, "first pts and dts value must be set\n"); return AVERROR_INVALIDDATA; } - ts_st->first_pts_check = 0; + ts_st->first_timestamp_checked = 1; if (st->codecpar->codec_id == AV_CODEC_ID_H264) { const uint8_t *p = buf, *buf_end = p + size; diff --git a/chromium/third_party/ffmpeg/libavformat/mpjpegdec.c b/chromium/third_party/ffmpeg/libavformat/mpjpegdec.c index df2880412d1..5fe00fd162d 100644 --- a/chromium/third_party/ffmpeg/libavformat/mpjpegdec.c +++ b/chromium/third_party/ffmpeg/libavformat/mpjpegdec.c @@ -328,18 +328,18 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); } else { /* no size was given -- we read until the next boundary or end-of-file */ - int remaining = 0, len; + int len; const int read_chunk = 2048; pkt->pos = avio_tell(s->pb); - while ((ret = ffio_ensure_seekback(s->pb, read_chunk - remaining)) >= 0 && /* we may need to return as much as all we've read back to the buffer */ - (ret = av_append_packet(s->pb, pkt, read_chunk - remaining)) >= 0) { + while ((ret = ffio_ensure_seekback(s->pb, read_chunk)) >= 0 && /* we may need to return as much as all we've read back to the buffer */ + (ret = av_append_packet(s->pb, pkt, read_chunk)) >= 0) { /* scan the new data */ char *start; - len = ret + remaining; + len = ret; start = pkt->data + pkt->size - len; do { if (!memcmp(start, mpjpeg->searchstr, mpjpeg->searchstr_len)) { @@ -351,7 +351,8 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) len--; start++; } while (len >= mpjpeg->searchstr_len); - remaining = len; + avio_seek(s->pb, -len, SEEK_CUR); + pkt->size -= len; } /* error or EOF occurred */ diff --git a/chromium/third_party/ffmpeg/libavformat/mspdec.c b/chromium/third_party/ffmpeg/libavformat/mspdec.c new file mode 100644 index 00000000000..b81d835a638 --- /dev/null +++ b/chromium/third_party/ffmpeg/libavformat/mspdec.c @@ -0,0 +1,116 @@ +/* + * Microsoft Paint (MSP) demuxer + * Copyright (c) 2020 Peter Ross (pross@xvid.org) + * + * 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 + * Microsoft Paint (MSP) demuxer + */ + +#include "libavutil/intreadwrite.h" +#include "libavutil/imgutils.h" +#include "avformat.h" +#include "internal.h" + +typedef struct { + int packet_size; +} MSPContext; + +static int msp_probe(const AVProbeData *p) +{ + unsigned int i, sum; + + if (p->buf_size <= 32 || (memcmp(p->buf, "DanM", 4) && memcmp(p->buf, "LinS", 4))) + return 0; + + sum = 0; + for (i = 0; i < 24; i += 2) + sum ^= AV_RL16(p->buf + i); + + return AV_RL16(p->buf + 24) == sum ? AVPROBE_SCORE_MAX : 0; +} + +static int msp_read_header(AVFormatContext *s) +{ + MSPContext * cntx = s->priv_data; + AVIOContext *pb = s->pb; + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = avio_rl32(pb) == MKTAG('D', 'a', 'n', 'M') ? AV_CODEC_ID_RAWVIDEO : AV_CODEC_ID_MSP2; + + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); + st->codecpar->format = AV_PIX_FMT_MONOBLACK; + + st->sample_aspect_ratio.num = avio_rl16(pb); + st->sample_aspect_ratio.den = avio_rl16(pb); + avio_skip(pb, 20); + + if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { + cntx->packet_size = av_image_get_buffer_size(st->codecpar->format, st->codecpar->width, st->codecpar->height, 1); + if (cntx->packet_size < 0) + return cntx->packet_size; + } else + cntx->packet_size = 2 * st->codecpar->height; + + return 0; +} + +static int msp_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVStream *st = s->streams[0]; + MSPContext *cntx = s->priv_data; + int ret; + + ret = av_get_packet(s->pb, pkt, cntx->packet_size); + if (ret < 0) + return ret; + + if (st->codecpar->codec_id == AV_CODEC_ID_MSP2) { + unsigned int size, i; + if (pkt->size != 2 * st->codecpar->height) + return AVERROR_INVALIDDATA; + size = 0; + for (i = 0; i < st->codecpar->height; i++) + size += AV_RL16(&pkt->data[i * 2]); + ret = av_append_packet(s->pb, pkt, size); + if (ret < 0) + return ret; + } + + pkt->stream_index = 0; + pkt->flags |= AV_PKT_FLAG_KEY; + return 0; +} + +AVInputFormat ff_msp_demuxer = { + .name = "msp", + .long_name = NULL_IF_CONFIG_SMALL("Microsoft Paint (MSP))"), + .read_probe = msp_probe, + .read_header = msp_read_header, + .read_packet = msp_read_packet, + .flags = AVFMT_NOTIMESTAMPS, + .priv_data_size = sizeof(MSPContext), +}; diff --git a/chromium/third_party/ffmpeg/libavformat/mux.c b/chromium/third_party/ffmpeg/libavformat/mux.c index 44d5e5d1c0b..84c56ac6bab 100644 --- a/chromium/third_party/ffmpeg/libavformat/mux.c +++ b/chromium/third_party/ffmpeg/libavformat/mux.c @@ -546,7 +546,7 @@ FF_DISABLE_DEPRECATION_WARNINGS static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { int delay = FFMAX(st->codecpar->video_delay, st->internal->avctx->max_b_frames > 0); - int num, den, i; + int i; int frame_size; if (!s->internal->missing_ts_warning && @@ -564,20 +564,6 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * av_log(s, AV_LOG_DEBUG, "compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n", av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index); - if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) { - av_log(s, AV_LOG_WARNING, "Packet with invalid duration %"PRId64" in stream %d\n", - pkt->duration, pkt->stream_index); - pkt->duration = 0; - } - - /* duration field */ - if (pkt->duration == 0) { - ff_compute_frame_duration(s, &num, &den, st, NULL, pkt); - if (den && num) { - pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num); - } - } - if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0) pkt->pts = pkt->dts; @@ -595,13 +581,13 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * //calculate dts from pts if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - st->pts_buffer[0] = pkt->pts; - for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++) - st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; - for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]); + st->internal->pts_buffer[0] = pkt->pts; + for (i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) + st->internal->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; + for (i = 0; i<delay && st->internal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); - pkt->dts = st->pts_buffer[0]; + pkt->dts = st->internal->pts_buffer[0]; } if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && @@ -652,6 +638,37 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * FF_ENABLE_DEPRECATION_WARNINGS #endif +static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt) +{ + if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) { + av_log(s, AV_LOG_WARNING, "Packet with invalid duration %"PRId64" in stream %d\n", + pkt->duration, pkt->stream_index); + pkt->duration = 0; + } + + if (pkt->duration) + return; + + switch (st->codecpar->codec_type) { + case AVMEDIA_TYPE_VIDEO: + if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) { + pkt->duration = av_rescale_q(1, av_inv_q(st->avg_frame_rate), + st->time_base); + } else if (st->time_base.num * 1000LL > st->time_base.den) + pkt->duration = 1; + break; + case AVMEDIA_TYPE_AUDIO: { + int frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); + if (frame_size && st->codecpar->sample_rate) { + pkt->duration = av_rescale_q(frame_size, + (AVRational){1, st->codecpar->sample_rate}, + st->time_base); + } + break; + } + } +} + /** * Shift timestamps and call muxer; the original pts/dts are not kept. * @@ -678,7 +695,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (s->avoid_negative_ts > 0) { AVStream *st = s->streams[pkt->stream_index]; - int64_t offset = st->mux_ts_offset; + int64_t offset = st->internal->mux_ts_offset; int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && @@ -688,7 +705,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->internal->offset != AV_NOPTS_VALUE && !offset) { - offset = st->mux_ts_offset = + offset = st->internal->mux_ts_offset = av_rescale_q_rnd(s->internal->offset, s->internal->offset_timebase, st->time_base, @@ -831,27 +848,27 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, av_packet_move_ref(&this_pktl->pkt, pkt); pkt = &this_pktl->pkt; - if (st->last_in_packet_buffer) { - next_point = &(st->last_in_packet_buffer->next); + if (st->internal->last_in_packet_buffer) { + next_point = &(st->internal->last_in_packet_buffer->next); } else { next_point = &s->internal->packet_buffer; } if (chunked) { uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP); - st->interleaver_chunk_size += pkt->size; - st->interleaver_chunk_duration += pkt->duration; - if ( (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size) - || (max && st->interleaver_chunk_duration > max)) { - st->interleaver_chunk_size = 0; + st->internal->interleaver_chunk_size += pkt->size; + st->internal->interleaver_chunk_duration += pkt->duration; + if ( (s->max_chunk_size && st->internal->interleaver_chunk_size > s->max_chunk_size) + || (max && st->internal->interleaver_chunk_duration > max)) { + st->internal->interleaver_chunk_size = 0; pkt->flags |= CHUNK_START; - if (max && st->interleaver_chunk_duration > max) { + if (max && st->internal->interleaver_chunk_duration > max) { int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2; int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset; - st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; + st->internal->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; } else - st->interleaver_chunk_duration = 0; + st->internal->interleaver_chunk_duration = 0; } } if (*next_point) { @@ -876,7 +893,7 @@ next_non_null: this_pktl->next = *next_point; - st->last_in_packet_buffer = *next_point = this_pktl; + st->internal->last_in_packet_buffer = *next_point = this_pktl; return 0; } @@ -926,7 +943,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } for (i = 0; i < s->nb_streams; i++) { - if (s->streams[i]->last_in_packet_buffer) { + if (s->streams[i]->internal->last_in_packet_buffer) { ++stream_count; } else if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && s->streams[i]->codecpar->codec_id != AV_CODEC_ID_VP8 && @@ -951,7 +968,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, for (i = 0; i < s->nb_streams; i++) { int64_t last_dts; - const AVPacketList *last = s->streams[i]->last_in_packet_buffer; + const AVPacketList *last = s->streams[i]->internal->last_in_packet_buffer; if (!last) continue; @@ -1000,8 +1017,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->last_in_packet_buffer == pktl) - st->last_in_packet_buffer = NULL; + if (st->internal->last_in_packet_buffer == pktl) + st->internal->last_in_packet_buffer = NULL; av_packet_unref(&pktl->pkt); av_freep(&pktl); @@ -1019,8 +1036,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->last_in_packet_buffer == pktl) - st->last_in_packet_buffer = NULL; + if (st->internal->last_in_packet_buffer == pktl) + st->internal->last_in_packet_buffer = NULL; av_freep(&pktl); return 1; @@ -1038,7 +1055,7 @@ int ff_interleaved_peek(AVFormatContext *s, int stream, *pkt = pktl->pkt; if (add_offset) { AVStream *st = s->streams[pkt->stream_index]; - int64_t offset = st->mux_ts_offset; + int64_t offset = st->internal->mux_ts_offset; if (s->output_ts_offset) offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); @@ -1118,6 +1135,8 @@ static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket *pkt, av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __FUNCTION__, pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts)); + guess_pkt_duration(s, st, pkt); + #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX if ((ret = compute_muxer_pkt_fields(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) return ret; @@ -1285,7 +1304,7 @@ int av_write_trailer(AVFormatContext *s) ret = s->pb ? s->pb->error : 0; for (i = 0; i < s->nb_streams; i++) { av_freep(&s->streams[i]->priv_data); - av_freep(&s->streams[i]->index_entries); + av_freep(&s->streams[i]->internal->index_entries); } if (s->oformat->priv_class) av_opt_free(s->priv_data); diff --git a/chromium/third_party/ffmpeg/libavformat/mvdec.c b/chromium/third_party/ffmpeg/libavformat/mvdec.c index d5b400213df..d8f121bea50 100644 --- a/chromium/third_party/ffmpeg/libavformat/mvdec.c +++ b/chromium/third_party/ffmpeg/libavformat/mvdec.c @@ -431,8 +431,8 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt) int64_t ret; uint64_t pos; - if (frame < st->nb_index_entries) { - index = &st->index_entries[frame]; + if (frame < st->internal->nb_index_entries) { + index = &st->internal->index_entries[frame]; pos = avio_tell(pb); if (index->pos > pos) avio_skip(pb, index->pos - pos); diff --git a/chromium/third_party/ffmpeg/libavformat/mvi.c b/chromium/third_party/ffmpeg/libavformat/mvi.c index ff5c08bf511..06c9cfe3f05 100644 --- a/chromium/third_party/ffmpeg/libavformat/mvi.c +++ b/chromium/third_party/ffmpeg/libavformat/mvi.c @@ -123,6 +123,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) count = (mvi->audio_size_counter + mvi->audio_frame_size + 512) >> MVI_FRAC_BITS; if (count > mvi->audio_size_left) count = mvi->audio_size_left; + if ((int64_t)count << MVI_FRAC_BITS > INT_MAX) + return AVERROR_INVALIDDATA; if ((ret = av_get_packet(pb, pkt, count)) < 0) return ret; pkt->stream_index = MVI_AUDIO_STREAM_INDEX; diff --git a/chromium/third_party/ffmpeg/libavformat/mxfdec.c b/chromium/third_party/ffmpeg/libavformat/mxfdec.c index d16a7af0dff..1f79f3d3cdb 100644 --- a/chromium/third_party/ffmpeg/libavformat/mxfdec.c +++ b/chromium/third_party/ffmpeg/libavformat/mxfdec.c @@ -2586,7 +2586,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) av_dict_set_int(&st->metadata, "source_track_origin", source_track->sequence->origin, 0); } if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) - st->display_aspect_ratio = descriptor->aspect_ratio; + st->internal->display_aspect_ratio = descriptor->aspect_ratio; st->codecpar->color_range = mxf_get_color_range(mxf, descriptor); st->codecpar->color_primaries = mxf_get_codec_ul(ff_mxf_color_primaries_uls, &descriptor->color_primaries_ul)->id; st->codecpar->color_trc = mxf_get_codec_ul(ff_mxf_color_trc_uls, &descriptor->color_trc_ul)->id; diff --git a/chromium/third_party/ffmpeg/libavformat/mxfenc.c b/chromium/third_party/ffmpeg/libavformat/mxfenc.c index cbb0fc5a6aa..d8678c9d254 100644 --- a/chromium/third_party/ffmpeg/libavformat/mxfenc.c +++ b/chromium/third_party/ffmpeg/libavformat/mxfenc.c @@ -3050,7 +3050,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket int i, stream_count = 0; for (i = 0; i < s->nb_streams; i++) - stream_count += !!s->streams[i]->last_in_packet_buffer; + stream_count += !!s->streams[i]->internal->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { AVPacketList *pktl = s->internal->packet_buffer; @@ -3061,8 +3061,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (!stream_count || pktl->pkt.stream_index == 0) break; // update last packet in packet buffer - if (s->streams[pktl->pkt.stream_index]->last_in_packet_buffer != pktl) - s->streams[pktl->pkt.stream_index]->last_in_packet_buffer = pktl; + if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != pktl) + s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = pktl; last = pktl; pktl = pktl->next; stream_count--; @@ -3087,8 +3087,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); s->internal->packet_buffer = pktl->next; - if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl) - s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL; + if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) + s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; if(!s->internal->packet_buffer) s->internal->packet_buffer_end= NULL; av_freep(&pktl); diff --git a/chromium/third_party/ffmpeg/libavformat/nistspheredec.c b/chromium/third_party/ffmpeg/libavformat/nistspheredec.c index 3ef3843d5e1..079369929f0 100644 --- a/chromium/third_party/ffmpeg/libavformat/nistspheredec.c +++ b/chromium/third_party/ffmpeg/libavformat/nistspheredec.c @@ -109,6 +109,8 @@ static int nist_read_header(AVFormatContext *s) sscanf(buffer, "%*s %*s %"SCNd64, &st->duration); } else if (!memcmp(buffer, "sample_n_bytes", 14)) { sscanf(buffer, "%*s %*s %d", &bps); + if (bps > INT_MAX/8U) + return AVERROR_INVALIDDATA; } else if (!memcmp(buffer, "sample_rate", 11)) { sscanf(buffer, "%*s %*s %d", &st->codecpar->sample_rate); } else if (!memcmp(buffer, "sample_sig_bits", 15)) { diff --git a/chromium/third_party/ffmpeg/libavformat/nsvdec.c b/chromium/third_party/ffmpeg/libavformat/nsvdec.c index eb26b294508..4fab52ed36f 100644 --- a/chromium/third_party/ffmpeg/libavformat/nsvdec.c +++ b/chromium/third_party/ffmpeg/libavformat/nsvdec.c @@ -682,10 +682,10 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if(index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - nst->frame_offset = st->index_entries[index].timestamp; + nst->frame_offset = st->internal->index_entries[index].timestamp; nsv->state = NSV_UNSYNC; return 0; } diff --git a/chromium/third_party/ffmpeg/libavformat/nutdec.c b/chromium/third_party/ffmpeg/libavformat/nutdec.c index 3779dce2a88..53a052503ec 100644 --- a/chromium/third_party/ffmpeg/libavformat/nutdec.c +++ b/chromium/third_party/ffmpeg/libavformat/nutdec.c @@ -1235,15 +1235,15 @@ static int read_seek(AVFormatContext *s, int stream_index, return AVERROR(ENOSYS); } - if (st->index_entries) { + if (st->internal->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index < 0) index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD); if (index < 0) return -1; - pos2 = st->index_entries[index].pos; - ts = st->index_entries[index].timestamp; + pos2 = st->internal->index_entries[index].pos; + ts = st->internal->index_entries[index].timestamp; } else { av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, (void **) next_node); diff --git a/chromium/third_party/ffmpeg/libavformat/nutenc.c b/chromium/third_party/ffmpeg/libavformat/nutenc.c index 6d3bf6c21e2..1dcb2be1b16 100644 --- a/chromium/third_party/ffmpeg/libavformat/nutenc.c +++ b/chromium/third_party/ffmpeg/libavformat/nutenc.c @@ -1013,12 +1013,12 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) int index = av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD); if (index >= 0) { - sp_pos = FFMIN(sp_pos, st->index_entries[index].pos); - if (!nut->write_index && 2*index > st->nb_index_entries) { - memmove(st->index_entries, - st->index_entries + index, - sizeof(*st->index_entries) * (st->nb_index_entries - index)); - st->nb_index_entries -= index; + sp_pos = FFMIN(sp_pos, st->internal->index_entries[index].pos); + if (!nut->write_index && 2*index > st->internal->nb_index_entries) { + memmove(st->internal->index_entries, + st->internal->index_entries + index, + sizeof(*st->internal->index_entries) * (st->internal->nb_index_entries - index)); + st->internal->nb_index_entries -= index; } } } diff --git a/chromium/third_party/ffmpeg/libavformat/options.c b/chromium/third_party/ffmpeg/libavformat/options.c index 3160904fda9..59e03898156 100644 --- a/chromium/third_party/ffmpeg/libavformat/options.c +++ b/chromium/third_party/ffmpeg/libavformat/options.c @@ -55,35 +55,38 @@ static void *format_child_next(void *obj, void *prev) } #if FF_API_CHILD_CLASS_NEXT -FF_DISABLE_DEPRECATION_WARNINGS static const AVClass *format_child_class_next(const AVClass *prev) { - AVInputFormat *ifmt = NULL; - AVOutputFormat *ofmt = NULL; + const AVInputFormat *ifmt = NULL; + const AVOutputFormat *ofmt = NULL; + void *ifmt_iter = NULL, *ofmt_iter = NULL; if (!prev) return &ff_avio_class; - while ((ifmt = av_iformat_next(ifmt))) + while ((ifmt = av_demuxer_iterate(&ifmt_iter))) if (ifmt->priv_class == prev) break; - if (!ifmt) - while ((ofmt = av_oformat_next(ofmt))) + if (!ifmt) { + ifmt_iter = NULL; + while ((ofmt = av_muxer_iterate(&ofmt_iter))) if (ofmt->priv_class == prev) break; - if (!ofmt) - while (ifmt = av_iformat_next(ifmt)) + } + if (!ofmt) { + ofmt_iter = NULL; + while ((ifmt = av_demuxer_iterate(&ifmt_iter))) if (ifmt->priv_class) return ifmt->priv_class; + } - while (ofmt = av_oformat_next(ofmt)) + while ((ofmt = av_muxer_iterate(&ofmt_iter))) if (ofmt->priv_class) return ofmt->priv_class; return NULL; } -FF_ENABLE_DEPRECATION_WARNINGS #endif enum { diff --git a/chromium/third_party/ffmpeg/libavformat/paf.c b/chromium/third_party/ffmpeg/libavformat/paf.c index a31d01502b2..9587111643c 100644 --- a/chromium/third_party/ffmpeg/libavformat/paf.c +++ b/chromium/third_party/ffmpeg/libavformat/paf.c @@ -75,14 +75,18 @@ static int read_close(AVFormatContext *s) return 0; } -static void read_table(AVFormatContext *s, uint32_t *table, uint32_t count) +static int read_table(AVFormatContext *s, uint32_t *table, uint32_t count) { int i; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { + if (avio_feof(s->pb)) + return AVERROR_INVALIDDATA; table[i] = avio_rl32(s->pb); + } avio_skip(s->pb, 4 * (FFALIGN(count, 512) - count)); + return 0; } static int read_header(AVFormatContext *s) @@ -171,9 +175,15 @@ static int read_header(AVFormatContext *s) avio_seek(pb, p->buffer_size, SEEK_SET); - read_table(s, p->blocks_count_table, p->nb_frames); - read_table(s, p->frames_offset_table, p->nb_frames); - read_table(s, p->blocks_offset_table, p->frame_blks); + ret = read_table(s, p->blocks_count_table, p->nb_frames); + if (ret < 0) + goto fail; + ret = read_table(s, p->frames_offset_table, p->nb_frames); + if (ret < 0) + goto fail; + ret = read_table(s, p->blocks_offset_table, p->frame_blks); + if (ret < 0) + goto fail; p->got_audio = 0; p->current_frame = 0; diff --git a/chromium/third_party/ffmpeg/libavformat/pcm.c b/chromium/third_party/ffmpeg/libavformat/pcm.c index 767bbd045a9..1effc0b6f8d 100644 --- a/chromium/third_party/ffmpeg/libavformat/pcm.c +++ b/chromium/third_party/ffmpeg/libavformat/pcm.c @@ -39,7 +39,11 @@ int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt) * Clamp to RAW_SAMPLES if larger. */ size = FFMAX(par->sample_rate/25, 1); - size = FFMIN(size, RAW_SAMPLES) * par->block_align; + if (par->block_align <= INT_MAX / RAW_SAMPLES) { + size = FFMIN(size, RAW_SAMPLES) * par->block_align; + } else { + size = par->block_align; + } ret = av_get_packet(s->pb, pkt, size); diff --git a/chromium/third_party/ffmpeg/libavformat/rawdec.c b/chromium/third_party/ffmpeg/libavformat/rawdec.c index 10c37c5cb91..122afca1b64 100644 --- a/chromium/third_party/ffmpeg/libavformat/rawdec.c +++ b/chromium/third_party/ffmpeg/libavformat/rawdec.c @@ -208,6 +208,8 @@ static int mjpeg_probe(const AVProbeData *p) return AVPROBE_SCORE_EXTENSION / 2; return AVPROBE_SCORE_EXTENSION / 4; } + if (!nb_invalid && nb_frames) + return AVPROBE_SCORE_EXTENSION / 4; return 0; } diff --git a/chromium/third_party/ffmpeg/libavformat/realtextdec.c b/chromium/third_party/ffmpeg/libavformat/realtextdec.c index c2316da0ed8..390f8ddc679 100644 --- a/chromium/third_party/ffmpeg/libavformat/realtextdec.c +++ b/chromium/third_party/ffmpeg/libavformat/realtextdec.c @@ -45,16 +45,16 @@ static int realtext_probe(const AVProbeData *p) return !av_strncasecmp(buf, "<window", 7) ? AVPROBE_SCORE_EXTENSION : 0; } -static int read_ts(const char *s) +static int64_t read_ts(const char *s) { int hh, mm, ss, ms; - if (sscanf(s, "%u:%u:%u.%u", &hh, &mm, &ss, &ms) == 4) return (hh*3600 + mm*60 + ss) * 100 + ms; - if (sscanf(s, "%u:%u:%u" , &hh, &mm, &ss ) == 3) return (hh*3600 + mm*60 + ss) * 100; - if (sscanf(s, "%u:%u.%u", &mm, &ss, &ms) == 3) return ( mm*60 + ss) * 100 + ms; - if (sscanf(s, "%u:%u" , &mm, &ss ) == 2) return ( mm*60 + ss) * 100; - if (sscanf(s, "%u.%u", &ss, &ms) == 2) return ( ss) * 100 + ms; - return strtol(s, NULL, 10) * 100; + if (sscanf(s, "%u:%u:%u.%u", &hh, &mm, &ss, &ms) == 4) return (hh*3600LL + mm*60LL + ss) * 100LL + ms; + if (sscanf(s, "%u:%u:%u" , &hh, &mm, &ss ) == 3) return (hh*3600LL + mm*60LL + ss) * 100LL; + if (sscanf(s, "%u:%u.%u", &mm, &ss, &ms) == 3) return ( mm*60LL + ss) * 100LL + ms; + if (sscanf(s, "%u:%u" , &mm, &ss ) == 2) return ( mm*60LL + ss) * 100LL; + if (sscanf(s, "%u.%u", &ss, &ms) == 2) return ( ss) * 100LL + ms; + return strtol(s, NULL, 10) * 100LL; } static int realtext_read_header(AVFormatContext *s) diff --git a/chromium/third_party/ffmpeg/libavformat/riffenc.c b/chromium/third_party/ffmpeg/libavformat/riffenc.c index 04a21fcffaa..df04b318932 100644 --- a/chromium/third_party/ffmpeg/libavformat/riffenc.c +++ b/chromium/third_party/ffmpeg/libavformat/riffenc.c @@ -65,6 +65,12 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, if (!par->codec_tag || par->codec_tag > 0xffff) return -1; + if (par->codec_id == AV_CODEC_ID_ADPCM_SWF && par->block_align == 0) { + av_log(s, AV_LOG_ERROR, "%s can only be written to WAVE with a constant frame size\n", + avcodec_get_name(par->codec_id)); + return AVERROR(EINVAL); + } + /* We use the known constant frame size for the codec if known, otherwise * fall back on using AVCodecContext.frame_size, which is not as reliable * for indicating packet duration. */ diff --git a/chromium/third_party/ffmpeg/libavformat/rl2.c b/chromium/third_party/ffmpeg/libavformat/rl2.c index cfde23a945b..fa1b38b1336 100644 --- a/chromium/third_party/ffmpeg/libavformat/rl2.c +++ b/chromium/third_party/ffmpeg/libavformat/rl2.c @@ -237,9 +237,9 @@ static int rl2_read_packet(AVFormatContext *s, /** check if there is a valid video or audio entry that can be used */ for(i=0; i<s->nb_streams; i++){ - if(rl2->index_pos[i] < s->streams[i]->nb_index_entries - && s->streams[i]->index_entries[ rl2->index_pos[i] ].pos < pos){ - sample = &s->streams[i]->index_entries[ rl2->index_pos[i] ]; + if(rl2->index_pos[i] < s->streams[i]->internal->nb_index_entries + && s->streams[i]->internal->index_entries[ rl2->index_pos[i] ].pos < pos){ + sample = &s->streams[i]->internal->index_entries[ rl2->index_pos[i] ]; pos= sample->pos; stream_id= i; } @@ -283,7 +283,7 @@ static int rl2_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp return -1; rl2->index_pos[stream_index] = index; - timestamp = st->index_entries[index].timestamp; + timestamp = st->internal->index_entries[index].timestamp; for(i=0; i < s->nb_streams; i++){ AVStream *st2 = s->streams[i]; diff --git a/chromium/third_party/ffmpeg/libavformat/rmdec.c b/chromium/third_party/ffmpeg/libavformat/rmdec.c index 72b8dba741e..004c62086d9 100644 --- a/chromium/third_party/ffmpeg/libavformat/rmdec.c +++ b/chromium/third_party/ffmpeg/libavformat/rmdec.c @@ -165,7 +165,11 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, avio_rb16(pb); /* version2 */ avio_rb32(pb); /* header size */ flavor= avio_rb16(pb); /* add codec info / flavor */ - ast->coded_framesize = coded_framesize = avio_rb32(pb); /* coded frame size */ + coded_framesize = avio_rb32(pb); /* coded frame size */ + if (coded_framesize < 0) + return AVERROR_INVALIDDATA; + ast->coded_framesize = coded_framesize; + avio_rb32(pb); /* ??? */ bytes_per_minute = avio_rb32(pb); if (version == 4) { @@ -454,6 +458,8 @@ static int rm_read_index(AVFormatContext *s) } for (n = 0; n < n_pkts; n++) { + if (avio_feof(pb)) + return AVERROR_INVALIDDATA; avio_skip(pb, 2); pts = avio_rb32(pb); pos = avio_rb32(pb); @@ -699,17 +705,19 @@ static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stre state= (state<<8) + avio_r8(pb); if(state == MKBETAG('I', 'N', 'D', 'X')){ - int n_pkts, expected_len; + int n_pkts; + int64_t expected_len; len = avio_rb32(pb); avio_skip(pb, 2); n_pkts = avio_rb32(pb); - expected_len = 20 + n_pkts * 14; - if (len == 20) + expected_len = 20 + n_pkts * 14LL; + + if (len == 20 && expected_len <= INT_MAX) /* some files don't add index entries to chunk size... */ len = expected_len; else if (len != expected_len) av_log(s, AV_LOG_WARNING, - "Index size %d (%d pkts) is wrong, should be %d.\n", + "Index size %d (%d pkts) is wrong, should be %"PRId64".\n", len, n_pkts, expected_len); len -= 14; // we already read part of the index header if(len<0) @@ -811,7 +819,6 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, av_packet_unref(&vst->pkt); //FIXME this should be output. if ((ret = av_new_packet(&vst->pkt, vst->videobufsize)) < 0) return ret; - memset(vst->pkt.data, 0, vst->pkt.size); vst->videobufpos = 8*vst->slices + 1; vst->cur_slice = 0; vst->curpic_num = pic_num; @@ -843,7 +850,7 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, if(vst->slices != vst->cur_slice) //FIXME find out how to set slices correct from the begin memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices, vst->videobufpos - 1 - 8*vst->slices); - pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices); + av_shrink_packet(pkt, vst->videobufpos + 8*(vst->cur_slice - vst->slices)); pkt->pts = AV_NOPTS_VALUE; pkt->pos = vst->pktpos; vst->slices = 0; diff --git a/chromium/third_party/ffmpeg/libavformat/rpl.c b/chromium/third_party/ffmpeg/libavformat/rpl.c index 208c50f00ce..b98488c7b17 100644 --- a/chromium/third_party/ffmpeg/libavformat/rpl.c +++ b/chromium/third_party/ffmpeg/libavformat/rpl.c @@ -253,6 +253,9 @@ static int rpl_read_header(AVFormatContext *s) error |= read_line(pb, line, sizeof(line)); } + if (s->nb_streams == 0) + return AVERROR_INVALIDDATA; + rpl->frames_per_chunk = read_line_and_int(pb, &error); // video frames per chunk if (vst && rpl->frames_per_chunk > 1 && vst->codecpar->codec_tag != 124) av_log(s, AV_LOG_WARNING, @@ -314,10 +317,10 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) stream = s->streams[rpl->chunk_part]; - if (rpl->chunk_number >= stream->nb_index_entries) + if (rpl->chunk_number >= stream->internal->nb_index_entries) return AVERROR_EOF; - index_entry = &stream->index_entries[rpl->chunk_number]; + index_entry = &stream->internal->index_entries[rpl->chunk_number]; if (rpl->frame_in_part == 0) if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0) diff --git a/chromium/third_party/ffmpeg/libavformat/rsd.c b/chromium/third_party/ffmpeg/libavformat/rsd.c index e23c8abae5e..ee0b9557ded 100644 --- a/chromium/third_party/ffmpeg/libavformat/rsd.c +++ b/chromium/third_party/ffmpeg/libavformat/rsd.c @@ -103,13 +103,9 @@ static int rsd_read_header(AVFormatContext *s) break; case AV_CODEC_ID_ADPCM_PSX: par->block_align = 16 * par->channels; - if (pb->seekable & AVIO_SEEKABLE_NORMAL) - st->duration = av_get_audio_frame_duration2(par, avio_size(pb) - start); break; case AV_CODEC_ID_ADPCM_IMA_RAD: par->block_align = 20 * par->channels; - if (pb->seekable & AVIO_SEEKABLE_NORMAL) - st->duration = av_get_audio_frame_duration2(par, avio_size(pb) - start); break; case AV_CODEC_ID_ADPCM_IMA_WAV: if (version == 2) @@ -117,8 +113,6 @@ static int rsd_read_header(AVFormatContext *s) par->bits_per_coded_sample = 4; par->block_align = 36 * par->channels; - if (pb->seekable & AVIO_SEEKABLE_NORMAL) - st->duration = av_get_audio_frame_duration2(par, avio_size(pb) - start); break; case AV_CODEC_ID_ADPCM_THP_LE: /* RSD3GADP is mono, so only alloc enough memory @@ -128,8 +122,6 @@ static int rsd_read_header(AVFormatContext *s) if ((ret = ff_get_extradata(s, par, s->pb, 32)) < 0) return ret; - if (pb->seekable & AVIO_SEEKABLE_NORMAL) - st->duration = av_get_audio_frame_duration2(par, avio_size(pb) - start); break; case AV_CODEC_ID_ADPCM_THP: par->block_align = 8 * par->channels; @@ -142,18 +134,36 @@ static int rsd_read_header(AVFormatContext *s) avio_read(s->pb, st->codecpar->extradata + 32 * i, 32); avio_skip(s->pb, 8); } - if (pb->seekable & AVIO_SEEKABLE_NORMAL) - st->duration = (avio_size(pb) - start) / (8 * par->channels) * 14; break; case AV_CODEC_ID_PCM_S16LE: case AV_CODEC_ID_PCM_S16BE: if (version != 4) start = avio_rl32(pb); - if (pb->seekable & AVIO_SEEKABLE_NORMAL) - st->duration = (avio_size(pb) - start) / 2 / par->channels; break; } + if (start < 0) + return AVERROR_INVALIDDATA; + + if (pb->seekable & AVIO_SEEKABLE_NORMAL) { + int64_t remaining = avio_size(pb); + + if (remaining >= start && remaining - start <= INT_MAX) + switch (par->codec_id) { + case AV_CODEC_ID_ADPCM_PSX: + case AV_CODEC_ID_ADPCM_IMA_RAD: + case AV_CODEC_ID_ADPCM_IMA_WAV: + case AV_CODEC_ID_ADPCM_THP_LE: + st->duration = av_get_audio_frame_duration2(par, remaining - start); + break; + case AV_CODEC_ID_ADPCM_THP: + st->duration = (remaining - start) / (8 * par->channels) * 14; + break; + case AV_CODEC_ID_PCM_S16LE: + case AV_CODEC_ID_PCM_S16BE: + st->duration = (remaining - start) / 2 / par->channels; + } + } avio_skip(pb, start - avio_tell(pb)); if (par->codec_id == AV_CODEC_ID_XMA2) { diff --git a/chromium/third_party/ffmpeg/libavformat/rtpproto.c b/chromium/third_party/ffmpeg/libavformat/rtpproto.c index 19e940d01e6..7dd60421581 100644 --- a/chromium/third_party/ffmpeg/libavformat/rtpproto.c +++ b/chromium/third_party/ffmpeg/libavformat/rtpproto.c @@ -60,6 +60,7 @@ typedef struct RTPContext { char *sources; char *block; char *fec_options_str; + int64_t rw_timeout; } RTPContext; #define OFFSET(x) offsetof(RTPContext, x) @@ -75,6 +76,7 @@ static const AVOption options[] = { { "write_to_source", "Send packets to the source address of the latest received packet", OFFSET(write_to_source), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E }, { "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { "dscp", "DSCP class", OFFSET(dscp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, { "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { "fec", "FEC", OFFSET(fec_options_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = E }, @@ -265,6 +267,9 @@ static int rtp_open(URLContext *h, const char *uri, int flags) if (av_find_info_tag(buf, sizeof(buf), "dscp", p)) { s->dscp = strtol(buf, NULL, 10); } + if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { + s->rw_timeout = strtol(buf, NULL, 10); + } if (av_find_info_tag(buf, sizeof(buf), "sources", p)) { av_strlcpy(include_sources, buf, sizeof(include_sources)); ff_ip_parse_sources(h, buf, &s->filters); @@ -280,6 +285,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags) block = s->block; } } + if (s->rw_timeout >= 0) + h->rw_timeout = s->rw_timeout; if (s->fec_options_str) { p = s->fec_options_str; @@ -375,9 +382,10 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) RTPContext *s = h->priv_data; int len, n, i; struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}}; - int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100; + int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : POLLING_TIME; struct sockaddr_storage *addrs[2] = { &s->last_rtp_source, &s->last_rtcp_source }; socklen_t *addr_lens[2] = { &s->last_rtp_source_len, &s->last_rtcp_source_len }; + int runs = h->rw_timeout / 1000 / POLLING_TIME; for(;;) { if (ff_check_interrupt(&h->interrupt_callback)) @@ -401,6 +409,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) continue; return len; } + } else if (n == 0 && h->rw_timeout > 0 && --runs <= 0) { + return AVERROR(ETIMEDOUT); } else if (n < 0) { if (ff_neterrno() == AVERROR(EINTR)) continue; diff --git a/chromium/third_party/ffmpeg/libavformat/rtsp.c b/chromium/third_party/ffmpeg/libavformat/rtsp.c index 5d8491b74ba..c7ffa07d9ee 100644 --- a/chromium/third_party/ffmpeg/libavformat/rtsp.c +++ b/chromium/third_party/ffmpeg/libavformat/rtsp.c @@ -51,12 +51,8 @@ #include "rtpenc.h" #include "mpegts.h" -/* Timeout values for socket poll, in ms, - * and read_packet(), in seconds */ -#define POLL_TIMEOUT_MS 100 +/* Default timeout values for read packet in seconds */ #define READ_PACKET_TIMEOUT_S 10 -#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS -#define SDP_MAX_SIZE 16384 #define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH #define DEFAULT_REORDERING_DELAY 100000 @@ -115,6 +111,7 @@ static const AVOption sdp_options[] = { RTSP_FLAG_OPTS("sdp_flags", "SDP flags"), { "custom_io", "use custom I/O", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, "rtsp_flags" }, { "rtcp_to_source", "send RTCP packets to the source address of received packets", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_RTCP_TO_SOURCE}, 0, 0, DEC, "rtsp_flags" }, + { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = READ_PACKET_TIMEOUT_S}, INT_MIN, INT_MAX, DEC }, RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"), COMMON_OPTS(), { NULL }, @@ -122,6 +119,8 @@ static const AVOption sdp_options[] = { static const AVOption rtp_options[] = { RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"), + { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = READ_PACKET_TIMEOUT_S}, INT_MIN, INT_MAX, DEC }, + RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"), COMMON_OPTS(), { NULL }, }; @@ -688,15 +687,7 @@ int ff_sdp_parse(AVFormatContext *s, const char *content) { const char *p; int letter, i; - /* Some SDP lines, particularly for Realmedia or ASF RTSP streams, - * contain long SDP lines containing complete ASF Headers (several - * kB) or arrays of MDPR (RM stream descriptor) headers plus - * "rulebooks" describing their properties. Therefore, the SDP line - * buffer is large. - * - * The Vorbis FMTP line can be up to 16KB - see xiph_parse_sdp_line - * in rtpdec_xiph.c. */ - char buf[16384], *q; + char buf[SDP_MAX_SIZE], *q; SDPParseState sdp_parse_state = { { 0 } }, *s1 = &sdp_parse_state; p = content; @@ -1034,7 +1025,7 @@ static void handle_rtp_info(RTSPState *rt, const char *url, static void rtsp_parse_rtp_info(RTSPState *rt, const char *p) { int read = 0; - char key[20], value[1024], url[1024] = ""; + char key[20], value[MAX_URL_SIZE], url[MAX_URL_SIZE] = ""; uint32_t seq = 0, rtptime = 0; for (;;) { @@ -1133,7 +1124,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s) { RTSPState *rt = s->priv_data; int ret, len, len1; - uint8_t buf[1024]; + uint8_t buf[MAX_URL_SIZE]; ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); if (ret != 3) @@ -1159,7 +1150,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, int return_on_interleaved_data, const char *method) { RTSPState *rt = s->priv_data; - char buf[4096], buf1[1024], *q; + char buf[MAX_URL_SIZE], buf1[MAX_URL_SIZE], *q; unsigned char ch; const char *p; int ret, content_length, line_count = 0, request = 0; @@ -1229,7 +1220,8 @@ start: content = av_malloc(content_length + 1); if (!content) return AVERROR(ENOMEM); - ffurl_read_complete(rt->rtsp_hd, content, content_length); + if (ffurl_read_complete(rt->rtsp_hd, content, content_length) != content_length) + return AVERROR(EIO); content[content_length] = '\0'; } if (content_ptr) @@ -1238,7 +1230,7 @@ start: av_freep(&content); if (request) { - char buf[1024]; + char buf[MAX_URL_SIZE]; char base64buf[AV_BASE64_SIZE(sizeof(buf))]; const char* ptr = buf; @@ -1314,7 +1306,7 @@ static int rtsp_send_cmd_with_content_async(AVFormatContext *s, int send_content_length) { RTSPState *rt = s->priv_data; - char buf[4096], *out_buf; + char buf[MAX_URL_SIZE], *out_buf; char base64buf[AV_BASE64_SIZE(sizeof(buf))]; if (!rt->rtsp_hd_out) @@ -1424,7 +1416,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, int rtx = 0, j, i, err, interleave = 0, port_off; RTSPStream *rtsp_st; RTSPMessageHeader reply1, *reply = &reply1; - char cmd[2048]; + char cmd[MAX_URL_SIZE]; const char *trans_pref; if (rt->transport == RTSP_TRANSPORT_RDT) @@ -1445,7 +1437,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, port_off -= port_off & 0x01; for (j = rt->rtp_port_min + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) { - char transport[2048]; + char transport[MAX_URL_SIZE]; /* * WMS serves all UDP data over a single connection, the RTX, which @@ -1594,7 +1586,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, break; case RTSP_LOWER_TRANSPORT_UDP: { - char url[1024], options[30] = ""; + char url[MAX_URL_SIZE], options[30] = ""; const char *peer = host; if (rt->rtsp_flags & RTSP_FLAG_FILTER_SRC) @@ -1612,7 +1604,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, break; } case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: { - char url[1024], namebuf[50], optbuf[20] = ""; + char url[MAX_URL_SIZE], namebuf[50], optbuf[20] = ""; struct sockaddr_storage addr; int port, ttl; AVDictionary *opts = map_to_opts(rt); @@ -1674,7 +1666,7 @@ int ff_rtsp_connect(AVFormatContext *s) { RTSPState *rt = s->priv_data; char proto[128], host[1024], path[1024]; - char tcpname[1024], cmd[2048], auth[128]; + char tcpname[1024], cmd[MAX_URL_SIZE], auth[128]; const char *lower_rtsp_proto = "tcp"; int port, err, tcp_fd; RTSPMessageHeader reply1, *reply = &reply1; @@ -1964,13 +1956,9 @@ static int parse_rtsp_message(AVFormatContext *s) if (rt->rtsp_flags & RTSP_FLAG_LISTEN) { if (rt->state == RTSP_STATE_STREAMING) { - if (!ff_rtsp_parse_streaming_commands(s)) - return AVERROR_EOF; - else - av_log(s, AV_LOG_WARNING, - "Unable to answer to TEARDOWN\n"); + return ff_rtsp_parse_streaming_commands(s); } else - return 0; + return AVERROR_EOF; } else { RTSPMessageHeader reply; ret = ff_rtsp_read_reply(s, &reply, NULL, 0, NULL); @@ -1989,12 +1977,13 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; - int n, i, ret, timeout_cnt = 0; + int n, i, ret; struct pollfd *p = rt->p; int *fds = NULL, fdsnum, fdsidx; + int runs = rt->initial_timeout * 1000LL / POLLING_TIME; if (!p) { - p = rt->p = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd)); + p = rt->p = av_malloc_array(2 * rt->nb_rtsp_streams + 1, sizeof(*p)); if (!p) return AVERROR(ENOMEM); @@ -2029,10 +2018,9 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, return AVERROR_EXIT; if (wait_end && wait_end - av_gettime_relative() < 0) return AVERROR(EAGAIN); - n = poll(p, rt->max_p, POLL_TIMEOUT_MS); + n = poll(p, rt->max_p, POLLING_TIME); if (n > 0) { int j = rt->rtsp_hd ? 1 : 0; - timeout_cnt = 0; for (i = 0; i < rt->nb_rtsp_streams; i++) { rtsp_st = rt->rtsp_streams[i]; if (rtsp_st->rtp_handle) { @@ -2053,7 +2041,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, } } #endif - } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) { + } else if (n == 0 && rt->initial_timeout > 0 && --runs <= 0) { return AVERROR(ETIMEDOUT); } else if (n < 0 && errno != EINTR) return AVERROR(errno); @@ -2259,9 +2247,7 @@ redo: s->start_time_realtime = av_rescale (rtpctx->first_rtcp_ntp_time - (NTP_OFFSET << 32), 1000000, 1LL << 32); if (rtpctx->st) { s->start_time_realtime -= - av_rescale (rtpctx->rtcp_ts_offset, - (uint64_t) rtpctx->st->time_base.num * 1000000, - rtpctx->st->time_base.den); + av_rescale_q (rtpctx->rtcp_ts_offset, rtpctx->st->time_base, AV_TIME_BASE_Q); } } } @@ -2338,7 +2324,7 @@ static int sdp_read_header(AVFormatContext *s) RTSPStream *rtsp_st; int size, i, err; char *content; - char url[1024]; + char url[MAX_URL_SIZE]; if (!ff_network_init()) return AVERROR(EIO); @@ -2351,11 +2337,14 @@ static int sdp_read_header(AVFormatContext *s) /* read the whole sdp file */ /* XXX: better loading */ content = av_malloc(SDP_MAX_SIZE); - if (!content) + if (!content) { + ff_network_close(); return AVERROR(ENOMEM); + } size = avio_read(s->pb, content, SDP_MAX_SIZE - 1); if (size <= 0) { av_free(content); + ff_network_close(); return AVERROR_INVALIDDATA; } content[size] ='\0'; @@ -2507,6 +2496,7 @@ static int rtp_read_header(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "Unable to receive RTP payload type %d " "without an SDP file describing it\n", payload_type); + ret = AVERROR_INVALIDDATA; goto fail; } if (par->codec_type != AVMEDIA_TYPE_DATA) { @@ -2553,7 +2543,9 @@ static int rtp_read_header(AVFormatContext *s) ffio_init_context(&pb, sdp.str, sdp.len, 0, NULL, NULL, NULL, NULL); s->pb = &pb; - /* sdp_read_header initializes this again */ + /* if sdp_read_header() fails then following ff_network_close() cancels out */ + /* ff_network_init() at the start of this function. Otherwise it cancels out */ + /* ff_network_init() inside sdp_read_header() */ ff_network_close(); rt->media_type_mask = (1 << (AVMEDIA_TYPE_SUBTITLE+1)) - 1; diff --git a/chromium/third_party/ffmpeg/libavformat/rtsp.h b/chromium/third_party/ffmpeg/libavformat/rtsp.h index 54a9a30c16f..b74cdc148a2 100644 --- a/chromium/third_party/ffmpeg/libavformat/rtsp.h +++ b/chromium/third_party/ffmpeg/libavformat/rtsp.h @@ -27,6 +27,7 @@ #include "rtpdec.h" #include "network.h" #include "httpauth.h" +#include "internal.h" #include "libavutil/log.h" #include "libavutil/opt.h" @@ -78,6 +79,7 @@ enum RTSPControlTransport { #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100 #define RTSP_RTP_PORT_MIN 5000 #define RTSP_RTP_PORT_MAX 65000 +#define SDP_MAX_SIZE 16384 /** * This describes a single item in the "Transport:" line of one stream as @@ -315,7 +317,7 @@ typedef struct RTSPState { /** some MS RTSP streams contain a URL in the SDP that we need to use * for all subsequent RTSP requests, rather than the input URI; in * other cases, this is a copy of AVFormatContext->filename. */ - char control_uri[1024]; + char control_uri[MAX_URL_SIZE]; /** The following are used for parsing raw mpegts in udp */ //@{ @@ -443,7 +445,7 @@ typedef struct RTSPStream { * for the selected transport. Only used for TCP. */ int interleaved_min, interleaved_max; - char control_url[1024]; /**< url for this stream (from SDP) */ + char control_url[MAX_URL_SIZE]; /**< url for this stream (from SDP) */ /** The following are used only in SDP, not RTSP */ //@{ diff --git a/chromium/third_party/ffmpeg/libavformat/rtspdec.c b/chromium/third_party/ffmpeg/libavformat/rtspdec.c index dfa29913bff..bfbb01d586a 100644 --- a/chromium/third_party/ffmpeg/libavformat/rtspdec.c +++ b/chromium/third_party/ffmpeg/libavformat/rtspdec.c @@ -97,7 +97,7 @@ static int rtsp_send_reply(AVFormatContext *s, enum RTSPStatusCode code, const char *extracontent, uint16_t seq) { RTSPState *rt = s->priv_data; - char message[4096]; + char message[MAX_URL_SIZE]; int index = 0; while (status_messages[index].code) { if (status_messages[index].code == code) { @@ -143,7 +143,7 @@ static inline int rtsp_read_request(AVFormatContext *s, const char *method) { RTSPState *rt = s->priv_data; - char rbuf[1024]; + char rbuf[MAX_URL_SIZE]; int rbuflen, ret; do { ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen); @@ -172,7 +172,7 @@ static int rtsp_read_announce(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPMessageHeader request = { 0 }; - char sdp[4096]; + char sdp[SDP_MAX_SIZE]; int ret; ret = rtsp_read_request(s, &request, "ANNOUNCE"); @@ -232,9 +232,9 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl) RTSPState *rt = s->priv_data; RTSPMessageHeader request = { 0 }; int ret = 0; - char url[1024]; + char url[MAX_URL_SIZE]; RTSPStream *rtsp_st; - char responseheaders[1024]; + char responseheaders[MAX_URL_SIZE]; int localport = -1; int transportidx = 0; int streamid = 0; @@ -274,6 +274,17 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl) rtsp_st = rt->rtsp_streams[streamid]; localport = rt->rtp_port_min; + /* check if the stream has already been setup */ + if (rtsp_st->transport_priv) { + if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RDT) + ff_rdt_parse_close(rtsp_st->transport_priv); + else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RTP) + ff_rtp_parse_close(rtsp_st->transport_priv); + rtsp_st->transport_priv = NULL; + } + if (rtsp_st->rtp_handle) + ffurl_closep(&rtsp_st->rtp_handle); + if (request.transports[0].lower_transport == RTSP_LOWER_TRANSPORT_TCP) { rt->lower_transport = RTSP_LOWER_TRANSPORT_TCP; if ((ret = ff_rtsp_open_transport_ctx(s, rtsp_st))) { @@ -291,7 +302,7 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl) AVDictionary *opts = NULL; av_dict_set_int(&opts, "buffer_size", rt->buffer_size, 0); ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL); - av_log(s, AV_LOG_TRACE, "Opening: %s", url); + av_log(s, AV_LOG_TRACE, "Opening: %s\n", url); ret = ffurl_open_whitelist(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); @@ -304,7 +315,7 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl) return ret; } - av_log(s, AV_LOG_TRACE, "Listening on: %d", + av_log(s, AV_LOG_TRACE, "Listening on: %d\n", ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle)); if ((ret = ff_rtsp_open_transport_ctx(s, rtsp_st))) { rtsp_send_reply(s, RTSP_STATUS_TRANSPORT, NULL, request.seq); @@ -340,7 +351,7 @@ static int rtsp_read_record(AVFormatContext *s) RTSPState *rt = s->priv_data; RTSPMessageHeader request = { 0 }; int ret = 0; - char responseheaders[1024]; + char responseheaders[MAX_URL_SIZE]; ret = rtsp_read_request(s, &request, "RECORD"); if (ret) @@ -463,7 +474,7 @@ static inline int parse_command_line(AVFormatContext *s, const char *line, int ff_rtsp_parse_streaming_commands(AVFormatContext *s) { RTSPState *rt = s->priv_data; - unsigned char rbuf[4096]; + unsigned char rbuf[MAX_URL_SIZE]; unsigned char method[10]; char uri[500]; int ret; @@ -474,6 +485,7 @@ int ff_rtsp_parse_streaming_commands(AVFormatContext *s) ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen); if (ret < 0) return ret; + av_log(s, AV_LOG_TRACE, "Parsing[%d]: %s\n", rbuflen, rbuf); ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method, sizeof(method), &methodcode); if (ret) { @@ -505,7 +517,7 @@ static int rtsp_read_play(AVFormatContext *s) RTSPState *rt = s->priv_data; RTSPMessageHeader reply1, *reply = &reply1; int i; - char cmd[1024]; + char cmd[MAX_URL_SIZE]; av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state); rt->nb_byes = 0; @@ -591,7 +603,7 @@ static int rtsp_read_pause(AVFormatContext *s) int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply) { RTSPState *rt = s->priv_data; - char cmd[1024]; + char cmd[MAX_URL_SIZE]; unsigned char *content = NULL; int ret; @@ -634,12 +646,15 @@ static int rtsp_listen(AVFormatContext *s) int default_port = RTSP_DEFAULT_PORT; char tcpname[500]; const char *lower_proto = "tcp"; - unsigned char rbuf[4096]; + unsigned char rbuf[MAX_URL_SIZE]; unsigned char method[10]; int rbuflen = 0; int ret; enum RTSPMethod methodcode; + if (!ff_network_init()) + return AVERROR(EIO); + /* extract hostname and port */ av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host), &port, path, sizeof(path), s->url); @@ -664,19 +679,20 @@ static int rtsp_listen(AVFormatContext *s) &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL)) { av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n"); - return ret; + goto fail; } rt->state = RTSP_STATE_IDLE; rt->rtsp_hd_out = rt->rtsp_hd; for (;;) { /* Wait for incoming RTSP messages */ ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen); if (ret < 0) - return ret; + goto fail; + av_log(s, AV_LOG_TRACE, "Parsing[%d]: %s\n", rbuflen, rbuf); ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method, sizeof(method), &methodcode); if (ret) { av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n"); - return ret; + goto fail; } if (methodcode == ANNOUNCE) { @@ -691,10 +707,15 @@ static int rtsp_listen(AVFormatContext *s) } else if (methodcode == SETUP) ret = rtsp_read_setup(s, host, uri); if (ret) { - ffurl_close(rt->rtsp_hd); - return AVERROR_INVALIDDATA; + ret = AVERROR_INVALIDDATA; + goto fail; } } +fail: + ff_rtsp_close_streams(s); + ff_rtsp_close_connections(s); + ff_network_close(); + return ret; } static int rtsp_probe(const AVProbeData *p) @@ -727,22 +748,26 @@ static int rtsp_read_header(AVFormatContext *s) rt->real_setup_cache = !s->nb_streams ? NULL : av_mallocz_array(s->nb_streams, 2 * sizeof(*rt->real_setup_cache)); - if (!rt->real_setup_cache && s->nb_streams) - return AVERROR(ENOMEM); + if (!rt->real_setup_cache && s->nb_streams) { + ret = AVERROR(ENOMEM); + goto fail; + } rt->real_setup = rt->real_setup_cache + s->nb_streams; if (rt->initial_pause) { /* do not start immediately */ } else { - if ((ret = rtsp_read_play(s)) < 0) { - ff_rtsp_close_streams(s); - ff_rtsp_close_connections(s); - return ret; - } + ret = rtsp_read_play(s); + if (ret < 0) + goto fail; } } return 0; + +fail: + rtsp_read_close(s); + return ret; } int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, @@ -768,7 +793,7 @@ redo: } ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); if (ret != 3) - return -1; + return AVERROR(EIO); id = buf[0]; len = AV_RB16(buf + 1); av_log(s, AV_LOG_TRACE, "id=%d len=%d\n", id, len); @@ -777,10 +802,10 @@ redo: /* get the data */ ret = ffurl_read_complete(rt->rtsp_hd, buf, len); if (ret != len) - return -1; + return AVERROR(EIO); if (rt->transport == RTSP_TRANSPORT_RDT && - ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0) - return -1; + (ret = ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL)) < 0) + return ret; /* find the matching stream */ for (i = 0; i < rt->nb_rtsp_streams; i++) { @@ -813,7 +838,7 @@ static int rtsp_read_packet(AVFormatContext *s, AVPacket *pkt) RTSPState *rt = s->priv_data; int ret; RTSPMessageHeader reply1, *reply = &reply1; - char cmd[1024]; + char cmd[MAX_URL_SIZE]; retry: if (rt->server_type == RTSP_SERVER_REAL) { diff --git a/chromium/third_party/ffmpeg/libavformat/rtspenc.c b/chromium/third_party/ffmpeg/libavformat/rtspenc.c index 97e3ef6da3c..c3202274388 100644 --- a/chromium/third_party/ffmpeg/libavformat/rtspenc.c +++ b/chromium/third_party/ffmpeg/libavformat/rtspenc.c @@ -34,7 +34,6 @@ #include "libavutil/time.h" #include "url.h" -#define SDP_MAX_SIZE 16384 static const AVClass rtsp_muxer_class = { .class_name = "RTSP muxer", @@ -50,7 +49,7 @@ int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr) int i; char *sdp; AVFormatContext sdp_ctx, *ctx_array[1]; - char url[1024]; + char url[MAX_URL_SIZE]; if (s->start_time_realtime == 0 || s->start_time_realtime == AV_NOPTS_VALUE) s->start_time_realtime = av_gettime(); @@ -112,7 +111,7 @@ static int rtsp_write_record(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPMessageHeader reply1, *reply = &reply1; - char cmd[1024]; + char cmd[MAX_URL_SIZE]; snprintf(cmd, sizeof(cmd), "Range: npt=0.000-\r\n"); diff --git a/chromium/third_party/ffmpeg/libavformat/sbgdec.c b/chromium/third_party/ffmpeg/libavformat/sbgdec.c index c11244ef3df..f56eb9ff59c 100644 --- a/chromium/third_party/ffmpeg/libavformat/sbgdec.c +++ b/chromium/third_party/ffmpeg/libavformat/sbgdec.c @@ -538,6 +538,9 @@ static int parse_time_sequence(struct sbg_parser *p, int inblock) return AVERROR_INVALIDDATA; } ts.type = p->current_time.type; + + if (av_sat_add64(p->current_time.t, rel_ts) != p->current_time.t + (uint64_t)rel_ts) + return AVERROR_INVALIDDATA; ts.t = p->current_time.t + rel_ts; r = parse_fade(p, &fade); if (r < 0) @@ -1413,6 +1416,11 @@ static av_cold int sbg_read_header(AVFormatContext *avf) if (r < 0) goto fail; + if (script.end_ts != AV_NOPTS_VALUE && script.end_ts < script.start_ts) { + r = AVERROR_INVALIDDATA; + goto fail; + } + st = avformat_new_stream(avf, NULL); if (!st) return AVERROR(ENOMEM); diff --git a/chromium/third_party/ffmpeg/libavformat/sdp.c b/chromium/third_party/ffmpeg/libavformat/sdp.c index 2ce1a62262d..95f3fbb8765 100644 --- a/chromium/third_party/ffmpeg/libavformat/sdp.c +++ b/chromium/third_party/ffmpeg/libavformat/sdp.c @@ -704,6 +704,8 @@ static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int case AV_CODEC_ID_SPEEX: av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n", payload_type, p->sample_rate); +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS if (st->codec) { const char *mode; uint64_t vad_option; @@ -718,6 +720,8 @@ static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int av_strlcatf(buff, size, "a=fmtp:%d vbr=%s\r\n", payload_type, mode); } +FF_ENABLE_DEPRECATION_WARNINGS +#endif break; case AV_CODEC_ID_OPUS: /* The opus RTP draft says that all opus streams MUST be declared diff --git a/chromium/third_party/ffmpeg/libavformat/segafilm.c b/chromium/third_party/ffmpeg/libavformat/segafilm.c index 4d14b81d163..1225227138d 100644 --- a/chromium/third_party/ffmpeg/libavformat/segafilm.c +++ b/chromium/third_party/ffmpeg/libavformat/segafilm.c @@ -144,8 +144,11 @@ static int film_read_header(AVFormatContext *s) film->video_type = AV_CODEC_ID_NONE; } + if (film->video_type == AV_CODEC_ID_NONE && film->audio_type == AV_CODEC_ID_NONE) + return AVERROR_INVALIDDATA; + /* initialize the decoder streams */ - if (film->video_type) { + if (film->video_type != AV_CODEC_ID_NONE) { st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); @@ -166,7 +169,7 @@ static int film_read_header(AVFormatContext *s) } } - if (film->audio_type) { + if (film->audio_type != AV_CODEC_ID_NONE) { st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); @@ -241,7 +244,7 @@ static int film_read_header(AVFormatContext *s) film->sample_table[i].pts = AV_RB32(&scratch[8]) & 0x7FFFFFFF; film->sample_table[i].keyframe = (scratch[8] & 0x80) ? 0 : AVINDEX_KEYFRAME; video_frame_counter++; - if (film->video_type) + if (film->video_type != AV_CODEC_ID_NONE) av_add_index_entry(s->streams[film->video_stream_index], film->sample_table[i].sample_offset, film->sample_table[i].pts, @@ -250,10 +253,10 @@ static int film_read_header(AVFormatContext *s) } } - if (film->audio_type) + if (film->audio_type != AV_CODEC_ID_NONE) s->streams[film->audio_stream_index]->duration = audio_frame_counter; - if (film->video_type) + if (film->video_type != AV_CODEC_ID_NONE) s->streams[film->video_stream_index]->duration = video_frame_counter; film->current_sample = 0; @@ -321,7 +324,7 @@ static int film_read_seek(AVFormatContext *s, int stream_index, int64_t timestam if (ret < 0) return ret; - pos = avio_seek(s->pb, st->index_entries[ret].pos, SEEK_SET); + pos = avio_seek(s->pb, st->internal->index_entries[ret].pos, SEEK_SET); if (pos < 0) return pos; diff --git a/chromium/third_party/ffmpeg/libavformat/subviewerdec.c b/chromium/third_party/ffmpeg/libavformat/subviewerdec.c index fdca3a48205..5c2fe676f19 100644 --- a/chromium/third_party/ffmpeg/libavformat/subviewerdec.c +++ b/chromium/third_party/ffmpeg/libavformat/subviewerdec.c @@ -148,6 +148,10 @@ static int subviewer_read_header(AVFormatContext *s) new_event = 1; pos = avio_tell(s->pb); } else if (*line) { + if (pts_start == AV_NOPTS_VALUE) { + res = AVERROR_INVALIDDATA; + goto end; + } if (!new_event) { sub = ff_subtitles_queue_insert(&subviewer->q, "\n", 1, 1); if (!sub) { diff --git a/chromium/third_party/ffmpeg/libavformat/swfdec.c b/chromium/third_party/ffmpeg/libavformat/swfdec.c index 2769a768def..fa11c050cdc 100644 --- a/chromium/third_party/ffmpeg/libavformat/swfdec.c +++ b/chromium/third_party/ffmpeg/libavformat/swfdec.c @@ -292,7 +292,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(ENOMEM); ast->duration = avio_rl32(pb); // number of samples if (((v>>4) & 15) == 2) { // MP3 sound data record - ast->skip_samples = avio_rl16(pb); + ast->internal->skip_samples = avio_rl16(pb); len -= 2; } len -= 7; diff --git a/chromium/third_party/ffmpeg/libavformat/tee.c b/chromium/third_party/ffmpeg/libavformat/tee.c index c5c59975e6b..c0b69a386c6 100644 --- a/chromium/third_party/ffmpeg/libavformat/tee.c +++ b/chromium/third_party/ffmpeg/libavformat/tee.c @@ -614,5 +614,5 @@ AVOutputFormat ff_tee_muxer = { .write_trailer = tee_write_trailer, .write_packet = tee_write_packet, .priv_class = &tee_muxer_class, - .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH, + .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH | AVFMT_TS_NEGATIVE, }; diff --git a/chromium/third_party/ffmpeg/libavformat/tls_gnutls.c b/chromium/third_party/ffmpeg/libavformat/tls_gnutls.c index 0c4ef34f5fc..f9d5af7096e 100644 --- a/chromium/third_party/ffmpeg/libavformat/tls_gnutls.c +++ b/chromium/third_party/ffmpeg/libavformat/tls_gnutls.c @@ -269,6 +269,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), { NULL } @@ -288,6 +294,7 @@ const URLProtocol ff_tls_protocol = { .url_write = tls_write, .url_close = tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class, diff --git a/chromium/third_party/ffmpeg/libavformat/tls_libtls.c b/chromium/third_party/ffmpeg/libavformat/tls_libtls.c index dff7f2d9fb4..911c8094b04 100644 --- a/chromium/third_party/ffmpeg/libavformat/tls_libtls.c +++ b/chromium/third_party/ffmpeg/libavformat/tls_libtls.c @@ -181,6 +181,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), { NULL } @@ -200,6 +206,7 @@ const URLProtocol ff_tls_protocol = { .url_write = ff_tls_write, .url_close = ff_tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class, diff --git a/chromium/third_party/ffmpeg/libavformat/tls_mbedtls.c b/chromium/third_party/ffmpeg/libavformat/tls_mbedtls.c index 965adf1be43..aadf17760d6 100644 --- a/chromium/third_party/ffmpeg/libavformat/tls_mbedtls.c +++ b/chromium/third_party/ffmpeg/libavformat/tls_mbedtls.c @@ -326,6 +326,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), \ {"key_password", "Password for the private key file", OFFSET(priv_key_pw), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \ @@ -346,6 +352,7 @@ const URLProtocol ff_tls_protocol = { .url_write = tls_write, .url_close = tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class, diff --git a/chromium/third_party/ffmpeg/libavformat/tls_openssl.c b/chromium/third_party/ffmpeg/libavformat/tls_openssl.c index 002197fa76d..e0616acbc8f 100644 --- a/chromium/third_party/ffmpeg/libavformat/tls_openssl.c +++ b/chromium/third_party/ffmpeg/libavformat/tls_openssl.c @@ -351,6 +351,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), { NULL } @@ -370,6 +376,7 @@ const URLProtocol ff_tls_protocol = { .url_write = tls_write, .url_close = tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class, diff --git a/chromium/third_party/ffmpeg/libavformat/tls_schannel.c b/chromium/third_party/ffmpeg/libavformat/tls_schannel.c index 4bfaa852284..d4959f75fa6 100644 --- a/chromium/third_party/ffmpeg/libavformat/tls_schannel.c +++ b/chromium/third_party/ffmpeg/libavformat/tls_schannel.c @@ -589,6 +589,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), { NULL } @@ -608,6 +614,7 @@ const URLProtocol ff_tls_protocol = { .url_write = tls_write, .url_close = tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class, diff --git a/chromium/third_party/ffmpeg/libavformat/tls_securetransport.c b/chromium/third_party/ffmpeg/libavformat/tls_securetransport.c index 3250b230517..b0cfab1e239 100644 --- a/chromium/third_party/ffmpeg/libavformat/tls_securetransport.c +++ b/chromium/third_party/ffmpeg/libavformat/tls_securetransport.c @@ -396,6 +396,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), { NULL } @@ -415,6 +421,7 @@ const URLProtocol ff_tls_protocol = { .url_write = tls_write, .url_close = tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class, diff --git a/chromium/third_party/ffmpeg/libavformat/tta.c b/chromium/third_party/ffmpeg/libavformat/tta.c index 467c24455c1..70e98b2937d 100644 --- a/chromium/third_party/ffmpeg/libavformat/tta.c +++ b/chromium/third_party/ffmpeg/libavformat/tta.c @@ -155,15 +155,15 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) if (c->currentframe >= c->totalframes) return AVERROR_EOF; - if (st->nb_index_entries < c->totalframes) { + if (st->internal->nb_index_entries < c->totalframes) { av_log(s, AV_LOG_ERROR, "Index entry disappeared\n"); return AVERROR_INVALIDDATA; } - size = st->index_entries[c->currentframe].size; + size = st->internal->index_entries[c->currentframe].size; ret = av_get_packet(s->pb, pkt, size); - pkt->dts = st->index_entries[c->currentframe++].timestamp; + pkt->dts = st->internal->index_entries[c->currentframe++].timestamp; pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size : c->frame_size; return ret; @@ -176,7 +176,7 @@ static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if (index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; c->currentframe = index; diff --git a/chromium/third_party/ffmpeg/libavformat/udp.c b/chromium/third_party/ffmpeg/libavformat/udp.c index 30d80414337..13c346a6a91 100644 --- a/chromium/third_party/ffmpeg/libavformat/udp.c +++ b/chromium/third_party/ffmpeg/libavformat/udp.c @@ -138,7 +138,7 @@ static const AVOption options[] = { { "connect", "set if connect() should be called on socket", OFFSET(is_connected), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E }, { "fifo_size", "set the UDP receiving circular buffer size, expressed as a number of packets with size of 188 bytes", OFFSET(circular_buffer_size), AV_OPT_TYPE_INT, {.i64 = 7*4096}, 0, INT_MAX, D }, { "overrun_nonfatal", "survive in case of UDP receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D }, - { "timeout", "set raise error timeout (only in read mode)", OFFSET(timeout), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D }, + { "timeout", "set raise error timeout, in microseconds (only in read mode)",OFFSET(timeout), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D }, { "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { NULL } @@ -190,7 +190,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct soc if (local_addr) mreq.imr_interface= ((struct sockaddr_in *)local_addr)->sin_addr; else - mreq.imr_interface.s_addr= INADDR_ANY; + mreq.imr_interface.s_addr = INADDR_ANY; if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP)"); return -1; @@ -203,7 +203,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct soc memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); //TODO: Interface index should be looked up from local_addr - mreq6.ipv6mr_interface= 0; + mreq6.ipv6mr_interface = 0; if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP)"); return -1; @@ -221,9 +221,9 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct so mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; if (local_addr) - mreq.imr_interface= ((struct sockaddr_in *)local_addr)->sin_addr; + mreq.imr_interface = ((struct sockaddr_in *)local_addr)->sin_addr; else - mreq.imr_interface.s_addr= INADDR_ANY; + mreq.imr_interface.s_addr = INADDR_ANY; if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP)"); return -1; @@ -236,7 +236,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct so memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); //TODO: Interface index should be looked up from local_addr - mreq6.ipv6mr_interface= 0; + mreq6.ipv6mr_interface = 0; if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP)"); return -1; @@ -295,9 +295,9 @@ static int udp_set_multicast_sources(URLContext *h, mreqs.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; if (local_addr) - mreqs.imr_interface= ((struct sockaddr_in *)local_addr)->sin_addr; + mreqs.imr_interface = ((struct sockaddr_in *)local_addr)->sin_addr; else - mreqs.imr_interface.s_addr= INADDR_ANY; + mreqs.imr_interface.s_addr = INADDR_ANY; mreqs.imr_sourceaddr.s_addr = ((struct sockaddr_in *)&sources[i])->sin_addr.s_addr; if (setsockopt(sockfd, IPPROTO_IP, @@ -545,7 +545,7 @@ static void *circular_buffer_task_tx( void *_URLContext) uint8_t tmp[4]; int64_t timestamp; - len=av_fifo_size(s->fifo); + len = av_fifo_size(s->fifo); while (len<4) { if (s->close_req) @@ -553,11 +553,11 @@ static void *circular_buffer_task_tx( void *_URLContext) if (pthread_cond_wait(&s->cond, &s->mutex) < 0) { goto end; } - len=av_fifo_size(s->fifo); + len = av_fifo_size(s->fifo); } av_fifo_generic_read(s->fifo, tmp, 4, NULL); - len=AV_RL32(tmp); + len = AV_RL32(tmp); av_assert0(len >= 0); av_assert0(len <= sizeof(s->tmp)); @@ -650,9 +650,6 @@ static int udp_open(URLContext *h, const char *uri, int flags) goto fail; } - if (s->pkt_size > 0) - h->max_packet_size = s->pkt_size; - p = strchr(uri, '?'); if (p) { if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) { @@ -956,10 +953,10 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) uint8_t tmp[4]; av_fifo_generic_read(s->fifo, tmp, 4, NULL); - avail= AV_RL32(tmp); + avail = AV_RL32(tmp); if(avail > size){ av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n"); - avail= size; + avail = size; } av_fifo_generic_read(s->fifo, buf, avail, NULL); @@ -973,8 +970,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) } else if(nonblock) { pthread_mutex_unlock(&s->mutex); return AVERROR(EAGAIN); - } - else { + } else { /* FIXME: using the monotonic clock would be better, but it does not exist on all supported platforms. */ int64_t t = av_gettime() + 100000; @@ -987,7 +983,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) } nonblock = 1; } - } while( 1); + } while(1); } #endif @@ -1020,7 +1016,7 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size) Here we can't know on which packet error was, but it needs to know that error exists. */ if (s->circular_buffer_error<0) { - int err=s->circular_buffer_error; + int err = s->circular_buffer_error; pthread_mutex_unlock(&s->mutex); return err; } diff --git a/chromium/third_party/ffmpeg/libavformat/url.c b/chromium/third_party/ffmpeg/libavformat/url.c index 3c858f0257c..6db4b4e1ae4 100644 --- a/chromium/third_party/ffmpeg/libavformat/url.c +++ b/chromium/third_party/ffmpeg/libavformat/url.c @@ -97,7 +97,7 @@ int ff_url_decompose(URLComponents *uc, const char *url, const char *end) /* scheme */ uc->scheme = cur; - p = find_delim(":/", cur, end); /* lavf "schemes" can contain options */ + p = find_delim(":/?#", cur, end); /* lavf "schemes" can contain options but not some RFC 3986 delimiters */ if (*p == ':') cur = p + 1; diff --git a/chromium/third_party/ffmpeg/libavformat/utils.c b/chromium/third_party/ffmpeg/libavformat/utils.c index 5a9247289fd..e1172130cbc 100644 --- a/chromium/third_party/ffmpeg/libavformat/utils.c +++ b/chromium/third_party/ffmpeg/libavformat/utils.c @@ -101,13 +101,13 @@ static int is_relative(int64_t ts) { */ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) { - if (st->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && - st->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { - if (st->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && - timestamp < st->pts_wrap_reference) + if (st->internal->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && + st->internal->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { + if (st->internal->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && + timestamp < st->internal->pts_wrap_reference) return timestamp + (1ULL << st->pts_wrap_bits); - else if (st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && - timestamp >= st->pts_wrap_reference) + else if (st->internal->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && + timestamp >= st->internal->pts_wrap_reference) return timestamp - (1ULL << st->pts_wrap_bits); } return timestamp; @@ -153,7 +153,7 @@ void av_format_inject_global_side_data(AVFormatContext *s) s->internal->inject_global_side_data = 1; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - st->inject_global_side_data = 1; + st->internal->inject_global_side_data = 1; } } @@ -253,9 +253,11 @@ int ffio_limit(AVIOContext *s, int size) remaining= FFMAX(remaining, 0); } - if (s->maxsize>= 0 && remaining+1 < size) { - av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG, "Truncating packet of size %d to %"PRId64"\n", size, remaining+1); - size = remaining+1; + if (s->maxsize >= 0 && remaining < size && size > 1) { + av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG, + "Truncating packet of size %d to %"PRId64"\n", + size, remaining + !remaining); + size = remaining + !remaining; } } return size; @@ -365,7 +367,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) continue; - if (st->request_probe > score && + if (st->internal->request_probe > score && st->codecpar->codec_id != fmt_id_type[i].id) continue; st->codecpar->codec_id = fmt_id_type[i].id; @@ -675,8 +677,8 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { - if (st->request_probe>0) { - AVProbeData *pd = &st->probe_data; + if (st->internal->request_probe>0) { + AVProbeData *pd = &st->internal->probe_data; int end; av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets); --st->probe_packets; @@ -711,7 +713,7 @@ no_packet: || end) { pd->buf_size = 0; av_freep(&pd->buf); - st->request_probe = -1; + st->internal->request_probe = -1; if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); } else @@ -732,7 +734,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (ref == AV_NOPTS_VALUE) ref = pkt->pts; - if (st->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) + if (st->internal->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) return 0; ref &= (1LL << st->pts_wrap_bits)-1; @@ -747,17 +749,17 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (!first_program) { int default_stream_index = av_find_default_stream_index(s); - if (s->streams[default_stream_index]->pts_wrap_reference == AV_NOPTS_VALUE) { + if (s->streams[default_stream_index]->internal->pts_wrap_reference == AV_NOPTS_VALUE) { for (i = 0; i < s->nb_streams; i++) { if (av_find_program_from_stream(s, NULL, i)) continue; - s->streams[i]->pts_wrap_reference = pts_wrap_reference; - s->streams[i]->pts_wrap_behavior = pts_wrap_behavior; + s->streams[i]->internal->pts_wrap_reference = pts_wrap_reference; + s->streams[i]->internal->pts_wrap_behavior = pts_wrap_behavior; } } else { - st->pts_wrap_reference = s->streams[default_stream_index]->pts_wrap_reference; - st->pts_wrap_behavior = s->streams[default_stream_index]->pts_wrap_behavior; + st->internal->pts_wrap_reference = s->streams[default_stream_index]->internal->pts_wrap_reference; + st->internal->pts_wrap_behavior = s->streams[default_stream_index]->internal->pts_wrap_behavior; } } else { @@ -776,8 +778,8 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in while (program) { if (program->pts_wrap_reference != pts_wrap_reference) { for (i = 0; i<program->nb_stream_indexes; i++) { - s->streams[program->stream_index[i]]->pts_wrap_reference = pts_wrap_reference; - s->streams[program->stream_index[i]]->pts_wrap_behavior = pts_wrap_behavior; + s->streams[program->stream_index[i]]->internal->pts_wrap_reference = pts_wrap_reference; + s->streams[program->stream_index[i]]->internal->pts_wrap_behavior = pts_wrap_behavior; } program->pts_wrap_reference = pts_wrap_reference; @@ -807,7 +809,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (s->internal->raw_packet_buffer_remaining_size <= 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; - if (st->request_probe <= 0) { + if (st->internal->request_probe <= 0) { avpriv_packet_list_get(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, pkt); s->internal->raw_packet_buffer_remaining_size += pkt->size; @@ -828,10 +830,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->probe_packets || st->request_probe > 0) + if (st->probe_packets || st->internal->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; - av_assert0(st->request_probe <= 0); + av_assert0(st->internal->request_probe <= 0); } continue; } @@ -859,7 +861,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) st = s->streams[pkt->stream_index]; - if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { + if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->internal->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { // correct first time stamps to negative values if (!is_relative(st->first_dts)) st->first_dts = wrap_timestamp(st, st->first_dts); @@ -878,7 +880,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (s->use_wallclock_as_timestamps) pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); - if (!pktl && st->request_probe <= 0) + if (!pktl && st->internal->request_probe <= 0) return ret; err = avpriv_packet_list_put(&s->internal->raw_packet_buffer, @@ -992,7 +994,7 @@ int ff_is_intra_only(enum AVCodecID id) static int has_decode_delay_been_guessed(AVStream *st) { if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; - if (!st->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy + if (!st->internal->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy return 1; #if CONFIG_H264_DECODER if (st->internal->avctx->has_b_frames && @@ -1000,11 +1002,11 @@ static int has_decode_delay_been_guessed(AVStream *st) return 1; #endif if (st->internal->avctx->has_b_frames<3) - return st->nb_decoded_frames >= 7; + return st->internal->nb_decoded_frames >= 7; else if (st->internal->avctx->has_b_frames<4) - return st->nb_decoded_frames >= 18; + return st->internal->nb_decoded_frames >= 18; else - return st->nb_decoded_frames >= 20; + return st->internal->nb_decoded_frames >= 20; } static AVPacketList *get_next_pkt(AVFormatContext *s, AVStream *st, AVPacketList *pktl) @@ -1027,8 +1029,8 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t if (dts == AV_NOPTS_VALUE) { int64_t best_score = INT64_MAX; for (i = 0; i<delay; i++) { - if (st->pts_reorder_error_count[i]) { - int64_t score = st->pts_reorder_error[i] / st->pts_reorder_error_count[i]; + if (st->internal->pts_reorder_error_count[i]) { + int64_t score = st->internal->pts_reorder_error[i] / st->internal->pts_reorder_error_count[i]; if (score < best_score) { best_score = score; dts = pts_buffer[i]; @@ -1039,13 +1041,13 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t for (i = 0; i<delay; i++) { if (pts_buffer[i] != AV_NOPTS_VALUE) { int64_t diff = FFABS(pts_buffer[i] - dts) - + (uint64_t)st->pts_reorder_error[i]; - diff = FFMAX(diff, st->pts_reorder_error[i]); - st->pts_reorder_error[i] = diff; - st->pts_reorder_error_count[i]++; - if (st->pts_reorder_error_count[i] > 250) { - st->pts_reorder_error[i] >>= 1; - st->pts_reorder_error_count[i] >>= 1; + + (uint64_t)st->internal->pts_reorder_error[i]; + diff = FFMAX(diff, st->internal->pts_reorder_error[i]); + st->internal->pts_reorder_error[i] = diff; + st->internal->pts_reorder_error_count[i]++; + if (st->internal->pts_reorder_error_count[i] > 250) { + st->internal->pts_reorder_error[i] >>= 1; + st->internal->pts_reorder_error_count[i] >>= 1; } } } @@ -1123,7 +1125,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { st->start_time = pktl_it->pkt.pts; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->internal->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); } } @@ -1136,7 +1138,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, st->start_time = pts; } if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->internal->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); } } @@ -1147,9 +1149,9 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, int64_t cur_dts = RELATIVE_TS_BASE; if (st->first_dts != AV_NOPTS_VALUE) { - if (st->update_initial_durations_done) + if (st->internal->update_initial_durations_done) return; - st->update_initial_durations_done = 1; + st->internal->update_initial_durations_done = 1; cur_dts = st->first_dts; for (; pktl; pktl = get_next_pkt(s, st, pktl)) { if (pktl->pkt.stream_index == stream_index) { @@ -1186,8 +1188,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, pktl->pkt.dts = cur_dts; if (!st->internal->avctx->has_b_frames) pktl->pkt.pts = cur_dts; -// if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) - pktl->pkt.duration = duration; + pktl->pkt.duration = duration; } else break; cur_dts = pktl->pkt.dts + pktl->pkt.duration; @@ -1210,24 +1211,24 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, return; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { - if (pkt->dts == pkt->pts && st->last_dts_for_order_check != AV_NOPTS_VALUE) { - if (st->last_dts_for_order_check <= pkt->dts) { - st->dts_ordered++; + if (pkt->dts == pkt->pts && st->internal->last_dts_for_order_check != AV_NOPTS_VALUE) { + if (st->internal->last_dts_for_order_check <= pkt->dts) { + st->internal->dts_ordered++; } else { - av_log(s, st->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, + av_log(s, st->internal->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, "DTS %"PRIi64" < %"PRIi64" out of order\n", pkt->dts, - st->last_dts_for_order_check); - st->dts_misordered++; + st->internal->last_dts_for_order_check); + st->internal->dts_misordered++; } - if (st->dts_ordered + st->dts_misordered > 250) { - st->dts_ordered >>= 1; - st->dts_misordered >>= 1; + if (st->internal->dts_ordered + st->internal->dts_misordered > 250) { + st->internal->dts_ordered >>= 1; + st->internal->dts_misordered >>= 1; } } - st->last_dts_for_order_check = pkt->dts; - if (st->dts_ordered < 8*st->dts_misordered && pkt->dts == pkt->pts) + st->internal->last_dts_for_order_check = pkt->dts; + if (st->internal->dts_ordered < 8*st->internal->dts_misordered && pkt->dts == pkt->pts) pkt->dts = AV_NOPTS_VALUE; } @@ -1358,12 +1359,12 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - st->pts_buffer[0] = pkt->pts; - for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]); + st->internal->pts_buffer[0] = pkt->pts; + for (i = 0; i<delay && st->internal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); if(has_decode_delay_been_guessed(st)) - pkt->dts = select_from_pts_buffer(st, st->pts_buffer, pkt->dts); + pkt->dts = select_from_pts_buffer(st, st->internal->pts_buffer, pkt->dts); } // We skipped it above so we try here. if (!onein_oneout) @@ -1535,12 +1536,14 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) ret = 0; st = s->streams[pkt->stream_index]; + st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; + /* update context if required */ if (st->internal->need_context_update) { if (avcodec_is_open(st->internal->avctx)) { av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); avcodec_close(st->internal->avctx); - st->info->found_decoder = 0; + st->internal->info->found_decoder = 0; } /* close parser, because it depends on the codec */ @@ -1626,8 +1629,8 @@ FF_ENABLE_DEPRECATION_WARNINGS av_packet_unref(pkt); } if (pkt->flags & AV_PKT_FLAG_KEY) - st->skip_to_keyframe = 0; - if (st->skip_to_keyframe) { + st->internal->skip_to_keyframe = 0; + if (st->internal->skip_to_keyframe) { av_packet_unref(pkt); got_packet = 0; } @@ -1639,28 +1642,28 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; int discard_padding = 0; - if (st->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { + if (st->internal->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); int64_t sample = ts_to_samples(st, pts); int duration = ts_to_samples(st, pkt->duration); int64_t end_sample = sample + duration; - if (duration > 0 && end_sample >= st->first_discard_sample && - sample < st->last_discard_sample) - discard_padding = FFMIN(end_sample - st->first_discard_sample, duration); + if (duration > 0 && end_sample >= st->internal->first_discard_sample && + sample < st->internal->last_discard_sample) + discard_padding = FFMIN(end_sample - st->internal->first_discard_sample, duration); } - if (st->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) - st->skip_samples = st->start_skip_samples; - if (st->skip_samples || discard_padding) { + if (st->internal->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) + st->internal->skip_samples = st->internal->start_skip_samples; + if (st->internal->skip_samples || discard_padding) { uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if (p) { - AV_WL32(p, st->skip_samples); + AV_WL32(p, st->internal->skip_samples); AV_WL32(p + 4, discard_padding); - av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", st->skip_samples, discard_padding); + av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", st->internal->skip_samples, discard_padding); } - st->skip_samples = 0; + st->internal->skip_samples = 0; } - if (st->inject_global_side_data) { + if (st->internal->inject_global_side_data) { for (i = 0; i < st->nb_side_data; i++) { AVPacketSideData *src_sd = &st->side_data[i]; uint8_t *dst_data; @@ -1676,7 +1679,7 @@ FF_ENABLE_DEPRECATION_WARNINGS memcpy(dst_data, src_sd->data, src_sd->size); } - st->inject_global_side_data = 0; + st->internal->inject_global_side_data = 0; } } @@ -1876,7 +1879,7 @@ void ff_read_frame_flush(AVFormatContext *s) st->parser = NULL; } st->last_IP_pts = AV_NOPTS_VALUE; - st->last_dts_for_order_check = AV_NOPTS_VALUE; + st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; if (st->first_dts == AV_NOPTS_VALUE) st->cur_dts = RELATIVE_TS_BASE; else @@ -1886,12 +1889,12 @@ void ff_read_frame_flush(AVFormatContext *s) st->probe_packets = s->max_probe_packets; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) - st->pts_buffer[j] = AV_NOPTS_VALUE; + st->internal->pts_buffer[j] = AV_NOPTS_VALUE; if (s->internal->inject_global_side_data) - st->inject_global_side_data = 1; + st->internal->inject_global_side_data = 1; - st->skip_samples = 0; + st->internal->skip_samples = 0; } } @@ -1914,11 +1917,11 @@ void ff_reduce_index(AVFormatContext *s, int stream_index) AVStream *st = s->streams[stream_index]; unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry); - if ((unsigned) st->nb_index_entries >= max_entries) { + if ((unsigned) st->internal->nb_index_entries >= max_entries) { int i; - for (i = 0; 2 * i < st->nb_index_entries; i++) - st->index_entries[i] = st->index_entries[2 * i]; - st->nb_index_entries = i; + for (i = 0; 2 * i < st->internal->nb_index_entries; i++) + st->internal->index_entries[i] = st->internal->index_entries[2 * i]; + st->internal->nb_index_entries = i; } } @@ -1985,8 +1988,8 @@ int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { timestamp = wrap_timestamp(st, timestamp); - return ff_add_index_entry(&st->index_entries, &st->nb_index_entries, - &st->index_entries_allocated_size, pos, + return ff_add_index_entry(&st->internal->index_entries, &st->internal->nb_index_entries, + &st->internal->index_entries_allocated_size, pos, timestamp, size, distance, flags); } @@ -2062,13 +2065,13 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) if (ist1 == ist2) continue; - for (i1 = i2 = 0; i1 < st1->nb_index_entries; i1++) { - AVIndexEntry *e1 = &st1->index_entries[i1]; + for (i1 = i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { + AVIndexEntry *e1 = &st1->internal->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); skip = FFMAX(skip, e1->size); - for (; i2 < st2->nb_index_entries; i2++) { - AVIndexEntry *e2 = &st2->index_entries[i2]; + for (; i2 < st2->internal->nb_index_entries; i2++) { + AVIndexEntry *e2 = &st2->internal->index_entries[i2]; int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) continue; @@ -2100,7 +2103,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { - return ff_index_search_timestamp(st->index_entries, st->nb_index_entries, + return ff_index_search_timestamp(st->internal->index_entries, st->internal->nb_index_entries, wanted_timestamp, flags); } @@ -2133,7 +2136,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, pos_limit = -1; // GCC falsely says it may be uninitialized. st = s->streams[stream_index]; - if (st->index_entries) { + if (st->internal->index_entries) { AVIndexEntry *e; /* FIXME: Whole function must be checked for non-keyframe entries in @@ -2141,7 +2144,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); index = FFMAX(index, 0); - e = &st->index_entries[index]; + e = &st->internal->index_entries[index]; if (e->timestamp <= target_ts || e->pos == e->min_distance) { pos_min = e->pos; @@ -2154,9 +2157,9 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD); - av_assert0(index < st->nb_index_entries); + av_assert0(index < st->internal->nb_index_entries); if (index >= 0) { - e = &st->index_entries[index]; + e = &st->internal->index_entries[index]; av_assert1(e->timestamp >= target_ts); pos_max = e->pos; ts_max = e->timestamp; @@ -2357,17 +2360,17 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, timestamp, flags); - if (index < 0 && st->nb_index_entries && - timestamp < st->index_entries[0].timestamp) + if (index < 0 && st->internal->nb_index_entries && + timestamp < st->internal->index_entries[0].timestamp) return -1; - if (index < 0 || index == st->nb_index_entries - 1) { + if (index < 0 || index == st->internal->nb_index_entries - 1) { AVPacket pkt; int nonkey = 0; - if (st->nb_index_entries) { - av_assert0(st->index_entries); - ie = &st->index_entries[st->nb_index_entries - 1]; + if (st->internal->nb_index_entries) { + av_assert0(st->internal->index_entries); + ie = &st->internal->index_entries[st->internal->nb_index_entries - 1]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; ff_update_cur_dts(s, st, ie->timestamp); @@ -2404,7 +2407,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, if (s->iformat->read_seek) if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) return 0; - ie = &st->index_entries[index]; + ie = &st->internal->index_entries[index]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; ff_update_cur_dts(s, st, ie->timestamp); @@ -2813,10 +2816,10 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) else duration -= st->first_dts; if (duration > 0) { - if (st->duration == AV_NOPTS_VALUE || st->info->last_duration<= 0 || - (st->duration < duration && FFABS(duration - st->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) + if (st->duration == AV_NOPTS_VALUE || st->internal->info->last_duration<= 0 || + (st->duration < duration && FFABS(duration - st->internal->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) st->duration = duration; - st->info->last_duration = duration; + st->internal->info->last_duration = duration; } } av_packet_unref(pkt); @@ -2865,9 +2868,9 @@ skip_duration_calc: st = ic->streams[i]; st->cur_dts = st->first_dts; st->last_IP_pts = AV_NOPTS_VALUE; - st->last_dts_for_order_check = AV_NOPTS_VALUE; + st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) - st->pts_buffer[j] = AV_NOPTS_VALUE; + st->internal->pts_buffer[j] = AV_NOPTS_VALUE; } } @@ -2953,20 +2956,20 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) case AVMEDIA_TYPE_AUDIO: if (!avctx->frame_size && determinable_frame_size(avctx)) FAIL("unspecified frame size"); - if (st->info->found_decoder >= 0 && + if (st->internal->info->found_decoder >= 0 && avctx->sample_fmt == AV_SAMPLE_FMT_NONE) FAIL("unspecified sample format"); if (!avctx->sample_rate) FAIL("unspecified sample rate"); if (!avctx->channels) FAIL("unspecified number of channels"); - if (st->info->found_decoder >= 0 && !st->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) + if (st->internal->info->found_decoder >= 0 && !st->internal->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) FAIL("no decodable DTS frames"); break; case AVMEDIA_TYPE_VIDEO: if (!avctx->width) FAIL("unspecified size"); - if (st->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) + if (st->internal->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) FAIL("unspecified pixel format"); if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !st->codec_info_nb_frames) @@ -3000,14 +3003,14 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, return AVERROR(ENOMEM); if (!avcodec_is_open(avctx) && - st->info->found_decoder <= 0 && - (st->codecpar->codec_id != -st->info->found_decoder || !st->codecpar->codec_id)) { + st->internal->info->found_decoder <= 0 && + (st->codecpar->codec_id != -st->internal->info->found_decoder || !st->codecpar->codec_id)) { AVDictionary *thread_opt = NULL; codec = find_probe_decoder(s, st, st->codecpar->codec_id); if (!codec) { - st->info->found_decoder = -st->codecpar->codec_id; + st->internal->info->found_decoder = -st->codecpar->codec_id; ret = -1; goto fail; } @@ -3021,14 +3024,14 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, if (!options) av_dict_free(&thread_opt); if (ret < 0) { - st->info->found_decoder = -avctx->codec_id; + st->internal->info->found_decoder = -avctx->codec_id; goto fail; } - st->info->found_decoder = 1; - } else if (!st->info->found_decoder) - st->info->found_decoder = 1; + st->internal->info->found_decoder = 1; + } else if (!st->internal->info->found_decoder) + st->internal->info->found_decoder = 1; - if (st->info->found_decoder < 0) { + if (st->internal->info->found_decoder < 0) { ret = -1; goto fail; } @@ -3067,7 +3070,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, } if (ret >= 0) { if (got_picture) - st->nb_decoded_frames++; + st->internal->nb_decoded_frames++; ret = got_picture; } } @@ -3294,59 +3297,59 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) { int i, j; - int64_t last = st->info->last_dts; + int64_t last = st->internal->info->last_dts; if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last && ts - (uint64_t)last < INT64_MAX) { double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); int64_t duration = ts - last; - if (!st->info->duration_error) - st->info->duration_error = av_mallocz(sizeof(st->info->duration_error[0])*2); - if (!st->info->duration_error) + if (!st->internal->info->duration_error) + st->internal->info->duration_error = av_mallocz(sizeof(st->internal->info->duration_error[0])*2); + if (!st->internal->info->duration_error) return AVERROR(ENOMEM); // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); for (i = 0; i<MAX_STD_TIMEBASES; i++) { - if (st->info->duration_error[0][1][i] < 1e10) { + if (st->internal->info->duration_error[0][1][i] < 1e10) { int framerate = get_std_framerate(i); double sdts = dts*framerate/(1001*12); for (j= 0; j<2; j++) { int64_t ticks = llrint(sdts+j*0.5); double error= sdts - ticks + j*0.5; - st->info->duration_error[j][0][i] += error; - st->info->duration_error[j][1][i] += error*error; + st->internal->info->duration_error[j][0][i] += error; + st->internal->info->duration_error[j][1][i] += error*error; } } } - if (st->info->rfps_duration_sum <= INT64_MAX - duration) { - st->info->duration_count++; - st->info->rfps_duration_sum += duration; + if (st->internal->info->rfps_duration_sum <= INT64_MAX - duration) { + st->internal->info->duration_count++; + st->internal->info->rfps_duration_sum += duration; } - if (st->info->duration_count % 10 == 0) { - int n = st->info->duration_count; + if (st->internal->info->duration_count % 10 == 0) { + int n = st->internal->info->duration_count; for (i = 0; i<MAX_STD_TIMEBASES; i++) { - if (st->info->duration_error[0][1][i] < 1e10) { - double a0 = st->info->duration_error[0][0][i] / n; - double error0 = st->info->duration_error[0][1][i] / n - a0*a0; - double a1 = st->info->duration_error[1][0][i] / n; - double error1 = st->info->duration_error[1][1][i] / n - a1*a1; + if (st->internal->info->duration_error[0][1][i] < 1e10) { + double a0 = st->internal->info->duration_error[0][0][i] / n; + double error0 = st->internal->info->duration_error[0][1][i] / n - a0*a0; + double a1 = st->internal->info->duration_error[1][0][i] / n; + double error1 = st->internal->info->duration_error[1][1][i] / n - a1*a1; if (error0 > 0.04 && error1 > 0.04) { - st->info->duration_error[0][1][i] = 2e10; - st->info->duration_error[1][1][i] = 2e10; + st->internal->info->duration_error[0][1][i] = 2e10; + st->internal->info->duration_error[1][1][i] = 2e10; } } } } // ignore the first 4 values, they might have some random jitter - if (st->info->duration_count > 3 && is_relative(ts) == is_relative(last)) - st->info->duration_gcd = av_gcd(st->info->duration_gcd, duration); + if (st->internal->info->duration_count > 3 && is_relative(ts) == is_relative(last)) + st->internal->info->duration_gcd = av_gcd(st->internal->info->duration_gcd, duration); } if (ts != AV_NOPTS_VALUE) - st->info->last_dts = ts; + st->internal->info->last_dts = ts; return 0; } @@ -3363,9 +3366,9 @@ void ff_rfps_calculate(AVFormatContext *ic) // the check for tb_unreliable() is not completely correct, since this is not about handling // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. // ipmovie.c produces. - if (tb_unreliable(st->internal->avctx) && st->info->duration_count > 15 && st->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num) - av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX); - if (st->info->duration_count>1 && !st->r_frame_rate.num + if (tb_unreliable(st->internal->avctx) && st->internal->info->duration_count > 15 && st->internal->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num) + av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->internal->info->duration_gcd, INT_MAX); + if (st->internal->info->duration_count>1 && !st->r_frame_rate.num && tb_unreliable(st->internal->avctx)) { int num = 0; double best_error= 0.01; @@ -3374,19 +3377,19 @@ void ff_rfps_calculate(AVFormatContext *ic) for (j= 0; j<MAX_STD_TIMEBASES; j++) { int k; - if (st->info->codec_info_duration && - st->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) + if (st->internal->info->codec_info_duration && + st->internal->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) continue; - if (!st->info->codec_info_duration && get_std_framerate(j) < 1001*12) + if (!st->internal->info->codec_info_duration && get_std_framerate(j) < 1001*12) continue; - if (av_q2d(st->time_base) * st->info->rfps_duration_sum / st->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) + if (av_q2d(st->time_base) * st->internal->info->rfps_duration_sum / st->internal->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) continue; for (k= 0; k<2; k++) { - int n = st->info->duration_count; - double a= st->info->duration_error[k][0][j] / n; - double error= st->info->duration_error[k][1][j]/n - a*a; + int n = st->internal->info->duration_count; + double a= st->internal->info->duration_error[k][0][j] / n; + double error= st->internal->info->duration_error[k][1][j]/n - a*a; if (error < best_error && best_error> 0.000000001) { best_error= error; @@ -3401,19 +3404,19 @@ void ff_rfps_calculate(AVFormatContext *ic) av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); } if ( !st->avg_frame_rate.num - && st->r_frame_rate.num && st->info->rfps_duration_sum - && st->info->codec_info_duration <= 0 - && st->info->duration_count > 2 - && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - st->info->rfps_duration_sum / (double)st->info->duration_count) <= 1.0 + && st->r_frame_rate.num && st->internal->info->rfps_duration_sum + && st->internal->info->codec_info_duration <= 0 + && st->internal->info->duration_count > 2 + && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - st->internal->info->rfps_duration_sum / (double)st->internal->info->duration_count) <= 1.0 ) { av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); st->avg_frame_rate = st->r_frame_rate; } - av_freep(&st->info->duration_error); - st->info->last_dts = AV_NOPTS_VALUE; - st->info->duration_count = 0; - st->info->rfps_duration_sum = 0; + av_freep(&st->internal->info->duration_error); + st->internal->info->last_dts = AV_NOPTS_VALUE; + st->internal->info->duration_count = 0; + st->internal->info->rfps_duration_sum = 0; } } @@ -3607,7 +3610,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif // only for the split stuff - if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->request_probe <= 0) { + if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->internal->request_probe <= 0) { st->parser = av_parser_init(st->codecpar->codec_id); if (st->parser) { if (st->need_parsing == AVSTREAM_PARSE_HEADERS) { @@ -3628,7 +3631,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ret = avcodec_parameters_to_context(avctx, st->codecpar); if (ret < 0) goto find_stream_info_err; - if (st->request_probe <= 0) + if (st->internal->request_probe <= 0) st->internal->avctx_inited = 1; codec = find_probe_decoder(ic, st, st->codecpar->codec_id); @@ -3649,7 +3652,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } // Try to just open decoders, in case this is enough to get parameters. - if (!has_codec_parameters(st, NULL) && st->request_probe <= 0) { + if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0) { if (codec && !avctx->codec) if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) av_log(ic, AV_LOG_WARNING, @@ -3661,10 +3664,10 @@ FF_ENABLE_DEPRECATION_WARNINGS for (i = 0; i < ic->nb_streams; i++) { #if FF_API_R_FRAME_RATE - ic->streams[i]->info->last_dts = AV_NOPTS_VALUE; + ic->streams[i]->internal->info->last_dts = AV_NOPTS_VALUE; #endif - ic->streams[i]->info->fps_first_dts = AV_NOPTS_VALUE; - ic->streams[i]->info->fps_last_dts = AV_NOPTS_VALUE; + ic->streams[i]->internal->info->fps_first_dts = AV_NOPTS_VALUE; + ic->streams[i]->internal->info->fps_last_dts = AV_NOPTS_VALUE; } read_size = 0; @@ -3698,8 +3701,8 @@ FF_ENABLE_DEPRECATION_WARNINGS fps_analyze_framecount = 0; /* variable fps and no guess at the real fps */ count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? - st->info->codec_info_duration_fields/2 : - st->info->duration_count; + st->internal->info->codec_info_duration_fields/2 : + st->internal->info->duration_count; if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (count < fps_analyze_framecount) @@ -3707,7 +3710,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } // Look at the first 3 frames if there is evidence of frame delay // but the decoder delay is not set. - if (st->info->frame_delay_evidence && count < 2 && st->internal->avctx->has_b_frames == 0) + if (st->internal->info->frame_delay_evidence && count < 2 && st->internal->avctx->has_b_frames == 0) break; if (!st->internal->avctx->extradata && (!st->internal->extract_extradata.inited || @@ -3742,7 +3745,7 @@ FF_ENABLE_DEPRECATION_WARNINGS "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); for (i = 0; i < ic->nb_streams; i++) if (!ic->streams[i]->r_frame_rate.num && - ic->streams[i]->info->duration_count <= 1 && + ic->streams[i]->internal->info->duration_count <= 1 && ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && strcmp(ic->iformat->name, "image2")) av_log(ic, AV_LOG_WARNING, @@ -3789,57 +3792,57 @@ FF_ENABLE_DEPRECATION_WARNINGS if (pkt->dts != AV_NOPTS_VALUE && st->codec_info_nb_frames > 1) { /* check for non-increasing dts */ - if (st->info->fps_last_dts != AV_NOPTS_VALUE && - st->info->fps_last_dts >= pkt->dts) { + if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && + st->internal->info->fps_last_dts >= pkt->dts) { av_log(ic, AV_LOG_DEBUG, "Non-increasing DTS in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, st->info->fps_last_dts_idx, - st->info->fps_last_dts, st->codec_info_nb_frames, + st->index, st->internal->info->fps_last_dts_idx, + st->internal->info->fps_last_dts, st->codec_info_nb_frames, pkt->dts); - st->info->fps_first_dts = - st->info->fps_last_dts = AV_NOPTS_VALUE; + st->internal->info->fps_first_dts = + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; } /* Check for a discontinuity in dts. If the difference in dts * is more than 1000 times the average packet duration in the * sequence, we treat it as a discontinuity. */ - if (st->info->fps_last_dts != AV_NOPTS_VALUE && - st->info->fps_last_dts_idx > st->info->fps_first_dts_idx && - (pkt->dts - (uint64_t)st->info->fps_last_dts) / 1000 > - (st->info->fps_last_dts - (uint64_t)st->info->fps_first_dts) / - (st->info->fps_last_dts_idx - st->info->fps_first_dts_idx)) { + if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && + st->internal->info->fps_last_dts_idx > st->internal->info->fps_first_dts_idx && + (pkt->dts - (uint64_t)st->internal->info->fps_last_dts) / 1000 > + (st->internal->info->fps_last_dts - (uint64_t)st->internal->info->fps_first_dts) / + (st->internal->info->fps_last_dts_idx - st->internal->info->fps_first_dts_idx)) { av_log(ic, AV_LOG_WARNING, "DTS discontinuity in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, st->info->fps_last_dts_idx, - st->info->fps_last_dts, st->codec_info_nb_frames, + st->index, st->internal->info->fps_last_dts_idx, + st->internal->info->fps_last_dts, st->codec_info_nb_frames, pkt->dts); - st->info->fps_first_dts = - st->info->fps_last_dts = AV_NOPTS_VALUE; + st->internal->info->fps_first_dts = + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; } /* update stored dts values */ - if (st->info->fps_first_dts == AV_NOPTS_VALUE) { - st->info->fps_first_dts = pkt->dts; - st->info->fps_first_dts_idx = st->codec_info_nb_frames; + if (st->internal->info->fps_first_dts == AV_NOPTS_VALUE) { + st->internal->info->fps_first_dts = pkt->dts; + st->internal->info->fps_first_dts_idx = st->codec_info_nb_frames; } - st->info->fps_last_dts = pkt->dts; - st->info->fps_last_dts_idx = st->codec_info_nb_frames; + st->internal->info->fps_last_dts = pkt->dts; + st->internal->info->fps_last_dts_idx = st->codec_info_nb_frames; } if (st->codec_info_nb_frames>1) { int64_t t = 0; int64_t limit; if (st->time_base.den > 0) - t = av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); + t = av_rescale_q(st->internal->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); if (st->avg_frame_rate.num > 0) t = FFMAX(t, av_rescale_q(st->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); if ( t == 0 && st->codec_info_nb_frames>30 - && st->info->fps_first_dts != AV_NOPTS_VALUE - && st->info->fps_last_dts != AV_NOPTS_VALUE) - t = FFMAX(t, av_rescale_q(st->info->fps_last_dts - st->info->fps_first_dts, st->time_base, AV_TIME_BASE_Q)); + && st->internal->info->fps_first_dts != AV_NOPTS_VALUE + && st->internal->info->fps_last_dts != AV_NOPTS_VALUE) + t = FFMAX(t, av_rescale_q(st->internal->info->fps_last_dts - st->internal->info->fps_first_dts, st->time_base, AV_TIME_BASE_Q)); if (analyzed_all_streams) limit = max_analyze_duration; else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; @@ -3855,10 +3858,10 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (pkt->duration) { if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time) { - st->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->info->codec_info_duration + pkt->duration); + st->internal->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->internal->info->codec_info_duration + pkt->duration); } else - st->info->codec_info_duration += pkt->duration; - st->info->codec_info_duration_fields += st->parser && st->need_parsing && avctx->ticks_per_frame ==2 ? st->parser->repeat_pict + 1 : 2; + st->internal->info->codec_info_duration += pkt->duration; + st->internal->info->codec_info_duration_fields += st->parser && st->need_parsing && avctx->ticks_per_frame ==2 ? st->parser->repeat_pict + 1 : 2; } } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -3866,7 +3869,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ff_rfps_add_frame(ic, st, pkt->dts); #endif if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) - st->info->frame_delay_evidence = 1; + st->internal->info->frame_delay_evidence = 1; } if (!st->internal->avctx->extradata) { ret = extract_extradata(st, pkt); @@ -3929,7 +3932,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st = ic->streams[i]; /* flush the decoders */ - if (st->info->found_decoder == 1) { + if (st->internal->info->found_decoder == 1) { do { err = try_decode_frame(ic, st, &empty_pkt, (options && i < orig_nb_streams) @@ -3957,20 +3960,20 @@ FF_ENABLE_DEPRECATION_WARNINGS } /* estimate average framerate if not set by demuxer */ - if (st->info->codec_info_duration_fields && + if (st->internal->info->codec_info_duration_fields && !st->avg_frame_rate.num && - st->info->codec_info_duration) { + st->internal->info->codec_info_duration) { int best_fps = 0; double best_error = 0.01; AVRational codec_frame_rate = avctx->framerate; - if (st->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| - st->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || - st->info->codec_info_duration < 0) + if (st->internal->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| + st->internal->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || + st->internal->info->codec_info_duration < 0) continue; av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, - st->info->codec_info_duration_fields * (int64_t) st->time_base.den, - st->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); + st->internal->info->codec_info_duration_fields * (int64_t) st->time_base.den, + st->internal->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); /* Round guessed framerate to a "standard" framerate if it's * within 1% of the original estimate. */ @@ -4008,9 +4011,9 @@ FF_ENABLE_DEPRECATION_WARNINGS st->r_frame_rate.den = st->time_base.num; } } - if (st->display_aspect_ratio.num && st->display_aspect_ratio.den) { + if (st->internal->display_aspect_ratio.num && st->internal->display_aspect_ratio.den) { AVRational hw_ratio = { avctx->height, avctx->width }; - st->sample_aspect_ratio = av_mul_q(st->display_aspect_ratio, + st->sample_aspect_ratio = av_mul_q(st->internal->display_aspect_ratio, hw_ratio); } } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { @@ -4139,10 +4142,10 @@ FF_ENABLE_DEPRECATION_WARNINGS find_stream_info_err: for (i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; - if (st->info) - av_freep(&st->info->duration_error); + if (st->internal->info) + av_freep(&st->internal->info->duration_error); avcodec_close(ic->streams[i]->internal->avctx); - av_freep(&ic->streams[i]->info); + av_freep(&ic->streams[i]->internal->info); av_bsf_free(&ic->streams[i]->internal->extract_extradata.bsf); av_packet_free(&ic->streams[i]->internal->extract_extradata.pkt); } @@ -4342,24 +4345,26 @@ static void free_stream(AVStream **pst) avcodec_free_context(&st->internal->avctx); av_bsf_free(&st->internal->bsfc); av_freep(&st->internal->priv_pts); + av_freep(&st->internal->index_entries); + av_freep(&st->internal->probe_data.buf); + av_bsf_free(&st->internal->extract_extradata.bsf); av_packet_free(&st->internal->extract_extradata.pkt); + + if (st->internal->info) + av_freep(&st->internal->info->duration_error); + av_freep(&st->internal->info); } av_freep(&st->internal); av_dict_free(&st->metadata); avcodec_parameters_free(&st->codecpar); - av_freep(&st->probe_data.buf); - av_freep(&st->index_entries); #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS avcodec_free_context(&st->codec); FF_ENABLE_DEPRECATION_WARNINGS #endif av_freep(&st->priv_data); - if (st->info) - av_freep(&st->info->duration_error); - av_freep(&st->info); #if FF_API_LAVF_FFSERVER FF_DISABLE_DEPRECATION_WARNINGS av_freep(&st->recommended_encoder_configuration); @@ -4467,17 +4472,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st = av_mallocz(sizeof(AVStream)); if (!st) return NULL; - if (!(st->info = av_mallocz(sizeof(*st->info)))) { - av_free(st); - return NULL; - } - st->info->last_dts = AV_NOPTS_VALUE; #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS st->codec = avcodec_alloc_context3(c); if (!st->codec) { - av_free(st->info); av_free(st); return NULL; } @@ -4488,6 +4487,11 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!st->internal) goto fail; + st->internal->info = av_mallocz(sizeof(*st->internal->info)); + if (!st->internal->info) + goto fail; + st->internal->info->last_dts = AV_NOPTS_VALUE; + st->codecpar = avcodec_parameters_alloc(); if (!st->codecpar) goto fail; @@ -4520,23 +4524,23 @@ FF_ENABLE_DEPRECATION_WARNINGS st->duration = AV_NOPTS_VALUE; st->first_dts = AV_NOPTS_VALUE; st->probe_packets = s->max_probe_packets; - st->pts_wrap_reference = AV_NOPTS_VALUE; - st->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; + st->internal->pts_wrap_reference = AV_NOPTS_VALUE; + st->internal->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; st->last_IP_pts = AV_NOPTS_VALUE; - st->last_dts_for_order_check = AV_NOPTS_VALUE; + st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (i = 0; i < MAX_REORDER_DELAY + 1; i++) - st->pts_buffer[i] = AV_NOPTS_VALUE; + st->internal->pts_buffer[i] = AV_NOPTS_VALUE; st->sample_aspect_ratio = (AVRational) { 0, 1 }; #if FF_API_R_FRAME_RATE - st->info->last_dts = AV_NOPTS_VALUE; + st->internal->info->last_dts = AV_NOPTS_VALUE; #endif - st->info->fps_first_dts = AV_NOPTS_VALUE; - st->info->fps_last_dts = AV_NOPTS_VALUE; + st->internal->info->fps_first_dts = AV_NOPTS_VALUE; + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; - st->inject_global_side_data = s->internal->inject_global_side_data; + st->internal->inject_global_side_data = s->internal->inject_global_side_data; st->internal->need_context_update = 1; @@ -5705,8 +5709,18 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, enum AVTimebaseSource copy_tb) { //TODO: use [io]st->internal->avctx - const AVCodecContext *dec_ctx = ist->codec; - AVCodecContext *enc_ctx = ost->codec; + const AVCodecContext *dec_ctx; + AVCodecContext *enc_ctx; + +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + dec_ctx = ist->codec; + enc_ctx = ost->codec; +FF_ENABLE_DEPRECATION_WARNINGS +#else + dec_ctx = ist->internal->avctx; + enc_ctx = ost->internal->avctx; +#endif enc_ctx->time_base = ist->time_base; /* diff --git a/chromium/third_party/ffmpeg/libavformat/version.h b/chromium/third_party/ffmpeg/libavformat/version.h index 40f84a220d5..b43193bcb17 100644 --- a/chromium/third_party/ffmpeg/libavformat/version.h +++ b/chromium/third_party/ffmpeg/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 59 +#define LIBAVFORMAT_VERSION_MINOR 65 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/chromium/third_party/ffmpeg/libavformat/vividas.c b/chromium/third_party/ffmpeg/libavformat/vividas.c index 7917df5d64f..96e0631b066 100644 --- a/chromium/third_party/ffmpeg/libavformat/vividas.c +++ b/chromium/third_party/ffmpeg/libavformat/vividas.c @@ -28,6 +28,7 @@ * @sa http://wiki.multimedia.cx/index.php?title=Vividas_VIV */ +#include "libavutil/avassert.h" #include "libavutil/intreadwrite.h" #include "avio_internal.h" #include "avformat.h" @@ -156,7 +157,7 @@ static void decode_block(uint8_t *src, uint8_t *dest, unsigned size, uint32_t tmpkey = *key_ptr - key; if (a2 > s) { a2 = s; - avpriv_request_sample(NULL, "tiny aligned block\n"); + avpriv_request_sample(NULL, "tiny aligned block"); } memcpy(tmp + align, src, a2); xor_block(tmp, tmp, 4, key, &tmpkey); @@ -319,6 +320,8 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * for (i = 0; i < num_video; i++) { AVStream *st = avformat_new_stream(s, NULL); + int num, den; + if (!st) return AVERROR(ENOMEM); @@ -331,8 +334,9 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * off += ffio_read_varlen(pb); avio_r8(pb); // '3' avio_r8(pb); // val_7 - st->time_base.num = avio_rl32(pb); // frame_time - st->time_base.den = avio_rl32(pb); // time_base + num = avio_rl32(pb); // frame_time + den = avio_rl32(pb); // time_base + avpriv_set_pts_info(st, 64, num, den); st->nb_frames = avio_rl32(pb); // n frames st->codecpar->width = avio_rl16(pb); // width st->codecpar->height = avio_rl16(pb); // height @@ -369,6 +373,8 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * avio_rl16(pb); //codec_subid st->codecpar->channels = avio_rl16(pb); // channels st->codecpar->sample_rate = avio_rl32(pb); // sample_rate + if (st->codecpar->sample_rate <= 0) + return AVERROR_INVALIDDATA; avio_seek(pb, 10, SEEK_CUR); // data_1 q = avio_r8(pb); avio_seek(pb, q, SEEK_CUR); // data_2 @@ -376,7 +382,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * if (avio_tell(pb) < off) { int num_data; - int xd_size = 0; + int xd_size = 1; int data_len[256]; int offset = 1; uint8_t *p; @@ -385,15 +391,15 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * ffio_read_varlen(pb); // len_3 num_data = avio_r8(pb); for (j = 0; j < num_data; j++) { - uint64_t len = ffio_read_varlen(pb); - if (len > INT_MAX/2 - xd_size) { + int64_t len = ffio_read_varlen(pb); + if (len < 0 || len > INT_MAX/2 - xd_size) { return AVERROR_INVALIDDATA; } data_len[j] = len; - xd_size += len; + xd_size += len + 1 + len/255; } - ret = ff_alloc_extradata(st->codecpar, 64 + xd_size + xd_size / 255); + ret = ff_alloc_extradata(st->codecpar, xd_size); if (ret < 0) return ret; @@ -402,9 +408,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * for (j = 0; j < num_data - 1; j++) { unsigned delta = av_xiphlacing(&p[offset], data_len[j]); - if (delta > data_len[j]) { - return AVERROR_INVALIDDATA; - } + av_assert0(delta <= xd_size - offset); offset += delta; } @@ -415,6 +419,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * av_freep(&st->codecpar->extradata); break; } + av_assert0(data_len[j] <= xd_size - offset); offset += data_len[j]; } @@ -670,6 +675,10 @@ static int viv_read_packet(AVFormatContext *s, if (!pb) return AVERROR(EIO); off = avio_tell(pb); + + if (viv->current_sb_entry >= viv->n_sb_entries) + return AVERROR_INVALIDDATA; + off += viv->sb_entries[viv->current_sb_entry].size; if (viv->sb_entries[viv->current_sb_entry].flag == 0) { @@ -679,7 +688,7 @@ static int viv_read_packet(AVFormatContext *s, return AVERROR_INVALIDDATA; ffio_read_varlen(pb); - if (v_size > INT_MAX) + if (v_size > INT_MAX || !v_size) return AVERROR_INVALIDDATA; ret = av_get_packet(pb, pkt, v_size); if (ret < 0) @@ -708,7 +717,7 @@ static int viv_read_packet(AVFormatContext *s, } else { uint64_t v_size = ffio_read_varlen(pb); - if (v_size > INT_MAX) + if (v_size > INT_MAX || !v_size) return AVERROR_INVALIDDATA; ret = av_get_packet(pb, pkt, v_size); if (ret < 0) diff --git a/chromium/third_party/ffmpeg/libavformat/vocdec.c b/chromium/third_party/ffmpeg/libavformat/vocdec.c index fd1ca20c9bd..d388fce92ef 100644 --- a/chromium/third_party/ffmpeg/libavformat/vocdec.c +++ b/chromium/third_party/ffmpeg/libavformat/vocdec.c @@ -83,14 +83,14 @@ static int voc_read_seek(AVFormatContext *s, int stream_index, st = s->streams[stream_index]; index = av_index_search_timestamp(st, timestamp, flags); - if (index >= 0 && index < st->nb_index_entries - 1) { - AVIndexEntry *e = &st->index_entries[index]; + if (index >= 0 && index < st->internal->nb_index_entries - 1) { + AVIndexEntry *e = &st->internal->index_entries[index]; avio_seek(s->pb, e->pos, SEEK_SET); voc->pts = e->timestamp; voc->remaining_size = e->size; return 0; - } else if (st->nb_index_entries && st->index_entries[0].timestamp <= timestamp) { - AVIndexEntry *e = &st->index_entries[st->nb_index_entries - 1]; + } else if (st->internal->nb_index_entries && st->internal->index_entries[0].timestamp <= timestamp) { + AVIndexEntry *e = &st->internal->index_entries[st->internal->nb_index_entries - 1]; // prepare context for seek_frame_generic() voc->pts = e->timestamp; voc->remaining_size = e->size; diff --git a/chromium/third_party/ffmpeg/libavformat/vqf.c b/chromium/third_party/ffmpeg/libavformat/vqf.c index 617a9706f43..449f4061f75 100644 --- a/chromium/third_party/ffmpeg/libavformat/vqf.c +++ b/chromium/third_party/ffmpeg/libavformat/vqf.c @@ -132,6 +132,9 @@ static int vqf_read_header(AVFormatContext *s) switch(chunk_tag){ case MKTAG('C','O','M','M'): + if (len < 12) + return AVERROR_INVALIDDATA; + avio_read(s->pb, comm_chunk, 12); st->codecpar->channels = AV_RB32(comm_chunk ) + 1; read_bitrate = AV_RB32(comm_chunk + 4); diff --git a/chromium/third_party/ffmpeg/libavformat/wavdec.c b/chromium/third_party/ffmpeg/libavformat/wavdec.c index d3334d2b4a0..6d6b9507af9 100644 --- a/chromium/third_party/ffmpeg/libavformat/wavdec.c +++ b/chromium/third_party/ffmpeg/libavformat/wavdec.c @@ -58,7 +58,6 @@ typedef struct WAVDemuxContext { int ignore_length; int max_size; int spdif; - int smv_cur_pt; int smv_given_first; int unaligned; // e.g. if an odd number of bytes ID3 tag was prepended int rifx; // RIFX: integer byte order for parameters is big endian @@ -156,7 +155,7 @@ static int wav_probe(const AVProbeData *p) static void handle_stream_probing(AVStream *st) { if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { - st->request_probe = AVPROBE_SCORE_EXTENSION; + st->internal->request_probe = AVPROBE_SCORE_EXTENSION; st->probe_packets = FFMIN(st->probe_packets, 32); } } @@ -499,7 +498,6 @@ static int wav_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } AV_WL32(vst->codecpar->extradata, wav->smv_frames_per_jpeg); - wav->smv_cur_pt = 0; goto break_loop; case MKTAG('L', 'I', 'S', 'T'): case MKTAG('l', 'i', 's', 't'): @@ -560,6 +558,9 @@ static int wav_read_header(AVFormatContext *s) for (int i = 0; i < nb_cues; i++) { unsigned offset, id = avio_rl32(pb); + if (avio_feof(pb)) + return AVERROR_INVALIDDATA; + avio_skip(pb, 16); offset = avio_rl32(pb); @@ -668,7 +669,7 @@ static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16]) while (!avio_feof(pb)) { avio_read(pb, guid, 16); size = avio_rl64(pb); - if (size <= 24) + if (size <= 24 || size > INT64_MAX - 8) return AVERROR_INVALIDDATA; if (!memcmp(guid, guid1, 16)) return size; @@ -718,12 +719,9 @@ smv_retry: if (ret < 0) goto smv_out; pkt->pos -= 3; - pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg + wav->smv_cur_pt; - wav->smv_cur_pt++; - if (wav->smv_frames_per_jpeg > 0) - wav->smv_cur_pt %= wav->smv_frames_per_jpeg; - if (!wav->smv_cur_pt) - wav->smv_block++; + pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg; + pkt->duration = wav->smv_frames_per_jpeg; + wav->smv_block++; pkt->stream_index = 1; smv_out: @@ -787,7 +785,6 @@ static int wav_read_seek(AVFormatContext *s, timestamp = av_rescale_q(smv_timestamp, s->streams[1]->time_base, s->streams[0]->time_base); if (wav->smv_frames_per_jpeg > 0) { wav->smv_block = smv_timestamp / wav->smv_frames_per_jpeg; - wav->smv_cur_pt = smv_timestamp % wav->smv_frames_per_jpeg; } } @@ -908,6 +905,7 @@ static int w64_read_header(AVFormatContext *s) } else if (!memcmp(guid, ff_w64_guid_summarylist, 16)) { int64_t start, end, cur; uint32_t count, chunk_size, i; + int64_t filesize = avio_size(s->pb); start = avio_tell(pb); end = start + FFALIGN(size, INT64_C(8)) - 24; @@ -922,7 +920,7 @@ static int w64_read_header(AVFormatContext *s) chunk_key[4] = 0; avio_read(pb, chunk_key, 4); chunk_size = avio_rl32(pb); - if (chunk_size == UINT32_MAX) + if (chunk_size == UINT32_MAX || (filesize >= 0 && chunk_size > filesize)) return AVERROR_INVALIDDATA; value = av_mallocz(chunk_size + 1); diff --git a/chromium/third_party/ffmpeg/libavformat/wtvdec.c b/chromium/third_party/ffmpeg/libavformat/wtvdec.c index 83f510b92f1..77908e63921 100644 --- a/chromium/third_party/ffmpeg/libavformat/wtvdec.c +++ b/chromium/third_party/ffmpeg/libavformat/wtvdec.c @@ -273,6 +273,11 @@ static AVIOContext * wtvfile_open2(AVFormatContext *s, const uint8_t *buf, int b "bad filename length, remaining directory entries ignored\n"); break; } + if (dir_length == 0) { + av_log(s, AV_LOG_ERROR, + "bad dir length, remaining directory entries ignored\n"); + break; + } if (48 + (int64_t)name_size > buf_end - buf) { av_log(s, AV_LOG_ERROR, "filename exceeds buffer size; remaining directory entries ignored\n"); break; diff --git a/chromium/third_party/ffmpeg/libavformat/xwma.c b/chromium/third_party/ffmpeg/libavformat/xwma.c index 5a57caa8411..aedadcf1405 100644 --- a/chromium/third_party/ffmpeg/libavformat/xwma.c +++ b/chromium/third_party/ffmpeg/libavformat/xwma.c @@ -211,6 +211,10 @@ static int xwma_read_header(AVFormatContext *s) } for (i = 0; i < dpds_table_size; ++i) { + if (avio_feof(pb)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } dpds_table[i] = avio_rl32(pb); size -= 4; } |