7 #include "packager/media/chunking/sync_point_queue.h"
8 #include "packager/media/base/media_handler.h"
16 SyncPointQueue::SyncPointQueue(
const AdCueGeneratorParams& params)
17 : sync_condition_(&lock_) {
18 for (
const Cuepoint& point : params.cue_points) {
19 std::shared_ptr<CueEvent>
event = std::make_shared<CueEvent>();
20 event->time_in_seconds = point.start_time_in_seconds;
21 unpromoted_[point.start_time_in_seconds] = std::move(event);
25 void SyncPointQueue::AddThread() {
26 base::AutoLock auto_lock(lock_);
30 void SyncPointQueue::Cancel() {
32 base::AutoLock auto_lock(lock_);
35 sync_condition_.Broadcast();
38 double SyncPointQueue::GetHint(
double time_in_seconds) {
39 base::AutoLock auto_lock(lock_);
41 auto iter = promoted_.upper_bound(time_in_seconds);
42 if (iter != promoted_.end())
45 iter = unpromoted_.upper_bound(time_in_seconds);
46 if (iter != unpromoted_.end())
51 return std::numeric_limits<double>::max();
54 std::shared_ptr<const CueEvent> SyncPointQueue::GetNext(
55 double hint_in_seconds) {
56 base::AutoLock auto_lock(lock_);
60 auto iter = promoted_.lower_bound(hint_in_seconds);
61 if (iter != promoted_.end()) {
66 if (waiting_thread_count_ + 1 == thread_count_) {
67 std::shared_ptr<const CueEvent> cue = PromoteAtNoLocking(hint_in_seconds);
72 waiting_thread_count_++;
78 sync_condition_.Wait();
79 waiting_thread_count_--;
84 std::shared_ptr<const CueEvent> SyncPointQueue::PromoteAt(
85 double time_in_seconds) {
86 base::AutoLock auto_lock(lock_);
87 return PromoteAtNoLocking(time_in_seconds);
90 bool SyncPointQueue::HasMore(
double hint_in_seconds)
const {
91 return hint_in_seconds < std::numeric_limits<double>::max();
94 std::shared_ptr<const CueEvent> SyncPointQueue::PromoteAtNoLocking(
95 double time_in_seconds) {
96 lock_.AssertAcquired();
99 auto iter = promoted_.find(time_in_seconds);
100 if (iter != promoted_.end())
107 iter = unpromoted_.upper_bound(time_in_seconds);
111 if (iter == unpromoted_.begin())
113 auto prev_iter = std::prev(iter);
114 DCHECK(prev_iter != unpromoted_.end());
116 std::shared_ptr<CueEvent> cue = prev_iter->second;
117 cue->time_in_seconds = time_in_seconds;
119 promoted_[time_in_seconds] = cue;
123 unpromoted_.erase(unpromoted_.begin(), iter);
126 sync_condition_.Broadcast();
127 return std::move(cue);
All the methods that are virtual are virtual for mocking.