| @@ -18,8 +18,6 @@ · 17 unmodified lines |
| 18 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | | −#include <stdint.h> |
| 22 | | − |
| 23 | 21 | #include "libavutil/avassert.h" |
| 24 | 22 | #include "libavutil/common.h" |
| 25 | 23 | #include "libavutil/mem.h" |
| @@ -34,13 +32,13 @@ · 8 unmodified lines |
| 34 | 32 | |
| 35 | 33 | static void av_noinline free_picture_tables(Picture *pic) |
| 36 | 34 | { |
| 37 | | − av_buffer_unref(&pic->mbskip_table_buf); |
| 38 | | − av_buffer_unref(&pic->qscale_table_buf); |
| 39 | | − av_buffer_unref(&pic->mb_type_buf); |
| 35 | + ff_refstruct_unref(&pic->mbskip_table); |
| 36 | + ff_refstruct_unref(&pic->qscale_table_base); |
| 37 | + ff_refstruct_unref(&pic->mb_type_base); |
| 40 | 38 | |
| 41 | 39 | for (int i = 0; i < 2; i++) { |
| 42 | | − av_buffer_unref(&pic->motion_val_buf[i]); |
| 43 | | − av_buffer_unref(&pic->ref_index_buf[i]); |
| 40 | + ff_refstruct_unref(&pic->motion_val_base[i]); |
| 41 | + ff_refstruct_unref(&pic->ref_index[i]); |
| 44 | 42 | } |
| 45 | 43 | |
| 46 | 44 | pic->mb_width = |
| @@ -135,18 +133,18 @@ static int handle_pic_linesizes(AVCodecContext *avctx, Picture *pic, · 88 unmodified lines |
| 135 | 133 | static int alloc_picture_tables(BufferPoolContext *pools, Picture *pic, |
| 136 | 134 | int mb_height) |
| 137 | 135 | { |
| 138 | | −#define GET_BUFFER(name, idx_suffix) do { \ |
| 139 | | − pic->name ## _buf idx_suffix = av_buffer_pool_get(pools->name ## _pool); \ |
| 140 | | − if (!pic->name ## _buf idx_suffix) \ |
| 136 | +#define GET_BUFFER(name, buf_suffix, idx_suffix) do { \ |
| 137 | + pic->name ## buf_suffix idx_suffix = ff_refstruct_pool_get(pools->name ## _pool); \ |
| 138 | + if (!pic->name ## buf_suffix idx_suffix) \ |
| 141 | 139 | return AVERROR(ENOMEM); \ |
| 142 | 140 | } while (0) |
| 143 | | − GET_BUFFER(mbskip_table,); |
| 144 | | − GET_BUFFER(qscale_table,); |
| 145 | | − GET_BUFFER(mb_type,); |
| 141 | + GET_BUFFER(mbskip_table,,); |
| 142 | + GET_BUFFER(qscale_table, _base,); |
| 143 | + GET_BUFFER(mb_type, _base,); |
| 146 | 144 | if (pools->motion_val_pool) { |
| 147 | 145 | for (int i = 0; i < 2; i++) { |
| 148 | | − GET_BUFFER(motion_val, [i]); |
| 149 | | − GET_BUFFER(ref_index, [i]); |
| 146 | + GET_BUFFER(ref_index,, [i]); |
| 147 | + GET_BUFFER(motion_val, _base, [i]); |
| 150 | 148 | } |
| 151 | 149 | } |
| 152 | 150 | #undef GET_BUFFER |
| @@ -166,7 +164,7 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, · 13 unmodified lines |
| 166 | 164 | ScratchpadContext *sc, BufferPoolContext *pools, |
| 167 | 165 | int mb_height, ptrdiff_t *linesize, ptrdiff_t *uvlinesize) |
| 168 | 166 | { |
| 169 | | − int i, ret; |
| 167 | + int ret; |
| 170 | 168 | |
| 171 | 169 | if (handle_pic_linesizes(avctx, pic, me, sc, |
| 172 | 170 | *linesize, *uvlinesize) < 0) |
| @@ -179,20 +177,12 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, · 6 unmodified lines |
| 179 | 177 | if (ret < 0) |
| 180 | 178 | goto fail; |
| 181 | 179 | |
| 182 | | − pic->mbskip_table = pic->mbskip_table_buf->data; |
| 183 | | − memset(pic->mbskip_table, 0, pic->mbskip_table_buf->size); |
| 184 | | − pic->qscale_table = pic->qscale_table_buf->data + 2 * pic->mb_stride + 1; |
| 185 | | − pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * pic->mb_stride + 1; |
| 186 | | − |
| 187 | | − if (pic->motion_val_buf[0]) { |
| 188 | | − for (i = 0; i < 2; i++) { |
| 189 | | − pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4; |
| 190 | | − pic->ref_index[i] = pic->ref_index_buf[i]->data; |
| 191 | | − /* FIXME: The output of H.263 with OBMC depends upon |
| 192 | | − * the earlier content of the buffer; therefore we |
| 193 | | − * reset it here. */ |
| 194 | | − memset(pic->motion_val_buf[i]->data, 0, pic->motion_val_buf[i]->size); |
| 195 | | − } |
| 180 | + pic->qscale_table = pic->qscale_table_base + 2 * pic->mb_stride + 1; |
| 181 | + pic->mb_type = pic->mb_type_base + 2 * pic->mb_stride + 1; |
| 182 | + |
| 183 | + if (pic->motion_val_base[0]) { |
| 184 | + for (int i = 0; i < 2; i++) |
| 185 | + pic->motion_val[i] = pic->motion_val_base[i] + 4; |
| 196 | 186 | } |
| 197 | 187 | |
| 198 | 188 | return 0; |
| @@ -224,36 +214,24 @@ void ff_mpeg_unref_picture(Picture *pic) · 25 unmodified lines |
| 224 | 214 | pic->coded_picture_number = 0; |
| 225 | 215 | } |
| 226 | 216 | |
| 227 | | −static int update_picture_tables(Picture *dst, const Picture *src) |
| 217 | +static void update_picture_tables(Picture *dst, const Picture *src) |
| 228 | 218 | { |
| 229 | | − int i, ret; |
| 230 | | − |
| 231 | | − ret = av_buffer_replace(&dst->mbskip_table_buf, src->mbskip_table_buf); |
| 232 | | − ret |= av_buffer_replace(&dst->qscale_table_buf, src->qscale_table_buf); |
| 233 | | − ret |= av_buffer_replace(&dst->mb_type_buf, src->mb_type_buf); |
| 234 | | − for (i = 0; i < 2; i++) { |
| 235 | | − ret |= av_buffer_replace(&dst->motion_val_buf[i], src->motion_val_buf[i]); |
| 236 | | − ret |= av_buffer_replace(&dst->ref_index_buf[i], src->ref_index_buf[i]); |
| 237 | | − } |
| 238 | | − |
| 239 | | − if (ret < 0) { |
| 240 | | − free_picture_tables(dst); |
| 241 | | − return ret; |
| 219 | + ff_refstruct_replace(&dst->mbskip_table, src->mbskip_table); |
| 220 | + ff_refstruct_replace(&dst->qscale_table_base, src->qscale_table_base); |
| 221 | + ff_refstruct_replace(&dst->mb_type_base, src->mb_type_base); |
| 222 | + for (int i = 0; i < 2; i++) { |
| 223 | + ff_refstruct_replace(&dst->motion_val_base[i], src->motion_val_base[i]); |
| 224 | + ff_refstruct_replace(&dst->ref_index[i], src->ref_index[i]); |
| 242 | 225 | } |
| 243 | 226 | |
| 244 | | − dst->mbskip_table = src->mbskip_table; |
| 245 | 227 | dst->qscale_table = src->qscale_table; |
| 246 | 228 | dst->mb_type = src->mb_type; |
| 247 | | − for (i = 0; i < 2; i++) { |
| 229 | + for (int i = 0; i < 2; i++) |
| 248 | 230 | dst->motion_val[i] = src->motion_val[i]; |
| 249 | | − dst->ref_index[i] = src->ref_index[i]; |
| 250 | | − } |
| 251 | 231 | |
| 252 | 232 | dst->mb_width = src->mb_width; |
| 253 | 233 | dst->mb_height = src->mb_height; |
| 254 | 234 | dst->mb_stride = src->mb_stride; |
| 255 | | − |
| 256 | | − return 0; |
| 257 | 235 | } |
| 258 | 236 | |
| 259 | 237 | int ff_mpeg_ref_picture(Picture *dst, Picture *src) |
| @@ -269,9 +247,7 @@ int ff_mpeg_ref_picture(Picture *dst, Picture *src) · 9 unmodified lines |
| 269 | 247 | if (ret < 0) |
| 270 | 248 | goto fail; |
| 271 | 249 | |
| 272 | | − ret = update_picture_tables(dst, src); |
| 273 | | − if (ret < 0) |
| 274 | | − goto fail; |
| 250 | + update_picture_tables(dst, src); |
| 275 | 251 | |
| 276 | 252 | ff_refstruct_replace(&dst->hwaccel_picture_private, |
| 277 | 253 | src->hwaccel_picture_private); |