Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC hwaccel code
Quoting Soft Works (2022-02-09 07:19:23) > > Sure. Don't understand my reply as an objection I don't even know what > xvmc is (or was). I rather see the burden and effort that it takes > to retain all those compatibility paths and at the same time how it > is blocking innovation and progress. > Compatibility is important - without question, but doing it in a way > that libs from different versions can be combined, is a somewhat crazy > endeavor. I keep wondering who would be the developer whose dreams > this might fulfil.. > The discussion about that seems to have gotten stuck about whether > to merge libs together or not, or how, but I haven't followed in > detailed, so please excuse the question (which has probably been > covered before): > Why can't ffmpeg simply declare that starting from version X, it > will be a requirement that all libs are from the same version? > (of course after equalizing) That is pretty offtopic in this thread =p That said, in my opinion - the extra flexibility is useful - the actual effort required to allow mismatching versions is overstated - the things this mainly affects are various private interfaces, which IMO are a mispattern and should not exist anyway -- Anton Khirnov ___ 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] libavcodec/vaapi_encode: Add async_depth to vaapi_encoder to increase performance
> Add async_depth to increase encoder's performance. Reuse encode_fifo as > async buffer. Encoder puts all reordered frame to HW and then check > fifo size. If fifo < async_depth and the top frame is not ready, it will > return AVERROR(EAGAIN) to require more frames. > > 1080p transcoding (no B frames) with -async_depth=4 can increase 20% > performance on my environment. > The async increases performance but also introduces frame delay. > > Signed-off-by: Wenbin Chen > --- > libavcodec/vaapi_encode.c | 16 > libavcodec/vaapi_encode.h | 12 ++-- > 2 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c > index 15ddbbaa4a..432abf31f7 100644 > --- a/libavcodec/vaapi_encode.c > +++ b/libavcodec/vaapi_encode.c > @@ -1158,7 +1158,8 @@ static int > vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) > if (ctx->input_order == ctx->decode_delay) > ctx->dts_pts_diff = pic->pts - ctx->first_pts; > if (ctx->output_delay > 0) > -ctx->ts_ring[ctx->input_order % (3 * ctx->output_delay)] = > pic->pts; > +ctx->ts_ring[ctx->input_order % > +(3 * ctx->output_delay + ctx->async_depth)] = > pic->pts; > > pic->display_order = ctx->input_order; > ++ctx->input_order; > @@ -1214,7 +1215,7 @@ int > ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt) > > #if VA_CHECK_VERSION(1, 9, 0) > if (ctx->has_sync_buffer_func) { > -while (av_fifo_can_read(ctx->encode_fifo) <= > MAX_PICTURE_REFERENCES) { > +while (av_fifo_can_read(ctx->encode_fifo) <= MAX_ASYNC_DEPTH) { Here is a mistake I should use "<" instead of "<=" and I can use av_fifo_can_write() instead. I will update it. > pic = NULL; > err = vaapi_encode_pick_next(avctx, ); > if (err < 0) > @@ -1232,6 +1233,13 @@ int > ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt) > } > if (!av_fifo_can_read(ctx->encode_fifo)) > return err; > +if (av_fifo_can_read(ctx->encode_fifo) < ctx->async_depth && > +!ctx->end_of_stream) { > +av_fifo_peek(ctx->encode_fifo, , 1, 0); > +err = vaapi_encode_wait(avctx, pic, 0); > +if (err < 0) > +return err; > +} > av_fifo_read(ctx->encode_fifo, , 1); > ctx->encode_order = pic->encode_order + 1; > } else > @@ -1267,7 +1275,7 @@ int > ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt) > pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff; > } else { > pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) % > -(3 * ctx->output_delay)]; > +(3 * ctx->output_delay + ctx->async_depth)]; > } > av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" > dts %"PRId64".\n", > pkt->pts, pkt->dts); > @@ -2588,7 +2596,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext > *avctx) > vas = vaSyncBuffer(ctx->hwctx->display, 0, 0); > if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) { > ctx->has_sync_buffer_func = 1; > -ctx->encode_fifo = av_fifo_alloc2(MAX_PICTURE_REFERENCES + 1, > +ctx->encode_fifo = av_fifo_alloc2(MAX_ASYNC_DEPTH, >sizeof(VAAPIEncodePicture *), >0); > if (!ctx->encode_fifo) > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h > index d33a486cb8..691521387d 100644 > --- a/libavcodec/vaapi_encode.h > +++ b/libavcodec/vaapi_encode.h > @@ -48,6 +48,7 @@ enum { > MAX_TILE_ROWS = 22, > // A.4.1: table A.6 allows at most 20 tile columns for any level. > MAX_TILE_COLS = 20, > +MAX_ASYNC_DEPTH= 64, > }; > > extern const AVCodecHWConfigInternal *const > ff_vaapi_encode_hw_configs[]; > @@ -298,7 +299,8 @@ typedef struct VAAPIEncodeContext { > // Timestamp handling. > int64_t first_pts; > int64_t dts_pts_diff; > -int64_t ts_ring[MAX_REORDER_DELAY * 3]; > +int64_t ts_ring[MAX_REORDER_DELAY * 3 + > +MAX_ASYNC_DEPTH]; > > // Slice structure. > int slice_block_rows; > @@ -350,6 +352,8 @@ typedef struct VAAPIEncodeContext { > AVFifo *encode_fifo; > //Whether the driver support vaSyncBuffer > int has_sync_buffer_func; > +//Max number of frame buffered in encoder. > +int async_depth; > } VAAPIEncodeContext; > > enum { > @@ -460,7 +464,11 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); > { "b_depth", \ >"Maximum B-frame reference depth", \ >OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \ > - { .i64 = 1 }, 1, INT_MAX, FLAGS } > + { .i64 = 1 }, 1, INT_MAX,
Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC hwaccel code
> -Original Message- > From: ffmpeg-devel On Behalf Of > Anton Khirnov > Sent: Wednesday, February 9, 2022 6:49 AM > To: FFmpeg development discussions and patches de...@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC > hwaccel code > > Quoting Soft Works (2022-02-08 22:34:42) > > > > > > > -Original Message- > > > From: ffmpeg-devel On Behalf Of > > > Anton Khirnov > > > Sent: Tuesday, February 8, 2022 10:37 AM > > > To: FFmpeg development discussions and patches > > de...@ffmpeg.org> > > > Subject: Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC > > > hwaccel code > > > > > > Quoting Soft Works (2022-02-07 03:18:54) > > > > I sometimes wonder whether there exists a single API user who > > > > really understands this (very special) kind of logic and > > > > would make decisions based on that understanding. > > > > > > > > When it's not even fully understood internally, how should it > > > > be understood externally? > > > > > > The rule for API users is simple: you are not allowed to assume a > > > specific component (like a decoder, demuxer or hwaccel) will be > > > available at runtime*. You are supposed to check for it using the > APIs > > > provided for this purpose. In this case, AV_PIX_FMT_XVMC will just > > > stop > > > being offered in get_format(). > > > > > > Not to mention that I very much doubt there are any users of xvmc > > > left, > > > besides the original mplayer. > > > > > > * unless you are running with a very specific verified build, in > which > > > case a removal like this should be caught at the build stage > > > > Thanks for the explanation. I misunderstood this a bit - when the > > only effect of the "removal" is an output like when the libs > wouldn't > > have been compiled with that part, then that's maybe nothing to > > be blamed for. > > On the other side: when somebody is using it and updates the libs > > to a point where it's missing, it will be broken for her/him. > > So the outcome might not be _that_ different for any other breaking > > changes being made. > > I agree that in general removing random components would be a bad > thing > to do, even though it's not technically an API break. That's why we > don't do it if there's any chance the component in question is useful. > > The argument _in this specific case_ is that xvmc is not useful to > anyone and has not been for a very long time, so no valid use cases > are > broken by its removal. In fact its only user ever I'm aware of is the > original mplayer (mplayer2, which was later forked into mpv, dropped > it > in 2011). Sure. Don't understand my reply as an objection I don't even know what xvmc is (or was). I rather see the burden and effort that it takes to retain all those compatibility paths and at the same time how it is blocking innovation and progress. Compatibility is important - without question, but doing it in a way that libs from different versions can be combined, is a somewhat crazy endeavor. I keep wondering who would be the developer whose dreams this might fulfil.. The discussion about that seems to have gotten stuck about whether to merge libs together or not, or how, but I haven't followed in detailed, so please excuse the question (which has probably been covered before): Why can't ffmpeg simply declare that starting from version X, it will be a requirement that all libs are from the same version? (of course after equalizing) BR, softworkz ___ 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] avformat/hls: Implement support for using AVSEEK_FLAG_BACKWARD when seeking
Steven Liu 于2022年2月3日周四 18:22写道: > > > > > 2022年1月29日 上午4:23,Gustav Grusell 写道: > > > > Before, seeking in hls streams would always seek to the next keyframe > > after the given timestamp. With this fix, if seeking in videostream and > > AVSEEK_FLAG_BACKWARD is set, seeking will be to the first keyframe of > > the segment containing the given timestamp. This fixes #7485. > > > > Signed-off-by: Gustav Grusell > > --- > > libavformat/hls.c | 24 +--- > > 1 file changed, 17 insertions(+), 7 deletions(-) > > > > diff --git a/libavformat/hls.c b/libavformat/hls.c > > index 4568e72cb2..44afdaab42 100644 > > --- a/libavformat/hls.c > > +++ b/libavformat/hls.c > > @@ -1653,7 +1653,8 @@ static void > > add_metadata_from_renditions(AVFormatContext *s, struct playlist *pl > > /* if timestamp was in valid range: returns 1 and sets seq_no > > * if not: returns 0 and sets seq_no to closest segment */ > > static int find_timestamp_in_playlist(HLSContext *c, struct playlist *pls, > > - int64_t timestamp, int64_t *seq_no) > > + int64_t timestamp, int64_t *seq_no, > > + int64_t *seg_start_ts) > > { > > int i; > > int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? > > @@ -1668,6 +1669,9 @@ static int find_timestamp_in_playlist(HLSContext *c, > > struct playlist *pls, > > int64_t diff = pos + pls->segments[i]->duration - timestamp; > > if (diff > 0) { > > *seq_no = pls->start_seq_no + i; > > +if (seg_start_ts) { > > +*seg_start_ts = pos; > > +} > > return 1; > > } > > pos += pls->segments[i]->duration; > > @@ -1691,7 +1695,7 @@ static int64_t select_cur_seq_no(HLSContext *c, > > struct playlist *pls) > > * playlist) and this is a complete file, find the matching segment > > * by counting durations. */ > > if (pls->finished && c->cur_timestamp != AV_NOPTS_VALUE) { > > -find_timestamp_in_playlist(c, pls, c->cur_timestamp, _no); > > +find_timestamp_in_playlist(c, pls, c->cur_timestamp, _no, > > NULL); > > return seq_no; > > } > > > > @@ -2362,7 +2366,7 @@ static int hls_read_seek(AVFormatContext *s, int > > stream_index, > > int i, j; > > int stream_subdemuxer_index; > > int64_t first_timestamp, seek_timestamp, duration; > > -int64_t seq_no; > > +int64_t seq_no, seg_start_ts; > > > > if ((flags & AVSEEK_FLAG_BYTE) || (c->ctx->ctx_flags & > > AVFMTCTX_UNSEEKABLE)) > > return AVERROR(ENOSYS); > > @@ -2372,8 +2376,7 @@ static int hls_read_seek(AVFormatContext *s, int > > stream_index, > > > > seek_timestamp = av_rescale_rnd(timestamp, AV_TIME_BASE, > > s->streams[stream_index]->time_base.den, > > -flags & AVSEEK_FLAG_BACKWARD ? > > -AV_ROUND_DOWN : AV_ROUND_UP); > > +AV_ROUND_DOWN); > > > > duration = s->duration == AV_NOPTS_VALUE ? > >0 : s->duration; > > @@ -2394,9 +2397,16 @@ static int hls_read_seek(AVFormatContext *s, int > > stream_index, > > } > > /* check if the timestamp is valid for the playlist with the > > * specified stream index */ > > -if (!seek_pls || !find_timestamp_in_playlist(c, seek_pls, > > seek_timestamp, _no)) > > +if (!seek_pls || !find_timestamp_in_playlist(c, seek_pls, > > seek_timestamp, _no, _start_ts)) > > return AVERROR(EIO); > > > > +if (s->streams[stream_index]->codecpar->codec_type == > > AVMEDIA_TYPE_VIDEO && > > +flags & AVSEEK_FLAG_BACKWARD && !(flags & AVSEEK_FLAG_ANY)) { > > +/* Seeking to start of segment ensures we seek to a keyframe > > located > > + * before the given timestamp. */ > > +seek_timestamp = seg_start_ts; > > +} > > + > > /* set segment now so we do not need to search again below */ > > seek_pls->cur_seq_no = seq_no; > > seek_pls->seek_stream_index = stream_subdemuxer_index; > > @@ -2423,7 +2433,7 @@ static int hls_read_seek(AVFormatContext *s, int > > stream_index, > > > > if (pls != seek_pls) { > > /* set closest segment seq_no for playlists not handled above */ > > -find_timestamp_in_playlist(c, pls, seek_timestamp, > > >cur_seq_no); > > +find_timestamp_in_playlist(c, pls, seek_timestamp, > > >cur_seq_no, NULL); > > /* seek the playlist to the given position without taking > > * keyframes into account since this playlist does not have the > > * specified stream where we should look for the keyframes */ > > -- > > 2.25.1 > > > > ___ > > ffmpeg-devel mailing list > > ffmpeg-devel@ffmpeg.org > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > > > To unsubscribe, visit link above, or
Re: [FFmpeg-devel] [PATCH 1/2] avformat/hls: Use unsigned for iv computation
Michael Niedermayer 于2022年2月8日周二 22:59写道: > > Fixes: signed integer overflow: 9223372036854775748 + 60 cannot be > represented in type 'long' > Fixes: > 44417/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5802443881971712 > > Found-by: continuous fuzzing process > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > Signed-off-by: Michael Niedermayer > --- > libavformat/hls.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libavformat/hls.c b/libavformat/hls.c > index 4568e72cb2..8541fa9420 100644 > --- a/libavformat/hls.c > +++ b/libavformat/hls.c > @@ -914,7 +914,7 @@ static int parse_playlist(HLSContext *c, const char *url, > if (has_iv) { > memcpy(seg->iv, iv, sizeof(iv)); > } else { > -int64_t seq = pls->start_seq_no + pls->n_segments; > +uint64_t seq = pls->start_seq_no + > (uint64_t)pls->n_segments; > memset(seg->iv, 0, sizeof(seg->iv)); > AV_WB64(seg->iv + 8, seq); > } > -- > 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". LGTM not sure int limit number is ok for n_segments, but i have no better idea for that. uint64_t here is ok. 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 1/4] lavc/mpeg*: drop the XvMC hwaccel code
Quoting Soft Works (2022-02-08 22:34:42) > > > > -Original Message- > > From: ffmpeg-devel On Behalf Of > > Anton Khirnov > > Sent: Tuesday, February 8, 2022 10:37 AM > > To: FFmpeg development discussions and patches > de...@ffmpeg.org> > > Subject: Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC > > hwaccel code > > > > Quoting Soft Works (2022-02-07 03:18:54) > > > I sometimes wonder whether there exists a single API user who > > > really understands this (very special) kind of logic and > > > would make decisions based on that understanding. > > > > > > When it's not even fully understood internally, how should it > > > be understood externally? > > > > The rule for API users is simple: you are not allowed to assume a > > specific component (like a decoder, demuxer or hwaccel) will be > > available at runtime*. You are supposed to check for it using the APIs > > provided for this purpose. In this case, AV_PIX_FMT_XVMC will just > > stop > > being offered in get_format(). > > > > Not to mention that I very much doubt there are any users of xvmc > > left, > > besides the original mplayer. > > > > * unless you are running with a very specific verified build, in which > > case a removal like this should be caught at the build stage > > Thanks for the explanation. I misunderstood this a bit - when the > only effect of the "removal" is an output like when the libs wouldn't > have been compiled with that part, then that's maybe nothing to > be blamed for. > On the other side: when somebody is using it and updates the libs > to a point where it's missing, it will be broken for her/him. > So the outcome might not be _that_ different for any other breaking > changes being made. I agree that in general removing random components would be a bad thing to do, even though it's not technically an API break. That's why we don't do it if there's any chance the component in question is useful. The argument _in this specific case_ is that xvmc is not useful to anyone and has not been for a very long time, so no valid use cases are broken by its removal. In fact its only user ever I'm aware of is the original mplayer (mplayer2, which was later forked into mpv, dropped it in 2011). -- Anton Khirnov ___ 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] avcodec/vp6: return value check for av_mallocz
On Mon, Feb 07, 2022 at 11:44:53AM +0800, Jiasheng Jiang wrote: > As the potential failure of the av_mallocz(), the 's->alpha_context' > could be NULL and be dereferenced later. > Therefore, it should be better to check it and deal with it if fails > in order to prevent memory leak, same as the av_frame_alloc() in > ff_vp56_init(). > > Fixes: 39a3894ad5 ("lavc/vp6: Implement "slice" threading for VP6A decode") > Signed-off-by: Jiasheng Jiang > --- > libavcodec/vp6.c | 4 > 1 file changed, 4 insertions(+) looks good to me. i will apply in couple of days. -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B) 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] avcodec/vp8: Remove always-false check
On Tue, Feb 08, 2022 at 04:39:27PM +0100, Andreas Rheinhardt wrote: > Since e9b66175793e5c2af19beefe8e143f6e4901b5df a codec's close > function is never ever called for a codec whose init function has not > been called; in particular, it is never ever called if the > AVCodecContext's private data has not been allocated. > > Signed-off-by: Andreas Rheinhardt > --- > libavcodec/vp8.c | 3 --- > 1 file changed, 3 deletions(-) > > diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c > index a70d94bd82..c9d9117528 100644 > --- a/libavcodec/vp8.c > +++ b/libavcodec/vp8.c > @@ -2826,9 +2826,6 @@ av_cold int ff_vp8_decode_free(AVCodecContext *avctx) > VP8Context *s = avctx->priv_data; > int i; > > -if (!s) > -return 0; > - > vp8_decode_flush_impl(avctx, 1); > for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) > av_frame_free(>frames[i].tf.f); looks good to me. please apply. -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B) 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] lavu/fifo: fix regression
On Tue, 2022-02-08 at 17:48 +, Eoff, Ullysses A wrote: > > -Original Message- > > From: ffmpeg-devel On Behalf Of Xiang, > > Haihao > > Sent: Monday, February 7, 2022 9:48 PM > > To: ffmpeg-devel@ffmpeg.org > > Cc: Xiang, Haihao > > Subject: [FFmpeg-devel] [PATCH] lavu/fifo: fix regression > > > > From: Haihao Xiang > > > > offset_w might be updated after growing the FIFO > > > > Fix ticket #9630 > > > > Tested-by: U. Artie Eoff > > Reviewed-by: mkver > > Reviewed-by: U. Artie Eoff > > Signed-off-by: Haihao Xiang > > --- > > libavutil/fifo.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/libavutil/fifo.c b/libavutil/fifo.c > > index 0af0154945..02e0ec3f0d 100644 > > --- a/libavutil/fifo.c > > +++ b/libavutil/fifo.c > > @@ -147,13 +147,15 @@ static int fifo_write_common(AVFifo *f, const uint8_t > > *buf, size_t *nb_elems, > > AVFifoCB read_cb, void *opaque) > > { > > size_t to_write = *nb_elems; > > -size_t offset_w = f->offset_w; > > +size_t offset_w; > > int ret = 0; > > > > ret = fifo_check_space(f, to_write); > > if (ret < 0) > > return ret; > > > > +offset_w = f->offset_w; > > + > > while (to_write > 0) { > > size_tlen = FFMIN(f->nb_elems - offset_w, to_write); > > uint8_t *wptr = f->buffer + offset_w * f->elem_size; > > -- > > 2.17.1 > > > > LGTM > Applied, thx > > ___ > > 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] [PATCH v3 8/8] avpriv_find_start_code(): make start_code output only
The input/output functionality was used by only (ff_)mpeg1_find_frame_end(). If the state/start_code input is a local variable and only one buffer is used, then no history is needed. In loops and inline functions: if ignoring history, don't initialize start_code, so it isn't reset twice each time. There is a slight functional change: 00 00 01 00 01 XX no longer incorrectly returns a start code at offset 7 that overlaps the start code at offset 4 if the start_code input is not modified between the two calls. --- libavcodec/cbs_mpeg2.c| 5 libavcodec/h264_parser.c | 2 +- libavcodec/mpeg12.c | 41 +- libavcodec/mpeg4_unpack_bframes_bsf.c | 1 - libavcodec/mpegvideo_parser.c | 42 +-- libavcodec/startcode.h| 14 +++-- libavcodec/utils.c| 16 -- libavcodec/vc1_common.h | 2 +- libavformat/rtpenc_mpv.c | 2 +- 9 files changed, 92 insertions(+), 33 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index f0a2265938..870119bab0 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -160,11 +160,6 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, const uint8_t *end; size_t unit_size; -// Reset start_code to ensure that avpriv_find_start_code() -// really reads a new start code and does not reuse the old -// start code in any way (as e.g. happens when there is a -// Sequence End unit at the very end of a packet). -start_code = UINT32_MAX; end = avpriv_find_start_code(start--, frag->data + frag->data_size, _code); diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 50810f1789..b67830d40e 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -69,7 +69,7 @@ typedef struct H264ParseContext { static int find_start_code(const uint8_t *buf, int buf_size, int buf_index, int next_avc) { -uint32_t state = -1; +uint32_t state; buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, ) - buf - 1; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 85f4f432bd..9639423152 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -165,6 +165,45 @@ av_cold void ff_mpeg12_init_vlcs(void) } #if FF_API_FLAG_TRUNCATED +/** + * By preserving the @p start_code value between subsequent calls, the caller can + * detect start codes across buffer boundaries. + * + * @param[in,out] start_code A pointer to a mutable @c uint32_t. + * As input: For no history preset to @c ~0 , otherwise preset to the last + *returned start code to enable detecting start codes across + *buffer boundaries. + * On output: Set to the found start code if it exists or an invalid + * start code (the 4 bytes prior to the returned value, + * using the input history if @f$ end - p < 4 @f$). + * + * @sa avpriv_find_start_code() + */ +static const uint8_t *find_start_code_truncated(const uint8_t *av_restrict p, + const uint8_t * const end, + uint32_t * const av_restrict start_code) +{ +av_assert0(p <= end); +if (p >= end) +return end; + +if (*start_code == 0x100) +*start_code = ~0; +// invalidate byte 0 so overlapping start codes are not erroneously detected + +// read up to the first three bytes in p to enable reading a start code across +// two (to four) buffers +for (int i = 0; i < 3; i++) { +*start_code <<= 8; +*start_code += *p; +p++; +if (start_code_is_valid(*start_code) || p == end) +return p; +} +// buffer length is at least 4 +return avpriv_find_start_code(p - 3, end, start_code); +} + /** * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 @@ -199,7 +238,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, } state++; } else { -i = avpriv_find_start_code(buf + i, buf + buf_size, ) - buf - 1; +i = find_start_code_truncated(buf + i, buf + buf_size, ) - buf - 1; if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { i++; pc->frame_start_found = 4; diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index ae2c129d88..1030dd60aa 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -36,7 +36,6 @@ static void scan_buffer(const uint8_t *buf, int buf_size, const uint8_t *end = buf +
[FFmpeg-devel] [PATCH v3 7/8] avpriv_find_start_code(): constify pointer parameters
Have the compiler enforce not changing the addresses these parameters point to. No functional change. --- libavcodec/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 68d126acd8..d11d92d21e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -937,8 +937,8 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in #endif const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, - const uint8_t *end, - uint32_t *av_restrict start_code) + const uint8_t * const end, + uint32_t * const av_restrict start_code) { av_assert0(p <= end); if (p >= end) -- 2.32.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 v3 6/8] avpriv_find_start_code(): correct type of start_code parameter
--- libavcodec/mpeg12dec.c | 2 +- libavformat/rtpenc_mpv.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 27fd61e848..24cd6aac77 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1768,7 +1768,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, if (avctx->hwaccel && avctx->hwaccel->decode_slice) { const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ -int start_code = -1; +uint32_t start_code = ~0; buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, _code); if (buf_end < *buf + buf_size) buf_end -= 4; diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index 8b6987b7f2..9c0816ef95 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -51,11 +51,10 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) end_of_slice = 1; } else { const uint8_t *r, *r1; -int start_code; r1 = buf1; while (1) { -start_code = -1; +uint32_t start_code = ~0; r = avpriv_find_start_code(r1, end, _code); if (start_code_is_valid(start_code)) { /* New start code found */ -- 2.32.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 v3 5/8] avpriv_find_start_code(): add doxygen comment and rename a parameter
--- libavcodec/startcode.h | 26 +- libavcodec/utils.c | 10 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libavcodec/startcode.h b/libavcodec/startcode.h index 833754af09..69389c729c 100644 --- a/libavcodec/startcode.h +++ b/libavcodec/startcode.h @@ -44,9 +44,33 @@ static av_always_inline int start_code_is_valid(uint32_t start_code) { return (start_code & 0xFF00) == 0x100; } +/** + * @brief Find the first start code in the buffer @p p. + * + * A start code is a sequence of 4 bytes with the hexadecimal value 00 00 01 XX , + * where XX represents any value and memory address increases left to right. + * + * By preserving the @p start_code value between subsequent calls, the caller can + * detect start codes across buffer boundaries. + * + * @param[in] p A pointer to the start of the memory buffer to scan. + * @param[in] end A pointer to the past-the-end memory address for the buffer + * given by @p p. @p p must be ≤ @p end. + * + * @param[in,out] start_code A pointer to a mutable @c uint32_t. + * As input: For no history preset to @c ~0 , otherwise preset to the last + *returned start code to enable detecting start codes across + *buffer boundaries. + * On output: Set to the found start code if it exists or an invalid + * start code (the 4 bytes prior to the returned value, + * using the input history if @f$ end - p < 4 @f$). + * + * @return A pointer to the memory address following the found start code, or @p end + * if no start code was found. + */ const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, - uint32_t *state); + uint32_t *start_code); int ff_startcode_find_candidate_c(const uint8_t *buf, int size); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index bdafdaa355..68d126acd8 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -938,7 +938,7 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, - uint32_t *av_restrict state) + uint32_t *av_restrict start_code) { av_assert0(p <= end); if (p >= end) @@ -947,10 +947,10 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // read up to the first three bytes in p to enable reading a start code across // two (to four) buffers for (int i = 0; i < 3; i++) { -*state <<= 8; -*state += *p; +*start_code <<= 8; +*start_code += *p; p++; -if (start_code_is_valid(*state) || p == end) +if (start_code_is_valid(*start_code) || p == end) return p; } // p is now properly incremented for the negative indices in the while loop @@ -983,7 +983,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, if (p > end) p = end; // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} -*state = AV_RB32(p - 4); +*start_code = AV_RB32(p - 4); return p; } -- 2.32.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 v3 4/8] avpriv_find_start_code(): rewrite for loop for clarity
--- libavcodec/utils.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 5b49657b44..bdafdaa355 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -940,18 +940,20 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, uint32_t *av_restrict state) { -int i; - av_assert0(p <= end); if (p >= end) return end; -for (i = 0; i < 3; i++) { -uint32_t tmp = *state << 8; -*state = tmp + *(p++); -if (tmp == 0x100 || p == end) +// read up to the first three bytes in p to enable reading a start code across +// two (to four) buffers +for (int i = 0; i < 3; i++) { +*state <<= 8; +*state += *p; +p++; +if (start_code_is_valid(*state) || p == end) return p; } +// p is now properly incremented for the negative indices in the while loop /* with memory address increasing left to right, we are looking for (in hexadecimal): * 00 00 01 XX -- 2.32.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 v3 3/8] avpriv_find_start_code(): rewrite while loop
The expected number of iterations may increase by one for an input of alternating 0 and 1 bytes. Instead of incrementing by 2 everytime, it now alternates between incrementing by 1 and by 3. For the check p[-2] != 0: This slightly reduces the number of iterations by starting with three new bytes on the next iteration, instead of keeping byte p[-3] which is invalid, since it is now known to be 01 when it must be 00. The comparisons (p[-1] > 1) and (p[-1] == 0) should be one comparison against 1 since p is unsigned, which makes (p[-1] == 0) equivalent to (p[-1] < 1) No other observable change. --- libavcodec/utils.c | 23 +++ 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 42a1885d61..5b49657b44 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -953,12 +953,27 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, return p; } +/* with memory address increasing left to right, we are looking for (in hexadecimal): + * 00 00 01 XX + * p points at the address which should have the value of XX + */ while (p < end) { -if (p[-1] > 1 ) p += 3; -else if (p[-2] ) p += 2; -else if (p[-3]|(p[-1]-1)) p++; -else { +// UU UU UU +if (p[-1] > 1) { +p += 3; +// start check over with 3 new bytes +} +else if (p[-1] == 0) { +p++; +// could be in a start code, so check next byte +} +else if (/* UU UU 01 */ p[-2] != 0 || + /* UU 00 01 */ p[-3] != 0) { +p += 3; +} +else { /* 00 00 01 */ p++; +// p now points at the address following the start code value XX break; } } -- 2.32.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 v3 2/8] avpriv_find_start_code(): readability enhancement part 1
No functional change. --- libavcodec/utils.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index c7c7323351..42a1885d61 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -963,10 +963,11 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, } } -p = FFMIN(p, end) - 4; -*state = AV_RB32(p); - -return p + 4; +if (p > end) +p = end; +// read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} +*state = AV_RB32(p - 4); +return p; } AVCPBProperties *av_cpb_properties_alloc(size_t *size) -- 2.32.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 v3 1/8] avcodec/startcode.h: create start_code_is_valid()
This slightly changes what is considered valid in the following cases: cavsdec.c: 0x00XX is now considered invalid. mpeg12dec.c: 0x00XX is now considered invalid. (where X is any value) IS_MARKER is equivalent since VC1_CODE_RES0 = 0x0100 --- libavcodec/cavsdec.c | 2 +- libavcodec/cbs_mpeg2.c | 6 +++--- libavcodec/extract_extradata_bsf.c | 2 +- libavcodec/mpeg12.c| 2 +- libavcodec/mpeg12dec.c | 2 +- libavcodec/mpegvideo_parser.c | 2 +- libavcodec/remove_extradata_bsf.c | 8 +++- libavcodec/startcode.h | 17 + libavcodec/vaapi_vc1.c | 2 +- libavcodec/vc1_common.h| 4 +--- libavcodec/vc1dec.c| 2 +- libavformat/avs2dec.c | 4 ++-- libavformat/avs3dec.c | 4 ++-- libavformat/cavsvideodec.c | 2 +- libavformat/mpegvideodec.c | 2 +- libavformat/rtpenc_mpv.c | 2 +- 16 files changed, 38 insertions(+), 25 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 894aa1b54a..75cf17e271 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -1250,7 +1250,7 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, buf_end = buf + buf_size; for(;;) { buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, ); -if ((stc & 0xFE00) || buf_ptr == buf_end) { +if (!start_code_is_valid(stc) || buf_ptr == buf_end) { if (!h->stc) av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n"); return FFMAX(0, buf_ptr - buf); diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 33bd3e0998..f0a2265938 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -150,7 +150,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, start = avpriv_find_start_code(frag->data, frag->data + frag->data_size, _code); -if (start_code >> 8 != 0x01) { +if (!start_code_is_valid(start_code)) { // No start code found. return AVERROR_INVALIDDATA; } @@ -172,7 +172,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, // (may be the last byte of fragment->data); end points to the byte // following the byte containing the start code identifier (or to // the end of fragment->data). -if (start_code >> 8 == 0x01) { +if (start_code_is_valid(start_code)) { // Unit runs from start to the beginning of the start code // pointed to by end (including any padding zeroes). unit_size = (end - 4) - start; @@ -189,7 +189,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, start = end; // Do we have a further unit to add to the fragment? -} while ((start_code >> 8) == 0x01); +} while (start_code_is_valid(start_code)); return 0; } diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index 027a578af1..9c639933ee 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -239,7 +239,7 @@ static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, ptr = avpriv_find_start_code(ptr, end, ); if (state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT) { has_extradata = 1; -} else if (has_extradata && IS_MARKER(state)) { +} else if (has_extradata && start_code_is_valid(state)) { extradata_size = ptr - 4 - pkt->data; break; } diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 5520960b74..85f4f432bd 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -213,7 +213,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, pc->frame_start_found = 0; if (pc->frame_start_found < 4 && state == EXT_START_CODE) pc->frame_start_found++; -if (pc->frame_start_found == 4 && (state & 0xFF00) == 0x100) { +if (pc->frame_start_found == 4 && start_code_is_valid(state)) { if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) { pc->frame_start_found = 0; pc->state = -1; diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 860e86aa74..27fd61e848 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2475,7 +2475,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, /* find next start code */ uint32_t start_code = -1; buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, _code); -if (start_code > 0x1ff) { +if (!start_code_is_valid(start_code)) { if (!skip_frame) { if (HAVE_THREADS &&
[FFmpeg-devel] [PATCH v3 0/8] rewrite avpriv_find_start_code() for clarity
I have removed most of my added comments. Rebased to account for Andreas Rheinhardt moving the prototype to startcode.h. Per his suggestion, the function signature is now unmodified. (ff_)mpeg1_find_frame_end() now has a wrapper function preserving the original behavior allowing start codes across buffer boundaries. -Scott ___ 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] avcodec/motion_est: Fix xy indexing on range violation in ff_get_best_fcode()
Michael Niedermayer: > This codepath seems untested, no testcases change > > Found-by: > Signed-off-by: Michael Niedermayer > --- > libavcodec/motion_est.c | 8 +--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c > index 9c548c1567..4cf1afe888 100644 > --- a/libavcodec/motion_est.c > +++ b/libavcodec/motion_est.c > @@ -1621,9 +1621,11 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t > (*mv_table)[2], int type) > fcode_tab[my + MAX_MV]); > int j; > > -if(mx >= range || mx < -range || > - my >= range || my < -range) > -continue; > +if (mx >= range || mx < -range || > +my >= range || my < -range) { > +xy++; > +continue; > +} > > for(j=0; j if(s->pict_type==AV_PICTURE_TYPE_B || > s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy]) It would be simpler if you added the xy++ to the outer-for-loop and removed the other xy++. - 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 1/2] http: Improve handling of Content-Range with Transfer-Encoding:chunked
On Thu, Feb 3, 2022 at 3:12 PM Derek Buitenhuis wrote: > On 2/3/2022 1:26 AM, Aman Karmani wrote: > > The size part of the range header is optional, and can be '*' as well. > > > > See also > > > https://patchwork.ffmpeg.org/project/ffmpeg/patch/20211005233244.37582-1-ffm...@tmm1.net/ > > Isn't this an orthogonal problem to what this patch is changing? > > - Derek > ___ > Are there any other comments/objections to the patchset? Thanks -- Vittorio ___ 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/2] libavformat/mov: fix udta reading in trak box
On Tue, Feb 8, 2022 at 9:48 AM Wang Chuan wrote: > > Any news? > Sorry, was not able to get to this according to the time line I expected. Will see if I can find some time for this soon. The attempt I had done in October was quite similar now that I look at it again (https://github.com/jeeb/ffmpeg/commits/enable_writing_udta_metadata_for_tracks), although it seems like I missed c->trak_index , will have to check it :) Additionally, when I did the changes a lot of tests had to be updated as the test would expect the metadata in the main context, as previously the metadata only got applied globally. The changes in my commit aren't what's needed as I just committed the changes in test results to remind myself which tests would require additional changes or at least review. Looking at the patchwork side for this patch set, it seems like it wasn't able to run the tests for you, so you probably did not get any messages about failing tests? https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=5839 For running tests locally, what I usually do is: 1. configure and build normally 2. `make fate-rsync SAMPLES=../../path/to/fate-suite` 3. `make fate SAMPLES=../../path/to/fate-suite` this is also documented at https://www.ffmpeg.org/fate.html . For the movenc patch, I think there was this weird thing where in QTFF there were two different "name" metadata entries (as well as the international one you've pointed out). I don't think I mentioned it on https://github.com/mpv-player/mpv/issues/8488#issuecomment-884381794 as it contains only my initial findings, but I'll have to grep my IRC logs :D . Thank you for your contribution and patience, Jan ___ 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] avfilter/adelay: Add command support
Yes, during development I tested it streaming to rtmp and to file with a python client sending zmq requests. I Also tried changing the delay multiple times while running a single ffmpeg instance. Seemed to be working fine. so 5. 2. 2022 o 15:05 Paul B Mahol napísal(a): > Have this been tested? > > For example changing delays multiple times per invocation? > ___ > 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/2] lavfi/qsvpp: fix after 85c938fa28
> -Original Message- > From: ffmpeg-devel On Behalf Of Anton > Khirnov > Sent: Tuesday, February 8, 2022 10:27 AM > To: ffmpeg-devel@ffmpeg.org > Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/qsvpp: fix after 85c938fa28 > > --- > libavfilter/qsvvpp.c | 10 +- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c > index 35769dfd60..954f882637 100644 > --- a/libavfilter/qsvvpp.c > +++ b/libavfilter/qsvvpp.c > @@ -796,7 +796,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink > *inlink, AVFrame *picr > AVFilterLink *outlink = ctx->outputs[0]; > QSVAsyncFrame aframe; > mfxSyncPoint sync; > -QSVFrame *in_frame, *out_frame, *tmp; > +QSVFrame *in_frame, *out_frame; > int ret, filter_ret; > > while (s->eof && av_fifo_read(s->async_fifo, , 1) >= 0) { > @@ -857,15 +857,15 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, > AVFilterLink *inlink, AVFrame *picr > ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, > 1000); > } while (ret == MFX_WRN_IN_EXECUTION); > > -filter_ret = s->filter_frame(outlink, tmp->frame); > +filter_ret = s->filter_frame(outlink, aframe.frame->frame); > if (filter_ret < 0) { > -av_frame_free(>frame); > +av_frame_free(>frame); > return filter_ret; > } > > -tmp->queued--; > +aframe.frame->queued--; > s->got_frame = 1; > -tmp->frame = NULL; > +aframe.frame->frame = NULL; > } > } while(ret == MFX_ERR_MORE_SURFACE); > > -- > 2.34.1 > Fixes https://trac.ffmpeg.org/ticket/9629 for me. LGTM > ___ > 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/4] lavc/mpeg*: drop the XvMC hwaccel code
> -Original Message- > From: ffmpeg-devel On Behalf Of > Anton Khirnov > Sent: Tuesday, February 8, 2022 10:37 AM > To: FFmpeg development discussions and patches de...@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC > hwaccel code > > Quoting Soft Works (2022-02-07 03:18:54) > > I sometimes wonder whether there exists a single API user who > > really understands this (very special) kind of logic and > > would make decisions based on that understanding. > > > > When it's not even fully understood internally, how should it > > be understood externally? > > The rule for API users is simple: you are not allowed to assume a > specific component (like a decoder, demuxer or hwaccel) will be > available at runtime*. You are supposed to check for it using the APIs > provided for this purpose. In this case, AV_PIX_FMT_XVMC will just > stop > being offered in get_format(). > > Not to mention that I very much doubt there are any users of xvmc > left, > besides the original mplayer. > > * unless you are running with a very specific verified build, in which > case a removal like this should be caught at the build stage Thanks for the explanation. I misunderstood this a bit - when the only effect of the "removal" is an output like when the libs wouldn't have been compiled with that part, then that's maybe nothing to be blamed for. On the other side: when somebody is using it and updates the libs to a point where it's missing, it will be broken for her/him. So the outcome might not be _that_ different for any other breaking changes being made. And that's what I meant to point out: On one side, we are carefully curating those versioning changes (individually for each lib!) with a complex set of rules and considerations to be made, while in the majority of cases I tend to believe that not many really care that much about it, instead sitting there, happily using it until the moment "Oh it's broken - - need to do something - fix it and go on.." :-) softworkz ___ 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/motion_est: Fix xy indexing on range violation in ff_get_best_fcode()
This codepath seems untested, no testcases change Found-by: Signed-off-by: Michael Niedermayer --- libavcodec/motion_est.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 9c548c1567..4cf1afe888 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1621,9 +1621,11 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) fcode_tab[my + MAX_MV]); int j; -if(mx >= range || mx < -range || - my >= range || my < -range) -continue; +if (mx >= range || mx < -range || +my >= range || my < -range) { +xy++; +continue; +} for(j=0; jpict_type==AV_PICTURE_TYPE_B || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy]) -- 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] cbs_mpeg2_split_fragment(): cache the buffer end
Also add a few clarifying comments. --- libavcodec/cbs_mpeg2.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 33bd3e0998..47732562d1 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -144,12 +144,12 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header) { -const uint8_t *start; +const uint8_t *start = frag->data; +const uint8_t * const buf_end = frag->data + frag->data_size; uint32_t start_code = -1; int err; -start = avpriv_find_start_code(frag->data, frag->data + frag->data_size, - _code); +start = avpriv_find_start_code(start, buf_end, _code); if (start_code >> 8 != 0x01) { // No start code found. return AVERROR_INVALIDDATA; @@ -165,12 +165,11 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, // start code in any way (as e.g. happens when there is a // Sequence End unit at the very end of a packet). start_code = UINT32_MAX; -end = avpriv_find_start_code(start--, frag->data + frag->data_size, - _code); - -// start points to the byte containing the start_code_identifier +end = avpriv_find_start_code(start, buf_end, _code); +start--; +// decrement so start points to the byte containing the start_code_identifier // (may be the last byte of fragment->data); end points to the byte -// following the byte containing the start code identifier (or to +// following the byte containing the next start code identifier (or to // the end of fragment->data). if (start_code >> 8 == 0x01) { // Unit runs from start to the beginning of the start code @@ -178,6 +177,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, unit_size = (end - 4) - start; } else { // We didn't find a start code, so this is the final unit. + // There is no start code to remove from end, hence not (end - 4). unit_size = end - start; } -- 2.32.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 1/2] avformat/demux: Make read_frame_internal() return AVERREOR(EAGAIN) on stuck empty input parser
Fixes: read_frame_internal() which does not return even though both demuxer and parser do return Fixes: 43717/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5206008287330304 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/demux.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/libavformat/demux.c b/libavformat/demux.c index ec34b65288..dd42d32710 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1222,11 +1222,15 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) FFFormatContext *const si = ffformatcontext(s); int ret, got_packet = 0; AVDictionary *metadata = NULL; +int empty = 0; while (!got_packet && !si->parse_queue.head) { AVStream *st; FFStream *sti; +if (empty > 1) +return AVERROR(EAGAIN); + /* read next packet */ ret = ff_read_packet(s, pkt); if (ret < 0) { @@ -1317,6 +1321,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } got_packet = 1; } else if (st->discard < AVDISCARD_ALL) { +if (pkt->size == 0) +empty ++; if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) return ret; st->codecpar->sample_rate = sti->avctx->sample_rate; -- 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/2] avformat/demux: Count EAGAIN as 100 bytes in relation to read limit in avformat_find_stream_info()
Fixes: Timeout Fixes: 43717/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5206008287330304 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/demux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index dd42d32710..1acba0c608 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -2590,8 +2590,10 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* NOTE: A new stream can be added there if no header in file * (AVFMTCTX_NOHEADER). */ ret = read_frame_internal(ic, pkt1); -if (ret == AVERROR(EAGAIN)) +if (ret == AVERROR(EAGAIN)) { +read_size += 100; continue; +} if (ret < 0) { /* EOF or error*/ -- 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 2/2] lavu/hwcontext_qsv: fix a potential infinite loop
On 2/8/2022 3:26 PM, Anton Khirnov wrote: Current code will loop forever if MFXVideoVPP_Init() fails. Also, simplify the code. --- libavutil/hwcontext_qsv.c | 80 +++ 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index d3d8f42c99..95f8071abe 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include @@ -71,12 +72,11 @@ typedef struct QSVDeviceContext { typedef struct QSVFramesContext { mfxSession session_download; -int session_download_init; +atomic_int session_download_init; mfxSession session_upload; -int session_upload_init; +atomic_int session_upload_init; #if HAVE_PTHREADS pthread_mutex_t session_lock; -pthread_cond_t session_cond; #endif AVBufferRef *child_frames_ref; @@ -297,7 +297,6 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) #if HAVE_PTHREADS pthread_mutex_destroy(>session_lock); -pthread_cond_destroy(>session_cond); #endif av_freep(>mem_ids); @@ -744,7 +743,6 @@ static int qsv_frames_init(AVHWFramesContext *ctx) #if HAVE_PTHREADS pthread_mutex_init(>session_lock, NULL); -pthread_cond_init(>session_cond, NULL); #endif return 0; @@ -1024,6 +1022,32 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) return 0; } +static int qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload) +{ +QSVFramesContext *s = ctx->internal->priv; +atomic_int *inited = upload ? >session_upload_init : >session_download_init; +mfxSession *session = upload ? >session_upload : >session_download; +int ret = 0; + +if (atomic_load(inited)) +return 0; + +#if HAVE_PTHREADS +pthread_mutex_lock(>session_lock); +#endif + +if (!atomic_load(inited)) { +ret = qsv_init_internal_session(ctx, session, upload); +atomic_store(inited, 1); Nit: How about if (atomic_compare_exchange_strong(inited, , 1)) ret = qsv_init_internal_session(ctx, session, upload); Or using some other variable for the second argument (It must be 0 before the call, and will become 1 if *inited was already 1). Since atomic_compare_exchange_strong() is not used anywhere in the tree, it would let us know if any of the atomics emulation implementations are faulty (win32, pthreads, old gcc). +} + +#if HAVE_PTHREADS +pthread_mutex_unlock(>session_lock); +#endif + +return ret; +} + static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src) { @@ -1035,28 +1059,7 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, mfxStatus err; int ret = 0; -while (!s->session_download_init && !s->session_download && !ret) { -#if HAVE_PTHREADS -if (pthread_mutex_trylock(>session_lock) == 0) { -#endif -if (!s->session_download_init) { -ret = qsv_init_internal_session(ctx, >session_download, 0); -if (s->session_download) -s->session_download_init = 1; -} -#if HAVE_PTHREADS -pthread_mutex_unlock(>session_lock); -pthread_cond_signal(>session_cond); -} else { -pthread_mutex_lock(>session_lock); -while (!s->session_download_init && !s->session_download) { -pthread_cond_wait(>session_cond, >session_lock); -} -pthread_mutex_unlock(>session_lock); -} -#endif -} - +ret = qsv_internal_session_check_init(ctx, 0); if (ret < 0) return ret; @@ -1109,28 +1112,7 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src_frame; int realigned = 0; - -while (!s->session_upload_init && !s->session_upload && !ret) { -#if HAVE_PTHREADS -if (pthread_mutex_trylock(>session_lock) == 0) { -#endif -if (!s->session_upload_init) { -ret = qsv_init_internal_session(ctx, >session_upload, 1); -if (s->session_upload) -s->session_upload_init = 1; -} -#if HAVE_PTHREADS -pthread_mutex_unlock(>session_lock); -pthread_cond_signal(>session_cond); -} else { -pthread_mutex_lock(>session_lock); -while (!s->session_upload_init && !s->session_upload) { -pthread_cond_wait(>session_cond, >session_lock); -} -pthread_mutex_unlock(>session_lock); -} -#endif -} +ret = qsv_internal_session_check_init(ctx, 1); if (ret < 0) return ret; ___ ffmpeg-devel mailing list
[FFmpeg-devel] [PATCH 2/2] lavu/hwcontext_qsv: fix a potential infinite loop
Current code will loop forever if MFXVideoVPP_Init() fails. Also, simplify the code. --- libavutil/hwcontext_qsv.c | 80 +++ 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index d3d8f42c99..95f8071abe 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include @@ -71,12 +72,11 @@ typedef struct QSVDeviceContext { typedef struct QSVFramesContext { mfxSession session_download; -int session_download_init; +atomic_int session_download_init; mfxSession session_upload; -int session_upload_init; +atomic_int session_upload_init; #if HAVE_PTHREADS pthread_mutex_t session_lock; -pthread_cond_t session_cond; #endif AVBufferRef *child_frames_ref; @@ -297,7 +297,6 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) #if HAVE_PTHREADS pthread_mutex_destroy(>session_lock); -pthread_cond_destroy(>session_cond); #endif av_freep(>mem_ids); @@ -744,7 +743,6 @@ static int qsv_frames_init(AVHWFramesContext *ctx) #if HAVE_PTHREADS pthread_mutex_init(>session_lock, NULL); -pthread_cond_init(>session_cond, NULL); #endif return 0; @@ -1024,6 +1022,32 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) return 0; } +static int qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload) +{ +QSVFramesContext *s = ctx->internal->priv; +atomic_int *inited = upload ? >session_upload_init : >session_download_init; +mfxSession *session = upload ? >session_upload : >session_download; +int ret = 0; + +if (atomic_load(inited)) +return 0; + +#if HAVE_PTHREADS +pthread_mutex_lock(>session_lock); +#endif + +if (!atomic_load(inited)) { +ret = qsv_init_internal_session(ctx, session, upload); +atomic_store(inited, 1); +} + +#if HAVE_PTHREADS +pthread_mutex_unlock(>session_lock); +#endif + +return ret; +} + static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src) { @@ -1035,28 +1059,7 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, mfxStatus err; int ret = 0; -while (!s->session_download_init && !s->session_download && !ret) { -#if HAVE_PTHREADS -if (pthread_mutex_trylock(>session_lock) == 0) { -#endif -if (!s->session_download_init) { -ret = qsv_init_internal_session(ctx, >session_download, 0); -if (s->session_download) -s->session_download_init = 1; -} -#if HAVE_PTHREADS -pthread_mutex_unlock(>session_lock); -pthread_cond_signal(>session_cond); -} else { -pthread_mutex_lock(>session_lock); -while (!s->session_download_init && !s->session_download) { -pthread_cond_wait(>session_cond, >session_lock); -} -pthread_mutex_unlock(>session_lock); -} -#endif -} - +ret = qsv_internal_session_check_init(ctx, 0); if (ret < 0) return ret; @@ -1109,28 +1112,7 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src_frame; int realigned = 0; - -while (!s->session_upload_init && !s->session_upload && !ret) { -#if HAVE_PTHREADS -if (pthread_mutex_trylock(>session_lock) == 0) { -#endif -if (!s->session_upload_init) { -ret = qsv_init_internal_session(ctx, >session_upload, 1); -if (s->session_upload) -s->session_upload_init = 1; -} -#if HAVE_PTHREADS -pthread_mutex_unlock(>session_lock); -pthread_cond_signal(>session_cond); -} else { -pthread_mutex_lock(>session_lock); -while (!s->session_upload_init && !s->session_upload) { -pthread_cond_wait(>session_cond, >session_lock); -} -pthread_mutex_unlock(>session_lock); -} -#endif -} +ret = qsv_internal_session_check_init(ctx, 1); if (ret < 0) return ret; -- 2.34.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] lavfi/qsvpp: fix after 85c938fa28
--- libavfilter/qsvvpp.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 35769dfd60..954f882637 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -796,7 +796,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr AVFilterLink *outlink = ctx->outputs[0]; QSVAsyncFrame aframe; mfxSyncPoint sync; -QSVFrame *in_frame, *out_frame, *tmp; +QSVFrame *in_frame, *out_frame; int ret, filter_ret; while (s->eof && av_fifo_read(s->async_fifo, , 1) >= 0) { @@ -857,15 +857,15 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000); } while (ret == MFX_WRN_IN_EXECUTION); -filter_ret = s->filter_frame(outlink, tmp->frame); +filter_ret = s->filter_frame(outlink, aframe.frame->frame); if (filter_ret < 0) { -av_frame_free(>frame); +av_frame_free(>frame); return filter_ret; } -tmp->queued--; +aframe.frame->queued--; s->got_frame = 1; -tmp->frame = NULL; +aframe.frame->frame = NULL; } } while(ret == MFX_ERR_MORE_SURFACE); -- 2.34.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/2] lavu/fifo: add a test for _cb functions
Makes an auto-growing FIFO and performs a sequence of randomly-sized writes/peeks/reads. --- libavutil/tests/fifo.c | 101 + 1 file changed, 101 insertions(+) diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c index 579602ccf3..bfcdfeebfb 100644 --- a/libavutil/tests/fifo.c +++ b/libavutil/tests/fifo.c @@ -18,7 +18,53 @@ #include #include +#include "libavutil/common.h" #include "libavutil/fifo.h" +#include "libavutil/lfg.h" +#include "libavutil/random_seed.h" + +typedef struct CBState { +unsigned int read_idx; +unsigned int write_idx; +unsigned int to_process; +unsigned int offset; +} CBState; + +static int read_cb(void *opaque, void *buf, size_t *nb_elems) +{ +CBState *s = opaque; +unsigned *b = buf; + +*nb_elems = FFMIN(*nb_elems, s->to_process); + +for (unsigned i = 0; i < *nb_elems; i++) +if (b[i] != s->read_idx + s->offset + i) { +printf("Mismatch at idx %u offset %u i %u\n", + s->read_idx, s->offset, i); +return AVERROR_BUG; +} + +s->offset += *nb_elems; +s->to_process -= *nb_elems; + +return 0; +} + +static int write_cb(void *opaque, void *buf, size_t *nb_elems) +{ +CBState *s = opaque; +unsigned *b = buf; + +*nb_elems = FFMIN(*nb_elems, s->to_process); + +for (unsigned i = 0; i < *nb_elems; i++) +b[i] = s->write_idx + i; + +s->write_idx += *nb_elems; +s->to_process -= *nb_elems; + +return 0; +} int main(void) { @@ -89,6 +135,61 @@ int main(void) printf("%d: %d\n", i, j); } +av_fifo_freep2(); + +/* test randomly-sized write/read/peek with a callback */ +{ +CBStates = { 0 }; +uint32_tseed = av_get_random_seed(); + +AVLFG lfg; +int ret; + +av_lfg_init(, seed); + +fifo = av_fifo_alloc2(1, sizeof(unsigned), AV_FIFO_FLAG_AUTO_GROW); + +for (i = 0; i < 32; i++) { +size_t nb_elems = 16; +unsigned to_process = av_lfg_get() % nb_elems; + +s.to_process = to_process; + +ret = av_fifo_write_from_cb(fifo, write_cb, , _elems); +if (ret < 0 || s.to_process || nb_elems != to_process) { +printf("FIFO write fail; seed %"PRIu32"\n", seed); +return 1; +} + +nb_elems = av_fifo_can_read(fifo); +if (nb_elems > 1) { +s.offset = av_lfg_get() % (nb_elems - 1); +nb_elems-= s.offset; + +s.to_process = av_lfg_get() % nb_elems; +to_process = s.to_process; + +ret = av_fifo_peek_to_cb(fifo, read_cb, , _elems, s.offset); +if (ret < 0 || s.to_process || nb_elems != to_process) { +printf("FIFO peek fail; seed %"PRIu32"\n", seed); +return 1; +} +} + +nb_elems = av_fifo_can_read(fifo); +to_process = nb_elems ? av_lfg_get() % nb_elems : 0; +s.to_process = to_process; +s.offset = 0; + +ret = av_fifo_read_to_cb(fifo, read_cb, , _elems); +if (ret < 0 || s.to_process || to_process != nb_elems) { +printf("FIFO peek fail; seed %"PRIu32"\n", seed); +return 1; +} +s.read_idx += s.offset; +} +} + av_fifo_freep2(); free(p); -- 2.34.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] lavu/fifo: fix a corner case in av_fifo_grow2()
When the fifo is grown by exactly the current write offset, it would end up with offset_w = nb_elems. If av_fifo_write_from_cb() is called in such a state, the user callback would get callled with *nb_elems=0, which will then cause the write to return without writing anything. --- libavutil/fifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/fifo.c b/libavutil/fifo.c index 0af0154945..2af8842cc5 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -115,7 +115,7 @@ int av_fifo_grow2(AVFifo *f, size_t inc) (f->offset_w - copy) * f->elem_size); f->offset_w -= copy; } else -f->offset_w = f->nb_elems + copy; +f->offset_w = copy == inc ? 0 : f->nb_elems + copy; } f->nb_elems += inc; -- 2.34.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 2/2] avcodec/hcadec: Mark decoder as init-threadsafe
set lgtm ___ 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] lavu/fifo: fix regression
> -Original Message- > From: ffmpeg-devel On Behalf Of Xiang, > Haihao > Sent: Monday, February 7, 2022 9:48 PM > To: ffmpeg-devel@ffmpeg.org > Cc: Xiang, Haihao > Subject: [FFmpeg-devel] [PATCH] lavu/fifo: fix regression > > From: Haihao Xiang > > offset_w might be updated after growing the FIFO > > Fix ticket #9630 > > Tested-by: U. Artie Eoff > Reviewed-by: mkver > Reviewed-by: U. Artie Eoff > Signed-off-by: Haihao Xiang > --- > libavutil/fifo.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/libavutil/fifo.c b/libavutil/fifo.c > index 0af0154945..02e0ec3f0d 100644 > --- a/libavutil/fifo.c > +++ b/libavutil/fifo.c > @@ -147,13 +147,15 @@ static int fifo_write_common(AVFifo *f, const uint8_t > *buf, size_t *nb_elems, > AVFifoCB read_cb, void *opaque) > { > size_t to_write = *nb_elems; > -size_t offset_w = f->offset_w; > +size_t offset_w; > int ret = 0; > > ret = fifo_check_space(f, to_write); > if (ret < 0) > return ret; > > +offset_w = f->offset_w; > + > while (to_write > 0) { > size_tlen = FFMIN(f->nb_elems - offset_w, to_write); > uint8_t *wptr = f->buffer + offset_w * f->elem_size; > -- > 2.17.1 > LGTM > ___ > 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] [PATCH 2/2] avcodec/hcadec: Mark decoder as init-threadsafe
Signed-off-by: Andreas Rheinhardt --- libavcodec/hcadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c index ef3af08c4c..f5e23efc5b 100644 --- a/libavcodec/hcadec.c +++ b/libavcodec/hcadec.c @@ -455,7 +455,7 @@ const AVCodec ff_hca_decoder = { .decode = decode_frame, .close = decode_close, .capabilities = AV_CODEC_CAP_DR1, -.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, }; -- 2.32.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 1/2] avcodec/hcadec: Fix memleak upon allocation error
An AVFloatDSPContext would leak upon av_tx_init() failure. Signed-off-by: Andreas Rheinhardt --- libavcodec/hcadec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c index c98f8eb379..ef3af08c4c 100644 --- a/libavcodec/hcadec.c +++ b/libavcodec/hcadec.c @@ -455,6 +455,7 @@ const AVCodec ff_hca_decoder = { .decode = decode_frame, .close = decode_close, .capabilities = AV_CODEC_CAP_DR1, +.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, }; -- 2.32.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] avutil/tx: Fix documentation of av_tx_uninit()
Adapt it to the actual (sane) behaviour. Signed-off-by: Andreas Rheinhardt --- libavutil/tx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/tx.h b/libavutil/tx.h index 087355f10d..3de2f7231b 100644 --- a/libavutil/tx.h +++ b/libavutil/tx.h @@ -154,7 +154,7 @@ int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags); /** - * Frees a context and sets ctx to NULL, does nothing when ctx == NULL + * Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL. */ void av_tx_uninit(AVTXContext **ctx); -- 2.32.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] avcodec/vp8: Remove always-false check
Since e9b66175793e5c2af19beefe8e143f6e4901b5df a codec's close function is never ever called for a codec whose init function has not been called; in particular, it is never ever called if the AVCodecContext's private data has not been allocated. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp8.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index a70d94bd82..c9d9117528 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -2826,9 +2826,6 @@ av_cold int ff_vp8_decode_free(AVCodecContext *avctx) VP8Context *s = avctx->priv_data; int i; -if (!s) -return 0; - vp8_decode_flush_impl(avctx, 1); for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) av_frame_free(>frames[i].tf.f); -- 2.32.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] avcodec/g2meet: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/g2meet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c index 4c53838af5..8628016ef4 100644 --- a/libavcodec/g2meet.c +++ b/libavcodec/g2meet.c @@ -1592,7 +1592,6 @@ static av_cold int g2m_decode_init(AVCodecContext *avctx) if ((ret = jpg_init(avctx, >jc)) != 0) { av_log(avctx, AV_LOG_ERROR, "Cannot initialise VLCs\n"); -jpg_free_context(>jc); return AVERROR(ENOMEM); } @@ -1633,5 +1632,5 @@ const AVCodec ff_g2m_decoder = { .close = g2m_decode_end, .decode = g2m_decode_frame, .capabilities = AV_CODEC_CAP_DR1, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/metasound, twinvqdec: Cleanup generically upon init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/metasound.c | 2 +- libavcodec/twinvq.c| 5 + libavcodec/twinvq.h| 1 + libavcodec/twinvqdec.c | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libavcodec/metasound.c b/libavcodec/metasound.c index 57851a43c5..f066182f02 100644 --- a/libavcodec/metasound.c +++ b/libavcodec/metasound.c @@ -382,5 +382,5 @@ const AVCodec ff_metasound_decoder = { .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF, .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c index 6dfaf06b14..38482e8c21 100644 --- a/libavcodec/twinvq.c +++ b/libavcodec/twinvq.c @@ -783,13 +783,10 @@ av_cold int ff_twinvq_decode_init(AVCodecContext *avctx) tctx->frames_per_packet = frames_per_packet; tctx->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); -if (!tctx->fdsp) { -ff_twinvq_decode_close(avctx); +if (!tctx->fdsp) return AVERROR(ENOMEM); -} if ((ret = init_mdct_win(tctx))) { av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n"); -ff_twinvq_decode_close(avctx); return ret; } init_bitstream_params(tctx); diff --git a/libavcodec/twinvq.h b/libavcodec/twinvq.h index 234604f581..5f49796f03 100644 --- a/libavcodec/twinvq.h +++ b/libavcodec/twinvq.h @@ -197,6 +197,7 @@ static inline float twinvq_mulawinv(float y, float clip, float mu) int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt); int ff_twinvq_decode_close(AVCodecContext *avctx); +/** Requires the caller to call ff_twinvq_decode_close() upon failure. */ int ff_twinvq_decode_init(AVCodecContext *avctx); #endif /* AVCODEC_TWINVQ_H */ diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c index 1fbe0bc32e..090a9fb0eb 100644 --- a/libavcodec/twinvqdec.c +++ b/libavcodec/twinvqdec.c @@ -426,5 +426,5 @@ const AVCodec ff_twinvq_decoder = { .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF, .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/sonic: Use unsigned for predictor_k to avoid undefined behavior
Fixes: signed integer overflow: -1094995529 * 24 cannot be represented in type 'int' Fixes: 44436/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-4874459459223552 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/sonic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c index cf1cfb1460..0d539e8879 100644 --- a/libavcodec/sonic.c +++ b/libavcodec/sonic.c @@ -1004,7 +1004,7 @@ static int sonic_decode_frame(AVCodecContext *avctx, // dequantize for (i = 0; i < s->num_taps; i++) -s->predictor_k[i] *= s->tap_quant[i]; +s->predictor_k[i] *= (unsigned) s->tap_quant[i]; if (s->lossless) quant = 1; -- 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/2] avformat/hls: Use unsigned for iv computation
Fixes: signed integer overflow: 9223372036854775748 + 60 cannot be represented in type 'long' Fixes: 44417/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5802443881971712 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/hls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 4568e72cb2..8541fa9420 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -914,7 +914,7 @@ static int parse_playlist(HLSContext *c, const char *url, if (has_iv) { memcpy(seg->iv, iv, sizeof(iv)); } else { -int64_t seq = pls->start_seq_no + pls->n_segments; +uint64_t seq = pls->start_seq_no + (uint64_t)pls->n_segments; memset(seg->iv, 0, sizeof(seg->iv)); AV_WB64(seg->iv + 8, seq); } -- 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 1/2] avdevice/avfoundation: fix memleak
Thilo Borgmann: > Am 08.02.22 um 13:50 schrieb Andreas Rheinhardt: >> Thilo Borgmann: >>> Am 04.02.22 um 17:19 schrieb Zhao Zhili: --- libavdevice/avfoundation.m | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index 0cd6e646d5..2078c4879c 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -106,6 +106,7 @@ typedef struct int audio_device_index; int audio_stream_index; + char *url; char *video_filename; char *audio_filename; @@ -299,6 +300,7 @@ static void destroy_context(AVFContext* ctx) ctx->avf_delegate = NULL; ctx->avf_audio_delegate = NULL; + av_freep(>url); av_freep(>audio_buffer); >>> >>> Why carry it in the context instead of adding the missing av_freep() in >>> parse_device_name() ? >>> >> >> Because video_filename and audio_filename point into it. > > Wondering if we couldn't skip av_strdup() and operate on s->url directly > then. > This would trash s->url. - 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 1/2] avdevice/avfoundation: fix memleak
Am 08.02.22 um 13:50 schrieb Andreas Rheinhardt: Thilo Borgmann: Am 04.02.22 um 17:19 schrieb Zhao Zhili: --- libavdevice/avfoundation.m | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index 0cd6e646d5..2078c4879c 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -106,6 +106,7 @@ typedef struct int audio_device_index; int audio_stream_index; + char *url; char *video_filename; char *audio_filename; @@ -299,6 +300,7 @@ static void destroy_context(AVFContext* ctx) ctx->avf_delegate = NULL; ctx->avf_audio_delegate = NULL; + av_freep(>url); av_freep(>audio_buffer); Why carry it in the context instead of adding the missing av_freep() in parse_device_name() ? Because video_filename and audio_filename point into it. Wondering if we couldn't skip av_strdup() and operate on s->url directly then. -Thilo ___ 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/2] avdevice/avfoundation: fix memleak
Thilo Borgmann: > Am 04.02.22 um 17:19 schrieb Zhao Zhili: >> --- >> libavdevice/avfoundation.m | 10 ++ >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m >> index 0cd6e646d5..2078c4879c 100644 >> --- a/libavdevice/avfoundation.m >> +++ b/libavdevice/avfoundation.m >> @@ -106,6 +106,7 @@ typedef struct >> int audio_device_index; >> int audio_stream_index; >> + char *url; >> char *video_filename; >> char *audio_filename; >> @@ -299,6 +300,7 @@ static void destroy_context(AVFContext* ctx) >> ctx->avf_delegate = NULL; >> ctx->avf_audio_delegate = NULL; >> + av_freep(>url); >> av_freep(>audio_buffer); > > Why carry it in the context instead of adding the missing av_freep() in > parse_device_name() ? > Because video_filename and audio_filename point into it. - 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 1/2] avdevice/avfoundation: fix memleak
Am 04.02.22 um 17:19 schrieb Zhao Zhili: --- libavdevice/avfoundation.m | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index 0cd6e646d5..2078c4879c 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -106,6 +106,7 @@ typedef struct int audio_device_index; int audio_stream_index; +char*url; char*video_filename; char*audio_filename; @@ -299,6 +300,7 @@ static void destroy_context(AVFContext* ctx) ctx->avf_delegate= NULL; ctx->avf_audio_delegate = NULL; +av_freep(>url); av_freep(>audio_buffer); Why carry it in the context instead of adding the missing av_freep() in parse_device_name() ? -Thilo ___ 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/4xm: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/4xm.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index cb315cd7e4..cb361772d2 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -1008,10 +1008,8 @@ static av_cold int decode_init(AVCodecContext *avctx) f->frame_buffer = av_mallocz(avctx->width * avctx->height * 2); f->last_frame_buffer = av_mallocz(avctx->width * avctx->height * 2); -if (!f->frame_buffer || !f->last_frame_buffer) { -decode_end(avctx); +if (!f->frame_buffer || !f->last_frame_buffer) return AVERROR(ENOMEM); -} f->version = AV_RL32(avctx->extradata) >> 16; ff_blockdsp_init(>bdsp, avctx); @@ -1038,5 +1036,5 @@ const AVCodec ff_fourxm_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/g2meet: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/g2meet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c index 4c53838af5..8628016ef4 100644 --- a/libavcodec/g2meet.c +++ b/libavcodec/g2meet.c @@ -1592,7 +1592,6 @@ static av_cold int g2m_decode_init(AVCodecContext *avctx) if ((ret = jpg_init(avctx, >jc)) != 0) { av_log(avctx, AV_LOG_ERROR, "Cannot initialise VLCs\n"); -jpg_free_context(>jc); return AVERROR(ENOMEM); } @@ -1633,5 +1632,5 @@ const AVCodec ff_g2m_decoder = { .close = g2m_decode_end, .decode = g2m_decode_frame, .capabilities = AV_CODEC_CAP_DR1, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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 3/3] avcodec/cavsdec: Fix error message
Signed-off-by: Andreas Rheinhardt --- libavcodec/cavsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index da9aa94deb..6f4856ce97 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -505,7 +505,7 @@ static inline int get_ue_code(GetBitContext *gb, int order) { unsigned ret = get_ue_golomb(gb); if (ret >= ((1U<<31)>>order)) { -av_log(NULL, AV_LOG_ERROR, "get_ue_code: value too larger\n"); +av_log(NULL, AV_LOG_ERROR, "get_ue_code: value too large\n"); return AVERROR_INVALIDDATA; } if (order) { -- 2.32.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/3] avcodec/cavsdec: Mark decoder as init-threadsafe
It does not initialize any static data in its .init. Signed-off-by: Andreas Rheinhardt --- libavcodec/cavsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 54e1877bbd..da9aa94deb 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -1319,5 +1319,5 @@ const AVCodec ff_cavs_decoder = { .decode = cavs_decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .flush = cavs_flush, -.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/cavsdec: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/cavs.c| 4 +--- libavcodec/cavsdec.c | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index e29d9c659b..5367c44248 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -812,10 +812,8 @@ av_cold int ff_cavs_init(AVCodecContext *avctx) h->cur.f= av_frame_alloc(); h->DPB[0].f = av_frame_alloc(); h->DPB[1].f = av_frame_alloc(); -if (!h->cur.f || !h->DPB[0].f || !h->DPB[1].f) { -ff_cavs_end(avctx); +if (!h->cur.f || !h->DPB[0].f || !h->DPB[1].f) return AVERROR(ENOMEM); -} h->luma_scan[0] = 0; h->luma_scan[1] = 8; diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 894aa1b54a..54e1877bbd 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -1319,4 +1319,5 @@ const AVCodec ff_cavs_decoder = { .decode = cavs_decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .flush = cavs_flush, +.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avformat/mpegts: initialize max_packet_size when sub-demuxer
On 2022-02-07 09:34 am, Gyan Doshi wrote: On 2022-02-07 03:59 am, Marton Balint wrote: On Sat, 5 Feb 2022, Gyan Doshi wrote: bca30570d2 added a user option to set max_packet_size replacing a hardcoded value. This had a side-effect of leaving the field set to 0 when packet demuxing is carried out from another demuxer using avpriv functions, which could lead to demux failure. Hardcoded max_packet_size inside avpriv_mpegts_parse_open to 2048000 to avoid this. Value chosen to be 10x that of default value to accommodate large payloads. I don't understand why the default is different from the normal mpegts case. Large payloads can happen there as well, and previously it was assumed that splitting is OK, because it will be parsed anyway. The option was added because MPEG-TS allows any codec to be carried as a private stream and when demuxing that, the parser isn't inserted, even when forcing a decoder, hence the need to not have split packets. In this case, the user can't tune the value, so I went with an expansive one. Plan to push tomorrow. Regards, Gyan ___ 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/3] configure: check avisynth header version
The headers from version 3.7.1 are needed in order to support parsing of frame properties. avs/version.h has been generated as part of the AviSynth+ build process for a long time, but was never installed with the includes until version 3.7.1a. Checking for the presence of avs/version.h might have been sufficient, but a version check mechanism might be useful in the future. This does not change the version compatibility with the library itself; previous 3.x versions of AviSynth+ as well as AviSynth 2.6 can still be used with the demuxer. Signed-off-by: Stephen Hutchinson --- configure | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 493493b4c5..544d341b49 100755 --- a/configure +++ b/configure @@ -6508,7 +6508,9 @@ for func in $COMPLEX_FUNCS; do done # these are off by default, so fail if requested and not available -enabled avisynth && require_headers "avisynth/avisynth_c.h" +enabled avisynth && { require_headers "avisynth/avisynth_c.h avisynth/avs/version.h" && + { test_cpp_condition avisynth/avs/version.h "AVS_MAJOR_VER >= 3 && AVS_MINOR_VER >= 7 && AVS_BUGFIX_VER >= 1 || AVS_MAJOR_VER >= 3 && AVS_MINOR_VER > 7 || AVS_MAJOR_VER > 3" || + die "ERROR: AviSynth+ header version must be >= 3.7.1"; } } enabled cuda_nvcc && { check_nvcc cuda_nvcc || die "ERROR: failed checking for nvcc."; } enabled chromaprint && require chromaprint chromaprint.h chromaprint_get_version -lchromaprint enabled decklink && { require_headers DeckLinkAPI.h && -- 2.32.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/3] avisynth: use AviSynth+'s frame properties to set various fields
* Field Order * Chroma Location * Color Transfer Characteristics * Color Range * Color Primaries * Matrix Coefficients The existing TFF/BFF detection is retained as a fallback for older versions of AviSynth that can't access frame properties. The other properties have no legacy equivalent to detect them. Signed-off-by: Stephen Hutchinson --- libavformat/avisynth.c | 263 +++-- 1 file changed, 250 insertions(+), 13 deletions(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 1e862a6a85..8bc39869a3 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "libavutil/attributes.h" #include "libavutil/internal.h" @@ -76,6 +78,9 @@ typedef struct AviSynthLibrary { AVSC_DECLARE_FUNC(avs_get_row_size_p); AVSC_DECLARE_FUNC(avs_is_planar_rgb); AVSC_DECLARE_FUNC(avs_is_planar_rgba); +AVSC_DECLARE_FUNC(avs_get_frame_props_ro); +AVSC_DECLARE_FUNC(avs_prop_get_int); +AVSC_DECLARE_FUNC(avs_get_env_property); #undef AVSC_DECLARE_FUNC } AviSynthLibrary; @@ -153,6 +158,9 @@ static av_cold int avisynth_load_library(void) LOAD_AVS_FUNC(avs_get_row_size_p, 1); LOAD_AVS_FUNC(avs_is_planar_rgb, 1); LOAD_AVS_FUNC(avs_is_planar_rgba, 1); +LOAD_AVS_FUNC(avs_get_frame_props_ro, 1); +LOAD_AVS_FUNC(avs_prop_get_int, 1); +LOAD_AVS_FUNC(avs_get_env_property, 1); #undef LOAD_AVS_FUNC atexit(avisynth_atexit_handler); @@ -236,6 +244,10 @@ static av_cold void avisynth_atexit_handler(void) static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) { AviSynthContext *avs = s->priv_data; +const AVS_Map *avsmap; +AVS_VideoFrame *frame; +int framedata, error; +bool frameprop; int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: Planar RGBA st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; @@ -251,19 +263,6 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) avpriv_set_pts_info(st, 32, avs->vi->fps_denominator, avs->vi->fps_numerator); -st->codecpar->field_order = AV_FIELD_UNKNOWN; -/* AviSynth works with frame-based video, detecting field order can - * only work when avs_is_field_based returns 'false'. */ -av_log(s, AV_LOG_TRACE, "avs_is_field_based: %d\n", avs_is_field_based(avs->vi)); -if (avs_is_field_based(avs->vi) == 0) { -if (avs_is_tff(avs->vi)) { -st->codecpar->field_order = AV_FIELD_TT; -} -else if (avs_is_bff(avs->vi)) { -st->codecpar->field_order = AV_FIELD_BB; -} -} - switch (avs->vi->pixel_type) { /* 10~16-bit YUV pix_fmts (AviSynth+) */ case AVS_CS_YUV444P10: @@ -499,6 +498,244 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) avs->n_planes = 1; avs->planes = avs_planes_packed; } + +/* Read AviSynth+'s frame properties to set additional info. + * + * Due to a bug preventing the C interface from accessing frame + * properties in earlier versions of interface version 8, only + * enable this if we detect version 8.1 at the minimum. */ + +if (!avs_library.avs_get_env_property) { +av_log(s, AV_LOG_TRACE, "%s\n", + "avs_get_env_property does not exist in AviSynth library; frame properties won't be checked."); +frameprop = false; +} else { +if (avs_library.avs_get_env_property(avs->env, AVS_AEP_INTERFACE_BUGFIX)) { +av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.1 or higher, reading frame properties."); +frameprop = true; +} else { +av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.0, need 8.1+ to read frame properties."); +frameprop = false; +} +} + +if (frameprop = true) { + +frame = avs_library.avs_get_frame(avs->clip, framedata); +avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame); + +/* Field order */ +switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_FieldBased", 0, )) { +case 0: +st->codecpar->field_order = AV_FIELD_PROGRESSIVE; +break; +case 1: +st->codecpar->field_order = AV_FIELD_BB; +break; +case 2: +st->codecpar->field_order = AV_FIELD_TT; +break; +default: +st->codecpar->field_order = AV_FIELD_UNKNOWN; +} + +/* Color Range */ +switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_ColorRange", 0, )) { +case 0: +st->codecpar->color_range = AVCOL_RANGE_JPEG; +break; +case 1: +st->codecpar->color_range = AVCOL_RANGE_MPEG; +break; +default: +st->codecpar->color_range =
[FFmpeg-devel] [PATCH 1/3] avisynth: corrected interlace detection
From: emcodem AviSynth works on frame-based video by default, which can be either progressive or interlaced. Some filters can break frames into half-height fields, at which point it considers the clip to be field-based (avs_is_field_based can be used to check for this situation). To properly detect the field order of a typical video clip, the frame needs to have been weaved back together already, so avs_is_field_based should actually report 'false' when checked. Signed-off-by: Stephen Hutchinson --- libavformat/avisynth.c | 11 --- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 350ac6d11d..1e862a6a85 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -250,15 +250,12 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) st->nb_frames = avs->vi->num_frames; avpriv_set_pts_info(st, 32, avs->vi->fps_denominator, avs->vi->fps_numerator); -av_log(s, AV_LOG_TRACE, "avs_is_field_based: %d\n", avs_is_field_based(avs->vi)); -av_log(s, AV_LOG_TRACE, "avs_is_parity_known: %d\n", avs_is_parity_known(avs->vi)); -/* The following typically only works when assumetff (-bff) and - * assumefieldbased is used in-script. Additional - * logic using GetParity() could deliver more accurate results - * but also decodes a frame which we want to avoid. */ st->codecpar->field_order = AV_FIELD_UNKNOWN; -if (avs_is_field_based(avs->vi)) { +/* AviSynth works with frame-based video, detecting field order can + * only work when avs_is_field_based returns 'false'. */ +av_log(s, AV_LOG_TRACE, "avs_is_field_based: %d\n", avs_is_field_based(avs->vi)); +if (avs_is_field_based(avs->vi) == 0) { if (avs_is_tff(avs->vi)) { st->codecpar->field_order = AV_FIELD_TT; } -- 2.32.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 0/3] avformat/avisynth: support frame properties
AviSynth+ 3.6.0 introduced support for frame properties, allowing various metadata to be passed between filters or read out by client programs. Using this, FFmpeg can read Color Range, Transfer Characteristics, Matrix, Color Primaries, Chroma Location, and Field Order information from AviSynth scripts. Reading frame properties through AviSynth's C interface was not possible until a few months ago, though, so client programs that use the C API need version 3.7.1 or higher to be able to take advantage of it. Incorporates a previous patch by emcodem that fixes setting field order on non-frameprop-aware versions of AviSynth. Stephen Hutchinson (2): avisynth: use AviSynth+'s frame properties to set various fields configure: check avisynth header version emcodem (1): avisynth: corrected interlace detection configure | 4 +- libavformat/avisynth.c | 266 ++--- 2 files changed, 253 insertions(+), 17 deletions(-) -- 2.32.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] avcodec/tta: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/tta.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/tta.c b/libavcodec/tta.c index 17b4ca9032..accac38893 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -114,10 +114,8 @@ static int allocate_buffers(AVCodecContext *avctx) } else s->decode_buffer = NULL; s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx)); -if (!s->ch_ctx) { -av_freep(>decode_buffer); +if (!s->ch_ctx) return AVERROR(ENOMEM); -} return 0; } @@ -427,5 +425,5 @@ const AVCodec ff_tta_decoder = { .decode = tta_decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_CHANNEL_CONF, .priv_class = _decoder_class, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/ralf: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/ralf.c | 26 +++--- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/libavcodec/ralf.c b/libavcodec/ralf.c index bb80119b0c..0c51f49939 100644 --- a/libavcodec/ralf.c +++ b/libavcodec/ralf.c @@ -163,47 +163,35 @@ static av_cold int decode_init(AVCodecContext *avctx) for (i = 0; i < 3; i++) { ret = init_ralf_vlc(>sets[i].filter_params, filter_param_def[i], FILTERPARAM_ELEMENTS); -if (ret < 0) { -decode_close(avctx); +if (ret < 0) return ret; -} ret = init_ralf_vlc(>sets[i].bias, bias_def[i], BIAS_ELEMENTS); -if (ret < 0) { -decode_close(avctx); +if (ret < 0) return ret; -} ret = init_ralf_vlc(>sets[i].coding_mode, coding_mode_def[i], CODING_MODE_ELEMENTS); -if (ret < 0) { -decode_close(avctx); +if (ret < 0) return ret; -} for (j = 0; j < 10; j++) { for (k = 0; k < 11; k++) { ret = init_ralf_vlc(>sets[i].filter_coeffs[j][k], filter_coeffs_def[i][j][k], FILTER_COEFFS_ELEMENTS); -if (ret < 0) { -decode_close(avctx); +if (ret < 0) return ret; -} } } for (j = 0; j < 15; j++) { ret = init_ralf_vlc(>sets[i].short_codes[j], short_codes_def[i][j], SHORT_CODES_ELEMENTS); -if (ret < 0) { -decode_close(avctx); +if (ret < 0) return ret; -} } for (j = 0; j < 125; j++) { ret = init_ralf_vlc(>sets[i].long_codes[j], long_codes_def[i][j], LONG_CODES_ELEMENTS); -if (ret < 0) { -decode_close(avctx); +if (ret < 0) return ret; -} } } @@ -539,5 +527,5 @@ const AVCodec ff_ralf_decoder = { AV_CODEC_CAP_DR1, .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/vc2enc: Cleanup generically on allocation failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/vc2enc.c | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c index f0d2cdf62d..ccca78d281 100644 --- a/libavcodec/vc2enc.c +++ b/libavcodec/vc2enc.c @@ -1135,7 +1135,7 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx) p->coef_stride = FFALIGN(p->dwt_width, 32); p->coef_buf = av_mallocz(p->coef_stride*p->dwt_height*sizeof(dwtcoef)); if (!p->coef_buf) -goto alloc_fail; +return AVERROR(ENOMEM); for (level = s->wavelet_depth-1; level >= 0; level--) { w = w >> 1; h = h >> 1; @@ -1154,7 +1154,7 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx) s->plane[i].coef_stride, s->plane[i].dwt_height, s->slice_width, s->slice_height)) -goto alloc_fail; +return AVERROR(ENOMEM); } /* Slices */ @@ -1163,7 +1163,7 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx) s->slice_args = av_calloc(s->num_x*s->num_y, sizeof(SliceArgs)); if (!s->slice_args) -goto alloc_fail; +return AVERROR(ENOMEM); for (i = 0; i < 116; i++) { const uint64_t qf = ff_dirac_qscale_tab[i]; @@ -1183,11 +1183,6 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx) } return 0; - -alloc_fail: -vc2_encode_end(avctx); -av_log(avctx, AV_LOG_ERROR, "Unable to allocate memory!\n"); -return AVERROR(ENOMEM); } #define VC2ENC_FLAGS (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) @@ -1234,10 +1229,10 @@ const AVCodec ff_vc2_encoder = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_DIRAC, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .priv_data_size = sizeof(VC2EncContext), .init = vc2_encode_init, .close = vc2_encode_end, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .encode2= vc2_encode_frame, .priv_class = _class, .defaults = vc2enc_defaults, -- 2.32.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 1/2] avcodec/vc2enc_dwt: Avoid NULL - 0
It is sane, but UB. It could happen in case of allocation errors in vc2_encode_init(). Signed-off-by: Andreas Rheinhardt --- libavcodec/vc2enc_dwt.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/vc2enc_dwt.c b/libavcodec/vc2enc_dwt.c index a8d3f1c669..441af040ec 100644 --- a/libavcodec/vc2enc_dwt.c +++ b/libavcodec/vc2enc_dwt.c @@ -276,6 +276,8 @@ av_cold int ff_vc2enc_init_transforms(VC2TransformContext *s, int p_stride, av_cold void ff_vc2enc_free_transforms(VC2TransformContext *s) { -av_free(s->buffer - s->padding); -s->buffer = NULL; +if (s->buffer) { +av_free(s->buffer - s->padding); +s->buffer = NULL; +} } -- 2.32.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] lavfi/drawtext: Add localtime_ms for millisecond precision
Am 08.02.22 um 10:27 schrieb Andreas Rheinhardt: Thilo Borgmann: Am 01.02.22 um 00:40 schrieb Andreas Rheinhardt: Thilo Borgmann: Am 31.01.22 um 14:08 schrieb Nicolas George: Thilo Borgman (12022-01-31): v10 attached. Also going to apply soon if there are no more comments. I think you neglected to attach the file. omg stupid me. Here it is... -Thilo Seems like I misunderstood your code and ignored the outer while. Your code can leak if there are multiple 'N', because (as I said) + + if (fmt_new && fmt_new != argv[0] && fmt_new != fmt_default) + av_freep(_new); + does not free fmt if it is already allocated. It is possible to fix this by adding an char *fmt_allocated = NULL; at outer scope and a fmt_new in the block that is executed if a 'N' is executed. (You have to free fmt_allocated immediately after av_asprintf().) But maybe it would be best to use an AVBPrint to write the new string instead of allocating a new string for every %N encountered. v11 does it that way. +av_bprintf(_bp, "%s", fmt_begin); +av_bprint_finalize(_bp, (char**)); +if (!fmt) +return AVERROR(ENOMEM); + av_bprint_strftime(bp, fmt, ); +av_freep(); + This is not how one uses an AVBPrint: You are loosing the small-string-optimization that way. Furthermore, you do not check for truncation. v12 including IRC comments. -ThiloFrom bb53ac8d924ed7d674f254091d2c7a92fe2ea41d Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Tue, 8 Feb 2022 11:39:46 +0100 Subject: [PATCH v12] lavfi/drawtext: Add %N for drawing fractions of a second Suggested-By: ffm...@fb.com --- doc/filters.texi | 4 +++ libavfilter/vf_drawtext.c | 70 +-- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 05d4b1a56e..c3895138e0 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -11378,10 +11378,14 @@ It can be used to add padding with zeros from the left. @item gmtime The time at which the filter is running, expressed in UTC. It can accept an argument: a strftime() format string. +The format string is extended to support the variable @var{%[1-6]N} +which prints fractions of the second with optionally specified number of digits. @item localtime The time at which the filter is running, expressed in the local time zone. It can accept an argument: a strftime() format string. +The format string is extended to support the variable @var{%[1-6]N} +which prints fractions of the second with optionally specified number of digits. @item metadata Frame metadata. Takes one or two arguments. diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 2a88692cbd..d3ec68004d 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -51,6 +51,7 @@ #include "libavutil/opt.h" #include "libavutil/random_seed.h" #include "libavutil/parseutils.h" +#include "libavutil/time.h" #include "libavutil/timecode.h" #include "libavutil/time_internal.h" #include "libavutil/tree.h" @@ -1045,15 +1046,78 @@ static int func_strftime(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { const char *fmt = argc ? argv[0] : "%Y-%m-%d %H:%M:%S"; +const char *fmt_begin = fmt; +int64_t unow; time_t now; struct tm tm; +const char *begin; +const char *tmp; +int len; +int div; +AVBPrint fmt_bp; -time(); -if (tag == 'L') +av_bprint_init(_bp, 0, AV_BPRINT_SIZE_UNLIMITED); + +unow = av_gettime(); +now = unow / 100; +if (tag == 'L' || tag == 'm') localtime_r(, ); else tm = *gmtime_r(, ); -av_bprint_strftime(bp, fmt, ); + +// manually parse format for %N (fractional seconds) +begin = fmt; +while ((begin = strchr(begin, '%'))) { +tmp = begin + 1; +len = 0; + +// skip escaped "%%" +if (*tmp == '%') { +begin = tmp + 1; +continue; +} + +// count digits between % and possible N +while (*tmp != '\0' && av_isdigit((int)*tmp)) { +len++; +tmp++; +} + +// N encountered, insert time +if (*tmp == 'N') { +int num_digits = 3; // default show millisecond [1,6] + +// if digit given, expect [1,6], warn & clamp otherwise +if (len == 1) { +num_digits = av_clip(*(begin + 1) - '0', 1, 6); +} else if (len > 1) { +av_log(ctx, AV_LOG_WARNING, "Invalid number of decimals for %%N, using default of %i\n", num_digits); +} + +len += 2; // add % and N to get length of string part + +div = pow(10, 6 - num_digits); + +av_bprintf(_bp, "%.*s%0*d", (int)(begin - fmt_begin), fmt_begin, num_digits, (int)(unow % 100) / div); + +begin += len; +fmt_begin = begin; + +
[FFmpeg-devel] [PATCH 2/2] avcodec/proresenc_kostya: Use av_calloc/av_malloc_array()
Signed-off-by: Andreas Rheinhardt --- libavcodec/proresenc_kostya.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 08a874dd4e..beceee621d 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -1273,18 +1273,18 @@ static av_cold int encode_init(AVCodecContext *avctx) } } -ctx->slice_q = av_malloc(ctx->slices_per_picture * sizeof(*ctx->slice_q)); +ctx->slice_q = av_malloc_array(ctx->slices_per_picture, sizeof(*ctx->slice_q)); if (!ctx->slice_q) return AVERROR(ENOMEM); -ctx->tdata = av_mallocz(avctx->thread_count * sizeof(*ctx->tdata)); +ctx->tdata = av_calloc(avctx->thread_count, sizeof(*ctx->tdata)); if (!ctx->tdata) return AVERROR(ENOMEM); for (j = 0; j < avctx->thread_count; j++) { -ctx->tdata[j].nodes = av_malloc((ctx->slices_width + 1) -* TRELLIS_WIDTH -* sizeof(*ctx->tdata->nodes)); +ctx->tdata[j].nodes = av_malloc_array(ctx->slices_width + 1, + TRELLIS_WIDTH + * sizeof(*ctx->tdata->nodes)); if (!ctx->tdata[j].nodes) return AVERROR(ENOMEM); for (i = min_quant; i < max_quant + 2; i++) { -- 2.32.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 1/2] avcodec/proresenc_kostya: Cleanup generically after init failure
Signed-off-by: Andreas Rheinhardt --- libavcodec/proresenc_kostya.c | 14 -- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 85651fce2a..08a874dd4e 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -1274,25 +1274,19 @@ static av_cold int encode_init(AVCodecContext *avctx) } ctx->slice_q = av_malloc(ctx->slices_per_picture * sizeof(*ctx->slice_q)); -if (!ctx->slice_q) { -encode_close(avctx); +if (!ctx->slice_q) return AVERROR(ENOMEM); -} ctx->tdata = av_mallocz(avctx->thread_count * sizeof(*ctx->tdata)); -if (!ctx->tdata) { -encode_close(avctx); +if (!ctx->tdata) return AVERROR(ENOMEM); -} for (j = 0; j < avctx->thread_count; j++) { ctx->tdata[j].nodes = av_malloc((ctx->slices_width + 1) * TRELLIS_WIDTH * sizeof(*ctx->tdata->nodes)); -if (!ctx->tdata[j].nodes) { -encode_close(avctx); +if (!ctx->tdata[j].nodes) return AVERROR(ENOMEM); -} for (i = min_quant; i < max_quant + 2; i++) { ctx->tdata[j].nodes[i].prev_node = -1; ctx->tdata[j].nodes[i].bits = 0; @@ -1415,5 +1409,5 @@ const AVCodec ff_prores_ks_encoder = { }, .priv_class = _class, .profiles = NULL_IF_CONFIG_SMALL(ff_prores_profiles), -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.32.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] avcodec/pngdec: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt --- I did not add these codecs the last time I searched for codecs to add the FF_CODEC_CAP_INIT_CLEANUP because I was unsure whether calling ff_thread_release_buffer() on a NULL frame was safe (it is). libavcodec/pngdec.c | 9 +++-- 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 3c7907..6a22f8d9d8 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1696,11 +1696,8 @@ static av_cold int png_dec_init(AVCodecContext *avctx) s->avctx = avctx; s->last_picture.f = av_frame_alloc(); s->picture.f = av_frame_alloc(); -if (!s->last_picture.f || !s->picture.f) { -av_frame_free(>last_picture.f); -av_frame_free(>picture.f); +if (!s->last_picture.f || !s->picture.f) return AVERROR(ENOMEM); -} ff_pngdsp_init(>dsp); @@ -1741,7 +1738,7 @@ const AVCodec ff_apng_decoder = { .decode = decode_frame_apng, .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context), .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ALLOCATE_PROGRESS, }; #endif @@ -1759,6 +1756,6 @@ const AVCodec ff_png_decoder = { .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context), .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/, .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE | - FF_CODEC_CAP_ALLOCATE_PROGRESS, + FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP, }; #endif -- 2.32.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] libavutil: include assembly with full path from source root
Quoting Alexander Kanavin (2022-02-07 12:24:58) > On Mon, 31 Jan 2022 at 14:29, Alexander Kanavin > wrote: > > > On Mon, 31 Jan 2022 at 13:52, Anton Khirnov wrote: > > > >> With a separate build directory, I'm getting > >> $ strings libavutil/x86/tx_float.o |grep asm > >> src/libavutil/x86/tx_float.asm > >> > > > > The key piece is > > ../configure --disable-stripping > > > > With stripping disabled and without the patch, you should see: > > > > alex@alex-lx-laptop:~/development/ffmpeg/build$ strings > > libavutil/x86/tx_float.o |grep asm > > src/libavutil/x86/tx_float.asm > > src/libavutil/x86/tx_float.asm > > /home/alex/development/ffmpeg/libavutil/x86/x86util.asm > > src/libavutil/x86/tx_float.asm > > > > Ping, please :) pushed. sorry for the delay -- Anton Khirnov ___ 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/cbs_jpeg: Fix size of huffman symbol table array
L[i] can be in the range of 0-255, see table B.5 of ITU T.81. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_jpeg.h | 2 +- libavcodec/cbs_jpeg_syntax_template.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/cbs_jpeg.h b/libavcodec/cbs_jpeg.h index 6305f0ee86..9dbebd259f 100644 --- a/libavcodec/cbs_jpeg.h +++ b/libavcodec/cbs_jpeg.h @@ -99,7 +99,7 @@ typedef struct JPEGRawHuffmanTable { uint8_t Tc; uint8_t Th; uint8_t L[16]; -uint8_t V[224]; +uint8_t V[256]; } JPEGRawHuffmanTable; typedef struct JPEGRawHuffmanTableSpecification { diff --git a/libavcodec/cbs_jpeg_syntax_template.c b/libavcodec/cbs_jpeg_syntax_template.c index 6eda56d623..e06abdc674 100644 --- a/libavcodec/cbs_jpeg_syntax_template.c +++ b/libavcodec/cbs_jpeg_syntax_template.c @@ -84,12 +84,12 @@ static int FUNC(huffman_table)(CodedBitstreamContext *ctx, RWContext *rw, u(4, Th, 0, 3); for (i = 0; i < 16; i++) -us(8, L[i], i, 0, 224); +us(8, L[i], i, 0, 255); ij = 0; for (i = 0; i < 16; i++) { for (j = 0; j < current->L[i]; j++) { -if (ij >= 224) +if (ij >= FF_ARRAY_ELEMS(current->V)) return AVERROR_INVALIDDATA; us(8, V[ij], ij, 0, 255); ++ij; -- 2.32.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 1/4] lavc/mpeg*: drop the XvMC hwaccel code
Quoting Andreas Rheinhardt (2022-02-07 02:46:08) > I thought that removing components is only possible at a major version > bump. Am I wrong? AFAIK we provide no API guarantees for specific components being available. -- Anton Khirnov ___ 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/4] lavc/mpeg*: drop the XvMC hwaccel code
Quoting Soft Works (2022-02-07 03:18:54) > I sometimes wonder whether there exists a single API user who > really understands this (very special) kind of logic and > would make decisions based on that understanding. > > When it's not even fully understood internally, how should it > be understood externally? The rule for API users is simple: you are not allowed to assume a specific component (like a decoder, demuxer or hwaccel) will be available at runtime*. You are supposed to check for it using the APIs provided for this purpose. In this case, AV_PIX_FMT_XVMC will just stop being offered in get_format(). Not to mention that I very much doubt there are any users of xvmc left, besides the original mplayer. * unless you are running with a very specific verified build, in which case a removal like this should be caught at the build stage -- Anton Khirnov ___ 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] lavfi/drawtext: Add localtime_ms for millisecond precision
Thilo Borgmann: > Am 01.02.22 um 00:40 schrieb Andreas Rheinhardt: >> Thilo Borgmann: >>> Am 31.01.22 um 14:08 schrieb Nicolas George: Thilo Borgman (12022-01-31): >> v10 attached. > > Also going to apply soon if there are no more comments. I think you neglected to attach the file. >>> >>> omg stupid me. Here it is... >>> >>> -Thilo >>> >> >> Seems like I misunderstood your code and ignored the outer while. Your >> code can leak if there are multiple 'N', because (as I said) >> >>> >>> + >>> + if (fmt_new && fmt_new != argv[0] && fmt_new != >>> fmt_default) >>> + av_freep(_new); >>> + >> >> does not free fmt if it is already allocated. It is possible to fix this >> by adding an char *fmt_allocated = NULL; at outer scope and a fmt_new in >> the block that is executed if a 'N' is executed. (You have to free >> fmt_allocated immediately after av_asprintf().) > >> But maybe it would be best to use an AVBPrint to write the new string >> instead of allocating a new string for every %N encountered. > > v11 does it that way. > > > +av_bprintf(_bp, "%s", fmt_begin); > +av_bprint_finalize(_bp, (char**)); > +if (!fmt) > +return AVERROR(ENOMEM); > + > av_bprint_strftime(bp, fmt, ); > +av_freep(); > + This is not how one uses an AVBPrint: You are loosing the small-string-optimization that way. Furthermore, you do not check for truncation. - 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 v2] lavfi/drawtext: Add localtime_ms for millisecond precision
Am 01.02.22 um 00:40 schrieb Andreas Rheinhardt: Thilo Borgmann: Am 31.01.22 um 14:08 schrieb Nicolas George: Thilo Borgman (12022-01-31): v10 attached. Also going to apply soon if there are no more comments. I think you neglected to attach the file. omg stupid me. Here it is... -Thilo Seems like I misunderstood your code and ignored the outer while. Your code can leak if there are multiple 'N', because (as I said) + +if (fmt_new && fmt_new != argv[0] && fmt_new != fmt_default) +av_freep(_new); + does not free fmt if it is already allocated. It is possible to fix this by adding an char *fmt_allocated = NULL; at outer scope and a fmt_new in the block that is executed if a 'N' is executed. (You have to free fmt_allocated immediately after av_asprintf().) But maybe it would be best to use an AVBPrint to write the new string instead of allocating a new string for every %N encountered. v11 does it that way. Thanks, ThiloFrom 1831153a5309502414c8639d1364930b305dd5dd Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Tue, 8 Feb 2022 10:15:13 +0100 Subject: [PATCH v11] lavfi/drawtext: Add %N for drawing fractions of a second Suggested-By: ffm...@fb.com --- doc/filters.texi | 4 +++ libavfilter/vf_drawtext.c | 67 +-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 05d4b1a56e..c3895138e0 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -11378,10 +11378,14 @@ It can be used to add padding with zeros from the left. @item gmtime The time at which the filter is running, expressed in UTC. It can accept an argument: a strftime() format string. +The format string is extended to support the variable @var{%[1-6]N} +which prints fractions of the second with optionally specified number of digits. @item localtime The time at which the filter is running, expressed in the local time zone. It can accept an argument: a strftime() format string. +The format string is extended to support the variable @var{%[1-6]N} +which prints fractions of the second with optionally specified number of digits. @item metadata Frame metadata. Takes one or two arguments. diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 2a88692cbd..75ce97a2a6 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -51,6 +51,7 @@ #include "libavutil/opt.h" #include "libavutil/random_seed.h" #include "libavutil/parseutils.h" +#include "libavutil/time.h" #include "libavutil/timecode.h" #include "libavutil/time_internal.h" #include "libavutil/tree.h" @@ -1045,15 +1046,77 @@ static int func_strftime(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { const char *fmt = argc ? argv[0] : "%Y-%m-%d %H:%M:%S"; +const char *fmt_begin = fmt; +int64_t unow; time_t now; struct tm tm; +const char *begin; +const char *tmp; +int len; +int div; +AVBPrint fmt_bp; -time(); -if (tag == 'L') +av_bprint_init(_bp, 0, AV_BPRINT_SIZE_UNLIMITED); + +unow = av_gettime(); +now = unow / 100; +if (tag == 'L' || tag == 'm') localtime_r(, ); else tm = *gmtime_r(, ); + +// manually parse format for %N (fractional seconds) +begin = fmt; +while ((begin = strchr(begin, '%'))) { +tmp = begin + 1; +len = 0; + +// skip escaped "%%" +if (*tmp == '%') { +begin = tmp + 1; +continue; +} + +// count digits between % and possible N +while (*tmp != '\0' && av_isdigit((int)*tmp)) { +len++; +tmp++; +} + +// N encountered, insert time +if (*tmp == 'N') { +int num_digits = 3; // default show millisecond [1,6] + +// if digit given, expect [1,6], warn & clamp otherwise +if (len == 1) { +num_digits = av_clip(*(begin + 1) - '0', 1, 6); +} else if (len > 1) { +av_log(ctx, AV_LOG_WARNING, "Invalid number of decimals for %%N, using default of %i\n", num_digits); +} + +len += 2; // add % and N to get length of string part + +div = pow(10, 6 - num_digits); + +av_bprintf(_bp, "%.*s%0*d", (int)(begin - fmt_begin), fmt_begin, num_digits, (int)(unow % 100) / div); + +begin += len; +fmt_begin = begin; + +continue; +} + +begin = tmp; +} + +av_bprintf(_bp, "%s", fmt_begin); +av_bprint_finalize(_bp, (char**)); +if (!fmt) +return AVERROR(ENOMEM); + av_bprint_strftime(bp, fmt, ); +av_freep(); + return 0; } -- 2.20.1 (Apple Git-117) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To