| // Copyright 2024 The Chromium Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #ifndef QUICHE_QUIC_MOQT_MOQT_PUBLISHER_H_ | |
| #define QUICHE_QUIC_MOQT_MOQT_PUBLISHER_H_ | |
| #include <cstdint> | |
| #include <memory> | |
| #include <optional> | |
| #include "absl/base/nullability.h" | |
| #include "absl/status/status.h" | |
| #include "quiche/quic/core/quic_time.h" | |
| #include "quiche/quic/moqt/moqt_error.h" | |
| #include "quiche/quic/moqt/moqt_fetch_task.h" | |
| #include "quiche/quic/moqt/moqt_key_value_pair.h" | |
| #include "quiche/quic/moqt/moqt_names.h" | |
| #include "quiche/quic/moqt/moqt_object.h" | |
| #include "quiche/quic/moqt/moqt_priority.h" | |
| #include "quiche/quic/moqt/moqt_session_callbacks.h" | |
| #include "quiche/quic/moqt/moqt_types.h" | |
| #include "quiche/web_transport/web_transport.h" | |
| namespace moqt { | |
| class MoqtPublishingMonitorInterface; | |
| // MoqtObjectListener is an interface for any entity that is listening for | |
| // incoming objects for a given track. | |
| class MoqtObjectListener { | |
| public: | |
| virtual ~MoqtObjectListener() = default; | |
| // Called when the publisher is sure that it can serve the subscription. This | |
| // could happen synchronously or asynchronously.Details necessary for the | |
| // SUBSCRIBE_OK can be obtained from the MoqtTrackPublisher. | |
| virtual void OnSubscribeAccepted() = 0; | |
| // Called when the publisher is sure that it cannot serve the subscription. | |
| // This could happen synchronously or asynchronously. | |
| virtual void OnSubscribeRejected(MoqtRequestErrorInfo info) = 0; | |
| // Notifies that a new object is available on the track, or new payload of | |
| // a partially delivered object. The object payload itself may be retrieved | |
| // via GetCachedObject method of the associated track publisher. If |subgroup| | |
| // is nullopt, the object is a datagram. | |
| virtual void OnNewObjectAvailable(Location sequence, | |
| std::optional<uint64_t> subgroup, | |
| MoqtPriority publisher_priority) = 0; | |
| // Notifies that a pure FIN has arrived following |sequence|. Listeners can | |
| // also find out about FINs by later retrieving an object with fin_after_this | |
| // set, so this doesn't have to be stored if the sender isn't ready for it. | |
| virtual void OnNewFinAvailable(Location final_object_in_subgroup, | |
| uint64_t subgroup_id) = 0; | |
| // Notifies that the a stream is being abandoned (via RESET_STREAM) before | |
| // all objects are delivered. | |
| virtual void OnSubgroupAbandoned( | |
| uint64_t group, uint64_t subgroup, | |
| webtransport::StreamErrorCode error_code) = 0; | |
| // No further object will be published for the given group, usually due to a | |
| // timeout. The owner of the Listener may want to reset the relevant streams, | |
| // MoqtSession will ignore all groups <= |group_id|. MoqtSession is also | |
| // dependent on the caller to periodically retire groups to clear state; state | |
| // will be unbounded if streams are frequently reset and OnGroupAbandoned is | |
| // never called. | |
| virtual void OnGroupAbandoned(uint64_t group_id) = 0; | |
| // Notifies that the Publisher is being destroyed, so no more objects are | |
| // coming. | |
| virtual void OnTrackPublisherGone() = 0; | |
| }; | |
| // MoqtTrackPublisher is an application-side API for an MoQT publisher | |
| // of a single individual track. | |
| class MoqtTrackPublisher { | |
| public: | |
| virtual ~MoqtTrackPublisher() = default; | |
| // Returns the full name of the associated track. | |
| virtual const FullTrackName& GetTrackName() const = 0; | |
| // GetCachedObject lets the MoQT stack access the objects that are available | |
| // in the track's built-in local cache. Retrieves the first object ID >= | |
| // min_object that matches (sequence.group, sequence.subgroup). | |
| // | |
| // This implementation of MoQT does not store any objects within the MoQT | |
| // stack itself, at least until the object is fully serialized and passed to | |
| // the QUIC stack. Instead, it relies on individual tracks having a shared | |
| // cache for recent objects, and objects are always pulled from that cache | |
| // whenever they are sent. Once an object is not available via the cache, it | |
| // can no longer be sent; this ensures that objects are not buffered forever. | |
| // | |
| // This method returns nullopt if the object is not available, or a fragment | |
| // at |offset| > 0 is not available. | |
| // If |subgroup| is nullopt, the object is a datagram. | |
| virtual std::optional<PublishedObject> GetCachedObject( | |
| uint64_t group, std::optional<uint64_t> subgroup, uint64_t min_object, | |
| uint64_t offset = 0) const = 0; | |
| // Registers a listener with the track. The listener will be notified of all | |
| // newly arriving objects. The pointer to the listener must be valid until | |
| // removed. | |
| virtual void AddObjectListener(MoqtObjectListener* listener, | |
| const MessageParameters& parameters) = 0; | |
| virtual void RemoveObjectListener(MoqtObjectListener* listener) = 0; | |
| virtual absl::Status UpdateObjectListener( | |
| MoqtObjectListener* listener, const MessageParameters& parameters) = 0; | |
| // Methods to return various track properties. Returns nullopt if the value is | |
| // not yet available. | |
| // Track alias is not present because MoqtSession always uses locally | |
| // generated values. | |
| virtual std::optional<Location> largest_location() const = 0; | |
| virtual const TrackProperties& properties() const = 0; | |
| virtual std::optional<quic::QuicTimeDelta> expiration() const = 0; | |
| // Performs a fetch for the specified range of objects. Should also be used | |
| // for joining fetches where Largest Location is known. | |
| virtual std::unique_ptr<MoqtFetchTask> StandaloneFetch( | |
| Location start, Location end, MoqtGroupOrder order, | |
| FetchResponseCallback callback) = 0; | |
| // Use only when the subscription is pending, so that Largest Location is | |
| // unknown. | |
| virtual std::unique_ptr<MoqtFetchTask> RelativeFetch( | |
| uint64_t group_diff, MoqtGroupOrder order, | |
| FetchResponseCallback callback) = 0; | |
| virtual std::unique_ptr<MoqtFetchTask> AbsoluteFetch( | |
| uint64_t group, MoqtGroupOrder order, FetchResponseCallback callback) = 0; | |
| // Returns an optional monitoring interface for tracking delivery and object | |
| // ACKs for this track. Note that this only works if there is one subscriber | |
| // associated with the track publisher object. | |
| virtual MoqtPublishingMonitorInterface* absl_nullable | |
| GetMonitoringInterface() { | |
| return nullptr; | |
| } | |
| }; | |
| // MoqtPublisher is an interface to a publisher that allows it to publish | |
| // multiple tracks. | |
| class MoqtPublisher { | |
| public: | |
| virtual ~MoqtPublisher() = default; | |
| // Called by MoqtSession based on messages arriving on the wire. | |
| virtual absl_nullable std::shared_ptr<MoqtTrackPublisher> GetTrack( | |
| const FullTrackName& track_name) = 0; | |
| }; | |
| } // namespace moqt | |
| #endif // QUICHE_QUIC_MOQT_MOQT_PUBLISHER_H_ |