Fix download of short videos in media overlay.

This commit is contained in:
John Preston 2019-12-19 14:13:27 +03:00
parent 4cdf08cbfb
commit 041670b8e7
4 changed files with 27 additions and 7 deletions

View File

@ -261,10 +261,8 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
if (!autoPaused) {
_parent->delegate()->elementAnimationAutoplayAsync(_parent);
}
} else if (_streamed
&& !_streamed->instance.active()
&& !_streamed->instance.failed()) {
startStreamedPlayer();
} else {
checkStreamedIsStarted();
}
const auto streamingMode = _streamed || activeRoundPlaying || autoplay;
const auto activeOwnPlaying = activeOwnStreamed();
@ -1204,6 +1202,17 @@ void Gif::startStreamedPlayer() const {
_streamed->instance.play(options);
}
void Gif::checkStreamedIsStarted() const {
if (!_streamed) {
return;
} else if (_streamed->instance.paused()) {
_streamed->instance.resume();
}
if (!_streamed->instance.active() && !_streamed->instance.failed()) {
startStreamedPlayer();
}
}
void Gif::setStreamed(std::unique_ptr<Streamed> value) {
const auto removed = (_streamed && !value);
const auto set = (!_streamed && value);

View File

@ -120,6 +120,7 @@ private:
::Media::View::PlaybackProgress *videoPlayback() const;
void createStreamedPlayer();
void checkStreamedIsStarted() const;
void startStreamedPlayer() const;
void setStreamed(std::unique_ptr<Streamed> value);
void handleStreamingUpdate(::Media::Streaming::Update &&update);

View File

@ -27,6 +27,8 @@ File::Context::Context(
, _size(reader->size()) {
}
File::Context::~Context() = default;
int File::Context::Read(void *opaque, uint8_t *buffer, int bufferSize) {
return static_cast<Context*>(opaque)->read(
bytes::make_span(buffer, bufferSize));
@ -344,12 +346,18 @@ void File::Context::fail(Error error) {
_delegate->fileError(error);
}
File::Context::~Context() = default;
bool File::Context::finished() const {
return unroll() || _readTillEnd;
}
void File::Context::waitTillInterrupted() {
while (!interrupted()) {
_reader->startSleep(&_semaphore);
_semaphore.acquire();
}
_reader->stopSleep();
}
File::File(
not_null<Data::Session*> owner,
std::shared_ptr<Reader> reader)
@ -366,6 +374,7 @@ void File::start(not_null<FileDelegate*> delegate, crl::time position) {
while (!context->finished()) {
context->readNextPacket();
}
context->waitTillInterrupted();
});
}

View File

@ -44,6 +44,7 @@ private:
class Context final : public base::has_weak_ptr {
public:
Context(not_null<FileDelegate*> delegate, not_null<Reader*> reader);
~Context();
void start(crl::time position);
void readNextPacket();
@ -54,7 +55,7 @@ private:
[[nodiscard]] bool failed() const;
[[nodiscard]] bool finished() const;
~Context();
void waitTillInterrupted();
private:
static int Read(void *opaque, uint8_t *buffer, int bufferSize);