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
2727 #include "libavutil/opt.h"
2828 #include "avcodec.h"
2929 #include "av1_parse.h"
30+#include "decode.h"
3031 #include "av1dec.h"
3132 #include "atsc_a53.h"
3233 #include "bytestream.h"
@@ -865,8 +866,7 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) · 832 unmodified lines
865866 if (avctx->hwaccel) {
866867 const AVHWAccel *hwaccel = avctx->hwaccel;
867868 if (hwaccel->frame_priv_data_size) {
868− f->hwaccel_priv_buf =
869− av_buffer_allocz(hwaccel->frame_priv_data_size);
869+ f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, hwaccel);
870870 if (!f->hwaccel_priv_buf) {
871871 ret = AVERROR(ENOMEM);
872872 goto fail;
libavcodec/avcodec.h+8−0
@@ -2259,6 +2259,14 @@ typedef struct AVHWAccel { · 2258 unmodified lines
22592259 * For thread-safe hwaccels only.
22602260 */
22612261 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);
22622270 } AVHWAccel;
22632271
22642272 /**
libavcodec/decode.c+20−0
@@ -1718,3 +1718,23 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) · 1717 unmodified lines
17181718 }
17191719 return 0;
17201720 }
1721+
1722+AVBufferRef *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
150150 int ff_side_data_update_matrix_encoding(AVFrame *frame,
151151 enum AVMatrixEncoding matrix_encoding);
152152
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+ */
161+AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
162+ const AVHWAccel *hwaccel);
163+
153164 #endif /* AVCODEC_DECODE_H */
libavcodec/h264_slice.c+2−1
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 #include "libavutil/pixdesc.h"
3434 #include "libavutil/timecode.h"
3535 #include "internal.h"
36+#include "decode.h"
3637 #include "cabac.h"
3738 #include "cabac_functions.h"
3839 #include "decode.h"
@@ -212,7 +213,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic) · 173 unmodified lines
212213 const AVHWAccel *hwaccel = h->avctx->hwaccel;
213214 av_assert0(!pic->hwaccel_picture_private);
214215 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);
216217 if (!pic->hwaccel_priv_buf)
217218 return AVERROR(ENOMEM);
218219 pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;
libavcodec/hevc_refs.c+2−1
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323
2424 #include "libavutil/avassert.h"
2525
26+#include "decode.h"
2627 #include "thread.h"
2728 #include "hevc.h"
2829 #include "hevcdec.h"
@@ -121,7 +122,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 92 unmodified lines
121122 const AVHWAccel *hwaccel = s->avctx->hwaccel;
122123 av_assert0(!frame->hwaccel_picture_private);
123124 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);
125126 if (!frame->hwaccel_priv_buf)
126127 goto fail;
127128 frame->hwaccel_picture_private = frame->hwaccel_priv_buf->data;
libavcodec/mpegpicture.c+3−1
@@ -27,6 +27,8 @@ · 26 unmodified lines
2727
2828 #include "avcodec.h"
2929 #include "encode.h"
30+#include "internal.h"
31+#include "decode.h"
3032 #include "motion_est.h"
3133 #include "mpegpicture.h"
3234 #include "mpegutils.h"
@@ -172,7 +174,7 @@ static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, · 139 unmodified lines
172174 if (avctx->hwaccel) {
173175 assert(!pic->hwaccel_picture_private);
174176 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);
176178 if (!pic->hwaccel_priv_buf) {
177179 av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
178180 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
109109 if (s->avctx->hwaccel) {
110110 const AVHWAccel *hwaccel = s->avctx->hwaccel;
111111 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);
113113 if (!f->hwaccel_priv_buf)
114114 goto fail;
115115 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
136136 const AVHWAccel *hwaccel = avctx->hwaccel;
137137 av_assert0(!f->hwaccel_picture_private);
138138 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);
140140 if (!f->hwaccel_priv_buf)
141141 goto fail;
142142 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