Re: [FFmpeg-devel] [PATCH v4 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
On 25/4/21 11:41 am, Zane van Iperen wrote: Interesting, FATE didn't catch it for me. Which test is it? $ make fate-adpcm fate-acodec fate-westwood-aud SAMPLES=fate-suite/ All pass for me. Never mind, found it. Both the sample from the ticket as well as the fate-sample (vqa/cc-demo1-partial.vqa) are 22050 Hz, mono, s16; the fate sample is version 2, the new sample version 0. None of them test the version 3 codepath, so the change to it is untested. Yeah, don't know where stereo came from. I need to sleep more... What I meant was see this. Top is before, bottom is after: https://0x0.st/-mex.png I've also confirmed all the "https://samples.ffmpeg.org/game-formats/vqa/Tiberian Sun VQAs" samples exhibit the same behaviour without the patch. I have tested a few files and the changes to the non-version 3 codepath seem to be correct; I have also found out that your commit c012f9b265e172de9c240c9dfab8665936fa3e83 made decoding https://samples.ffmpeg.org/game-formats/vqa/Tiberian Sun VQAs/startup.vqa (which is a version 3 format ima-ws file) crash. I've fixed the crash, see https://ffmpeg.org/pipermail/ffmpeg-devel/2021-April/279504.html Once the patch (and my crash fix) are merged, I'll submit a test case for v3 VQA files so this doesn't happen again. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v3 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types
On Sun, Apr 25, 2021 at 2:13 AM Marton Balint wrote: > > The order of the patches seems wrong. Patch/3 (or similar) should be > applied first, otherwise you are checking the stream_id provided via side > data, not the stream id actually used. > > Also note that is_dvb_teletext/is_dvb_subtitle might not be set if certain > stream_id is used, that can also cause issues. > > I will send a patch series for these two issues, please check them and if > they look good then rebase your patchset on top of that. > > You should add the relevant stream type constants to mpegts.h and use > those for the checks, you can spare the comments that way. > I have sent a new patchset v4 for these changes. https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=3833 Notice that I re-sent the 3/4 patch file which seems to be lost, so please pay attention to the order. Thanks, zheng ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 3/4] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types
Changes since v3: Use STREAM_ID_* constants in mpegts.h for stream_id judgement Current implementation skipped the judgement of stream_id causing some kind of stream like private_stream_2 to be incorrectly written with actually a private_stream_1-like PES header with PTS/DTS field. For example, Japan DTV transmits news and alerts through ARIB superimpose that utilizes private_stream_2 still could not be remuxed correctly for now. This patch set fixes the remuxing for private_stream_2 and other stream_id types. Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 48d724d646..e6fcecbaca 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1479,6 +1479,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, pts = dts = AV_NOPTS_VALUE; header_len = 0; + +if (stream_id != STREAM_ID_PROGRAM_STREAM_MAP && +stream_id != STREAM_ID_PADDING_STREAM && +stream_id != STREAM_ID_PRIVATE_STREAM_2 && +stream_id != STREAM_ID_ECM_STREAM && +stream_id != STREAM_ID_EMM_STREAM && +stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY && +stream_id != STREAM_ID_DSMCC_STREAM && +stream_id != STREAM_ID_TYPE_E_STREAM) { + flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; @@ -1572,6 +1582,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; } +} else { +len = payload_size; +*q++ = len >> 8; +*q++ = len; +} is_start = 0; } /* header size */ -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 3/4] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types
Changes since v3: Use STREAM_ID_* constants in mpegts.h for stream_id judgement Current implementation skipped the judgement of stream_id causing some kind of stream like private_stream_2 to be incorrectly written with actually a private_stream_1-like PES header with PTS/DTS field. For example, Japan DTV transmits news and alerts through ARIB superimpose that utilizes private_stream_2 still could not be remuxed correctly for now. This patch set fixes the remuxing for private_stream_2 and other stream_id types. Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 48d724d646..e6fcecbaca 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1479,6 +1479,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, pts = dts = AV_NOPTS_VALUE; header_len = 0; + +if (stream_id != STREAM_ID_PROGRAM_STREAM_MAP && +stream_id != STREAM_ID_PADDING_STREAM && +stream_id != STREAM_ID_PRIVATE_STREAM_2 && +stream_id != STREAM_ID_ECM_STREAM && +stream_id != STREAM_ID_EMM_STREAM && +stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY && +stream_id != STREAM_ID_DSMCC_STREAM && +stream_id != STREAM_ID_TYPE_E_STREAM) { + flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; @@ -1572,6 +1582,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; } +} else { +len = payload_size; +*q++ = len >> 8; +*q++ = len; +} is_start = 0; } /* header size */ -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 1/4] avformat/mpegts: Add missing constants for MPEG-TS stream_id definitions
Signed-off-by: zheng qian --- libavformat/mpegts.h | 8 1 file changed, 8 insertions(+) diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h index 04874e0f42..224282b3ed 100644 --- a/libavformat/mpegts.h +++ b/libavformat/mpegts.h @@ -138,11 +138,19 @@ #define STREAM_TYPE_AUDIO_EAC3 0x87 /* ISO/IEC 13818-1 Table 2-22 */ +#define STREAM_ID_PROGRAM_STREAM_MAP 0xbc #define STREAM_ID_PRIVATE_STREAM_1 0xbd +#define STREAM_ID_PADDING_STREAM 0xbe +#define STREAM_ID_PRIVATE_STREAM_2 0xbf #define STREAM_ID_AUDIO_STREAM_0 0xc0 #define STREAM_ID_VIDEO_STREAM_0 0xe0 +#define STREAM_ID_ECM_STREAM 0xf0 +#define STREAM_ID_EMM_STREAM 0xf1 +#define STREAM_ID_DSMCC_STREAM 0xf2 +#define STREAM_ID_TYPE_E_STREAM 0xf8 #define STREAM_ID_METADATA_STREAM0xfc #define STREAM_ID_EXTENDED_STREAM_ID 0xfd +#define STREAM_ID_PROGRAM_STREAM_DIRECTORY 0xff /* ISO/IEC 13818-1 Table 2-45 */ #define VIDEO_STREAM_DESCRIPTOR 0x02 -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 2/4] avformat/mpegts: Fix indentation for stream_id constants
Signed-off-by: zheng qian --- libavformat/mpegts.h | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h index 224282b3ed..c75ba08f29 100644 --- a/libavformat/mpegts.h +++ b/libavformat/mpegts.h @@ -138,18 +138,18 @@ #define STREAM_TYPE_AUDIO_EAC3 0x87 /* ISO/IEC 13818-1 Table 2-22 */ -#define STREAM_ID_PROGRAM_STREAM_MAP 0xbc -#define STREAM_ID_PRIVATE_STREAM_1 0xbd -#define STREAM_ID_PADDING_STREAM 0xbe -#define STREAM_ID_PRIVATE_STREAM_2 0xbf -#define STREAM_ID_AUDIO_STREAM_0 0xc0 -#define STREAM_ID_VIDEO_STREAM_0 0xe0 -#define STREAM_ID_ECM_STREAM 0xf0 -#define STREAM_ID_EMM_STREAM 0xf1 -#define STREAM_ID_DSMCC_STREAM 0xf2 -#define STREAM_ID_TYPE_E_STREAM 0xf8 -#define STREAM_ID_METADATA_STREAM0xfc -#define STREAM_ID_EXTENDED_STREAM_ID 0xfd +#define STREAM_ID_PROGRAM_STREAM_MAP0xbc +#define STREAM_ID_PRIVATE_STREAM_1 0xbd +#define STREAM_ID_PADDING_STREAM0xbe +#define STREAM_ID_PRIVATE_STREAM_2 0xbf +#define STREAM_ID_AUDIO_STREAM_00xc0 +#define STREAM_ID_VIDEO_STREAM_00xe0 +#define STREAM_ID_ECM_STREAM0xf0 +#define STREAM_ID_EMM_STREAM0xf1 +#define STREAM_ID_DSMCC_STREAM 0xf2 +#define STREAM_ID_TYPE_E_STREAM 0xf8 +#define STREAM_ID_METADATA_STREAM 0xfc +#define STREAM_ID_EXTENDED_STREAM_ID0xfd #define STREAM_ID_PROGRAM_STREAM_DIRECTORY 0xff /* ISO/IEC 13818-1 Table 2-45 */ -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 4/4] avformat/mpegtsenc: Fix indentation inside if-clause in mpegts_write_pes()
Fix indentation caused by the added stream_id judgement Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 180 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index e6fcecbaca..d055e5bc15 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1489,99 +1489,99 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, stream_id != STREAM_ID_DSMCC_STREAM && stream_id != STREAM_ID_TYPE_E_STREAM) { -flags = 0; -if (pts != AV_NOPTS_VALUE) { -header_len += 5; -flags |= 0x80; -} -if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { -header_len += 5; -flags |= 0x40; -} -if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && -st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { -/* set PES_extension_flag */ -pes_extension = 1; -flags|= 0x01; - -/* One byte for PES2 extension flag + - * one byte for extension length + - * one byte for extension id */ -header_len += 3; -} -/* for Blu-ray AC3 Audio the PES Extension flag should be as follow - * otherwise it will not play sound on blu-ray - */ -if (ts->m2ts_mode && -st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && -st->codecpar->codec_id == AV_CODEC_ID_AC3) { -/* set PES_extension_flag */ -pes_extension = 1; -flags |= 0x01; -header_len += 3; -} -if (is_dvb_teletext) { -pes_header_stuffing_bytes = 0x24 - header_len; -header_len = 0x24; -} -len = payload_size + header_len + 3; -/* 3 extra bytes should be added to DVB subtitle payload: 0x20 0x00 at the beginning and trailing 0xff */ -if (is_dvb_subtitle) { -len += 3; -payload_size++; -} -if (len > 0x) -len = 0; -if (ts->omit_video_pes_length && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { -len = 0; -} -*q++ = len >> 8; -*q++ = len; -val = 0x80; -/* data alignment indicator is required for subtitle and data streams */ -if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA) -val |= 0x04; -*q++ = val; -*q++ = flags; -*q++ = header_len; -if (pts != AV_NOPTS_VALUE) { -write_pts(q, flags >> 6, pts); -q += 5; -} -if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { -write_pts(q, 1, dts); -q += 5; -} -if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { -flags = 0x01; /* set PES_extension_flag_2 */ -*q++ = flags; -*q++ = 0x80 | 0x01; /* marker bit + extension length */ -/* Set the stream ID extension flag bit to 0 and - * write the extended stream ID. */ -*q++ = 0x00 | 0x60; -} -/* For Blu-ray AC3 Audio Setting extended flags */ -if (ts->m2ts_mode && -pes_extension && -st->codecpar->codec_id == AV_CODEC_ID_AC3) { -flags = 0x01; /* set PES_extension_flag_2 */ +flags = 0; +if (pts != AV_NOPTS_VALUE) { +header_len += 5; +flags |= 0x80; +} +if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { +header_len += 5; +flags |= 0x40; +} +if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && +st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { +/* set PES_extension_flag */ +pes_extension = 1; +flags|= 0x01; + +/* One byte for PES2 extension flag + + * one byte for extension length + + * one byte for extension id */ +header_len += 3; +} +/* for Blu-ray AC3 Audio the PES Extension flag should be as follow + * otherwise it will not play sound on blu-ray + */ +if (ts->m2ts_mode && +st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && +st-
Re: [FFmpeg-devel] [PATCH v4 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
On 25/4/21 11:02 am, Andreas Rheinhardt wrote: Zane van Iperen: On 25/4/21 9:40 am, Andreas Rheinhardt wrote: This format is covered by FATE (namely the adpcm-ima-ws test) and so you need to update the checksums in your patch; of course you should verify that your change is correct. See https://ffmpeg.org/fate.html for more. - Andreas ___ The attached file here https://trac.ffmpeg.org/ticket/9198 decodes incorrectly without the patch. I'd be inclined to say that it's correct. The issue isn't caught by FATE because it only tests a mono sample. If it weren't caught by FATE, the test wouldn't need an update. Interesting, FATE didn't catch it for me. Which test is it? $ make fate-adpcm fate-acodec fate-westwood-aud SAMPLES=fate-suite/ All pass for me. Both the sample from the ticket as well as the fate-sample (vqa/cc-demo1-partial.vqa) are 22050 Hz, mono, s16; the fate sample is version 2, the new sample version 0. None of them test the version 3 codepath, so the change to it is untested. Yeah, don't know where stereo came from. I need to sleep more... What I meant was see this. Top is before, bottom is after: https://0x0.st/-mex.png I have tested a few files and the changes to the non-version 3 codepath seem to be correct; I have also found out that your commit c012f9b265e172de9c240c9dfab8665936fa3e83 made decoding https://samples.ffmpeg.org/game-formats/vqa/Tiberian Sun VQAs/startup.vqa (which is a version 3 format ima-ws file) crash. I've fixed the crash, see https://ffmpeg.org/pipermail/ffmpeg-devel/2021-April/279504.html ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/2] lavf/qsvenc: '0' is not a valid value for GopOptFlag
The accepted values for GopOptFlag are MFX_GOP_CLOSED (1) and MFX_GOP_STRICT (2). Signed-off-by: Haihao Xiang --- libavcodec/qsvenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index aeb010e456..684c8089eb 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -531,7 +531,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size); q->param.mfx.GopRefDist = FFMAX(-1, avctx->max_b_frames) + 1; q->param.mfx.GopOptFlag = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? - MFX_GOP_CLOSED : 0; + MFX_GOP_CLOSED : MFX_GOP_STRICT; q->param.mfx.IdrInterval= q->idr_interval; q->param.mfx.NumSlice = avctx->slices; q->param.mfx.NumRefFrame= FFMAX(0, avctx->refs); -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/2] lavc/qsvenc_hevc: allow user set more coding options
The SDK supports NalHrdConformance, RecoveryPointSEI and AUDelimiter for hevc encoder, so we may allow user to set these coding options like what we did for h264_qsv encoder. '-strict xxx' to turn on / off NalHrdConformance '-recovery_point_sei xxx' to turn on / off RecoveryPointSEI '-aud xxx' to turn on / off AUDelimiter Signed-off-by: Haihao Xiang --- libavcodec/qsvenc.c | 15 --- libavcodec/qsvenc_hevc.c | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 566a5c8552..aeb010e456 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -290,6 +290,10 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, "NalHrdConformance: %s; SingleSeiNalUnit: %s; VuiVclHrdParameters: %s VuiNalHrdParameters: %s\n", print_threestate(co->NalHrdConformance), print_threestate(co->SingleSeiNalUnit), print_threestate(co->VuiVclHrdParameters), print_threestate(co->VuiNalHrdParameters)); +} else if (avctx->codec_id == AV_CODEC_ID_HEVC) { +av_log(avctx, AV_LOG_VERBOSE, + "NalHrdConformance: %s; VuiNalHrdParameters: %s\n", + print_threestate(co->NalHrdConformance), print_threestate(co->VuiNalHrdParameters)); } av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: %"PRIu32" \n", @@ -676,15 +680,20 @@ FF_ENABLE_DEPRECATION_WARNINGS q->extco.CAVLC = q->cavlc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN; +if (q->single_sei_nal_unit >= 0) +q->extco.SingleSeiNalUnit = q->single_sei_nal_unit ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; + +q->extco.MaxDecFrameBuffering = q->max_dec_frame_buffering; +} + +if (avctx->codec_id == AV_CODEC_ID_H264 || +avctx->codec_id == AV_CODEC_ID_HEVC) { if (avctx->strict_std_compliance != FF_COMPLIANCE_NORMAL) q->extco.NalHrdConformance = avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; -if (q->single_sei_nal_unit >= 0) -q->extco.SingleSeiNalUnit = q->single_sei_nal_unit ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; if (q->recovery_point_sei >= 0) q->extco.RecoveryPointSEI = q->recovery_point_sei ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; -q->extco.MaxDecFrameBuffering = q->max_dec_frame_buffering; q->extco.AUDelimiter = q->aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; } diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index 347f30655e..aa02361d1d 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -246,6 +246,8 @@ static const AVOption options[] = { { "tile_cols", "Number of columns for tiled encoding", OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE }, { "tile_rows", "Number of rows for tiled encoding", OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE }, +{ "recovery_point_sei", "Insert recovery point SEI messages", OFFSET(qsv.recovery_point_sei), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, +{ "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE}, { NULL }, }; -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avcodec/adpcm: init from extradata before setting sample formats
Fixes a crash when decoding VQA files. Reported-by: Andreas Rheinhardt Signed-off-by: Zane van Iperen --- libavcodec/adpcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index be14607eac..b031e24981 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -111,6 +111,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) unsigned int min_channels = 1; unsigned int max_channels = 2; +adpcm_flush(avctx); + switch(avctx->codec->id) { case AV_CODEC_ID_ADPCM_IMA_AMV: max_channels = 1; @@ -201,8 +203,6 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) default: avctx->sample_fmt = AV_SAMPLE_FMT_S16; } - -adpcm_flush(avctx); return 0; } -- 2.29.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] libavfilter: Spelling Correction in OpenVino Backend
> -Original Message- > From: ffmpeg-devel On Behalf Of > shubhanshu02 > Sent: 2021年4月23日 18:57 > To: ffmpeg-devel@ffmpeg.org > Cc: shubhanshu02 > Subject: [FFmpeg-devel] [PATCH] libavfilter: Spelling Correction in OpenVino > Backend > > Correct Spelling of the word `descibe` to `describe` > in init_model_ov > > Signed-off-by: shubhanshu02 > --- > libavfilter/dnn/dnn_backend_openvino.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libavfilter/dnn/dnn_backend_openvino.c > b/libavfilter/dnn/dnn_backend_openvino.c > index 0757727a9c..a8032fe56b 100644 > --- a/libavfilter/dnn/dnn_backend_openvino.c > +++ b/libavfilter/dnn/dnn_backend_openvino.c > @@ -318,7 +318,7 @@ static DNNReturnType init_model_ov(OVModel > *ov_model, const char *input_name, co > } > > // all models in openvino open model zoo use BGR with range [0.0f, > 255.0f] as input, > -// we don't have a AVPixelFormat to descibe it, so we'll use > AV_PIX_FMT_BGR24 and > +// we don't have a AVPixelFormat to describe it, so we'll use > AV_PIX_FMT_BGR24 and > // ask openvino to do the conversion internally. > // the current supported SR model (frame processing) is generated > from tensorflow model, > // and its input is Y channel as float with range [0.0f, 1.0f], so do not > set for this case. > -- LGTM, we can add the file name in the commit log title since only one file is changed, will modify locally and push soon, thanks. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
Zane van Iperen: > > > On 25/4/21 9:40 am, Andreas Rheinhardt wrote: > >> This format is covered by FATE (namely the adpcm-ima-ws test) and so you >> need to update the checksums in your patch; of course you should verify >> that your change is correct. See https://ffmpeg.org/fate.html for more. >> >> - Andreas >> ___ > > The attached file here https://trac.ffmpeg.org/ticket/9198 decodes > incorrectly without the patch. I'd be inclined to say that it's correct. > > The issue isn't caught by FATE because it only tests a mono sample. > If it weren't caught by FATE, the test wouldn't need an update. Both the sample from the ticket as well as the fate-sample (vqa/cc-demo1-partial.vqa) are 22050 Hz, mono, s16; the fate sample is version 2, the new sample version 0. None of them test the version 3 codepath, so the change to it is untested. I have tested a few files and the changes to the non-version 3 codepath seem to be correct; I have also found out that your commit c012f9b265e172de9c240c9dfab8665936fa3e83 made decoding https://samples.ffmpeg.org/game-formats/vqa/Tiberian Sun VQAs/startup.vqa (which is a version 3 format ima-ws file) crash. > > I'll merge this patch shortly if you have no objections. > > After the encoder's added, I'll add an ENCDEC test which should cover > the stereo case. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
On 25/4/21 9:40 am, Andreas Rheinhardt wrote: This format is covered by FATE (namely the adpcm-ima-ws test) and so you need to update the checksums in your patch; of course you should verify that your change is correct. See https://ffmpeg.org/fate.html for more. - Andreas ___ The attached file here https://trac.ffmpeg.org/ticket/9198 decodes incorrectly without the patch. I'd be inclined to say that it's correct. The issue isn't caught by FATE because it only tests a mono sample. I'll merge this patch shortly if you have no objections. After the encoder's added, I'll add an ENCDEC test which should cover the stereo case. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4 2/3] avformat/westwoodaudenc: Adds muxer for Westwood AUD format.
On 25/4/21 8:42 am, Aidan Richmond wrote: + +static int wsaud_init(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; + +/* Stream must be seekable to correctly write the file. */ +if(!(pb->seekable & AVIO_SEEKABLE_NORMAL)) { Missing space, "if (" +static int wsaud_write_header(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; +int ret; +unsigned char flags = 0; + +ret = wsaud_init(ctx); AVOutputFormat::init should be used for this purpose. See line 312 in libavformat/apm.c for an example. The rest lgtm. Will apply after these notes are fixed. Zane ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
Aidan Richmond: > Fixes bug #9198 > > Signed-off-by: Aidan Richmond > --- > libavcodec/adpcm.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c > index be14607eac..5ec9691001 100644 > --- a/libavcodec/adpcm.c > +++ b/libavcodec/adpcm.c > @@ -1400,16 +1400,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx, > void *data, > > for (n = nb_samples / 2; n > 0; n--) { > int v = bytestream2_get_byteu(&gb); > -*smp++ = adpcm_ima_expand_nibble(&c->status[channel], v > >> 4 , 3); > *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v > & 0x0F, 3); > +*smp++ = adpcm_ima_expand_nibble(&c->status[channel], v > >> 4 , 3); > } > } > } else { > for (n = nb_samples / 2; n > 0; n--) { > for (channel = 0; channel < avctx->channels; channel++) { > int v = bytestream2_get_byteu(&gb); > -*samples++ = > adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); > -samples[st] = > adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); > +*samples++ = > adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); > +samples[st] = > adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); > } > samples += avctx->channels; > } > This format is covered by FATE (namely the adpcm-ima-ws test) and so you need to update the checksums in your patch; of course you should verify that your change is correct. See https://ffmpeg.org/fate.html for more. - Andreas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
Fixes bug #9198 Signed-off-by: Aidan Richmond --- libavcodec/adpcm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index be14607eac..5ec9691001 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -1400,16 +1400,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (n = nb_samples / 2; n > 0; n--) { int v = bytestream2_get_byteu(&gb); -*smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); +*smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); } } } else { for (n = nb_samples / 2; n > 0; n--) { for (channel = 0; channel < avctx->channels; channel++) { int v = bytestream2_get_byteu(&gb); -*samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); -samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); +*samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); +samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); } samples += avctx->channels; } -- 2.16.1.windows.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 2/3] avformat/westwoodaudenc: Adds muxer for Westwood AUD format.
Format is still used by modders of these old games. Signed-off-by: Aidan Richmond --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/westwood_audenc.c | 145 ++ 3 files changed, 147 insertions(+) create mode 100644 libavformat/westwood_audenc.c diff --git a/libavformat/Makefile b/libavformat/Makefile index bc1ddfa81c..85b5d8e7eb 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -581,6 +581,7 @@ OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o +OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv_common.o \ diff --git a/libavformat/allformats.c b/libavformat/allformats.c index fa093c7ac2..fe70a1e9a2 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -478,6 +478,7 @@ extern AVOutputFormat ff_webp_muxer; extern AVInputFormat ff_webvtt_demuxer; extern AVOutputFormat ff_webvtt_muxer; extern AVInputFormat ff_wsaud_demuxer; +extern AVOutputFormat ff_wsaud_muxer; extern AVInputFormat ff_wsd_demuxer; extern AVInputFormat ff_wsvqa_demuxer; extern AVInputFormat ff_wtv_demuxer; diff --git a/libavformat/westwood_audenc.c b/libavformat/westwood_audenc.c new file mode 100644 index 00..45875f7873 --- /dev/null +++ b/libavformat/westwood_audenc.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2021 Aidan Richmond + * + * 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 + * Westwood Studios AUD file muxer + * by Aidan Richmond (aidan...@hotmail.co.uk) + * + * This muxer supports IMA ADPCM packed in westwoods format. + * + * @see http://xhp.xwis.net/documents/aud3.txt + */ + +#include "libavutil/avassert.h" + +#include "avformat.h" +#include "avio_internal.h" +#include "internal.h" +#include + +#define AUD_CHUNK_SIGNATURE 0xDEAF + +typedef struct AUDMuxContext { +int uncomp_size; +int size; +} AUDMuxContext; + +static int wsaud_init(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; + +/* Stream must be seekable to correctly write the file. */ +if(!(pb->seekable & AVIO_SEEKABLE_NORMAL)) { +av_log(ctx->streams[0], AV_LOG_ERROR, "Cannot write Westwood aud to" + " none seekable stream.\n"); +return AVERROR(EINVAL); +} + +if (st->codecpar->codec_id != AV_CODEC_ID_ADPCM_IMA_WS) { +av_log(st, AV_LOG_ERROR, "%s codec not supported for Westwood AUD.\n", + avcodec_get_name(st->codecpar->codec_id)); +return AVERROR(EINVAL); +} + +if (ctx->nb_streams != 1) { +av_log(st, AV_LOG_ERROR, "AUD files have exactly one stream\n"); +return AVERROR(EINVAL); +} + +return 0; +} + +static int wsaud_write_header(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; +int ret; +unsigned char flags = 0; + +ret = wsaud_init(ctx); + +if (ret) +return ret; + +a->uncomp_size = 0; +a->size = 0; + +/* Flag if we have stereo data. */ +if (st->codecpar->channels == 2) +flags |= 1; + +/* This flags that the file contains 16 bit samples rather than 8 bit + since the encoder only encodes 16 bit samples this should be set. */ +if (av_get_bits_per_sample(st->codecpar->codec_id) == 4) +flags |= 2; + +avio_wl16(pb, st->codecpar->sample_rate); +/* We don't know the file size yet, so just zero 8 bytes */ +ffio_fill(pb, 0, 8); +avio_w8(pb, flags); +/* 99 indicates the ADPCM format. Other formats not supported. */ +avio_w8(pb, 99); + +return 0; +} + +static int wsaud_write_packet(AVFormatContext *ctx, AVPacket *pkt) +{ +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; + +av_assert1(pkt->size < UINT16_MAX && (pkt->size * 4) < UINT16_MAX); +
[FFmpeg-devel] [PATCH v4 1/3] avcodec/adpcmenc: Adds encoder for Westwood ADPCM.
Signed-off-by: Aidan Richmond --- Apologies, I messed up a variable name in westwood_audenc.c in the v3 version of this patch series. libavcodec/Makefile| 1 + libavcodec/adpcmenc.c | 32 ++-- libavcodec/allcodecs.c | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 4a597f727a..fcddde459d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -898,6 +898,7 @@ OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_IMA_WS_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MTAF_DECODER) += adpcm.o adpcm_data.o diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 9dc77d519a..752cae5cf4 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -94,7 +94,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI || avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_APM || -avctx->codec->id == AV_CODEC_ID_ADPCM_ARGO) { +avctx->codec->id == AV_CODEC_ID_ADPCM_ARGO|| +avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_WS) { /* * The current trellis implementation doesn't work for extended * runs of samples without periodic resets. Disallow it. @@ -192,6 +193,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->frame_size = 32; avctx->block_align = 17 * avctx->channels; break; +case AV_CODEC_ID_ADPCM_IMA_WS: +/* each 16 bits sample gives one nibble */ +avctx->frame_size = s->block_size * 2 / avctx->channels; +avctx->block_align = s->block_size; +break; default: return AVERROR(EINVAL); } @@ -594,7 +600,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI || avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_ALP || -avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM) +avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM || +avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_WS) pkt_size = (frame->nb_samples * avctx->channels) / 2; else pkt_size = avctx->block_align; @@ -929,6 +936,26 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, flush_put_bits(&pb); break; } +case AV_CODEC_ID_ADPCM_IMA_WS: +{ +PutBitContext pb; +init_put_bits(&pb, dst, pkt_size); + +av_assert0(avctx->trellis == 0); +for (n = frame->nb_samples / 2; n > 0; n--) { +/* stereo: 1 byte (2 samples) for left, 1 byte for right */ +for (ch = 0; ch < avctx->channels; ch++) { +int t1, t2; +t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++); +t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]); +put_bits(&pb, 4, t2); +put_bits(&pb, 4, t1); +} +samples += avctx->channels; +} +flush_put_bits(&pb); +break; +} default: return AVERROR(EINVAL); } @@ -990,6 +1017,7 @@ ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_ALP, adpcm_ima_alp, sample_fmts, AV_CODEC_ ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, 0, "ADPCM IMA QuickTime"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0, "ADPCM IMA WAV"); +ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Westwood"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_MS, adpcm_ms, sample_fmts, 0, "ADPCM Microsoft"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_SWF, adpcm_swf, sample_fmts, 0, "ADPCM Shockwave Flash"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, sample_fmts, 0, "ADPCM Yamaha"); diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 2e9a3581de..b748c9718e 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -645,6 +645,7 @@ extern AVCodec ff_adpcm_ima_ssi_encoder; extern AVCodec ff_adpcm_ima_smjpeg_decoder; extern AVCodec ff_adpcm_ima_wav_encoder; extern AVCodec ff_adpcm_ima_wav_decoder; +extern AVCodec ff_adpcm_ima_ws_encoder; extern AVCodec ff_adpcm_ima_ws
[FFmpeg-devel] [PATCH v3 3/3] avcodec/adpcm: Fixes output from Westwood ADPCM.
Fixes bug #9198 Signed-off-by: Aidan Richmond --- libavcodec/adpcm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index be14607eac..5ec9691001 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -1400,16 +1400,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (n = nb_samples / 2; n > 0; n--) { int v = bytestream2_get_byteu(&gb); -*smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); +*smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); } } } else { for (n = nb_samples / 2; n > 0; n--) { for (channel = 0; channel < avctx->channels; channel++) { int v = bytestream2_get_byteu(&gb); -*samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); -samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); +*samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); +samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); } samples += avctx->channels; } -- 2.16.1.windows.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v3 2/3] avformat/westwoodaudenc: Adds muxer for Westwood AUD format.
Format is still used by modders of these old games. Signed-off-by: Aidan Richmond --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/westwood_audenc.c | 145 ++ 3 files changed, 147 insertions(+) create mode 100644 libavformat/westwood_audenc.c diff --git a/libavformat/Makefile b/libavformat/Makefile index bc1ddfa81c..85b5d8e7eb 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -581,6 +581,7 @@ OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o +OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv_common.o \ diff --git a/libavformat/allformats.c b/libavformat/allformats.c index fa093c7ac2..fe70a1e9a2 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -478,6 +478,7 @@ extern AVOutputFormat ff_webp_muxer; extern AVInputFormat ff_webvtt_demuxer; extern AVOutputFormat ff_webvtt_muxer; extern AVInputFormat ff_wsaud_demuxer; +extern AVOutputFormat ff_wsaud_muxer; extern AVInputFormat ff_wsd_demuxer; extern AVInputFormat ff_wsvqa_demuxer; extern AVInputFormat ff_wtv_demuxer; diff --git a/libavformat/westwood_audenc.c b/libavformat/westwood_audenc.c new file mode 100644 index 00..95bda57847 --- /dev/null +++ b/libavformat/westwood_audenc.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2021 Aidan Richmond + * + * 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 + * Westwood Studios AUD file muxer + * by Aidan Richmond (aidan...@hotmail.co.uk) + * + * This muxer supports IMA ADPCM packed in westwoods format. + * + * @see http://xhp.xwis.net/documents/aud3.txt + */ + +#include "libavutil/avassert.h" + +#include "avformat.h" +#include "avio_internal.h" +#include "internal.h" +#include + +#define AUD_CHUNK_SIGNATURE 0xDEAF + +typedef struct AUDMuxContext { +int uncomp_size; +int size; +} AUDMuxContext; + +static int wsaud_init(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; + +/* Stream must be seekable to correctly write the file. */ +if(!(pb->seekable & AVIO_SEEKABLE_NORMAL)) { +av_log(ctx->streams[0], AV_LOG_ERROR, "Cannot write Westwood aud to" + " none seekable stream.\n"); +return AVERROR(EINVAL); +} + +if (st->codecpar->codec_id != AV_CODEC_ID_ADPCM_IMA_WS) { +av_log(st, AV_LOG_ERROR, "%s codec not supported for Westwood AUD.\n", + avcodec_get_name(st->codecpar->codec_id)); +return AVERROR(EINVAL); +} + +if (ctx->nb_streams != 1) { +av_log(st, AV_LOG_ERROR, "AUD files have exactly one stream\n"); +return AVERROR(EINVAL); +} + +return 0; +} + +static int wsaud_write_header(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; +int retval; +unsigned char flags = 0; + +ret = wsaud_init(ctx); + +if (ret) +return ret; + +a->uncomp_size = 0; +a->size = 0; + +/* Flag if we have stereo data. */ +if (st->codecpar->channels == 2) +flags |= 1; + +/* This flags that the file contains 16 bit samples rather than 8 bit + since the encoder only encodes 16 bit samples this should be set. */ +if (av_get_bits_per_sample(st->codecpar->codec_id) == 4) +flags |= 2; + +avio_wl16(pb, st->codecpar->sample_rate); +/* We don't know the file size yet, so just zero 8 bytes */ +ffio_fill(pb, 0, 8); +avio_w8(pb, flags); +/* 99 indicates the ADPCM format. Other formats not supported. */ +avio_w8(pb, 99); + +return 0; +} + +static int wsaud_write_packet(AVFormatContext *ctx, AVPacket *pkt) +{ +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; + +av_assert1(pkt->size < UINT16_MAX && (pkt->size * 4) < UINT16_MAX)
[FFmpeg-devel] [PATCH v3 1/3] avcodec/adpcmenc: Adds encoder for Westwood ADPCM.
Signed-off-by: Aidan Richmond --- libavcodec/Makefile| 1 + libavcodec/adpcmenc.c | 32 ++-- libavcodec/allcodecs.c | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 4a597f727a..fcddde459d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -898,6 +898,7 @@ OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_IMA_WS_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MTAF_DECODER) += adpcm.o adpcm_data.o diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 9dc77d519a..752cae5cf4 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -94,7 +94,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI || avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_APM || -avctx->codec->id == AV_CODEC_ID_ADPCM_ARGO) { +avctx->codec->id == AV_CODEC_ID_ADPCM_ARGO|| +avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_WS) { /* * The current trellis implementation doesn't work for extended * runs of samples without periodic resets. Disallow it. @@ -192,6 +193,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->frame_size = 32; avctx->block_align = 17 * avctx->channels; break; +case AV_CODEC_ID_ADPCM_IMA_WS: +/* each 16 bits sample gives one nibble */ +avctx->frame_size = s->block_size * 2 / avctx->channels; +avctx->block_align = s->block_size; +break; default: return AVERROR(EINVAL); } @@ -594,7 +600,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI || avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_ALP || -avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM) +avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM || +avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_WS) pkt_size = (frame->nb_samples * avctx->channels) / 2; else pkt_size = avctx->block_align; @@ -929,6 +936,26 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, flush_put_bits(&pb); break; } +case AV_CODEC_ID_ADPCM_IMA_WS: +{ +PutBitContext pb; +init_put_bits(&pb, dst, pkt_size); + +av_assert0(avctx->trellis == 0); +for (n = frame->nb_samples / 2; n > 0; n--) { +/* stereo: 1 byte (2 samples) for left, 1 byte for right */ +for (ch = 0; ch < avctx->channels; ch++) { +int t1, t2; +t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++); +t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]); +put_bits(&pb, 4, t2); +put_bits(&pb, 4, t1); +} +samples += avctx->channels; +} +flush_put_bits(&pb); +break; +} default: return AVERROR(EINVAL); } @@ -990,6 +1017,7 @@ ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_ALP, adpcm_ima_alp, sample_fmts, AV_CODEC_ ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, 0, "ADPCM IMA QuickTime"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0, "ADPCM IMA WAV"); +ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Westwood"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_MS, adpcm_ms, sample_fmts, 0, "ADPCM Microsoft"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_SWF, adpcm_swf, sample_fmts, 0, "ADPCM Shockwave Flash"); ADPCM_ENCODER(AV_CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, sample_fmts, 0, "ADPCM Yamaha"); diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 2e9a3581de..b748c9718e 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -645,6 +645,7 @@ extern AVCodec ff_adpcm_ima_ssi_encoder; extern AVCodec ff_adpcm_ima_smjpeg_decoder; extern AVCodec ff_adpcm_ima_wav_encoder; extern AVCodec ff_adpcm_ima_wav_decoder; +extern AVCodec ff_adpcm_ima_ws_encoder; extern AVCodec ff_adpcm_ima_ws_decoder; extern AVCodec ff_adpcm_ms_encoder; extern AVCodec ff_adpcm_ms_decoder; -- 2.16.1.window
Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec/adpcmenc: Adds encoder for Westwood ADPCM.
> +case AV_CODEC_ID_ADPCM_IMA_WS: > +{ > +PutBitContext pb; > +init_put_bits(&pb, dst, pkt_size); > + > +av_assert0(avctx->trellis == 0); > +for (n = frame->nb_samples / 2; n > 0; n--) { > +/* stereo: 1 byte (2 samples) for left, 1 byte for right */ > +for (ch = 0; ch < avctx->channels; ch++) { > +int t1, t2; > +t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++); > +t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]); > +put_bits(&pb, 4, t2); > +put_bits(&pb, 4, t1); > +} > +samples += avctx->channels; You've got the channels flipped around. When run as-is: stddev:14745.44 PSNR: 12.96 MAXDIFF:65535 bytes: 1058400/ 1058400 With: put_bits(&pb, 4, t1); put_bits(&pb, 4, t2); I get: stddev: 906.36 PSNR: 37.18 MAXDIFF:34026 bytes: 1058400/ 1058400 Which is similar to all the other ADPCM codecs. This is assuming the current decoder is correct, of course. Also, could you please --signoff the commits? Zane ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". Turns out that the decoder is wrong. I had submitted a bug to the tracker as I couldn't work out what was wrong with it, I didn't consider it might be reading the nibbles in the wrong order, My next round of updates to the patch will contain a fixed decoder too. Aidan ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 6/7] avcodec/avcodec: Use avcodec_close() on avcodec_open2() failure
Compared to the earlier behaviour the following changes: a) AVCodecInternal.byte_buffer is freed. b) The last_pkt_props FIFO is emptied before freeing it. c) If set AVCodecContext.hwaccel is uninitialized and its private data is freed; hw_frames_ctx and hw_device_ctx are also unreferenced. d) coded_side_data is freed. e) active_thread_type is reset. a), b), d) should be no-ops as the buffer/fifo should be empty and no coded_side_data should exist at any point of avcodec_open2(). e) is obviously not bad. c) is in accordance with the documentation of hw_(frames|device)_ctx which states that libacodec takes over ownership of these references. At least in the case of VC-1 it is possible for the hw acceleration to be set during init and in this case freeing it actually fixes a memleak. avcodec_close() needed only minor adjustments to make it work with a potentially not fully initialized codec. Signed-off-by: Andreas Rheinhardt --- Now including minor necessary adjustments to make avcodec_close() work with a not properly-allocated AVCodecContext. libavcodec/avcodec.c | 59 +++- 1 file changed, 9 insertions(+), 50 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c7a8001608..7f9c9c1c87 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -395,51 +395,8 @@ end: return ret; free_and_end: -if (avci->needs_close && avctx->codec->close) -avctx->codec->close(avctx); - -if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder) -ff_frame_thread_encoder_free(avctx); -if (HAVE_THREADS && avci->thread_ctx) -ff_thread_free(avctx); - -if (codec->priv_class && avctx->priv_data) -av_opt_free(avctx->priv_data); -av_opt_free(avctx); - -if (av_codec_is_encoder(avctx->codec)) { -#if FF_API_CODED_FRAME -FF_DISABLE_DEPRECATION_WARNINGS -av_frame_free(&avctx->coded_frame); -FF_ENABLE_DEPRECATION_WARNINGS -#endif -av_freep(&avctx->extradata); -avctx->extradata_size = 0; -} - +avcodec_close(avctx); av_dict_free(&tmp); -av_freep(&avctx->priv_data); -if (av_codec_is_decoder(avctx->codec)) -av_freep(&avctx->subtitle_header); - -#if FF_API_OLD_ENCDEC -av_frame_free(&avci->to_free); -av_frame_free(&avci->compat_decode_frame); -av_packet_free(&avci->compat_encode_packet); -#endif -av_frame_free(&avci->buffer_frame); -av_packet_free(&avci->buffer_pkt); -av_packet_free(&avci->last_pkt_props); -av_fifo_freep(&avci->pkt_props); - -av_packet_free(&avci->ds.in_pkt); -av_frame_free(&avci->es.in_frame); -av_bsf_free(&avci->bsf); - -av_buffer_unref(&avci->pool); -av_freep(&avci); -avctx->internal = NULL; -avctx->codec = NULL; goto end; } @@ -549,14 +506,15 @@ av_cold int avcodec_close(AVCodecContext *avctx) #endif av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); -av_packet_unref(avci->last_pkt_props); -while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { -av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, - sizeof(*avci->last_pkt_props), NULL); -av_packet_unref(avci->last_pkt_props); +if (avci->pkt_props) { +while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { +av_packet_unref(avci->last_pkt_props); +av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, + sizeof(*avci->last_pkt_props), NULL); +} +av_fifo_freep(&avci->pkt_props); } av_packet_free(&avci->last_pkt_props); -av_fifo_freep(&avci->pkt_props); av_packet_free(&avci->ds.in_pkt); av_frame_free(&avci->es.in_frame); @@ -586,6 +544,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_freep(&avctx->priv_data); if (av_codec_is_encoder(avctx->codec)) { av_freep(&avctx->extradata); +avctx->extradata_size = 0; #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS av_frame_free(&avctx->coded_frame); -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/2] avformat/mpegtsenc: factorize determining pes stream id
Signed-off-by: Marton Balint --- libavformat/mpegtsenc.c | 60 - 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 8ff834be4e..9a387419bf 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1288,6 +1288,36 @@ static uint8_t *get_ts_payload_start(uint8_t *pkt) return pkt + 4; } +static int get_pes_stream_id(AVFormatContext *s, AVStream *st, int stream_id, int *async) +{ +MpegTSWrite *ts = s->priv_data; +*async = 0; +if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { +if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) +return STREAM_ID_EXTENDED_STREAM_ID; +else +return STREAM_ID_VIDEO_STREAM_0; +} else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + (st->codecpar->codec_id == AV_CODEC_ID_MP2 || +st->codecpar->codec_id == AV_CODEC_ID_MP3 || +st->codecpar->codec_id == AV_CODEC_ID_AAC)) { +return STREAM_ID_AUDIO_STREAM_0; +} else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && +st->codecpar->codec_id == AV_CODEC_ID_AC3 && +ts->m2ts_mode) { +return STREAM_ID_EXTENDED_STREAM_ID; +} else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA && + st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) { +return STREAM_ID_PRIVATE_STREAM_1; +} else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { +if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */ +*async = 1; +return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM; +} else { +return STREAM_ID_PRIVATE_STREAM_1; +} +} + /* Add a PES header to the front of the payload, and segment into an integer * number of TS packets. The final TS packet is padded using an oversized * adaptation header to exactly fill the last TS packet. @@ -1410,35 +1440,15 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, if (is_start) { int pes_extension = 0; int pes_header_stuffing_bytes = 0; +int async; /* write PES header */ *q++ = 0x00; *q++ = 0x00; *q++ = 0x01; -if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { -if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) -*q++ = STREAM_ID_EXTENDED_STREAM_ID; -else -*q++ = STREAM_ID_VIDEO_STREAM_0; -} else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - (st->codecpar->codec_id == AV_CODEC_ID_MP2 || -st->codecpar->codec_id == AV_CODEC_ID_MP3 || -st->codecpar->codec_id == AV_CODEC_ID_AAC)) { -*q++ = STREAM_ID_AUDIO_STREAM_0; -} else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && -st->codecpar->codec_id == AV_CODEC_ID_AC3 && -ts->m2ts_mode) { -*q++ = STREAM_ID_EXTENDED_STREAM_ID; -} else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA && - st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) { -*q++ = STREAM_ID_PRIVATE_STREAM_1; -} else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { -*q++ = stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM; - -if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */ -pts = dts = AV_NOPTS_VALUE; -} else { -*q++ = STREAM_ID_PRIVATE_STREAM_1; -} +*q++ = stream_id = get_pes_stream_id(s, st, stream_id, &async); +if (async) +pts = dts = AV_NOPTS_VALUE; + header_len = 0; flags = 0; if (pts != AV_NOPTS_VALUE) { -- 2.26.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: move is_dvb_subtitle/is_dvb_teletext initialization upwards
Signed-off-by: Marton Balint --- libavformat/mpegtsenc.c | 13 +++-- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index a357f3a6aa..8ff834be4e 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1300,8 +1300,10 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, MpegTSWrite *ts = s->priv_data; uint8_t buf[TS_PACKET_SIZE]; uint8_t *q; -int val, is_start, len, header_len, write_pcr, is_dvb_subtitle, is_dvb_teletext, flags; +int val, is_start, len, header_len, write_pcr, flags; int afc_len, stuffing_len; +int is_dvb_subtitle = (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE); +int is_dvb_teletext = (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT); int64_t delay = av_rescale(s->max_delay, 9, AV_TIME_BASE); int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; int force_sdt = 0; @@ -1412,8 +1414,6 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = 0x00; *q++ = 0x00; *q++ = 0x01; -is_dvb_subtitle = 0; -is_dvb_teletext = 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) *q++ = STREAM_ID_EXTENDED_STREAM_ID; @@ -1438,13 +1438,6 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, pts = dts = AV_NOPTS_VALUE; } else { *q++ = STREAM_ID_PRIVATE_STREAM_1; -if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { -if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { -is_dvb_subtitle = 1; -} else if (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT) { -is_dvb_teletext = 1; -} -} } header_len = 0; flags = 0; -- 2.26.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v3 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types
On Thu, 22 Apr 2021, zheng qian wrote: Changes since v2: Fix PES_packet_length mismatch bug According to the PES packet definition defined in Table 2-17 of ISO_IEC_13818-1 specification, some fields like PTS/DTS or pes_extension could only appears if the stream_id meets the condition: if (stream_id != 0xBC && // program_stream_map stream_id != 0xBE && // padding_stream stream_id != 0xBF && // private_stream_2 stream_id != 0xF0 && // ECM stream_id != 0xF1 && // EMM stream_id != 0xFF && // program_stream_directory stream_id != 0xF2 && // DSMCC_stream stream_id != 0xF8) // ITU-T Rec. H.222.1 type E stream And the following stream_id types don't have fields like PTS/DTS: else if ( stream_id == program_stream_map || stream_id == private_stream_2 || stream_id == ECM || stream_id == EMM || stream_id == program_stream_directory || stream_id == DSMCC_stream || stream_id == ITU-T Rec. H.222.1 type E stream ) { for (i = 0; i < PES_packet_length; i++) { PES_packet_data_byte } } Current implementation skipped the judgement of stream_id causing some kind of stream like private_stream_2 to be incorrectly written with PTS/DTS field. For example, Japan DTV transmits news and alerts through ARIB superimpose that utilizes private_stream_2 still could not be remuxed correctly for now. This patch set fixes the remuxing for private_stream_2 and other stream_id types. Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 15 +++ 1 file changed, 15 insertions(+) The order of the patches seems wrong. Patch/3 (or similar) should be applied first, otherwise you are checking the stream_id provided via side data, not the stream id actually used. Also note that is_dvb_teletext/is_dvb_subtitle might not be set if certain stream_id is used, that can also cause issues. I will send a patch series for these two issues, please check them and if they look good then rebase your patchset on top of that. diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index f302af84ff..b59dab5174 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1476,6 +1476,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } } header_len = 0; + +if (stream_id != 0xBC && // program_stream_map +stream_id != 0xBE && // padding_stream +stream_id != 0xBF && // private_stream_2 +stream_id != 0xF0 && // ECM +stream_id != 0xF1 && // EMM +stream_id != 0xFF && // program_stream_directory +stream_id != 0xF2 && // DSMCC_stream +stream_id != 0xF8) { // ITU-T Rec. H.222.1 type E stream You should add the relevant stream type constants to mpegts.h and use those for the checks, you can spare the comments that way. + flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; @@ -1569,6 +1579,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; } +} else { +len = payload_size; +*q++ = len >> 8; +*q++ = len; +} is_start = 0; } /* header size */ Thanks, Marton ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 3/4] avformat/mccdec: Fix overflows in num/den
On 4/24/2021 12:59 PM, Michael Niedermayer wrote: Fixes: signed integer overflow: 6365816 * 1000 cannot be represented in type 'int' Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_MCC_fuzzer-6737934184218624 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mccdec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavformat/mccdec.c b/libavformat/mccdec.c index 2a0b7905a0..7671be61d4 100644 --- a/libavformat/mccdec.c +++ b/libavformat/mccdec.c @@ -127,8 +127,7 @@ static int mcc_read_header(AVFormatContext *s) num = strtol(rate_str, &df, 10); den = 1; if (df && !av_strncasecmp(df, "DF", 2)) { -num *= 1000; -den = 1001; +av_reduce(&num, &den, num * 1000LL, 10001, INT_MAX); 10001? } } ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/4] avformat/mccdec: Fix overflows in num/den
Fixes: signed integer overflow: 6365816 * 1000 cannot be represented in type 'int' Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_MCC_fuzzer-6737934184218624 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mccdec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavformat/mccdec.c b/libavformat/mccdec.c index 2a0b7905a0..7671be61d4 100644 --- a/libavformat/mccdec.c +++ b/libavformat/mccdec.c @@ -127,8 +127,7 @@ static int mcc_read_header(AVFormatContext *s) num = strtol(rate_str, &df, 10); den = 1; if (df && !av_strncasecmp(df, "DF", 2)) { -num *= 1000; -den = 1001; +av_reduce(&num, &den, num * 1000LL, 10001, INT_MAX); } } -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/4] avformat/mpc8: Check for position overflow in mpc8_handle_chunk()
Fixes: signed integer overflow: 15 + 9223372036854775796 cannot be represented in type 'long' Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-6723520756318208 Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-6739833034768384 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mpc8.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index b12a417f63..b3fcae75fb 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -205,8 +205,11 @@ static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, in switch(tag){ case TAG_SEEKTBLOFF: -pos = avio_tell(pb) + size; +pos = avio_tell(pb); off = ffio_read_varlen(pb); +if (pos > INT64_MAX - size || off < 0 || off > INT64_MAX - chunk_pos) +return; +pos += size; mpc8_parse_seektable(s, chunk_pos + off); avio_seek(pb, pos, SEEK_SET); break; -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/4] avformat/iff: Use 64bit in duration computation
Fixes: signed integer overflow: 588 * 16719904 cannot be represented in type 'int' Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_IFF_fuzzer-6748331936186368 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/iff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/iff.c b/libavformat/iff.c index 27b5581cc3..bc4c410ebe 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -384,7 +384,7 @@ static int read_dst_frame(AVFormatContext *s, AVPacket *pkt) avio_skip(pb, 1); pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = 0; -pkt->duration = 588 * s->streams[0]->codecpar->sample_rate / 44100; +pkt->duration = 588LL * s->streams[0]->codecpar->sample_rate / 44100; pkt->pos = chunk_pos; chunk_pos = avio_tell(pb); -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/4] avformat/dxa: Check fps to be within the supported range more precissely
Fixes: negation of -2147483648 cannot be represented in type 'int32_t' (aka 'int'); cast to an unsigned type to negate this value to itself Fixes: assertiomnm failure Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_DXA_fuzzer-6744985740378112 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/dxa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/dxa.c b/libavformat/dxa.c index 909c5ba2ba..cd9c489851 100644 --- a/libavformat/dxa.c +++ b/libavformat/dxa.c @@ -79,7 +79,7 @@ static int dxa_read_header(AVFormatContext *s) if(fps > 0){ den = 1000; num = fps; -}else if (fps < 0){ +}else if (fps < 0 && fps > INT_MIN){ den = 10; num = -fps; }else{ -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 00/11] lavu/tx: FFT improvements, additions and assembly
Apr 19, 2021, 22:19 by d...@lynne.ee: > This patchset cleans up and improves the power-of-two C code, > adds a 7-point and a 9-point FFT, and adds a power-of-two length > floating-point assembly. > Patchset pushed. Hopefully FATE will pass everywhere, but there's enough lenience in the check for any precision gained by FMA that it will. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/7] avcodec/avcodec: Document current behaviour of subtitle_header
James Almer: > On 4/18/2021 11:06 PM, Andreas Rheinhardt wrote: >> Mention that avcodec_free_context() always frees it even when >> encoding. And mention that freeing is of course performed in >> avcodec_close() when decoding and not necessarily in avcodec_open2(). >> >> Signed-off-by: Andreas Rheinhardt >> --- >> libavcodec/avcodec.h | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h >> index 8a71c04230..9b68aecd31 100644 >> --- a/libavcodec/avcodec.h >> +++ b/libavcodec/avcodec.h >> @@ -2011,7 +2011,9 @@ typedef struct AVCodecContext { >> * [Script Info] and [V4+ Styles] section, plus the [Events] >> line and >> * the Format line following. It shouldn't include any Dialogue >> line. >> * - encoding: Set/allocated/freed by user (before avcodec_open2()) >> - * - decoding: Set/allocated/freed by libavcodec (by >> avcodec_open2()) >> + * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2() >> + * resp. avcodec_close()) > > What does resp. mean? > respectively >> + * Furthermore, avcodec_free_context() always frees it even when >> encoding. > > What this doxy is missing is the fact the buffer must be allocated with > av_malloc(), considering we free it with av_free(). > It is actually currently allowed to use custom allocators when encoding (which this patch further restricts to the case of encoding and not using avcodec_free_context()). > LGTM either way. > >> */ >> uint8_t *subtitle_header; >> int subtitle_header_size; >> > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/7] avcodec/avcodec: Document current behaviour of subtitle_header
On 4/18/2021 11:06 PM, Andreas Rheinhardt wrote: Mention that avcodec_free_context() always frees it even when encoding. And mention that freeing is of course performed in avcodec_close() when decoding and not necessarily in avcodec_open2(). Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 8a71c04230..9b68aecd31 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2011,7 +2011,9 @@ typedef struct AVCodecContext { * [Script Info] and [V4+ Styles] section, plus the [Events] line and * the Format line following. It shouldn't include any Dialogue line. * - encoding: Set/allocated/freed by user (before avcodec_open2()) - * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2()) + * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2() + * resp. avcodec_close()) What does resp. mean? + * Furthermore, avcodec_free_context() always frees it even when encoding. What this doxy is missing is the fact the buffer must be allocated with av_malloc(), considering we free it with av_free(). LGTM either way. */ uint8_t *subtitle_header; int subtitle_header_size; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 8/8] avcodec/avcodec: Document current behaviour for extradata
On 4/24/2021 9:53 AM, Andreas Rheinhardt wrote: James Almer: On 4/24/2021 9:29 AM, Andreas Rheinhardt wrote: Despite the documentation saying that it is not freed by libavcodec for a decoder, avcodec_free_context() does so and has been doing so since this function has been added more than seven years ago. Honouring the current documentation in avcodec_free_context() would add memleaks to all users of it that don't free their extradata manually; given how long this behaviour has been around we can safely assume that these are many (i.e. the fftools are among them, as is libavformat as well as parts of libavcodec itself). Therefore adapt the documentation to match actual behaviour. This fixes ticket #5027. Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b9b487be41..4596d12647 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -633,6 +633,8 @@ typedef struct AVCodecContext { * Must be allocated with the av_malloc() family of functions. * - encoding: Set/allocated/freed by libavcodec. * - decoding: Set/allocated/freed by user. + * Additionally, avcodec_free_context() frees it regardless of whether + * the context is used for encoding or not. I'd prefer to instead change the decoding line to * - decoding: Set/allocated by user, freed by libavcodec. This would be wrong as avcodec_close() does not free it for decoders. Changing the behaviour would be a breaking change. avcodec_free_context() needs to be called to free any AVCodecContext. doing avcodec_close(avctx) + av_free(avctx) (Or worse, reusing the avctx after avcodec_close()) is not only heavily discouraged by the doxy, but already leads to leaks if you don't free a bunch of things, like extradata, intra_matrix and inter_matrix. Maybe also (or instead) change the * Must be allocated with the av_malloc() family of functions. line with * Must be allocated with the av_malloc() family of functions, and will be freed in avcodec_free_context(). Which puts the extradata doxy in line with the other two fields, both of which are handled in a similar way. Leaving the line about freed by user is IMO pointless, considering you even mentioned in the patch message how nobody ever bothers to free it. Honestly? avcodec_close() should have been deprecated alongside avcodec_get_context_defaults3() and avcodec_copy_context(), so maybe we should do it now. Having a function with its doxy saying "Do not use this function" is pretty silly. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 8/8] avcodec/avcodec: Document current behaviour for extradata
James Almer: > On 4/24/2021 9:29 AM, Andreas Rheinhardt wrote: >> Despite the documentation saying that it is not freed by libavcodec >> for a decoder, avcodec_free_context() does so and has been doing so >> since this function has been added more than seven years ago. >> >> Honouring the current documentation in avcodec_free_context() would >> add memleaks to all users of it that don't free their extradata >> manually; given how long this behaviour has been around we can safely >> assume that these are many (i.e. the fftools are among them, as is >> libavformat as well as parts of libavcodec itself). >> >> Therefore adapt the documentation to match actual behaviour. >> This fixes ticket #5027. >> >> Signed-off-by: Andreas Rheinhardt >> --- >> libavcodec/avcodec.h | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h >> index b9b487be41..4596d12647 100644 >> --- a/libavcodec/avcodec.h >> +++ b/libavcodec/avcodec.h >> @@ -633,6 +633,8 @@ typedef struct AVCodecContext { >> * Must be allocated with the av_malloc() family of functions. >> * - encoding: Set/allocated/freed by libavcodec. >> * - decoding: Set/allocated/freed by user. >> + * Additionally, avcodec_free_context() frees it regardless of >> whether >> + * the context is used for encoding or not. > > I'd prefer to instead change the decoding line to > > * - decoding: Set/allocated by user, freed by libavcodec. This would be wrong as avcodec_close() does not free it for decoders. Changing the behaviour would be a breaking change. - Andreas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 82/87] avformat: remove deprecated AVStream.codec
James Almer: > Signed-off-by: James Almer > --- > fftools/ffmpeg_opt.c | 13 --- > libavformat/avformat.h| 8 +- > libavformat/dump.c| 24 -- > libavformat/isom.c| 12 +-- > libavformat/mov.c | 17 > libavformat/movenc.c | 38 + > libavformat/mux.c | 27 --- > libavformat/sdp.c | 18 - > libavformat/segment.c | 6 -- > libavformat/utils.c | 164 +- > libavformat/version.h | 3 - > libavformat/yuv4mpegenc.c | 7 -- > 12 files changed, 7 insertions(+), 330 deletions(-) > > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > index 28069d45dc..3e307efb16 100644 > --- a/libavformat/avformat.h > +++ b/libavformat/avformat.h > @@ -839,13 +839,7 @@ typedef struct AVStream { > * encoding: set by the user, replaced by libavformat if left unset > */ > int id; > -#if FF_API_LAVF_AVCTX > -/** > - * @deprecated use the codecpar struct instead > - */ > -attribute_deprecated > -AVCodecContext *codec; > -#endif The documentation of avformat_new_stream() must also be updated. E.g.: "User is required to call avcodec_close() and avformat_free_context() to clean up the allocation by avformat_new_stream()." Furthermore, the AVCodec parameter is currently only used for the public AVCodecContext that is about to be removed and not the private AVCodecContext, so I wonder whether this should be changed or if we should add a avformat_new_stream2() without this useless parameter. > + > void *priv_data; > > /** > diff --git a/libavformat/utils.c b/libavformat/utils.c > index 2f66f539a6..49bf19b2b0 100644 > --- a/libavformat/utils.c > +++ b/libavformat/utils.c > @@ -158,13 +158,6 @@ int ff_copy_whiteblacklists(AVFormatContext *dst, const > AVFormatContext *src) > > static const AVCodec *find_decoder(AVFormatContext *s, const AVStream *st, > enum AVCodecID codec_id) > { > -#if FF_API_LAVF_AVCTX > -FF_DISABLE_DEPRECATION_WARNINGS > -if (st->codec->codec) > -return st->codec->codec; > -FF_ENABLE_DEPRECATION_WARNINGS > -#endif > - > switch (st->codecpar->codec_type) { > case AVMEDIA_TYPE_VIDEO: > if (s->video_codec)return s->video_codec; > @@ -354,12 +347,6 @@ static int set_codec_from_probe_data(AVFormatContext *s, > AVStream *st, > st->codecpar->codec_id = fmt_id_type[i].id; > st->codecpar->codec_type = fmt_id_type[i].type; > st->internal->need_context_update = 1; > -#if FF_API_LAVF_AVCTX > -FF_DISABLE_DEPRECATION_WARNINGS > -st->codec->codec_type = st->codecpar->codec_type; > -st->codec->codec_id = st->codecpar->codec_id; > -FF_ENABLE_DEPRECATION_WARNINGS > -#endif > return score; > } > } > @@ -480,15 +467,6 @@ static int update_stream_avctx(AVFormatContext *s) > if (ret < 0) > return ret; > > -#if FF_API_LAVF_AVCTX > -FF_DISABLE_DEPRECATION_WARNINGS > -/* update deprecated public codec context */ > -ret = avcodec_parameters_to_context(st->codec, st->codecpar); > -if (ret < 0) > -return ret; > -FF_ENABLE_DEPRECATION_WARNINGS > -#endif > - > st->internal->need_context_update = 0; > } > return 0; > @@ -920,13 +898,6 @@ void ff_compute_frame_duration(AVFormatContext *s, int > *pnum, int *pden, AVStrea > > av_mul_q(av_inv_q(st->internal->avctx->time_base), (AVRational){1, > st->internal->avctx->ticks_per_frame}); > int frame_size, sample_rate; > > -#if FF_API_LAVF_AVCTX > -FF_DISABLE_DEPRECATION_WARNINGS > -if ((!codec_framerate.den || !codec_framerate.num) && > st->codec->time_base.den && st->codec->time_base.num) > -codec_framerate = av_mul_q(av_inv_q(st->codec->time_base), > (AVRational){1, st->codec->ticks_per_frame}); > -FF_ENABLE_DEPRECATION_WARNINGS > -#endif > - > *pnum = 0; > *pden = 0; > switch (st->codecpar->codec_type) { > @@ -1547,17 +1518,6 @@ static int read_frame_internal(AVFormatContext *s, > AVPacket *pkt) > return ret; > } > > -#if FF_API_LAVF_AVCTX > -FF_DISABLE_DEPRECATION_WARNINGS > -/* update deprecated public codec context */ > -ret = avcodec_parameters_to_context(st->codec, st->codecpar); > -if (ret < 0) { > -av_packet_unref(pkt); > -return ret; > -} > -FF_ENABLE_DEPRECATION_WARNINGS > -#endif > - > st->internal->need_context_update = 0; > } > > @@ -1680,10 +1640,6 @@ FF_ENABLE_DEPRECATION_WARNINGS > av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); > } > > -#if FF_API_LAVF_AVCTX > -update_stream_avctx(s); > -#endif > - > if (s->debug & FF_FDEBUG_TS) > av_log(s, AV_LOG_DEBUG, > "read_f
Re: [FFmpeg-devel] [PATCH 8/8] avcodec/avcodec: Document current behaviour for extradata
On 4/24/2021 9:29 AM, Andreas Rheinhardt wrote: Despite the documentation saying that it is not freed by libavcodec for a decoder, avcodec_free_context() does so and has been doing so since this function has been added more than seven years ago. Honouring the current documentation in avcodec_free_context() would add memleaks to all users of it that don't free their extradata manually; given how long this behaviour has been around we can safely assume that these are many (i.e. the fftools are among them, as is libavformat as well as parts of libavcodec itself). Therefore adapt the documentation to match actual behaviour. This fixes ticket #5027. Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b9b487be41..4596d12647 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -633,6 +633,8 @@ typedef struct AVCodecContext { * Must be allocated with the av_malloc() family of functions. * - encoding: Set/allocated/freed by libavcodec. * - decoding: Set/allocated/freed by user. + * Additionally, avcodec_free_context() frees it regardless of whether + * the context is used for encoding or not. I'd prefer to instead change the decoding line to * - decoding: Set/allocated by user, freed by libavcodec. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 8/8] avcodec/avcodec: Document current behaviour for extradata
Despite the documentation saying that it is not freed by libavcodec for a decoder, avcodec_free_context() does so and has been doing so since this function has been added more than seven years ago. Honouring the current documentation in avcodec_free_context() would add memleaks to all users of it that don't free their extradata manually; given how long this behaviour has been around we can safely assume that these are many (i.e. the fftools are among them, as is libavformat as well as parts of libavcodec itself). Therefore adapt the documentation to match actual behaviour. This fixes ticket #5027. Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b9b487be41..4596d12647 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -633,6 +633,8 @@ typedef struct AVCodecContext { * Must be allocated with the av_malloc() family of functions. * - encoding: Set/allocated/freed by libavcodec. * - decoding: Set/allocated/freed by user. + * Additionally, avcodec_free_context() frees it regardless of whether + * the context is used for encoding or not. */ uint8_t *extradata; int extradata_size; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/7] avcodec/avcodec: Document current behaviour of subtitle_header
Andreas Rheinhardt: > Mention that avcodec_free_context() always frees it even when > encoding. And mention that freeing is of course performed in > avcodec_close() when decoding and not necessarily in avcodec_open2(). > > Signed-off-by: Andreas Rheinhardt > --- > libavcodec/avcodec.h | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > index 8a71c04230..9b68aecd31 100644 > --- a/libavcodec/avcodec.h > +++ b/libavcodec/avcodec.h > @@ -2011,7 +2011,9 @@ typedef struct AVCodecContext { > * [Script Info] and [V4+ Styles] section, plus the [Events] line and > * the Format line following. It shouldn't include any Dialogue line. > * - encoding: Set/allocated/freed by user (before avcodec_open2()) > - * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2()) > + * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2() > + * resp. avcodec_close()) > + * Furthermore, avcodec_free_context() always frees it even when > encoding. > */ > uint8_t *subtitle_header; > int subtitle_header_size; > Will apply patches 2-6 later today unless there are objections. - Andreas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 14/14] avcodec/ffv1: Use av_memdup() instead of av_mallocz()+memcpy()
Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 8e7542f918..a5f5449602 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -120,19 +120,18 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) av_assert0(max_slice_count > 0); for (i = 0; i < max_slice_count;) { +FFV1Context *fs = av_memdup(f, sizeof(*fs)); int sx = i % f->num_h_slices; int sy = i / f->num_h_slices; int sxs = f->avctx->width * sx / f->num_h_slices; int sxe = f->avctx->width * (sx + 1) / f->num_h_slices; int sys = f->avctx->height * sy / f->num_v_slices; int sye = f->avctx->height * (sy + 1) / f->num_v_slices; -FFV1Context *fs = av_mallocz(sizeof(*fs)); if (!fs) goto memfail; f->slice_context[i] = fs; -memcpy(fs, f, sizeof(*fs)); memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2)); fs->slice_index = i++; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 08/14] avcodec/ffv1dec: Check allocations for failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 12 1 file changed, 12 insertions(+) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 45bfe21be5..791dc073bf 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -259,9 +259,17 @@ static int decode_slice(AVCodecContext *c, void *arg) if (fssrc->ac) { pdst->state = av_malloc_array(CONTEXT_SIZE, psrc->context_count); +if (!pdst->state) { +ret = AVERROR(ENOMEM); +goto fail; +} memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count); } else { pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count); +if (!pdst->vlc_state) { +ret = AVERROR(ENOMEM); +goto fail; +} memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count); } } @@ -343,6 +351,10 @@ static int decode_slice(AVCodecContext *c, void *arg) ff_thread_report_progress(&f->picture, si, 0); return 0; +fail: +fs->slice_damaged = 1; +ff_thread_report_progress(&f->picture, si, 0); +return ret; } static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale) -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 07/14] avcodec/ffv1dec: Don't copy fields unnecessarily
Copy slice-only fields only for the slicecontexts and not for the main contexts in update_thread_context(). The converse is true for e.g. key_frame_ok which is only used with the main context; when not doing frame-threaded decoding it is actually only ever set for the main context, so not setting it for the slice contexts when doing frame threading is more consistent. Signed-off-by: Andreas Rheinhardt --- I wonder whether one should use different structures for the main context and the slice contexts. libavcodec/ffv1dec.c | 27 +-- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index ef908a24b7..45bfe21be5 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -993,8 +993,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac return buf_size; } -static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, -const FFV1Context *fsrc) +static void copy_fields(FFV1Context *fsdst, const FFV1Context *fsrc) { fsdst->version = fsrc->version; fsdst->micro_version = fsrc->micro_version; @@ -1007,18 +1006,8 @@ static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, fsdst->colorspace = fsrc->colorspace; fsdst->ec = fsrc->ec; -fsdst->intra = fsrc->intra; -fsdst->slice_damaged = fssrc->slice_damaged; -fsdst->key_frame_ok= fsrc->key_frame_ok; fsdst->packed_at_lsb = fsrc->packed_at_lsb; -fsdst->slice_count = fsrc->slice_count; -if (fsrc->version<3){ -fsdst->slice_x = fssrc->slice_x; -fsdst->slice_y = fssrc->slice_y; -fsdst->slice_width = fssrc->slice_width; -fsdst->slice_height= fssrc->slice_height; -} } #if HAVE_THREADS @@ -1031,8 +1020,11 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) if (dst == src) return 0; -copy_fields(fdst, fsrc, fsrc); +copy_fields(fdst, fsrc); fdst->use32bit = fsrc->use32bit; +fdst->intra= fsrc->intra; +fdst->key_frame_ok = fsrc->key_frame_ok; +fdst->slice_count = fsrc->slice_count; memcpy(fdst->state_transition, fsrc->state_transition, sizeof(fdst->state_transition)); memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table)); @@ -1040,7 +1032,14 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) for (i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; -copy_fields(fsdst, fssrc, fsrc); +copy_fields(fsdst, fsrc); +fsdst->slice_damaged = fssrc->slice_damaged; +if (fsrc->version < 3) { +fsdst->slice_x = fssrc->slice_x; +fsdst->slice_y = fssrc->slice_y; +fsdst->slice_width = fssrc->slice_width; +fsdst->slice_height = fssrc->slice_height; +} } av_assert0(!fdst->plane[0].state); av_assert0(!fdst->sample_buffer); -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 13/14] avcodec/ffv1dec: Combine identical checks
Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 060efc25ab..9a755937e6 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -234,16 +234,14 @@ static int decode_slice(AVCodecContext *c, void *arg) av_assert1(si >= 0 && si < MAX_SLICES && f->slice_context[si] == fs); -if(f->fsrc && !p->key_frame) -ff_thread_await_progress(&f->last_picture, si, 0); - if(f->fsrc && !p->key_frame) { FFV1Context *fssrc = f->fsrc->slice_context[si]; FFV1Context *fsdst = fs; + av_assert1(fsdst->plane_count == fssrc->plane_count); +ff_thread_await_progress(&f->last_picture, si, 0); -if (!p->key_frame) -fsdst->slice_damaged |= fssrc->slice_damaged; +fsdst->slice_damaged |= fssrc->slice_damaged; for (i = 0; i < f->plane_count; i++) { PlaneContext *psrc = &fssrc->plane[i]; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 12/14] avcodec/ffv1, ffv1dec: Store index of slice context
instead of searching the index again and again each time a slice is decoded. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1.c| 3 ++- libavcodec/ffv1.h| 1 + libavcodec/ffv1dec.c | 8 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 47bb032876..8e7542f918 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -131,10 +131,11 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) if (!fs) goto memfail; -f->slice_context[i++] = fs; +f->slice_context[i] = fs; memcpy(fs, f, sizeof(*fs)); memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2)); +fs->slice_index = i++; fs->slice_width = sxe - sxs; fs->slice_height = sye - sys; fs->slice_x = sxs; diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index f5ac8090bd..7f97b2c6f7 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -127,6 +127,7 @@ typedef struct FFV1Context { int quant_table_count; struct FFV1Context *slice_context[MAX_SLICES]; +int slice_index; int slice_count; int max_slice_count; int num_v_slices; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index c16fc81927..060efc25ab 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -230,19 +230,17 @@ static int decode_slice(AVCodecContext *c, void *arg) int width, height, x, y, ret; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; AVFrame * const p = f->cur; -int i, si; +int i, si = fs->slice_index; -for( si=0; fs != f->slice_context[si]; si ++) -; +av_assert1(si >= 0 && si < MAX_SLICES && f->slice_context[si] == fs); if(f->fsrc && !p->key_frame) ff_thread_await_progress(&f->last_picture, si, 0); if(f->fsrc && !p->key_frame) { FFV1Context *fssrc = f->fsrc->slice_context[si]; -FFV1Context *fsdst = f->slice_context[si]; +FFV1Context *fsdst = fs; av_assert1(fsdst->plane_count == fssrc->plane_count); -av_assert1(fsdst == fs); if (!p->key_frame) fsdst->slice_damaged |= fssrc->slice_damaged; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 10/14] avcodec/ffv1dec: Treat all slices as damaged if frame is fully discarded
In this case each slice's context is damaged, so decoding future frames will fail until the next keyframe; furthermore, in case of frame threading, the current thread's decoding state is not updated based upon the earlier frame's decoding state, so that the damaged frames produced by frame threaded decoding do not coincide with the result of received by non-multithreaded decoding/slice-threaded decoding. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 28 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index bddfd8e2fb..c9583db60a 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -870,9 +870,27 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac } p->key_frame = 0; } +buf_p = buf + buf_size; +for (i = f->slice_count - 1; i >= 0; i--) { +int trailer = 3 + 5*!!f->ec; +int v; + +if (i || f->version > 2) { +if (trailer > buf_p - buf || +buf_p - c->bytestream_start < (v = AV_RB24(buf_p-trailer) + trailer)) { +f->key_frame_ok = 0; +av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n"); +return AVERROR_INVALIDDATA; +} +buf_p -= v; +} +} -if ((ret = ff_thread_get_buffer(avctx, &f->picture, AV_GET_BUFFER_FLAG_REF)) < 0) +ret = ff_thread_get_buffer(avctx, &f->picture, AV_GET_BUFFER_FLAG_REF); +if (ret < 0) { +f->key_frame_ok = 0; return ret; +} if (avctx->debug & FF_DEBUG_PICT_INFO) av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d slices:%d bps:%d\n", @@ -887,14 +905,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac int v; if (i || f->version > 2) { -if (trailer > buf_p - buf) v = INT_MAX; -else v = AV_RB24(buf_p-trailer) + trailer; +v = AV_RB24(buf_p-trailer) + trailer; } else v = buf_p - c->bytestream_start; -if (buf_p - c->bytestream_start < v) { -av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n"); -ff_thread_report_progress(&f->picture, INT_MAX, 0); -return AVERROR_INVALIDDATA; -} buf_p -= v; if (f->ec) { -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 09/14] avcodec/ffv1dec: Fix segfault with frame threading upon error
It is possible for the source state to be NULL, namely if an error happened in the src thread and it never even reached the point of decoding the slices; or if the allocation of src's states failed. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 791dc073bf..bddfd8e2fb 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -256,7 +256,10 @@ static int decode_slice(AVCodecContext *c, void *arg) memcpy(pdst, psrc, sizeof(*pdst)); pdst->state = NULL; pdst->vlc_state = NULL; - +if (fssrc->ac && !psrc->state || !fssrc->ac && !psrc->vlc_state) { +ret = AVERROR_INVALIDDATA; +goto fail; +} if (fssrc->ac) { pdst->state = av_malloc_array(CONTEXT_SIZE, psrc->context_count); if (!pdst->state) { -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 11/14] avcodec/ffv1dec: Fix race when updating slice_damaged
A slice is marked as damaged when its checksums indicate an error or if it is not a keyframe and the same slice of the preceding frame was damaged. These checksums are only evaluated after ff_thread_finish_setup() has been called and therefore setting them actually constitutes a data race when using frame threading, because the decoder's update_thread_context copies it. This is undefined behaviour, but in practice it works: If the src slice is damaged, but its preceding slice is not, then it is indeed uncertain whether the dst slice will already be marked as damaged in update_thread_context(); but decoding the slice only begins after the src slice has been completely decoded in which case the dst slice will be marked as damaged if the src slice is so marked. Yet it is still a data race; fixing it is easy: Don't copy slice_damaged in update_thread_context; instead just reset it there and only set it when it is known whether the src slice is damaged or not, i.e. after the src slice has been decoded. This fixes all ffv1-FATE-tests with TSAN when frame-threading is used. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index c9583db60a..c16fc81927 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1060,7 +1060,12 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; copy_fields(fsdst, fsrc); -fsdst->slice_damaged = fssrc->slice_damaged; +/* Reset fsdst->slice_damaged here. decode_frame() will set it + * if the slice crc indicates an error and decode_slice() will + * set it after the same slice from the previous frame has + * been decoded if said slice has it set. Copying the field + * here would be a race. */ +fsdst->slice_damaged = 0; if (fsrc->version < 3) { fsdst->slice_x = fssrc->slice_x; fsdst->slice_y = fssrc->slice_y; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 06/14] avcodec/ffv1dec: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 9a9ee10a4c..ef908a24b7 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1037,13 +1037,13 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) sizeof(fdst->state_transition)); memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table)); -for (i = 0; inum_h_slices * fdst->num_v_slices; i++) { -FFV1Context *fssrc = fsrc->slice_context[i]; -FFV1Context *fsdst = fdst->slice_context[i]; -copy_fields(fsdst, fssrc, fsrc); -} -av_assert0(!fdst->plane[0].state); -av_assert0(!fdst->sample_buffer); +for (i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { +FFV1Context *fssrc = fsrc->slice_context[i]; +FFV1Context *fsdst = fdst->slice_context[i]; +copy_fields(fsdst, fssrc, fsrc); +} +av_assert0(!fdst->plane[0].state); +av_assert0(!fdst->sample_buffer); av_assert1(fdst->max_slice_count == fsrc->max_slice_count); -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 04/14] avcodec/ffv1dec: Don't copy unused field
The decoder always uses AVCodecContext.bits_per_raw_sample. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 3ac2904b63..c08ec5c1b7 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1011,7 +1011,6 @@ static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, fsdst->slice_damaged = fssrc->slice_damaged; fsdst->key_frame_ok= fsrc->key_frame_ok; -fsdst->bits_per_raw_sample = fsrc->bits_per_raw_sample; fsdst->packed_at_lsb = fsrc->packed_at_lsb; fsdst->slice_count = fsrc->slice_count; if (fsrc->version<3){ -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 05/14] avcodec/ffv1dec: Fix data races emanating from copying whole context
When using frame threading, the FFV1 decoder's update_thread_context() function copies the whole context and afterwards restores some allocated fields with backups made earlier. Among these fields are the ThreadFrames and the source context's ThreadFrames can change concurrently without any synchronization, leading to data races which are undefined behaviour even if they don't lead to problems in practice (as the destination's own ThreadFrames are restored directly thereafter). Fix this by only copying the actually needed fields. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 19 ++- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index c08ec5c1b7..9a9ee10a4c 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1031,18 +1031,12 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) if (dst == src) return 0; -{ -ThreadFrame picture = fdst->picture, last_picture = fdst->last_picture; -uint8_t (*initial_states[MAX_QUANT_TABLES])[32]; -struct FFV1Context *slice_context[MAX_SLICES]; -memcpy(initial_states, fdst->initial_states, sizeof(fdst->initial_states)); -memcpy(slice_context, fdst->slice_context , sizeof(fdst->slice_context)); - -memcpy(fdst, fsrc, sizeof(*fdst)); -memcpy(fdst->initial_states, initial_states, sizeof(fdst->initial_states)); -memcpy(fdst->slice_context, slice_context , sizeof(fdst->slice_context)); -fdst->picture = picture; -fdst->last_picture = last_picture; +copy_fields(fdst, fsrc, fsrc); +fdst->use32bit = fsrc->use32bit; +memcpy(fdst->state_transition, fsrc->state_transition, + sizeof(fdst->state_transition)); +memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table)); + for (i = 0; inum_h_slices * fdst->num_v_slices; i++) { FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; @@ -1050,7 +1044,6 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) } av_assert0(!fdst->plane[0].state); av_assert0(!fdst->sample_buffer); -} av_assert1(fdst->max_slice_count == fsrc->max_slice_count); -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 03/14] avcodec/ffv1, ffv1dec: Add const where appropriate
Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1.c| 4 ++-- libavcodec/ffv1.h| 4 ++-- libavcodec/ffv1dec.c | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 1c580c3b49..47bb032876 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -63,7 +63,7 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx) return 0; } -av_cold int ff_ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs) +av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) { int j, i; @@ -170,7 +170,7 @@ int ff_ffv1_allocate_initial_states(FFV1Context *f) return 0; } -void ff_ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs) +void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs) { int i, j; diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 81cbe8757d..f5ac8090bd 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -142,11 +142,11 @@ typedef struct FFV1Context { } FFV1Context; int ff_ffv1_common_init(AVCodecContext *avctx); -int ff_ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs); +int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs); int ff_ffv1_init_slices_state(FFV1Context *f); int ff_ffv1_init_slice_contexts(FFV1Context *f); int ff_ffv1_allocate_initial_states(FFV1Context *f); -void ff_ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs); +void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs); int ff_ffv1_close(AVCodecContext *avctx); static av_always_inline int fold(int diff, int bits) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index b3481df922..3ac2904b63 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -161,7 +161,7 @@ static int decode_plane(FFV1Context *s, uint8_t *src, return 0; } -static int decode_slice_header(FFV1Context *f, FFV1Context *fs) +static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; @@ -993,7 +993,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac return buf_size; } -static void copy_fields(FFV1Context *fsdst, FFV1Context *fssrc, FFV1Context *fsrc) +static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, +const FFV1Context *fsrc) { fsdst->version = fsrc->version; fsdst->micro_version = fsrc->micro_version; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 02/14] avcodec/ffv1dec: Don't set ThreadFrame properties, fix race
Each FFV1 slice has its own SAR and picture structure encoded; when a slice header was parsed, the relevant fields of a ThreadFrame's AVFrame were directly set based upon the parsed values. This is a data race in case slice threading is in use because of the concurrent writes. In case of frame threading, it is also a data race because the writes happen after ff_thread_finish_setup(), so that the reads performed by ff_thread_ref_frame() are unsynchronized with the writes performed when parsing the header. This commit fixes these issues by not writing to the ThreadFrame at all; instead the raw data is read into the each SliceContext first; after decoding the current frame and creating the actual output frame these values are compared to each other. If they are valid and coincide, the derived value is written directly to the output frame, not to the ThreadFrame, thereby avoiding data races. This fixes most FFV1 FATE-tests completely when using slice threading; the exceptions are fate-vsynth3-ffv1, vsynth3-ffv1-v3-yuv420p and vsynth3-ffv1-v3-yuv422p10. (In these tests the partitioning into slices does not honour chroma subsampling; as a result, chroma pixels at slice borders get set by more than one thread without any synchronization.) Signed-off-by: Andreas Rheinhardt --- The spec [1] does not rule out that these values differ on a per-slice basis; I don't know whether this is even intended (is there a use-case for this?). That the slice dimensions needn't be compatible with subsampling is very weird. I think it is possible for two adjacent slices to set different values for the same chroma pixel. libavcodec/ffv1.h| 2 ++ libavcodec/ffv1dec.c | 62 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 147fe7ae16..81cbe8757d 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -96,6 +96,8 @@ typedef struct FFV1Context { struct FFV1Context *fsrc; AVFrame *cur; +int picture_structure; +AVRational sample_aspect_ratio; int plane_count; int ac; ///< 1=range coder <-> 0=golomb rice int ac_byte_count; ///< number of bytes used for AC coding diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 24dfc68ca4..b3481df922 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -165,7 +165,7 @@ static int decode_slice_header(FFV1Context *f, FFV1Context *fs) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; -unsigned ps, i, context_count; +unsigned i, context_count; memset(state, 128, sizeof(state)); av_assert0(f->version > 2); @@ -203,26 +203,9 @@ static int decode_slice_header(FFV1Context *f, FFV1Context *fs) p->context_count = context_count; } -ps = get_symbol(c, state, 0); -if (ps == 1) { -f->cur->interlaced_frame = 1; -f->cur->top_field_first = 1; -} else if (ps == 2) { -f->cur->interlaced_frame = 1; -f->cur->top_field_first = 0; -} else if (ps == 3) { -f->cur->interlaced_frame = 0; -} -f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0); -f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0); - -if (av_image_check_sar(f->width, f->height, - f->cur->sample_aspect_ratio) < 0) { -av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", - f->cur->sample_aspect_ratio.num, - f->cur->sample_aspect_ratio.den); -f->cur->sample_aspect_ratio = (AVRational){ 0, 1 }; -} +fs->picture_structure = get_symbol(c, state, 0); +fs->sample_aspect_ratio.num = get_symbol(c, state, 0); +fs->sample_aspect_ratio.den = get_symbol(c, state, 0); if (fs->version > 3) { fs->slice_reset_contexts = get_rac(c, state); @@ -967,9 +950,44 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac if (f->last_picture.f) ff_thread_release_buffer(avctx, &f->last_picture); -if ((ret = av_frame_ref(data, f->picture.f)) < 0) +p = data; +if ((ret = av_frame_ref(p, f->picture.f)) < 0) return ret; +if (f->version > 2) { +AVRational sar = f->slice_context[0]->sample_aspect_ratio; +int picture_structure; + +for (i = f->slice_count - 1; i > 0; i--) +if (f->slice_context[i]->sample_aspect_ratio.num != sar.num || +f->slice_context[i]->sample_aspect_ratio.den != sar.den) +break; +if (i > 0) { +av_log(avctx, AV_LOG_WARNING, "ignoring inconsistent SAR\n"); +p->sample_aspect_ratio = (AVRational){ 0, 1 }; +} else if (av_image_check_sar(f->width, f->height, sar) < 0) { +av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", + sar.num, sar.den); +p->sample_aspect_ratio = (AVRational){ 0, 1 };
Re: [FFmpeg-devel] [PATCH v2 2/2] avformat/westwoodaudenc: Adds muxer for Westwood AUD format.
On 24/4/21 8:35 am, Aidan Richmond wrote: Format is still used by modders of these old games. --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/westwood_audenc.c | 129 ++ 3 files changed, 131 insertions(+) create mode 100644 libavformat/westwood_audenc.c diff --git a/libavformat/Makefile b/libavformat/Makefile index bc1ddfa81c..85b5d8e7eb 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -581,6 +581,7 @@ OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o +OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv_common.o \ diff --git a/libavformat/allformats.c b/libavformat/allformats.c index fa093c7ac2..fe70a1e9a2 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -478,6 +478,7 @@ extern AVOutputFormat ff_webp_muxer; extern AVInputFormat ff_webvtt_demuxer; extern AVOutputFormat ff_webvtt_muxer; extern AVInputFormat ff_wsaud_demuxer; +extern AVOutputFormat ff_wsaud_muxer; extern AVInputFormat ff_wsd_demuxer; extern AVInputFormat ff_wsvqa_demuxer; extern AVInputFormat ff_wtv_demuxer; diff --git a/libavformat/westwood_audenc.c b/libavformat/westwood_audenc.c new file mode 100644 index 00..e381aa9a1a --- /dev/null +++ b/libavformat/westwood_audenc.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 Aidan Richmond + * + * 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 + * Westwood Studios AUD file muxer + * by Aidan Richmond (aidan...@hotmail.co.uk) + * + * This muxer supports IMA ADPCM packed in westwoods format. + * + * @see http://xhp.xwis.net/documents/aud3.txt + */ + +#include "libavutil/avassert.h" + +#include "avformat.h" +#include "avio_internal.h" +#include "internal.h" +#include + +#define AUD_CHUNK_SIGNATURE 0xDEAF + +typedef struct AUDMuxContext { +int uncomp_size; +int size; +} AUDMuxContext; + +static int wsaud_write_header(AVFormatContext *ctx) +{ +AVStream *st = ctx->streams[0]; +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; +unsigned char flags = 0; + +if (st->codecpar->codec_id != AV_CODEC_ID_ADPCM_IMA_WS) { +av_log(st, AV_LOG_ERROR, "%s codec not supported for Westwood AUD.\n", + avcodec_get_name(st->codecpar->codec_id)); +return -1; +} + +if (ctx->nb_streams != 1) { +av_log(st, AV_LOG_ERROR, "AUD files have exactly one stream\n"); +return AVERROR(EINVAL); +} + +a->uncomp_size = 0; +a->size = 0; + +/* Flag if we have stereo data. */ +if (st->codecpar->channels == 2) +flags |= 1; + +/* This flags that the file contains 16 bit samples rather than 8 bit + since the encoder only encodes 16 bit samples this should be set. */ +if (av_get_bits_per_sample(st->codecpar->codec_id) == 4) +flags |= 2; + +avio_wl16(pb, st->codecpar->sample_rate); +/* We don't know the file size yet, so just zero 8 bytes */ +ffio_fill(pb, 0, 8); +avio_w8(pb, flags); +/* 99 indicates the ADPCM format. Other formats not supported. */ +avio_w8(pb, 99); + +return 0; +} + +static int wsaud_write_packet(AVFormatContext *ctx, AVPacket *pkt) +{ +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; + +av_assert1(pkt->size < UINT16_MAX && (pkt->size * 4) < UINT16_MAX); +/* Assumes ADPCM since this muxer doesn't support SND1 or PCM format. */ +avio_wl16(pb, pkt->size); +avio_wl16(pb, pkt->size * 4); +avio_wl32(pb, AUD_CHUNK_SIGNATURE); +avio_write(pb, pkt->data, pkt->size); +a->size += pkt->size + 8; +a->uncomp_size += pkt->size * 4; + +return 0; +} + +static int wsaud_write_trailer(AVFormatContext *ctx) +{ +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; + +if(!pb->seekable) { And should be !(s->pb->seekable & AVIO
Re: [FFmpeg-devel] [PATCH v2 2/2] avformat/westwoodaudenc: Adds muxer for Westwood AUD format.
On 24/4/21 8:35 am, Aidan Richmond wrote: + +static int wsaud_write_trailer(AVFormatContext *ctx) +{ +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; + +if(!pb->seekable) { Also missing a space. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 01/14] avcodec/ffv1dec: Remove redundant writes, fix races
Every modification of the data that is copied in update_thread_context() is a data race if it happens after ff_thread_finish_setup. ffv1dec's update_thread_context() simply uses memcpy for updating the new context, so that every modification of the src's context is a race. Some of these modifications are unnecessary: picture_number is write-only for the decoder and cur will be reset when decoding the next frame anyway. So remove them. And while just at it, also don't set cur for the slice contexts as this variable is write-only. Signed-off-by: Andreas Rheinhardt --- Weirdly ubitux's TSAN fate-box (which uses frame threading by default) does not show any failing FFV1 tests; although (Clang-)TSAN does it for me and it is totally obvious that these are data races. libavcodec/ffv1dec.c | 4 1 file changed, 4 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 8516fef5d7..24dfc68ca4 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -924,7 +924,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac fs->c.bytestream_end = buf_p + v; fs->avctx = avctx; -fs->cur = p; } avctx->execute(avctx, @@ -966,11 +965,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac } ff_thread_report_progress(&f->picture, INT_MAX, 0); -f->picture_number++; - if (f->last_picture.f) ff_thread_release_buffer(avctx, &f->last_picture); -f->cur = NULL; if ((ret = av_frame_ref(data, f->picture.f)) < 0) return ret; -- 2.27.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2 2/2] avformat/westwoodaudenc: Adds muxer for Westwood AUD format.
On 24/4/21 8:35 am, Aidan Richmond wrote: + +if (st->codecpar->codec_id != AV_CODEC_ID_ADPCM_IMA_WS) { +av_log(st, AV_LOG_ERROR, "%s codec not supported for Westwood AUD.\n", + avcodec_get_name(st->codecpar->codec_id)); +return -1; AVERROR(EINVAL) +} + +if (ctx->nb_streams != 1) { +av_log(st, AV_LOG_ERROR, "AUD files have exactly one stream\n"); +return AVERROR(EINVAL); +} + Move both these checks into an init function. +static int wsaud_write_trailer(AVFormatContext *ctx) +{ +AVIOContext *pb = ctx->pb; +AUDMuxContext *a = ctx->priv_data; + +if(!pb->seekable) { +av_log(ctx->streams[0], AV_LOG_ERROR, "Cannot seek to write file size to header."); +return -1; +} + Same with this one. No point writing the file at all if it's not seekable. +avio_seek(pb, 2, SEEK_SET); +avio_wl32(pb, a->size); +avio_wl32(pb, a->uncomp_size); + +return 0; +} + +AVOutputFormat ff_wsaud_muxer = { +.name = "wsaud", +.long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio"), +.extensions= "aud", +.priv_data_size= sizeof(AUDMuxContext), +.audio_codec = AV_CODEC_ID_ADPCM_IMA_WS, +.video_codec = AV_CODEC_ID_NONE, +.write_header = wsaud_write_header, +.write_packet = wsaud_write_packet, +.write_trailer = wsaud_write_trailer, +}; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v3 3/3] avformat/mpegtsenc: Write stream_id into PES after stream_id decision
On Sat, Apr 24, 2021 at 5:09 PM Mao Hata wrote: > > > v3 patch looks good to me. > Then, since the patch itself is based on ISO_IEC_13818-1, it perhaps has > some (side) effects for ATSC/DVB as well. If possible, you might want to > wait for opinions from ATSC/DVB sides. > > Mao Hata > I will add arib_superimpose codec later once this patchset got merged. Just waiting for other maintainers to review and merge this, yet. Regards, zheng > P.S. > I confirmed the effect of your patch with the following command. > $ ffmpeg -i some_arib_mpeg.ts -c:v libx264 -map 0:v -c:a aac -map 0:a > -map 0:4 dest.ts > > Here "-map 0:4" points to private_stream_2 (ARIB-superimpose). > The command now properly remuxes "-map 0:4" stream into "dest.ts" > without any editing. > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/7] avformat/asfdec_o: shrink extradata to the initialized size
On Fri, Apr 23, 2021 at 08:00:16PM +0200, Andreas Rheinhardt wrote: > Michael Niedermayer: > > Fixes: OOM > > Fixes: > > 27240/clusterfuzz-testcase-minimized-ffmpeg_dem_ASF_O_fuzzer-5937469859823616 > > > > Found-by: continuous fuzzing process > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > > Signed-off-by: Michael Niedermayer > > --- > > libavformat/asfdec_o.c | 6 +- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c > > index 6cfcd8b088..d08a09c14d 100644 > > --- a/libavformat/asfdec_o.c > > +++ b/libavformat/asfdec_o.c > > @@ -600,8 +600,12 @@ static int parse_video_info(AVIOContext *pb, AVStream > > *st) > > memset(st->codecpar->extradata + st->codecpar->extradata_size , 0, > > AV_INPUT_BUFFER_PADDING_SIZE); > > if ((ret = avio_read(pb, st->codecpar->extradata, > > - st->codecpar->extradata_size)) < 0) > > + st->codecpar->extradata_size)) < 0) { > > +st->codecpar->extradata_size = 0; > > +av_freep(&st->codecpar->extradata); > > return ret; > > +} > > +st->codecpar->extradata_size = ret; > > } > > return 0; > > } > > > How important is it to preserve partially read extradata? If it is not > important, one could just use ff_get_extradata(); if it is important, > then memset should be performed after the read, so that the real padding > of the extradata is zeroed (it is uninitialized with your patch if the > desired size could not be read). i guess its not important to preserve, will apply with ff_get_extradata() thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB "I am not trying to be anyone's saviour, I'm trying to think about the future and not be sad" - Elon Musk signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v3 3/3] avformat/mpegtsenc: Write stream_id into PES after stream_id decision
On 2021/04/22 21:03, zheng qian wrote: Changes since v2: Fix PES_packet_length mismatch bug According to the PES packet definition defined in Table 2-17 of ISO_IEC_13818-1 specification, some fields like PTS/DTS or pes_extension could only appears if the stream_id meets the condition: if (stream_id != 0xBC && // program_stream_map stream_id != 0xBE && // padding_stream stream_id != 0xBF && // private_stream_2 stream_id != 0xF0 && // ECM stream_id != 0xF1 && // EMM stream_id != 0xFF && // program_stream_directory stream_id != 0xF2 && // DSMCC_stream stream_id != 0xF8) // ITU-T Rec. H.222.1 type E stream And the following stream_id types don't have fields like PTS/DTS: else if ( stream_id == program_stream_map || stream_id == private_stream_2 || stream_id == ECM || stream_id == EMM || stream_id == program_stream_directory || stream_id == DSMCC_stream || stream_id == ITU-T Rec. H.222.1 type E stream ) { for (i = 0; i < PES_packet_length; i++) { PES_packet_data_byte } } Current implementation skipped the judgement of stream_id causing some kind of stream like private_stream_2 to be incorrectly written with PTS/DTS field. For example, Japan DTV transmits news and alerts through ARIB superimpose that utilizes private_stream_2 still could not be remuxed correctly for now. This patch set fixes the remuxing for private_stream_2 and other stream_id types. Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index f302af84ff..b59dab5174 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1476,6 +1476,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } } header_len = 0; + +if (stream_id != 0xBC && // program_stream_map +stream_id != 0xBE && // padding_stream +stream_id != 0xBF && // private_stream_2 +stream_id != 0xF0 && // ECM +stream_id != 0xF1 && // EMM +stream_id != 0xFF && // program_stream_directory +stream_id != 0xF2 && // DSMCC_stream +stream_id != 0xF8) { // ITU-T Rec. H.222.1 type E stream > + flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; @@ -1569,6 +1579,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; } +} else { +len = payload_size; +*q++ = len >> 8; +*q++ = len; +} is_start = 0; } /* header size */ Your patch changes the behavior of mpegts_write_pes() function only if its "st->codecpar->codec_type" parameter is AVMEDIA_TYPE_DATA. In other cases, "stream_id" variable in this function is set to any of the following: STREAM_ID_EXTENDED_STREAM_ID (0xfd) STREAM_ID_VIDEO_STREAM_0 (0xe0) STREAM_ID_AUDIO_STREAM_0 (0xc0) STREAM_ID_EXTENDED_STREAM_ID (0xfd) STREAM_ID_PRIVATE_STREAM_1 (0xbd) So, the "if (stream_id != ...)" statement added by the patch is always true, therefore, the function behaves the same as before. If "st->codecpar->codec_type" parameter is AVMEDIA_TYPE_DATA, unless additionally conditioned by "st->codecpar->codec_id" parameter, basically, the "stream_id" value given as an argument is written to PES packets as it is. In this case, the behavior of the function should be fixed as you commented. v3 patch looks good to me. Then, since the patch itself is based on ISO_IEC_13818-1, it perhaps has some (side) effects for ATSC/DVB as well. If possible, you might want to wait for opinions from ATSC/DVB sides. Mao Hata P.S. I confirmed the effect of your patch with the following command. $ ffmpeg -i some_arib_mpeg.ts -c:v libx264 -map 0:v -c:a aac -map 0:a -map 0:4 dest.ts Here "-map 0:4" points to private_stream_2 (ARIB-superimpose). The command now properly remuxes "-map 0:4" stream into "dest.ts" without any editing. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avutil/cpu: Use HW_NCPUONLINE to detect # of online CPUs with OpenBSD
On Mon, 19 Apr 2021, Brad Smith wrote: Can this please be back ported to the 4.4 branch? Ok, done. Regards, Marton On 4/18/2021 4:50 PM, Marton Balint wrote: On Fri, 16 Apr 2021, Brad Smith wrote: ping. Will apply, thanks. Marton On 4/3/2021 2:49 PM, Brad Smith wrote: avutil/cpu: Use HW_NCPUONLINE to detect # of online CPUs with OpenBSD Signed-off-by: Brad Smith --- libavutil/cpu.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/libavutil/cpu.c b/libavutil/cpu.c index 8e3576a1f3..9d249737df 100644 --- a/libavutil/cpu.c +++ b/libavutil/cpu.c @@ -291,6 +291,12 @@ int av_cpu_count(void) DWORD_PTR proc_aff, sys_aff; if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff)) nb_cpus = av_popcount64(proc_aff); +#elif HAVE_SYSCTL && defined(HW_NCPUONLINE) + int mib[2] = { CTL_HW, HW_NCPUONLINE }; + size_t len = sizeof(nb_cpus); + + if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1) + nb_cpus = 0; #elif HAVE_SYSCTL && defined(HW_NCPU) int mib[2] = { CTL_HW, HW_NCPU }; size_t len = sizeof(nb_cpus); ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".