Shaka Packager SDK
Classes | Public Types | Public Member Functions | List of all members
shaka::hls::MediaPlaylist Class Reference

Methods are virtual for mocking. More...

#include <media_playlist.h>

Inheritance diagram for shaka::hls::MediaPlaylist:
shaka::hls::MockMediaPlaylist

Public Types

enum class  MediaPlaylistStreamType {
  kUnknown , kAudio , kVideo , kVideoIFramesOnly ,
  kSubtitle
}
 
enum class  EncryptionMethod { kNone , kAes128 , kSampleAes , kSampleAesCenc }
 

Public Member Functions

 MediaPlaylist (const HlsParams &hls_params, const std::string &file_name, const std::string &name, const std::string &group_id)
 
const std::string & file_name () const
 
const std::string & name () const
 
const std::string & group_id () const
 
MediaPlaylistStreamType stream_type () const
 
const std::string & codec () const
 
const std::string & supplemental_codec () const
 
const media::FourCC & compatible_brand () const
 
const std::list< std::unique_ptr< HlsEntry > > & entries () const
 
void SetStreamTypeForTesting (MediaPlaylistStreamType stream_type)
 For testing only.
 
void SetCodecForTesting (const std::string &codec)
 For testing only.
 
void SetLanguageForTesting (const std::string &language)
 For testing only.
 
void SetForcedSubtitleForTesting (const bool forced_subtitle)
 For testing only.
 
void SetCharacteristicsForTesting (const std::vector< std::string > &characteristics)
 For testing only.
 
void AddEncryptionInfoForTesting (MediaPlaylist::EncryptionMethod method, const std::string &url, const std::string &key_id, const std::string &iv, const std::string &key_format, const std::string &key_format_versions)
 For testing only.
 
virtual bool SetMediaInfo (const MediaInfo &media_info)
 
MediaInfo GetMediaInfo () const
 
virtual void SetSampleDuration (int32_t sample_duration)
 
virtual void AddSegment (const std::string &file_name, int64_t start_time, int64_t duration, uint64_t start_byte_offset, uint64_t size)
 
virtual void AddKeyFrame (int64_t timestamp, uint64_t start_byte_offset, uint64_t size)
 
virtual void AddEncryptionInfo (EncryptionMethod method, const std::string &url, const std::string &key_id, const std::string &iv, const std::string &key_format, const std::string &key_format_versions)
 
virtual void AddPlacementOpportunity ()
 
virtual bool WriteToFile (const std::filesystem::path &file_path)
 
virtual uint64_t MaxBitrate () const
 
virtual uint64_t AvgBitrate () const
 
virtual double GetLongestSegmentDuration () const
 
virtual void SetTargetDuration (int32_t target_duration)
 
virtual int GetNumChannels () const
 
virtual int GetEC3JocComplexity () const
 
virtual bool GetAC4ImsFlag () const
 
virtual bool GetAC4CbiFlag () const
 
virtual bool GetDisplayResolution (uint32_t *width, uint32_t *height) const
 
virtual std::string GetVideoRange () const
 
virtual double GetFrameRate () const
 
const std::string & language () const
 
const std::vector< std::string > & characteristics () const
 
bool forced_subtitle () const
 
bool is_dvs () const
 

Detailed Description

Methods are virtual for mocking.

Definition at line 49 of file media_playlist.h.

Constructor & Destructor Documentation

◆ MediaPlaylist()

shaka::hls::MediaPlaylist::MediaPlaylist ( const HlsParams &  hls_params,
const std::string &  file_name,
const std::string &  name,
const std::string &  group_id 
)
Parameters
hls_paramscontains HLS parameters.
file_nameis the file name of this media playlist, relative to master playlist output path.
nameis the name of this playlist. In other words this is the value of the NAME attribute for EXT-X-MEDIA. This is not necessarily the same as file_name.
group_idis the group ID for this playlist. This is the value of GROUP-ID attribute for EXT-X-MEDIA.

Definition at line 333 of file media_playlist.cc.

Member Function Documentation

◆ AddEncryptionInfo()

void shaka::hls::MediaPlaylist::AddEncryptionInfo ( MediaPlaylist::EncryptionMethod  method,
const std::string &  url,
const std::string &  key_id,
const std::string &  iv,
const std::string &  key_format,
const std::string &  key_format_versions 
)
virtual

All segments added after calling this method must be decryptable with the key that can be fetched from |url|, until calling this again.

Parameters
methodis the encryption method.
urlspecifies where the key is i.e. the value of the URI attribute. #param key_id is the default key ID for the encrypted segements.
ivis the initialization vector in human readable format, i.e. the value for IV attribute. This may be empty.
key_formatis the key format, i.e. the KEYFORMAT value. This may be empty.
key_format_versionsis the KEYFORMATVERIONS value. This may be empty.

Definition at line 469 of file media_playlist.cc.

◆ AddKeyFrame()

void shaka::hls::MediaPlaylist::AddKeyFrame ( int64_t  timestamp,
uint64_t  start_byte_offset,
uint64_t  size 
)
virtual

Keyframes must be added in order. It is also called before the containing segment being called.

Parameters
timestampis the timestamp of the key frame in timescale of the media.
start_byte_offsetis the offset of where the key frame starts.
sizeis size in bytes.

Definition at line 454 of file media_playlist.cc.

◆ AddPlacementOpportunity()

void shaka::hls::MediaPlaylist::AddPlacementOpportunity ( )
virtual

Add #EXT-X-PLACEMENT-OPPORTUNITY for mid-roll ads. See https://support.google.com/dfp_premium/answer/7295798?hl=en.

Definition at line 486 of file media_playlist.cc.

◆ AddSegment()

void shaka::hls::MediaPlaylist::AddSegment ( const std::string &  file_name,
int64_t  start_time,
int64_t  duration,
uint64_t  start_byte_offset,
uint64_t  size 
)
virtual

Segments must be added in order.

Parameters
file_nameis the file name of the segment.
start_timeis in terms of the timescale of the media.
durationis in terms of the timescale of the media.
start_byte_offsetis the offset of where the subsegment starts. This must be 0 if the whole segment is a subsegment.
sizeis size in bytes.

Definition at line 426 of file media_playlist.cc.

◆ AvgBitrate()

uint64_t shaka::hls::MediaPlaylist::AvgBitrate ( ) const
virtual

Unlike MaxBitrate, AvgBitrate is always computed from the segment size and duration.

Returns
The average bitrate (in bits per second) of this MediaPlaylist.

Definition at line 520 of file media_playlist.cc.

◆ GetAC4CbiFlag()

bool shaka::hls::MediaPlaylist::GetAC4CbiFlag ( ) const
virtual
Returns
true if it's an AC-4 CBI stream, based on ETSI TS 103 190-2 Digital Audio Compression (AC-4) Standard; Part 2: Immersive and personalized audio 4.3.

Definition at line 551 of file media_playlist.cc.

◆ GetAC4ImsFlag()

bool shaka::hls::MediaPlaylist::GetAC4ImsFlag ( ) const
virtual
Returns
true if it's an AC-4 IMS stream, based on Dolby AC-4 in MPEG-DASH for Online Delivery Specification 2.5.3. https://developer.dolby.com/tools-media/online-delivery-kits/dolby-ac-4/

Definition at line 547 of file media_playlist.cc.

◆ GetDisplayResolution()

bool shaka::hls::MediaPlaylist::GetDisplayResolution ( uint32_t *  width,
uint32_t *  height 
) const
virtual
Returns
true if |width| and |height| have been set with a valid resolution values.

Definition at line 555 of file media_playlist.cc.

◆ GetEC3JocComplexity()

int shaka::hls::MediaPlaylist::GetEC3JocComplexity ( ) const
virtual
Returns
Dolby Digital Plus JOC decoding complexity, ETSI TS 103 420 v1.2.1 Backwards-compatible object audio carriage using Enhanced AC-3 Standard C.3.2.3.

Definition at line 543 of file media_playlist.cc.

◆ GetFrameRate()

double shaka::hls::MediaPlaylist::GetFrameRate ( ) const
virtual
Returns
the frame rate.

Definition at line 606 of file media_playlist.cc.

◆ GetLongestSegmentDuration()

double shaka::hls::MediaPlaylist::GetLongestSegmentDuration ( ) const
virtual
Returns
the longest segment’s duration. This will return 0 if no segments have been added.

Definition at line 524 of file media_playlist.cc.

◆ GetNumChannels()

int shaka::hls::MediaPlaylist::GetNumChannels ( ) const
virtual
Returns
number of channels for audio. 0 is returned for video.

Definition at line 539 of file media_playlist.cc.

◆ GetVideoRange()

std::string shaka::hls::MediaPlaylist::GetVideoRange ( ) const
virtual
Returns
The video range of the stream.

Definition at line 573 of file media_playlist.cc.

◆ language()

const std::string& shaka::hls::MediaPlaylist::language ( ) const
inline
Returns
the language of the media, as an ISO language tag in its shortest form. May be an empty string for video.

Definition at line 237 of file media_playlist.h.

◆ MaxBitrate()

uint64_t shaka::hls::MediaPlaylist::MaxBitrate ( ) const
virtual

If bitrate is specified in MediaInfo then it will use that value. Otherwise, returns the max bitrate.

Returns
the max bitrate (in bits per second) of this MediaPlaylist.

Definition at line 514 of file media_playlist.cc.

◆ SetMediaInfo()

bool shaka::hls::MediaPlaylist::SetMediaInfo ( const MediaInfo &  media_info)
virtual

This must succeed before calling any other public methods.

Parameters
media_infois the info of the segments that are going to be added to this playlist.
Returns
true on success, false otherwise.

Definition at line 382 of file media_playlist.cc.

◆ SetSampleDuration()

void shaka::hls::MediaPlaylist::SetSampleDuration ( int32_t  sample_duration)
virtual

Set the sample duration. Sample duration is used to generate frame rate. Sample duration is not available right away especially. This allows setting the sample duration after the Media Playlist has been initialized.

Parameters
sample_durationis the duration of a sample.

Definition at line 421 of file media_playlist.cc.

◆ SetTargetDuration()

void shaka::hls::MediaPlaylist::SetTargetDuration ( int32_t  target_duration)
virtual

Set the target duration of this MediaPlaylist. In other words this is the value for EXT-X-TARGETDURATION. If this is not called before calling Write(), it will estimate the best target duration. The spec does not allow changing EXT-X-TARGETDURATION. However, this class has no control over the input source.

Parameters
target_durationis the target duration for this playlist.

Definition at line 528 of file media_playlist.cc.

◆ WriteToFile()

bool shaka::hls::MediaPlaylist::WriteToFile ( const std::filesystem::path &  file_path)
virtual

Write the playlist to |file_path|. This does not close the file. If target duration is not set explicitly, this will try to find the target duration. Note that target duration cannot be changed. So calling this without explicitly setting the target duration and before adding any segments will end up setting the target duration to 0 and will always generate an invalid playlist.

Parameters
file_pathis the output file path accepted by the File implementation.
Returns
true on success, false otherwise.

Definition at line 490 of file media_playlist.cc.


The documentation for this class was generated from the following files: