Skip to content

Commit e9060bf

Browse files
committed
Include payloadType in FrameInfo
So that consumers of onFrame can tell what codec the frame is in and know what decoder to use.
1 parent 8296892 commit e9060bf

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

include/rtc/frameinfo.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
namespace rtc {
1515

1616
struct RTC_CPP_EXPORT FrameInfo {
17-
FrameInfo(uint32_t timestamp) : timestamp(timestamp){};
17+
FrameInfo(uint8_t payloadType, uint32_t timestamp) : payloadType(payloadType), timestamp(timestamp){};
18+
uint8_t payloadType; // Indicates codec of the frame
1819
uint32_t timestamp = 0; // RTP Timestamp
1920
};
2021

include/rtc/h264rtpdepacketizer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RTC_CPP_EXPORT H264RtpDepacketizer : public MediaHandler {
3333
std::vector<message_ptr> mRtpBuffer;
3434

3535
message_vector buildFrames(message_vector::iterator firstPkt, message_vector::iterator lastPkt,
36-
uint32_t timestamp);
36+
uint8_t payloadType, uint32_t timestamp);
3737
};
3838

3939
} // namespace rtc

src/h264rtpdepacketizer.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ const uint8_t naluTypeSTAPA = 24;
3232
const uint8_t naluTypeFUA = 28;
3333

3434
message_vector H264RtpDepacketizer::buildFrames(message_vector::iterator begin,
35-
message_vector::iterator end, uint32_t timestamp) {
35+
message_vector::iterator end, uint8_t payloadType, uint32_t timestamp) {
3636
message_vector out = {};
3737
auto fua_buffer = std::vector<std::byte>{};
38-
auto frameInfo = std::make_shared<FrameInfo>(timestamp);
38+
auto frameInfo = std::make_shared<FrameInfo>(payloadType, timestamp);
3939

4040
for (auto it = begin; it != end; it++) {
4141
auto pkt = it->get();
@@ -111,6 +111,7 @@ void H264RtpDepacketizer::incoming(message_vector &messages, const message_callb
111111
messages.end());
112112

113113
while (mRtpBuffer.size() != 0) {
114+
uint8_t payload_type = 0;
114115
uint32_t current_timestamp = 0;
115116
size_t packets_in_timestamp = 0;
116117

@@ -119,6 +120,7 @@ void H264RtpDepacketizer::incoming(message_vector &messages, const message_callb
119120

120121
if (current_timestamp == 0) {
121122
current_timestamp = p->timestamp();
123+
payload_type = p->payloadType(); // should all be the same for data of the same codec
122124
} else if (current_timestamp != p->timestamp()) {
123125
break;
124126
}
@@ -133,7 +135,7 @@ void H264RtpDepacketizer::incoming(message_vector &messages, const message_callb
133135
auto begin = mRtpBuffer.begin();
134136
auto end = mRtpBuffer.begin() + (packets_in_timestamp - 1);
135137

136-
auto frames = buildFrames(begin, end + 1, current_timestamp);
138+
auto frames = buildFrames(begin, end + 1, payload_type, current_timestamp);
137139
messages.insert(messages.end(), frames.begin(), frames.end());
138140
mRtpBuffer.erase(mRtpBuffer.begin(), mRtpBuffer.begin() + packets_in_timestamp);
139141
}

src/rtpdepacketizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RtpDepacketizer::incoming([[maybe_unused]] message_vector &messages,
3636
auto headerSize = sizeof(rtc::RtpHeader) + pkt->csrcCount() + pkt->getExtensionHeaderSize();
3737
result.push_back(make_message(message->begin() + headerSize, message->end(),
3838
Message::Binary, 0, nullptr,
39-
std::make_shared<FrameInfo>(pkt->timestamp())));
39+
std::make_shared<FrameInfo>(pkt->payloadType(), pkt->timestamp())));
4040
}
4141

4242
messages.swap(result);

0 commit comments

Comments
 (0)