Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/audio/ffmpeg_dec/ffmpeg-enc-alac.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ static int ffmpeg_enc_alac_encode_frame(struct processing_module *mod, struct ff
if (av_frame_get_buffer(alac->frame, 0) < 0)
return -ENOMEM;

ffmpeg_dec_pcm_to_frame(e->pcm_in, alac->frame,
e->src_fmt, ch, e->nb);
ret = ffmpeg_dec_pcm_to_frame(e->pcm_in, alac->frame,
e->src_fmt, ch, e->nb);
if (ret < 0) {
av_frame_unref(alac->frame);
return ret;
}

ret = avcodec_send_frame(alac->avctx, alac->frame);
av_frame_unref(alac->frame);
Expand Down
8 changes: 6 additions & 2 deletions src/audio/ffmpeg_dec/ffmpeg-enc-aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ static int ffmpeg_enc_aptx_encode_frame(struct processing_module *mod, struct ff
if (av_frame_get_buffer(aptx->frame, 0) < 0)
return -ENOMEM;

ffmpeg_dec_pcm_to_frame(e->pcm_in, aptx->frame,
e->src_fmt, 2, e->nb);
ret = ffmpeg_dec_pcm_to_frame(e->pcm_in, aptx->frame,
e->src_fmt, 2, e->nb);
if (ret < 0) {
av_frame_unref(aptx->frame);
return ret;
}

ret = avcodec_send_frame(aptx->avctx, aptx->frame);
av_frame_unref(aptx->frame);
Expand Down
8 changes: 6 additions & 2 deletions src/audio/ffmpeg_dec/ffmpeg-enc-flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ static int ffmpeg_enc_flac_encode_frame(struct processing_module *mod, struct ff
if (av_frame_get_buffer(flac->frame, 0) < 0)
return -ENOMEM;

ffmpeg_dec_pcm_to_frame(e->pcm_in, flac->frame,
e->src_fmt, ch, e->nb);
ret = ffmpeg_dec_pcm_to_frame(e->pcm_in, flac->frame,
e->src_fmt, ch, e->nb);
if (ret < 0) {
av_frame_unref(flac->frame);
return ret;
}

ret = avcodec_send_frame(flac->avctx, flac->frame);
av_frame_unref(flac->frame);
Expand Down
10 changes: 7 additions & 3 deletions src/audio/ffmpeg_dec/ffmpeg-enc-g722.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ static int ffmpeg_enc_g722_encode_frame(struct processing_module *mod, struct ff
G722_ENC_FRAME_SAMPLES,
e->decim_hist);
} else {
ffmpeg_dec_pcm_to_frame(e->pcm_in, g722->frame,
e->src_fmt, cd->out_channels,
G722_ENC_FRAME_SAMPLES);
ret = ffmpeg_dec_pcm_to_frame(e->pcm_in, g722->frame,
e->src_fmt, cd->out_channels,
G722_ENC_FRAME_SAMPLES);
if (ret < 0) {
av_frame_unref(g722->frame);
return ret;
}
}

ret = avcodec_send_frame(g722->avctx, g722->frame);
Expand Down
10 changes: 7 additions & 3 deletions src/audio/ffmpeg_dec/ffmpeg-enc-sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ static int ffmpeg_enc_sbc_encode_frame(struct processing_module *mod, struct ffm
MSBC_FRAME_SAMPLES,
e->decim_hist);
} else {
ffmpeg_dec_pcm_to_frame(e->pcm_in, sbc->frame,
e->src_fmt, cd->out_channels,
enc_samples);
ret = ffmpeg_dec_pcm_to_frame(e->pcm_in, sbc->frame,
e->src_fmt, cd->out_channels,
enc_samples);
if (ret < 0) {
av_frame_unref(sbc->frame);
return ret;
}
}

ret = avcodec_send_frame(sbc->avctx, sbc->frame);
Expand Down
127 changes: 0 additions & 127 deletions src/audio/ffmpeg_dec/ffmpeg-encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,133 +80,6 @@ static inline size_t ffmpeg_enc_min(size_t a, size_t b)
return a < b ? a : b;
}

static inline int16_t ffmpeg_enc_s24_to_s16(int32_t s)
{
int32_t v = s >> 8;

if (v > 32767)
return 32767;
if (v < -32768)
return -32768;
return (int16_t)v;
}

void ffmpeg_enc_pcm_to_s16_interleaved(const uint8_t *pcm_in, int16_t *dst,
size_t total_samples, int src_fmt)
{
size_t i;

if (src_fmt == SOF_IPC_FRAME_S16_LE) {
memcpy_s(dst, total_samples * sizeof(int16_t),
pcm_in, total_samples * sizeof(int16_t));
return;
}

if (src_fmt == SOF_IPC_FRAME_S24_4LE) {
const int32_t *in = (const int32_t *)pcm_in;

for (i = 0; i < total_samples; i++)
dst[i] = ffmpeg_enc_s24_to_s16(in[i]);
return;
}

{
const int32_t *in = (const int32_t *)pcm_in;

for (i = 0; i + 4 <= total_samples; i += 4) {
dst[i + 0] = (int16_t)(in[i + 0] >> 16);
dst[i + 1] = (int16_t)(in[i + 1] >> 16);
dst[i + 2] = (int16_t)(in[i + 2] >> 16);
dst[i + 3] = (int16_t)(in[i + 3] >> 16);
}
for (; i < total_samples; i++)
dst[i] = (int16_t)(in[i] >> 16);
}
}

void ffmpeg_enc_pcm_to_s16_planar(const uint8_t *pcm_in, uint8_t * const *planes,
int nb_samples, int ch, int src_fmt)
{
int i, c;

if (src_fmt == SOF_IPC_FRAME_S16_LE) {
const int16_t *in = (const int16_t *)pcm_in;

if (ch == 2) {
int16_t *out0 = (int16_t *)planes[0];
int16_t *out1 = (int16_t *)planes[1];

for (i = 0; i < nb_samples; i++) {
out0[i] = in[2 * i + 0];
out1[i] = in[2 * i + 1];
}
return;
}
for (c = 0; c < ch; c++) {
int16_t *out = (int16_t *)planes[c];

for (i = 0; i < nb_samples; i++)
out[i] = in[i * ch + c];
}
return;
}

if (src_fmt == SOF_IPC_FRAME_S24_4LE) {
const int32_t *in = (const int32_t *)pcm_in;

if (ch == 2) {
int16_t *out0 = (int16_t *)planes[0];
int16_t *out1 = (int16_t *)planes[1];

for (i = 0; i < nb_samples; i++) {
out0[i] = ffmpeg_enc_s24_to_s16(in[2 * i + 0]);
out1[i] = ffmpeg_enc_s24_to_s16(in[2 * i + 1]);
}
return;
}
for (c = 0; c < ch; c++) {
int16_t *out = (int16_t *)planes[c];

for (i = 0; i < nb_samples; i++)
out[i] = ffmpeg_enc_s24_to_s16(in[i * ch + c]);
}
return;
}

{
const int32_t *in = (const int32_t *)pcm_in;

if (ch == 2) {
int16_t *out0 = (int16_t *)planes[0];
int16_t *out1 = (int16_t *)planes[1];

for (i = 0; i + 4 <= nb_samples; i += 4) {
out0[i + 0] = (int16_t)(in[0] >> 16);
out1[i + 0] = (int16_t)(in[1] >> 16);
out0[i + 1] = (int16_t)(in[2] >> 16);
out1[i + 1] = (int16_t)(in[3] >> 16);
out0[i + 2] = (int16_t)(in[4] >> 16);
out1[i + 2] = (int16_t)(in[5] >> 16);
out0[i + 3] = (int16_t)(in[6] >> 16);
out1[i + 3] = (int16_t)(in[7] >> 16);
in += 8;
}
for (; i < nb_samples; i++) {
out0[i] = (int16_t)(in[0] >> 16);
out1[i] = (int16_t)(in[1] >> 16);
in += 2;
}
return;
}
for (c = 0; c < ch; c++) {
int16_t *out = (int16_t *)planes[c];

for (i = 0; i < nb_samples; i++)
out[i] = (int16_t)(in[i * ch + c] >> 16);
}
}
}

void ffmpeg_enc_stage_packet(struct processing_module *mod, struct ffmpeg_enc_data *e,
const uint8_t *data, size_t len)
{
Expand Down
2 changes: 1 addition & 1 deletion src/audio/ffmpeg_dec/ffmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ set(_ff_flacenc_prep "")
if(CONFIG_FFMPEG_ENC_FLAC)
set(_ff_extra_cflags "${_ff_extra_cflags} -I${SOF_FFMPEG_SRC_DIR}/libavcodec")
set(_ff_flacenc_prep
COMMAND sh -c "sed -e 's/FLAC_MAX_BLOCKSIZE/1152/g' -e 's/rc_sums\\[32\\]/rc_sums[1]/g' -e 's/subframes\\[FLAC_MAX_CHANNELS\\]/subframes[2]/g' -e 's/channels > FLAC_MAX_CHANNELS/channels > 2/g' <SOURCE_DIR>/libavcodec/flacenc.c > <BINARY_DIR>/libavcodec/flacenc.c")
COMMAND sh -c "sed -e 's/\\[FLAC_MAX_BLOCKSIZE\\]/[1152]/g' -e 's/\\[FLAC_MAX_BLOCKSIZE+11\\]/[1152+11]/g' -e 's/> FLAC_MAX_BLOCKSIZE/> 1152/g' -e 's/rc_sums\\[32\\]/rc_sums[1]/g' -e 's/subframes\\[FLAC_MAX_CHANNELS\\]/subframes[2]/g' -e 's/channels > FLAC_MAX_CHANNELS/channels > 2/g' <SOURCE_DIR>/libavcodec/flacenc.c > <BINARY_DIR>/libavcodec/flacenc.c")
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
Expand Down
Loading
Loading