[libav-devel] [PATCH] libfdk-aacenc: Fix building with libfdk-aac v2
When flushing the encoder, we now need to provide non-null buffer parameters for everything, even if they are unused. The encoderDelay parameter has been replaced by two, nDelay and nDelayCore. --- libfdk-aac v2 also has a bunch of other new, yet untested features, like support for xHE-AAC. --- libavcodec/libfdk-aacenc.c | 34 +- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index c340a1e3e0..2ad768ed44 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -26,6 +26,11 @@ #include "audio_frame_queue.h" #include "internal.h" +#define FDKENC_VER_AT_LEAST(vl0, vl1) \ +(defined(AACENCODER_LIB_VL0) && \ +((AACENCODER_LIB_VL0 > vl0) || \ + (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 >= vl1))) + typedef struct AACContext { const AVClass *class; HANDLE_AACENCODER handle; @@ -290,7 +295,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } avctx->frame_size = info.frameLength; +#if FDKENC_VER_AT_LEAST(4, 0) +avctx->initial_padding = info.nDelay; +#else avctx->initial_padding = info.encoderDelay; +#endif ff_af_queue_init(avctx, >afq); if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { @@ -323,28 +332,35 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int out_buffer_size, out_buffer_element_size; void *in_ptr, *out_ptr; int ret; +uint8_t dummy_buf[1]; AACENC_ERROR err; /* handle end-of-stream small frame and flushing */ if (!frame) { +/* Must be a non-null pointer, even if it's a dummy. We could use + * the address of anything else on the stack as well. */ +in_ptr = dummy_buf; +in_buffer_size = 0; + in_args.numInSamples = -1; } else { -in_ptr = frame->data[0]; -in_buffer_size = 2 * avctx->channels * frame->nb_samples; -in_buffer_element_size = 2; +in_ptr = frame->data[0]; +in_buffer_size = 2 * avctx->channels * frame->nb_samples; -in_args.numInSamples = avctx->channels * frame->nb_samples; -in_buf.numBufs = 1; -in_buf.bufs = _ptr; -in_buf.bufferIdentifiers = _buffer_identifier; -in_buf.bufSizes = _buffer_size; -in_buf.bufElSizes= _buffer_element_size; +in_args.numInSamples = avctx->channels * frame->nb_samples; /* add current frame to the queue */ if ((ret = ff_af_queue_add(>afq, frame)) < 0) return ret; } +in_buffer_element_size = 2; +in_buf.numBufs = 1; +in_buf.bufs = _ptr; +in_buf.bufferIdentifiers = _buffer_identifier; +in_buf.bufSizes = _buffer_size; +in_buf.bufElSizes= _buffer_element_size; + /* The maximum packet size is 6144 bits aka 768 bytes per channel. */ if ((ret = ff_alloc_packet(avpkt, FFMAX(8192, 768 * avctx->channels { av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); -- 2.15.2 (Apple Git-101.1) ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH v7] qsvvpp: Fix to perform full init only when needed
On 02/09/2018 20:06, Maxym Dmytrychenko wrote: > From: Joe Olivas > > Removing unused VPP sessions by initializing only when used in order to help > reduce CPU utilization. Thanks to Maxym for the guidance. > > Signed-off-by: Joe Olivas > Signed-off-by: Maxym Dmytrychenko > --- > libavutil/hwcontext_qsv.c | 83 > +++ > 1 file changed, 77 insertions(+), 6 deletions(-) > Fine for me :) lu ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH v7] qsvvpp: Fix to perform full init only when needed
From: Joe Olivas Removing unused VPP sessions by initializing only when used in order to help reduce CPU utilization. Thanks to Maxym for the guidance. Signed-off-by: Joe Olivas Signed-off-by: Maxym Dmytrychenko --- libavutil/hwcontext_qsv.c | 83 +++ 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index b3eb4a3ea..0cfcc01fe 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -23,6 +23,10 @@ #include "config.h" +#if HAVE_PTHREADS +#include +#endif + #if CONFIG_VAAPI #include "hwcontext_vaapi.h" #endif @@ -56,7 +60,13 @@ typedef struct QSVDeviceContext { typedef struct QSVFramesContext { mfxSession session_download; +int session_download_init; mfxSession session_upload; +int session_upload_init; +#if HAVE_PTHREADS +pthread_mutex_t session_lock; +pthread_cond_t session_cond; +#endif AVBufferRef *child_frames_ref; mfxFrameSurface1 *surfaces_internal; @@ -147,12 +157,19 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) MFXClose(s->session_download); } s->session_download = NULL; +s->session_download_init = 0; if (s->session_upload) { MFXVideoVPP_Close(s->session_upload); MFXClose(s->session_upload); } s->session_upload = NULL; +s->session_upload_init = 0; + +#if HAVE_PTHREADS +pthread_mutex_destroy(>session_lock); +pthread_cond_destroy(>session_cond); +#endif av_freep(>mem_ids); av_freep(>surface_ptrs); @@ -535,13 +552,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx) s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId; } -ret = qsv_init_internal_session(ctx, >session_download, 0); -if (ret < 0) -return ret; +s->session_download = NULL; +s->session_upload = NULL; -ret = qsv_init_internal_session(ctx, >session_upload, 1); -if (ret < 0) -return ret; +s->session_download_init = 0; +s->session_upload_init = 0; + +#if HAVE_PTHREADS +pthread_mutex_init(>session_lock, NULL); +pthread_cond_init(>session_cond, NULL); +#endif return 0; } @@ -740,6 +760,32 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, mfxSyncPoint sync = NULL; 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 +} + +if (ret < 0) +return ret; if (!s->session_download) { if (s->child_frames_ref) @@ -787,6 +833,31 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, mfxSyncPoint sync = NULL; mfxStatus err; +int ret; + +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 +} +if (ret < 0) +return ret; if (!s->session_upload) { if (s->child_frames_ref) -- 2.15.2 (Apple Git-101.1) ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH] fixup: qsvvpp: Make check for initialization failures
--- I'd squash this on top of this patch and push it in a bit. libavutil/hwcontext_qsv.c | 21 + 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 36a30c5c35..0cfcc01fe8 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -760,21 +760,21 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, mfxSyncPoint sync = NULL; mfxStatus err; +int ret = 0; -while (!s->session_download_init && !s->session_download) { +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) { -qsv_init_internal_session(ctx, >session_download, 0); +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 { +} else { pthread_mutex_lock(>session_lock); while (!s->session_download_init && !s->session_download) { pthread_cond_wait(>session_cond, >session_lock); @@ -784,6 +784,9 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, #endif } +if (ret < 0) +return ret; + if (!s->session_download) { if (s->child_frames_ref) return qsv_transfer_data_child(ctx, dst, src); @@ -830,21 +833,21 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, mfxSyncPoint sync = NULL; mfxStatus err; +int ret; -while (!s->session_upload_init && !s->session_upload) { +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) { -qsv_init_internal_session(ctx, >session_upload, 1); +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 { +} else { pthread_mutex_lock(>session_lock); while (!s->session_upload_init && !s->session_upload) { pthread_cond_wait(>session_cond, >session_lock); @@ -853,6 +856,8 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, } #endif } +if (ret < 0) +return ret; if (!s->session_upload) { if (s->child_frames_ref) -- 2.13.3 ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel