/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "media/streaming/media_streaming_utility.h" namespace Media { namespace Streaming { class AudioTrack final { public: // Called from some unspecified thread. // Callbacks are assumed to be thread-safe. AudioTrack( const PlaybackOptions &options, Stream &&stream, AudioMsgId audioId, FnMut ready, Fn error); // Called from the main thread. // Must be called after 'ready' was invoked. void pause(crl::time time); void resume(crl::time time); // Called from the main thread. void setSpeed(float64 speed); // Called from the main thread. // Non-const, because we subscribe to changes on the first call. // Must be called after 'ready' was invoked. [[nodiscard]] rpl::producer playPosition(); // Thread-safe. [[nodiscard]] int streamIndex() const; [[nodiscard]] AVRational streamTimeBase() const; // Called from the same unspecified thread. void process(Packet &&packet); void waitForData(); // Called from the main thread. ~AudioTrack(); private: // Called from the same unspecified thread. [[nodiscard]] bool initialized() const; [[nodiscard]] bool tryReadFirstFrame(Packet &&packet); [[nodiscard]] bool fillStateFromFrame(); void mixerInit(); void mixerEnqueue(Packet &&packet); void mixerForceToBuffer(); void callReady(); PlaybackOptions _options; // Accessed from the same unspecified thread. Stream _stream; const AudioMsgId _audioId; bool _noMoreData = false; // Assumed to be thread-safe. FnMut _ready; const Fn _error; // First set from the same unspecified thread before _ready is called. // After that is immutable. crl::time _startedPosition = kTimeUnknown; // Accessed from the main thread. base::Subscription _subscription; // First set from the same unspecified thread before _ready is called. // After that accessed from the main thread. rpl::variable _playPosition; }; } // namespace Streaming } // namespace Media