-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a media handler to respond to intra frame requests
This introduces a PLIResponder class, which can be used for responding back with an intra frame after the receiver requests one with an FIR (Full Intra Request) or a PLI (Picture Loss Indicator) message. This is useful when a video is being streamed live and we can control the behavior of the video encoder. PLIResponder simply notifies its caller when a new intra frame is requested, which passes this request onto its video frame source.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) 2023 Arda Cinar | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef RTC_PLI_RESPONDER_H | ||
#define RTC_PLI_RESPONDER_H | ||
|
||
#include "mediahandlerelement.hpp" | ||
#include <functional> | ||
|
||
namespace rtc { | ||
|
||
/// Responds to PLI and FIR messages sent by the receiver. The sender should respond to these | ||
/// messages by sending an intra. | ||
class RTC_CPP_EXPORT PliResponder final : public MediaHandlerElement { | ||
std::function<void(void)> onPli; | ||
|
||
public: | ||
/// Constructs the PLIResponder object to notify whenever a new intra frame is requested | ||
/// @param onPli The callback that gets called whenever an intra frame is requested by the receiver | ||
PliResponder(std::function<void(void)> onPli); | ||
ChainedIncomingControlProduct processIncomingControlMessage(message_ptr) override; | ||
}; | ||
|
||
} | ||
|
||
#endif // RTC_PLI_RESPONDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2023 Arda Cinar | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "pliresponder.hpp" | ||
|
||
namespace rtc { | ||
|
||
ChainedIncomingControlProduct PliResponder::processIncomingControlMessage(message_ptr message) { | ||
size_t offset = 0; | ||
|
||
while ((sizeof(RtcpHeader) + offset) <= message->size()) { | ||
auto header = reinterpret_cast<rtc::RtcpHeader*>(message->data() + offset); | ||
uint8_t payload_type = header->payloadType(); | ||
|
||
if (payload_type == 196) { | ||
// FIR message, call pli handler anyway | ||
onPli(); | ||
break; | ||
} else if (payload_type == 206) { | ||
// On a payload specific fb message, there is a "feedback message type" (FMT) in the | ||
// header instead of a report count. PT = 206, FMT = 1 means a PLI message | ||
uint8_t feedback_message_type = header->reportCount(); | ||
if (feedback_message_type == 1) { | ||
onPli(); | ||
break; | ||
} | ||
} | ||
offset += header->lengthInBytes(); | ||
} | ||
return { message, std::nullopt }; | ||
} | ||
|
||
PliResponder::PliResponder(std::function<void(void)> onPli) : onPli(onPli) { } | ||
|
||
} |