~ubuntu-branches/ubuntu/utopic/libav/utopic-proposed

« back to all changes in this revision

Viewing changes to libavcodec/svq1enc.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler, Reinhard Tartler, Rico Tzschichholz
  • Date: 2014-08-30 11:02:45 UTC
  • mfrom: (1.3.47 sid)
  • Revision ID: package-import@ubuntu.com-20140830110245-io3dg7q85wfr7125
Tags: 6:11~beta1-2
[ Reinhard Tartler ]
* Make libavcodec-dev depend on libavresample-dev

[ Rico Tzschichholz ]
* Some fixes and leftovers from soname bumps

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 */
28
28
 
29
29
#include "avcodec.h"
30
 
#include "dsputil.h"
31
30
#include "hpeldsp.h"
 
31
#include "me_cmp.h"
32
32
#include "mpegvideo.h"
33
33
#include "h263.h"
34
34
#include "internal.h"
 
35
#include "mpegutils.h"
35
36
#include "svq1.h"
 
37
#include "svq1enc.h"
36
38
#include "svq1enc_cb.h"
37
39
 
38
40
#undef NDEBUG
39
41
#include <assert.h>
40
42
 
41
 
typedef struct SVQ1Context {
42
 
    /* FIXME: Needed for motion estimation, should not be used for anything
43
 
     * else, the idea is to make the motion estimation eventually independent
44
 
     * of MpegEncContext, so this will be removed then. */
45
 
    MpegEncContext m;
46
 
    AVCodecContext *avctx;
47
 
    DSPContext dsp;
48
 
    HpelDSPContext hdsp;
49
 
    AVFrame *current_picture;
50
 
    AVFrame *last_picture;
51
 
    PutBitContext pb;
52
 
    GetBitContext gb;
53
 
 
54
 
    /* why ooh why this sick breadth first order,
55
 
     * everything is slower and more complex */
56
 
    PutBitContext reorder_pb[6];
57
 
 
58
 
    int frame_width;
59
 
    int frame_height;
60
 
 
61
 
    /* Y plane block dimensions */
62
 
    int y_block_width;
63
 
    int y_block_height;
64
 
 
65
 
    /* U & V plane (C planes) block dimensions */
66
 
    int c_block_width;
67
 
    int c_block_height;
68
 
 
69
 
    uint16_t *mb_type;
70
 
    uint32_t *dummy;
71
 
    int16_t (*motion_val8[3])[2];
72
 
    int16_t (*motion_val16[3])[2];
73
 
 
74
 
    int64_t rd_total;
75
 
 
76
 
    uint8_t *scratchbuf;
77
 
} SVQ1Context;
78
 
 
79
 
static void svq1_write_header(SVQ1Context *s, int frame_type)
 
43
static void svq1_write_header(SVQ1EncContext *s, int frame_type)
80
44
{
81
45
    int i;
82
46
 
113
77
#define QUALITY_THRESHOLD    100
114
78
#define THRESHOLD_MULTIPLIER 0.6
115
79
 
116
 
static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref,
 
80
static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
 
81
                               int size)
 
82
{
 
83
    int score = 0, i;
 
84
 
 
85
    for (i = 0; i < size; i++)
 
86
        score += (pix1[i] - pix2[i]) * (pix1[i] - pix2[i]);
 
87
    return score;
 
88
}
 
89
 
 
90
static int encode_block(SVQ1EncContext *s, uint8_t *src, uint8_t *ref,
117
91
                        uint8_t *decoded, int stride, int level,
118
92
                        int threshold, int lambda, int intra)
119
93
{
174
148
                int sqr, diff, score;
175
149
 
176
150
                vector = codebook + stage * size * 16 + i * size;
177
 
                sqr    = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
 
151
                sqr    = s->ssd_int8_vs_int16(vector, block[stage], size);
178
152
                diff   = block_sum[stage] - sum;
179
153
                score  = sqr - (diff * (int64_t)diff >> (level + 3)); // FIXME: 64bit slooow
180
154
                if (score < best_vector_score) {
258
232
    return best_score;
259
233
}
260
234
 
261
 
static int svq1_encode_plane(SVQ1Context *s, int plane,
 
235
static int svq1_encode_plane(SVQ1EncContext *s, int plane,
262
236
                             unsigned char *src_plane,
263
237
                             unsigned char *ref_plane,
264
238
                             unsigned char *decoded_plane,
286
260
        s->m.avctx                         = s->avctx;
287
261
        s->m.current_picture_ptr           = &s->m.current_picture;
288
262
        s->m.last_picture_ptr              = &s->m.last_picture;
289
 
        s->m.last_picture.f.data[0]        = ref_plane;
 
263
        s->m.last_picture.f->data[0]        = ref_plane;
290
264
        s->m.linesize                      =
291
 
        s->m.last_picture.f.linesize[0]    =
292
 
        s->m.new_picture.f.linesize[0]     =
293
 
        s->m.current_picture.f.linesize[0] = stride;
 
265
        s->m.last_picture.f->linesize[0]    =
 
266
        s->m.new_picture.f->linesize[0]     =
 
267
        s->m.current_picture.f->linesize[0] = stride;
294
268
        s->m.width                         = width;
295
269
        s->m.height                        = height;
296
270
        s->m.mb_width                      = block_width;
332
306
        s->m.current_picture.motion_val[0]   = s->motion_val8[plane] + 2;
333
307
        s->m.p_mv_table                      = s->motion_val16[plane] +
334
308
                                               s->m.mb_stride + 1;
335
 
        s->m.dsp                             = s->dsp; // move
 
309
        s->m.mecc                            = s->mecc; // move
336
310
        ff_init_me(&s->m);
337
311
 
338
312
        s->m.me.dia_size      = s->avctx->dia_size;
339
313
        s->m.first_slice_line = 1;
340
314
        for (y = 0; y < block_height; y++) {
341
 
            s->m.new_picture.f.data[0] = src - y * 16 * stride; // ugly
 
315
            s->m.new_picture.f->data[0] = src - y * 16 * stride; // ugly
342
316
            s->m.mb_y                  = y;
343
317
 
344
318
            for (i = 0; i < 16 && i + 16 * y < height; i++) {
457
431
                    best      = score[1] <= score[0];
458
432
 
459
433
                    vlc       = ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
460
 
                    score[2]  = s->dsp.sse[0](NULL, src + 16 * x, ref,
461
 
                                              stride, 16);
 
434
                    score[2]  = s->mecc.sse[0](NULL, src + 16 * x, ref,
 
435
                                               stride, 16);
462
436
                    score[2] += vlc[1] * lambda;
463
437
                    if (score[2] < score[best] && mx == 0 && my == 0) {
464
438
                        best = 2;
501
475
 
502
476
static av_cold int svq1_encode_end(AVCodecContext *avctx)
503
477
{
504
 
    SVQ1Context *const s = avctx->priv_data;
 
478
    SVQ1EncContext *const s = avctx->priv_data;
505
479
    int i;
506
480
 
507
481
    av_log(avctx, AV_LOG_DEBUG, "RD: %f\n",
508
482
           s->rd_total / (double)(avctx->width * avctx->height *
509
483
                                  avctx->frame_number));
510
484
 
 
485
    s->m.mb_type = NULL;
 
486
    ff_mpv_common_end(&s->m);
 
487
 
511
488
    av_freep(&s->m.me.scratchpad);
512
489
    av_freep(&s->m.me.map);
513
490
    av_freep(&s->m.me.score_map);
529
506
 
530
507
static av_cold int svq1_encode_init(AVCodecContext *avctx)
531
508
{
532
 
    SVQ1Context *const s = avctx->priv_data;
 
509
    SVQ1EncContext *const s = avctx->priv_data;
 
510
    int ret;
533
511
 
534
 
    ff_dsputil_init(&s->dsp, avctx);
535
512
    ff_hpeldsp_init(&s->hdsp, avctx->flags);
 
513
    ff_me_cmp_init(&s->mecc, avctx);
 
514
    ff_mpegvideoencdsp_init(&s->m.mpvencdsp, avctx);
536
515
 
537
516
    avctx->coded_frame = av_frame_alloc();
538
517
    s->current_picture = av_frame_alloc();
553
532
 
554
533
    s->avctx               = avctx;
555
534
    s->m.avctx             = avctx;
 
535
 
 
536
    if ((ret = ff_mpv_common_init(&s->m)) < 0) {
 
537
        svq1_encode_end(avctx);
 
538
        return ret;
 
539
    }
 
540
 
556
541
    s->m.picture_structure = PICT_FRAME;
557
542
    s->m.me.temp           =
558
543
    s->m.me.scratchpad     = av_mallocz((avctx->width + 64) *
563
548
                                        s->y_block_height * sizeof(int16_t));
564
549
    s->dummy               = av_mallocz((s->y_block_width + 1) *
565
550
                                        s->y_block_height * sizeof(int32_t));
 
551
    s->ssd_int8_vs_int16   = ssd_int8_vs_int16_c;
 
552
 
 
553
    if (ARCH_PPC)
 
554
        ff_svq1enc_init_ppc(s);
 
555
    if (ARCH_X86)
 
556
        ff_svq1enc_init_x86(s);
 
557
 
566
558
    ff_h263_encode_init(&s->m); // mv_penalty
567
559
 
568
560
    return 0;
571
563
static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
572
564
                             const AVFrame *pict, int *got_packet)
573
565
{
574
 
    SVQ1Context *const s = avctx->priv_data;
575
 
    AVFrame *const p     = avctx->coded_frame;
 
566
    SVQ1EncContext *const s = avctx->priv_data;
 
567
    AVFrame *const p        = avctx->coded_frame;
576
568
    int i, ret;
577
569
 
578
570
    if (!pkt->data &&
633
625
    .long_name      = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
634
626
    .type           = AVMEDIA_TYPE_VIDEO,
635
627
    .id             = AV_CODEC_ID_SVQ1,
636
 
    .priv_data_size = sizeof(SVQ1Context),
 
628
    .priv_data_size = sizeof(SVQ1EncContext),
637
629
    .init           = svq1_encode_init,
638
630
    .encode2        = svq1_encode_frame,
639
631
    .close          = svq1_encode_end,