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