mirror of https://github.com/nu774/fdkaac.git
Fix LD/ELD issue: priming samples are too short to be discarded
When discarded, cannot reconstruct the beginning. Now we changed to activate smartpadding only for LC/HE/HEv2. (padding is not nice for low delay codec anyway) LD and ELD are two short
This commit is contained in:
parent
ca65cffdd3
commit
836367a7fe
23
src/main.c
23
src/main.c
|
@ -503,6 +503,11 @@ int write_sample(FILE *ofp, m4af_ctx_t *m4af, aacenc_frame_t *frame)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_smart_padding(int profile)
|
||||||
|
{
|
||||||
|
return profile == 2 || profile == 5 || profile == 29;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||||
HANDLE_AACENCODER encoder, uint32_t frame_length,
|
HANDLE_AACENCODER encoder, uint32_t frame_length,
|
||||||
|
@ -517,15 +522,12 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||||
int frames_written = 0, encoded = 0;
|
int frames_written = 0, encoded = 0;
|
||||||
aacenc_progress_t progress = { 0 };
|
aacenc_progress_t progress = { 0 };
|
||||||
const pcm_sample_description_t *fmt = pcm_get_format(reader);
|
const pcm_sample_description_t *fmt = pcm_get_format(reader);
|
||||||
|
const int is_padding = do_smart_padding(params->profile);
|
||||||
|
|
||||||
ibuf = malloc(frame_length * fmt->bytes_per_frame);
|
ibuf = malloc(frame_length * fmt->bytes_per_frame);
|
||||||
aacenc_progress_init(&progress, pcm_get_length(reader), fmt->sample_rate);
|
aacenc_progress_init(&progress, pcm_get_length(reader), fmt->sample_rate);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/*
|
|
||||||
* Since we delay the write, we cannot just exit loop when interrupted.
|
|
||||||
* Instead, we regard it as EOF.
|
|
||||||
*/
|
|
||||||
if (g_interrupted)
|
if (g_interrupted)
|
||||||
nread = 0;
|
nread = 0;
|
||||||
if (nread > 0) {
|
if (nread > 0) {
|
||||||
|
@ -548,7 +550,7 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||||
|
|
||||||
remaining -= consumed;
|
remaining -= consumed;
|
||||||
ip += consumed * fmt->channels_per_frame;
|
ip += consumed * fmt->channels_per_frame;
|
||||||
flip ^= 1;
|
if (is_padding) {
|
||||||
/*
|
/*
|
||||||
* As we pad 1 frame at beginning and ending by our extrapolator,
|
* As we pad 1 frame at beginning and ending by our extrapolator,
|
||||||
* we want to drop them.
|
* we want to drop them.
|
||||||
|
@ -557,14 +559,17 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||||
* Since sbr_header is included in the first frame (in case of
|
* Since sbr_header is included in the first frame (in case of
|
||||||
* SBR), we cannot discard first frame. So we pick second instead.
|
* SBR), we cannot discard first frame. So we pick second instead.
|
||||||
*/
|
*/
|
||||||
|
flip ^= 1;
|
||||||
++encoded;
|
++encoded;
|
||||||
if (encoded == 1 || encoded == 3)
|
if (encoded == 1 || encoded == 3)
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if (write_sample(params->output_fp, m4af, &obuf[flip]) < 0)
|
if (write_sample(params->output_fp, m4af, &obuf[flip]) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
++frames_written;
|
++frames_written;
|
||||||
} while (remaining > 0);
|
} while (remaining > 0);
|
||||||
|
}
|
||||||
|
DONE:
|
||||||
/*
|
/*
|
||||||
* When interrupted, we haven't pulled out last extrapolated frames
|
* When interrupted, we haven't pulled out last extrapolated frames
|
||||||
* from the reader. Therefore, we have to write the final outcome.
|
* from the reader. Therefore, we have to write the final outcome.
|
||||||
|
@ -574,8 +579,6 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||||
goto END;
|
goto END;
|
||||||
++frames_written;
|
++frames_written;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
DONE:
|
|
||||||
if (!params->silent)
|
if (!params->silent)
|
||||||
aacenc_progress_finish(&progress, pcm_get_position(reader));
|
aacenc_progress_finish(&progress, pcm_get_position(reader));
|
||||||
rc = frames_written;
|
rc = frames_written;
|
||||||
|
@ -755,8 +758,10 @@ pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
||||||
reader = pcm_open_native_converter(reader);
|
reader = pcm_open_native_converter(reader);
|
||||||
if (reader && PCM_IS_FLOAT(pcm_get_format(reader)))
|
if (reader && PCM_IS_FLOAT(pcm_get_format(reader)))
|
||||||
reader = limiter_open(reader);
|
reader = limiter_open(reader);
|
||||||
if (reader && (reader = pcm_open_sint16_converter(reader)) != 0)
|
if (reader && (reader = pcm_open_sint16_converter(reader)) != 0) {
|
||||||
|
if (do_smart_padding(params->profile))
|
||||||
reader = extrapolater_open(reader);
|
reader = extrapolater_open(reader);
|
||||||
|
}
|
||||||
return reader;
|
return reader;
|
||||||
FAIL:
|
FAIL:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue