Re: [FFmpeg-devel] [PATCH 12/13] avcodec/omx: Check initializing mutexes/conditions
On Thu, 2 Sep 2021, Andreas Rheinhardt wrote: The earlier code did not properly check these initializations: It only recorded whether the part of init where these initializations are has been reached, but it did not check whether the initializations were successful, although destroying them would be undefined behaviour if they had not been initialized successfully. Furthermore cleanup() always locked a mutex regardless of whether there was any attempt to initialize these mutexes at all. Signed-off-by: Andreas Rheinhardt --- This is mostly untested: I only tested whether it compiles. libavcodec/omx.c | 34 +- 1 file changed, 17 insertions(+), 17 deletions(-) Seems to work in very brief testing, so ok with me. // Martin ___ 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 11/13] avcodec/frame_thread_encoder: Mark init and free functions as av_cold
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] fate/wma: Account for trimmed samples in wmapro-ism test
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 10/10] lavfi/vf_scale: pass the thread count to the scaler
On Wed, Sep 01, 2021 at 10:26:25AM +0200, Anton Khirnov wrote: > Quoting Michael Niedermayer (2021-08-30 14:34:30) > > On Mon, Aug 30, 2021 at 11:38:53AM +0200, Michael Niedermayer wrote: > > > > I am not familiar with the generic scaler code, but it seems independent > > > > of this partitioning, otherwise the threaded scaling tests would fail. > > > > > > the generic scaler simply stores the data originating from the previous > > > slice > > > (generally after the horizontal scaler) > > > > > > the 410->420 one probably should > > > * store the one chroma line too somewhere > > > * initialize it to the first image line > > > * simplify all the 410->420 code so it always uses a pointer to the > > > previous > > > line either from the buffer or if available straight from the input > > > image > > > > > > It seems not worth for just 410->420, and i agree but the same could > > > be used for 420->444 and others which would have the same problem if one > > > wanted to do higher quality chroma interpolation in the unscaled special > > > converters > > > > Just to clarify, this is meant as a path forward for the bug with chroma > > interpolation in the special converters which do or might want to use > > chroma interpolation. > > Its not a review comment to the patchset(s) > > Right, that's how I understood this. > > Are you still looking at the patchset or shall I go ahead with pushing > it to master? ive posted some comments and tested it, i didnt see any issues beyond what was in my 2 replies thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Its not that you shouldnt use gotos but rather that you should write readable code and code with gotos often but not always is less readable 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".
[FFmpeg-devel] [PATCH] fate/wma: Account for trimmed samples in wmapro-ism test
Fixes FATE failures after 61c2c9ef8e66920c8ba308e8fa9f36ae602f8245. Signed-off-by: Andreas Rheinhardt --- tests/fate/wma.mak | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fate/wma.mak b/tests/fate/wma.mak index 12a8fa989a..bc530998e8 100644 --- a/tests/fate/wma.mak +++ b/tests/fate/wma.mak @@ -11,6 +11,7 @@ fate-wmapro-5.1: SIZE_TOLERANCE = 24576 FATE_WMAPRO-$(call DEMDEC, MOV, WMAPRO) += fate-wmapro-ism fate-wmapro-ism: CMD = pcm -i $(TARGET_SAMPLES)/isom/vc1-wmapro.ism -vn fate-wmapro-ism: REF = $(SAMPLES)/isom/vc1-wmapro.pcm +fate-wmapro-ism: SIZE_TOLERANCE = 4784 $(FATE_WMAPRO-yes): CMP = oneoff -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avcodec/libvpxenc: Apply codec options to alpha codec context
Hi, On Thu, Sep 2, 2021 at 3:08 AM Adam Chelminski wrote: > > When encoding yuva420 (alpha) frames, the vpx encoder uses a second > vpx_codec_ctx to encode the alpha stream. However, codec options were > only being applied to the primary encoder. This patch updates > codecctl_int and codecctl_intp to also apply codec options to the alpha > codec context when encoding frames with alpha. > > This is necessary to take advantage of libvpx speed optimization options > such as 'row-mt', 'cpu-used', and 'deadline' when encoding videos with deadline is passed to the encode call in libvpx, but the others are correct. > alpha. Without this patch, the speed optimizations are only applied to > the primary stream encoding, and the overall encoding is just as slow as > it would be without the options specified. > > Signed-off-by: Adam Chelminski > --- > libavcodec/libvpxenc.c | 26 -- > 1 file changed, 24 insertions(+), 2 deletions(-) > Thanks for the patch. This should bump the micro version in libavcodec/version.h for the behavior change. > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > index 0e50fbfd7c..1df0a8343c 100644 > --- a/libavcodec/libvpxenc.c > +++ b/libavcodec/libvpxenc.c > @@ -385,9 +385,20 @@ static av_cold int codecctl_int(AVCodecContext *avctx, > snprintf(buf, sizeof(buf), "Failed to set %s codec control", > ctlidstr[id]); > log_encoder_error(avctx, buf); > +return AVERROR(EINVAL); > } > > -return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); > +if (ctx->is_alpha) { > +int res_alpha = vpx_codec_control(>encoder_alpha, id, val); > +if (res_alpha != VPX_CODEC_OK) { > +snprintf(buf, sizeof(buf), "Failed to set %s alpha codec > control", > +ctlidstr[id]); indent is off. > +log_encoder_error(avctx, buf); > +return AVERROR(EINVAL); > +} > +} > + > +return 0; > } > > #if VPX_ENCODER_ABI_VERSION >= 12 > @@ -407,9 +418,20 @@ static av_cold int codecctl_intp(AVCodecContext *avctx, > snprintf(buf, sizeof(buf), "Failed to set %s codec control", > ctlidstr[id]); > log_encoder_error(avctx, buf); > +return AVERROR(EINVAL); > } > > -return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); > +if (ctx->is_alpha) { > +int res_alpha = vpx_codec_control(>encoder_alpha, id, val); > +if (res_alpha != VPX_CODEC_OK) { > +snprintf(buf, sizeof(buf), "Failed to set %s alpha codec > control", > +ctlidstr[id]); here too. > +log_encoder_error(avctx, buf); > +return AVERROR(EINVAL); > +} > +} > + > +return 0; > } > #endif > > -- > 2.25.1 > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel 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 05/13] avcodec/vp9: Use av_freep() instead of av_free()
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 v2] lavfi: add nlmeans CUDA filter
On 02.09.2021 15:32, Timo Rothenpieler wrote: On 02.09.2021 19:50, Dylan Fernando wrote: I want to add support for the other formats, but I'm not sure how to find video files to test it out. I tried looking through https://samples.ffmpeg.org/, but I'm not sure which files on there are the formats im looking for (AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_P010, AV_PIX_FMT_P016, AV_PIX_FMT_YUV444P16). Just slap a format_cuda filter in front and convert to the desired format. For RGB formats, which it doesn't support right now, just use format,hwupload_cuda. sorry, scale_cuda or format+hwupload smime.p7s Description: S/MIME Cryptographic 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 1/2] avcodec/pictordec: Optimize more odd cases for picmemset()
On Wed, Sep 01, 2021 at 09:50:20AM +1000, Peter Ross wrote: > On Tue, Aug 31, 2021 at 08:33:41PM +0200, Michael Niedermayer wrote: > > Fixes: Timeout > > Fixes: > > 36875/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PICTOR_fuzzer-4842960888922112 > > > > Found-by: continuous fuzzing process > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > > Signed-off-by: Michael Niedermayer > > --- > > libavcodec/pictordec.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/libavcodec/pictordec.c b/libavcodec/pictordec.c > > index c37c5e7106..c7b3a335d3 100644 > > --- a/libavcodec/pictordec.c > > +++ b/libavcodec/pictordec.c > > @@ -89,8 +89,7 @@ static void picmemset(PicContext *s, AVFrame *frame, > > unsigned value, int run, > > d = frame->data[0] + yl * frame->linesize[0]; > > if (s->nb_planes == 1 && > > run*pixels_per_value >= s->width && > > -pixels_per_value < s->width && > > -s->width % pixels_per_value == 0 > > +pixels_per_value < (s->width / pixels_per_value * > > pixels_per_value) > > ) { > > for (; xl < pixels_per_value; xl ++) { > > j = (j < bits_per_plane ? 8 : j) - bits_per_plane; > > @@ -98,7 +97,7 @@ static void picmemset(PicContext *s, AVFrame *frame, > > unsigned value, int run, > > } > > av_memcpy_backptr(d+xl, pixels_per_value, s->width - > > xl); > > run -= s->width / pixels_per_value; > > -xl = s->width; > > +xl = s->width / pixels_per_value * pixels_per_value; > > } > > } > > } > > -- > > 2.17.1 > > i have tested this against variety of samples. please apply. will apply thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Good people do not need laws to tell them to act responsibly, while bad people will find a way around the laws. -- Plato 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".
[FFmpeg-devel] [PATCH 11/13] avcodec/frame_thread_encoder: Mark init and free functions as av_cold
Signed-off-by: Andreas Rheinhardt --- libavcodec/frame_thread_encoder.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index e9a5a146ca..d4f86f7418 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -130,7 +130,7 @@ end: return NULL; } -int ff_frame_thread_encoder_init(AVCodecContext *avctx) +av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx) { int i=0; ThreadContext *c; @@ -253,7 +253,8 @@ fail: return ret; } -void ff_frame_thread_encoder_free(AVCodecContext *avctx){ +av_cold void ff_frame_thread_encoder_free(AVCodecContext *avctx) +{ ThreadContext *c= avctx->internal->frame_thread_encoder; /* In case initializing the mutexes/condition variables failed, -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 06/13] avcodec/vp9: Remove vp9_free_entries()
Now that the mutexes and conditions are only initialized and destroyed once, said function only had one purpose: free the entries array. Given that vp9_alloc_entries() already does this if the array is already allocated it is unnecessary to call vp9_free_entries() anywhere except when closing. And then one can just inline the one free into vp9_decode_free(). Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 12 +--- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 8bdcb86625..c1b58d4752 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -45,14 +45,6 @@ DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt, (offsetof(VP9Context, progress_mutex)), (offsetof(VP9Context, progress_cond))); -static void vp9_free_entries(AVCodecContext *avctx) { -VP9Context *s = avctx->priv_data; - -if (avctx->active_thread_type & FF_THREAD_SLICE) { -av_freep(>entries); -} -} - static int vp9_alloc_entries(AVCodecContext *avctx, int n) { VP9Context *s = avctx->priv_data; int i; @@ -88,7 +80,6 @@ static void vp9_await_tile_progress(VP9Context *s, int field, int n) { pthread_mutex_unlock(>progress_mutex); } #else -static void vp9_free_entries(AVCodecContext *avctx) {} static int vp9_alloc_entries(AVCodecContext *avctx, int n) { return 0; } #endif @@ -794,7 +785,6 @@ static int decode_frame_header(AVCodecContext *avctx, } s->s.h.tiling.tile_cols = 1 << s->s.h.tiling.log2_tile_cols; -vp9_free_entries(avctx); s->active_tile_cols = avctx->active_thread_type == FF_THREAD_SLICE ? s->s.h.tiling.tile_cols : 1; vp9_alloc_entries(avctx, s->sb_rows); @@ -1249,8 +1239,8 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) } free_buffers(s); -vp9_free_entries(avctx); #if HAVE_THREADS +av_freep(>entries); ff_pthread_free(s, vp9_context_offsets); #endif av_freep(>td); -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 10/13] avcodec/frame_thread_encoder: Return proper error codes
Signed-off-by: Andreas Rheinhardt --- libavcodec/frame_thread_encoder.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 219d65cce7..e9a5a146ca 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -202,15 +202,19 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx) c->max_tasks = avctx->thread_count + 2; for (unsigned j = 0; j < c->max_tasks; j++) { if (!(c->tasks[j].indata = av_frame_alloc()) || -!(c->tasks[j].outdata = av_packet_alloc())) +!(c->tasks[j].outdata = av_packet_alloc())) { +ret = AVERROR(ENOMEM); goto fail; +} } for(i=0; ithread_count ; i++){ void *tmpv; thread_avctx = avcodec_alloc_context3(avctx->codec); -if(!thread_avctx) +if (!thread_avctx) { +ret = AVERROR(ENOMEM); goto fail; +} tmpv = thread_avctx->priv_data; *thread_avctx = *avctx; thread_avctx->priv_data = tmpv; @@ -227,11 +231,12 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx) thread_avctx->thread_count = 1; thread_avctx->active_thread_type &= ~FF_THREAD_FRAME; -if (avcodec_open2(thread_avctx, avctx->codec, NULL) < 0) +if ((ret = avcodec_open2(thread_avctx, avctx->codec, NULL)) < 0) goto fail; av_assert0(!thread_avctx->internal->frame_thread_encoder); thread_avctx->internal->frame_thread_encoder = c; -if(pthread_create(>worker[i], NULL, worker, thread_avctx)) { +if ((ret = pthread_create(>worker[i], NULL, worker, thread_avctx))) { +ret = AVERROR(ret); goto fail; } } @@ -245,7 +250,7 @@ fail: avctx->thread_count = i; av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n"); ff_frame_thread_encoder_free(avctx); -return -1; +return ret; } void ff_frame_thread_encoder_free(AVCodecContext *avctx){ -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 09/13] avcodec/frame_thread_encoder: Don't shadow variables
Signed-off-by: Andreas Rheinhardt --- libavcodec/frame_thread_encoder.c | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 8f8294374f..219d65cce7 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -200,14 +200,13 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx) atomic_init(>exit, 0); c->max_tasks = avctx->thread_count + 2; -for (unsigned i = 0; i < c->max_tasks; i++) { -if (!(c->tasks[i].indata = av_frame_alloc()) || -!(c->tasks[i].outdata = av_packet_alloc())) +for (unsigned j = 0; j < c->max_tasks; j++) { +if (!(c->tasks[j].indata = av_frame_alloc()) || +!(c->tasks[j].outdata = av_packet_alloc())) goto fail; } for(i=0; ithread_count ; i++){ -int ret; void *tmpv; thread_avctx = avcodec_alloc_context3(avctx->codec); if(!thread_avctx) @@ -221,7 +220,7 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx) if (ret < 0) goto fail; if (avctx->codec->priv_class) { -int ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data); +ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data); if (ret < 0) goto fail; } -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 08/13] avcodec/frame_thread_encoder: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt --- libavcodec/frame_thread_encoder.c | 14 ++ 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index e5f6544750..8f8294374f 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -250,21 +250,19 @@ fail: } void ff_frame_thread_encoder_free(AVCodecContext *avctx){ -int i; ThreadContext *c= avctx->internal->frame_thread_encoder; /* In case initializing the mutexes/condition variables failed, * they must not be used. In this case the thread_count is zero * as no thread has been initialized yet. */ if (avctx->thread_count > 0) { -pthread_mutex_lock(>task_fifo_mutex); -atomic_store(>exit, 1); -pthread_cond_broadcast(>task_fifo_cond); -pthread_mutex_unlock(>task_fifo_mutex); +pthread_mutex_lock(>task_fifo_mutex); +atomic_store(>exit, 1); +pthread_cond_broadcast(>task_fifo_cond); +pthread_mutex_unlock(>task_fifo_mutex); -for (i=0; ithread_count; i++) { - pthread_join(c->worker[i], NULL); -} +for (int i = 0; i < avctx->thread_count; i++) +pthread_join(c->worker[i], NULL); } for (unsigned i = 0; i < c->max_tasks; i++) { -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 04/13] avcodec/vp9: Don't free buffer known to be NULL
Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 239475cdbe..8eb57eb8e6 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -62,11 +62,8 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) { av_freep(>entries); s->entries = av_malloc_array(n, sizeof(atomic_int)); - -if (!s->entries) { -av_freep(>entries); +if (!s->entries) return AVERROR(ENOMEM); -} for (i = 0; i < n; i++) atomic_init(>entries[i], 0); -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 07/13] avcodec/frame_thread_encoder: Check initializing mutexes/conditions
Signed-off-by: Andreas Rheinhardt --- libavcodec/frame_thread_encoder.c | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 9bc48c7761..e5f6544750 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -29,6 +29,7 @@ #include "libavutil/thread.h" #include "avcodec.h" #include "internal.h" +#include "pthread_internal.h" #include "thread.h" #define MAX_THREADS 64 @@ -52,6 +53,7 @@ typedef struct{ pthread_mutex_t task_fifo_mutex; /* Used to guard (next_)task_index */ pthread_cond_t task_fifo_cond; +unsigned pthread_init_cnt; unsigned max_tasks; Task tasks[BUFFER_SIZE]; pthread_mutex_t finished_task_mutex; /* Guards tasks[i].finished */ @@ -65,6 +67,12 @@ typedef struct{ atomic_int exit; } ThreadContext; +#define OFF(member) offsetof(ThreadContext, member) +DEFINE_OFFSET_ARRAY(ThreadContext, thread_ctx, pthread_init_cnt, +(OFF(buffer_mutex), OFF(task_fifo_mutex), OFF(finished_task_mutex)), +(OFF(task_fifo_cond), OFF(finished_task_cond))); +#undef OFF + static void * attribute_align_arg worker(void *v){ AVCodecContext *avctx = v; ThreadContext *c = avctx->internal->frame_thread_encoder; @@ -127,6 +135,7 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx) int i=0; ThreadContext *c; AVCodecContext *thread_avctx = NULL; +int ret; if( !(avctx->thread_type & FF_THREAD_FRAME) || !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)) @@ -185,11 +194,9 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx) c->parent_avctx = avctx; -pthread_mutex_init(>task_fifo_mutex, NULL); -pthread_mutex_init(>finished_task_mutex, NULL); -pthread_mutex_init(>buffer_mutex, NULL); -pthread_cond_init(>task_fifo_cond, NULL); -pthread_cond_init(>finished_task_cond, NULL); +ret = ff_pthread_init(c, thread_ctx_offsets); +if (ret < 0) +goto fail; atomic_init(>exit, 0); c->max_tasks = avctx->thread_count + 2; @@ -246,6 +253,10 @@ void ff_frame_thread_encoder_free(AVCodecContext *avctx){ int i; ThreadContext *c= avctx->internal->frame_thread_encoder; +/* In case initializing the mutexes/condition variables failed, + * they must not be used. In this case the thread_count is zero + * as no thread has been initialized yet. */ +if (avctx->thread_count > 0) { pthread_mutex_lock(>task_fifo_mutex); atomic_store(>exit, 1); pthread_cond_broadcast(>task_fifo_cond); @@ -254,17 +265,14 @@ void ff_frame_thread_encoder_free(AVCodecContext *avctx){ for (i=0; ithread_count; i++) { pthread_join(c->worker[i], NULL); } +} for (unsigned i = 0; i < c->max_tasks; i++) { av_frame_free(>tasks[i].indata); av_packet_free(>tasks[i].outdata); } -pthread_mutex_destroy(>task_fifo_mutex); -pthread_mutex_destroy(>finished_task_mutex); -pthread_mutex_destroy(>buffer_mutex); -pthread_cond_destroy(>task_fifo_cond); -pthread_cond_destroy(>finished_task_cond); +ff_pthread_free(c, thread_ctx_offsets); av_freep(>internal->frame_thread_encoder); } -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 05/13] avcodec/vp9: Use av_freep() instead of av_free()
Otherwise the context would be in an inconsistent state if vp9_alloc_entries() failed (and if this would be checked). Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 8eb57eb8e6..8bdcb86625 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -790,7 +790,7 @@ static int decode_frame_header(AVCodecContext *avctx, if (s->td) { for (i = 0; i < s->active_tile_cols; i++) vp9_tile_data_free(>td[i]); -av_free(s->td); +av_freep(>td); } s->s.h.tiling.tile_cols = 1 << s->s.h.tiling.log2_tile_cols; -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 13/13] avcodec/omx: Reindentation
Signed-off-by: Andreas Rheinhardt --- libavcodec/omx.c | 62 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/libavcodec/omx.c b/libavcodec/omx.c index 7086ddd3a4..4078ac84a4 100644 --- a/libavcodec/omx.c +++ b/libavcodec/omx.c @@ -596,45 +596,45 @@ static av_cold int omx_component_init(AVCodecContext *avctx, const char *role) static av_cold void cleanup(OMXCodecContext *s) { -int i, executing; +int executing; /* If the mutexes/condition variables have not been properly initialized, * nothing has been initialized and locking the mutex might be unsafe. */ if (s->mutex_cond_inited_cnt == NB_MUTEX_CONDS) { -pthread_mutex_lock(>state_mutex); -executing = s->state == OMX_StateExecuting; -pthread_mutex_unlock(>state_mutex); +pthread_mutex_lock(>state_mutex); +executing = s->state == OMX_StateExecuting; +pthread_mutex_unlock(>state_mutex); -if (executing) { -OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateIdle, NULL); -wait_for_state(s, OMX_StateIdle); -OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL); -for (i = 0; i < s->num_in_buffers; i++) { -OMX_BUFFERHEADERTYPE *buffer = get_buffer(>input_mutex, >input_cond, - >num_free_in_buffers, s->free_in_buffers, 1); -if (s->input_zerocopy) -buffer->pBuffer = NULL; -OMX_FreeBuffer(s->handle, s->in_port, buffer); +if (executing) { +OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateIdle, NULL); +wait_for_state(s, OMX_StateIdle); +OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL); +for (int i = 0; i < s->num_in_buffers; i++) { +OMX_BUFFERHEADERTYPE *buffer = get_buffer(>input_mutex, >input_cond, + >num_free_in_buffers, s->free_in_buffers, 1); +if (s->input_zerocopy) +buffer->pBuffer = NULL; +OMX_FreeBuffer(s->handle, s->in_port, buffer); +} +for (int i = 0; i < s->num_out_buffers; i++) { +OMX_BUFFERHEADERTYPE *buffer = get_buffer(>output_mutex, >output_cond, + >num_done_out_buffers, s->done_out_buffers, 1); +OMX_FreeBuffer(s->handle, s->out_port, buffer); +} +wait_for_state(s, OMX_StateLoaded); } -for (i = 0; i < s->num_out_buffers; i++) { -OMX_BUFFERHEADERTYPE *buffer = get_buffer(>output_mutex, >output_cond, - >num_done_out_buffers, s->done_out_buffers, 1); -OMX_FreeBuffer(s->handle, s->out_port, buffer); +if (s->handle) { +s->omx_context->ptr_FreeHandle(s->handle); +s->handle = NULL; } -wait_for_state(s, OMX_StateLoaded); -} -if (s->handle) { -s->omx_context->ptr_FreeHandle(s->handle); -s->handle = NULL; -} -omx_deinit(s->omx_context); -s->omx_context = NULL; -av_freep(>in_buffer_headers); -av_freep(>out_buffer_headers); -av_freep(>free_in_buffers); -av_freep(>done_out_buffers); -av_freep(>output_buf); +omx_deinit(s->omx_context); +s->omx_context = NULL; +av_freep(>in_buffer_headers); +av_freep(>out_buffer_headers); +av_freep(>free_in_buffers); +av_freep(>done_out_buffers); +av_freep(>output_buf); } ff_pthread_free(s, omx_codec_context_offsets); } -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 12/13] avcodec/omx: Check initializing mutexes/conditions
The earlier code did not properly check these initializations: It only recorded whether the part of init where these initializations are has been reached, but it did not check whether the initializations were successful, although destroying them would be undefined behaviour if they had not been initialized successfully. Furthermore cleanup() always locked a mutex regardless of whether there was any attempt to initialize these mutexes at all. Signed-off-by: Andreas Rheinhardt --- This is mostly untested: I only tested whether it compiles. libavcodec/omx.c | 34 +- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libavcodec/omx.c b/libavcodec/omx.c index 9597c60057..7086ddd3a4 100644 --- a/libavcodec/omx.c +++ b/libavcodec/omx.c @@ -43,6 +43,7 @@ #include "avcodec.h" #include "h264.h" #include "internal.h" +#include "pthread_internal.h" #ifdef OMX_SKIP64BIT static OMX_TICKS to_omx_ticks(int64_t value) @@ -218,7 +219,7 @@ typedef struct OMXCodecContext { OMX_STATETYPE state; OMX_ERRORTYPE error; -int mutex_cond_inited; +unsigned mutex_cond_inited_cnt; int eos_sent, got_eos; @@ -229,6 +230,12 @@ typedef struct OMXCodecContext { int profile; } OMXCodecContext; +#define NB_MUTEX_CONDS 6 +#define OFF(field) offsetof(OMXCodecContext, field) +DEFINE_OFFSET_ARRAY(OMXCodecContext, omx_codec_context, mutex_cond_inited_cnt, +(OFF(input_mutex), OFF(output_mutex), OFF(state_mutex)), +(OFF(input_cond), OFF(output_cond), OFF(state_cond))); + static void append_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond, int* array_size, OMX_BUFFERHEADERTYPE **array, OMX_BUFFERHEADERTYPE *buffer) @@ -591,6 +598,9 @@ static av_cold void cleanup(OMXCodecContext *s) { int i, executing; +/* If the mutexes/condition variables have not been properly initialized, + * nothing has been initialized and locking the mutex might be unsafe. */ +if (s->mutex_cond_inited_cnt == NB_MUTEX_CONDS) { pthread_mutex_lock(>state_mutex); executing = s->state == OMX_StateExecuting; pthread_mutex_unlock(>state_mutex); @@ -620,20 +630,13 @@ static av_cold void cleanup(OMXCodecContext *s) omx_deinit(s->omx_context); s->omx_context = NULL; -if (s->mutex_cond_inited) { -pthread_cond_destroy(>state_cond); -pthread_mutex_destroy(>state_mutex); -pthread_cond_destroy(>input_cond); -pthread_mutex_destroy(>input_mutex); -pthread_cond_destroy(>output_cond); -pthread_mutex_destroy(>output_mutex); -s->mutex_cond_inited = 0; -} av_freep(>in_buffer_headers); av_freep(>out_buffer_headers); av_freep(>free_in_buffers); av_freep(>done_out_buffers); av_freep(>output_buf); +} +ff_pthread_free(s, omx_codec_context_offsets); } static av_cold int omx_encode_init(AVCodecContext *avctx) @@ -644,17 +647,14 @@ static av_cold int omx_encode_init(AVCodecContext *avctx) OMX_BUFFERHEADERTYPE *buffer; OMX_ERRORTYPE err; +/* cleanup relies on the mutexes/conditions being initialized first. */ +ret = ff_pthread_init(s, omx_codec_context_offsets); +if (ret < 0) +return ret; s->omx_context = omx_init(avctx, s->libname, s->libprefix); if (!s->omx_context) return AVERROR_ENCODER_NOT_FOUND; -pthread_mutex_init(>state_mutex, NULL); -pthread_cond_init(>state_cond, NULL); -pthread_mutex_init(>input_mutex, NULL); -pthread_cond_init(>input_cond, NULL); -pthread_mutex_init(>output_mutex, NULL); -pthread_cond_init(>output_cond, NULL); -s->mutex_cond_inited = 1; s->avctx = avctx; s->state = OMX_StateLoaded; s->error = OMX_ErrorNone; -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 03/13] avcodec/vp9: Check initializing conditions/mutexes
Also don't destroy uninitialized conditions/mutexes. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c| 17 +++-- libavcodec/vp9dec.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 5c20a7ec5d..239475cdbe 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -27,6 +27,8 @@ #include "internal.h" #include "profiles.h" #include "thread.h" +#include "pthread_internal.h" + #include "videodsp.h" #include "vp56.h" #include "vp9.h" @@ -39,6 +41,10 @@ #define VP9_SYNCCODE 0x498342 #if HAVE_THREADS +DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt, +(offsetof(VP9Context, progress_mutex)), +(offsetof(VP9Context, progress_cond))); + static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; @@ -1248,10 +1254,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) free_buffers(s); vp9_free_entries(avctx); #if HAVE_THREADS -if (avctx->active_thread_type & FF_THREAD_SLICE) { -pthread_mutex_destroy(>progress_mutex); -pthread_cond_destroy(>progress_cond); -} +ff_pthread_free(s, vp9_context_offsets); #endif av_freep(>td); return 0; @@ -1794,14 +1797,16 @@ static void vp9_decode_flush(AVCodecContext *avctx) static av_cold int vp9_decode_init(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; +int ret; s->last_bpp = 0; s->s.h.filter.sharpness = -1; #if HAVE_THREADS if (avctx->active_thread_type & FF_THREAD_SLICE) { -pthread_mutex_init(>progress_mutex, NULL); -pthread_cond_init(>progress_cond, NULL); +ret = ff_pthread_init(s, vp9_context_offsets); +if (ret < 0) +return ret; } #endif diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h index d82b258a3d..9cbd5839a8 100644 --- a/libavcodec/vp9dec.h +++ b/libavcodec/vp9dec.h @@ -105,6 +105,7 @@ typedef struct VP9Context { pthread_mutex_t progress_mutex; pthread_cond_t progress_cond; atomic_int *entries; +unsigned pthread_init_cnt; #endif uint8_t ss_h, ss_v; -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 02/13] avcodec/pthread_frame: Move (init|free)_pthread() to pthread.c
We have more mutexes/condition variables whose initialization is unchecked. Also use a proper namespace for these functions. Signed-off-by: Andreas Rheinhardt --- libavcodec/pthread.c | 38 libavcodec/pthread_frame.c| 55 +-- libavcodec/pthread_internal.h | 32 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 14b7cca4fe..e7bad19f8b 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -29,6 +29,8 @@ * @see doc/multithreading.txt */ +#include "libavutil/thread.h" + #include "avcodec.h" #include "internal.h" #include "pthread_internal.h" @@ -86,3 +88,39 @@ void ff_thread_free(AVCodecContext *avctx) else ff_slice_thread_free(avctx); } + +av_cold void ff_pthread_free(void *obj, const unsigned offsets[]) +{ +unsigned cnt = *(unsigned*)((char*)obj + offsets[0]); +const unsigned *cur_offset = offsets; + +*(unsigned*)((char*)obj + offsets[0]) = 0; + +for (; *(++cur_offset) != THREAD_SENTINEL && cnt; cnt--) +pthread_mutex_destroy((pthread_mutex_t*)((char*)obj + *cur_offset)); +for (; *(++cur_offset) != THREAD_SENTINEL && cnt; cnt--) +pthread_cond_destroy ((pthread_cond_t *)((char*)obj + *cur_offset)); +} + +av_cold int ff_pthread_init(void *obj, const unsigned offsets[]) +{ +const unsigned *cur_offset = offsets; +unsigned cnt = 0; +int err; + +#define PTHREAD_INIT_LOOP(type) \ +for (; *(++cur_offset) != THREAD_SENTINEL; cnt++) { \ +pthread_ ## type ## _t *dst = (void*)((char*)obj + *cur_offset); \ +err = pthread_ ## type ## _init(dst, NULL); \ +if (err) {\ +err = AVERROR(err); \ +goto fail;\ +} \ +} +PTHREAD_INIT_LOOP(mutex) +PTHREAD_INIT_LOOP(cond) + +fail: +*(unsigned*)((char*)obj + offsets[0]) = cnt; +return err; +} diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 8c0966f026..9c5d66c0d4 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -680,59 +680,18 @@ static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count async_lock(fctx); } -#define SENTINEL 0 // This forbids putting a mutex/condition variable at the front. -#define OFFSET_ARRAY(...) __VA_ARGS__, SENTINEL -#define DEFINE_OFFSET_ARRAY(type, name, mutexes, conds) \ -static const unsigned name ## _offsets[] = { offsetof(type, pthread_init_cnt),\ - OFFSET_ARRAY mutexes,\ - OFFSET_ARRAY conds } - #define OFF(member) offsetof(FrameThreadContext, member) -DEFINE_OFFSET_ARRAY(FrameThreadContext, thread_ctx, +DEFINE_OFFSET_ARRAY(FrameThreadContext, thread_ctx, pthread_init_cnt, (OFF(buffer_mutex), OFF(hwaccel_mutex), OFF(async_mutex)), (OFF(async_cond))); #undef OFF #define OFF(member) offsetof(PerThreadContext, member) -DEFINE_OFFSET_ARRAY(PerThreadContext, per_thread, +DEFINE_OFFSET_ARRAY(PerThreadContext, per_thread, pthread_init_cnt, (OFF(progress_mutex), OFF(mutex)), (OFF(input_cond), OFF(progress_cond), OFF(output_cond))); #undef OFF -static av_cold void free_pthread(void *obj, const unsigned offsets[]) -{ -unsigned cnt = *(unsigned*)((char*)obj + offsets[0]); -const unsigned *cur_offset = offsets; - -for (; *(++cur_offset) != SENTINEL && cnt; cnt--) -pthread_mutex_destroy((pthread_mutex_t*)((char*)obj + *cur_offset)); -for (; *(++cur_offset) != SENTINEL && cnt; cnt--) -pthread_cond_destroy ((pthread_cond_t *)((char*)obj + *cur_offset)); -} - -static av_cold int init_pthread(void *obj, const unsigned offsets[]) -{ -const unsigned *cur_offset = offsets; -unsigned cnt = 0; -int err; - -#define PTHREAD_INIT_LOOP(type) \ -for (; *(++cur_offset) != SENTINEL; cnt++) { \ -pthread_ ## type ## _t *dst = (void*)((char*)obj + *cur_offset); \ -err = pthread_ ## type ## _init(dst, NULL); \ -if (err) {\ -err = AVERROR(err); \ -goto fail;\ -} \ -} -PTHREAD_INIT_LOOP(mutex) -PTHREAD_INIT_LOOP(cond)
Re: [FFmpeg-devel] [PATCH] avforma: add an AV1 Low overhead bitstream format muxer
On 9/2/2021 3:53 AM, Hendrik Leppkes wrote: On Thu, Sep 2, 2021 at 12:54 AM James Almer wrote: On 8/27/2021 4:34 PM, James Almer wrote: Suggested-by: BBB Signed-off-by: James Almer --- Changelog | 1 + configure | 1 + doc/general_contents.texi | 1 + libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/rawenc.c | 20 libavformat/version.h | 4 ++-- 7 files changed, 27 insertions(+), 2 deletions(-) Will apply soon. Maybe you already fixed it, maybe not, but there is a typo in the commit message, avformat is missing a t. :) Yes, i had noticed and amended it locally, but thanks anyway :p ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions
Also do not destroy and reinitialize mutexes and conditions when certain input parameters change. Given that the decoder did not create these variables at all during init, uninitialized mutexes and conditions are destroyed before the very first initialization. This is undefined behaviour and certain threading implementations like pthreadGC2 crash when it is attempted. Fix this by initializing these objects once during init and freeing them in close. Reported-by: Steve Lhomme Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 18 +- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..5c20a7ec5d 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -43,8 +43,6 @@ static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; if (avctx->active_thread_type & FF_THREAD_SLICE) { -pthread_mutex_destroy(>progress_mutex); -pthread_cond_destroy(>progress_cond); av_freep(>entries); } } @@ -66,9 +64,6 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) { for (i = 0; i < n; i++) atomic_init(>entries[i], 0); - -pthread_mutex_init(>progress_mutex, NULL); -pthread_cond_init(>progress_cond, NULL); } return 0; } @@ -1252,6 +1247,12 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) free_buffers(s); vp9_free_entries(avctx); +#if HAVE_THREADS +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_destroy(>progress_mutex); +pthread_cond_destroy(>progress_cond); +} +#endif av_freep(>td); return 0; } @@ -1797,6 +1798,13 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +#if HAVE_THREADS +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_init(>progress_mutex, NULL); +pthread_cond_init(>progress_cond, NULL); +} +#endif + for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); if (!s->s.frames[i].tf.f) -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] sws: implement slice threading
On Sun, Aug 29, 2021 at 06:40:47PM +0200, Anton Khirnov wrote: > --- > Updated to conform to the slice alignment requirements > --- > libswscale/options.c | 3 ++ > libswscale/swscale.c | 59 + > libswscale/swscale_internal.h | 14 ++ > libswscale/utils.c| 82 +++ > 4 files changed, 158 insertions(+) > > diff --git a/libswscale/options.c b/libswscale/options.c > index 7eb2752543..4b71a23e37 100644 > --- a/libswscale/options.c > +++ b/libswscale/options.c > @@ -81,6 +81,9 @@ static const AVOption swscale_options[] = { > { "uniform_color", "blend onto a uniform color",0, > AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_UNIFORM},INT_MIN, INT_MAX, > VE, "alphablend" }, > { "checkerboard","blend onto a checkerboard", 0, > AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_CHECKERBOARD},INT_MIN, INT_MAX, > VE, "alphablend" }, > > +{ "threads", "number of threads", > OFFSET(nb_threads), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, INT_MAX, VE, "threads" > }, > +{ "auto",NULL,0, > AV_OPT_TYPE_CONST, {.i64 = 0 },.flags = VE, "threads" }, > + > { NULL } > }; > > diff --git a/libswscale/swscale.c b/libswscale/swscale.c > index ca5c612b18..c233818dcf 100644 > --- a/libswscale/swscale.c > +++ b/libswscale/swscale.c > @@ -1113,6 +1113,9 @@ int sws_send_slice(struct SwsContext *c, unsigned int > slice_start, > > unsigned int sws_receive_slice_alignment(const struct SwsContext *c) > { > +if (c->slice_ctx) > +return c->slice_ctx[0]->dst_slice_align; > + > return c->dst_slice_align; > } > > @@ -1136,6 +1139,27 @@ int sws_receive_slice(struct SwsContext *c, unsigned > int slice_start, > return AVERROR(EINVAL); > } > > +if (c->slicethread) { > +int nb_jobs = c->slice_ctx[0]->dither == SWS_DITHER_ED ? 1 : > c->nb_slice_ctx; This may merrit some sort of info/debug av_log() explaining why only 1 job is used so a user knows why scaling is slower [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The day soldiers stop bringing you their problems is the day you have stopped leading them. They have either lost confidence that you can help or concluded you do not care. Either case is a failure of leadership. - Colin Powell 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] sws: add a new scaling API
On Sun, Aug 29, 2021 at 06:38:58PM +0200, Anton Khirnov wrote: > --- > Now with a new public function to query required slice alignment, which > fixes the yuv410p->yuv420p conversion issue reported by Michael. {...] > +/** > + * Indicate that a horizontal slice of input data is available in the source > + * frame previously provided to sws_frame_start(). The slices may be > provided in > + * any order, but may not overlap. For vertically subsampled pixel formats, > the > + * slices must be aligned according to subsampling. > + * > + * @param slice_start first row of the slice > + * @param slice_height number of rows in the slice > + * > + * @return a non-negative number on success, a negative AVERROR code on > failure. > + */ > +int sws_send_slice(struct SwsContext *c, unsigned int slice_start, > + unsigned int slice_height); > + > +/** > + * Request a horizontal slice of the output data to be written into the frame > + * previously provided to sws_frame_start(). > + * > + * When a slice smaller than the whole output frame is requested, both > + * slice_start and slice_height must be multiples of > + * sws_receive_slice_alignment(). the image height might not be a multiple of sws_receive_slice_alignment() in that case the last slice would violate this rule > + * > + * @param slice_start first row of the slice > + * @param slice_height number of rows in the slice > + * > + * @return a non-negative number if the data was successfully written into > the output > + * AVERROR(EAGAIN) if more input data needs to be provided before the > + * output can be produced > + * another negative AVERROR code on other kinds of scaling failure > + */ > +int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, > + unsigned int slice_height); > + > +/** > + * Query required alignment on output data requested with > sws_receive_slice(). > + */ > +unsigned int sws_receive_slice_alignment(const struct SwsContext *c); I think this one line documentation taken alone is insufficient to understand this [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Nations do behave wisely once they have exhausted all other alternatives. -- Abba Eban 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 2/6] lavf/concat: add file_packet_meta directive
Andreas Rheinhardt (12021-08-31): > realloc is not supposed to transfer ownership, av_dict_set() with these > flags is. For me its behaviour makes sense (and avoids lots of av_free() > on failure paths). This is C, not Rust: ownership rules are in the eye of the beholder. The objective thing to say is: av_dict_set() with DONT_STRDUP destroys its argument in case of failure, realloc() does not. Anyway, the problem is fixed, let us not split hairs furthers on this, and thank you for spotting it. Regards, -- Nicolas George 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 12/12] tools/dvd2concat: generate VOBSUB extradata
Andreas Rheinhardt (12021-08-31): > Our VobSub demuxer does not set the duration (it is encoded as part of > the payload). So our muxer uses SimpleBlocks (because duration == 0 > actually says "play this until the next packet arrives", which coincides > with the semantics for SimpleBlocks). > mkvmerge reads the duration from the payload. > Is there a proper spec for the VobSub format somewhere? As far as I know, the best there is would be: https://www.matroska.org/technical/subtitles.html https://www.matroska.org/technical/codec_specs.html I vaguely remember that muxing Matroska from VobSub in FFmpeg failed because it did not set durations on the subtitles packets, but I do not remember what tool exactly refused to use the result. Now, it seems to work, which is the most we can ask for with a fringe format like that. Regards, -- Nicolas George 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 v2] lavfi: add nlmeans CUDA filter
On 02.09.2021 19:50, Dylan Fernando wrote: I want to add support for the other formats, but I'm not sure how to find video files to test it out. I tried looking through https://samples.ffmpeg.org/, but I'm not sure which files on there are the formats im looking for (AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_P010, AV_PIX_FMT_P016, AV_PIX_FMT_YUV444P16). Just slap a format_cuda filter in front and convert to the desired format. For RGB formats, which it doesn't support right now, just use format,hwupload_cuda. smime.p7s Description: S/MIME Cryptographic 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".
[FFmpeg-devel] [PATCH 4/4] avcodec/nvenc: Add constrainedFrame encoding support
From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/nvenc.c | 12 libavcodec/nvenc.h | 1 + libavcodec/nvenc_h264.c | 2 ++ libavcodec/nvenc_hevc.c | 2 ++ libavcodec/version.h| 2 +- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 79f3253..5eeb4fe 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -552,6 +552,12 @@ static int nvenc_check_capabilities(AVCodecContext *avctx) return AVERROR(ENOSYS); } +ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING); +if(ctx->constrained_encoding && ret <= 0) { +av_log(avctx, AV_LOG_WARNING, "constrained encoding not supported by the device\n"); +return AVERROR(ENOSYS); +} + ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE); return 0; @@ -1108,6 +1114,9 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) #endif } +if (ctx->constrained_encoding) +h264->enableConstrainedEncoding = 1; + h264->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0; h264->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1; h264->outputAUD = ctx->aud; @@ -1214,6 +1223,9 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) #endif } +if (ctx->constrained_encoding) +hevc->enableConstrainedEncoding = 1; + hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0; hevc->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1; hevc->outputAUD = ctx->aud; diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 1e756a6..950c2ab 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -233,6 +233,7 @@ typedef struct NvencContext int extra_sei; int intra_refresh; int single_slice_intra_refresh; +int constrained_encoding; } NvencContext; int ff_nvenc_encode_init(AVCodecContext *avctx); diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c index 1a46e70..ab7c67f 100644 --- a/libavcodec/nvenc_h264.c +++ b/libavcodec/nvenc_h264.c @@ -192,6 +192,8 @@ static const AVOption options[] = { OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { "single_slice_intra_refresh", "Use single slice intra refresh.", OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, +{ "constrained_encoding", "enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.", + OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { NULL } }; diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c index 8c89d6e..180e7a3 100644 --- a/libavcodec/nvenc_hevc.c +++ b/libavcodec/nvenc_hevc.c @@ -173,6 +173,8 @@ static const AVOption options[] = { OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { "single_slice_intra_refresh", "Use single slice intra refresh.", OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, +{ "constrained_encoding", "enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.", + OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { NULL } }; diff --git a/libavcodec/version.h b/libavcodec/version.h index d39329b..10f998e 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 59 #define LIBAVCODEC_VERSION_MINOR 6 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 1.8.3.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/mxf: rename sub_descriptors as file_descriptors
--- libavformat/mxfdec.c | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 34cbd2cd77..c28549f6a9 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -203,8 +203,8 @@ typedef struct MXFDescriptor { unsigned int color_range; unsigned int horiz_subsampling; unsigned int vert_subsampling; -UID *sub_descriptors_refs; -int sub_descriptors_count; +UID *file_descriptors_refs; +int file_descriptors_count; int linked_track_id; uint8_t *extradata; int extradata_size; @@ -342,7 +342,7 @@ static void mxf_free_metadataset(MXFMetadataSet **ctx, int freectx) av_freep(&((MXFDescriptor *)*ctx)->extradata); av_freep(&((MXFDescriptor *)*ctx)->mastering); av_freep(&((MXFDescriptor *)*ctx)->coll); -av_freep(&((MXFDescriptor *)*ctx)->sub_descriptors_refs); +av_freep(&((MXFDescriptor *)*ctx)->file_descriptors_refs); break; case Sequence: av_freep(&((MXFSequence *)*ctx)->structural_components_refs); @@ -1194,8 +1194,8 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int switch(tag) { case 0x3F01: -return mxf_read_strong_ref_array(pb, >sub_descriptors_refs, - >sub_descriptors_count); +return mxf_read_strong_ref_array(pb, >file_descriptors_refs, + >file_descriptors_count); case 0x3002: /* ContainerDuration */ descriptor->duration = avio_rb64(pb); break; @@ -2066,22 +2066,22 @@ static MXFPackage* mxf_resolve_source_package(MXFContext *mxf, UID package_ul, U static MXFDescriptor* mxf_resolve_multidescriptor(MXFContext *mxf, MXFDescriptor *descriptor, int track_id) { -MXFDescriptor *sub_descriptor = NULL; +MXFDescriptor *file_descriptor = NULL; int i; if (!descriptor) return NULL; if (descriptor->meta.type == MultipleDescriptor) { -for (i = 0; i < descriptor->sub_descriptors_count; i++) { -sub_descriptor = mxf_resolve_strong_ref(mxf, >sub_descriptors_refs[i], Descriptor); +for (i = 0; i < descriptor->file_descriptors_count; i++) { +file_descriptor = mxf_resolve_strong_ref(mxf, >file_descriptors_refs[i], Descriptor); -if (!sub_descriptor) { -av_log(mxf->fc, AV_LOG_ERROR, "could not resolve sub descriptor strong ref\n"); +if (!file_descriptor) { +av_log(mxf->fc, AV_LOG_ERROR, "could not resolve file descriptor strong ref\n"); continue; } -if (sub_descriptor->linked_track_id == track_id) { -return sub_descriptor; +if (file_descriptor->linked_track_id == track_id) { +return file_descriptor; } } } else if (descriptor->meta.type == Descriptor) -- 2.33.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/libvpxenc: Apply codec options to alpha codec context
When encoding yuva420 (alpha) frames, the vpx encoder uses a second vpx_codec_ctx to encode the alpha stream. However, codec options were only being applied to the primary encoder. This patch updates codecctl_int and codecctl_intp to also apply codec options to the alpha codec context when encoding frames with alpha. This is necessary to take advantage of libvpx speed optimization options such as 'row-mt', 'cpu-used', and 'deadline' when encoding videos with alpha. Without this patch, the speed optimizations are only applied to the primary stream encoding, and the overall encoding is just as slow as it would be without the options specified. Signed-off-by: Adam Chelminski --- libavcodec/libvpxenc.c | 26 -- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 0e50fbfd7c..1df0a8343c 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -385,9 +385,20 @@ static av_cold int codecctl_int(AVCodecContext *avctx, snprintf(buf, sizeof(buf), "Failed to set %s codec control", ctlidstr[id]); log_encoder_error(avctx, buf); +return AVERROR(EINVAL); } -return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); +if (ctx->is_alpha) { +int res_alpha = vpx_codec_control(>encoder_alpha, id, val); +if (res_alpha != VPX_CODEC_OK) { +snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control", +ctlidstr[id]); +log_encoder_error(avctx, buf); +return AVERROR(EINVAL); +} +} + +return 0; } #if VPX_ENCODER_ABI_VERSION >= 12 @@ -407,9 +418,20 @@ static av_cold int codecctl_intp(AVCodecContext *avctx, snprintf(buf, sizeof(buf), "Failed to set %s codec control", ctlidstr[id]); log_encoder_error(avctx, buf); +return AVERROR(EINVAL); } -return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); +if (ctx->is_alpha) { +int res_alpha = vpx_codec_control(>encoder_alpha, id, val); +if (res_alpha != VPX_CODEC_OK) { +snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control", +ctlidstr[id]); +log_encoder_error(avctx, buf); +return AVERROR(EINVAL); +} +} + +return 0; } #endif -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/mux: Fix double-free when using AVPacket.opaque_ref
Up until now, ff_write_chained() copied the packet (manually, not with av_packet_move_ref()) from a packet given to it to a stack packet whose timing and stream_index is then modified before being sent to another muxer via av_(interleaved_)write_frame(). Afterwards it is intended to sync the fields of the packet relevant to freeing again; yet this only encompasses buf, side_data and side_data_elems and not the newly added opaque_ref. The other fields are not synced so that the returned packet can have a size > 0 and data != NULL despite its buf being NULL (this always happens in the interleaved codepath; before commit fe251f77c80b0512ab8907902e1dbed3f4fe1aad it could also happen in the noninterleaved one). This leads to double-frees if the interleaved codepath is used and opaque_ref is set. This commit therefore changes this by directly reusing the packet instead of a spare packet. Given that av_write_frame() does not change the packet given to it, one only needs to restore the timing information to return it as it was; for the interleaved codepath it is not possible to do likewise*, because av_interleaved_write_frame() takes ownership of the packets given to it and returns blank packets. But precisely because of this users of the interleaved codepath have no legitimate expectation that their packet will be returned unchanged. In line with av_interleaved_write_frame() ff_write_chained() therefore returns blank packets when using the interleaved codepath. Making the only user of said codepath compatible with this was trivial. *: Unless one wanted to create a full new reference. Signed-off-by: Andreas Rheinhardt --- ff_write_chained() will be redundant when we allow muxers to convert timestamps internally (we can then make the slave muxer do the conversion). So I am not really worried about the case of adding a new timestamp-related field and forgetting to reset it in ff_write_chained(). libavformat/internal.h | 3 ++- libavformat/mux.c | 35 ++- libavformat/segment.c | 4 +++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 4fc1154b9d..9d7312c0e2 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -506,7 +506,8 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, * * @param dst the muxer to write the packet to * @param dst_stream the stream index within dst to write the packet to - * @param pkt the packet to be written + * @param pkt the packet to be written. It will be returned blank when + *av_interleaved_write_frame() is used, unchanged otherwise. * @param src the muxer the packet originally was intended for * @param interleave 0->use av_write_frame, 1->av_interleaved_write_frame * @return the value av_write_frame returned diff --git a/libavformat/mux.c b/libavformat/mux.c index b1ad0dd561..6ba1306f2b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -643,12 +643,12 @@ static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt) */ static int write_packet(AVFormatContext *s, AVPacket *pkt) { +AVStream *const st = s->streams[pkt->stream_index]; int ret; // If the timestamp offsetting below is adjusted, adjust // ff_interleaved_peek similarly. if (s->output_ts_offset) { -AVStream *st = s->streams[pkt->stream_index]; int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); if (pkt->dts != AV_NOPTS_VALUE) @@ -658,7 +658,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->avoid_negative_ts > 0) { -AVStream *st = s->streams[pkt->stream_index]; int64_t offset = st->internal->mux_ts_offset; int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; @@ -719,7 +718,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (ret >= 0) -s->streams[pkt->stream_index]->nb_frames++; +st->nb_frames++; return ret; } @@ -1192,6 +1191,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *in) pkt = in; } else { /* We don't own in, so we have to make sure not to modify it. + * (ff_write_chained() relies on this fact.) * The following avoids copying in's data unnecessarily. * Copying side data is unavoidable as a bitstream filter * may change it, e.g. free it on errors. */ @@ -1291,21 +1291,30 @@ int av_get_output_timestamp(struct AVFormatContext *s, int stream, int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, AVFormatContext *src, int interleave) { -AVPacket local_pkt; +int64_t pts = pkt->pts, dts = pkt->dts, duration = pkt->duration; +int stream_index = pkt->stream_index; +AVRational time_base = pkt->time_base; int ret; -local_pkt = *pkt; -local_pkt.stream_index = dst_stream;
Re: [FFmpeg-devel] [PATCH] avcodec/vp9: avoid using uninitialized mutex/condition
On 2021-09-02 11:27, Andreas Rheinhardt wrote: Steve Lhomme: When using slice decoding vp9_free_entries is called before vp9_alloc_entries is ever called. It should destroy properly initialized variables (or check it was never called before). It usually works undetected as pthread implementations allows NULL as a special value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow NULL in pthread_mutex_destroy() and crashes when that's the case. --- libavcodec/vp9.c | 4 1 file changed, 4 insertions(+) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..d40e90b70e 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_init(>progress_mutex, NULL); +pthread_cond_init(>progress_cond, NULL); +} for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); 1. progress_mutex and progress_cond don't exist if compiled without threading support, so your patch will lead to compilation failures in this case. Ah yes, I missed that the 2 functions are conditionally compiled. 2. I don't see a reason why these mutexes need to be initialized and destroyed when the dimensions/number of tile cols change at all. They should be initialized once during init (if slice threading is used) and freed during close (if they have been successfully initialized). Yes, it makes total sense. 3. Initializing this condition and mutex is currently not checked. I can fix this if you want. Sure. This is currently leading to a crash in VLC 3.0 because we use a pthread implementation that doesn't like this case (the only lib compatible with XP). https://code.videolan.org/videolan/vlc/-/issues/26017 ___ 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/vp9: avoid using uninitialized mutex/condition
Steve Lhomme: > When using slice decoding vp9_free_entries is called before vp9_alloc_entries > is ever called. It should destroy properly initialized variables (or check it > was never called before). > > It usually works undetected as pthread implementations allows NULL as a > special > value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow > NULL > in pthread_mutex_destroy() and crashes when that's the case. > --- > libavcodec/vp9.c | 4 > 1 file changed, 4 insertions(+) > > diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c > index 874005a5ae..d40e90b70e 100644 > --- a/libavcodec/vp9.c > +++ b/libavcodec/vp9.c > @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext > *avctx) > > s->last_bpp = 0; > s->s.h.filter.sharpness = -1; > +if (avctx->active_thread_type & FF_THREAD_SLICE) { > +pthread_mutex_init(>progress_mutex, NULL); > +pthread_cond_init(>progress_cond, NULL); > +} > > for (int i = 0; i < 3; i++) { > s->s.frames[i].tf.f = av_frame_alloc(); > 1. progress_mutex and progress_cond don't exist if compiled without threading support, so your patch will lead to compilation failures in this case. 2. I don't see a reason why these mutexes need to be initialized and destroyed when the dimensions/number of tile cols change at all. They should be initialized once during init (if slice threading is used) and freed during close (if they have been successfully initialized). 3. Initializing this condition and mutex is currently not checked. I can fix this if you want. - Andreas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v3] avcodec/vp9: avoid using uninitialized mutex/condition
When using slice decoding vp9_free_entries() is called before vp9_alloc_entries() is ever called. It should destroy properly initialized variables (or check it was never called before). It usually works undetected as pthread implementations allows NULL as a special value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow NULL in pthread_mutex_destroy() and crashes when that's the case. --- libavcodec/vp9.c | 4 1 file changed, 4 insertions(+) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..f4af90eaec 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_init(>progress_mutex, NULL); +pthread_cond_init(>progress_cond, NULL); +} for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2] avcodec/vp9: avoid using uninitialized mutex/condition
v2: shorter commit lines and removed an extra space, now I realize it's the wrong one, the original being also wrong... On 2021-09-02 11:19, Steve Lhomme wrote: When using slice decoding vp9_free_entries() is called before vp9_alloc_entries() is ever called. It should destroy properly initialized variables (or check it was never called before). It usually works undetected as pthread implementations allows NULL as a special value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow NULL in pthread_mutex_destroy() and crashes when that's the case. --- libavcodec/vp9.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..8a3d82da09 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -42,7 +42,7 @@ static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; -if (avctx->active_thread_type & FF_THREAD_SLICE) { +if (avctx->active_thread_type & FF_THREAD_SLICE) { pthread_mutex_destroy(>progress_mutex); pthread_cond_destroy(>progress_cond); av_freep(>entries); @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_init(>progress_mutex, NULL); +pthread_cond_init(>progress_cond, NULL); +} for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] avcodec/vp9: avoid using uninitialized mutex/condition
When using slice decoding vp9_free_entries() is called before vp9_alloc_entries() is ever called. It should destroy properly initialized variables (or check it was never called before). It usually works undetected as pthread implementations allows NULL as a special value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow NULL in pthread_mutex_destroy() and crashes when that's the case. --- libavcodec/vp9.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..8a3d82da09 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -42,7 +42,7 @@ static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; -if (avctx->active_thread_type & FF_THREAD_SLICE) { +if (avctx->active_thread_type & FF_THREAD_SLICE) { pthread_mutex_destroy(>progress_mutex); pthread_cond_destroy(>progress_cond); av_freep(>entries); @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_init(>progress_mutex, NULL); +pthread_cond_init(>progress_cond, NULL); +} for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avcodec/vp9: avoid using uninitialized mutex/condition
When using slice decoding vp9_free_entries is called before vp9_alloc_entries is ever called. It should destroy properly initialized variables (or check it was never called before). It usually works undetected as pthread implementations allows NULL as a special value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow NULL in pthread_mutex_destroy() and crashes when that's the case. --- libavcodec/vp9.c | 4 1 file changed, 4 insertions(+) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..d40e90b70e 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +if (avctx->active_thread_type & FF_THREAD_SLICE) { +pthread_mutex_init(>progress_mutex, NULL); +pthread_cond_init(>progress_cond, NULL); +} for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); -- 2.29.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/mov: reword log message about dref
Most of the times it's just 'url ', so it's not unknown. --- By the way, there is a patch to add support for dref.url https://patchwork.ffmpeg.org/project/ffmpeg/patch/1596807454-17939-2-git-send-email-mypopy...@gmail.com/ I agree there are safety issues. libavformat/mov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index c5583e07c7..c4024fc402 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -708,8 +708,8 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_skip(pb, len); } } else { -av_log(c->fc, AV_LOG_DEBUG, "Unknown dref type 0x%08"PRIx32" size %"PRIu32"\n", - dref->type, size); +av_log(c->fc, AV_LOG_DEBUG, "Ignore dref type %s size %"PRIu32"\n", + av_fourcc2str(dref->type), size); entries--; i--; } -- 2.31.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 v2] lavfi: add nlmeans CUDA filter
I want to add support for the other formats, but I'm not sure how to find video files to test it out. I tried looking through https://samples.ffmpeg.org/, but I'm not sure which files on there are the formats im looking for (AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_P010, AV_PIX_FMT_P016, AV_PIX_FMT_YUV444P16). From 9183993c6b31560ed21fe9dd4c06f7e01735d903 Mon Sep 17 00:00:00 2001 From: Dylan Fernando Date: Thu, 2 Sep 2021 17:31:49 + Subject: [PATCH] lavfi: add nlmeans_cuda filter Signed-off-by: Dylan Fernando --- configure | 2 + doc/filters.texi | 4 + libavfilter/Makefile | 2 + libavfilter/allfilters.c | 1 + libavfilter/version.h | 2 +- libavfilter/vf_nlmeans_cuda.c | 850 + libavfilter/vf_nlmeans_cuda.cu | 378 +++ 7 files changed, 1238 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_nlmeans_cuda.c create mode 100644 libavfilter/vf_nlmeans_cuda.cu diff --git a/configure b/configure index 9249254b70..55ed0200c7 100755 --- a/configure +++ b/configure @@ -3094,6 +3094,8 @@ thumbnail_cuda_filter_deps_any="cuda_nvcc cuda_llvm" transpose_npp_filter_deps="ffnvcodec libnpp" overlay_cuda_filter_deps="ffnvcodec" overlay_cuda_filter_deps_any="cuda_nvcc cuda_llvm" +nlmeans_cuda_filter_deps="ffnvcodec" +nlmeans_cuda_filter_deps_any="cuda_nvcc cuda_llvm" amf_deps_any="libdl LoadLibrary" nvenc_deps="ffnvcodec" diff --git a/doc/filters.texi b/doc/filters.texi index 9ad6031d23..b5eb9ecd33 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -15380,6 +15380,10 @@ Same as @option{r} but for chroma planes. The default value is @var{0} and means automatic. @end table +@section nlmeans_cuda + +Non-local Means denoise filter through CUDA, this filter accepts same options as @ref{nlmeans}. + @section nnedi Deinterlace video using neural network edge directed interpolation. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index af957a5ac0..7a61d7591e 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -347,6 +347,8 @@ OBJS-$(CONFIG_MPDECIMATE_FILTER) += vf_mpdecimate.o OBJS-$(CONFIG_NEGATE_FILTER) += vf_lut.o OBJS-$(CONFIG_NLMEANS_FILTER)+= vf_nlmeans.o OBJS-$(CONFIG_NLMEANS_OPENCL_FILTER) += vf_nlmeans_opencl.o opencl.o opencl/nlmeans.o +OBJS-$(CONFIG_NLMEANS_CUDA_FILTER) += vf_nlmeans_cuda.o vf_nlmeans_cuda.ptx.o \ +cuda/load_helper.o OBJS-$(CONFIG_NNEDI_FILTER) += vf_nnedi.o OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_NOISE_FILTER) += vf_noise.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 0c6b2347c8..d65c13011c 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -333,6 +333,7 @@ extern const AVFilter ff_vf_msad; extern const AVFilter ff_vf_negate; extern const AVFilter ff_vf_nlmeans; extern const AVFilter ff_vf_nlmeans_opencl; +extern const AVFilter ff_vf_nlmeans_cuda; extern const AVFilter ff_vf_nnedi; extern const AVFilter ff_vf_noformat; extern const AVFilter ff_vf_noise; diff --git a/libavfilter/version.h b/libavfilter/version.h index ff12ff9f8f..306bb62ff4 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #include "libavutil/version.h" #define LIBAVFILTER_VERSION_MAJOR 8 -#define LIBAVFILTER_VERSION_MINOR 7 +#define LIBAVFILTER_VERSION_MINOR 8 #define LIBAVFILTER_VERSION_MICRO 100 diff --git a/libavfilter/vf_nlmeans_cuda.c b/libavfilter/vf_nlmeans_cuda.c new file mode 100644 index 00..3dc74e310d --- /dev/null +++ b/libavfilter/vf_nlmeans_cuda.c @@ -0,0 +1,850 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "libavutil/hwcontext.h" +#include "libavutil/hwcontext_cuda_internal.h" +#include "libavutil/cuda_check.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" + +#include "avfilter.h" +#include "internal.h" + +#include "cuda/load_helper.h" + +static const enum AVPixelFormat supported_formats[] = { +AV_PIX_FMT_NV12 +}; + + +#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x) +
Re: [FFmpeg-devel] [PATCH] avforma: add an AV1 Low overhead bitstream format muxer
On Thu, Sep 2, 2021 at 12:54 AM James Almer wrote: > > On 8/27/2021 4:34 PM, James Almer wrote: > > Suggested-by: BBB > > Signed-off-by: James Almer > > --- > > Changelog | 1 + > > configure | 1 + > > doc/general_contents.texi | 1 + > > libavformat/Makefile | 1 + > > libavformat/allformats.c | 1 + > > libavformat/rawenc.c | 20 > > libavformat/version.h | 4 ++-- > > 7 files changed, 27 insertions(+), 2 deletions(-) > > Will apply soon. Maybe you already fixed it, maybe not, but there is a typo in the commit message, avformat is missing a t. :) - Hendrik ___ 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".