2019-02-17 11:08:29 +00:00
|
|
|
/*
|
|
|
|
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(
|
|
|
|
Stream &&stream,
|
|
|
|
FnMut<void(const Information &)> ready,
|
|
|
|
Fn<void()> error);
|
|
|
|
|
|
|
|
// Called from the main thread.
|
|
|
|
// Must be called after 'ready' was invoked.
|
|
|
|
void start();
|
|
|
|
|
|
|
|
// Called from the main thread.
|
|
|
|
// Non-const, because we subscribe to changes on the first call.
|
|
|
|
// Must be called after 'ready' was invoked.
|
2019-02-20 13:28:48 +00:00
|
|
|
[[nodiscard]] rpl::producer<crl::time> playPosition();
|
2019-02-17 11:08:29 +00:00
|
|
|
|
|
|
|
// Thread-safe.
|
|
|
|
[[nodiscard]] int streamIndex() const;
|
|
|
|
[[nodiscard]] AVRational streamTimeBase() const;
|
|
|
|
|
|
|
|
// Called from the same unspecified thread.
|
|
|
|
void process(Packet &&packet);
|
|
|
|
|
|
|
|
// Called from the main thread.
|
|
|
|
~AudioTrack();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Called from the same unspecified thread.
|
|
|
|
[[nodiscard]] bool tryReadFirstFrame(Packet &&packet);
|
|
|
|
[[nodiscard]] bool fillStateFromFrame();
|
|
|
|
void mixerInit();
|
|
|
|
void mixerEnqueue(Packet &&packet);
|
|
|
|
void callReady();
|
|
|
|
|
|
|
|
// Accessed from the same unspecified thread.
|
|
|
|
Stream _stream;
|
2019-02-20 13:28:48 +00:00
|
|
|
bool _noMoreData = false;
|
2019-02-17 11:08:29 +00:00
|
|
|
|
|
|
|
// Assumed to be thread-safe.
|
|
|
|
FnMut<void(const Information &)> _ready;
|
|
|
|
const Fn<void()> _error;
|
|
|
|
|
|
|
|
// First set from the same unspecified thread before _ready is called.
|
|
|
|
// After that is immutable.
|
|
|
|
AudioMsgId _audioMsgId;
|
2019-02-20 13:28:48 +00:00
|
|
|
crl::time _startedPosition = kTimeUnknown;
|
2019-02-17 11:08:29 +00:00
|
|
|
|
|
|
|
// Accessed from the main thread.
|
|
|
|
base::Subscription _subscription;
|
2019-02-20 13:28:48 +00:00
|
|
|
rpl::variable<crl::time> _playPosition;
|
2019-02-17 11:08:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|