21 #include "dsp_fdk_aac.h"
22 #include "dsp_fdk_impl.h"
24 #include <freerdp/log.h>
25 #define TAG FREERDP_TAG("dsp.fdk")
27 static void write_log(
unsigned log_level,
const char* fmt, ...)
29 wLog* log = WLog_Get(TAG);
31 if (WLog_IsLevelActive(log, log_level))
33 char buffer[1024] = { 0 };
37 vsnprintf(buffer,
sizeof(buffer), fmt, ap);
40 WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, log_level, __LINE__, __FILE__, __func__,
"%s",
46 const BYTE* data,
size_t length,
wStream* out)
48 WINPR_ASSERT(context);
49 WINPR_ASSERT(srcFormat);
51 if (srcFormat->wFormatTag != WAVE_FORMAT_PCM)
53 WLog_WARN(TAG,
"Feeding %s format data to encoder function, but require %s",
54 audio_format_get_tag_string(srcFormat->wFormatTag),
55 audio_format_get_tag_string(WAVE_FORMAT_PCM));
59 if (!context->fdkSetup)
61 ssize_t rc = fdk_aac_dsp_impl_config(
62 context->fdkAacInstance, &context->buffersize, context->encoder,
63 context->format.nSamplesPerSec, context->format.nChannels,
64 context->format.nAvgBytesPerSec, context->frames_per_packet, write_log);
68 context->fdkSetup = TRUE;
71 if (!Stream_EnsureRemainingCapacity(out, context->buffersize))
75 const ssize_t encoded =
76 fdk_aac_dsp_impl_encode(context->fdkAacInstance, data, length, Stream_Pointer(out),
77 Stream_GetRemainingCapacity(out), write_log);
80 Stream_Seek(out, (
size_t)encoded);
86 const BYTE* data,
size_t length,
wStream* out)
88 WINPR_ASSERT(context);
89 WINPR_ASSERT(srcFormat);
91 if (srcFormat->wFormatTag != WAVE_FORMAT_AAC_MS)
93 WLog_WARN(TAG,
"Feeding %s format data to encoder function, but require %s",
94 audio_format_get_tag_string(srcFormat->wFormatTag),
95 audio_format_get_tag_string(WAVE_FORMAT_AAC_MS));
99 if (!context->fdkSetup)
101 ssize_t rc = fdk_aac_dsp_impl_config(
102 context->fdkAacInstance, &context->buffersize, context->encoder,
103 context->format.nSamplesPerSec, context->format.nChannels,
104 context->format.nAvgBytesPerSec, context->frames_per_packet, write_log);
108 context->fdkSetup = TRUE;
114 rest = fdk_aac_dsp_impl_decode_fill(context->fdkAacInstance, data, length, write_log);
117 WLog_WARN(TAG,
"DecodeFill() failed");
124 const size_t expect = context->buffersize;
125 if (!Stream_EnsureRemainingCapacity(out, expect))
128 ret = fdk_aac_dsp_impl_decode_read(context->fdkAacInstance, Stream_Pointer(out), expect,
133 Stream_Seek(out, (
size_t)ret);
142 WINPR_ASSERT(context);
144 fdk_aac_dsp_impl_uninit(&context->fdkAacInstance, context->encoder, write_log);
149 WINPR_ASSERT(context);
150 context->fdkSetup = FALSE;
151 WINPR_ASSERT(frames_per_packet <= UINT_MAX);
152 context->frames_per_packet = (unsigned)frames_per_packet;
153 return fdk_aac_dsp_impl_init(&context->fdkAacInstance, context->encoder, write_log);