2019-02-13 18:10:18 +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
|
|
|
|
*/
|
|
|
|
#include "media/streaming/media_streaming_file.h"
|
|
|
|
|
|
|
|
#include "media/streaming/media_streaming_loader.h"
|
2019-02-17 06:54:57 +00:00
|
|
|
#include "media/streaming/media_streaming_file_delegate.h"
|
2019-06-26 15:04:38 +00:00
|
|
|
#include "ffmpeg/ffmpeg_utility.h"
|
2019-02-13 18:10:18 +00:00
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
2019-03-14 10:14:24 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMaxSingleReadAmount = 8 * 1024 * 1024;
|
2019-12-19 15:14:05 +00:00
|
|
|
constexpr auto kMaxQueuedPackets = 1024;
|
2019-03-14 10:14:24 +00:00
|
|
|
|
|
|
|
} // namespace
|
2019-02-13 18:10:18 +00:00
|
|
|
|
2019-02-17 06:54:57 +00:00
|
|
|
File::Context::Context(
|
|
|
|
not_null<FileDelegate*> delegate,
|
|
|
|
not_null<Reader*> reader)
|
|
|
|
: _delegate(delegate)
|
|
|
|
, _reader(reader)
|
|
|
|
, _size(reader->size()) {
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 11:13:27 +00:00
|
|
|
File::Context::~Context() = default;
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
int File::Context::Read(void *opaque, uint8_t *buffer, int bufferSize) {
|
|
|
|
return static_cast<Context*>(opaque)->read(
|
|
|
|
bytes::make_span(buffer, bufferSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t File::Context::Seek(void *opaque, int64_t offset, int whence) {
|
|
|
|
return static_cast<Context*>(opaque)->seek(offset, whence);
|
|
|
|
}
|
|
|
|
|
|
|
|
int File::Context::read(bytes::span buffer) {
|
|
|
|
const auto amount = std::min(size_type(_size - _offset), buffer.size());
|
2019-03-14 10:14:24 +00:00
|
|
|
Assert(amount >= 0);
|
|
|
|
|
|
|
|
if (unroll()) {
|
|
|
|
return -1;
|
|
|
|
} else if (amount > kMaxSingleReadAmount) {
|
|
|
|
LOG(("Streaming Error: Read callback asked for too much data: %1"
|
|
|
|
).arg(amount));
|
2019-02-13 18:10:18 +00:00
|
|
|
return -1;
|
|
|
|
} else if (!amount) {
|
|
|
|
return amount;
|
|
|
|
}
|
2019-02-25 17:26:08 +00:00
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
buffer = buffer.subspan(0, amount);
|
2019-02-25 17:26:08 +00:00
|
|
|
while (!_reader->fill(_offset, buffer, &_semaphore)) {
|
2019-12-19 15:14:05 +00:00
|
|
|
processQueuedPackets(SleepPolicy::Disallowed);
|
2019-02-21 13:40:09 +00:00
|
|
|
_delegate->fileWaitingForData();
|
2019-02-13 18:10:18 +00:00
|
|
|
_semaphore.acquire();
|
|
|
|
if (_interrupted) {
|
|
|
|
return -1;
|
2019-04-12 07:34:39 +00:00
|
|
|
} else if (const auto error = _reader->streamingError()) {
|
2019-03-05 13:56:27 +00:00
|
|
|
fail(*error);
|
2019-02-13 18:10:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 16:45:03 +00:00
|
|
|
|
|
|
|
sendFullInCache();
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
_offset += amount;
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t File::Context::seek(int64_t offset, int whence) {
|
|
|
|
const auto checkedSeek = [&](int64_t offset) {
|
|
|
|
if (_failed || offset < 0 || offset > _size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (_offset = offset);
|
|
|
|
};
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET: return checkedSeek(offset);
|
|
|
|
case SEEK_CUR: return checkedSeek(_offset + offset);
|
|
|
|
case SEEK_END: return checkedSeek(_size + offset);
|
|
|
|
case AVSEEK_SIZE: return _size;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void File::Context::logError(QLatin1String method) {
|
|
|
|
if (!unroll()) {
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::LogError(method);
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 15:04:38 +00:00
|
|
|
void File::Context::logError(
|
|
|
|
QLatin1String method,
|
|
|
|
FFmpeg::AvErrorWrap error) {
|
2019-02-13 18:10:18 +00:00
|
|
|
if (!unroll()) {
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::LogError(method, error);
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void File::Context::logFatal(QLatin1String method) {
|
|
|
|
if (!unroll()) {
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::LogError(method);
|
2019-03-05 13:56:27 +00:00
|
|
|
fail(_format ? Error::InvalidData : Error::OpenFailed);
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 15:04:38 +00:00
|
|
|
void File::Context::logFatal(
|
|
|
|
QLatin1String method,
|
|
|
|
FFmpeg::AvErrorWrap error) {
|
2019-02-13 18:10:18 +00:00
|
|
|
if (!unroll()) {
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::LogError(method, error);
|
2019-03-05 13:56:27 +00:00
|
|
|
fail(_format ? Error::InvalidData : Error::OpenFailed);
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
Stream File::Context::initStream(
|
|
|
|
not_null<AVFormatContext*> format,
|
|
|
|
AVMediaType type) {
|
2019-02-17 06:54:57 +00:00
|
|
|
auto result = Stream();
|
|
|
|
const auto index = result.index = av_find_best_stream(
|
2019-03-05 13:56:27 +00:00
|
|
|
format,
|
2019-02-13 18:10:18 +00:00
|
|
|
type,
|
|
|
|
-1,
|
|
|
|
-1,
|
2019-02-16 10:29:55 +00:00
|
|
|
nullptr,
|
2019-02-13 18:10:18 +00:00
|
|
|
0);
|
2019-02-17 06:54:57 +00:00
|
|
|
if (index < 0) {
|
2019-03-06 07:07:33 +00:00
|
|
|
return result;
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
const auto info = format->streams[index];
|
2019-02-13 18:10:18 +00:00
|
|
|
if (type == AVMEDIA_TYPE_VIDEO) {
|
2019-06-26 15:04:38 +00:00
|
|
|
result.rotation = FFmpeg::ReadRotationFromMetadata(info);
|
|
|
|
result.aspect = FFmpeg::ValidateAspectRatio(info->sample_aspect_ratio);
|
2019-02-17 06:54:57 +00:00
|
|
|
} else if (type == AVMEDIA_TYPE_AUDIO) {
|
|
|
|
result.frequency = info->codecpar->sample_rate;
|
|
|
|
if (!result.frequency) {
|
2019-03-06 07:07:33 +00:00
|
|
|
return result;
|
2019-02-17 06:54:57 +00:00
|
|
|
}
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 15:04:38 +00:00
|
|
|
result.codec = FFmpeg::MakeCodecPointer(info);
|
2019-02-22 12:39:32 +00:00
|
|
|
if (!result.codec) {
|
2019-03-06 07:07:33 +00:00
|
|
|
return result;
|
2019-02-22 12:39:32 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 15:04:38 +00:00
|
|
|
result.frame = FFmpeg::MakeFramePointer();
|
2019-02-17 06:54:57 +00:00
|
|
|
if (!result.frame) {
|
2019-03-06 07:07:33 +00:00
|
|
|
result.codec = nullptr;
|
|
|
|
return result;
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
2019-02-17 06:54:57 +00:00
|
|
|
result.timeBase = info->time_base;
|
|
|
|
result.duration = (info->duration != AV_NOPTS_VALUE)
|
2019-06-26 15:04:38 +00:00
|
|
|
? FFmpeg::PtsToTime(info->duration, result.timeBase)
|
|
|
|
: FFmpeg::PtsToTime(format->duration, FFmpeg::kUniversalTimeBase);
|
2019-06-17 11:28:47 +00:00
|
|
|
if (result.duration <= 0) {
|
2019-03-06 07:07:33 +00:00
|
|
|
result.codec = nullptr;
|
2019-03-13 14:58:50 +00:00
|
|
|
} else if (result.duration == kTimeUnknown) {
|
|
|
|
result.duration = kDurationUnavailable;
|
|
|
|
} else {
|
|
|
|
++result.duration;
|
|
|
|
if (result.duration > kDurationMax) {
|
|
|
|
result.duration = 0;
|
|
|
|
result.codec = nullptr;
|
|
|
|
}
|
2019-02-20 13:28:48 +00:00
|
|
|
}
|
2019-02-17 06:54:57 +00:00
|
|
|
return result;
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 11:58:26 +00:00
|
|
|
void File::Context::seekToPosition(
|
2019-03-05 13:56:27 +00:00
|
|
|
not_null<AVFormatContext*> format,
|
2019-02-22 11:58:26 +00:00
|
|
|
const Stream &stream,
|
|
|
|
crl::time position) {
|
2019-06-26 15:04:38 +00:00
|
|
|
auto error = FFmpeg::AvErrorWrap();
|
2019-02-13 18:10:18 +00:00
|
|
|
|
2019-02-17 06:54:57 +00:00
|
|
|
if (!position) {
|
2019-02-13 18:10:18 +00:00
|
|
|
return;
|
2019-03-13 14:58:50 +00:00
|
|
|
} else if (stream.duration == kDurationUnavailable) {
|
|
|
|
// Seek in files with unknown duration is not supported.
|
|
|
|
return;
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
2019-02-22 11:58:26 +00:00
|
|
|
//
|
|
|
|
// Non backward search reads the whole file if the position is after
|
|
|
|
// the last keyframe inside the index. So we search only backward.
|
|
|
|
//
|
|
|
|
//const auto seekFlags = 0;
|
|
|
|
//error = av_seek_frame(
|
2019-03-05 13:56:27 +00:00
|
|
|
// format,
|
2019-02-22 11:58:26 +00:00
|
|
|
// streamIndex,
|
|
|
|
// TimeToPts(position, kUniversalTimeBase),
|
|
|
|
// seekFlags);
|
|
|
|
//if (!error) {
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
//
|
2019-02-13 18:10:18 +00:00
|
|
|
error = av_seek_frame(
|
2019-03-05 13:56:27 +00:00
|
|
|
format,
|
2019-02-22 11:58:26 +00:00
|
|
|
stream.index,
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::TimeToPts(
|
2019-02-22 11:58:26 +00:00
|
|
|
std::clamp(position, crl::time(0), stream.duration - 1),
|
|
|
|
stream.timeBase),
|
|
|
|
AVSEEK_FLAG_BACKWARD);
|
2019-02-13 18:10:18 +00:00
|
|
|
if (!error) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return logFatal(qstr("av_seek_frame"), error);
|
|
|
|
}
|
|
|
|
|
2019-06-26 15:04:38 +00:00
|
|
|
base::variant<FFmpeg::Packet, FFmpeg::AvErrorWrap> File::Context::readPacket() {
|
|
|
|
auto error = FFmpeg::AvErrorWrap();
|
2019-02-13 18:10:18 +00:00
|
|
|
|
2019-06-26 15:04:38 +00:00
|
|
|
auto result = FFmpeg::Packet();
|
2019-03-04 11:28:52 +00:00
|
|
|
error = av_read_frame(_format.get(), &result.fields());
|
2019-02-13 18:10:18 +00:00
|
|
|
if (unroll()) {
|
2019-06-26 15:04:38 +00:00
|
|
|
return FFmpeg::AvErrorWrap();
|
2019-02-13 18:10:18 +00:00
|
|
|
} else if (!error) {
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2019-02-13 18:10:18 +00:00
|
|
|
} else if (error.code() != AVERROR_EOF) {
|
|
|
|
logFatal(qstr("av_read_frame"), error);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2019-02-17 06:54:57 +00:00
|
|
|
void File::Context::start(crl::time position) {
|
2019-06-26 15:04:38 +00:00
|
|
|
auto error = FFmpeg::AvErrorWrap();
|
2019-02-13 18:10:18 +00:00
|
|
|
|
|
|
|
if (unroll()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-06-26 15:04:38 +00:00
|
|
|
auto format = FFmpeg::MakeFormatPointer(
|
2019-03-04 11:28:52 +00:00
|
|
|
static_cast<void *>(this),
|
2019-02-13 18:10:18 +00:00
|
|
|
&Context::Read,
|
|
|
|
nullptr,
|
|
|
|
&Context::Seek);
|
2019-03-05 13:56:27 +00:00
|
|
|
if (!format) {
|
|
|
|
return fail(Error::OpenFailed);
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
if ((error = avformat_find_stream_info(format.get(), nullptr))) {
|
2019-02-13 18:10:18 +00:00
|
|
|
return logFatal(qstr("avformat_find_stream_info"), error);
|
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
auto video = initStream(format.get(), AVMEDIA_TYPE_VIDEO);
|
2019-02-13 18:10:18 +00:00
|
|
|
if (unroll()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
auto audio = initStream(format.get(), AVMEDIA_TYPE_AUDIO);
|
2019-02-13 18:10:18 +00:00
|
|
|
if (unroll()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
_reader->headerDone();
|
2019-05-31 16:45:03 +00:00
|
|
|
if (_reader->isRemoteLoader()) {
|
|
|
|
sendFullInCache(true);
|
|
|
|
}
|
2019-02-22 11:58:26 +00:00
|
|
|
if (video.codec || audio.codec) {
|
2019-03-05 13:56:27 +00:00
|
|
|
seekToPosition(format.get(), video.codec ? video : audio, position);
|
2019-02-22 11:58:26 +00:00
|
|
|
}
|
2019-02-13 18:10:18 +00:00
|
|
|
if (unroll()) {
|
2019-02-17 06:54:57 +00:00
|
|
|
return;
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +00:00
|
|
|
if (video.codec) {
|
|
|
|
_queuedPackets[video.index].reserve(kMaxQueuedPackets);
|
|
|
|
}
|
|
|
|
if (audio.codec) {
|
|
|
|
_queuedPackets[audio.index].reserve(kMaxQueuedPackets);
|
|
|
|
}
|
|
|
|
|
2019-05-31 11:45:35 +00:00
|
|
|
const auto header = _reader->headerSize();
|
|
|
|
if (!_delegate->fileReady(header, std::move(video), std::move(audio))) {
|
2019-03-05 13:56:27 +00:00
|
|
|
return fail(Error::OpenFailed);
|
2019-03-05 07:40:25 +00:00
|
|
|
}
|
2019-03-05 13:56:27 +00:00
|
|
|
_format = std::move(format);
|
2019-02-17 06:54:57 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 16:45:03 +00:00
|
|
|
void File::Context::sendFullInCache(bool force) {
|
|
|
|
const auto started = _fullInCache.has_value();
|
|
|
|
if (force || started) {
|
|
|
|
const auto nowFullInCache = _reader->fullInCache();
|
|
|
|
if (!started || *_fullInCache != nowFullInCache) {
|
|
|
|
_fullInCache = nowFullInCache;
|
|
|
|
_delegate->fileFullInCache(nowFullInCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
void File::Context::readNextPacket() {
|
|
|
|
auto result = readPacket();
|
|
|
|
if (unroll()) {
|
|
|
|
return;
|
2019-06-26 15:04:38 +00:00
|
|
|
} else if (const auto packet = base::get_if<FFmpeg::Packet>(&result)) {
|
2019-12-19 15:14:05 +00:00
|
|
|
const auto index = packet->fields().stream_index;
|
|
|
|
const auto i = _queuedPackets.find(index);
|
|
|
|
if (i == end(_queuedPackets)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i->second.push_back(std::move(*packet));
|
|
|
|
if (i->second.size() == kMaxQueuedPackets) {
|
|
|
|
processQueuedPackets(SleepPolicy::Allowed);
|
2019-02-20 13:28:48 +00:00
|
|
|
}
|
2019-02-13 18:10:18 +00:00
|
|
|
} else {
|
|
|
|
// Still trying to read by drain.
|
2019-06-26 15:04:38 +00:00
|
|
|
Assert(result.is<FFmpeg::AvErrorWrap>());
|
|
|
|
Assert(result.get<FFmpeg::AvErrorWrap>().code() == AVERROR_EOF);
|
2019-12-19 15:14:05 +00:00
|
|
|
processQueuedPackets(SleepPolicy::Allowed);
|
|
|
|
if (!finished()) {
|
|
|
|
handleEndOfFile();
|
|
|
|
}
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-25 10:17:25 +00:00
|
|
|
|
2019-02-17 06:54:57 +00:00
|
|
|
void File::Context::handleEndOfFile() {
|
2019-12-19 15:14:05 +00:00
|
|
|
const auto more = _delegate->fileProcessEndOfFile();
|
2019-03-05 07:40:25 +00:00
|
|
|
if (_delegate->fileReadMore()) {
|
|
|
|
_readTillEnd = false;
|
2019-06-26 15:04:38 +00:00
|
|
|
auto error = FFmpeg::AvErrorWrap(av_seek_frame(
|
2019-03-05 07:40:25 +00:00
|
|
|
_format.get(),
|
|
|
|
-1, // stream_index
|
|
|
|
0, // timestamp
|
|
|
|
AVSEEK_FLAG_BACKWARD));
|
|
|
|
if (error) {
|
|
|
|
logFatal(qstr("av_seek_frame"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_readTillEnd = true;
|
|
|
|
}
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +00:00
|
|
|
void File::Context::processQueuedPackets(SleepPolicy policy) {
|
|
|
|
const auto more = _delegate->fileProcessPackets(_queuedPackets);
|
|
|
|
if (!more && policy == SleepPolicy::Allowed) {
|
|
|
|
do {
|
|
|
|
_reader->startSleep(&_semaphore);
|
|
|
|
_semaphore.acquire();
|
|
|
|
_reader->stopSleep();
|
|
|
|
} while (!unroll() && !_delegate->fileReadMore());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
void File::Context::interrupt() {
|
|
|
|
_interrupted = true;
|
|
|
|
_semaphore.release();
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:28:48 +00:00
|
|
|
void File::Context::wake() {
|
|
|
|
_semaphore.release();
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
bool File::Context::interrupted() const {
|
|
|
|
return _interrupted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool File::Context::failed() const {
|
|
|
|
return _failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool File::Context::unroll() const {
|
|
|
|
return failed() || interrupted();
|
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
void File::Context::fail(Error error) {
|
2019-02-17 06:54:57 +00:00
|
|
|
_failed = true;
|
2019-03-05 13:56:27 +00:00
|
|
|
_delegate->fileError(error);
|
2019-02-17 06:54:57 +00:00
|
|
|
}
|
2019-02-13 18:10:18 +00:00
|
|
|
|
|
|
|
bool File::Context::finished() const {
|
2019-02-25 10:17:25 +00:00
|
|
|
return unroll() || _readTillEnd;
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 11:13:27 +00:00
|
|
|
void File::Context::waitTillInterrupted() {
|
|
|
|
while (!interrupted()) {
|
|
|
|
_reader->startSleep(&_semaphore);
|
|
|
|
_semaphore.acquire();
|
|
|
|
}
|
|
|
|
_reader->stopSleep();
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
File::File(
|
|
|
|
not_null<Data::Session*> owner,
|
2019-04-10 11:26:15 +00:00
|
|
|
std::shared_ptr<Reader> reader)
|
|
|
|
: _reader(std::move(reader)) {
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 06:54:57 +00:00
|
|
|
void File::start(not_null<FileDelegate*> delegate, crl::time position) {
|
2019-04-11 10:52:49 +00:00
|
|
|
stop(true);
|
2019-02-17 06:54:57 +00:00
|
|
|
|
2019-04-11 10:52:49 +00:00
|
|
|
_reader->startStreaming();
|
2019-04-10 11:26:15 +00:00
|
|
|
_context.emplace(delegate, _reader.get());
|
2019-02-17 11:08:29 +00:00
|
|
|
_thread = std::thread([=, context = &*_context] {
|
2019-02-17 06:54:57 +00:00
|
|
|
context->start(position);
|
|
|
|
while (!context->finished()) {
|
|
|
|
context->readNextPacket();
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
2019-12-19 11:13:27 +00:00
|
|
|
context->waitTillInterrupted();
|
2019-02-13 18:10:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:28:48 +00:00
|
|
|
void File::wake() {
|
|
|
|
Expects(_context.has_value());
|
|
|
|
|
|
|
|
_context->wake();
|
|
|
|
}
|
|
|
|
|
2019-04-11 10:52:49 +00:00
|
|
|
void File::stop(bool stillActive) {
|
2019-02-13 18:10:18 +00:00
|
|
|
if (_thread.joinable()) {
|
|
|
|
_context->interrupt();
|
|
|
|
_thread.join();
|
|
|
|
}
|
2019-04-11 10:52:49 +00:00
|
|
|
_reader->stopStreaming(stillActive);
|
2019-02-17 06:54:57 +00:00
|
|
|
_context.reset();
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 13:56:27 +00:00
|
|
|
bool File::isRemoteLoader() const {
|
2019-04-10 11:26:15 +00:00
|
|
|
return _reader->isRemoteLoader();
|
2019-03-05 13:56:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
File::~File() {
|
2019-02-17 06:54:57 +00:00
|
|
|
stop();
|
2019-02-13 18:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|