Skip to content

Commit

Permalink
Modify obj header priority to 8bytes and MoQFlvStreamerClient.cpp c…
Browse files Browse the repository at this point in the history
…lient simplification

Summary:
- Convert obj header priority to 8bytes
- Simplification of `MoQFlvStreamerClient`
   - Better priority assignment
   - Code simplification

Reviewed By: afrind

Differential Revision: D66570493

fbshipit-source-id: ae7501190fec776c59af628f948c0a575cfa051f
  • Loading branch information
jordicenzano authored and facebook-github-bot committed Nov 28, 2024
1 parent 5f57e24 commit 75f9fbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 45 deletions.
5 changes: 1 addition & 4 deletions moxygen/MoQFramer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,7 @@ WriteResult writeStreamHeader(
writeVarint(writeBuf, objectHeader.group, size, error);
writeVarint(writeBuf, objectHeader.subgroup, size, error);
}
// TODO: Very weird conversion here (we are keeping obj priority in uint64 and
// we need to convert to uint8)
uint8_t priority = objectHeader.priority;
writeBuf.append(&priority, 1);
writeBuf.append(&objectHeader.priority, 1);
size += 1;
if (error) {
return folly::makeUnexpected(quic::TransportErrorCode::INTERNAL_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion moxygen/MoQFramer.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ struct ObjectHeader {
uint64_t group;
uint64_t subgroup{0}; // meaningless for Track and Datagram
uint64_t id;
uint64_t priority;
uint8_t priority;
ForwardPreference forwardPreference;
ObjectStatus status{ObjectStatus::NORMAL};
folly::Optional<uint64_t> length{folly::none};
Expand Down
56 changes: 16 additions & 40 deletions moxygen/samples/flv_streamer_client/MoQFlvStreamerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ class MoQFlvStreamerClient {
<< sub.second.trackAlias;

if (sub.second.fullTrackName == fullVideoTrackName_) {
auto videoPriority = calculatePriotity(latestVideo_, false);

if (item->isEOF &&
MoQFlvStreamerClient::isAnyElementSent(latestVideo_)) {
// EOF detected and an some video element was sent, close group
auto objHeaderEndOfGroup = createObjectHeaderEndOfGroup(
ObjectHeader objHeaderEndOfGroup = {
sub.second.trackAlias,
latestVideo_.group,
latestVideo_.group,
0, // subgroup per group
latestVideo_.object++,
videoPriority,
ForwardPreference::Subgroup);
VIDEO_STREAM_PRIORITY,
ForwardPreference::Subgroup,
ObjectStatus::END_OF_GROUP};

XLOG(DBG1) << "Closing group because EOF. objHeader: "
<< objHeaderEndOfGroup;
moqClient_.getEventBase()->runInEventBaseThread(
Expand All @@ -136,13 +136,15 @@ class MoQFlvStreamerClient {
if (item->isIdr &&
MoQFlvStreamerClient::isAnyElementSent(latestVideo_)) {
// Close group
auto objHeaderEndOfGroup = createObjectHeaderEndOfGroup(
ObjectHeader objHeaderEndOfGroup = {
sub.second.trackAlias,
latestVideo_.group,
0, // subgroup per group
latestVideo_.object++,
videoPriority,
ForwardPreference::Subgroup);
VIDEO_STREAM_PRIORITY,
ForwardPreference::Subgroup,
ObjectStatus::END_OF_GROUP};

XLOG(DBG1) << "Closing group because IDR. objHeader: "
<< objHeaderEndOfGroup;
moqClient_.getEventBase()->runInEventBaseThread(
Expand All @@ -161,7 +163,6 @@ class MoQFlvStreamerClient {
[this,
item,
latestVideo(latestVideo_),
videoPriority,
trackAlias(sub.second.trackAlias),
subscribeID(sub.second.subscribeID)] {
auto objPayload = encodeToMoQMi(item);
Expand All @@ -171,9 +172,9 @@ class MoQFlvStreamerClient {
ObjectHeader objHeader = ObjectHeader{
trackAlias,
latestVideo.group,
latestVideo.group,
0, // subgroup per group
latestVideo.object,
videoPriority,
VIDEO_STREAM_PRIORITY,
ForwardPreference::Subgroup,
ObjectStatus::NORMAL,
objPayload->computeChainDataLength()};
Expand All @@ -193,16 +194,14 @@ class MoQFlvStreamerClient {
if (sub.second.fullTrackName == fullAudioTrackName_ &&
item->type == FlvSequentialReader::MediaType::AUDIO) {
// Audio
auto audioPriority = calculatePriotity(latestAudio_, true);

if (item->data) {
// Send audio data in a thread (stream per object)
ObjectHeader objHeader = ObjectHeader{
sub.second.trackAlias,
latestAudio_.group++,
/*subgroup=*/0,
latestAudio_.object,
audioPriority,
AUDIO_STREAM_PRIORITY,
ForwardPreference::Subgroup,
ObjectStatus::NORMAL};

Expand Down Expand Up @@ -311,8 +310,8 @@ class MoQFlvStreamerClient {
}

private:
static const uint64_t PRIORITY_AUDIO_OFFSET =
std::numeric_limits<uint64_t>::max() / 2;
static const uint8_t AUDIO_STREAM_PRIORITY = 100; /* Lower is higher pri */
static const uint8_t VIDEO_STREAM_PRIORITY = 200;

static bool isAnyElementSent(const AbsoluteLocation& loc) {
if (loc.group == 0 && loc.object == 0) {
Expand All @@ -321,29 +320,6 @@ class MoQFlvStreamerClient {
return true;
}

static uint64_t calculatePriotity(
const AbsoluteLocation& latest,
bool isAudio) {
return latest.group + (isAudio ? PRIORITY_AUDIO_OFFSET : 0);
}

static ObjectHeader createObjectHeaderEndOfGroup(
TrackIdentifier trackIdentifier,
uint64_t group,
uint64_t subgroup,
uint64_t id,
uint64_t priority,
ForwardPreference forwardPreference) {
return {
trackIdentifier,
group,
subgroup,
id,
priority,
forwardPreference,
ObjectStatus::END_OF_GROUP};
}

static std::unique_ptr<folly::IOBuf> encodeToMoQMi(
std::shared_ptr<FlvSequentialReader::MediaItem> item) {
if (item->type == FlvSequentialReader::MediaType::VIDEO) {
Expand Down

0 comments on commit 75f9fbe

Please sign in to comment.