diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index 3635f15d99..85783c5494 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -15,6 +15,7 @@ #include "packager/base/strings/stringprintf.h" #include "packager/file/file.h" #include "packager/hls/base/media_playlist.h" +#include "packager/hls/base/tag.h" #include "packager/version/version.h" namespace shaka { @@ -63,47 +64,6 @@ std::list AudioGroupsToVariants( return variants; } -class Tag { - public: - Tag(const std::string& name, std::string* buffer) : buffer_(buffer) { - base::StringAppendF(buffer_, "%s:", name.c_str()); - } - - void AddString(const std::string& key, const std::string& value) { - NextField(); - base::StringAppendF(buffer_, "%s=%s", key.c_str(), value.c_str()); - } - - void AddQuotedString(const std::string& key, const std::string& value) { - NextField(); - base::StringAppendF(buffer_, "%s=\"%s\"", key.c_str(), value.c_str()); - } - - void AddNumber(const std::string& key, uint64_t value) { - NextField(); - base::StringAppendF(buffer_, "%s=%" PRIu64, key.c_str(), value); - } - - void AddResolution(const std::string& key, uint32_t width, uint32_t height) { - NextField(); - base::StringAppendF(buffer_, "%s=%" PRIu32 "x%" PRIu32, key.c_str(), width, - height); - } - - private: - Tag(const Tag&) = delete; - Tag& operator=(const Tag&) = delete; - - std::string* buffer_; - size_t fields = 0; - - void NextField() { - if (fields++) { - buffer_->append(","); - } - } -}; - void BuildAudioTag(const std::string& base_url, const std::string& group_id, const MediaPlaylist& audio_playlist, diff --git a/packager/hls/base/tag.cc b/packager/hls/base/tag.cc new file mode 100644 index 0000000000..995038096c --- /dev/null +++ b/packager/hls/base/tag.cc @@ -0,0 +1,50 @@ +// Copyright 2018 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 + +#include "packager/hls/base/tag.h" + +#include + +#include "packager/base/strings/stringprintf.h" + +namespace shaka { +namespace hls { + +Tag::Tag(const std::string& name, std::string* buffer) : buffer_(buffer) { + base::StringAppendF(buffer_, "%s:", name.c_str()); +} + +void Tag::AddString(const std::string& key, const std::string& value) { + NextField(); + base::StringAppendF(buffer_, "%s=%s", key.c_str(), value.c_str()); +} + +void Tag::AddQuotedString(const std::string& key, const std::string& value) { + NextField(); + base::StringAppendF(buffer_, "%s=\"%s\"", key.c_str(), value.c_str()); +} + +void Tag::AddNumber(const std::string& key, uint64_t value) { + NextField(); + base::StringAppendF(buffer_, "%s=%" PRIu64, key.c_str(), value); +} + +void Tag::AddResolution(const std::string& key, + uint32_t width, + uint32_t height) { + NextField(); + base::StringAppendF(buffer_, "%s=%" PRIu32 "x%" PRIu32, key.c_str(), width, + height); +} + +void Tag::NextField() { + if (fields++) { + buffer_->append(","); + } +} + +} // namespace hls +} // namespace shaka diff --git a/packager/hls/base/tag.h b/packager/hls/base/tag.h new file mode 100644 index 0000000000..d3e7c4e17e --- /dev/null +++ b/packager/hls/base/tag.h @@ -0,0 +1,46 @@ +// Copyright 2018 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_TAG_H_ +#define PACKAGER_HLS_BASE_TAG_H_ + +#include + +namespace shaka { +namespace hls { + +/// Tag is a string formatting class used to build HLS tags that contain +/// argument lists. +class Tag { + public: + Tag(const std::string& name, std::string* buffer); + + /// Add a non-quoted string value to the argument list. + void AddString(const std::string& key, const std::string& value); + + /// Add a quoted string value to the argument list. + void AddQuotedString(const std::string& key, const std::string& value); + + /// Add a non-quoted numeric value to the argument list. + void AddNumber(const std::string& key, uint64_t value); + + /// Add a resolution value (AxB) to the argument list. + void AddResolution(const std::string& key, uint32_t width, uint32_t height); + + private: + Tag(const Tag&) = delete; + Tag& operator=(const Tag&) = delete; + + std::string* const buffer_; + size_t fields = 0; + + void NextField(); +}; + +} // namespace hls +} // namespace shaka + +#endif // PACKAGER_HLS_BASE_TAG_H_ diff --git a/packager/hls/hls.gyp b/packager/hls/hls.gyp index 1569cb2bb0..f1c94dd521 100644 --- a/packager/hls/hls.gyp +++ b/packager/hls/hls.gyp @@ -20,6 +20,8 @@ 'base/media_playlist.h', 'base/simple_hls_notifier.cc', 'base/simple_hls_notifier.h', + 'base/tag.cc', + 'base/tag.h', 'public/hls_params.h', ], 'dependencies': [