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

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

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
34#include "hwaccel_internal.h"34#include "hwaccel_internal.h"
35#include "hwconfig.h"35#include "hwconfig.h"
36#include "mathops.h"36#include "mathops.h"
37#include "refstruct.h"
37#include "thread.h"38#include "thread.h"
38#include "threadframe.h"39#include "threadframe.h"
39#include "vp8.h"40#include "vp8.h"
@@ -105,10 +106,8 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 65 unmodified lines
105 if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf,106 if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf,
106 ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)107 ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
107 return ret;108 return ret;
108 if (!(f->seg_map = av_buffer_allocz(s->mb_width * s->mb_height))) {109 if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height)))
109 ret = AVERROR(ENOMEM);
110 goto fail;110 goto fail;
111 }
112 ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private,111 ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private,
113 &f->hwaccel_priv_buf);112 &f->hwaccel_priv_buf);
114 if (ret < 0)113 if (ret < 0)
@@ -117,14 +116,14 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 2 unmodified lines
117 return 0;116 return 0;
118 117
119fail:118fail:
120 av_buffer_unref(&f->seg_map);119 ff_refstruct_unref(&f->seg_map);
121 ff_thread_release_ext_buffer(s->avctx, &f->tf);120 ff_thread_release_ext_buffer(s->avctx, &f->tf);
122 return ret;121 return ret;
123}122}
124 123
125static void vp8_release_frame(VP8Context *s, VP8Frame *f)124static void vp8_release_frame(VP8Context *s, VP8Frame *f)
126{125{
127 av_buffer_unref(&f->seg_map);126 ff_refstruct_unref(&f->seg_map);
128 av_buffer_unref(&f->hwaccel_priv_buf);127 av_buffer_unref(&f->hwaccel_priv_buf);
129 f->hwaccel_picture_private = NULL;128 f->hwaccel_picture_private = NULL;
130 ff_thread_release_ext_buffer(s->avctx, &f->tf);129 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
139 138
140 if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0)139 if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0)
141 return ret;140 return ret;
142 if (src->seg_map &&141 ff_refstruct_replace(&dst->seg_map, src->seg_map);
143 !(dst->seg_map = av_buffer_ref(src->seg_map))) {
144 vp8_release_frame(s, dst);
145 return AVERROR(ENOMEM);
146 }
147 if (src->hwaccel_picture_private) {142 if (src->hwaccel_picture_private) {
148 dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);143 dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
149 if (!dst->hwaccel_priv_buf)144 if (!dst->hwaccel_priv_buf)
@@ -2334,9 +2329,9 @@ int vp78_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe, · 2184 unmodified lines
2334 if (mb_y == 0)2329 if (mb_y == 0)
2335 AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top,2330 AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top,
2336 DC_PRED * 0x01010101);2331 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,
2338 prev_frame && prev_frame->seg_map ?2333 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);
2340 s->mv_bounds.mv_min.x -= 64;2335 s->mv_bounds.mv_min.x -= 64;
2341 s->mv_bounds.mv_max.x -= 64;2336 s->mv_bounds.mv_max.x -= 64;
2342 }2337 }
@@ -2467,9 +2462,9 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void · 124 unmodified lines
2467 dst[2] - dst[1], 2);2462 dst[2] - dst[1], 2);
2468 2463
2469 if (!s->mb_layout)2464 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,
2471 prev_frame && prev_frame->seg_map ?2466 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);
2473 2468
2474 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS);2469 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS);
2475 2470
libavcodec/vp8.h+1−1
@@ -152,7 +152,7 @@ typedef struct VP8ThreadData { · 151 unmodified lines
152 152
153typedef struct VP8Frame {153typedef struct VP8Frame {
154 ThreadFrame tf;154 ThreadFrame tf;
155 AVBufferRef *seg_map;155 uint8_t *seg_map; ///< RefStruct reference
156 156
157 AVBufferRef *hwaccel_priv_buf;157 AVBufferRef *hwaccel_priv_buf;
158 void *hwaccel_picture_private;158 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