Skip to content
Open
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
4 changes: 2 additions & 2 deletions Library/TeamTalkLib/build/opustools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 ""
Expand Down
58 changes: 58 additions & 0 deletions Library/TeamTalkLib/codec/OggFileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading