Shaka Packager SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
simple_hls_notifier.h
1 // Copyright 2016 Google Inc. 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 <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "packager/base/atomic_sequence_num.h"
16 #include "packager/base/macros.h"
17 #include "packager/base/synchronization/lock.h"
18 #include "packager/hls/base/hls_notifier.h"
19 #include "packager/hls/base/master_playlist.h"
20 #include "packager/hls/base/media_playlist.h"
21 #include "packager/hls/public/hls_params.h"
22 
23 namespace shaka {
24 namespace hls {
25 
29  public:
30  virtual ~MediaPlaylistFactory();
31  virtual std::unique_ptr<MediaPlaylist> Create(HlsPlaylistType type,
32  double time_shift_buffer_depth,
33  const std::string& file_name,
34  const std::string& name,
35  const std::string& group_id);
36 };
37 
40  public:
52  double time_shift_buffer_depth,
53  const std::string& prefix,
54  const std::string& output_dir,
55  const std::string& master_playlist_name);
56  ~SimpleHlsNotifier() override;
57 
60  bool Init() override;
61  bool NotifyNewStream(const MediaInfo& media_info,
62  const std::string& playlist_name,
63  const std::string& stream_name,
64  const std::string& group_id,
65  uint32_t* stream_id) override;
66  bool NotifyNewSegment(uint32_t stream_id,
67  const std::string& segment_name,
68  uint64_t start_time,
69  uint64_t duration,
70  uint64_t start_byte_offset,
71  uint64_t size) override;
73  uint32_t stream_id,
74  const std::vector<uint8_t>& key_id,
75  const std::vector<uint8_t>& system_id,
76  const std::vector<uint8_t>& iv,
77  const std::vector<uint8_t>& protection_system_specific_data) override;
78  bool Flush() override;
80 
81  private:
82  friend class SimpleHlsNotifierTest;
83 
84  struct StreamEntry {
85  std::unique_ptr<MediaPlaylist> media_playlist;
86  MediaPlaylist::EncryptionMethod encryption_method;
87  };
88 
89  const double time_shift_buffer_depth_ = 0;
90  const std::string prefix_;
91  const std::string output_dir_;
92  uint32_t target_duration_ = 0;
93 
94  std::unique_ptr<MediaPlaylistFactory> media_playlist_factory_;
95  std::unique_ptr<MasterPlaylist> master_playlist_;
96 
97  // Maps to unique_ptr because StreamEntry also holds unique_ptr
98  std::map<uint32_t, std::unique_ptr<StreamEntry>> stream_map_;
99 
100  base::AtomicSequenceNumber sequence_number_;
101 
102  base::Lock lock_;
103 
104  DISALLOW_COPY_AND_ASSIGN(SimpleHlsNotifier);
105 };
106 
107 } // namespace hls
108 } // namespace shaka
109 
110 #endif // PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
SimpleHlsNotifier(HlsPlaylistType playlist_type, double time_shift_buffer_depth, const std::string &prefix, const std::string &output_dir, const std::string &master_playlist_name)
HlsPlaylistType
Definition: hls_params.h:16
bool NotifyNewSegment(uint32_t stream_id, const std::string &segment_name, uint64_t start_time, uint64_t duration, uint64_t start_byte_offset, uint64_t size) override
HlsPlaylistType playlist_type() const
Definition: hls_notifier.h:80
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 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