28 constexpr
const double kNeedForPlay = 0.3;
30 constexpr
const double kEpsilon = 0.1;
32 bool IsBufferedUntil(
const BufferedRanges& ranges,
double start_time,
33 double end_time,
double duration) {
34 for (
auto& range : ranges) {
36 (range.end >= end_time || end_time + kEpsilon >= duration)) {
43 bool CanPlay(
const BufferedRanges& ranges,
double time,
double duration) {
44 return IsBufferedUntil(ranges, time, time + kNeedForPlay, duration);
54 : mutex_(
"PipelineMonitor"),
55 start_(
"PipelineMonitor::Start"),
56 get_buffered_(
std::move(get_buffered)),
57 get_decoded_(
std::move(get_decoded)),
58 ready_state_changed_(
std::move(ready_state_changed)),
64 thread_(
"PipelineMonitor",
69 std::unique_lock<Mutex> lock(mutex_);
77 std::unique_lock<Mutex> lock(mutex_);
84 std::unique_lock<Mutex> lock(mutex_);
88 void PipelineMonitor::ThreadMain() {
89 std::unique_lock<Mutex> lock(mutex_);
108 const bool has_current_frame =
109 IsBufferedUntil(decoded, time, time, duration);
110 const bool can_start =
111 CanPlay(buffered, time, duration) && has_current_frame;
112 const bool can_play = is_playing ? has_current_frame : can_start;
113 if (time >= duration) {
115 }
else if (can_play) {
123 }
else if (can_play) {
125 }
else if (has_current_frame) {
137 if (ready_state_ != new_state) {
138 ready_state_ = new_state;
139 ready_state_changed_(new_state);
T ResetAndWaitWhileUnlocked(std::unique_lock< _Mutex > &lock)
virtual void SleepSeconds(double seconds) const