2016-03-25 08:40:15 +00:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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_
|
|
|
|
|
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>
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
#include "packager/base/atomic_sequence_num.h"
|
|
|
|
#include "packager/base/macros.h"
|
2016-04-17 07:12:10 +00:00
|
|
|
#include "packager/base/stl_util.h"
|
2016-03-25 08:40:15 +00:00
|
|
|
#include "packager/base/synchronization/lock.h"
|
|
|
|
#include "packager/hls/base/hls_notifier.h"
|
|
|
|
#include "packager/hls/base/master_playlist.h"
|
2016-04-20 22:23:19 +00:00
|
|
|
#include "packager/hls/base/media_playlist.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();
|
2016-08-17 17:41:40 +00:00
|
|
|
virtual std::unique_ptr<MediaPlaylist> Create(
|
2016-04-20 22:23:19 +00:00
|
|
|
MediaPlaylist::MediaPlaylistType type,
|
|
|
|
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:
|
|
|
|
/// @a prefix is used as hte prefix for all the URIs for Media Playlist. This
|
|
|
|
/// includes the segment URIs in the Media Playlists.
|
2016-04-20 22:23:19 +00:00
|
|
|
/// @param profile is the profile of the playlists.
|
2016-03-25 08:40:15 +00:00
|
|
|
/// @param prefix is the used as the prefix for MediaPlaylist URIs. May be
|
|
|
|
/// empty for relative URI from the playlist.
|
|
|
|
/// @param output_dir is the output directory of the playlists. May be empty
|
|
|
|
/// to write to current directory.
|
|
|
|
/// @param master_playlist_name is the name of the master playlist.
|
2016-04-20 22:23:19 +00:00
|
|
|
SimpleHlsNotifier(HlsProfile profile,
|
|
|
|
const std::string& prefix,
|
2016-03-25 08:40:15 +00:00
|
|
|
const std::string& output_dir,
|
|
|
|
const std::string& master_playlist_name);
|
|
|
|
~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;
|
|
|
|
bool NotifyNewSegment(uint32_t stream_id,
|
|
|
|
const std::string& segment_name,
|
|
|
|
uint64_t start_time,
|
|
|
|
uint64_t duration,
|
|
|
|
uint64_t size) 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;
|
|
|
|
bool Flush() override;
|
|
|
|
/// }@
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SimpleHlsNotifierTest;
|
|
|
|
|
|
|
|
const std::string prefix_;
|
|
|
|
const std::string output_dir_;
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MediaPlaylistFactory> media_playlist_factory_;
|
|
|
|
std::unique_ptr<MasterPlaylist> master_playlist_;
|
2016-04-17 07:12:10 +00:00
|
|
|
std::map<uint32_t, MediaPlaylist*> media_playlist_map_;
|
|
|
|
STLValueDeleter<decltype(media_playlist_map_)> media_playlist_map_deleter_;
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
base::AtomicSequenceNumber sequence_number_;
|
|
|
|
|
|
|
|
base::Lock lock_;
|
|
|
|
|
|
|
|
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_
|