Avoids allocations and error checks when syncing the buffers. Also avoids indirections.
Unified · Split
| @@ -34,6 +34,7 @@ · 33 unmodified lines | ||
| 34 | 34 | #include "hwaccel_internal.h" |
| 35 | 35 | #include "hwconfig.h" |
| 36 | 36 | #include "mathops.h" |
| 37 | +#include "refstruct.h" | |
| 37 | 38 | #include "thread.h" |
| 38 | 39 | #include "threadframe.h" |
| 39 | 40 | #include "vp8.h" |
| @@ -105,10 +106,8 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 65 unmodified lines | ||
| 105 | 106 | if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf, |
| 106 | 107 | ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0) |
| 107 | 108 | 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))) | |
| 110 | 110 | goto fail; |
| 111 | − } | |
| 112 | 111 | ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private, |
| 113 | 112 | &f->hwaccel_priv_buf); |
| 114 | 113 | if (ret < 0) |
| @@ -117,14 +116,14 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 2 unmodified lines | ||
| 117 | 116 | return 0; |
| 118 | 117 | |
| 119 | 118 | fail: |
| 120 | − av_buffer_unref(&f->seg_map); | |
| 119 | + ff_refstruct_unref(&f->seg_map); | |
| 121 | 120 | ff_thread_release_ext_buffer(s->avctx, &f->tf); |
| 122 | 121 | return ret; |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | 124 | static 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 | 127 | av_buffer_unref(&f->hwaccel_priv_buf); |
| 129 | 128 | f->hwaccel_picture_private = NULL; |
| 130 | 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 | 139 | if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0) |
| 141 | 140 | 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); | |
| 147 | 142 | if (src->hwaccel_picture_private) { |
| 148 | 143 | dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); |
| 149 | 144 | if (!dst->hwaccel_priv_buf) |
| @@ -2334,9 +2329,9 @@ int vp78_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe, · 2184 unmodified lines | ||
| 2334 | 2329 | if (mb_y == 0) |
| 2335 | 2330 | AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top, |
| 2336 | 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 | 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 | 2335 | s->mv_bounds.mv_min.x -= 64; |
| 2341 | 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 | 2462 | dst[2] - dst[1], 2); |
| 2468 | 2463 | |
| 2469 | 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 | 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 | 2469 | prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS); |
| 2475 | 2470 | |
| @@ -152,7 +152,7 @@ typedef struct VP8ThreadData { · 151 unmodified lines | ||
| 152 | 152 | |
| 153 | 153 | typedef struct VP8Frame { |
| 154 | 154 | ThreadFrame tf; |
| 155 | − AVBufferRef *seg_map; | |
| 155 | + uint8_t *seg_map; ///< RefStruct reference | |
| 156 | 156 | |
| 157 | 157 | AVBufferRef *hwaccel_priv_buf; |
| 158 | 158 | void *hwaccel_picture_private; |