Commit e4c6fc18 authored by Sebastien Alaiwan's avatar Sebastien Alaiwan

Encode superframes in front

This moves the superframe index at the beginning of the frame packet.
There's no change in the superframe index format, and it's still
optional.

BUG=aomedia:22

Change-Id: I1488429bd114c220ed110be34baee19191ff730e
parent 627e2fd5
......@@ -1069,7 +1069,11 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
const size_t index_sz = x - buffer;
assert(ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz);
memcpy(ctx->pending_cx_data + ctx->pending_cx_data_sz, buffer, index_sz);
// move the frame to make room for the index
memmove(ctx->pending_cx_data + index_sz, ctx->pending_cx_data,
ctx->pending_cx_data_sz);
memcpy(ctx->pending_cx_data, buffer, index_sz);
ctx->pending_cx_data_sz += index_sz;
return (int)index_sz;
......
......@@ -625,10 +625,14 @@ static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx,
if (res != AOM_CODEC_OK) return res;
}
int index_size = 0;
res = av1_parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
ctx->decrypt_cb, ctx->decrypt_state);
&index_size, ctx->decrypt_cb,
ctx->decrypt_state);
if (res != AOM_CODEC_OK) return res;
data_start += index_size;
if (ctx->frame_parallel_decode) {
// Decode in frame parallel mode. When decoding in this mode, the frame
// passed to the decoder must be either a normal frame or a superframe with
......
......@@ -520,6 +520,7 @@ int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) {
aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
uint32_t sizes[8], int *count,
int *index_size,
aom_decrypt_cb decrypt_cb,
void *decrypt_state) {
// A chunk ending with a byte matching 0xc0 is an invalid chunk unless
......@@ -532,13 +533,14 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
size_t frame_sz_sum = 0;
assert(data_sz);
marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
marker = read_marker(decrypt_cb, decrypt_state, data);
*count = 0;
if ((marker & 0xe0) == 0xc0) {
const uint32_t frames = (marker & 0x7) + 1;
const uint32_t mag = ((marker >> 3) & 0x3) + 1;
const size_t index_sz = 2 + mag * (frames - 1);
*index_size = (int)index_sz;
// This chunk is marked as having a superframe index but doesn't have
// enough data for it, thus it's an invalid superframe index.
......@@ -546,7 +548,7 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
{
const uint8_t marker2 =
read_marker(decrypt_cb, decrypt_state, data + data_sz - index_sz);
read_marker(decrypt_cb, decrypt_state, data + index_sz - 1);
// This chunk is marked as having a superframe index but doesn't have
// the matching marker byte at the front of the index therefore it's an
......@@ -557,7 +559,7 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
{
// Found a valid superframe index.
uint32_t i, j;
const uint8_t *x = &data[data_sz - index_sz + 1];
const uint8_t *x = &data[1];
// Frames has a maximum of 8 and mag has a maximum of 4.
uint8_t clear_buffer[28];
......
......@@ -182,6 +182,7 @@ static INLINE uint8_t read_marker(aom_decrypt_cb decrypt_cb,
// "read_marker".
aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
uint32_t sizes[8], int *count,
int *index_size,
aom_decrypt_cb decrypt_cb,
void *decrypt_state);
......
......@@ -63,16 +63,17 @@ class SuperframeTest
if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return pkt;
const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf);
const uint8_t marker = buffer[pkt->data.frame.sz - 1];
const uint8_t marker = buffer[0];
const int frames = (marker & 0x7) + 1;
const int mag = ((marker >> 3) & 3) + 1;
const unsigned int index_sz = 2 + mag * (frames - 1);
if ((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz &&
buffer[pkt->data.frame.sz - index_sz] == marker) {
buffer[index_sz - 1] == marker) {
// frame is a superframe. strip off the index.
if (modified_buf_) delete[] modified_buf_;
delete[] modified_buf_;
modified_buf_ = new uint8_t[pkt->data.frame.sz - index_sz];
memcpy(modified_buf_, pkt->data.frame.buf, pkt->data.frame.sz - index_sz);
memcpy(modified_buf_, (uint8_t *)pkt->data.frame.buf + index_sz,
pkt->data.frame.sz - index_sz);
modified_pkt_ = *pkt;
modified_pkt_.data.frame.buf = modified_buf_;
modified_pkt_.data.frame.sz -= index_sz;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment