avcodec/dnxhd: Make ff_dxnhd_get_cid_table return a pointer, not index

All callers only use the index into ff_dnxhd_cid_table to get a pointer
to the desired entry.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
pull/371/head
Andreas Rheinhardt 4 years ago
parent 37f76c81d6
commit 10d059bb24
  1. 46
      libavcodec/dnxhddata.c
  2. 4
      libavcodec/dnxhddata.h
  3. 13
      libavcodec/dnxhddec.c
  4. 8
      libavcodec/dnxhdenc.c

@ -932,7 +932,7 @@ static const uint8_t dnxhd_1250_run[62] = {
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
}; };
const CIDEntry ff_dnxhd_cid_table[] = { static const CIDEntry dnxhd_cid_table[] = {
{ 1235, 1920, 1080, 917504, 917504, { 1235, 1920, 1080, 917504, 917504,
0, 6, 10, 4, 0, 6, 10, 4,
dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight, dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight,
@ -1075,31 +1075,31 @@ const CIDEntry ff_dnxhd_cid_table[] = {
{ 0 }, { 5888, 255} }, { 0 }, { 5888, 255} },
}; };
int ff_dnxhd_get_cid_table(int cid) const CIDEntry *ff_dnxhd_get_cid_table(int cid)
{ {
int i; for (int i = 0; i < FF_ARRAY_ELEMS(dnxhd_cid_table); i++)
for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) if (dnxhd_cid_table[i].cid == cid)
if (ff_dnxhd_cid_table[i].cid == cid) return &dnxhd_cid_table[i];
return i; return NULL;
return -1;
} }
int avpriv_dnxhd_get_frame_size(int cid) int avpriv_dnxhd_get_frame_size(int cid)
{ {
int i = ff_dnxhd_get_cid_table(cid); const CIDEntry *entry = ff_dnxhd_get_cid_table(cid);
if (i<0) if (!entry)
return i; return -1;
return ff_dnxhd_cid_table[i].frame_size; return entry->frame_size;
} }
int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h) int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h)
{ {
int result, i = ff_dnxhd_get_cid_table(cid); const CIDEntry *entry = ff_dnxhd_get_cid_table(cid);
int result;
if (i < 0) if (!entry)
return i; return -1;
result = ((h + 15) / 16) * ((w + 15) / 16) * (int64_t)ff_dnxhd_cid_table[i].packet_scale.num / ff_dnxhd_cid_table[i].packet_scale.den; result = ((h + 15) / 16) * ((w + 15) / 16) * (int64_t)entry->packet_scale.num / entry->packet_scale.den;
result = (result + 2048) / 4096 * 4096; result = (result + 2048) / 4096 * 4096;
return FFMAX(result, 8192); return FFMAX(result, 8192);
@ -1107,10 +1107,10 @@ int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h)
int avpriv_dnxhd_get_interlaced(int cid) int avpriv_dnxhd_get_interlaced(int cid)
{ {
int i = ff_dnxhd_get_cid_table(cid); const CIDEntry *entry = ff_dnxhd_get_cid_table(cid);
if (i < 0) if (!entry)
return i; return -1;
return ff_dnxhd_cid_table[i].flags & DNXHD_INTERLACED ? 1 : 0; return entry->flags & DNXHD_INTERLACED ? 1 : 0;
} }
static int dnxhd_find_hr_cid(AVCodecContext *avctx) static int dnxhd_find_hr_cid(AVCodecContext *avctx)
@ -1140,8 +1140,8 @@ int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth)
if (!mbs) if (!mbs)
return 0; return 0;
for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) { for (i = 0; i < FF_ARRAY_ELEMS(dnxhd_cid_table); i++) {
const CIDEntry *cid = &ff_dnxhd_cid_table[i]; const CIDEntry *cid = &dnxhd_cid_table[i];
int interlaced = cid->flags & DNXHD_INTERLACED ? 1 : 0; int interlaced = cid->flags & DNXHD_INTERLACED ? 1 : 0;
if (cid->width == avctx->width && cid->height == avctx->height && if (cid->width == avctx->width && cid->height == avctx->height &&
interlaced == !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) && interlaced == !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) &&
@ -1163,8 +1163,8 @@ int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth)
void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel) void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel)
{ {
int i, j; int i, j;
for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) { for (i = 0; i < FF_ARRAY_ELEMS(dnxhd_cid_table); i++) {
const CIDEntry *cid = &ff_dnxhd_cid_table[i]; const CIDEntry *cid = &dnxhd_cid_table[i];
for (j = 0; j < FF_ARRAY_ELEMS(cid->bit_rates); j++) { for (j = 0; j < FF_ARRAY_ELEMS(cid->bit_rates); j++) {
if (!cid->bit_rates[j]) if (!cid->bit_rates[j])
break; break;

@ -58,9 +58,7 @@ typedef struct CIDEntry {
AVRational packet_scale; AVRational packet_scale;
} CIDEntry; } CIDEntry;
extern const CIDEntry ff_dnxhd_cid_table[]; const CIDEntry *ff_dnxhd_get_cid_table(int cid);
int ff_dnxhd_get_cid_table(int cid);
int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth); int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth);
void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel); void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel);

@ -113,18 +113,19 @@ static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid, int bitdepth) static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid, int bitdepth)
{ {
if (cid != ctx->cid) { if (cid != ctx->cid) {
int index; const CIDEntry *cid_table = ff_dnxhd_get_cid_table(cid);
if ((index = ff_dnxhd_get_cid_table(cid)) < 0) { if (!cid_table) {
av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %"PRIu32"\n", cid); av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %"PRIu32"\n", cid);
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
if (ff_dnxhd_cid_table[index].bit_depth != bitdepth && if (cid_table->bit_depth != bitdepth &&
ff_dnxhd_cid_table[index].bit_depth != DNXHD_VARIABLE) { cid_table->bit_depth != DNXHD_VARIABLE) {
av_log(ctx->avctx, AV_LOG_ERROR, "bit depth mismatches %d %d\n", ff_dnxhd_cid_table[index].bit_depth, bitdepth); av_log(ctx->avctx, AV_LOG_ERROR, "bit depth mismatches %d %d\n",
cid_table->bit_depth, bitdepth);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
ctx->cid_table = &ff_dnxhd_cid_table[index]; ctx->cid_table = cid_table;
av_log(ctx->avctx, AV_LOG_VERBOSE, "Profile cid %"PRIu32".\n", cid); av_log(ctx->avctx, AV_LOG_VERBOSE, "Profile cid %"PRIu32".\n", cid);
ff_free_vlc(&ctx->ac_vlc); ff_free_vlc(&ctx->ac_vlc);

@ -351,7 +351,7 @@ static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx)
static av_cold int dnxhd_encode_init(AVCodecContext *avctx) static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
{ {
DNXHDEncContext *ctx = avctx->priv_data; DNXHDEncContext *ctx = avctx->priv_data;
int i, index, ret; int i, ret;
switch (avctx->pix_fmt) { switch (avctx->pix_fmt) {
case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUV422P:
@ -411,10 +411,8 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
index = ff_dnxhd_get_cid_table(ctx->cid); ctx->cid_table = ff_dnxhd_get_cid_table(ctx->cid);
av_assert0(index >= 0); av_assert0(ctx->cid_table);
ctx->cid_table = &ff_dnxhd_cid_table[index];
ctx->m.avctx = avctx; ctx->m.avctx = avctx;
ctx->m.mb_intra = 1; ctx->m.mb_intra = 1;

Loading…
Cancel
Save