2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2016 Google LLC. All rights reserved.
|
2016-03-25 08:40:15 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
|
|
|
|
#define PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
|
|
|
|
|
2018-02-02 17:14:46 +00:00
|
|
|
#include <list>
|
2016-05-19 23:43:13 +00:00
|
|
|
#include <map>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2016-05-19 23:43:13 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-08-22 01:41:18 +00:00
|
|
|
#include <absl/synchronization/mutex.h>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/hls/base/hls_notifier.h>
|
|
|
|
#include <packager/hls/base/master_playlist.h>
|
|
|
|
#include <packager/hls/base/media_playlist.h>
|
|
|
|
#include <packager/hls/public/hls_params.h>
|
|
|
|
#include <packager/macros.h>
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-25 08:40:15 +00:00
|
|
|
namespace hls {
|
|
|
|
|
|
|
|
/// For testing.
|
|
|
|
/// Creates MediaPlaylist. Mock this and return mock MediaPlaylist.
|
|
|
|
class MediaPlaylistFactory {
|
|
|
|
public:
|
|
|
|
virtual ~MediaPlaylistFactory();
|
2018-04-14 01:26:02 +00:00
|
|
|
virtual std::unique_ptr<MediaPlaylist> Create(const HlsParams& hls_params,
|
2017-06-30 20:42:46 +00:00
|
|
|
const std::string& file_name,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& group_id);
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This is thread safe.
|
|
|
|
class SimpleHlsNotifier : public HlsNotifier {
|
|
|
|
public:
|
2018-01-17 23:43:41 +00:00
|
|
|
/// @param hls_params contains parameters for setting up the notifier.
|
|
|
|
explicit SimpleHlsNotifier(const HlsParams& hls_params);
|
2016-03-25 08:40:15 +00:00
|
|
|
~SimpleHlsNotifier() override;
|
|
|
|
|
|
|
|
/// @name HlsNotifier implemetation overrides.
|
|
|
|
/// @{
|
|
|
|
bool Init() 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;
|
2019-09-23 06:47:07 +00:00
|
|
|
bool NotifySampleDuration(uint32_t stream_id,
|
2021-08-04 18:56:44 +00:00
|
|
|
int32_t sample_duration) override;
|
2016-03-25 08:40:15 +00:00
|
|
|
bool NotifyNewSegment(uint32_t stream_id,
|
|
|
|
const std::string& segment_name,
|
2021-08-04 18:56:44 +00:00
|
|
|
int64_t start_time,
|
|
|
|
int64_t duration,
|
2017-05-01 20:38:58 +00:00
|
|
|
uint64_t start_byte_offset,
|
2016-03-25 08:40:15 +00:00
|
|
|
uint64_t size) override;
|
2018-01-31 02:30:19 +00:00
|
|
|
bool NotifyKeyFrame(uint32_t stream_id,
|
2021-08-04 18:56:44 +00:00
|
|
|
int64_t timestamp,
|
2018-01-31 02:30:19 +00:00
|
|
|
uint64_t start_byte_offset,
|
|
|
|
uint64_t size) override;
|
2021-08-04 18:56:44 +00:00
|
|
|
bool NotifyCueEvent(uint32_t container_id, int64_t timestamp) override;
|
2016-03-25 08:40:15 +00:00
|
|
|
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 Flush() override;
|
|
|
|
/// }@
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SimpleHlsNotifierTest;
|
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
struct StreamEntry {
|
|
|
|
std::unique_ptr<MediaPlaylist> media_playlist;
|
|
|
|
MediaPlaylist::EncryptionMethod encryption_method;
|
|
|
|
};
|
|
|
|
|
2019-04-30 22:29:37 +00:00
|
|
|
std::string master_playlist_dir_;
|
2021-08-04 18:56:44 +00:00
|
|
|
int32_t target_duration_ = 0;
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MediaPlaylistFactory> media_playlist_factory_;
|
|
|
|
std::unique_ptr<MasterPlaylist> master_playlist_;
|
2017-04-04 20:57:50 +00:00
|
|
|
|
|
|
|
// Maps to unique_ptr because StreamEntry also holds unique_ptr
|
|
|
|
std::map<uint32_t, std::unique_ptr<StreamEntry>> stream_map_;
|
2018-02-02 17:14:46 +00:00
|
|
|
std::list<MediaPlaylist*> media_playlists_;
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2018-07-23 22:24:20 +00:00
|
|
|
uint32_t sequence_number_ = 0;
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2023-08-22 01:41:18 +00:00
|
|
|
absl::Mutex lock_;
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SimpleHlsNotifier);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace hls
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
#endif // PACKAGER_HLS_BASE_SIMPLE_HLS_NOTIFIER_H_
|