diff --git a/packager/app/mpd_generator.cc b/packager/app/mpd_generator.cc index 17074fc1b4..b86b6a59e4 100644 --- a/packager/app/mpd_generator.cc +++ b/packager/app/mpd_generator.cc @@ -24,6 +24,9 @@ #endif // defined(OS_WIN) DEFINE_bool(licenses, false, "Dump licenses."); +DEFINE_string(test_packager_version, + "", + "Packager version for testing. Should be used for testing only."); namespace shaka { namespace { @@ -117,6 +120,9 @@ int MpdMain(int argc, char** argv) { return status; } + if (!FLAGS_test_packager_version.empty()) + SetPackagerVersionForTesting(FLAGS_test_packager_version); + return RunMpdGenerator(); } diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index b601a8ca16..3f65302f72 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -44,15 +44,9 @@ 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, +DEFINE_string(test_packager_version, "", - "Packager version for testing. Ignored if --override_version is " - "false. Should be used for testing only."); + "Packager version for testing. Should be used for testing only."); namespace shaka { namespace { @@ -441,8 +435,8 @@ base::Optional GetPackagingParams() { TestParams& test_params = packaging_params.test_params; test_params.dump_stream_info = FLAGS_dump_stream_info; test_params.inject_fake_clock = FLAGS_use_fake_clock_for_muxer; - if (FLAGS_override_version) - test_params.injected_library_version = FLAGS_test_version; + if (!FLAGS_test_packager_version.empty()) + test_params.injected_library_version = FLAGS_test_packager_version; return packaging_params; } diff --git a/packager/app/test/packager_app.py b/packager/app/test/packager_app.py index 159432ae0a..bb909fb124 100644 --- a/packager/app/test/packager_app.py +++ b/packager/app/test/packager_app.py @@ -5,7 +5,7 @@ # 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 -"""Test wrapper for the sample packager binary.""" +"""Test wrapper for the sample packager binaries.""" import os import platform @@ -15,18 +15,24 @@ import test_env class PackagerApp(object): - """Main integration class for testing the packager binary.""" + """Main integration class for testing the packager binaries.""" def __init__(self): - packager_name = 'packager' - if platform.system() == 'Windows': - packager_name += '.exe' - self.binary = os.path.join(test_env.SCRIPT_DIR, packager_name) + self.packager_binary = os.path.join(test_env.SCRIPT_DIR, + self._GetBinaryName('packager')) + self.mpd_generator_binary = os.path.join( + test_env.SCRIPT_DIR, self._GetBinaryName('mpd_generator')) # Set this to empty for now in case GetCommandLine() is called before # Package(). self.packaging_command_line = '' - assert os.path.exists(self.binary), ('Please run from output directory, ' - 'e.g. out/Debug/packager_test.py') + assert os.path.exists( + self.packager_binary), ('Please run from output directory, ' + 'e.g. out/Debug/packager_test.py') + + def _GetBinaryName(self, name): + if platform.system() == 'Windows': + name += '.exe' + return name def GetEnv(self): env = os.environ.copy() @@ -37,18 +43,18 @@ class PackagerApp(object): def DumpStreamInfo(self, stream): input_str = 'input=%s' % stream - cmd = [self.binary, input_str, '--dump_stream_info'] + cmd = [self.packager_binary, input_str, '--dump_stream_info'] return subprocess.check_output(cmd, env=self.GetEnv()) def Version(self): return subprocess.check_output( - [self.binary, '--version'], env=self.GetEnv()) + [self.packager_binary, '--version'], env=self.GetEnv()) def Package(self, streams, flags=None): """Executes packager command.""" if flags is None: flags = [] - cmd = [self.binary] + cmd = [self.packager_binary] cmd.extend(streams) cmd.extend(flags) @@ -67,3 +73,15 @@ class PackagerApp(object): def GetCommandLine(self): return self.packaging_command_line + + def MpdGenerator(self, flags): + """Executes MPD Generator command.""" + cmd = [self.mpd_generator_binary] + cmd.extend(flags) + + if test_env.options.v: + cmd.extend(['--v=%s' % test_env.options.v]) + if test_env.options.vmodule: + cmd.extend(['--vmodule="%s"' % test_env.options.vmodule]) + + return subprocess.call(cmd, env=self.GetEnv()) diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 088e979131..bfd78a7245 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -378,7 +378,7 @@ class PackagerAppTest(unittest.TestCase): flags.append('--use_fake_clock_for_muxer') # Override packager version string for testing. - flags += ['--override_version', '--test_version', '--'] + flags += ['--test_packager_version', '--'] return flags def _CompareWithGold(self, test_output, golden_file_name): @@ -519,6 +519,14 @@ class PackagerFunctionalTest(PackagerAppTest): def assertPackageSuccess(self, streams, flags=None): self.assertEqual(self.packager.Package(streams, flags), 0) + def assertMpdGeneratorSuccess(self): + media_infos = glob.glob(os.path.join(self.tmp_dir, '*.media_info')) + self.assertTrue(media_infos) + + flags = ['--input', ','.join(media_infos), '--output', self.mpd_output] + flags += ['--test_packager_version', '--'] + self.assertEqual(self.packager.MpdGenerator(flags), 0) + def testVersion(self): self.assertRegexpMatches( self.packager.Version(), '^packager(.exe)? version ' @@ -1278,6 +1286,16 @@ class PackagerFunctionalTest(PackagerAppTest): self._GetFlags(encryption=True, output_media_info=True)) self._CheckTestResults('encryption-and-output-media-info') + def testEncryptionAndOutputMediaInfoAndMpdFromMediaInfo(self): + self.assertPackageSuccess( + # The order is not determinstic if there are more than one + # AdaptationSets, so only one is included here. + self._GetStreams(['video']), + self._GetFlags(encryption=True, output_media_info=True)) + self.assertMpdGeneratorSuccess() + self._CheckTestResults( + 'encryption-and-output-media-info-and-mpd-from-media-info') + def testHlsSingleSegmentMp4Encrypted(self): self.assertPackageSuccess( self._GetStreams(['audio', 'video'], hls=True), diff --git a/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/bear-640x360-video.mp4 b/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/bear-640x360-video.mp4 new file mode 100644 index 0000000000..cebb14a0e8 Binary files /dev/null and b/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/bear-640x360-video.mp4 differ diff --git a/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/bear-640x360-video.mp4.media_info b/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/bear-640x360-video.mp4.media_info new file mode 100644 index 0000000000..bcdeea3035 --- /dev/null +++ b/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/bear-640x360-video.mp4.media_info @@ -0,0 +1,31 @@ +bandwidth: 977743 +video_info { + codec: "avc1.64001e" + width: 640 + height: 360 + time_scale: 30000 + frame_duration: 1001 + decoder_config: "\001d\000\036\377\341\000\031gd\000\036\254\331@\240/\371p\021\000\000\003\003\351\000\000\352`\017\026-\226\001\000\006h\353\343\313\"\300" + pixel_width: 1 + pixel_height: 1 +} +init_range { + begin: 0 + end: 1090 +} +index_range { + begin: 1091 + end: 1158 +} +media_file_name: "bear-640x360-video.mp4" +media_duration_seconds: 2.73606658 +reference_time_scale: 30000 +container_type: CONTAINER_MP4 +protected_content { + default_key_id: "1234567890123456" + content_protection_entry { + uuid: "1077efec-c0b2-4d02-ace3-3c1e52e2fb4b" + pssh: "\000\000\0004pssh\001\000\000\000\020w\357\354\300\262M\002\254\343<\036R\342\373K\000\000\000\0011234567890123456\000\000\000\000" + } + protection_scheme: "cenc" +} diff --git a/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/output.mpd b/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/output.mpd new file mode 100644 index 0000000000..9f33624f0d --- /dev/null +++ b/packager/app/test/testdata/encryption-and-output-media-info-and-mpd-from-media-info/output.mpd @@ -0,0 +1,18 @@ + + + + + + + + + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== + + bear-640x360-video.mp4 + + + + + + +