Commit 62fc41ad authored by Sebastien Alaiwan's avatar Sebastien Alaiwan
Browse files

Reduce scope of local variables

Change-Id: I702240cde0bd3befa196d722311003758b507c04
parent 1fd71059
...@@ -1016,9 +1016,6 @@ static void pick_quickcompress_mode(aom_codec_alg_priv_t *ctx, ...@@ -1016,9 +1016,6 @@ static void pick_quickcompress_mode(aom_codec_alg_priv_t *ctx,
// #define TEST_SUPPLEMENTAL_SUPERFRAME_DATA // #define TEST_SUPPLEMENTAL_SUPERFRAME_DATA
static int write_superframe_index(aom_codec_alg_priv_t *ctx) { static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
uint8_t marker = 0xc0; uint8_t marker = 0xc0;
unsigned int mask;
int mag, index_sz;
int i;
size_t max_frame_sz = 0; size_t max_frame_sz = 0;
assert(ctx->pending_frame_count); assert(ctx->pending_frame_count);
...@@ -1026,12 +1023,14 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) { ...@@ -1026,12 +1023,14 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
// Add the number of frames to the marker byte // Add the number of frames to the marker byte
marker |= ctx->pending_frame_count - 1; marker |= ctx->pending_frame_count - 1;
for (i = 0; i < ctx->pending_frame_count - 1; i++) { for (int i = 0; i < ctx->pending_frame_count - 1; i++) {
const size_t frame_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1; const size_t frame_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1;
max_frame_sz = frame_sz > max_frame_sz ? frame_sz : max_frame_sz; max_frame_sz = frame_sz > max_frame_sz ? frame_sz : max_frame_sz;
} }
// Choose the magnitude // Choose the magnitude
int mag;
unsigned int mask;
for (mag = 0, mask = 0xff; mag < 4; mag++) { for (mag = 0, mask = 0xff; mag < 4; mag++) {
if (max_frame_sz <= mask) break; if (max_frame_sz <= mask) break;
mask <<= 8; mask <<= 8;
...@@ -1040,7 +1039,7 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) { ...@@ -1040,7 +1039,7 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
marker |= mag << 3; marker |= mag << 3;
// Write the index // Write the index
index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - 1); const int index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - 1);
if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) { if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) {
uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz; uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz;
#ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
...@@ -1051,7 +1050,7 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) { ...@@ -1051,7 +1050,7 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
marker_test |= frames_test - 1; marker_test |= frames_test - 1;
marker_test |= (mag_test - 1) << 3; marker_test |= (mag_test - 1) << 3;
*x++ = marker_test; *x++ = marker_test;
for (i = 0; i < mag_test * frames_test; ++i) for (int i = 0; i < mag_test * frames_test; ++i)
*x++ = 0; // fill up with arbitrary data *x++ = 0; // fill up with arbitrary data
*x++ = marker_test; *x++ = marker_test;
ctx->pending_cx_data_sz += index_sz_test; ctx->pending_cx_data_sz += index_sz_test;
...@@ -1059,13 +1058,10 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) { ...@@ -1059,13 +1058,10 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
#endif #endif
*x++ = marker; *x++ = marker;
for (i = 0; i < ctx->pending_frame_count - 1; i++) { for (int i = 0; i < ctx->pending_frame_count - 1; i++) {
unsigned int this_sz;
int j;
assert(ctx->pending_frame_sizes[i] > 0); assert(ctx->pending_frame_sizes[i] > 0);
this_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1; unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1;
for (j = 0; j <= mag; j++) { for (int j = 0; j <= mag; j++) {
*x++ = this_sz & 0xff; *x++ = this_sz & 0xff;
this_sz >>= 8; this_sz >>= 8;
} }
...@@ -1112,10 +1108,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1112,10 +1108,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
unsigned long deadline) { unsigned long deadline) {
const size_t kMinCompressedSize = 8192; const size_t kMinCompressedSize = 8192;
volatile aom_codec_err_t res = AOM_CODEC_OK; volatile aom_codec_err_t res = AOM_CODEC_OK;
volatile aom_enc_frame_flags_t flags = enc_flags;
AV1_COMP *const cpi = ctx->cpi; AV1_COMP *const cpi = ctx->cpi;
const aom_rational_t *const timebase = &ctx->cfg.g_timebase; const aom_rational_t *const timebase = &ctx->cfg.g_timebase;
size_t data_sz;
if (cpi == NULL) return AOM_CODEC_INVALID_PARAM; if (cpi == NULL) return AOM_CODEC_INVALID_PARAM;
...@@ -1125,14 +1119,15 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1125,14 +1119,15 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
// failure condition, encoder setup is done fully in init() currently. // failure condition, encoder setup is done fully in init() currently.
if (res == AOM_CODEC_OK) { if (res == AOM_CODEC_OK) {
#if CONFIG_EXT_REFS #if CONFIG_EXT_REFS
data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) * size_t data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) *
ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img); ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img);
#else #else
// There's no codec control for multiple alt-refs so check the encoder // There's no codec control for multiple alt-refs so check the encoder
// instance for its status to determine the compressed data size. // instance for its status to determine the compressed data size.
data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) * size_t data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) *
ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img) / 8 * ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) *
(cpi->multi_arf_allowed ? 8 : 2); get_image_bps(img) / 8 *
(cpi->multi_arf_allowed ? 8 : 2);
#endif // CONFIG_EXT_REFS #endif // CONFIG_EXT_REFS
if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize; if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize;
if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) { if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
...@@ -1149,6 +1144,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1149,6 +1144,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
pick_quickcompress_mode(ctx, deadline); pick_quickcompress_mode(ctx, deadline);
aom_codec_pkt_list_init(&ctx->pkt_list); aom_codec_pkt_list_init(&ctx->pkt_list);
volatile aom_enc_frame_flags_t flags = enc_flags;
// Handle Flags // Handle Flags
if (((flags & AOM_EFLAG_NO_UPD_GF) && (flags & AOM_EFLAG_FORCE_GF)) || if (((flags & AOM_EFLAG_NO_UPD_GF) && (flags & AOM_EFLAG_FORCE_GF)) ||
((flags & AOM_EFLAG_NO_UPD_ARF) && (flags & AOM_EFLAG_FORCE_ARF))) { ((flags & AOM_EFLAG_NO_UPD_ARF) && (flags & AOM_EFLAG_FORCE_ARF))) {
...@@ -1176,18 +1173,15 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1176,18 +1173,15 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
} }
if (res == AOM_CODEC_OK) { if (res == AOM_CODEC_OK) {
unsigned int lib_flags = 0;
YV12_BUFFER_CONFIG sd;
int64_t dst_time_stamp = timebase_units_to_ticks(timebase, pts); int64_t dst_time_stamp = timebase_units_to_ticks(timebase, pts);
int64_t dst_end_time_stamp = int64_t dst_end_time_stamp =
timebase_units_to_ticks(timebase, pts + duration); timebase_units_to_ticks(timebase, pts + duration);
size_t size, cx_data_sz;
unsigned char *cx_data;
// Set up internal flags // Set up internal flags
if (ctx->base.init_flags & AOM_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1; if (ctx->base.init_flags & AOM_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1;
if (img != NULL) { if (img != NULL) {
YV12_BUFFER_CONFIG sd;
res = image2yuvconfig(img, &sd); res = image2yuvconfig(img, &sd);
// Store the original flags in to the frame buffer. Will extract the // Store the original flags in to the frame buffer. Will extract the
...@@ -1199,8 +1193,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1199,8 +1193,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
ctx->next_frame_flags = 0; ctx->next_frame_flags = 0;
} }
cx_data = ctx->cx_data; unsigned char *cx_data = ctx->cx_data;
cx_data_sz = ctx->cx_data_sz; size_t cx_data_sz = ctx->cx_data_sz;
/* Any pending invisible frames? */ /* Any pending invisible frames? */
if (ctx->pending_cx_data) { if (ctx->pending_cx_data) {
...@@ -1219,6 +1213,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1219,6 +1213,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
} }
} }
size_t size;
unsigned int lib_flags = 0;
while (cx_data_sz >= ctx->cx_data_sz / 2 && while (cx_data_sz >= ctx->cx_data_sz / 2 &&
-1 != av1_get_compressed_data(cpi, &lib_flags, &size, cx_data, -1 != av1_get_compressed_data(cpi, &lib_flags, &size, cx_data,
&dst_time_stamp, &dst_end_time_stamp, &dst_time_stamp, &dst_end_time_stamp,
...@@ -1230,8 +1226,6 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1230,8 +1226,6 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
} }
#endif #endif
if (size) { if (size) {
aom_codec_cx_pkt_t pkt;
// Pack invisible frames with the next visible frame // Pack invisible frames with the next visible frame
if (!cpi->common.show_frame) { if (!cpi->common.show_frame) {
if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data; if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data;
...@@ -1244,6 +1238,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -1244,6 +1238,8 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
} }
// Add the frame packet to the list of returned packets. // Add the frame packet to the list of returned packets.
aom_codec_cx_pkt_t pkt;
pkt.kind = AOM_CODEC_CX_FRAME_PKT; pkt.kind = AOM_CODEC_CX_FRAME_PKT;
pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp); pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp);
pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units( pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units(
......
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