Commit 12759cc0 authored by Burt P's avatar Burt P Committed by Michael Niedermayer

af_hdcd: Move code detect/check into own function

Signed-off-by: 's avatarBurt P <pburt0@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent b90d0ab4
...@@ -933,6 +933,45 @@ static void hdcd_update_info(hdcd_state_t *state) ...@@ -933,6 +933,45 @@ static void hdcd_update_info(hdcd_state_t *state)
state->max_gain = FFMAX(state->max_gain, (state->control & 15)); state->max_gain = FFMAX(state->max_gain, (state->control & 15));
} }
typedef enum {
HDCD_CODE_NONE=0,
HDCD_CODE_A,
HDCD_CODE_A_ALMOST,
HDCD_CODE_B,
HDCD_CODE_B_CHECKFAIL,
HDCD_CODE_EXPECT_A,
HDCD_CODE_EXPECT_B,
} hdcd_code_result_t;
static hdcd_code_result_t hdcd_code(const uint32_t bits, unsigned char *code)
{
if ((bits & 0x0fa00500) == 0x0fa00500) {
/* A: 8-bit code 0x7e0fa005[..] */
if ((bits & 0xc8) == 0) {
/* [..pt gggg]
* 0x0fa005[..] -> 0b[00.. 0...], gain part doubled */
*code = (bits & 255) + (bits & 7);
return HDCD_CODE_A;
} else
return HDCD_CODE_A_ALMOST; /* one of bits 3, 6, or 7 was not 0 */
} else if ((bits & 0xa0060000) == 0xa0060000) {
/* B: 8-bit code, 8-bit XOR check, 0x7e0fa006[....] */
if (((bits ^ (~bits >> 8 & 255)) & 0xffff00ff) == 0xa0060000) {
/* check: [..pt gggg ~(..pt gggg)]
* 0xa006[....] -> 0b[.... .... .... .... ] */
*code = bits >> 8 & 255;
return HDCD_CODE_B;
} else
return HDCD_CODE_B_CHECKFAIL; /* XOR check failed */
}
if (bits == 0x7e0fa005)
return HDCD_CODE_EXPECT_A;
else if (bits == 0x7e0fa006)
return HDCD_CODE_EXPECT_B;
return HDCD_CODE_NONE;
}
static int hdcd_integrate(HDCDContext *ctx, hdcd_state_t *state, int *flag, const int32_t *samples, int count, int stride) static int hdcd_integrate(HDCDContext *ctx, hdcd_state_t *state, int *flag, const int32_t *samples, int count, int stride)
{ {
uint32_t bits = 0; uint32_t bits = 0;
...@@ -953,44 +992,39 @@ static int hdcd_integrate(HDCDContext *ctx, hdcd_state_t *state, int *flag, cons ...@@ -953,44 +992,39 @@ static int hdcd_integrate(HDCDContext *ctx, hdcd_state_t *state, int *flag, cons
bits = (state->window ^ state->window >> 5 ^ state->window >> 23); bits = (state->window ^ state->window >> 5 ^ state->window >> 23);
if (state->arg) { if (state->arg) {
if ((bits & 0x0fa00500) == 0x0fa00500) { switch (hdcd_code(bits, &state->control)) {
/* A: 8-bit code */ case HDCD_CODE_A:
if ((bits & 0xc8) == 0) {
/* [..pt gggg]
* 0x0fa005[..] -> 0b[00.. 0...], gain part doubled */
state->control = (bits & 255) + (bits & 7);
*flag = 1; *flag = 1;
state->code_counterA++; state->code_counterA++;
} else { break;
/* one of bits 3, 6, or 7 was not 0 */ case HDCD_CODE_B:
*flag = 1;
state->code_counterB++;
break;
case HDCD_CODE_A_ALMOST:
state->code_counterA_almost++; state->code_counterA_almost++;
av_log(ctx->fctx, AV_LOG_VERBOSE, av_log(ctx->fctx, AV_LOG_VERBOSE,
"hdcd error: Control A almost: 0x%02x near %d\n", bits & 0xff, ctx->sample_count); "hdcd error: Control A almost: 0x%02x near %d\n", bits & 0xff, ctx->sample_count);
} break;
} else if ((bits & 0xa0060000) == 0xa0060000) { case HDCD_CODE_B_CHECKFAIL:
/* B: 8-bit code, 8-bit XOR check */
if (((bits ^ (~bits >> 8 & 255)) & 0xffff00ff) == 0xa0060000) {
/* check: [..pt gggg ~(..pt gggg)]
* 0xa006[....] -> 0b[.... .... .... .... ] */
state->control = bits >> 8 & 255;
*flag = 1;
state->code_counterB++;
} else {
/* XOR check failed */
state->code_counterB_checkfails++; state->code_counterB_checkfails++;
av_log(ctx->fctx, AV_LOG_VERBOSE, av_log(ctx->fctx, AV_LOG_VERBOSE,
"hdcd error: Control B check failed: 0x%04x (0x%02x vs 0x%02x) near %d\n", bits & 0xffff, (bits & 0xff00) >> 8, ~bits & 0xff, ctx->sample_count); "hdcd error: Control B check failed: 0x%04x (0x%02x vs 0x%02x) near %d\n", bits & 0xffff, (bits & 0xff00) >> 8, ~bits & 0xff, ctx->sample_count);
} break;
} else { case HDCD_CODE_NONE:
/* told to look for a code, but didn't match one */ state->code_counterC_unmatched++;
state->code_counterC_unmatched++; av_log(ctx->fctx, AV_LOG_VERBOSE,
av_log(ctx->fctx, AV_LOG_VERBOSE, "hdcd error: Unmatched code: 0x%08x near %d\n", bits, ctx->sample_count);
"hdcd error: Unmatched code: 0x%08x near %d\n", bits, ctx->sample_count); default:
av_log(ctx->fctx, AV_LOG_INFO,
"hdcd error: Unexpected return value from hdcd_code()\n");
av_assert0(0); /* die */
} }
if (*flag) hdcd_update_info(state); if (*flag) hdcd_update_info(state);
state->arg = 0; state->arg = 0;
} }
if (bits == 0x7e0fa005 || bits == 0x7e0fa006) { if (bits == 0x7e0fa005 || bits == 0x7e0fa006) {
/* 0x7e0fa00[.]-> [0b0101 or 0b0110] */
state->readahead = (bits & 3) * 8; state->readahead = (bits & 3) * 8;
state->arg = 1; state->arg = 1;
state->code_counterC++; state->code_counterC++;
......
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