2014-07-16 20:47:57 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright 2014 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
|
|
|
|
"""Tests utilizing the sample packager binary."""
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
import filecmp
|
2014-07-16 20:47:57 +00:00
|
|
|
import os
|
2016-08-14 22:28:21 +00:00
|
|
|
import platform
|
2015-09-25 22:58:18 +00:00
|
|
|
import re
|
2014-07-16 20:47:57 +00:00
|
|
|
import shutil
|
2015-09-25 22:58:18 +00:00
|
|
|
import subprocess
|
2014-07-16 20:47:57 +00:00
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import packager_app
|
|
|
|
import test_env
|
|
|
|
|
2017-04-04 23:35:25 +00:00
|
|
|
_TEST_FAILURE_COMMAND_LINE_MESSAGE = """
|
|
|
|
!!! To reproduce the failure, change the output files to an !!!
|
|
|
|
!!! existing directory, e.g. output artifacts to current !!!
|
|
|
|
!!! directory by removing /tmp/something/ in the following !!!
|
|
|
|
!!! command line. !!!
|
|
|
|
The test executed the following command line:
|
|
|
|
"""
|
|
|
|
|
2014-07-16 20:47:57 +00:00
|
|
|
|
|
|
|
class PackagerAppTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.packager = packager_app.PackagerApp()
|
2015-09-25 22:58:18 +00:00
|
|
|
self.tmp_dir = tempfile.mkdtemp()
|
2015-10-01 23:29:52 +00:00
|
|
|
self.test_data_dir = os.path.join(test_env.SRC_DIR, 'packager', 'media',
|
|
|
|
'test', 'data')
|
|
|
|
self.golden_file_dir = os.path.join(test_env.SRC_DIR, 'packager', 'app',
|
|
|
|
'test', 'testdata')
|
2015-09-25 22:58:18 +00:00
|
|
|
self.output_prefix = os.path.join(self.tmp_dir, 'output')
|
|
|
|
self.mpd_output = self.output_prefix + '.mpd'
|
2016-06-30 22:25:52 +00:00
|
|
|
self.hls_master_playlist_output = self.output_prefix + '.m3u8'
|
2015-11-05 01:49:35 +00:00
|
|
|
self.output = None
|
2014-07-16 20:47:57 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2017-03-23 18:05:22 +00:00
|
|
|
if test_env.options.remove_temp_files_after_test:
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
2014-07-16 20:47:57 +00:00
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
def testVersion(self):
|
|
|
|
self.assertRegexpMatches(
|
2016-12-09 22:08:56 +00:00
|
|
|
self.packager.Version(), '^packager(.exe)? version '
|
|
|
|
r'((?P<tag>[\w\.]+)-)?(?P<hash>[a-f\d]+)-(debug|release)[\r\n]+.*$')
|
2015-12-21 23:10:17 +00:00
|
|
|
|
2014-07-16 20:47:57 +00:00
|
|
|
def testDumpStreamInfo(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
test_file = os.path.join(self.test_data_dir, 'bear-640x360.mp4')
|
|
|
|
stream_info = self.packager.DumpStreamInfo(test_file)
|
2014-07-16 20:47:57 +00:00
|
|
|
expected_stream_info = ('Found 2 stream(s).\n'
|
2015-09-29 17:13:09 +00:00
|
|
|
'Stream [0] type: Video\n'
|
|
|
|
' codec_string: avc1.64001e\n'
|
|
|
|
' time_scale: 30000\n'
|
|
|
|
' duration: 82082 (2.7 seconds)\n'
|
|
|
|
' is_encrypted: false\n'
|
|
|
|
' codec: H264\n'
|
|
|
|
' width: 640\n'
|
|
|
|
' height: 360\n'
|
2015-12-09 23:54:02 +00:00
|
|
|
' pixel_aspect_ratio: 1:1\n'
|
2015-09-29 17:13:09 +00:00
|
|
|
' trick_play_rate: 0\n'
|
|
|
|
' nalu_length_size: 4\n\n'
|
|
|
|
'Stream [1] type: Audio\n'
|
2014-07-16 20:47:57 +00:00
|
|
|
' codec_string: mp4a.40.2\n'
|
|
|
|
' time_scale: 44100\n'
|
|
|
|
' duration: 121856 (2.8 seconds)\n'
|
|
|
|
' is_encrypted: false\n'
|
|
|
|
' codec: AAC\n'
|
|
|
|
' sample_bits: 16\n'
|
|
|
|
' num_channels: 2\n'
|
2015-09-25 22:58:18 +00:00
|
|
|
' sampling_frequency: 44100\n'
|
2015-09-29 17:13:09 +00:00
|
|
|
' language: und\n')
|
2016-08-14 22:28:21 +00:00
|
|
|
stream_info = stream_info.replace('\r\n', '\n')
|
2015-09-25 22:58:18 +00:00
|
|
|
self.assertIn(expected_stream_info, stream_info,
|
2016-04-21 23:27:05 +00:00
|
|
|
'\nExpecting: \n %s\n\nBut seeing: \n%s' %
|
|
|
|
(expected_stream_info, stream_info))
|
2015-09-25 22:58:18 +00:00
|
|
|
|
|
|
|
def testPackageFirstStream(self):
|
|
|
|
self.packager.Package(self._GetStreams(['0']), self._GetFlags())
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-v-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2015-11-05 01:49:35 +00:00
|
|
|
def testPackageText(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2016-04-21 23:27:05 +00:00
|
|
|
self._GetStreams(['text'], test_files=['subtitle-english.vtt']),
|
2015-10-01 23:29:52 +00:00
|
|
|
self._GetFlags())
|
2015-11-05 01:49:35 +00:00
|
|
|
self._DiffGold(self.output[0], 'subtitle-english-golden.vtt')
|
|
|
|
self._DiffGold(self.mpd_output, 'subtitle-english-vtt-golden.mpd')
|
|
|
|
|
|
|
|
# Probably one of the most common scenarios is to package audio and video.
|
|
|
|
def testPackageAudioVideo(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']), self._GetFlags())
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-03-21 23:14:46 +00:00
|
|
|
def testPackageAudioVideoWithTrickPlay(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video', 'video,trick_play_rate=1']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-v-trick-1-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-trick-1-golden.mpd')
|
|
|
|
|
|
|
|
def testPackageAudioVideoWithTwoTrickPlay(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video', 'video,trick_play_rate=1',
|
|
|
|
'video,trick_play_rate=2']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-v-trick-1-golden.mp4')
|
|
|
|
self._DiffGold(self.output[3], 'bear-640x360-v-trick-2-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output,
|
|
|
|
'bear-640x360-av-trick-1-trick-2-golden.mpd')
|
|
|
|
|
|
|
|
def testPackageAudioVideoWithTwoTrickPlayDecreasingRate(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video', 'video,trick_play_rate=2',
|
|
|
|
'video,trick_play_rate=1']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-v-trick-2-golden.mp4')
|
|
|
|
self._DiffGold(self.output[3], 'bear-640x360-v-trick-1-golden.mp4')
|
|
|
|
# Since the stream descriptors are sorted in packager app, a different
|
|
|
|
# order of trick play rates gets the same mpd.
|
|
|
|
self._DiffGold(self.mpd_output,
|
|
|
|
'bear-640x360-av-trick-1-trick-2-golden.mpd')
|
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
def testPackageAudioVideoWithLanguageOverride(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video'], language_override='por-BR'),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-por-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-por-golden.mpd')
|
|
|
|
|
|
|
|
def testPackageAudioVideoWithLanguageOverrideWithSubtag(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video'], language_override='por-BR'),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-por-BR-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-por-BR-golden.mpd')
|
2017-04-10 20:20:45 +00:00
|
|
|
|
|
|
|
def testPackageAacHe(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(
|
|
|
|
['audio'], test_files=['bear-640x360-aac_he-silent_right.mp4']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0],
|
|
|
|
'bear-640x360-aac_he-silent_right-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output,
|
|
|
|
'bear-640x360-aac_he-silent_right-golden.mpd')
|
2017-02-21 18:36:50 +00:00
|
|
|
|
2015-11-05 01:49:35 +00:00
|
|
|
# Package all video, audio, and text.
|
|
|
|
def testPackageVideoAudioText(self):
|
|
|
|
audio_video_streams = self._GetStreams(['audio', 'video'])
|
2015-10-01 23:29:52 +00:00
|
|
|
text_stream = self._GetStreams(['text'],
|
|
|
|
test_files=['subtitle-english.vtt'])
|
2015-11-05 01:49:35 +00:00
|
|
|
self.packager.Package(audio_video_streams + text_stream, self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'subtitle-english-golden.vtt')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-avt-golden.mpd')
|
|
|
|
|
2016-04-28 22:02:55 +00:00
|
|
|
def testPackageAvcTs(self):
|
|
|
|
# Currently we only support live packaging for ts.
|
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'],
|
|
|
|
output_format='ts',
|
|
|
|
live=True,
|
|
|
|
test_files=['bear-640x360.ts']),
|
2017-01-07 02:40:37 +00:00
|
|
|
self._GetFlags(output_hls=True))
|
2016-04-28 22:02:55 +00:00
|
|
|
self._DiffLiveGold(self.output[0],
|
|
|
|
'bear-640x360-a-golden',
|
2016-06-30 22:25:52 +00:00
|
|
|
output_format='ts')
|
2016-04-28 22:02:55 +00:00
|
|
|
self._DiffLiveGold(self.output[1],
|
|
|
|
'bear-640x360-v-golden',
|
2016-06-30 22:25:52 +00:00
|
|
|
output_format='ts')
|
|
|
|
self._DiffGold(self.hls_master_playlist_output,
|
|
|
|
'bear-640x360-av-master-golden.m3u8')
|
|
|
|
self._DiffGold(
|
|
|
|
os.path.join(self.tmp_dir, 'audio.m3u8'), 'bear-640x360-a-golden.m3u8')
|
|
|
|
self._DiffGold(
|
|
|
|
os.path.join(self.tmp_dir, 'video.m3u8'), 'bear-640x360-v-golden.m3u8')
|
2016-04-28 22:02:55 +00:00
|
|
|
|
2016-01-09 00:18:52 +00:00
|
|
|
def testPackageVp8Webm(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
output_format='webm',
|
|
|
|
test_files=['bear-640x360.webm']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-vp8-golden.webm')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-vp8-webm-golden.mpd')
|
|
|
|
|
|
|
|
def testPackageVp9Webm(self):
|
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'],
|
|
|
|
output_format='webm',
|
|
|
|
test_files=['bear-320x240-vp9-opus.webm']),
|
2016-01-09 00:18:52 +00:00
|
|
|
self._GetFlags())
|
2016-05-05 22:26:48 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-320x240-opus-golden.webm')
|
|
|
|
self._DiffGold(self.output[1], 'bear-320x240-vp9-golden.webm')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-320x240-vp9-opus-webm-golden.mpd')
|
2016-01-09 00:18:52 +00:00
|
|
|
|
2016-07-29 23:06:20 +00:00
|
|
|
def testPackageVp9WebmWithBlockgroup(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
output_format='webm',
|
|
|
|
test_files=['bear-vp9-blockgroup.webm']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-vp9-blockgroup-golden.webm')
|
|
|
|
|
2016-01-13 19:58:48 +00:00
|
|
|
def testPackageVorbisWebm(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio'],
|
|
|
|
output_format='webm',
|
|
|
|
test_files=['bear-320x240-audio-only.webm']),
|
|
|
|
self._GetFlags())
|
|
|
|
self._DiffGold(self.output[0], 'bear-320x240-vorbis-golden.webm')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-320x240-vorbis-webm-golden.mpd')
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
def testPackageWithEncryption(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
|
|
|
self._GetFlags(encryption=True))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cenc-golden.mpd')
|
2016-04-21 23:27:05 +00:00
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-03-21 23:14:46 +00:00
|
|
|
def testPackageWithEncryptionAndTrickPlay(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video', 'video,trick_play_rate=1']),
|
|
|
|
self._GetFlags(encryption=True))
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-v-trick-1-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-trick-1-cenc-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[2], 'bear-640x360-v-trick-1-golden.mp4')
|
|
|
|
|
|
|
|
# TODO(hmchen): Add a test case that SD and HD AdapatationSet share one trick
|
|
|
|
# play stream.
|
|
|
|
def testPackageWithEncryptionAndTwoTrickPlays(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video', 'video,trick_play_rate=1',
|
|
|
|
'video,trick_play_rate=2']),
|
|
|
|
self._GetFlags(encryption=True))
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-v-trick-1-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[3], 'bear-640x360-v-trick-2-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output,
|
|
|
|
'bear-640x360-av-trick-1-trick-2-cenc-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[2], 'bear-640x360-v-trick-1-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[3], 'bear-640x360-v-trick-2-golden.mp4')
|
|
|
|
|
2017-05-09 22:49:01 +00:00
|
|
|
def testPackageWithEncryptionAndNoClearLead(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
|
|
|
self._GetFlags(encryption=True, clear_lead=0))
|
|
|
|
self._DiffGold(self.output[0],
|
|
|
|
'bear-640x360-a-cenc-no-clear-lead-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1],
|
|
|
|
'bear-640x360-v-cenc-no-clear-lead-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output,
|
|
|
|
'bear-640x360-av-cenc-no-clear-lead-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
|
2017-03-15 19:42:00 +00:00
|
|
|
def testPackageWithEncryptionAndNoPsshInStream(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
|
|
|
self._GetFlags(encryption=True, include_pssh_in_stream=False))
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cenc-no-pssh-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cenc-no-pssh-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cenc-no-pssh-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
|
2016-04-21 23:28:21 +00:00
|
|
|
def testPackageWithEncryptionCbc1(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
|
|
|
self._GetFlags(encryption=True,
|
|
|
|
protection_scheme='cbc1'))
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cbc1-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cbc1-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cbc1-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
|
|
|
|
def testPackageWithEncryptionCens(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
|
|
|
self._GetFlags(encryption=True,
|
|
|
|
protection_scheme='cens'))
|
2016-05-26 22:44:37 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cens-golden.mp4')
|
2016-04-21 23:28:21 +00:00
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cens-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cens-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
|
|
|
|
def testPackageWithEncryptionCbcs(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
|
|
|
self._GetFlags(encryption=True,
|
|
|
|
protection_scheme='cbcs'))
|
2016-05-26 22:44:37 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cbcs-golden.mp4')
|
2016-04-21 23:28:21 +00:00
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cbcs-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cbcs-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
|
|
|
|
2016-07-27 00:51:08 +00:00
|
|
|
def testPackageWithWebmSubsampleEncryption(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
output_format='webm',
|
2017-04-25 19:02:08 +00:00
|
|
|
test_files=['bear-320x180-vp9-altref.webm']),
|
2016-07-27 00:51:08 +00:00
|
|
|
self._GetFlags(encryption=True))
|
2017-04-25 19:02:08 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-320x180-vp9-altref-enc-golden.webm')
|
2016-07-27 00:51:08 +00:00
|
|
|
self._VerifyDecryption(self.output[0],
|
2017-04-25 19:02:08 +00:00
|
|
|
'bear-320x180-vp9-altref-dec-golden.webm')
|
2016-07-27 00:51:08 +00:00
|
|
|
|
2017-03-28 15:19:15 +00:00
|
|
|
def testPackageWithWebmVp9FullSampleEncryption(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
output_format='webm',
|
2017-04-25 19:02:08 +00:00
|
|
|
test_files=['bear-320x180-vp9-altref.webm']),
|
2017-03-28 15:19:15 +00:00
|
|
|
self._GetFlags(encryption=True, vp9_subsample_encryption=False))
|
|
|
|
self._DiffGold(self.output[0],
|
2017-04-25 19:02:08 +00:00
|
|
|
'bear-320x180-vp9-fullsample-enc-golden.webm')
|
2017-03-28 15:19:15 +00:00
|
|
|
self._VerifyDecryption(self.output[0],
|
2017-04-25 19:02:08 +00:00
|
|
|
'bear-320x180-vp9-altref-dec-golden.webm')
|
2017-03-28 15:19:15 +00:00
|
|
|
|
2016-06-30 22:25:52 +00:00
|
|
|
def testPackageAvcTsWithEncryption(self):
|
|
|
|
# Currently we only support live packaging for ts.
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video'],
|
|
|
|
output_format='ts',
|
|
|
|
live=True,
|
|
|
|
test_files=['bear-640x360.ts']),
|
2017-01-07 02:40:37 +00:00
|
|
|
self._GetFlags(encryption=True, output_hls=True))
|
2016-06-30 22:25:52 +00:00
|
|
|
self._DiffLiveGold(self.output[0],
|
|
|
|
'bear-640x360-a-enc-golden',
|
|
|
|
output_format='ts')
|
|
|
|
self._DiffLiveGold(self.output[1],
|
|
|
|
'bear-640x360-v-enc-golden',
|
|
|
|
output_format='ts')
|
|
|
|
self._DiffGold(self.hls_master_playlist_output,
|
|
|
|
'bear-640x360-av-enc-master-golden.m3u8')
|
|
|
|
self._DiffGold(
|
|
|
|
os.path.join(self.tmp_dir, 'audio.m3u8'),
|
|
|
|
'bear-640x360-a-enc-golden.m3u8')
|
|
|
|
self._DiffGold(
|
|
|
|
os.path.join(self.tmp_dir, 'video.m3u8'),
|
|
|
|
'bear-640x360-v-enc-golden.m3u8')
|
|
|
|
|
2017-03-23 18:05:22 +00:00
|
|
|
def testPackageAvcTsWithEncryptionExerciseEmulationPrevention(self):
|
|
|
|
# Currently we only support live packaging for ts.
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(
|
|
|
|
['video'],
|
|
|
|
output_format='ts',
|
|
|
|
live=True,
|
|
|
|
test_files=['sintel-1024x436.mp4']),
|
|
|
|
self._GetFlags(
|
|
|
|
encryption=True,
|
|
|
|
encryption_key='ad7e9786def9159db6724be06dfcde7a',
|
|
|
|
output_hls=True))
|
|
|
|
self._DiffLiveGold(self.output[0],
|
|
|
|
'sintel-1024x436-v-enc-golden',
|
|
|
|
output_format='ts')
|
|
|
|
self._DiffGold(self.hls_master_playlist_output,
|
|
|
|
'sintel-1024x436-v-enc-master-golden.m3u8')
|
|
|
|
self._DiffGold(
|
|
|
|
os.path.join(self.tmp_dir, 'video.m3u8'),
|
|
|
|
'sintel-1024x436-v-enc-golden.m3u8')
|
|
|
|
|
2016-01-21 00:14:24 +00:00
|
|
|
def testPackageWebmWithEncryption(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
output_format='webm',
|
|
|
|
test_files=['bear-640x360.webm']),
|
|
|
|
self._GetFlags(encryption=True))
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-vp8-cenc-golden.webm')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-vp8-cenc-webm-golden.mpd')
|
2016-04-21 23:27:05 +00:00
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-vp8-golden.webm')
|
2016-01-21 00:14:24 +00:00
|
|
|
|
2015-10-29 00:26:29 +00:00
|
|
|
def testPackageHevcWithEncryption(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
test_files=['bear-640x360-hevc.mp4']),
|
|
|
|
self._GetFlags(encryption=True))
|
2016-04-21 23:27:05 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-hevc-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-hevc-cenc-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-hevc-golden.mp4')
|
2015-10-29 00:26:29 +00:00
|
|
|
|
2016-01-09 00:18:52 +00:00
|
|
|
def testPackageVp8Mp4WithEncryption(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['video'],
|
|
|
|
output_format='mp4',
|
|
|
|
test_files=['bear-640x360.webm']),
|
|
|
|
self._GetFlags(encryption=True))
|
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-vp8-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-vp8-cenc-golden.mpd')
|
2016-04-21 23:27:05 +00:00
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-vp8-golden.mp4')
|
2016-01-09 00:18:52 +00:00
|
|
|
|
2016-06-01 23:28:56 +00:00
|
|
|
def testPackageOpusVp9Mp4WithEncryption(self):
|
2016-01-09 00:18:52 +00:00
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'],
|
2016-01-09 00:18:52 +00:00
|
|
|
output_format='mp4',
|
2016-05-05 22:26:48 +00:00
|
|
|
test_files=['bear-320x240-vp9-opus.webm']),
|
2016-01-09 00:18:52 +00:00
|
|
|
self._GetFlags(encryption=True))
|
2016-06-01 23:28:56 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-320x240-opus-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-320x240-vp9-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-320x240-opus-vp9-cenc-golden.mpd')
|
|
|
|
self._VerifyDecryption(self.output[0], 'bear-320x240-opus-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-320x240-vp9-golden.mp4')
|
2016-01-09 00:18:52 +00:00
|
|
|
|
2017-03-23 18:36:47 +00:00
|
|
|
def testPackageWvmInput(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(
|
|
|
|
['0', '1', '2', '3'], test_files=['bear-multi-configs.wvm']),
|
|
|
|
self._GetFlags(
|
|
|
|
decryption=True, encryption_key='9248d245390e0a49d483ba9b43fc69c3'))
|
|
|
|
# Output timescale is 90000.
|
|
|
|
self._DiffGold(self.output[0], 'bear-320x180-v-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-320x180-a-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-v-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.output[3], 'bear-640x360-a-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-wvm-golden.mpd')
|
|
|
|
|
|
|
|
def testPackageWvmInputWithoutStrippingParameterSetNalus(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(
|
|
|
|
['0', '1', '2', '3'], test_files=['bear-multi-configs.wvm']),
|
|
|
|
self._GetFlags(
|
|
|
|
strip_parameter_set_nalus=False,
|
|
|
|
decryption=True,
|
|
|
|
encryption_key='9248d245390e0a49d483ba9b43fc69c3'))
|
|
|
|
# Output timescale is 90000.
|
|
|
|
self._DiffGold(self.output[0], 'bear-320x180-avc3-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-320x180-a-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.output[2], 'bear-640x360-avc3-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.output[3], 'bear-640x360-a-wvm-golden.mp4')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-avc3-wvm-golden.mpd')
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
def testPackageWithEncryptionAndRandomIv(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
2016-04-21 23:27:05 +00:00
|
|
|
self._GetFlags(encryption=True, random_iv=True))
|
2015-09-25 22:58:18 +00:00
|
|
|
self._AssertStreamInfo(self.output[0], 'is_encrypted: true')
|
|
|
|
self._AssertStreamInfo(self.output[1], 'is_encrypted: true')
|
|
|
|
# The outputs are encrypted with random iv, so they are not the same as
|
|
|
|
# golden files.
|
2015-10-01 23:29:52 +00:00
|
|
|
self.assertFalse(self._CompareWithGold(self.output[0],
|
|
|
|
'bear-640x360-a-cenc-golden.mp4'))
|
|
|
|
self.assertFalse(self._CompareWithGold(self.output[1],
|
|
|
|
'bear-640x360-v-cenc-golden.mp4'))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cenc-golden.mpd')
|
2016-04-21 23:27:05 +00:00
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
|
|
|
def testPackageWithEncryptionAndRealClock(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
2016-04-21 23:27:05 +00:00
|
|
|
self._GetFlags(encryption=True, use_fake_clock=False))
|
2015-09-25 22:58:18 +00:00
|
|
|
self._AssertStreamInfo(self.output[0], 'is_encrypted: true')
|
|
|
|
self._AssertStreamInfo(self.output[1], 'is_encrypted: true')
|
|
|
|
# The outputs are generated with real clock, so they are not the same as
|
|
|
|
# golden files.
|
2015-10-01 23:29:52 +00:00
|
|
|
self.assertFalse(self._CompareWithGold(self.output[0],
|
|
|
|
'bear-640x360-a-cenc-golden.mp4'))
|
|
|
|
self.assertFalse(self._CompareWithGold(self.output[1],
|
|
|
|
'bear-640x360-v-cenc-golden.mp4'))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cenc-golden.mpd')
|
2016-04-21 23:27:05 +00:00
|
|
|
self._VerifyDecryption(self.output[0], 'bear-640x360-a-golden.mp4')
|
|
|
|
self._VerifyDecryption(self.output[1], 'bear-640x360-v-golden.mp4')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-02-09 00:47:59 +00:00
|
|
|
def testPackageWithEncryptionAndNonDashIfIop(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
2017-02-09 00:47:59 +00:00
|
|
|
self._GetFlags(encryption=True, dash_if_iop=False))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cenc-golden.mp4')
|
2017-02-09 00:47:59 +00:00
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-cenc-non-iop-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
|
|
|
def testPackageWithEncryptionAndOutputMediaInfo(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video']),
|
2016-04-21 23:27:05 +00:00
|
|
|
self._GetFlags(encryption=True, output_media_info=True))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffGold(self.output[0], 'bear-640x360-a-cenc-golden.mp4')
|
|
|
|
self._DiffGold(self.output[1], 'bear-640x360-v-cenc-golden.mp4')
|
|
|
|
self._DiffMediaInfoGold(self.output[0], 'bear-640x360-a-cenc-golden.mp4')
|
|
|
|
self._DiffMediaInfoGold(self.output[1], 'bear-640x360-v-cenc-golden.mp4')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
|
|
|
def testPackageWithLiveProfile(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2017-01-07 02:40:37 +00:00
|
|
|
self._GetStreams(['audio', 'video'], live=True), self._GetFlags())
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffLiveGold(self.output[0], 'bear-640x360-a-live-golden')
|
|
|
|
self._DiffLiveGold(self.output[1], 'bear-640x360-v-live-golden')
|
|
|
|
self._DiffLiveMpdGold(self.mpd_output, 'bear-640x360-av-live-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-02-09 00:42:44 +00:00
|
|
|
def testPackageWithLiveStaticProfile(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video'], live=True),
|
|
|
|
self._GetFlags(generate_static_mpd=True))
|
|
|
|
self._DiffLiveGold(self.output[0], 'bear-640x360-a-live-golden')
|
|
|
|
self._DiffLiveGold(self.output[1], 'bear-640x360-v-live-golden')
|
|
|
|
self._DiffGold(self.mpd_output, 'bear-640x360-av-live-static-golden.mpd')
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
def testPackageWithLiveProfileAndEncryption(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'], live=True),
|
2017-01-07 02:40:37 +00:00
|
|
|
self._GetFlags(encryption=True))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffLiveGold(self.output[0], 'bear-640x360-a-live-cenc-golden')
|
|
|
|
self._DiffLiveGold(self.output[1], 'bear-640x360-v-live-cenc-golden')
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveMpdGold(self.mpd_output,
|
2015-09-29 17:13:09 +00:00
|
|
|
'bear-640x360-av-live-cenc-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-02-09 00:47:59 +00:00
|
|
|
def testPackageWithLiveProfileAndEncryptionAndNonDashIfIop(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'], live=True),
|
2017-02-09 00:47:59 +00:00
|
|
|
self._GetFlags(encryption=True, dash_if_iop=False))
|
2015-09-29 17:13:09 +00:00
|
|
|
self._DiffLiveGold(self.output[0], 'bear-640x360-a-live-cenc-golden')
|
|
|
|
self._DiffLiveGold(self.output[1], 'bear-640x360-v-live-cenc-golden')
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveMpdGold(self.mpd_output,
|
2017-02-09 00:47:59 +00:00
|
|
|
'bear-640x360-av-live-cenc-non-iop-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-02-09 00:47:59 +00:00
|
|
|
def testPackageWithLiveProfileAndEncryptionAndMultFiles(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'],
|
|
|
|
live=True,
|
|
|
|
test_files=['bear-1280x720.mp4', 'bear-640x360.mp4',
|
|
|
|
'bear-320x180.mp4']),
|
2017-02-09 00:47:59 +00:00
|
|
|
self._GetFlags(encryption=True))
|
2015-10-01 23:29:52 +00:00
|
|
|
self._DiffLiveGold(self.output[2], 'bear-640x360-a-live-cenc-golden')
|
|
|
|
self._DiffLiveGold(self.output[3], 'bear-640x360-v-live-cenc-golden')
|
|
|
|
# Mpd cannot be validated right now since we don't generate determinstic
|
|
|
|
# mpd with multiple inputs due to thread racing.
|
|
|
|
# TODO(kqyang): Generate determinstic mpd or at least validate mpd schema.
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
def testPackageWithLiveProfileAndKeyRotation(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'], live=True),
|
2017-01-07 02:40:37 +00:00
|
|
|
self._GetFlags(encryption=True, key_rotation=True))
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveGold(self.output[0],
|
2015-09-29 17:13:09 +00:00
|
|
|
'bear-640x360-a-live-cenc-rotation-golden')
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveGold(self.output[1],
|
2015-09-29 17:13:09 +00:00
|
|
|
'bear-640x360-v-live-cenc-rotation-golden')
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveMpdGold(self.mpd_output,
|
2015-09-29 17:13:09 +00:00
|
|
|
'bear-640x360-av-live-cenc-rotation-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-03-15 19:42:00 +00:00
|
|
|
def testPackageWithLiveProfileAndKeyRotationAndNoPsshInStream(self):
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video'], live=True),
|
|
|
|
self._GetFlags(
|
|
|
|
encryption=True, key_rotation=True, include_pssh_in_stream=False))
|
|
|
|
self._DiffLiveGold(self.output[0],
|
|
|
|
'bear-640x360-a-live-cenc-rotation-no-pssh-golden')
|
|
|
|
self._DiffLiveGold(self.output[1],
|
|
|
|
'bear-640x360-v-live-cenc-rotation-no-pssh-golden')
|
|
|
|
self._DiffLiveMpdGold(
|
|
|
|
self.mpd_output,
|
|
|
|
'bear-640x360-av-live-cenc-rotation-no-pssh-golden.mpd')
|
|
|
|
|
2017-02-09 00:47:59 +00:00
|
|
|
def testPackageWithLiveProfileAndKeyRotationAndNonDashIfIop(self):
|
2015-10-01 23:29:52 +00:00
|
|
|
self.packager.Package(
|
2016-06-01 23:28:56 +00:00
|
|
|
self._GetStreams(['audio', 'video'], live=True),
|
2015-10-01 23:29:52 +00:00
|
|
|
self._GetFlags(encryption=True,
|
|
|
|
key_rotation=True,
|
2017-02-09 00:47:59 +00:00
|
|
|
dash_if_iop=False))
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveGold(self.output[0],
|
2015-09-29 17:13:09 +00:00
|
|
|
'bear-640x360-a-live-cenc-rotation-golden')
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffLiveGold(self.output[1],
|
2015-09-29 17:13:09 +00:00
|
|
|
'bear-640x360-v-live-cenc-rotation-golden')
|
2017-02-09 00:47:59 +00:00
|
|
|
self._DiffLiveMpdGold(
|
|
|
|
self.mpd_output,
|
|
|
|
'bear-640x360-av-live-cenc-rotation-non-iop-golden.mpd')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
|
|
|
@unittest.skipUnless(test_env.has_aes_flags, 'Requires AES credentials.')
|
2014-07-16 20:47:57 +00:00
|
|
|
def testWidevineEncryptionWithAes(self):
|
2015-09-25 22:58:18 +00:00
|
|
|
flags = self._GetFlags(widevine_encryption=True)
|
|
|
|
flags += ['--aes_signing_key=' + test_env.options.aes_signing_key,
|
|
|
|
'--aes_signing_iv=' + test_env.options.aes_signing_iv]
|
|
|
|
self.packager.Package(self._GetStreams(['audio', 'video']), flags)
|
|
|
|
self._AssertStreamInfo(self.output[0], 'is_encrypted: true')
|
|
|
|
self._AssertStreamInfo(self.output[1], 'is_encrypted: true')
|
|
|
|
|
2016-12-13 23:48:54 +00:00
|
|
|
@unittest.skipUnless(test_env.has_aes_flags, 'Requires AES credentials.')
|
2017-02-09 00:47:59 +00:00
|
|
|
def testWidevineEncryptionWithAesAndMultFiles(self):
|
|
|
|
flags = self._GetFlags(widevine_encryption=True)
|
2016-12-13 23:48:54 +00:00
|
|
|
flags += ['--aes_signing_key=' + test_env.options.aes_signing_key,
|
|
|
|
'--aes_signing_iv=' + test_env.options.aes_signing_iv]
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['audio', 'video'],
|
|
|
|
test_files=['bear-1280x720.mp4', 'bear-640x360.mp4',
|
|
|
|
'bear-320x180.mp4']), flags)
|
|
|
|
with open(self.mpd_output, 'rb') as f:
|
|
|
|
print f.read()
|
|
|
|
# TODO(kqyang): Add some validations.
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
@unittest.skipUnless(test_env.has_aes_flags, 'Requires AES credentials.')
|
2014-07-16 20:47:57 +00:00
|
|
|
def testKeyRotationWithAes(self):
|
2015-09-25 22:58:18 +00:00
|
|
|
flags = self._GetFlags(widevine_encryption=True, key_rotation=True)
|
|
|
|
flags += ['--aes_signing_key=' + test_env.options.aes_signing_key,
|
|
|
|
'--aes_signing_iv=' + test_env.options.aes_signing_iv]
|
|
|
|
self.packager.Package(self._GetStreams(['audio', 'video']), flags)
|
|
|
|
self._AssertStreamInfo(self.output[0], 'is_encrypted: true')
|
|
|
|
self._AssertStreamInfo(self.output[1], 'is_encrypted: true')
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_env.has_rsa_flags, 'Requires RSA credentials.')
|
2014-07-16 20:47:57 +00:00
|
|
|
def testWidevineEncryptionWithRsa(self):
|
2015-09-25 22:58:18 +00:00
|
|
|
flags = self._GetFlags(widevine_encryption=True)
|
|
|
|
flags += ['--rsa_signing_key_path=' + test_env.options.rsa_signing_key_path]
|
|
|
|
self.packager.Package(self._GetStreams(['audio', 'video']), flags)
|
|
|
|
self._AssertStreamInfo(self.output[0], 'is_encrypted: true')
|
|
|
|
self._AssertStreamInfo(self.output[1], 'is_encrypted: true')
|
|
|
|
|
2016-01-09 00:18:52 +00:00
|
|
|
def _GetStreams(self,
|
|
|
|
stream_descriptors,
|
2017-02-21 18:36:50 +00:00
|
|
|
language_override=None,
|
2016-07-22 17:46:38 +00:00
|
|
|
output_format=None,
|
2016-01-09 00:18:52 +00:00
|
|
|
live=False,
|
|
|
|
test_files=None):
|
2015-10-01 23:29:52 +00:00
|
|
|
if test_files is None:
|
|
|
|
test_files = ['bear-640x360.mp4']
|
2015-09-25 22:58:18 +00:00
|
|
|
streams = []
|
2015-11-05 01:49:35 +00:00
|
|
|
if not self.output:
|
|
|
|
self.output = []
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2015-10-01 23:29:52 +00:00
|
|
|
for test_file_index, test_file_name in enumerate(test_files):
|
|
|
|
test_file = os.path.join(self.test_data_dir, test_file_name)
|
|
|
|
for stream_descriptor in stream_descriptors:
|
|
|
|
if len(test_files) == 1:
|
|
|
|
output_prefix = '%s_%s' % (self.output_prefix, stream_descriptor)
|
|
|
|
else:
|
|
|
|
output_prefix = '%s_%d_%s' % (self.output_prefix, test_file_index,
|
|
|
|
stream_descriptor)
|
2017-03-21 23:14:46 +00:00
|
|
|
# Replace ',', '=' with '_' to make it more like a filename, also
|
|
|
|
# avoid potential illegal charactors for a filename.
|
|
|
|
for ch in [',', '=']:
|
|
|
|
output_prefix = output_prefix.replace(ch, '_')
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
if live:
|
2016-06-30 22:25:52 +00:00
|
|
|
if output_format == 'ts':
|
2016-07-22 17:46:38 +00:00
|
|
|
stream = ('input=%s,stream=%s,segment_template=%s-$Number$.ts,'
|
|
|
|
'playlist_name=%s.m3u8' % (test_file, stream_descriptor,
|
|
|
|
output_prefix,
|
|
|
|
stream_descriptor))
|
2016-06-30 22:25:52 +00:00
|
|
|
else:
|
2016-07-22 17:46:38 +00:00
|
|
|
stream = (
|
|
|
|
'input=%s,stream=%s,init_segment=%s-init.mp4,'
|
|
|
|
'segment_template=%s-$Number$.m4s' %
|
|
|
|
(test_file, stream_descriptor, output_prefix, output_prefix))
|
2015-10-01 23:29:52 +00:00
|
|
|
self.output.append(output_prefix)
|
2015-09-25 22:58:18 +00:00
|
|
|
else:
|
2016-01-09 00:18:52 +00:00
|
|
|
output = '%s.%s' % (
|
|
|
|
output_prefix,
|
|
|
|
self._GetExtension(stream_descriptor, output_format))
|
2016-07-22 17:46:38 +00:00
|
|
|
stream = ('input=%s,stream=%s,output=%s' %
|
|
|
|
(test_file, stream_descriptor, output))
|
2015-10-01 23:29:52 +00:00
|
|
|
self.output.append(output)
|
2017-02-21 18:36:50 +00:00
|
|
|
if output_format:
|
|
|
|
stream += ',format=%s' % output_format
|
|
|
|
if language_override:
|
|
|
|
stream += ',lang=%s' % language_override
|
|
|
|
streams.append(stream)
|
2015-09-25 22:58:18 +00:00
|
|
|
return streams
|
|
|
|
|
2016-01-09 00:18:52 +00:00
|
|
|
def _GetExtension(self, stream_descriptor, output_format):
|
2015-11-05 01:49:35 +00:00
|
|
|
# TODO(rkuroiwa): Support ttml.
|
2015-10-01 23:29:52 +00:00
|
|
|
if stream_descriptor == 'text':
|
|
|
|
return 'vtt'
|
2016-07-22 17:46:38 +00:00
|
|
|
if output_format:
|
|
|
|
return output_format
|
|
|
|
# Default to mp4.
|
|
|
|
return 'mp4'
|
2015-10-01 23:29:52 +00:00
|
|
|
|
|
|
|
def _GetFlags(self,
|
2017-03-23 18:36:47 +00:00
|
|
|
strip_parameter_set_nalus=True,
|
2015-10-01 23:29:52 +00:00
|
|
|
encryption=False,
|
2017-05-09 22:49:01 +00:00
|
|
|
clear_lead=1,
|
2016-04-21 23:28:21 +00:00
|
|
|
protection_scheme=None,
|
2017-03-28 15:19:15 +00:00
|
|
|
vp9_subsample_encryption=True,
|
2016-04-21 23:27:05 +00:00
|
|
|
decryption=False,
|
2017-03-23 18:05:22 +00:00
|
|
|
encryption_key='32333435363738393021323334353637',
|
|
|
|
encryption_iv='3334353637383930',
|
2015-10-01 23:29:52 +00:00
|
|
|
random_iv=False,
|
|
|
|
widevine_encryption=False,
|
|
|
|
key_rotation=False,
|
2017-03-15 19:42:00 +00:00
|
|
|
include_pssh_in_stream=True,
|
2017-02-09 00:47:59 +00:00
|
|
|
dash_if_iop=True,
|
2015-10-01 23:29:52 +00:00
|
|
|
output_media_info=False,
|
2016-06-30 22:25:52 +00:00
|
|
|
output_hls=False,
|
2017-02-09 00:42:44 +00:00
|
|
|
generate_static_mpd=False,
|
2015-10-01 23:29:52 +00:00
|
|
|
use_fake_clock=True):
|
2015-09-25 22:58:18 +00:00
|
|
|
flags = []
|
2017-03-23 18:36:47 +00:00
|
|
|
|
|
|
|
if not strip_parameter_set_nalus:
|
|
|
|
flags += ['--strip_parameter_set_nalus=false']
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
if widevine_encryption:
|
2015-10-01 23:29:52 +00:00
|
|
|
widevine_server_url = ('https://license.uat.widevine.com/cenc'
|
|
|
|
'/getcontentkey/widevine_test')
|
|
|
|
flags += ['--enable_widevine_encryption',
|
|
|
|
'--key_server_url=' + widevine_server_url,
|
|
|
|
'--content_id=3031323334353637', '--signer=widevine_test']
|
2015-09-25 22:58:18 +00:00
|
|
|
elif encryption:
|
2015-10-01 23:29:52 +00:00
|
|
|
flags += ['--enable_fixed_key_encryption',
|
|
|
|
'--key_id=31323334353637383930313233343536',
|
2017-05-09 22:49:01 +00:00
|
|
|
'--clear_lead={0}'.format(clear_lead)]
|
2016-06-30 22:25:52 +00:00
|
|
|
|
2017-03-23 18:05:22 +00:00
|
|
|
if test_env.options.encryption_key:
|
|
|
|
encryption_key = test_env.options.encryption_key
|
|
|
|
flags.append('--key=' + encryption_key)
|
2015-10-01 23:29:52 +00:00
|
|
|
if not random_iv:
|
2017-03-23 18:05:22 +00:00
|
|
|
if test_env.options.encryption_iv:
|
|
|
|
encryption_iv = test_env.options.encryption_iv
|
|
|
|
flags.append('--iv=' + encryption_iv)
|
2016-04-21 23:28:21 +00:00
|
|
|
if protection_scheme:
|
|
|
|
flags += ['--protection_scheme', protection_scheme]
|
2017-03-28 15:19:15 +00:00
|
|
|
if not vp9_subsample_encryption:
|
|
|
|
flags += ['--vp9_subsample_encryption=false']
|
2016-04-21 23:27:05 +00:00
|
|
|
|
|
|
|
if decryption:
|
|
|
|
flags += ['--enable_fixed_key_decryption',
|
|
|
|
'--key_id=31323334353637383930313233343536',
|
2017-03-23 18:36:47 +00:00
|
|
|
'--key=' + encryption_key]
|
2016-04-21 23:27:05 +00:00
|
|
|
|
2015-10-01 23:29:52 +00:00
|
|
|
if key_rotation:
|
|
|
|
flags.append('--crypto_period_duration=1')
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-03-15 19:42:00 +00:00
|
|
|
if not include_pssh_in_stream:
|
|
|
|
flags.append('--mp4_include_pssh_in_stream=false')
|
|
|
|
|
2017-02-09 00:47:59 +00:00
|
|
|
if not dash_if_iop:
|
|
|
|
flags.append('--generate_dash_if_iop_compliant_mpd=false')
|
2015-09-25 22:58:18 +00:00
|
|
|
if output_media_info:
|
2015-10-01 23:29:52 +00:00
|
|
|
flags.append('--output_media_info')
|
2016-06-30 22:25:52 +00:00
|
|
|
elif output_hls:
|
|
|
|
flags += ['--hls_master_playlist_output', self.hls_master_playlist_output]
|
2015-09-25 22:58:18 +00:00
|
|
|
else:
|
2015-10-01 23:29:52 +00:00
|
|
|
flags += ['--mpd_output', self.mpd_output]
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2017-02-09 00:42:44 +00:00
|
|
|
if generate_static_mpd:
|
|
|
|
flags += ['--generate_static_mpd']
|
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
flags.append('--segment_duration=1')
|
|
|
|
# Use fake clock, so output can be compared.
|
|
|
|
if use_fake_clock:
|
2015-10-01 23:29:52 +00:00
|
|
|
flags.append('--use_fake_clock_for_muxer')
|
2015-12-21 23:10:17 +00:00
|
|
|
|
|
|
|
# Override packager version string for testing.
|
2016-07-07 19:34:07 +00:00
|
|
|
flags += ['--override_version', '--test_version', '<tag>-<hash>-<test>']
|
2015-09-25 22:58:18 +00:00
|
|
|
return flags
|
|
|
|
|
|
|
|
def _CompareWithGold(self, test_output, golden_file_name):
|
2015-10-01 23:29:52 +00:00
|
|
|
golden_file = os.path.join(self.golden_file_dir, golden_file_name)
|
2015-09-25 22:58:18 +00:00
|
|
|
return filecmp.cmp(test_output, golden_file)
|
|
|
|
|
|
|
|
def _DiffGold(self, test_output, golden_file_name):
|
2015-10-01 23:29:52 +00:00
|
|
|
golden_file = os.path.join(self.golden_file_dir, golden_file_name)
|
2015-09-25 22:58:18 +00:00
|
|
|
if test_env.options.test_update_golden_files:
|
2016-01-09 00:18:52 +00:00
|
|
|
if not os.path.exists(golden_file) or not filecmp.cmp(test_output,
|
|
|
|
golden_file):
|
2015-10-01 23:29:52 +00:00
|
|
|
print 'Updating golden file: ', golden_file_name
|
|
|
|
shutil.copyfile(test_output, golden_file)
|
2015-09-25 22:58:18 +00:00
|
|
|
else:
|
2015-11-05 01:49:35 +00:00
|
|
|
match = filecmp.cmp(test_output, golden_file)
|
|
|
|
if not match:
|
2016-08-14 22:28:21 +00:00
|
|
|
git = 'git'
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
git += '.bat'
|
|
|
|
p = subprocess.Popen([git, '--no-pager', 'diff', '--color=auto',
|
2016-06-01 23:28:56 +00:00
|
|
|
'--no-ext-diff', '--no-index', golden_file,
|
|
|
|
test_output],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
2015-11-05 01:49:35 +00:00
|
|
|
output, error = p.communicate()
|
2017-04-04 23:35:25 +00:00
|
|
|
command_line = self.packager.GetCommandLine()
|
|
|
|
failure_message = (output + error + '\n' +
|
|
|
|
_TEST_FAILURE_COMMAND_LINE_MESSAGE +
|
|
|
|
command_line)
|
|
|
|
self.fail(failure_message)
|
2015-09-25 22:58:18 +00:00
|
|
|
|
|
|
|
# '*.media_info' outputs contain media file names, which is changing for
|
|
|
|
# every test run. These needs to be replaced for comparison.
|
|
|
|
def _DiffMediaInfoGold(self, test_output, golden_file_name):
|
2016-08-14 22:28:21 +00:00
|
|
|
if platform.system() == 'Windows':
|
|
|
|
test_output = test_output.replace('\\', '\\\\')
|
2015-09-25 22:58:18 +00:00
|
|
|
media_info_output = test_output + '.media_info'
|
|
|
|
# Replaces filename, which is changing for every test run.
|
2016-08-14 22:28:21 +00:00
|
|
|
with open(media_info_output, 'rb') as f:
|
2015-10-01 23:29:52 +00:00
|
|
|
content = f.read()
|
2016-08-14 22:28:21 +00:00
|
|
|
with open(media_info_output, 'wb') as f:
|
2015-10-01 23:29:52 +00:00
|
|
|
f.write(content.replace(test_output, 'place_holder'))
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffGold(media_info_output, golden_file_name + '.media_info')
|
|
|
|
|
2016-04-28 22:02:55 +00:00
|
|
|
def _DiffLiveGold(self,
|
|
|
|
test_output_prefix,
|
|
|
|
golden_file_name_prefix,
|
2016-06-30 22:25:52 +00:00
|
|
|
output_format='mp4'):
|
2015-09-25 22:58:18 +00:00
|
|
|
# Compare init and the first three segments.
|
2016-06-30 22:25:52 +00:00
|
|
|
if output_format == 'ts':
|
|
|
|
for i in range(1, 4):
|
|
|
|
self._DiffGold('%s-%d.ts' % (test_output_prefix, i),
|
|
|
|
'%s-%d.ts' % (golden_file_name_prefix, i))
|
|
|
|
else:
|
2016-04-28 22:02:55 +00:00
|
|
|
self._DiffGold(test_output_prefix + '-init.mp4',
|
|
|
|
golden_file_name_prefix + '-init.mp4')
|
2016-06-30 22:25:52 +00:00
|
|
|
for i in range(1, 4):
|
|
|
|
self._DiffGold('%s-%d.m4s' % (test_output_prefix, i),
|
|
|
|
'%s-%d.m4s' % (golden_file_name_prefix, i))
|
2015-09-25 22:58:18 +00:00
|
|
|
|
2016-01-11 23:58:02 +00:00
|
|
|
# Live mpd contains current availabilityStartTime and publishTime, which
|
|
|
|
# needs to be replaced for comparison.
|
2015-09-25 22:58:18 +00:00
|
|
|
def _DiffLiveMpdGold(self, test_output, golden_file_name):
|
2016-08-14 22:28:21 +00:00
|
|
|
with open(test_output, 'rb') as f:
|
2015-10-01 23:29:52 +00:00
|
|
|
content = f.read()
|
2016-01-11 23:58:02 +00:00
|
|
|
|
|
|
|
# Extract availabilityStartTime.
|
|
|
|
m = re.search('availabilityStartTime="[^"]+"', content)
|
2015-09-25 22:58:18 +00:00
|
|
|
self.assertIsNotNone(m)
|
2015-10-01 23:29:52 +00:00
|
|
|
availability_start_time = m.group(0)
|
2016-01-11 23:58:02 +00:00
|
|
|
print availability_start_time
|
|
|
|
|
|
|
|
# Extract publishTime.
|
|
|
|
m = re.search('publishTime="[^"]+"', content)
|
|
|
|
self.assertIsNotNone(m)
|
|
|
|
publish_time = m.group(0)
|
|
|
|
print publish_time
|
2016-08-14 22:28:21 +00:00
|
|
|
with open(test_output, 'wb') as f:
|
2016-03-30 00:37:58 +00:00
|
|
|
f.write(content.replace(
|
|
|
|
availability_start_time,
|
|
|
|
'availabilityStartTime="some_availability_start_time"').replace(
|
|
|
|
publish_time, 'publishTime="some_publish_time"'))
|
2016-01-11 23:58:02 +00:00
|
|
|
|
2015-09-25 22:58:18 +00:00
|
|
|
self._DiffGold(test_output, golden_file_name)
|
2014-07-16 20:47:57 +00:00
|
|
|
|
|
|
|
def _AssertStreamInfo(self, stream, info):
|
|
|
|
stream_info = self.packager.DumpStreamInfo(stream)
|
|
|
|
self.assertIn('Found 1 stream(s).', stream_info)
|
|
|
|
self.assertIn(info, stream_info)
|
|
|
|
|
2016-04-21 23:27:05 +00:00
|
|
|
def _VerifyDecryption(self, test_encrypted_file, golden_clear_file):
|
|
|
|
output_extension = os.path.splitext(golden_clear_file)[1][1:]
|
|
|
|
self.packager.Package(
|
|
|
|
self._GetStreams(['0'],
|
|
|
|
output_format=output_extension,
|
|
|
|
test_files=[test_encrypted_file]),
|
|
|
|
self._GetFlags(decryption=True))
|
|
|
|
self._DiffGold(self.output[-1], golden_clear_file)
|
|
|
|
|
2014-07-16 20:47:57 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|