From 1516bf7af1e8647962738f590be0a5ea1a553afd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 18 Mar 2013 07:38:20 +0100 Subject: lavc: update the doxy for avcodec_decode_{video,audio} wtih refcounting. --- libavcodec/avcodec.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index f7d6553fa5..316d30a656 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3281,11 +3281,17 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, * * @param avctx the codec context * @param[out] frame The AVFrame in which to store decoded audio samples. - * Decoders request a buffer of a particular size by setting - * AVFrame.nb_samples prior to calling get_buffer(). The - * decoder may, however, only utilize part of the buffer by - * setting AVFrame.nb_samples to a smaller value in the - * output frame. + * The decoder will allocate a buffer for the decoded frame by + * calling the AVCodecContext.get_buffer2() callback. + * When AVCodecContext.refcounted_frames is set to 1, the frame is + * reference counted and the returned reference belongs to the + * caller. The caller must release the frame using av_frame_unref() + * when the frame is no longer needed. The caller may safely write + * to the frame if av_frame_is_writable() returns 1. + * When AVCodecContext.refcounted_frames is set to 0, the returned + * reference belongs to the decoder and is valid only until the + * next call to this function or until closing the decoder. + * The caller may not write to it. * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is * non-zero. * @param[in] avpkt The input AVPacket containing the input buffer. @@ -3323,12 +3329,18 @@ int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, * * @param avctx the codec context * @param[out] picture The AVFrame in which the decoded video frame will be stored. - * Use avcodec_alloc_frame to get an AVFrame, the codec will - * allocate memory for the actual bitmap. - * with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit. - * with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder - * decodes and the decoder tells the user once it does not need the data anymore, - * the user app can at this point free/reuse/keep the memory as it sees fit. + * Use av_frame_alloc() to get an AVFrame. The codec will + * allocate memory for the actual bitmap by calling the + * AVCodecContext.get_buffer2() callback. + * When AVCodecContext.refcounted_frames is set to 1, the frame is + * reference counted and the returned reference belongs to the + * caller. The caller must release the frame using av_frame_unref() + * when the frame is no longer needed. The caller may safely write + * to the frame if av_frame_is_writable() returns 1. + * When AVCodecContext.refcounted_frames is set to 0, the returned + * reference belongs to the decoder and is valid only until the + * next call to this function or until closing the decoder. The + * caller may not write to it. * * @param[in] avpkt The input AVpacket containing the input buffer. * You can create such packet with av_init_packet() and by then setting -- cgit v1.2.3 From 4e70d66ded537cadd32dbd02a38c3d86a203c812 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Fri, 15 Mar 2013 21:20:37 +0100 Subject: mpegvideo: fix allocation of the hwaccel_picture_private data Signed-off-by: Anton Khirnov --- libavcodec/mpegvideo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 9048179c74..ae6cdefe6b 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -269,11 +269,12 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic) if (s->avctx->hwaccel) { assert(!pic->hwaccel_picture_private); if (s->avctx->hwaccel->priv_data_size) { - pic->hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size); - if (!pic->hwaccel_picture_private) { + pic->hwaccel_priv_buf = av_buffer_allocz(s->avctx->hwaccel->priv_data_size); + if (!pic->hwaccel_priv_buf) { av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n"); return -1; } + pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data; } } @@ -293,7 +294,8 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic) if (r < 0 || !pic->f.data[0]) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n", r, pic->f.data[0]); - av_freep(&pic->hwaccel_picture_private); + av_buffer_unref(&pic->hwaccel_priv_buf); + pic->hwaccel_picture_private = NULL; return -1; } -- cgit v1.2.3