Skip to content

Commit 037bb2b

Browse files
committed
Upgrade opus-tools to v0.2 with local opus_header_to_packet
1 parent d4494bb commit 037bb2b

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

Library/TeamTalkLib/build/opustools/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include(ExternalProject)
88
if (TOOLCHAIN_OGG)
99
ExternalProject_Add(opustools-src
1010
GIT_REPOSITORY https://github.com/xiph/opus-tools.git
11-
GIT_TAG v0.1.10
11+
GIT_TAG v0.2
1212
UPDATE_COMMAND ""
1313
CONFIGURE_COMMAND ""
1414
BUILD_COMMAND ""
@@ -19,7 +19,7 @@ if (TOOLCHAIN_OGG)
1919
else()
2020
ExternalProject_Add(opustools-src
2121
GIT_REPOSITORY https://github.com/xiph/opus-tools.git
22-
GIT_TAG v0.1.10
22+
GIT_TAG v0.2
2323
UPDATE_COMMAND ""
2424
CONFIGURE_COMMAND ""
2525
BUILD_COMMAND ""

Library/TeamTalkLib/codec/OggFileIO.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,64 @@ int SpeexEncFile::Encode(const short* samples, bool last/*=false*/)
673673

674674
#if defined(ENABLE_OPUSTOOLS)
675675

676+
static int opus_header_to_packet(const OpusHeader *h, unsigned char *packet, int len)
677+
{
678+
if (len < 19)
679+
return 0;
680+
681+
int pos = 0;
682+
auto wb = [&](const void* src, int n) -> bool
683+
{
684+
if (pos > len - n)
685+
return false;
686+
memcpy(packet + pos, src, n);
687+
pos += n;
688+
return true;
689+
};
690+
auto w8 = [&](unsigned char v) { return wb(&v, 1); };
691+
auto w16 = [&](ogg_uint16_t v) -> bool
692+
{
693+
unsigned char b[2] = { (unsigned char)(v & 0xFF), (unsigned char)((v >> 8) & 0xFF) };
694+
return wb(b, 2);
695+
};
696+
auto w32 = [&](ogg_uint32_t v) -> bool
697+
{
698+
unsigned char b[4] = { (unsigned char)(v & 0xFF), (unsigned char)((v >> 8) & 0xFF),
699+
(unsigned char)((v >> 16) & 0xFF), (unsigned char)((v >> 24) & 0xFF) };
700+
return wb(b, 4);
701+
};
702+
703+
if (!wb("OpusHead", 8))
704+
return 0;
705+
if (!w8(1))
706+
return 0;
707+
if (!w8(h->channels))
708+
return 0;
709+
if (!w16(h->preskip))
710+
return 0;
711+
if (!w32(h->input_sample_rate))
712+
return 0;
713+
if (!w16(h->gain))
714+
return 0;
715+
if (!w8(h->channel_mapping))
716+
return 0;
717+
718+
if (h->channel_mapping != 0)
719+
{
720+
if (!w8(h->nb_streams))
721+
return 0;
722+
if (!w8(h->nb_coupled))
723+
return 0;
724+
for (int i = 0; i < h->channels; i++)
725+
{
726+
if (!w8(h->stream_map[i]))
727+
return 0;
728+
}
729+
}
730+
731+
return pos;
732+
}
733+
676734
OpusFile::OpusFile()
677735
{
678736
Close();

0 commit comments

Comments
 (0)