avcodec/hap: pass texture-compression destination as argument, not in context
This allows a subsequent change to compress directly into the output packet when possible. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Tom Butterworth <bangnoise@gmail.com>
This commit is contained in:
@ -52,12 +52,14 @@ enum HapHeaderLength {
|
|||||||
HAP_HDR_LONG = 8,
|
HAP_HDR_LONG = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void compress_texture(AVCodecContext *avctx, const AVFrame *f)
|
static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, const AVFrame *f)
|
||||||
{
|
{
|
||||||
HapContext *ctx = avctx->priv_data;
|
HapContext *ctx = avctx->priv_data;
|
||||||
uint8_t *out = ctx->tex_buf;
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
if (ctx->tex_size > out_length)
|
||||||
|
return AVERROR_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
for (j = 0; j < avctx->height; j += 4) {
|
for (j = 0; j < avctx->height; j += 4) {
|
||||||
for (i = 0; i < avctx->width; i += 4) {
|
for (i = 0; i < avctx->width; i += 4) {
|
||||||
uint8_t *p = f->data[0] + i * 4 + j * f->linesize[0];
|
uint8_t *p = f->data[0] + i * 4 + j * f->linesize[0];
|
||||||
@ -65,6 +67,8 @@ static void compress_texture(AVCodecContext *avctx, const AVFrame *f)
|
|||||||
out += step;
|
out += step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* section_length does not include the header */
|
/* section_length does not include the header */
|
||||||
@ -201,7 +205,9 @@ static int hap_encode(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* DXTC compression. */
|
/* DXTC compression. */
|
||||||
compress_texture(avctx, frame);
|
ret = compress_texture(avctx, ctx->tex_buf, ctx->tex_size, frame);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* Compress (using Snappy) the frame */
|
/* Compress (using Snappy) the frame */
|
||||||
final_data_size = hap_compress_frame(avctx, pkt->data + header_length);
|
final_data_size = hap_compress_frame(avctx, pkt->data + header_length);
|
||||||
|
Reference in New Issue
Block a user