History

avcodec/vp8: Use RefStruct API for seg_map

Avoids allocations and error checks when syncing the buffers. Also avoids indirections.

Andreas Rheinhardt committed 3 years ago

Commit e1ba00a1 parent 2db94a92 files · +10 −15Browse files

Unified · Split

2 files
  1. libavcodec/vp8.c +9 −14
  2. libavcodec/vp8.h +1 −1
libavcodec/vp8.c+9−14
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434 #include "hwaccel_internal.h"
3535 #include "hwconfig.h"
3636 #include "mathops.h"
37+#include "refstruct.h"
3738 #include "thread.h"
3839 #include "threadframe.h"
3940 #include "vp8.h"
@@ -105,10 +106,8 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 65 unmodified lines
105106 if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf,
106107 ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
107108 return ret;
108− if (!(f->seg_map = av_buffer_allocz(s->mb_width * s->mb_height))) {
109− ret = AVERROR(ENOMEM);
109+ if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height)))
110110 goto fail;
111− }
112111 ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private,
113112 &f->hwaccel_priv_buf);
114113 if (ret < 0)
@@ -117,14 +116,14 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 2 unmodified lines
117116 return 0;
118117
119118 fail:
120− av_buffer_unref(&f->seg_map);
119+ ff_refstruct_unref(&f->seg_map);
121120 ff_thread_release_ext_buffer(s->avctx, &f->tf);
122121 return ret;
123122 }
124123
125124 static void vp8_release_frame(VP8Context *s, VP8Frame *f)
126125 {
127− av_buffer_unref(&f->seg_map);
126+ ff_refstruct_unref(&f->seg_map);
128127 av_buffer_unref(&f->hwaccel_priv_buf);
129128 f->hwaccel_picture_private = NULL;
130129 ff_thread_release_ext_buffer(s->avctx, &f->tf);
@@ -139,11 +138,7 @@ static int vp8_ref_frame(VP8Context *s, VP8Frame *dst, const VP8Frame *src) · 8 unmodified lines
139138
140139 if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0)
141140 return ret;
142− if (src->seg_map &&
143− !(dst->seg_map = av_buffer_ref(src->seg_map))) {
144− vp8_release_frame(s, dst);
145− return AVERROR(ENOMEM);
146− }
141+ ff_refstruct_replace(&dst->seg_map, src->seg_map);
147142 if (src->hwaccel_picture_private) {
148143 dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
149144 if (!dst->hwaccel_priv_buf)
@@ -2334,9 +2329,9 @@ int vp78_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe, · 2184 unmodified lines
23342329 if (mb_y == 0)
23352330 AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top,
23362331 DC_PRED * 0x01010101);
2337− decode_mb_mode(s, &s->mv_bounds, mb, mb_x, mb_y, curframe->seg_map->data + mb_xy,
2332+ decode_mb_mode(s, &s->mv_bounds, mb, mb_x, mb_y, curframe->seg_map + mb_xy,
23382333 prev_frame && prev_frame->seg_map ?
2339− prev_frame->seg_map->data + mb_xy : NULL, 1, is_vp7);
2334+ prev_frame->seg_map + mb_xy : NULL, 1, is_vp7);
23402335 s->mv_bounds.mv_min.x -= 64;
23412336 s->mv_bounds.mv_max.x -= 64;
23422337 }
@@ -2467,9 +2462,9 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void · 124 unmodified lines
24672462 dst[2] - dst[1], 2);
24682463
24692464 if (!s->mb_layout)
2470− decode_mb_mode(s, &td->mv_bounds, mb, mb_x, mb_y, curframe->seg_map->data + mb_xy,
2465+ decode_mb_mode(s, &td->mv_bounds, mb, mb_x, mb_y, curframe->seg_map + mb_xy,
24712466 prev_frame && prev_frame->seg_map ?
2472− prev_frame->seg_map->data + mb_xy : NULL, 0, is_vp7);
2467+ prev_frame->seg_map + mb_xy : NULL, 0, is_vp7);
24732468
24742469 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS);
24752470
libavcodec/vp8.h+1−1
@@ -152,7 +152,7 @@ typedef struct VP8ThreadData { · 151 unmodified lines
152152
153153 typedef struct VP8Frame {
154154 ThreadFrame tf;
155− AVBufferRef *seg_map;
155+ uint8_t *seg_map; ///< RefStruct reference
156156
157157 AVBufferRef *hwaccel_priv_buf;
158158 void *hwaccel_picture_private;

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