Skip to content

Commit 1439a65

Browse files
committed
Add OpusRtpDepacketizer
Inverse of OpusRtpPacketizer. Takes incoming Opus packets and emits frames.
1 parent 9d6671c commit 1439a65

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ set(LIBDATACHANNEL_SOURCES
7575
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizationconfig.cpp
7676
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpsrreporter.cpp
7777
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizer.cpp
78+
${CMAKE_CURRENT_SOURCE_DIR}/src/rtpdepacketizer.cpp
7879
${CMAKE_CURRENT_SOURCE_DIR}/src/h264rtppacketizer.cpp
7980
${CMAKE_CURRENT_SOURCE_DIR}/src/h264rtpdepacketizer.cpp
8081
${CMAKE_CURRENT_SOURCE_DIR}/src/nalunit.cpp
@@ -111,6 +112,7 @@ set(LIBDATACHANNEL_HEADERS
111112
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtppacketizationconfig.hpp
112113
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpsrreporter.hpp
113114
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtppacketizer.hpp
115+
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtpdepacketizer.hpp
114116
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264rtppacketizer.hpp
115117
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264rtpdepacketizer.hpp
116118
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/nalunit.hpp

include/rtc/rtc.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
#include "rtcpreceivingsession.hpp"
3939
#include "rtcpsrreporter.hpp"
4040
#include "rtppacketizer.hpp"
41+
#include "rtpdepacketizer.hpp"
4142

4243
#endif // RTC_ENABLE_MEDIA

include/rtc/rtpdepacketizer.hpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) 2024 Paul-Louis Ageneau
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
#ifndef RTC_RTP_DEPACKETIZER_H
10+
#define RTC_RTP_DEPACKETIZER_H
11+
12+
#if RTC_ENABLE_MEDIA
13+
14+
#include "mediahandler.hpp"
15+
#include "message.hpp"
16+
17+
namespace rtc {
18+
19+
class RTC_CPP_EXPORT RtpDepacketizer : public MediaHandler {
20+
public:
21+
RtpDepacketizer() = default;
22+
virtual ~RtpDepacketizer() = default;
23+
24+
virtual void incoming(message_vector &messages, const message_callback &send) override;
25+
};
26+
27+
using OpusRtpDepacketizer = RtpDepacketizer;
28+
using AACRtpDepacketizer = RtpDepacketizer;
29+
30+
} // namespace rtc
31+
32+
#endif /* RTC_ENABLE_MEDIA */
33+
34+
#endif /* RTC_RTP_DEPACKETIZER_H */

src/rtpdepacketizer.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2024 Paul-Louis Ageneau
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
#if RTC_ENABLE_MEDIA
10+
11+
#include "rtpdepacketizer.hpp"
12+
#include "rtp.hpp"
13+
14+
#include "impl/logcounter.hpp"
15+
16+
#include <cmath>
17+
#include <cstring>
18+
19+
namespace rtc {
20+
21+
void RtpDepacketizer::incoming([[maybe_unused]] message_vector &messages,
22+
[[maybe_unused]] const message_callback &send) {
23+
message_vector result;
24+
for (auto &message : messages) {
25+
if (message->type == Message::Control) {
26+
result.push_back(std::move(message));
27+
continue;
28+
}
29+
30+
if (message->size() < sizeof(RtpHeader)) {
31+
PLOG_VERBOSE << "RTP packet is too small, size=" << message->size();
32+
continue;
33+
}
34+
35+
auto pkt = reinterpret_cast<const rtc::RtpHeader *>(message->data());
36+
auto headerSize = sizeof(rtc::RtpHeader) + pkt->csrcCount() + pkt->getExtensionHeaderSize();
37+
result.push_back(make_message(message->begin() + headerSize, message->end(),
38+
Message::Binary, 0, nullptr,
39+
std::make_shared<FrameInfo>(pkt->timestamp())));
40+
}
41+
42+
messages.swap(result);
43+
}
44+
45+
} // namespace rtc
46+
47+
#endif /* RTC_ENABLE_MEDIA */

0 commit comments

Comments
 (0)