~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/a64multienc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "a64colors.h"
29
29
#include "a64tables.h"
30
30
#include "elbg.h"
 
31
#include "internal.h"
 
32
#include "libavutil/common.h"
31
33
#include "libavutil/intreadwrite.h"
32
34
 
33
35
#define DITHERSTEPS   8
186
188
    av_log(avctx, AV_LOG_INFO, "charset lifetime set to %d frame(s)\n", c->mc_lifetime);
187
189
 
188
190
    c->mc_frame_counter = 0;
189
 
    c->mc_use_5col      = avctx->codec->id == CODEC_ID_A64_MULTI5;
 
191
    c->mc_use_5col      = avctx->codec->id == AV_CODEC_ID_A64_MULTI5;
190
192
    c->mc_pal_size      = 4 + c->mc_use_5col;
191
193
 
192
194
    /* precalc luma values for later use */
221
223
    if (!avctx->codec_tag)
222
224
         avctx->codec_tag = AV_RL32("a64m");
223
225
 
 
226
    c->next_pts = AV_NOPTS_VALUE;
 
227
 
224
228
    return 0;
225
229
}
226
230
 
239
243
    }
240
244
}
241
245
 
242
 
static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
243
 
                                 int buf_size, void *data)
 
246
static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
247
                                 const AVFrame *pict, int *got_packet)
244
248
{
245
249
    A64Context *c = avctx->priv_data;
246
 
    AVFrame *pict = data;
247
 
    AVFrame *const p = (AVFrame *) & c->picture;
 
250
    AVFrame *const p = &c->picture;
248
251
 
249
252
    int frame;
250
253
    int x, y;
251
254
    int b_height;
252
255
    int b_width;
253
256
 
254
 
    int req_size;
 
257
    int req_size, ret;
 
258
    uint8_t *buf;
255
259
 
256
260
    int *charmap     = c->mc_charmap;
257
261
    uint8_t *colram  = c->mc_colram;
274
278
    }
275
279
 
276
280
    /* no data, means end encoding asap */
277
 
    if (!data) {
 
281
    if (!pict) {
278
282
        /* all done, end encoding */
279
283
        if (!c->mc_lifetime) return 0;
280
284
        /* no more frames in queue, prepare to flush remaining frames */
292
296
            p->key_frame = 1;
293
297
            to_meta_with_crop(avctx, p, meta + 32000 * c->mc_frame_counter);
294
298
            c->mc_frame_counter++;
 
299
            if (c->next_pts == AV_NOPTS_VALUE)
 
300
                c->next_pts = pict->pts;
295
301
            /* lifetime is not reached so wait for next frame first */
296
302
            return 0;
297
303
        }
302
308
        req_size = 0;
303
309
        /* any frames to encode? */
304
310
        if (c->mc_lifetime) {
 
311
            req_size = charset_size + c->mc_lifetime*(screen_size + colram_size);
 
312
            if ((ret = ff_alloc_packet(pkt, req_size)) < 0) {
 
313
                av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", req_size);
 
314
                return ret;
 
315
            }
 
316
            buf = pkt->data;
 
317
 
305
318
            /* calc optimal new charset + charmaps */
306
319
            ff_init_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb, CHARSET_CHARS, 50, charmap, &c->randctx);
307
320
            ff_do_elbg  (meta, 32, 1000 * c->mc_lifetime, best_cb, CHARSET_CHARS, 50, charmap, &c->randctx);
310
323
            render_charset(avctx, charset, colram);
311
324
 
312
325
            /* copy charset to buf */
313
 
            memcpy(buf,charset, charset_size);
 
326
            memcpy(buf, charset, charset_size);
314
327
 
315
328
            /* advance pointers */
316
329
            buf      += charset_size;
317
330
            charset  += charset_size;
318
 
            req_size += charset_size;
319
331
        }
320
 
        /* no charset so clean buf */
321
 
        else memset(buf, 0, charset_size);
322
332
 
323
333
        /* write x frames to buf */
324
334
        for (frame = 0; frame < c->mc_lifetime; frame++) {
351
361
        /* reset counter */
352
362
        c->mc_frame_counter = 0;
353
363
 
354
 
        if (req_size > buf_size) {
355
 
            av_log(avctx, AV_LOG_ERROR, "buf size too small (need %d, got %d)\n", req_size, buf_size);
356
 
            return -1;
357
 
        }
358
 
        return req_size;
 
364
        pkt->pts = pkt->dts = c->next_pts;
 
365
        c->next_pts         = AV_NOPTS_VALUE;
 
366
 
 
367
        pkt->size   = req_size;
 
368
        pkt->flags |= AV_PKT_FLAG_KEY;
 
369
        *got_packet = !!req_size;
359
370
    }
360
371
    return 0;
361
372
}
363
374
AVCodec ff_a64multi_encoder = {
364
375
    .name           = "a64multi",
365
376
    .type           = AVMEDIA_TYPE_VIDEO,
366
 
    .id             = CODEC_ID_A64_MULTI,
 
377
    .id             = AV_CODEC_ID_A64_MULTI,
367
378
    .priv_data_size = sizeof(A64Context),
368
379
    .init           = a64multi_init_encoder,
369
 
    .encode         = a64multi_encode_frame,
 
380
    .encode2        = a64multi_encode_frame,
370
381
    .close          = a64multi_close_encoder,
371
 
    .pix_fmts       = (const enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_NONE},
 
382
    .pix_fmts       = (const enum AVPixelFormat[]) {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE},
372
383
    .long_name      = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64"),
373
384
    .capabilities   = CODEC_CAP_DELAY,
374
385
};
376
387
AVCodec ff_a64multi5_encoder = {
377
388
    .name           = "a64multi5",
378
389
    .type           = AVMEDIA_TYPE_VIDEO,
379
 
    .id             = CODEC_ID_A64_MULTI5,
 
390
    .id             = AV_CODEC_ID_A64_MULTI5,
380
391
    .priv_data_size = sizeof(A64Context),
381
392
    .init           = a64multi_init_encoder,
382
 
    .encode         = a64multi_encode_frame,
 
393
    .encode2        = a64multi_encode_frame,
383
394
    .close          = a64multi_close_encoder,
384
 
    .pix_fmts       = (const enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_NONE},
 
395
    .pix_fmts       = (const enum AVPixelFormat[]) {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE},
385
396
    .long_name      = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64, extended with 5th color (colram)"),
386
397
    .capabilities   = CODEC_CAP_DELAY,
387
398
};