diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index aa16c2d0e1..fd39bf3c98 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -35,7 +35,8 @@ class PackagerAppTest(unittest.TestCase): self.output = None def tearDown(self): - shutil.rmtree(self.tmp_dir) + if test_env.options.remove_temp_files_after_test: + shutil.rmtree(self.tmp_dir) def testVersion(self): self.assertRegexpMatches( @@ -252,6 +253,27 @@ class PackagerAppTest(unittest.TestCase): os.path.join(self.tmp_dir, 'video.m3u8'), 'bear-640x360-v-enc-golden.m3u8') + 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') + def testPackageWebmWithEncryption(self): self.packager.Package( self._GetStreams(['video'], @@ -511,6 +533,8 @@ class PackagerAppTest(unittest.TestCase): encryption=False, protection_scheme=None, decryption=False, + encryption_key='32333435363738393021323334353637', + encryption_iv='3334353637383930', random_iv=False, widevine_encryption=False, key_rotation=False, @@ -529,10 +553,15 @@ class PackagerAppTest(unittest.TestCase): elif encryption: flags += ['--enable_fixed_key_encryption', '--key_id=31323334353637383930313233343536', - '--key=32333435363738393021323334353637', '--clear_lead=1'] + '--clear_lead=1'] + if test_env.options.encryption_key: + encryption_key = test_env.options.encryption_key + flags.append('--key=' + encryption_key) if not random_iv: - flags.append('--iv=3334353637383930') + if test_env.options.encryption_iv: + encryption_iv = test_env.options.encryption_iv + flags.append('--iv=' + encryption_iv) if protection_scheme: flags += ['--protection_scheme', protection_scheme] diff --git a/packager/app/test/test_env.py b/packager/app/test/test_env.py index b1ad15c8e6..caa33f5e8b 100644 --- a/packager/app/test/test_env.py +++ b/packager/app/test/test_env.py @@ -27,6 +27,15 @@ SRC_DIR = os.path.join(SCRIPT_DIR, os.pardir, os.pardir) parser = argparse.ArgumentParser() parser.add_argument('--test_update_golden_files', default=0, type=int) +# Overwrite the test to encryption key/iv specified in the command line. +parser.add_argument('--encryption_key') +parser.add_argument('--encryption_iv') + +parser.add_argument('--remove_temp_files_after_test', + dest='remove_test_files_after_test', action='store_true') +parser.add_argument('--no-remove_temp_files_after_test', + dest='remove_temp_files_after_test', action='store_false') +parser.set_defaults(remove_temp_files_after_test=True) aes = parser.add_argument_group( 'aes flags', diff --git a/packager/app/test/testdata/sintel-1024x436-v-enc-golden-1.ts b/packager/app/test/testdata/sintel-1024x436-v-enc-golden-1.ts new file mode 100644 index 0000000000..9a71ce2969 Binary files /dev/null and b/packager/app/test/testdata/sintel-1024x436-v-enc-golden-1.ts differ diff --git a/packager/app/test/testdata/sintel-1024x436-v-enc-golden-2.ts b/packager/app/test/testdata/sintel-1024x436-v-enc-golden-2.ts new file mode 100644 index 0000000000..fe440e9b5d Binary files /dev/null and b/packager/app/test/testdata/sintel-1024x436-v-enc-golden-2.ts differ diff --git a/packager/app/test/testdata/sintel-1024x436-v-enc-golden-3.ts b/packager/app/test/testdata/sintel-1024x436-v-enc-golden-3.ts new file mode 100644 index 0000000000..b653e42ea7 Binary files /dev/null and b/packager/app/test/testdata/sintel-1024x436-v-enc-golden-3.ts differ diff --git a/packager/app/test/testdata/sintel-1024x436-v-enc-golden.m3u8 b/packager/app/test/testdata/sintel-1024x436-v-enc-golden.m3u8 new file mode 100644 index 0000000000..607904d24b --- /dev/null +++ b/packager/app/test/testdata/sintel-1024x436-v-enc-golden.m3u8 @@ -0,0 +1,20 @@ +#EXTM3U +#EXT-X-VERSION:6 +## Generated with https://github.com/google/shaka-packager version -- +#EXT-X-TARGETDURATION:2 +#EXT-X-PLAYLIST-TYPE:VOD +#EXTINF:1.000, +output_video-1.ts +#EXT-X-DISCONTINUITY +#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,MTIzNDU2Nzg5MDEyMzQ1Ng==",IV=0x3334353637383930,KEYFORMAT="identity" +#EXTINF:1.000, +output_video-2.ts +#EXTINF:1.875, +output_video-3.ts +#EXTINF:0.917, +output_video-4.ts +#EXTINF:1.000, +output_video-5.ts +#EXTINF:0.208, +output_video-6.ts +#EXT-X-ENDLIST diff --git a/packager/app/test/testdata/sintel-1024x436-v-enc-master-golden.m3u8 b/packager/app/test/testdata/sintel-1024x436-v-enc-master-golden.m3u8 new file mode 100644 index 0000000000..94e6cd0d57 --- /dev/null +++ b/packager/app/test/testdata/sintel-1024x436-v-enc-master-golden.m3u8 @@ -0,0 +1,4 @@ +#EXTM3U +## Generated with https://github.com/google/shaka-packager version -- +#EXT-X-STREAM-INF:CODECS="avc1.64001f",BANDWIDTH=1183948 +video.m3u8 diff --git a/packager/media/test/data/README b/packager/media/test/data/README index 78d7b3e899..dbe240e4ac 100644 --- a/packager/media/test/data/README +++ b/packager/media/test/data/README @@ -85,3 +85,5 @@ avc-unit-stream-frame.h264 - Single IDR frame from avc-byte-stream-frame.h264 co hevc-byte-stream-frame.h265 - Several video frames with SPS/PPS/VPS manually extracted from an H.265 stream, in Annex B byte stream format. hevc-byte-stream-frame.h265 - hevc-byte-stream-frame.h265 converted to unit stream format. + +sintel-1024x436.mp4 - First 6 seconds of Sintel stream. diff --git a/packager/media/test/data/sintel-1024x436.mp4 b/packager/media/test/data/sintel-1024x436.mp4 new file mode 100644 index 0000000000..f97d22421c Binary files /dev/null and b/packager/media/test/data/sintel-1024x436.mp4 differ