|
LibQuicR
|
MOQ track handler for published track. More...
#include <publish_track_handler.h>
Classes | |
| struct | StreamInfo |
| State retained for one open subgroup stream. More... | |
Public Types | |
| enum class | PublishObjectStatus : uint8_t { kOk = 0 , kInternalError , kNotAuthorized , kNotAnnounced , kNoSubscribers , kObjectPayloadLengthExceeded , kPreviousObjectTruncated , kNoPreviousObject , kObjectDataComplete , kObjectContinuationDataNeeded , kObjectDataIncomplete , kObjectDataTooLarge , kPreviousObjectNotCompleteMustStartNewGroup , kPreviousObjectNotCompleteMustStartNewTrack , kPaused , kPendingPublishOk , kSubgroupClosed , kFetchClosed } |
| Publish status codes. More... | |
| enum class | Status : uint8_t { kOk = 0 , kNotConnected , kNotAnnounced , kPendingAnnounceResponse , kAnnounceNotAuthorized , kNoSubscribers , kUnsubscribed , kDoneByFin , kSendingUnannounce , kSubscriptionUpdated , kNewGroupRequested , kPendingPublishOk , kPaused } |
| Status codes for the publish track. More... | |
Public Member Functions | |
| void | SetPublisherPriority (const uint8_t priority) noexcept |
| Sets the publisher priority used in future datagram and subgroup headers. More... | |
| void | SetPublishObjectPriority (const uint8_t priority) noexcept |
| set/update the publish object priority More... | |
| constexpr uint8_t | GetPublisherPriority () const noexcept |
| Get the publisher priority. More... | |
| constexpr uint8_t | GetPublishObjectPriority () const noexcept |
| Get the publish object priority. More... | |
| void | SetDefaultTTL (const uint32_t ttl) noexcept |
| Sets the default transport queue lifetime for future objects. More... | |
| uint32_t | GetDefaultTTL () const noexcept |
| Gets the default transport queue lifetime. More... | |
| void | SetDefaultTrackMode (const TrackMode track_mode) noexcept |
| Changes framing mode for subsequent objects. More... | |
| constexpr std::optional< messages::StreamHeaderProperties > | GetStreamMode () const noexcept |
| Get the current stream mode. More... | |
| Status | GetStatus () const noexcept |
| Get the publish status. More... | |
| constexpr messages::Location | GetLargestLocation () const noexcept |
| Gets the largest/current location observed by publication. More... | |
| virtual void | StreamClosed (std::uint64_t stream_id, bool reset=false) |
| Notification that a stream has been closed. More... | |
| bool | CanPublish () const noexcept |
| Check if the state allows publishing or not. More... | |
| void | SetTrackAlias (uint64_t track_alias) |
| Set the track alias. More... | |
| std::optional< uint64_t > | GetTrackAlias () const noexcept |
| Get the track alias. More... | |
| virtual PublishObjectStatus | PublishObject (const ObjectHeaders &object_headers, BytesSpan data, std::optional< messages::StreamHeaderProperties > stream_mode=std::nullopt) |
| Publish [full] object. More... | |
| PublishObjectStatus | ForwardPublishedData (bool is_new_stream, uint64_t group_id, uint64_t subgroup_id, std::shared_ptr< const std::vector< uint8_t >> data) |
| Forward received object data to subscriber/relay/remote client. More... | |
| virtual void | EndSubgroup (uint64_t group_id, uint64_t subgroup_id, bool completed=true) |
| Ends the subgroup as completed or not. More... | |
| void | EndAllSubgroups (bool completed) |
| End every subgroup still open on this track. More... | |
| void | SetStatus (Status status) noexcept |
| Set the publish status. More... | |
| template<typename T > | |
| requires std::is_base_of_v< TrackHandler, T > std::shared_ptr< T > | Get () |
| Get the derived type of the track handler. More... | |
| void | SetRequestId (std::optional< uint64_t > request_id) |
| Sets or clears the connection-scoped request ID. More... | |
| std::optional< uint64_t > | GetRequestId () const noexcept |
| Get the request ID. More... | |
| std::optional< uint64_t > | GetRequestStreamId () const |
| Get the stream ID of the request control stream. More... | |
| FullTrackName | GetFullTrackName () const noexcept |
| Get the full track name. More... | |
| uint64_t | GetConnectionId () const noexcept |
| Gets the transport connection identifier assigned by the session. More... | |
| std::shared_ptr< Connection > | GetConnection () const |
| Binding | GetBinding () const |
| virtual void | RequestError (ErrorCode error_code, std::string reason) |
| Handles a REQUEST_ERROR for this handler. More... | |
Callbacks | |
| virtual void | StatusChanged (Status status) |
| Notification of publish track status change. More... | |
| virtual void | MetricsSampled (const PublishTrackMetrics &metrics) |
| Notification callback to provide sampled metrics. More... | |
| Reply< messages::Parameters, ErrorCode > | RequestUpdateReceived (const messages::Parameters ¶ms) override |
| Applies subscriber forwarding and new-group update parameters. More... | |
Static Public Member Functions | |
| static std::shared_ptr< PublishTrackHandler > | Create (const FullTrackName &full_track_name, TrackMode track_mode, uint8_t publisher_priority, uint8_t publish_object_priority, uint32_t default_ttl, messages::Location largest_location) |
| Create a shared Publish track handler. More... | |
Public Attributes | |
| PublishTrackMetrics | publish_track_metrics_ |
| Publish metrics for the track. More... | |
Protected Member Functions | |
| PublishTrackHandler (const FullTrackName &full_track_name, TrackMode track_mode, uint8_t publisher_priority, uint8_t publish_object_priority, uint32_t default_ttl, std::optional< messages::StreamHeaderProperties > stream_mode=std::nullopt, messages::Location largest_location={ 0, 0 }) | |
| Publish track handler constructor. More... | |
| void | RequestOkReceived (const messages::Parameters ¶ms) override |
| Handles PUBLISH_OK or REQUEST_UPDATE_OK parameters. More... | |
| void | SetTransport (std::shared_ptr< Session > transport) |
| Sets the session used for control and data operations. More... | |
| const std::weak_ptr< Session > & | GetSession () const noexcept |
| Gets the non-owning session handle. More... | |
Protected Attributes | |
| std::atomic< Status > | publish_status_ { Status::kNotAnnounced } |
| Atomic publication state; does not synchronize the remaining fields. More... | |
| TrackMode | default_track_mode_ |
| Framing mode used for the next object. More... | |
| std::optional< messages::StreamHeaderProperties > | stream_mode_ |
| Default subgroup framing properties; populated for stream mode. More... | |
| uint8_t | publisher_priority_ |
| Publisher priority encoded in object headers. More... | |
| uint8_t | publish_object_priority_ |
| Subscriber-derived transport scheduling priority. More... | |
| uint32_t | default_ttl_ |
| Queue lifetime used when object TTL is absent. More... | |
| std::map< std::uint64_t, std::map< std::uint64_t, StreamInfo > > | stream_info_by_group_ |
| Open streams keyed first by group ID and then subgroup ID. More... | |
| std::optional< uint64_t > | track_alias_ |
| Connection-scoped track alias required by object framing. More... | |
| messages::Location | largest_location_ |
| Largest/current location reported for the track. More... | |
| Bytes | object_msg_buffer_ |
| Reusable serialization scratch buffer; invalidated by the next publish/end operation. More... | |
| bool | support_new_group_request_ { true } |
| Whether PUBLISH_OK may request dynamic groups. More... | |
| std::optional< uint64_t > | pending_new_group_request_id_ |
| Pending requested group ID, when one has been recorded. More... | |
| FullTrackName | full_track_name_ |
| Full track identity retained for the handler's lifetime. More... | |
| std::mutex | binding_operation_mutex_ |
MOQ track handler for published track.
Publishes one track using unreliable object datagrams (TrackMode::kDatagram) or reliable streams with one stream per subgroup (TrackMode::kStream). Despite older terminology, there are no stream-per-group or stream-per-track modes. Publishing methods and mutable configuration are not internally serialized; callers must not invoke them concurrently.
|
strong |
Publish status codes.
| Enumerator | |
|---|---|
| kOk | Object or bytes were queued successfully. |
| kInternalError | Required session/stream state was unavailable or invalid. |
| kNotAuthorized | Peer denied publication. |
| kNotAnnounced | Track is not ready/connected/announced. |
| kNoSubscribers | No active subscriber/request ID exists. |
| kObjectPayloadLengthExceeded | Legacy continuation status; not returned by current implementation. |
| kPreviousObjectTruncated | Legacy continuation status; not returned by current implementation. |
| kNoPreviousObject | Legacy continuation status; not returned by current implementation. |
| kObjectDataComplete | Legacy continuation status; not returned by current implementation. |
| kObjectContinuationDataNeeded | Legacy continuation status; not returned by current implementation. |
| kObjectDataIncomplete | PublishObject() was called when continuation data remains. |
| kObjectDataTooLarge | Indicates that the published object data is too large based on the object header payload size plus any/all data that was sent already. Legacy continuation status; not returned by current implementation. |
| kPreviousObjectNotCompleteMustStartNewGroup | Previous object payload has not been completed and new object cannot start in per-group track mode unless new group is used. Legacy status; current subgroup streams are independent. |
| kPreviousObjectNotCompleteMustStartNewTrack | Previous object payload has not been completed and new object cannot start in per-track track mode without creating a new track. This requires to unpublish and to publish track again. Legacy status; not returned by current implementation. |
| kPaused | Forwarding is paused by subscription state. |
| kPendingPublishOk | A publisher-initiated PUBLISH awaits acknowledgement. |
| kSubgroupClosed | This subgroup is closed and cannot be published to. |
| kFetchClosed | This fetch request is over and cannot accept more objects. |
|
strong |
Status codes for the publish track.
| Enumerator | |
|---|---|
| kOk | Publication is ready to queue objects. |
| kNotConnected | Transport is disconnected. |
| kNotAnnounced | Track is not announced/active. |
| kPendingAnnounceResponse | Waiting for announce acceptance. |
| kAnnounceNotAuthorized | Peer denied the announcement. |
| kNoSubscribers | No subscriber is currently bound. |
| kUnsubscribed | Subscriber ended the subscription. |
| kDoneByFin | Request stream ended normally. |
| kSendingUnannounce | In this state, callbacks will not be called. |
| kSubscriptionUpdated | Subscription parameters changed; next publish normalizes to |
| kNewGroupRequested | Subscriber requested a new group; next publish normalizes to |
| kPendingPublishOk | Waiting for acknowledgement of publisher-initiated publish. |
| kPaused | Subscriber disabled forwarding. |
|
protected |
Publish track handler constructor.
| full_track_name | Full track name |
| track_mode | The track mode to operate using |
| publisher_priority | Publisher priority of origin publisher |
| publish_object_priority | Publish object priority for objects being sent (set by Subscriber priority) |
| default_ttl | Default transport queue lifetime when object headers omit TTL. |
| stream_mode | Stream to use when track mode is kStream. |
| largest_location | Largest location to start the handler |
| std::invalid_argument | if datagram mode is combined with stream properties. |
Stream mode defaults to explicit subgroup IDs with the library's standard subgroup framing properties when stream_mode is omitted.
|
inlinenoexcept |
Check if the state allows publishing or not.
true only for kOk, kNewGroupRequested, or kSubscriptionUpdated.
|
inlinestatic |
Create a shared Publish track handler.
| full_track_name | Full track name |
| track_mode | The track mode to operate using |
| publisher_priority | Publisher priority of origin publisher |
| publish_object_priority | Publish object priority for objects being sent |
| default_ttl | Default TTL for objects if not specified in ObjectHeaderss |
| largest_location | Largest location to start handler at |
| void quicr::PublishTrackHandler::EndAllSubgroups | ( | bool | completed | ) |
End every subgroup still open on this track.
Called by the session when the track is unbound, so that subgroups the application never ended do not keep their streams open for the life of the connection.
| completed | If all have finished, drain and close with FIN. If false, end abruptly with RESET. |
|
virtual |
Ends the subgroup as completed or not.
Applications must call this to release an open stream-mode subgroup. With completed == true, an empty close marker is queued after existing data; otherwise the stream is reset immediately. The subgroup is then removed from local bookkeeping. Silently does nothing without a live session or matching open subgroup.
| group_id | Group containing the subgroup. |
| subgroup_id | Subgroup stream to end. |
| completed | true for orderly drain-and-close, false to reset. |
| PublishObjectStatus quicr::PublishTrackHandler::ForwardPublishedData | ( | bool | is_new_stream, |
| uint64_t | group_id, | ||
| uint64_t | subgroup_id, | ||
| std::shared_ptr< const std::vector< uint8_t >> | data | ||
| ) |
Forward received object data to subscriber/relay/remote client.
This method is similar to PublishObject except that the data forwarded is byte array level data, which should have already been encoded upon receive from the origin publisher. Relays implement this method to forward bytes received to subscriber connection.
| is_new_stream | Indicates if this data starts a new stream |
| group_id | Group ID for stream |
| subgroup_id | Subgroup ID for stream |
| data | MoQ data to send |
is_new_stream == true currently returns kObjectDataIncomplete; the caller must first establish stream bookkeeping through PublishObject. Missing subgroup bookkeeping returns kInternalError. | TransportException | if enqueueing fails. |
Shared ownership of data is passed to the transport without copying. In datagram mode bytes are sent unreliably as already encoded; in stream mode they are appended to the existing subgroup stream.
|
inlineinherited |
Get the derived type of the track handler.
| T | Derived type of the track handler. |
T, or null when the dynamic type is incompatible. | std::bad_weak_ptr | if this object is not currently owned by a shared_ptr. |
|
inlineinherited |
|
inherited |
|
inlinenoexceptinherited |
Gets the transport connection identifier assigned by the session.
|
inlinenoexcept |
Gets the default transport queue lifetime.
|
inlinenoexceptinherited |
Get the full track name.
|
inlineconstexprnoexcept |
Gets the largest/current location observed by publication.
|
inlineconstexprnoexcept |
Get the publisher priority.
|
inlineconstexprnoexcept |
Get the publish object priority.
|
inlinenoexceptinherited |
Get the request ID.
std::nullopt when none is assigned.
|
inherited |
Get the stream ID of the request control stream.
std::nullopt if no stream is attached.
|
protectednoexceptinherited |
Gets the non-owning session handle.
|
inlinenoexcept |
Get the publish status.
|
inlineconstexprnoexcept |
Get the current stream mode.
std::nullopt in datagram mode.
|
inlinenoexcept |
Get the track alias.
If the track alias is set, it will be returned, otherwise std::nullopt.
|
virtual |
Notification callback to provide sampled metrics.
Called at the connection metrics cadence, including idle periods. Object, byte, drop, and most QUIC counters are cumulative snapshots; only QUIC min/max/average aggregates are cleared after the callback for the next period.
| metrics | Copy of the published metrics for the sample period |
|
virtual |
Publish [full] object.
Encodes and queues one complete object. Datagram mode emits one object datagram. Stream mode creates/reuses the stream identified by (group_id, subgroup_id), emits a subgroup header on first use, and delta-encodes subsequent object IDs. The implementation does not compare data.size() with payload_length; data is the payload that is encoded. A per-object track_mode changes the default mode before encoding subsequent framing, but mode changes while streams are open require application coordination.
| object_headers | Object headers, must include group and object Ids |
| data | Full complete payload data for the object |
| stream_mode | Subgroup header properties |
publish_track_metrics_.objects_dropped_not_ok, except a missing request ID. | TransportException | if enqueueing fails. |
| std::bad_optional_access | if required track alias or stream properties were not set. |
data is borrowed and copied into an owned queue buffer before return. Calls must be externally serialized. Reimplemented in quicr::PublishFetchHandler.
|
virtualinherited |
Handles a REQUEST_ERROR for this handler.
| error_code | Peer-provided request error code. |
| reason | Peer-provided reason, passed by value for optional retention. |
Reimplemented in quicr::TrackStatusHandler, quicr::SubscribeNamespaceHandler, and quicr::PublishNamespaceHandler.
|
overrideprotectedvirtual |
Handles PUBLISH_OK or REQUEST_UPDATE_OK parameters.
| params | Borrowed acknowledgement parameters. |
| messages::ProtocolViolationException | for unsupported PUBLISH_OK parameters or a new-group request when dynamic groups are disabled. |
During kPendingPublishOk, validates parameters and resolves forwarding to kOk/kPaused; a new-group status may be transiently set before forwarding is applied. For later update acknowledgements parameters are currently ignored.
Implements quicr::TrackHandler.
|
overridevirtual |
Applies subscriber forwarding and new-group update parameters.
| params | Borrowed update parameters. |
A present forwarding value changes status to kOk or kPaused; a present new-group request then changes it to kNewGroupRequested. Other parameters are currently ignored.
Implements quicr::TrackHandler.
|
inlinenoexcept |
Changes framing mode for subsequent objects.
| track_mode | Datagram or subgroup-stream framing. |
|
inlinenoexcept |
Sets the default transport queue lifetime for future objects.
| ttl | TTL used when ObjectHeaders::ttl is absent. |
|
inlinenoexcept |
Sets the publisher priority used in future datagram and subgroup headers.
| priority | New protocol priority; already-open subgroup headers are unchanged. |
|
inlinenoexcept |
set/update the publish object priority
Publish object priority is set by subscriber priority, but the client app can update this as needed at any time. The setting will take effect on next datagram object and on next start of group/subgroup
| priority | New transport scheduling priority. |
|
inlineinherited |
Sets or clears the connection-scoped request ID.
| request_id | Request ID assigned by the session, or std::nullopt when unbound. |
|
inlinenoexcept |
Set the publish status.
| status | Status of publishing (aka publish objects) |
Atomically changes status and invokes StatusChanged only when the value differs. The callback executes synchronously on the caller's thread.
|
inline |
Set the track alias.
| track_alias | MoQ track alias for this connection. |
|
protectedinherited |
Sets the session used for control and data operations.
| transport | Session retained weakly; passing null clears effective access. |
|
virtual |
Notification of publish track status change.
Notification of a change to publish track status, such as when it's ready to publish or not ready to publish
| status | Indicates the status of being able to publish |
SetStatus() suppresses this callback when the atomic status value is unchanged.
|
virtual |
Notification that a stream has been closed.
| stream_id | The ID of the stream being closed. |
| reset | True if stream closed by reset |
Removes matching subgroup bookkeeping. The default implementation does not change publication status and currently ignores reset.
|
protectedinherited |
|
protected |
Framing mode used for the next object.
|
protected |
Queue lifetime used when object TTL is absent.
|
protectedinherited |
Full track identity retained for the handler's lifetime.
|
protected |
Largest/current location reported for the track.
|
protected |
Reusable serialization scratch buffer; invalidated by the next publish/end operation.
|
protected |
Pending requested group ID, when one has been recorded.
|
protected |
Subscriber-derived transport scheduling priority.
|
protected |
Atomic publication state; does not synchronize the remaining fields.
| PublishTrackMetrics quicr::PublishTrackHandler::publish_track_metrics_ |
Publish metrics for the track.
Public live counters updated by publication and session metrics processing. Byte/object counters increase when an object passes state checks, before enqueue success; forwarded bytes increase before the request-ID check. Rejected states increment objects_dropped_not_ok; missing request IDs and later encoding/enqueue failures do not. Counters are cumulative except the QUIC min/max/average aggregates cleared after sampling. Unsynchronized application writes race with library updates.
|
protected |
Publisher priority encoded in object headers.
|
protected |
Open streams keyed first by group ID and then subgroup ID.
|
protected |
Default subgroup framing properties; populated for stream mode.
|
protected |
Whether PUBLISH_OK may request dynamic groups.
|
protected |
Connection-scoped track alias required by object framing.