Shaka Packager SDK
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 <list>
11 #include <map>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
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(const HlsParams& hls_params,
32  const std::string& file_name,
33  const std::string& name,
34  const std::string& group_id);
35 };
36 
39  public:
41  explicit SimpleHlsNotifier(const HlsParams& hls_params);
42  ~SimpleHlsNotifier() override;
43 
46  bool Init() override;
47  bool NotifyNewStream(const MediaInfo& media_info,
48  const std::string& playlist_name,
49  const std::string& stream_name,
50  const std::string& group_id,
51  uint32_t* stream_id) override;
52  bool NotifySampleDuration(uint32_t stream_id,
53  uint32_t sample_duration) override;
54  bool NotifyNewSegment(uint32_t stream_id,
55  const std::string& segment_name,
56  uint64_t start_time,
57  uint64_t duration,
58  uint64_t start_byte_offset,
59  uint64_t size) override;
60  bool NotifyKeyFrame(uint32_t stream_id,
61  uint64_t timestamp,
62  uint64_t start_byte_offset,
63  uint64_t size) override;
64  bool NotifyCueEvent(uint32_t container_id, uint64_t timestamp) override;
65  bool NotifyEncryptionUpdate(
66  uint32_t stream_id,
67  const std::vector<uint8_t>& key_id,
68  const std::vector<uint8_t>& system_id,
69  const std::vector<uint8_t>& iv,
70  const std::vector<uint8_t>& protection_system_specific_data) override;
71  bool Flush() override;
73 
74  private:
75  friend class SimpleHlsNotifierTest;
76 
77  struct StreamEntry {
78  std::unique_ptr<MediaPlaylist> media_playlist;
79  MediaPlaylist::EncryptionMethod encryption_method;
80  };
81 
82  std::string master_playlist_dir_;
83  uint32_t target_duration_ = 0;
84 
85  std::unique_ptr<MediaPlaylistFactory> media_playlist_factory_;
86  std::unique_ptr<MasterPlaylist> master_playlist_;
87 
88  // Maps to unique_ptr because StreamEntry also holds unique_ptr
89  std::map<uint32_t, std::unique_ptr<StreamEntry>> stream_map_;
90  std::list<MediaPlaylist*> media_playlists_;
91 
92  uint32_t sequence_number_ = 0;
93 
94  base::Lock lock_;
95 
96  DISALLOW_COPY_AND_ASSIGN(SimpleHlsNotifier);
97 };
98 
99 } // namespace hls
100 } // namespace shaka
101 
102 #endif // PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
HLS related parameters.
Definition: hls_params.h:23
All the methods that are virtual are virtual for mocking.