Skip to content

Commit

Permalink
support Dolby Vision back compatiable signaling in HLS.
Browse files Browse the repository at this point in the history
  • Loading branch information
XingzhaoYun committed Aug 9, 2023
1 parent cc9a691 commit aba9b89
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
20 changes: 19 additions & 1 deletion packager/hls/base/media_playlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ MediaPlaylist::MediaPlaylist(const HlsParams& hls_params,
file_name_(file_name),
name_(name),
group_id_(group_id),
dovi_compatible_brand_(),
media_sequence_number_(hls_params_.media_sequence_number) {
// When there's a forced media_sequence_number, start with discontinuity
if (media_sequence_number_ > 0)
Expand Down Expand Up @@ -380,6 +381,11 @@ bool MediaPlaylist::SetMediaInfo(const MediaInfo& media_info) {
if (media_info.has_video_info()) {
stream_type_ = MediaPlaylistStreamType::kVideo;
codec_ = AdjustVideoCodec(media_info.video_info().codec());
if (media_info.video_info().has_extra_decoder_config()) {
dovi_codec_ = AdjustVideoCodec(media_info.video_info().dovi_codec());
dovi_compatible_brand_ = static_cast<media::FourCC>(media_info.video_info().dovi_compatible_brand());
}

} else if (media_info.has_audio_info()) {
stream_type_ = MediaPlaylistStreamType::kAudio;
codec_ = media_info.audio_info().codec();
Expand Down Expand Up @@ -560,10 +566,22 @@ std::string MediaPlaylist::GetVideoRange() const {
// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-02#section-4.4.4.2
switch (media_info_.video_info().transfer_characteristics()) {
case 1:
case 6:
case 13:
case 15:
return "SDR";
case 14:
// Dolby Vision profile 8.4 may have a transfer_characteristics 14, the
// actual value refers to preferred_transfer_characteristic value in SEI
// message, using compatible brand as a temp solution.
if (!dovi_codec_.empty() && dovi_compatible_brand_ == media::FOURCC_db4g)
return "HLG";
else
return "SDR";
case 16:
case 18:
return "PQ";
case 18:
return "HLG";
default:
// Leave it empty if we do not have the transfer characteristics
// information.
Expand Down
5 changes: 5 additions & 0 deletions packager/hls/base/media_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "packager/hls/public/hls_params.h"
#include "packager/mpd/base/bandwidth_estimator.h"
#include "packager/mpd/base/media_info.pb.h"
#include "packager/media/base/fourccs.h"

namespace shaka {

Expand Down Expand Up @@ -79,6 +80,8 @@ class MediaPlaylist {
const std::string& group_id() const { return group_id_; }
MediaPlaylistStreamType stream_type() const { return stream_type_; }
const std::string& codec() const { return codec_; }
const std::string& dovi_codec() const { return dovi_codec_; }
const media::FourCC& dovi_compatible_brand() const { return dovi_compatible_brand_; }

/// For testing only.
void SetStreamTypeForTesting(MediaPlaylistStreamType stream_type);
Expand Down Expand Up @@ -258,6 +261,8 @@ class MediaPlaylist {
// Whether to use byte range for SegmentInfoEntry.
bool use_byte_range_ = false;
std::string codec_;
std::string dovi_codec_;
media::FourCC dovi_compatible_brand_;
std::string language_;
std::vector<std::string> characteristics_;
uint32_t media_sequence_number_ = 0;
Expand Down
6 changes: 5 additions & 1 deletion packager/media/base/fourccs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ enum FourCC : uint32_t {
FOURCC_dac3 = 0x64616333,
FOURCC_dac4 = 0x64616334,
FOURCC_dash = 0x64617368,
FOURCC_dby1 = 0x64627931,
FOURCC_db1p = 0x64623170, // "db1p"
FOURCC_db2g = 0x64623267, // "db2g"
FOURCC_db4g = 0x64623467, // "db4g"
FOURCC_db4h = 0x64623468, // "db4h"
FOURCC_dby1 = 0x64627931, // "dby1"
FOURCC_ddts = 0x64647473,
FOURCC_dec3 = 0x64656333,
FOURCC_dfLa = 0x64664c61,
Expand Down
5 changes: 5 additions & 0 deletions packager/media/base/video_stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class VideoStreamInfo : public StreamInfo {
std::unique_ptr<StreamInfo> Clone() const override;
/// @}

FourCC dovi_compatible_brand() const { return dovi_compatible_brand_; }
const std::vector<uint8_t>& extra_config() const { return extra_config_; }
H26xStreamFormat h26x_stream_format() const { return h26x_stream_format_; }
uint16_t width() const { return width_; }
Expand All @@ -70,6 +71,9 @@ class VideoStreamInfo : public StreamInfo {
uint32_t playback_rate() const { return playback_rate_; }
const std::vector<uint8_t>& eme_init_data() const { return eme_init_data_; }

void set_dovi_compatible_brand(const FourCC dovi_compatible_brand) {
dovi_compatible_brand_ = dovi_compatible_brand;
}
void set_extra_config(const std::vector<uint8_t>& extra_config) {
extra_config_ = extra_config;
}
Expand All @@ -94,6 +98,7 @@ class VideoStreamInfo : public StreamInfo {
private:
// Extra codec configuration in a stream of mp4 boxes. It is only applicable
// to mp4 container only. It is needed by some codecs, e.g. Dolby Vision.
FourCC dovi_compatible_brand_;
std::vector<uint8_t> extra_config_;
H26xStreamFormat h26x_stream_format_;
uint16_t width_;
Expand Down

0 comments on commit aba9b89

Please sign in to comment.