Skip to content

Commit

Permalink
Merge pull request #1 from indiereign/dash-label-support
Browse files Browse the repository at this point in the history
Dash label support
  • Loading branch information
gscragg authored Apr 20, 2022
2 parents 3fd538a + b7299ec commit 10c6e80
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM alpine:3.11 as builder
RUN apk add --no-cache \
bash curl \
bsd-compat-headers c-ares-dev linux-headers \
build-base git ninja python2 python3
build-base git ninja python2 python3 libexecinfo-dev c-ares-dev

# Default to python2 because our build system is ancient.
RUN ln -sf python2 /usr/bin/python
Expand Down Expand Up @@ -35,7 +35,7 @@ RUN ninja -C src/out/Release

# Copy only result binaries to our final image.
FROM alpine:3.11
RUN apk add --no-cache libstdc++ python
RUN apk add --no-cache libstdc++ python libexecinfo-dev c-ares-dev
COPY --from=builder /shaka_packager/src/out/Release/packager \
/shaka_packager/src/out/Release/mpd_generator \
/shaka_packager/src/out/Release/pssh-box.py \
Expand Down
8 changes: 7 additions & 1 deletion docs/source/options/dash_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ DASH options
--low_latency_dash_mode

If enabled, LL-DASH streaming will be used,
reducing overall latency by decoupling latency from segment duration.
reducing overall latency by decoupling latency from segment duration.

--dash_label <label_name>

Optional. Will add Label tag to adapation set and will be taken into
consideration along with codecs, language, media type (audio, video etc)
and container type to create different adaptation sets.
5 changes: 5 additions & 0 deletions packager/app/stream_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum FieldType {
kDashRolesField,
kDashOnlyField,
kHlsOnlyField,
kDashLabelField,
};

struct FieldNameToTypeMapping {
Expand Down Expand Up @@ -83,6 +84,7 @@ const FieldNameToTypeMapping kFieldNameTypeMappings[] = {
{"role", kDashRolesField},
{"dash_only", kDashOnlyField},
{"hls_only", kHlsOnlyField},
{"dash_label", kDashLabelField},
};

FieldType GetFieldType(const std::string& field_name) {
Expand Down Expand Up @@ -247,6 +249,9 @@ base::Optional<StreamDescriptor> ParseStreamDescriptor(
}
descriptor.hls_only = hls_only_value > 0;
break;
case kDashLabelField:
descriptor.dash_label = iter->second;
break;
default:
LOG(ERROR) << "Unknown field in stream descriptor (\"" << iter->first
<< "\").";
Expand Down
13 changes: 13 additions & 0 deletions packager/app/test/packager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def _GetStream(self,
dash_accessibilities=None,
dash_roles=None,
dash_only=None,
dash_label=None,
trick_play_factor=None,
drm_label=None,
skip_encryption=None,
Expand Down Expand Up @@ -334,6 +335,7 @@ def _GetStream(self,
dash_accessibilities: Accessibility element for the DASH stream.
dash_roles: Role element for the DASH stream.
dash_only: If set to true, will indicate that the stream is for DASH only.
dash_label: Label element for the DASH stream.
trick_play_factor: Signals the stream is to be used for a trick play
stream and which key frames to use. A trick play factor of 0 is the
same as not specifying a trick play factor.
Expand Down Expand Up @@ -400,6 +402,9 @@ def _GetStream(self,
if dash_only:
stream.Append('dash_only', 1)

if dash_label:
stream.Append('dash_label', dash_label)

requires_init_segment = segmented and base_ext not in [
'aac', 'ac3', 'ec3', 'ts', 'vtt', 'ttml',
]
Expand Down Expand Up @@ -781,6 +786,14 @@ def testDashOnlyAndHlsOnly(self):
self._GetFlags(output_dash=True, output_hls=True))
self._CheckTestResults('hls-only-dash-only')

def testDashLabel(self):
streams = [
self._GetStream('video', dash_label='English'),
self._GetStream('audio', dash_label='English'),
]
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True))
self._CheckTestResults('dash-label')

def testAudioVideoWithLanguageOverride(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'], language='por', hls=True),
Expand Down
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions packager/app/test/testdata/dash-label/output.mpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Generated with https://github.com/shaka-project/shaka-packager version <tag>-<hash>-<test>-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT2.7360665798187256S">
<Period id="0">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="30000/1001" subsegmentAlignment="true" par="16:9">
<Label>English</Label>
<Representation id="0" bandwidth="973483" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<BaseURL>bear-640x360-video.mp4</BaseURL>
<SegmentBase indexRange="870-937" timescale="30000">
<Initialization range="0-869"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet id="1" contentType="audio" subsegmentAlignment="true">
<Label>English</Label>
<Representation id="1" bandwidth="133334" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<BaseURL>bear-640x360-audio.mp4</BaseURL>
<SegmentBase indexRange="804-871" timescale="44100">
<Initialization range="0-803"/>
</SegmentBase>
</Representation>
</AdaptationSet>
</Period>
</MPD>
3 changes: 3 additions & 0 deletions packager/media/event/mpd_notify_muxer_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ void MpdNotifyMuxerListener::OnMediaStart(const MuxerOptions& muxer_options,
media_info->add_dash_roles(role);
}

if (!dash_label_.empty())
media_info->set_dash_label(dash_label_);

if (is_encrypted_) {
internal::SetContentProtectionFields(protection_scheme_, default_key_id_,
key_system_info_, media_info.get());
Expand Down
3 changes: 3 additions & 0 deletions packager/media/event/mpd_notify_muxer_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MpdNotifyMuxerListener : public MuxerListener {

void set_roles(const std::vector<std::string>& roles) { roles_ = roles; }

void set_dash_label(std::string label) { dash_label_ = label; }

private:
MpdNotifyMuxerListener(const MpdNotifyMuxerListener&) = delete;
MpdNotifyMuxerListener& operator=(const MpdNotifyMuxerListener&) = delete;
Expand All @@ -77,6 +79,7 @@ class MpdNotifyMuxerListener : public MuxerListener {

std::vector<std::string> accessibilities_;
std::vector<std::string> roles_;
std::string dash_label_;

bool is_encrypted_ = false;
// Storage for values passed to OnEncryptionInfoReady().
Expand Down
1 change: 1 addition & 0 deletions packager/media/event/muxer_listener_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ std::unique_ptr<MuxerListener> CreateMpdListenerInternal(
auto listener = base::MakeUnique<MpdNotifyMuxerListener>(notifier);
listener->set_accessibilities(stream.dash_accessiblities);
listener->set_roles(stream.dash_roles);
listener->set_dash_label(stream.dash_label);
return listener;
}

Expand Down
1 change: 1 addition & 0 deletions packager/media/event/muxer_listener_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MuxerListenerFactory {
std::vector<std::string> dash_accessiblities;
std::vector<std::string> dash_roles;
bool dash_only = false;
std::string dash_label;
};

/// Create a new muxer listener.
Expand Down
6 changes: 6 additions & 0 deletions packager/mpd/base/adaptation_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ base::Optional<xml::XmlNode> AdaptationSet::GetXml() {
}
}

if (!label_.empty() && !adaptation_set.AddLabelElement(label_))
return base::nullopt;

for (const auto& representation_pair : representation_map_) {
const auto& representation = representation_pair.second;
if (suppress_representation_width)
Expand Down Expand Up @@ -439,6 +442,9 @@ void AdaptationSet::UpdateFromMediaInfo(const MediaInfo& media_info) {
AddPictureAspectRatio(video_info, &picture_aspect_ratio_);
}

if (media_info.has_dash_label())
label_ = media_info.dash_label();

if (media_info.has_video_info()) {
content_type_ = "video";
} else if (media_info.has_audio_info()) {
Expand Down
3 changes: 3 additions & 0 deletions packager/mpd/base/adaptation_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ class AdaptationSet {
// and HD videos in different AdaptationSets can share the same trick play
// stream.
std::vector<const AdaptationSet*> trick_play_references_;

// The label of this AdaptationSet.
std::string label_;
};

} // namespace shaka
Expand Down
2 changes: 2 additions & 0 deletions packager/mpd/base/media_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,6 @@ message MediaInfo {
// with respect to the reference time scale.
// Equal to the target segment duration times the reference time scale.
optional uint64 segment_duration = 25;

optional string dash_label = 26;
}
5 changes: 4 additions & 1 deletion packager/mpd/base/mpd_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ std::string GetAdaptationSetKey(const MediaInfo& media_info,
key.append("unknown:");
}

if (media_info.has_dash_label())
key.append(media_info.dash_label() + ":");

key.append(MediaInfo_ContainerType_Name(media_info.container_type()));
if (!ignore_codec) {
key.append(":");
Expand Down Expand Up @@ -327,7 +330,7 @@ const char kMarlinUUID[] = "5e629af5-38da-4063-8977-97ffbd9902d4";
const char kFairPlayUUID[] = "29701fe4-3cc7-4a34-8c5b-ae90c7439a47";
// String representation of media::kPlayReadySystemId.
const char kPlayReadyUUID[] = "9a04f079-9840-4286-ab92-e65be0885f95";
// It is RECOMMENDED to include the @value attribute with name and version "MSPR 2.0".
// It is RECOMMENDED to include the @value attribute with name and version "MSPR 2.0".
// See https://docs.microsoft.com/en-us/playready/specifications/mpeg-dash-playready#221-general.
const char kContentProtectionValueMSPR20[] = "MSPR 2.0";

Expand Down
6 changes: 6 additions & 0 deletions packager/mpd/base/xml/xml_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ bool AdaptationSetXmlNode::AddRoleElement(const std::string& scheme_id_uri,
return AddDescriptor("Role", scheme_id_uri, value);
}

bool AdaptationSetXmlNode::AddLabelElement(const std::string& value) {
XmlNode descriptor("Label");
descriptor.SetContent(value);
return AddChild(std::move(descriptor));
}

RepresentationXmlNode::RepresentationXmlNode()
: RepresentationBaseXmlNode("Representation") {}
RepresentationXmlNode::~RepresentationXmlNode() {}
Expand Down
3 changes: 3 additions & 0 deletions packager/mpd/base/xml/xml_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class AdaptationSetXmlNode : public RepresentationBaseXmlNode {
bool AddRoleElement(const std::string& scheme_id_uri,
const std::string& value) WARN_UNUSED_RESULT;

/// @param value is element's content.
bool AddLabelElement(const std::string& value) WARN_UNUSED_RESULT;

private:
DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
};
Expand Down
1 change: 1 addition & 0 deletions packager/packager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ MuxerListenerFactory::StreamData ToMuxerListenerData(
data.dash_accessiblities = stream.dash_accessiblities;
data.dash_roles = stream.dash_roles;
data.dash_only = stream.dash_only;
data.dash_label = stream.dash_label;
return data;
};

Expand Down
3 changes: 3 additions & 0 deletions packager/packager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ struct StreamDescriptor {
bool dash_only = false;
/// Set to true to indicate that the stream is for hls only.
bool hls_only = false;

/// Optional for DASH output. It defines the Label element in Adaptation Set.
std::string dash_label;
};

class SHAKA_EXPORT Packager {
Expand Down

0 comments on commit 10c6e80

Please sign in to comment.