Move Tag to Own File

Moved HLS Tag to its own file so that it can be used in other
HLS classes.

Change-Id: Ie3c2668fde28e43784661fc789d2edc80fc4a8fa
This commit is contained in:
Aaron Vaage 2018-01-31 13:02:28 -08:00
parent 0f17631017
commit 1731fef14d
4 changed files with 99 additions and 41 deletions

View File

@ -15,6 +15,7 @@
#include "packager/base/strings/stringprintf.h" #include "packager/base/strings/stringprintf.h"
#include "packager/file/file.h" #include "packager/file/file.h"
#include "packager/hls/base/media_playlist.h" #include "packager/hls/base/media_playlist.h"
#include "packager/hls/base/tag.h"
#include "packager/version/version.h" #include "packager/version/version.h"
namespace shaka { namespace shaka {
@ -63,47 +64,6 @@ std::list<Variant> AudioGroupsToVariants(
return variants; 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, void BuildAudioTag(const std::string& base_url,
const std::string& group_id, const std::string& group_id,
const MediaPlaylist& audio_playlist, const MediaPlaylist& audio_playlist,

50
packager/hls/base/tag.cc Normal file
View File

@ -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 <inttypes.h>
#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

46
packager/hls/base/tag.h Normal file
View File

@ -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 <string>
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_

View File

@ -20,6 +20,8 @@
'base/media_playlist.h', 'base/media_playlist.h',
'base/simple_hls_notifier.cc', 'base/simple_hls_notifier.cc',
'base/simple_hls_notifier.h', 'base/simple_hls_notifier.h',
'base/tag.cc',
'base/tag.h',
'public/hls_params.h', 'public/hls_params.h',
], ],
'dependencies': [ 'dependencies': [