diff --git a/src/rtp_opus.cc b/src/rtp_opus.cc new file mode 100644 index 0000000..537ce29 --- /dev/null +++ b/src/rtp_opus.cc @@ -0,0 +1,20 @@ +#include +#include + +#include "conn.hh" +#include "rtp_opus.hh" +#include "rtp_generic.hh" + +int RTPOpus::pushOpusFrame(RTPConnection *conn, uint8_t *data, uint32_t dataLen, uint32_t timestamp) +{ + uint8_t buffer[MAX_PACKET] = { 0 }; + RTPOpus::OpusConfig *config = (RTPOpus::OpusConfig *)conn->getConfig(); + + buffer[0] = (config->configurationNumber << 3) | + (config->channels > 1 ? (1 << 2) : 0) | 0; + + memcpy(&buffer[1], data, dataLen); + conn->setPayload(RTP_FORMAT_OPUS); + + return RTPGeneric::pushGenericFrame(conn, buffer, dataLen + 1, 0); +} diff --git a/src/rtp_opus.hh b/src/rtp_opus.hh new file mode 100644 index 0000000..0f6688c --- /dev/null +++ b/src/rtp_opus.hh @@ -0,0 +1,13 @@ +#pragma once + +#include "rtp_generic.hh" + +namespace RTPOpus { + struct OpusConfig { + uint32_t samplerate; + uint8_t channels; + uint8_t configurationNumber; + }; + + int pushOpusFrame(RTPConnection *conn, uint8_t *data, uint32_t dataLen, uint32_t timestamp); +};