~siretart/libav/trusty

« back to all changes in this revision

Viewing changes to libavcodec/roqvideoenc.c

  • Committer: Reinhard Tartler
  • Date: 2013-10-23 03:04:17 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: siretart@tauware.de-20131023030417-1o6mpkl1l0raifjt
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include "roqvideo.h"
60
60
#include "bytestream.h"
61
61
#include "elbg.h"
 
62
#include "internal.h"
62
63
#include "mathops.h"
63
64
 
64
65
#define CHROMA_BIAS 1
112
113
    return x*x;
113
114
}
114
115
 
115
 
static inline int eval_sse(uint8_t *a, uint8_t *b, int count)
 
116
static inline int eval_sse(const uint8_t *a, const uint8_t *b, int count)
116
117
{
117
118
    int diff=0;
118
119
 
124
125
 
125
126
// FIXME Could use DSPContext.sse, but it is not so speed critical (used
126
127
// just for motion estimation).
127
 
static int block_sse(uint8_t **buf1, uint8_t **buf2, int x1, int y1, int x2,
128
 
                     int y2, int *stride1, int *stride2, int size)
 
128
static int block_sse(uint8_t * const *buf1, uint8_t * const *buf2, int x1, int y1,
 
129
                     int x2, int y2, const int *stride1, const int *stride2, int size)
129
130
{
130
131
    int i, k;
131
132
    int sse=0;
260
261
/**
261
262
 * Get macroblocks from parts of the image
262
263
 */
263
 
static void get_frame_mb(AVFrame *frame, int x, int y, uint8_t mb[], int dim)
 
264
static void get_frame_mb(const AVFrame *frame, int x, int y, uint8_t mb[], int dim)
264
265
{
265
266
    int i, j, cp;
266
267
 
754
755
/**
755
756
 * Create a single YUV cell from a 2x2 section of the image
756
757
 */
757
 
static inline void frame_block_to_cell(uint8_t *block, uint8_t **data,
758
 
                                       int top, int left, int *stride)
 
758
static inline void frame_block_to_cell(uint8_t *block, uint8_t * const *data,
 
759
                                       int top, int left, const int *stride)
759
760
{
760
761
    int i, j, u=0, v=0;
761
762
 
775
776
/**
776
777
 * Create YUV clusters for the entire image
777
778
 */
778
 
static void create_clusters(AVFrame *frame, int w, int h, uint8_t *yuvClusters)
 
779
static void create_clusters(const AVFrame *frame, int w, int h, uint8_t *yuvClusters)
779
780
{
780
781
    int i, j, k, l;
781
782
 
1001
1002
    bytestream_put_byte(&enc->out_buf, 0x00);
1002
1003
}
1003
1004
 
1004
 
static int roq_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
 
1005
static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
1006
                            const AVFrame *frame, int *got_packet)
1005
1007
{
1006
1008
    RoqContext *enc = avctx->priv_data;
1007
 
    AVFrame *frame= data;
1008
 
    uint8_t *buf_start = buf;
 
1009
    int size, ret;
1009
1010
 
1010
 
    enc->out_buf = buf;
1011
1011
    enc->avctx = avctx;
1012
1012
 
1013
1013
    enc->frame_to_enc = frame;
1019
1019
 
1020
1020
    /* 138 bits max per 8x8 block +
1021
1021
     *     256 codebooks*(6 bytes 2x2 + 4 bytes 4x4) + 8 bytes frame header */
1022
 
    if (((enc->width*enc->height/64)*138+7)/8 + 256*(6+4) + 8 > buf_size) {
1023
 
        av_log(avctx, AV_LOG_ERROR, "  RoQ: Output buffer too small!\n");
1024
 
        return -1;
 
1022
    size = ((enc->width * enc->height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
 
1023
    if ((ret = ff_alloc_packet(pkt, size)) < 0) {
 
1024
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet with size %d.\n", size);
 
1025
        return ret;
1025
1026
    }
 
1027
    enc->out_buf = pkt->data;
1026
1028
 
1027
1029
    /* Check for I frame */
1028
1030
    if (enc->framesSinceKeyframe == avctx->gop_size)
1031
1033
    if (enc->first_frame) {
1032
1034
        /* Alloc memory for the reconstruction data (we must know the stride
1033
1035
         for that) */
1034
 
        if (avctx->get_buffer(avctx, enc->current_frame) ||
1035
 
            avctx->get_buffer(avctx, enc->last_frame)) {
 
1036
        if (ff_get_buffer(avctx, enc->current_frame) ||
 
1037
            ff_get_buffer(avctx, enc->last_frame)) {
1036
1038
            av_log(avctx, AV_LOG_ERROR, "  RoQ: get_buffer() failed\n");
1037
1039
            return -1;
1038
1040
        }
1046
1048
    /* Encode the actual frame */
1047
1049
    roq_encode_video(enc);
1048
1050
 
1049
 
    return enc->out_buf - buf_start;
 
1051
    pkt->size   = enc->out_buf - pkt->data;
 
1052
    if (enc->framesSinceKeyframe == 1)
 
1053
        pkt->flags |= AV_PKT_FLAG_KEY;
 
1054
    *got_packet = 1;
 
1055
 
 
1056
    return 0;
1050
1057
}
1051
1058
 
1052
1059
static int roq_encode_end(AVCodecContext *avctx)
1068
1075
AVCodec ff_roq_encoder = {
1069
1076
    .name                 = "roqvideo",
1070
1077
    .type                 = AVMEDIA_TYPE_VIDEO,
1071
 
    .id                   = CODEC_ID_ROQ,
 
1078
    .id                   = AV_CODEC_ID_ROQ,
1072
1079
    .priv_data_size       = sizeof(RoqContext),
1073
1080
    .init                 = roq_encode_init,
1074
 
    .encode               = roq_encode_frame,
 
1081
    .encode2              = roq_encode_frame,
1075
1082
    .close                = roq_encode_end,
1076
 
    .supported_framerates = (const AVRational[]){{30,1}, {0,0}},
1077
 
    .pix_fmts             = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE},
 
1083
    .supported_framerates = (const AVRational[]){ {30,1}, {0,0} },
 
1084
    .pix_fmts             = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV444P,
 
1085
                                                        AV_PIX_FMT_NONE },
1078
1086
    .long_name            = NULL_IF_CONFIG_SMALL("id RoQ video"),
1079
1087
};