Revision a75529e8 libavcodec/mimic.c

View differences:

libavcodec/mimic.c
27 27
#include "get_bits.h"
28 28
#include "bytestream.h"
29 29
#include "dsputil.h"
30
#include "thread.h"
30 31

  
31 32
#define MIMIC_HEADER_SIZE   20
32 33

  
......
51 52
    ScanTable       scantable;
52 53
    DSPContext      dsp;
53 54
    VLC             vlc;
55

  
56
    /* Kept in the context so multithreading can have a constant to read from */
57
    int             next_cur_index;
58
    int             next_prev_index;
54 59
} MimicContext;
55 60

  
56 61
static const uint32_t huffcodes[] = {
......
121 126
    return 0;
122 127
}
123 128

  
129
static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from)
130
{
131
    MimicContext *dst = avctx->priv_data, *src = avctx_from->priv_data;
132

  
133
    if (avctx == avctx_from) return 0;
134

  
135
    dst->cur_index  = src->next_cur_index;
136
    dst->prev_index = src->next_prev_index;
137

  
138
    memcpy(dst->buf_ptrs, src->buf_ptrs, sizeof(src->buf_ptrs));
139
    memcpy(dst->flipped_ptrs, src->flipped_ptrs, sizeof(src->flipped_ptrs));
140

  
141
    memset(&dst->buf_ptrs[dst->cur_index], 0, sizeof(AVFrame));
142

  
143
    return 0;
144
}
145

  
124 146
static const int8_t vlcdec_lookup[9][64] = {
125 147
    {    0, },
126 148
    {   -1,   1, },
......
205 227
static int decode(MimicContext *ctx, int quality, int num_coeffs,
206 228
                  int is_iframe)
207 229
{
208
    int y, x, plane;
230
    int y, x, plane, cur_row = 0;
209 231

  
210 232
    for(plane = 0; plane < 3; plane++) {
211 233
        const int is_chroma = !!plane;
......
236 258
                        int index = (ctx->cur_index+backref)&15;
237 259
                        uint8_t *p = ctx->flipped_ptrs[index].data[0];
238 260

  
261
                        ff_thread_await_progress(&ctx->buf_ptrs[index], cur_row, 0);
239 262
                        if(p) {
240 263
                            p += src -
241 264
                                ctx->flipped_ptrs[ctx->prev_index].data[plane];
......
246 269
                        }
247 270
                    }
248 271
                } else {
272
                    ff_thread_await_progress(&ctx->buf_ptrs[ctx->prev_index], cur_row, 0);
249 273
                    ctx->dsp.put_pixels_tab[1][0](dst, src, stride, 8);
250 274
                }
251 275
                src += 8;
......
253 277
            }
254 278
            src += (stride - ctx->num_hblocks[plane])<<3;
255 279
            dst += (stride - ctx->num_hblocks[plane])<<3;
280

  
281
            ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], cur_row++, 0);
256 282
        }
257 283
    }
258 284

  
......
326 352
    }
327 353

  
328 354
    ctx->buf_ptrs[ctx->cur_index].reference = 1;
329
    if(avctx->get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) {
355
    ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? FF_P_TYPE:FF_I_TYPE;
356
    if(ff_thread_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) {
330 357
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
331 358
        return -1;
332 359
    }
333 360

  
361
    ctx->next_prev_index = ctx->cur_index;
362
    ctx->next_cur_index  = (ctx->cur_index - 1) & 15;
363

  
334 364
    prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index],
335 365
                  (AVPicture*) &ctx->buf_ptrs[ctx->cur_index]);
336 366

  
367
    ff_thread_finish_setup(avctx);
368

  
337 369
    av_fast_malloc(&ctx->swap_buf, &ctx->swap_buf_size,
338 370
                                 swap_buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
339 371
    if(!ctx->swap_buf)
......
345 377
    init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3);
346 378

  
347 379
    if(!decode(ctx, quality, num_coeffs, !is_pframe)) {
348
        avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
349
        return -1;
380
        if (avctx->active_thread_type&FF_THREAD_FRAME)
381
            ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], INT_MAX, 0);
382
        else {
383
            ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
384
            return -1;
385
        }
350 386
    }
351 387

  
352
    ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? FF_P_TYPE:FF_I_TYPE;
353 388
    *(AVFrame*)data = ctx->buf_ptrs[ctx->cur_index];
354 389
    *data_size = sizeof(AVFrame);
355 390

  
356
    ctx->prev_index = ctx->cur_index;
357
    ctx->cur_index--;
358
    ctx->cur_index &= 15;
391
    ctx->prev_index = ctx->next_prev_index;
392
    ctx->cur_index  = ctx->next_cur_index;
359 393

  
360 394
    /* Only release frames that aren't used for backreferences anymore */
361 395
    if(ctx->buf_ptrs[ctx->cur_index].data[0])
362
        avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
396
        ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
363 397

  
364 398
    return buf_size;
365 399
}
......
370 404
    int i;
371 405

  
372 406
    av_free(ctx->swap_buf);
407

  
408
    if(avctx->is_copy) return 0;
409

  
373 410
    for(i = 0; i < 16; i++)
374 411
        if(ctx->buf_ptrs[i].data[0])
375
            avctx->release_buffer(avctx, &ctx->buf_ptrs[i]);
412
            ff_thread_release_buffer(avctx, &ctx->buf_ptrs[i]);
376 413
    free_vlc(&ctx->vlc);
377 414

  
378 415
    return 0;
......
387 424
    NULL,
388 425
    mimic_decode_end,
389 426
    mimic_decode_frame,
390
    CODEC_CAP_DR1,
427
    CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
391 428
    .long_name = NULL_IF_CONFIG_SMALL("Mimic"),
429
    .update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context)
392 430
};

Also available in: Unified diff