Register shared voice encoding in core build targets
This commit is contained in:
1 parent
ad707fe533
commit
d807ff261e
2 files changed
+7
-2
No files matched your search
@@ -67,6 +67,8 @@ utun_CORE_SOURCES = \
|
||||
media_async/media_async.c \
|
||||
media_async/attachment.c \
|
||||
media_async/attachment.h \
|
||||
media_async/voice_file.c \
|
||||
media_async/voice_file.h \
|
||||
video/video.c \
|
||||
transport_layer/dummynet.c \
|
||||
ntp_time.c \
|
||||
@@ -181,6 +183,8 @@ libutun_a_SOURCES = \
|
||||
media_async/media_async.c \
|
||||
media_async/attachment.c \
|
||||
media_async/attachment.h \
|
||||
media_async/voice_file.c \
|
||||
media_async/voice_file.h \
|
||||
video/video.c \
|
||||
transport_layer/dummynet.c \
|
||||
ntp_time.c \
|
||||
|
||||
@@ -10,7 +10,8 @@ int voice_file_encode(const int16_t* pcm, size_t count, int rate, int channels,
|
||||
const char* path, struct attachment_info* info) {
|
||||
static const int bitrates[] = {16000, 32000, 64000}, complexities[] = {2, 5, 10};
|
||||
static const char levels[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
if (!pcm || !info || !path || rate <= 0 || (channels != 1 && channels != 2) || preset < 0 || preset > 2) goto invalid;
|
||||
if (!pcm || !info || !path || (rate != 8000 && rate != 12000 && rate != 16000 && rate != 24000 && rate != 48000) ||
|
||||
(channels != 1 && channels != 2) || preset < 0 || preset > 2) goto invalid;
|
||||
size_t frame = (size_t)(rate / 50) * channels, samples = count / frame * frame;
|
||||
if (samples < (size_t)rate * channels / 2 || samples / channels / rate > 86400) goto invalid;
|
||||
opus_codec_encoder_t* encoder = opus_codec_encoder_create(rate, channels);
|
||||
@@ -52,7 +53,7 @@ done:
|
||||
opus_codec_encoder_destroy(encoder);
|
||||
if (error) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "voice_file: encoding/write failed path=%s", path);
|
||||
if (remove(path)) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "voice_file: partial file cleanup failed path=%s", path);
|
||||
if (file && remove(path)) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "voice_file: partial file cleanup failed path=%s", path);
|
||||
} else DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "voice_file: prepared path=%s duration=%ums rate=%d channels=%d", path, info->duration_ms, rate, channels);
|
||||
return error;
|
||||
invalid:
|
||||
|
||||
Reference in new issue
Block a user