Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit ebb5115

Browse files
authored
Add metadata methods in pipeline (#700)
1 parent 30404de commit ebb5115

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

source/core/owt_base/InternalIn.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ void InternalIn::onFeedback(const FeedbackMsg& msg)
4141
void InternalIn::onTransportData(char* buf, int len)
4242
{
4343
Frame* frame = nullptr;
44+
MetaData* metadata = nullptr;
4445
switch (buf[0]) {
4546
case TDT_MEDIA_FRAME:
4647
frame = reinterpret_cast<Frame*>(buf + 1);
4748
frame->payload = reinterpret_cast<uint8_t*>(buf + 1 + sizeof(Frame));
4849
deliverFrame(*frame);
4950
break;
51+
case TDT_MEDIA_METADATA:
52+
metadata = reinterpret_cast<MetaData*>(buf + 1);
53+
metadata->payload = reinterpret_cast<uint8_t*>(buf + 1 + sizeof(MetaData));
54+
deliverMetaData(*metadata);
55+
break;
5056
default:
5157
break;
5258
}

source/core/owt_base/InternalOut.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ void InternalOut::onFrame(const Frame& frame)
3131
m_transport->sendData(sendBuffer, header_len + 1, reinterpret_cast<char*>(const_cast<uint8_t*>(frame.payload)), frame.length);
3232
}
3333

34+
void InternalOut::onMetaData(const MetaData& metadata)
35+
{
36+
char sendBuffer[sizeof(MetaData) + 1];
37+
size_t header_len = sizeof(MetaData);
38+
39+
sendBuffer[0] = TDT_MEDIA_METADATA;
40+
memcpy(&sendBuffer[1], reinterpret_cast<char*>(const_cast<MetaData*>(&metadata)), header_len);
41+
m_transport->sendData(sendBuffer, header_len + 1, reinterpret_cast<char*>(const_cast<uint8_t*>(metadata.payload)), metadata.length);
42+
}
43+
3444
void InternalOut::onTransportData(char* buf, int len)
3545
{
3646
switch (buf[0]) {

source/core/owt_base/InternalOut.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class InternalOut : public FrameDestination, public RawTransportListener {
1616
virtual ~InternalOut();
1717

1818
void onFrame(const Frame&);
19+
void onMetaData(const MetaData&);
20+
1921

2022
void onTransportData(char*, int len);
2123
void onTransportError() { }

source/core/owt_base/MediaFramePipeline.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ void FrameSource::deliverFrame(const Frame& frame)
9999
}
100100
}
101101

102+
void FrameSource::deliverMetaData(const MetaData& metadata)
103+
{
104+
{
105+
boost::shared_lock<boost::shared_mutex> lock(m_audio_dests_mutex);
106+
for (auto it = m_audio_dests.begin(); it != m_audio_dests.end(); ++it) {
107+
(*it)->onMetaData(metadata);
108+
}
109+
}
110+
{
111+
boost::shared_lock<boost::shared_mutex> lock(m_video_dests_mutex);
112+
for (auto it = m_video_dests.begin(); it != m_video_dests.end(); ++it) {
113+
(*it)->onMetaData(metadata);
114+
}
115+
}
116+
}
117+
102118
//=========================================================================================
103119

104120
void FrameDestination::setAudioSource(FrameSource* src)

source/core/owt_base/MediaFramePipeline.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ struct Frame {
8585
MediaSpecInfo additionalInfo;
8686
};
8787

88+
enum MetaDataType {
89+
META_DATA_OWNER_ID = 0,
90+
};
91+
92+
struct MetaData {
93+
MetaDataType type;
94+
uint8_t* payload;
95+
uint32_t length;
96+
};
97+
8898
inline FrameFormat getFormat(const std::string& codec) {
8999
if (codec == "vp8") {
90100
return owt_base::FRAME_FORMAT_VP8;
@@ -210,6 +220,7 @@ enum FeedbackType {
210220
enum FeedbackCmd {
211221
REQUEST_KEY_FRAME,
212222
SET_BITRATE,
223+
REQUEST_OWNER_ID,
213224
RTCP_PACKET // FIXME: Temporarily use FeedbackMsg to carry audio rtcp-packets due to the premature AudioFrameConstructor implementation.
214225
};
215226

@@ -245,6 +256,7 @@ class FrameSource {
245256

246257
protected:
247258
void deliverFrame(const Frame&);
259+
void deliverMetaData(const MetaData&);
248260

249261
private:
250262
std::list<FrameDestination*> m_audio_dests;
@@ -262,6 +274,7 @@ class FrameDestination {
262274
virtual ~FrameDestination() { }
263275

264276
virtual void onFrame(const Frame&) = 0;
277+
virtual void onMetaData(const MetaData&) {}
265278
virtual void onVideoSourceChanged() {}
266279

267280
void setAudioSource(FrameSource*);

source/core/owt_base/RawTransport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace owt_base {
1818

1919
const char TDT_FEEDBACK_MSG = 0x5A;
2020
const char TDT_MEDIA_FRAME = 0x8F;
21+
const char TDT_MEDIA_METADATA = 0x3A;
2122

2223
enum Protocol {
2324
TCP = 0,

0 commit comments

Comments
 (0)