7 #include <packager/media/chunking/sync_point_queue.h>
12 #include <absl/log/check.h>
14 #include <packager/media/base/media_handler.h>
19 SyncPointQueue::SyncPointQueue(
const AdCueGeneratorParams& params) {
20 for (
const Cuepoint& point : params.cue_points) {
21 std::shared_ptr<CueEvent>
event = std::make_shared<CueEvent>();
22 event->time_in_seconds = point.start_time_in_seconds;
23 unpromoted_[point.start_time_in_seconds] = std::move(event);
28 absl::MutexLock lock(&mutex_);
34 absl::MutexLock lock(&mutex_);
37 sync_condition_.SignalAll();
41 absl::MutexLock lock(&mutex_);
43 auto iter = promoted_.upper_bound(time_in_seconds);
44 if (iter != promoted_.end())
47 iter = unpromoted_.upper_bound(time_in_seconds);
48 if (iter != unpromoted_.end())
53 return std::numeric_limits<double>::max();
57 double hint_in_seconds) {
58 absl::MutexLock lock(&mutex_);
62 auto iter = promoted_.lower_bound(hint_in_seconds);
63 if (iter != promoted_.end()) {
68 if (waiting_thread_count_ + 1 == thread_count_) {
69 std::shared_ptr<const CueEvent> cue = PromoteAtNoLocking(hint_in_seconds);
74 waiting_thread_count_++;
80 sync_condition_.Wait(&mutex_);
81 waiting_thread_count_--;
87 double time_in_seconds) {
88 absl::MutexLock lock(&mutex_);
89 return PromoteAtNoLocking(time_in_seconds);
93 return hint_in_seconds < std::numeric_limits<double>::max();
96 std::shared_ptr<const CueEvent> SyncPointQueue::PromoteAtNoLocking(
97 double time_in_seconds) {
101 auto iter = promoted_.find(time_in_seconds);
102 if (iter != promoted_.end())
109 iter = unpromoted_.upper_bound(time_in_seconds);
113 if (iter == unpromoted_.begin())
115 auto prev_iter = std::prev(iter);
116 DCHECK(prev_iter != unpromoted_.end());
118 std::shared_ptr<CueEvent> cue = prev_iter->second;
119 cue->time_in_seconds = time_in_seconds;
121 promoted_[time_in_seconds] = cue;
125 unpromoted_.erase(unpromoted_.begin(), iter);
128 sync_condition_.SignalAll();
All the methods that are virtual are virtual for mocking.