diff --git a/Library/TeamTalkLib/build/opustools/CMakeLists.txt b/Library/TeamTalkLib/build/opustools/CMakeLists.txt index 09ee0d695d..f28a793ff4 100644 --- a/Library/TeamTalkLib/build/opustools/CMakeLists.txt +++ b/Library/TeamTalkLib/build/opustools/CMakeLists.txt @@ -8,7 +8,7 @@ include(ExternalProject) if (TOOLCHAIN_OGG) ExternalProject_Add(opustools-src GIT_REPOSITORY https://github.com/xiph/opus-tools.git - GIT_TAG v0.1.10 + GIT_TAG v0.2 UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" @@ -19,7 +19,7 @@ if (TOOLCHAIN_OGG) else() ExternalProject_Add(opustools-src GIT_REPOSITORY https://github.com/xiph/opus-tools.git - GIT_TAG v0.1.10 + GIT_TAG v0.2 UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/Library/TeamTalkLib/codec/OggFileIO.cpp b/Library/TeamTalkLib/codec/OggFileIO.cpp index 6aed8f5ede..ed7e9b3a92 100644 --- a/Library/TeamTalkLib/codec/OggFileIO.cpp +++ b/Library/TeamTalkLib/codec/OggFileIO.cpp @@ -673,6 +673,64 @@ int SpeexEncFile::Encode(const short* samples, bool last/*=false*/) #if defined(ENABLE_OPUSTOOLS) +static int opus_header_to_packet(const OpusHeader *h, unsigned char *packet, int len) +{ + if (len < 19) + return 0; + + int pos = 0; + auto wb = [&](const void* src, int n) -> bool + { + if (pos > len - n) + return false; + memcpy(packet + pos, src, n); + pos += n; + return true; + }; + auto w8 = [&](unsigned char v) { return wb(&v, 1); }; + auto w16 = [&](ogg_uint16_t v) -> bool + { + unsigned char b[2] = { (unsigned char)(v & 0xFF), (unsigned char)((v >> 8) & 0xFF) }; + return wb(b, 2); + }; + auto w32 = [&](ogg_uint32_t v) -> bool + { + unsigned char b[4] = { (unsigned char)(v & 0xFF), (unsigned char)((v >> 8) & 0xFF), + (unsigned char)((v >> 16) & 0xFF), (unsigned char)((v >> 24) & 0xFF) }; + return wb(b, 4); + }; + + if (!wb("OpusHead", 8)) + return 0; + if (!w8(1)) + return 0; + if (!w8(h->channels)) + return 0; + if (!w16(h->preskip)) + return 0; + if (!w32(h->input_sample_rate)) + return 0; + if (!w16(h->gain)) + return 0; + if (!w8(h->channel_mapping)) + return 0; + + if (h->channel_mapping != 0) + { + if (!w8(h->nb_streams)) + return 0; + if (!w8(h->nb_coupled)) + return 0; + for (int i = 0; i < h->channels; i++) + { + if (!w8(h->stream_map[i])) + return 0; + } + } + + return pos; +} + OpusFile::OpusFile() { Close();