17 #include <glog/logging.h> 34 constexpr
const double kDecodeBufferSize = 1;
37 constexpr
const double kEndDelta = 0.1;
39 double DecodedAheadOf(StreamBase* stream,
double time) {
40 for (
auto& range : stream->GetBufferedRanges()) {
41 if (range.end > time) {
43 return range.end - std::max(time, range.start);
56 : mutex_(
"DecoderThread"),
57 signal_(
"DecoderChanged"),
63 last_frame_time_(NAN),
66 raised_waiting_event_(false),
71 std::unique_lock<Mutex> lock(mutex_);
79 std::unique_lock<Mutex> lock(mutex_);
81 if (input && decoder_)
86 std::unique_lock<Mutex> lock(mutex_);
91 std::unique_lock<Mutex> lock(mutex_);
92 last_frame_time_ = NAN;
96 output_->
Remove(0, INFINITY);
100 std::unique_lock<Mutex> lock(mutex_);
105 std::unique_lock<Mutex> lock(mutex_);
107 if (decoder && input_)
111 void DecoderThread::ThreadMain() {
112 std::unique_lock<Mutex> lock(mutex_);
114 if (!input_ || !decoder_) {
116 LOG(DFATAL) <<
"No decoder provided and no default decoder exists";
123 double last_time = last_frame_time_;
125 if (DecodedAheadOf(output_, cur_time) > kDecodeBufferSize) {
133 output_->
Remove(0, cur_time - kDecodeBufferSize);
135 std::shared_ptr<EncodedFrame>
frame;
136 if (std::isnan(last_time)) {
144 if (!std::isnan(last_time) &&
145 last_time + kEndDelta >= client_->
Duration() && !did_flush_) {
157 std::vector<std::shared_ptr<DecodedFrame>> decoded;
159 decoder_->
Decode(frame, cdm_, &decoded, &error);
162 if (!raised_waiting_event_) {
163 raised_waiting_event_ =
true;
177 raised_waiting_event_ =
false;
178 for (
auto& decoded_frame : decoded) {
183 last_frame_time_ = frame->dts;
std::shared_ptr< shaka::media::DecodedFrame > frame
T ResetAndWaitWhileUnlocked(std::unique_lock< _Mutex > &lock)
static const Clock Instance
virtual void SleepSeconds(double seconds) const