Fix streaming from the middle of the file.

This commit is contained in:
John Preston 2019-02-21 15:51:22 +04:00
parent 99d05ba967
commit e5cd7e6d40
5 changed files with 16 additions and 4 deletions

View File

@ -326,6 +326,7 @@ void StartStreaming(
auto options = Media::Streaming::PlaybackOptions();
options.speed = 1.;
options.position = (document->duration() / 2) * crl::time(1000);
player->init(options);
player->updates(
) | rpl::start_with_next_error_done([=](Update &&update) {

View File

@ -25,7 +25,8 @@ AudioTrack::AudioTrack(
, _stream(std::move(stream))
, _audioId(audioId)
, _ready(std::move(ready))
, _error(std::move(error)) {
, _error(std::move(error))
, _playPosition(options.position) {
Expects(_ready != nullptr);
Expects(_error != nullptr);
Expects(_audioId.playId() != 0);

View File

@ -69,6 +69,8 @@ private:
// 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<crl::time> _playPosition;
};

View File

@ -138,6 +138,13 @@ void LoaderMtproto::cancelRequestsBefore(int offset) {
_sender.requestCanceller(),
&base::flat_map<int, mtpRequestId>::value_type::second);
_requests.erase(from, till);
if (!_requests.empty() && _requests.front().first > offset) {
ranges::for_each(
base::take(_requests),
_sender.requestCanceller(),
&base::flat_map<int, mtpRequestId>::value_type::second);
}
}
} // namespace Streaming

View File

@ -280,7 +280,9 @@ VideoTrackObject::TrackTime VideoTrackObject::trackTime() const {
const auto correction = _audioId.playId()
? Media::Player::mixer()->getVideoTimeCorrection(_audioId)
: Media::Player::Mixer::TimeCorrection();
const auto knownValue = correction ? correction.audioPositionValue : 0;
const auto knownValue = correction
? correction.audioPositionValue
: _startedPosition;
const auto knownTime = correction
? correction.audioPositionTime
: _startedTime;
@ -288,8 +290,7 @@ VideoTrackObject::TrackTime VideoTrackObject::trackTime() const {
const auto sinceKnown = (worldNow - knownTime);
result.worldNow = worldNow;
result.trackNow = _startedPosition
+ knownValue
result.trackNow = knownValue
+ crl::time(std::round(sinceKnown * _options.speed));
return result;
}