History

avcodec: add AVHWAccel.free_frame_priv callback

Lynne committed 4 years ago

Commit be071451 parent 09dc9199 files · +50 −7Browse files

Showing the changes to libavcodec (9 of 9 files). Show all

Unified · Split

9 files
  1. libavcodec/av1dec.c +2 −2
  2. libavcodec/avcodec.h +8 −0
  3. libavcodec/decode.c +20 −0
  4. libavcodec/decode.h +11 −0
  5. libavcodec/h264_slice.c +2 −1
  6. libavcodec/hevc_refs.c +2 −1
  7. libavcodec/mpegpicture.c +3 −1
  8. libavcodec/vp8.c +1 −1
  9. libavcodec/vp9.c +1 −1
libavcodec/av1dec.c+2−2
@@ -27,6 +27,7 @@ · 26 unmodified lines
27#include "libavutil/opt.h"27#include "libavutil/opt.h"
28#include "avcodec.h"28#include "avcodec.h"
29#include "av1_parse.h"29#include "av1_parse.h"
30#include "decode.h"
30#include "av1dec.h"31#include "av1dec.h"
31#include "atsc_a53.h"32#include "atsc_a53.h"
32#include "bytestream.h"33#include "bytestream.h"
@@ -865,8 +866,7 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) · 832 unmodified lines
865 if (avctx->hwaccel) {866 if (avctx->hwaccel) {
866 const AVHWAccel *hwaccel = avctx->hwaccel;867 const AVHWAccel *hwaccel = avctx->hwaccel;
867 if (hwaccel->frame_priv_data_size) {868 if (hwaccel->frame_priv_data_size) {
868 f->hwaccel_priv_buf =869 f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, hwaccel);
869 av_buffer_allocz(hwaccel->frame_priv_data_size);
870 if (!f->hwaccel_priv_buf) {870 if (!f->hwaccel_priv_buf) {
871 ret = AVERROR(ENOMEM);871 ret = AVERROR(ENOMEM);
872 goto fail;872 goto fail;
libavcodec/avcodec.h+8−0
@@ -2259,6 +2259,14 @@ typedef struct AVHWAccel { · 2258 unmodified lines
2259 * For thread-safe hwaccels only.2259 * For thread-safe hwaccels only.
2260 */2260 */
2261 int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);2261 int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
2262
2263 /**
2264 * Callback to free the hwaccel-specific frame data.
2265 *
2266 * @param hwctx a pointer to an AVHWDeviceContext.
2267 * @param data the per-frame hardware accelerator private data to be freed.
2268 */
2269 void (*free_frame_priv)(void *hwctx, uint8_t *data);
2262} AVHWAccel;2270} AVHWAccel;
2263 2271
2264/**2272/**
libavcodec/decode.c+20−0
@@ -1718,3 +1718,23 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) · 1717 unmodified lines
1718 }1718 }
1719 return 0;1719 return 0;
1720}1720}
1721
1722AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
1723 const AVHWAccel *hwaccel)
1724{
1725 AVBufferRef *ref;
1726 AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
1727 uint8_t *data = av_mallocz(hwaccel->frame_priv_data_size);
1728 if (!data)
1729 return NULL;
1730
1731 ref = av_buffer_create(data, hwaccel->frame_priv_data_size,
1732 hwaccel->free_frame_priv,
1733 frames_ctx->device_ctx, 0);
1734 if (!ref) {
1735 av_free(data);
1736 return NULL;
1737 }
1738
1739 return ref;
1740}
libavcodec/decode.h+11−0
@@ -150,4 +150,15 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags); · 149 unmodified lines
150int ff_side_data_update_matrix_encoding(AVFrame *frame,150int ff_side_data_update_matrix_encoding(AVFrame *frame,
151 enum AVMatrixEncoding matrix_encoding);151 enum AVMatrixEncoding matrix_encoding);
152 152
153/**
154 * Allocate a hwaccel frame private data and create an AVBufferRef
155 * from it.
156 *
157 * @param avctx The codec context which to attach as an opaque value
158 * @param hwaccel The hwaccel for which to allocate
159 * @return The allocated buffer
160 */
161AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
162 const AVHWAccel *hwaccel);
163
153#endif /* AVCODEC_DECODE_H */164#endif /* AVCODEC_DECODE_H */
libavcodec/h264_slice.c+2−1
@@ -33,6 +33,7 @@ · 32 unmodified lines
33#include "libavutil/pixdesc.h"33#include "libavutil/pixdesc.h"
34#include "libavutil/timecode.h"34#include "libavutil/timecode.h"
35#include "internal.h"35#include "internal.h"
36#include "decode.h"
36#include "cabac.h"37#include "cabac.h"
37#include "cabac_functions.h"38#include "cabac_functions.h"
38#include "decode.h"39#include "decode.h"
@@ -212,7 +213,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic) · 173 unmodified lines
212 const AVHWAccel *hwaccel = h->avctx->hwaccel;213 const AVHWAccel *hwaccel = h->avctx->hwaccel;
213 av_assert0(!pic->hwaccel_picture_private);214 av_assert0(!pic->hwaccel_picture_private);
214 if (hwaccel->frame_priv_data_size) {215 if (hwaccel->frame_priv_data_size) {
215 pic->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size);216 pic->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(h->avctx, hwaccel);
216 if (!pic->hwaccel_priv_buf)217 if (!pic->hwaccel_priv_buf)
217 return AVERROR(ENOMEM);218 return AVERROR(ENOMEM);
218 pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;219 pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;
libavcodec/hevc_refs.c+2−1
@@ -23,6 +23,7 @@ · 22 unmodified lines
23 23
24#include "libavutil/avassert.h"24#include "libavutil/avassert.h"
25 25
26#include "decode.h"
26#include "thread.h"27#include "thread.h"
27#include "hevc.h"28#include "hevc.h"
28#include "hevcdec.h"29#include "hevcdec.h"
@@ -121,7 +122,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 92 unmodified lines
121 const AVHWAccel *hwaccel = s->avctx->hwaccel;122 const AVHWAccel *hwaccel = s->avctx->hwaccel;
122 av_assert0(!frame->hwaccel_picture_private);123 av_assert0(!frame->hwaccel_picture_private);
123 if (hwaccel->frame_priv_data_size) {124 if (hwaccel->frame_priv_data_size) {
124 frame->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size);125 frame->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(s->avctx, hwaccel);
125 if (!frame->hwaccel_priv_buf)126 if (!frame->hwaccel_priv_buf)
126 goto fail;127 goto fail;
127 frame->hwaccel_picture_private = frame->hwaccel_priv_buf->data;128 frame->hwaccel_picture_private = frame->hwaccel_priv_buf->data;
libavcodec/mpegpicture.c+3−1
@@ -27,6 +27,8 @@ · 26 unmodified lines
27 27
28#include "avcodec.h"28#include "avcodec.h"
29#include "encode.h"29#include "encode.h"
30#include "internal.h"
31#include "decode.h"
30#include "motion_est.h"32#include "motion_est.h"
31#include "mpegpicture.h"33#include "mpegpicture.h"
32#include "mpegutils.h"34#include "mpegutils.h"
@@ -172,7 +174,7 @@ static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, · 139 unmodified lines
172 if (avctx->hwaccel) {174 if (avctx->hwaccel) {
173 assert(!pic->hwaccel_picture_private);175 assert(!pic->hwaccel_picture_private);
174 if (avctx->hwaccel->frame_priv_data_size) {176 if (avctx->hwaccel->frame_priv_data_size) {
175 pic->hwaccel_priv_buf = av_buffer_allocz(avctx->hwaccel->frame_priv_data_size);177 pic->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, avctx->hwaccel);
176 if (!pic->hwaccel_priv_buf) {178 if (!pic->hwaccel_priv_buf) {
177 av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");179 av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
178 return -1;180 return -1;
libavcodec/vp8.c+1−1
@@ -109,7 +109,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 108 unmodified lines
109 if (s->avctx->hwaccel) {109 if (s->avctx->hwaccel) {
110 const AVHWAccel *hwaccel = s->avctx->hwaccel;110 const AVHWAccel *hwaccel = s->avctx->hwaccel;
111 if (hwaccel->frame_priv_data_size) {111 if (hwaccel->frame_priv_data_size) {
112 f->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size);112 f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(s->avctx, hwaccel);
113 if (!f->hwaccel_priv_buf)113 if (!f->hwaccel_priv_buf)
114 goto fail;114 goto fail;
115 f->hwaccel_picture_private = f->hwaccel_priv_buf->data;115 f->hwaccel_picture_private = f->hwaccel_priv_buf->data;
libavcodec/vp9.c+1−1
@@ -136,7 +136,7 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) · 135 unmodified lines
136 const AVHWAccel *hwaccel = avctx->hwaccel;136 const AVHWAccel *hwaccel = avctx->hwaccel;
137 av_assert0(!f->hwaccel_picture_private);137 av_assert0(!f->hwaccel_picture_private);
138 if (hwaccel->frame_priv_data_size) {138 if (hwaccel->frame_priv_data_size) {
139 f->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size);139 f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, hwaccel);
140 if (!f->hwaccel_priv_buf)140 if (!f->hwaccel_priv_buf)
141 goto fail;141 goto fail;
142 f->hwaccel_picture_private = f->hwaccel_priv_buf->data;142 f->hwaccel_picture_private = f->hwaccel_priv_buf->data;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t