Shaka Packager SDK
Loading...
Searching...
No Matches
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 <cstddef>
8#include <map>
9#include <memory>
10
11#include <absl/base/thread_annotations.h>
12#include <absl/synchronization/mutex.h>
13
14#include <packager/ad_cue_generator_params.h>
15
16namespace shaka {
17namespace media {
18
19struct CueEvent;
20
23 public:
24 explicit SyncPointQueue(const AdCueGeneratorParams& params);
25 ~SyncPointQueue() = default;
26
29 void AddThread();
30
32 void Cancel();
33
38 double GetHint(double time_in_seconds);
39
46 std::shared_ptr<const CueEvent> GetNext(double hint_in_seconds);
47
50 std::shared_ptr<const CueEvent> PromoteAt(double time_in_seconds);
51
55 bool HasMore(double hint_in_seconds) const;
56
57 private:
58 SyncPointQueue(const SyncPointQueue&) = delete;
59 SyncPointQueue& operator=(const SyncPointQueue&) = delete;
60
61 // PromoteAt() without locking. It is called by PromoteAt() and other
62 // functions that have locks.
63 std::shared_ptr<const CueEvent> PromoteAtNoLocking(double time_in_seconds);
64
65 absl::Mutex mutex_;
66 absl::CondVar sync_condition_ ABSL_GUARDED_BY(mutex_);
67 size_t thread_count_ = 0;
68 size_t waiting_thread_count_ = 0;
69 bool cancelled_ = false;
70
71 std::map<double, std::shared_ptr<CueEvent>> unpromoted_;
72 std::map<double, std::shared_ptr<CueEvent>> promoted_;
73};
74
75} // namespace media
76} // 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.