Shaka Packager SDK
sync_point_queue.h
1 // Copyright 2018 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include <map>
8 #include <memory>
9 
10 #include <absl/synchronization/mutex.h>
11 
12 #include <packager/ad_cue_generator_params.h>
13 
14 namespace shaka {
15 namespace media {
16 
17 struct CueEvent;
18 
21  public:
22  explicit SyncPointQueue(const AdCueGeneratorParams& params);
23  ~SyncPointQueue() = default;
24 
27  void AddThread();
28 
30  void Cancel();
31 
36  double GetHint(double time_in_seconds);
37 
44  std::shared_ptr<const CueEvent> GetNext(double hint_in_seconds);
45 
48  std::shared_ptr<const CueEvent> PromoteAt(double time_in_seconds);
49 
53  bool HasMore(double hint_in_seconds) const;
54 
55  private:
56  SyncPointQueue(const SyncPointQueue&) = delete;
57  SyncPointQueue& operator=(const SyncPointQueue&) = delete;
58 
59  // PromoteAt() without locking. It is called by PromoteAt() and other
60  // functions that have locks.
61  std::shared_ptr<const CueEvent> PromoteAtNoLocking(double time_in_seconds);
62 
63  absl::Mutex mutex_;
64  absl::CondVar sync_condition_ ABSL_GUARDED_BY(mutex_);
65  size_t thread_count_ = 0;
66  size_t waiting_thread_count_ = 0;
67  bool cancelled_ = false;
68 
69  std::map<double, std::shared_ptr<CueEvent>> unpromoted_;
70  std::map<double, std::shared_ptr<CueEvent>> promoted_;
71 };
72 
73 } // namespace media
74 } // namespace shaka
A synchronized queue for cue points.
std::shared_ptr< const CueEvent > PromoteAt(double time_in_seconds)
std::shared_ptr< const CueEvent > GetNext(double hint_in_seconds)
bool HasMore(double hint_in_seconds) const
void Cancel()
Cancel the queue and unblock all threads.
double GetHint(double time_in_seconds)
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66