|
6 | 6 |
|
7 | 7 | #include "moxygen/relay/MoQRelay.h" |
8 | 8 | #include "moxygen/MoQFilters.h" |
| 9 | +#include "moxygen/MoQTrackProperties.h" |
9 | 10 |
|
10 | 11 | namespace { |
11 | 12 | constexpr uint8_t kDefaultUpstreamPriority = 128; |
@@ -34,6 +35,24 @@ folly::coro::Task<void> MoQRelay::doSubscribeUpdate( |
34 | 35 | } |
35 | 36 | } |
36 | 37 |
|
| 38 | +// Sends a REQUEST_UPDATE that carries only the NEW_GROUP_REQUEST parameter. |
| 39 | +folly::coro::Task<void> MoQRelay::doNewGroupRequestUpdate( |
| 40 | + std::shared_ptr<Publisher::SubscriptionHandle> handle, |
| 41 | + uint64_t newGroupRequestValue) { |
| 42 | + XLOG(DBG4) << "Sending NEW_GROUP_REQUEST update: " << newGroupRequestValue; |
| 43 | + RequestUpdate update; |
| 44 | + update.requestID = RequestID(0); |
| 45 | + update.existingRequestID = handle->subscribeOk().requestID; |
| 46 | + update.params.insertParam(Parameter( |
| 47 | + folly::to_underlying(TrackRequestParamKey::NEW_GROUP_REQUEST), |
| 48 | + newGroupRequestValue)); |
| 49 | + auto updateRes = co_await handle->requestUpdate(std::move(update)); |
| 50 | + if (updateRes.hasError()) { |
| 51 | + XLOG(ERR) << "NEW_GROUP_REQUEST update failed: " |
| 52 | + << updateRes.error().reasonPhrase; |
| 53 | + } |
| 54 | +} |
| 55 | + |
37 | 56 | std::shared_ptr<MoQRelay::NamespaceNode> MoQRelay::findNamespaceNode( |
38 | 57 | const TrackNamespace& ns, |
39 | 58 | bool createMissingNodes, |
@@ -509,13 +528,10 @@ folly::coro::Task<void> MoQRelay::publishToSession( |
509 | 528 | guard.dismiss(); |
510 | 529 | XLOG(DBG1) << "Publish OK sess=" << session.get(); |
511 | 530 | auto& pubOk = pubResult.value().value(); |
512 | | - std::optional<AbsoluteLocation> end; |
513 | | - if (pubOk.endGroup) { |
514 | | - end = AbsoluteLocation{*pubOk.endGroup, 0}; |
515 | | - } |
516 | | - subscriber->range = |
517 | | - toSubscribeRange(pubOk.start, end, pubOk.locType, forwarder->largest()); |
518 | | - subscriber->shouldForward = pubOk.forward; |
| 531 | + |
| 532 | + // Process the PUBLISH_OK response - updates range, forward flag, and |
| 533 | + // handles NEW_GROUP_REQUEST forwarding via callback |
| 534 | + subscriber->onPublishOk(pubOk); |
519 | 535 | } |
520 | 536 |
|
521 | 537 | class MoQRelay::NamespaceSubscription |
@@ -871,6 +887,8 @@ folly::coro::Task<Publisher::SubscribeResult> MoQRelay::subscribe( |
871 | 887 | auto& rsub = it->second; |
872 | 888 | rsub.requestID = subRes.value()->subscribeOk().requestID; |
873 | 889 | rsub.handle = std::move(subRes.value()); |
| 890 | + // Record NGR as outstanding (no fire — it rides the outgoing SUBSCRIBE). |
| 891 | + forwarder->tryProcessNewGroupRequest(subReq.params, /*fire=*/false); |
874 | 892 | rsub.promise.setValue(folly::unit); |
875 | 893 | co_return subscriber; |
876 | 894 | } else { |
@@ -911,6 +929,8 @@ folly::coro::Task<Publisher::SubscribeResult> MoQRelay::subscribe( |
911 | 929 | doSubscribeUpdate(subscriptionIt->second.handle, /*forward=*/true)) |
912 | 930 | .start(); |
913 | 931 | } |
| 932 | + |
| 933 | + forwarder->tryProcessNewGroupRequest(subReq.params); |
914 | 934 | co_return subscriber; |
915 | 935 | } |
916 | 936 | } |
@@ -1110,4 +1130,24 @@ void MoQRelay::forwardChanged(MoQForwarder* forwarder) { |
1110 | 1130 | .start(); |
1111 | 1131 | } |
1112 | 1132 |
|
| 1133 | +void MoQRelay::newGroupRequested(MoQForwarder* forwarder, uint64_t group) { |
| 1134 | + auto subscriptionIt = subscriptions_.find(forwarder->fullTrackName()); |
| 1135 | + if (subscriptionIt == subscriptions_.end()) { |
| 1136 | + return; |
| 1137 | + } |
| 1138 | + auto& subscription = subscriptionIt->second; |
| 1139 | + // Check if handle is still valid (publisher may have terminated) |
| 1140 | + if (!subscription.handle) { |
| 1141 | + XLOG(DBG4) << "Ignoring NEW_GROUP_REQUEST for " << subscriptionIt->first |
| 1142 | + << " - publisher terminated"; |
| 1143 | + return; |
| 1144 | + } |
| 1145 | + XLOG(INFO) << "New group request detected for " << subscriptionIt->first; |
| 1146 | + |
| 1147 | + auto exec = subscription.upstream->getExecutor(); |
| 1148 | + auto handle = subscription.handle; |
| 1149 | + co_withExecutor(exec, doNewGroupRequestUpdate(std::move(handle), group)) |
| 1150 | + .start(); |
| 1151 | +} |
| 1152 | + |
1113 | 1153 | } // namespace moxygen |
0 commit comments