Add version information to generated HLS manifests

- Also refactor the existing version code.

Change-Id: Ib409630c4f87965a37b1d6a1bcec68178a704ce6
This commit is contained in:
Kongqun Yang 2016-07-07 12:34:07 -07:00 committed by KongQun Yang
parent db70721e35
commit f3d35b730c
25 changed files with 158 additions and 58 deletions

View File

@ -91,8 +91,8 @@ int MpdMain(int argc, char** argv) {
ExitStatus status = CheckRequiredFlags();
if (status != kSuccess) {
std::string version_string =
base::StringPrintf("mpd_generator version %s", kPackagerVersion);
const std::string version_string = base::StringPrintf(
"mpd_generator version %s", GetPackagerVersion().c_str());
google::ShowUsageWithFlags(version_string.c_str());
return status;
}

View File

@ -51,6 +51,15 @@ DEFINE_bool(use_fake_clock_for_muxer,
"Set to true to use a fake clock for muxer. With this flag set, "
"creation time and modification time in outputs are set to 0. "
"Should only be used for testing.");
DEFINE_bool(override_version,
false,
"Override packager version in the generated outputs with "
"--test_version if it is set to true. Should be used for "
"testing only.");
DEFINE_string(test_version,
"",
"Packager version for testing. Ignored if --override_version is "
"false. Should be used for testing only.");
namespace shaka {
namespace media {
@ -517,8 +526,8 @@ int PackagerMain(int argc, char** argv) {
google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
google::ParseCommandLineFlags(&argc, &argv, true);
if (argc < 2) {
std::string version_string =
base::StringPrintf("shaka-packager version %s", kPackagerVersion);
const std::string version_string = base::StringPrintf(
"shaka-packager version %s", GetPackagerVersion().c_str());
google::ShowUsageWithFlags(version_string.c_str());
return kSuccess;
}
@ -526,6 +535,9 @@ int PackagerMain(int argc, char** argv) {
if (!ValidateWidevineCryptoFlags() || !ValidateFixedCryptoFlags())
return kArgumentValidationFailed;
if (FLAGS_override_version)
SetPackagerVersionForTesting(FLAGS_test_version);
LibcryptoThreading libcrypto_threading;
// TODO(tinskip): Make InsertStreamDescriptor a member of
// StreamDescriptorList.

View File

@ -26,16 +26,6 @@
#include "packager/mpd/base/mpd_builder.h"
DEFINE_bool(dump_stream_info, false, "Dump demuxed stream info.");
DEFINE_bool(override_version_string,
false,
"Override packager version string in the generated outputs with "
"--test_version_string if it is set to true. Should be used for "
"testing only.");
DEFINE_string(test_version_string,
"",
"Packager version string for testing. Ignored if "
"--override_version_string is false. Should be used for testing "
"only.");
namespace shaka {
namespace media {
@ -159,8 +149,6 @@ bool GetMuxerOptions(MuxerOptions* muxer_options) {
muxer_options->fragment_sap_aligned = FLAGS_fragment_sap_aligned;
muxer_options->num_subsegments_per_sidx = FLAGS_num_subsegments_per_sidx;
muxer_options->temp_dir = FLAGS_temp_dir;
if (FLAGS_override_version_string)
muxer_options->packager_version_string = FLAGS_test_version_string;
return true;
}
@ -173,8 +161,6 @@ bool GetMpdOptions(MpdOptions* mpd_options) {
mpd_options->time_shift_buffer_depth = FLAGS_time_shift_buffer_depth;
mpd_options->suggested_presentation_delay =
FLAGS_suggested_presentation_delay;
if (FLAGS_override_version_string)
mpd_options->packager_version_string = FLAGS_test_version_string;
return true;
}

View File

@ -504,8 +504,7 @@ class PackagerAppTest(unittest.TestCase):
flags.append('--use_fake_clock_for_muxer')
# Override packager version string for testing.
flags += ['--override_version_string', '--test_version_string',
'<tag>-<hash>-<test>']
flags += ['--override_version', '--test_version', '<tag>-<hash>-<test>']
return flags
def _CompareWithGold(self, test_output, golden_file_name):

View File

@ -1,5 +1,6 @@
#EXTM3U
#EXT-X-VERSION:5
## Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>
#EXT-X-TARGETDURATION:2
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:1.021,

View File

@ -1,5 +1,6 @@
#EXTM3U
#EXT-X-VERSION:5
## Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>
#EXT-X-TARGETDURATION:2
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:1.021,

View File

@ -1,4 +1,5 @@
#EXTM3U
## Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="stream_0",URI="audio.m3u8"
#EXT-X-STREAM-INF:AUDIO="audio",CODECS="avc1.64001e,mp4a.40.2",BANDWIDTH=1217603
video.m3u8

View File

@ -1,4 +1,5 @@
#EXTM3U
## Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="stream_0",URI="audio.m3u8"
#EXT-X-STREAM-INF:AUDIO="audio",CODECS="avc1.64001e,mp4a.40.2",BANDWIDTH=1217603
video.m3u8

View File

@ -1,5 +1,6 @@
#EXTM3U
#EXT-X-VERSION:5
## Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>
#EXT-X-TARGETDURATION:2
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:1.001,

View File

@ -1,5 +1,6 @@
#EXTM3U
#EXT-X-VERSION:5
## Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>
#EXT-X-TARGETDURATION:2
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:1.001,

View File

@ -18,6 +18,7 @@
#include "packager/hls/base/media_playlist.h"
#include "packager/media/file/file.h"
#include "packager/media/file/file_closer.h"
#include "packager/version/version.h"
namespace shaka {
namespace hls {
@ -147,7 +148,16 @@ bool MasterPlaylist::WriteMasterPlaylist(const std::string& base_url,
}
}
std::string content = "#EXTM3U\n" + audio_output + video_output;
const std::string version = GetPackagerVersion();
std::string version_line;
if (!version.empty()) {
version_line =
base::StringPrintf("## Generated with %s version %s\n",
GetPackagerProjectUrl().c_str(), version.c_str());
}
std::string content =
"#EXTM3U\n" + version_line + audio_output + video_output;
int64_t bytes_written = file->Write(content.data(), content.size());
if (bytes_written < 0) {
LOG(ERROR) << "Error while writing master playlist " << file_path;

View File

@ -13,6 +13,7 @@
#include "packager/hls/base/media_playlist.h"
#include "packager/hls/base/mock_media_playlist.h"
#include "packager/media/file/file.h"
#include "packager/version/version.h"
namespace shaka {
namespace hls {
@ -33,6 +34,7 @@ class MasterPlaylistTest : public ::testing::Test {
MasterPlaylistTest() : master_playlist_(kDefaultMasterPlaylistName) {}
void SetUp() override {
SetPackagerVersionForTesting("test");
GetOutputDir(&test_output_dir_path_, &test_output_dir_);
}
@ -86,6 +88,8 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneVideo) {
const std::string expected =
"#EXTM3U\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-STREAM-INF:CODECS=\"avc1\",BANDWIDTH=435889\n"
"http://myplaylistdomain.com/media1.m3u8\n";
@ -155,6 +159,8 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) {
const std::string expected =
"#EXTM3U\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audiogroup\",NAME=\"english\","
"URI=\"http://playlists.org/eng.m3u8\"\n"
"#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audiogroup\",NAME=\"espanol\","
@ -220,6 +226,8 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) {
const std::string expected =
"#EXTM3U\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audio_hi\",NAME=\"english_hi\","
"URI=\"http://anydomain.com/eng_hi.m3u8\"\n"
"#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audio_lo\",NAME=\"english_lo\","

View File

@ -12,6 +12,7 @@
#include "packager/base/logging.h"
#include "packager/base/strings/stringprintf.h"
#include "packager/media/file/file.h"
#include "packager/version/version.h"
namespace shaka {
namespace hls {
@ -272,11 +273,21 @@ bool MediaPlaylist::WriteToFile(media::File* file) {
SetTargetDuration(ceil(GetLongestSegmentDuration()));
}
const std::string version = GetPackagerVersion();
std::string version_line;
if (!version.empty()) {
version_line =
base::StringPrintf("## Generated with %s version %s\n",
GetPackagerProjectUrl().c_str(), version.c_str());
}
// KEYFORMAT and KEYFORMATVERSIONS on EXT-X-KEY requires 5 or above.
std::string header = base::StringPrintf("#EXTM3U\n"
std::string header = base::StringPrintf(
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"%s"
"#EXT-X-TARGETDURATION:%d\n",
target_duration_);
version_line.c_str(), target_duration_);
if (type_ == MediaPlaylistType::kVod) {
header += "#EXT-X-PLAYLIST-TYPE:VOD\n";
}

View File

@ -9,6 +9,7 @@
#include "packager/media/file/file.h"
#include "packager/hls/base/media_playlist.h"
#include "packager/version/version.h"
namespace shaka {
namespace hls {
@ -56,6 +57,8 @@ class MediaPlaylistTest : public ::testing::Test {
default_group_id_) {}
void SetUp() override {
SetPackagerVersionForTesting("test");
MediaInfo::VideoInfo* video_info =
valid_video_media_info_.mutable_video_info();
video_info->set_codec("avc1");
@ -117,6 +120,8 @@ TEST_F(MediaPlaylistTest, WriteToFile) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-TARGETDURATION:0\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXT-X-ENDLIST\n";
@ -172,6 +177,8 @@ TEST_F(MediaPlaylistTest, SetTargetDuration) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-TARGETDURATION:20\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXT-X-ENDLIST\n";
@ -198,6 +205,8 @@ TEST_F(MediaPlaylistTest, WriteToFileWithSegments) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-TARGETDURATION:30\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXTINF:10.000,\n"
@ -227,6 +236,8 @@ TEST_F(MediaPlaylistTest, WriteToFileWithEncryptionInfo) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-TARGETDURATION:30\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
@ -259,6 +270,8 @@ TEST_F(MediaPlaylistTest, WriteToFileWithEncryptionInfoEmptyIv) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-TARGETDURATION:30\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
@ -290,6 +303,7 @@ TEST_F(MediaPlaylistTest, WriteToFileWithClearLead) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version test\n"
"#EXT-X-TARGETDURATION:30\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXTINF:10.000,\n"
@ -323,6 +337,8 @@ TEST_F(MediaPlaylistTest, RemoveOldestSegment) {
const std::string kExpectedOutput =
"#EXTM3U\n"
"#EXT-X-VERSION:5\n"
"## Generated with https://github.com/google/shaka-packager version "
"test\n"
"#EXT-X-TARGETDURATION:30\n"
"#EXT-X-PLAYLIST-TYPE:VOD\n"
"#EXTINF:30.000,\n"

View File

@ -5,7 +5,6 @@
// https://developers.google.com/open-source/licenses/bsd
#include "packager/media/base/muxer_options.h"
#include "packager/version/version.h"
namespace shaka {
namespace media {
@ -17,8 +16,7 @@ MuxerOptions::MuxerOptions()
segment_sap_aligned(false),
fragment_sap_aligned(false),
num_subsegments_per_sidx(0),
bandwidth(0),
packager_version_string(kPackagerVersion) {}
bandwidth(0) {}
MuxerOptions::~MuxerOptions() {}
} // namespace media

View File

@ -66,9 +66,6 @@ struct MuxerOptions {
/// User-specified bit rate for the media stream. If zero, the muxer will
/// attempt to estimate.
uint32_t bandwidth;
/// Specify the version string to be embedded in the output files.
std::string packager_version_string;
};
} // namespace media

View File

@ -22,6 +22,7 @@
#include "packager/media/event/progress_listener.h"
#include "packager/media/formats/mp4/box_definitions.h"
#include "packager/media/formats/mp4/key_rotation_fragmenter.h"
#include "packager/version/version.h"
namespace shaka {
namespace media {
@ -276,11 +277,13 @@ Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
moof_->header.sequence_number = 1;
// Fill in version information.
const std::string version = GetPackagerVersion();
if (!version.empty()) {
moov_->metadata.handler.handler_type = FOURCC_ID32;
moov_->metadata.id3v2.language.code = "eng";
moov_->metadata.id3v2.private_frame.owner =
"https://github.com/google/shaka-packager";
moov_->metadata.id3v2.private_frame.value = options_.packager_version_string;
moov_->metadata.id3v2.private_frame.owner = GetPackagerProjectUrl();
moov_->metadata.id3v2.private_frame.value = version;
}
return DoInitialize();
}

View File

@ -19,6 +19,7 @@
#include "packager/media/event/progress_listener.h"
#include "packager/third_party/libwebm/src/mkvmuxerutil.hpp"
#include "packager/third_party/libwebm/src/webmids.hpp"
#include "packager/version/version.h"
namespace shaka {
namespace media {
@ -60,13 +61,15 @@ Status Segmenter::Initialize(scoped_ptr<MkvWriter> writer,
progress_target_ = info_->duration();
progress_listener_ = progress_listener;
const std::string version_string =
"https://github.com/google/shaka-packager version " +
options().packager_version_string;
segment_info_.Init();
segment_info_.set_timecode_scale(kTimecodeScale);
segment_info_.set_writing_app(version_string.c_str());
const std::string version = GetPackagerVersion();
if (!version.empty()) {
segment_info_.set_writing_app(
(GetPackagerProjectUrl() + " version " + version).c_str());
}
if (options().single_segment) {
// Set an initial duration so the duration element is written; will be
// overwritten at the end. This works because this is a float and floats

View File

@ -9,6 +9,7 @@
#include "packager/media/base/muxer_util.h"
#include "packager/media/file/memory_file.h"
#include "packager/media/formats/webm/webm_constants.h"
#include "packager/version/version.h"
namespace shaka {
namespace media {
@ -39,6 +40,8 @@ const uint8_t kNaluLengthSize = 0;
SegmentTestBase::SegmentTestBase() {}
void SegmentTestBase::SetUp() {
SetPackagerVersionForTesting("test");
output_file_name_ = std::string(kMemoryFilePrefix) + "output-file.webm";
segment_template_ =
std::string(kMemoryFilePrefix) + "output-template-$Number$.webm";
@ -78,7 +81,6 @@ MuxerOptions SegmentTestBase::CreateMuxerOptions() const {
ret.single_segment = single_segment_;
ret.output_file_name = output_file_name_;
ret.segment_template = segment_template_;
ret.packager_version_string = "test";
ret.segment_duration = 30; // seconds
ret.fragment_duration = 30; // seconds
ret.segment_sap_aligned = false;

View File

@ -29,6 +29,7 @@
#include "packager/mpd/base/language_utils.h"
#include "packager/mpd/base/mpd_utils.h"
#include "packager/mpd/base/xml/xml_node.h"
#include "packager/version/version.h"
namespace shaka {
@ -505,13 +506,18 @@ xmlDocPtr MpdBuilder::GenerateMpd() {
}
DCHECK(doc);
const std::string version = GetPackagerVersion();
if (!version.empty()) {
std::string version_string =
"Generated with https://github.com/google/shaka-packager version " +
mpd_options_.packager_version_string;
base::StringPrintf("Generated with %s version %s",
GetPackagerProjectUrl().c_str(), version.c_str());
xml::scoped_xml_ptr<xmlNode> comment(
xmlNewDocComment(doc.get(), BAD_CAST version_string.c_str()));
xmlDocSetRootElement(doc.get(), comment.get());
xmlAddSibling(comment.release(), mpd.Release());
} else {
xmlDocSetRootElement(doc.get(), mpd.Release());
}
return doc.release();
}

View File

@ -20,6 +20,7 @@
#include "packager/mpd/base/mpd_utils.h"
#include "packager/mpd/test/mpd_builder_test_helper.h"
#include "packager/mpd/test/xml_compare.h"
#include "packager/version/version.h"
namespace shaka {
@ -184,9 +185,8 @@ class DynamicMpdBuilderTest : public MpdBuilderTest<MpdBuilder::kDynamic> {
// Anchors availabilityStartTime so that the test result doesn't depend on the
// current time.
void SetUp() override {
SetPackagerVersionForTesting("<tag>-<hash>-<test>");
mpd_.availability_start_time_ = "2011-12-25T12:30:00";
// Override packager version string for testing.
mpd_.mpd_options_.packager_version_string = "<tag>-<hash>-<test>";
InjectTestClock();
}

View File

@ -9,8 +9,6 @@
#include <string>
#include "packager/version/version.h"
namespace shaka {
/// Defines Mpd Options.
@ -21,8 +19,7 @@ struct MpdOptions {
// TODO(tinskip): Set min_buffer_time in unit tests rather than here.
min_buffer_time(2.0),
time_shift_buffer_depth(0),
suggested_presentation_delay(0),
packager_version_string(kPackagerVersion) {}
suggested_presentation_delay(0) {}
~MpdOptions() {};
@ -31,7 +28,6 @@ struct MpdOptions {
double min_buffer_time;
double time_shift_buffer_depth;
double suggested_presentation_delay;
std::string packager_version_string;
};
} // namespace shaka

View File

@ -6,7 +6,9 @@
#include "packager/version/version.h"
namespace shaka {
#include "packager/base/lazy_instance.h"
namespace {
#if defined(PACKAGER_VERSION)
// PACKAGER_VERSION is generated in gyp file using script
@ -20,4 +22,36 @@ const char kPackagerVersion[] = PACKAGER_VERSION "-debug";
const char kPackagerVersion[] = "";
#endif // #if defined(PACKAGER_VERSION)
const char kPackagerGithubUrl[] = "https://github.com/google/shaka-packager";
class Version {
public:
Version() : version_(kPackagerVersion) {}
~Version() {}
const std::string& version() { return version_; }
void set_version(const std::string& version) { version_ = version; }
private:
std::string version_;
};
} // namespace
namespace shaka {
base::LazyInstance<Version> g_packager_version;
std::string GetPackagerProjectUrl(){
return kPackagerGithubUrl;
}
std::string GetPackagerVersion() {
return g_packager_version.Get().version();
}
void SetPackagerVersionForTesting(const std::string& version) {
g_packager_version.Get().set_version(version);
}
} // namespace shaka

View File

@ -19,6 +19,9 @@
'version.cc',
'version.h',
],
'dependencies': [
'../base/base.gyp:base',
],
},
],
}

View File

@ -4,8 +4,18 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include <string>
namespace shaka {
extern const char kPackagerVersion[];
/// @return URL of shaka-packager project.
std::string GetPackagerProjectUrl();
/// @return The version string.
std::string GetPackagerVersion();
/// Set version for testing.
/// @param version contains the injected testing version.
void SetPackagerVersionForTesting(const std::string& version);
} // namespace shaka