Shaka Packager SDK
Loading...
Searching...
No Matches
simple_hls_notifier.h
1// Copyright 2016 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#ifndef PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
8#define PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
9
10#include <cstdint>
11#include <list>
12#include <map>
13#include <memory>
14#include <string>
15#include <vector>
16
17#include <absl/synchronization/mutex.h>
18
19#include <packager/hls/base/hls_notifier.h>
20#include <packager/hls/base/master_playlist.h>
21#include <packager/hls/base/media_playlist.h>
22#include <packager/hls_params.h>
23#include <packager/macros/classes.h>
24
25namespace shaka {
26namespace hls {
27
31 public:
32 virtual ~MediaPlaylistFactory();
33 virtual std::unique_ptr<MediaPlaylist> Create(const HlsParams& hls_params,
34 const std::string& file_name,
35 const std::string& name,
36 const std::string& group_id);
37};
38
41 public:
43 explicit SimpleHlsNotifier(const HlsParams& hls_params);
44 ~SimpleHlsNotifier() override;
45
48 bool Init() override;
49 bool NotifyNewStream(const MediaInfo& media_info,
50 const std::string& playlist_name,
51 const std::string& stream_name,
52 const std::string& group_id,
53 uint32_t* stream_id) override;
54 bool NotifySampleDuration(uint32_t stream_id,
55 int32_t sample_duration) override;
56 bool NotifyNewSegment(uint32_t stream_id,
57 const std::string& segment_name,
58 int64_t start_time,
59 int64_t duration,
60 uint64_t start_byte_offset,
61 uint64_t size) override;
62 bool NotifyKeyFrame(uint32_t stream_id,
63 int64_t timestamp,
64 uint64_t start_byte_offset,
65 uint64_t size) override;
66 bool NotifyCueEvent(uint32_t container_id, int64_t timestamp) override;
68 uint32_t stream_id,
69 const std::vector<uint8_t>& key_id,
70 const std::vector<uint8_t>& system_id,
71 const std::vector<uint8_t>& iv,
72 const std::vector<uint8_t>& protection_system_specific_data) override;
73 bool Flush() override;
75
76 protected:
77 const absl::Time& reference_time() const { return reference_time_; }
78
79 private:
80 friend class SimpleHlsNotifierTest;
81
82 struct StreamEntry {
83 std::unique_ptr<MediaPlaylist> media_playlist;
84 MediaPlaylist::EncryptionMethod encryption_method;
85 };
86
87 std::string master_playlist_dir_;
88 int32_t target_duration_ = 0;
89
90 std::unique_ptr<MediaPlaylistFactory> media_playlist_factory_;
91 std::unique_ptr<MasterPlaylist> master_playlist_;
92
93 // Maps to unique_ptr because StreamEntry also holds unique_ptr
94 std::map<uint32_t, std::unique_ptr<StreamEntry>> stream_map_;
95 std::list<MediaPlaylist*> media_playlists_;
96
97 uint32_t sequence_number_ = 0;
98
99 absl::Mutex lock_;
100 absl::Time reference_time_ = absl::InfinitePast();
101
102 DISALLOW_COPY_AND_ASSIGN(SimpleHlsNotifier);
103};
104
105} // namespace hls
106} // namespace shaka
107
108#endif // PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
const HlsParams & hls_params() const
bool NotifyNewSegment(uint32_t stream_id, const std::string &segment_name, int64_t start_time, int64_t duration, uint64_t start_byte_offset, uint64_t size) override
bool NotifyNewStream(const MediaInfo &media_info, const std::string &playlist_name, const std::string &stream_name, const std::string &group_id, uint32_t *stream_id) override
bool NotifyKeyFrame(uint32_t stream_id, int64_t timestamp, uint64_t start_byte_offset, uint64_t size) override
const absl::Time & reference_time() const
}@
bool NotifyEncryptionUpdate(uint32_t stream_id, const std::vector< uint8_t > &key_id, const std::vector< uint8_t > &system_id, const std::vector< uint8_t > &iv, const std::vector< uint8_t > &protection_system_specific_data) override
bool NotifyCueEvent(uint32_t container_id, int64_t timestamp) override
bool NotifySampleDuration(uint32_t stream_id, int32_t sample_duration) override
All the methods that are virtual are virtual for mocking.