11package org .mp4parser .muxer ;
22
3+ import java .io .ByteArrayOutputStream ;
4+ import java .io .FileOutputStream ;
5+ import java .io .IOException ;
6+ import java .io .OutputStream ;
7+ import java .nio .channels .Channels ;
8+ import java .util .HashMap ;
9+ import java .util .Iterator ;
10+ import java .util .List ;
11+ import java .util .Map ;
12+ import java .util .UUID ;
13+
14+ import javax .crypto .SecretKey ;
15+ import javax .crypto .spec .SecretKeySpec ;
16+
317import org .junit .Assert ;
418import org .junit .Before ;
519import org .junit .Test ;
1428import org .mp4parser .tools .ByteBufferByteChannel ;
1529import org .mp4parser .tools .RangeStartMap ;
1630
17- import javax .crypto .SecretKey ;
18- import javax .crypto .spec .SecretKeySpec ;
19- import java .io .ByteArrayOutputStream ;
20- import java .io .FileOutputStream ;
21- import java .io .IOException ;
22- import java .nio .channels .Channels ;
23- import java .util .*;
24-
2531public class CencFileRoundtripTest {
26- private String baseDir = CencFileRoundtripTest .class .getProtectionDomain ().getCodeSource ().getLocation ().getFile ();
2732 private Map <UUID , SecretKey > keys ;
2833 private RangeStartMap <Integer , UUID > keyRotation1 ;
2934 private RangeStartMap <Integer , UUID > keyRotation2 ;
@@ -59,67 +64,67 @@ public void setUp() throws Exception {
5964
6065 @ Test
6166 public void testSingleKeysStdMp4_cbc1 () throws IOException {
62- testMultipleKeys (new DefaultMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cbc1" , false );
67+ testMultipleKeys (new DefaultMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cbc1" , false );
6368 }
6469
6570
6671 @ Test
6772 public void testSingleKeysFragMp4_cbc1 () throws IOException {
68- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cbc1" , false );
73+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cbc1" , false );
6974 }
7075
7176 @ Test
7277 public void testSingleKeysStdMp4_cenc () throws IOException {
73- testMultipleKeys (new DefaultMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cenc" , false );
78+ testMultipleKeys (new DefaultMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cenc" , false );
7479 }
7580
7681 @ Test
7782 public void testSingleKeysFragMp4_cenc () throws IOException {
78- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cenc" , false );
83+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation1 , "cenc" , false );
7984 }
8085
8186
8287 @ Test
8388 public void testClearLeadStdMp4_2_cbc1 () throws IOException {
84- testMultipleKeys (new DefaultMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cbc1" , false );
89+ testMultipleKeys (new DefaultMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cbc1" , false );
8590 }
8691
8792 @ Test
8893 public void testClearLeadFragMp4_2_cbc1 () throws IOException {
89- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cbc1" , false );
94+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cbc1" , false );
9095 }
9196
9297
9398 @ Test
9499 public void testClearLeadStdMp4_2_cenc () throws IOException {
95- testMultipleKeys (new DefaultMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cenc" , false );
100+ testMultipleKeys (new DefaultMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cenc" , false );
96101 }
97102
98103 @ Test
99104 public void testClearLeadFragMp4_2_cenc () throws IOException {
100- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cenc" , false );
105+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cenc" , false );
101106 }
102107
103108
104109 @ Test
105110 public void testMultipleKeysStdMp4_2_cbc1 () throws IOException {
106- testMultipleKeys (new DefaultMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cbc1" , false );
111+ testMultipleKeys (new DefaultMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cbc1" , false );
107112 }
108113
109114 @ Test
110115 public void testMultipleKeysFragMp4_2_cbc1 () throws IOException {
111- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cbc1" , false );
116+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cbc1" , false );
112117 }
113118
114119
115120 @ Test
116121 public void testMultipleKeysStdMp4_2_cenc () throws IOException {
117- testMultipleKeys (new DefaultMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cenc" , false );
122+ testMultipleKeys (new DefaultMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cenc" , false );
118123 }
119124
120125 @ Test
121126 public void testMultipleKeysFragMp4_2_cenc () throws IOException {
122- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cenc" , false );
127+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation3 , "cenc" , false );
123128 }
124129
125130
@@ -128,13 +133,14 @@ public void testMultipleKeysFragMp4_2_cenc() throws IOException {
128133
129134 @ Test
130135 public void testMultipleKeysFragMp4_2_cenc_pseudo_encrypted () throws IOException {
131- testMultipleKeys (new FragmentedMp4Builder (), baseDir + "/ BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cenc" , true );
136+ testMultipleKeys (new FragmentedMp4Builder (), " BBB_qpfile_10sec/BBB_fixedres_B_180x320_80.mp4" , keys , keyRotation2 , "cenc" , true );
132137 }
133138
134139 private void testMultipleKeys (Mp4Builder builder , String testFile , Map <UUID , SecretKey > keys ,
135140 RangeStartMap <Integer , UUID > keyRotation ,
136141 String encAlgo , boolean encryptButClear ) throws IOException {
137- Movie m1 = MovieCreator .build (testFile );
142+ String filePath = getClass ().getClassLoader ().getResource (testFile ).getPath ();
143+ Movie m1 = MovieCreator .build (filePath );
138144 Movie m2 = new Movie ();
139145 for (Track track : m1 .getTracks ()) {
140146 CencEncryptingTrackImpl cencEncryptingTrack =
@@ -145,7 +151,9 @@ private void testMultipleKeys(Mp4Builder builder, String testFile, Map<UUID, Sec
145151
146152 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
147153 c .writeContainer (Channels .newChannel (baos ));
148- new FileOutputStream ("m2.mp4" ).write (baos .toByteArray ());
154+ try (OutputStream os = new FileOutputStream ("m2.mp4" )) {
155+ os .write (baos .toByteArray ());
156+ }
149157
150158 Movie m3 = MovieCreator .build (
151159 new ByteBufferByteChannel (baos .toByteArray ()),
0 commit comments