diff options
author | 2020-06-16 21:03:41 +0000 | |
---|---|---|
committer | 2020-06-16 21:03:41 +0000 | |
commit | 3db2e59e043d18c35f6689a466af846ced15f90c (patch) | |
tree | e50b8001152fc3c70fa27c34c4afc5c6394969f5 | |
parent | b51641316c321314372b299d739bb7a403ce7ff2 (diff) | |
parent | c4b07f6eae9ba55ac4abf117092891b4895ddd0c (diff) |
Merge "transcoding: Add tests for transcoding to internal/external storage."
-rw-r--r-- | media/tests/MediaTranscodingTest/src/com/android/mediatranscodingtest/MediaTranscodeManagerWithMockServiceTest.java | 176 |
1 files changed, 60 insertions, 116 deletions
diff --git a/media/tests/MediaTranscodingTest/src/com/android/mediatranscodingtest/MediaTranscodeManagerWithMockServiceTest.java b/media/tests/MediaTranscodingTest/src/com/android/mediatranscodingtest/MediaTranscodeManagerWithMockServiceTest.java index 6d1a85c6654d..748c21acebab 100644 --- a/media/tests/MediaTranscodingTest/src/com/android/mediatranscodingtest/MediaTranscodeManagerWithMockServiceTest.java +++ b/media/tests/MediaTranscodingTest/src/com/android/mediatranscodingtest/MediaTranscodeManagerWithMockServiceTest.java @@ -75,7 +75,6 @@ public class MediaTranscodeManagerWithMockServiceTest private MediaTranscodeManager mMediaTranscodeManager = null; private Uri mSourceHEVCVideoUri = null; private Uri mDestinationUri = null; - // Use mock transcoding service for testing the api. private MockTranscodingService mTranscodingService = null; @@ -224,7 +223,6 @@ public class MediaTranscodeManagerWithMockServiceTest super("com.android.MediaTranscodeManagerWithMockServiceTest", MediaTranscodingTest.class); } - private static Uri resourceToUri(Context context, int resId) { Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) @@ -374,22 +372,8 @@ public class MediaTranscodeManagerWithMockServiceTest }); } - // Tests transcoding from invalid a invalid and expects failure. - @Test - public void testTranscodingInvalidSrcUri() throws Exception { - Log.d(TAG, "Starting: testMediaTranscodeManager"); - - Uri invalidSrcUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" - + mContext.getPackageName() + "/source.mp4"); - Log.d(TAG, "Transcoding from source: " + invalidSrcUri); - - // Create a file Uri: file:///data/user/0/com.android.mediatranscodingtest/cache/temp.mp4 - // The full path of this file is: - // /data/user/0/com.android.mediatranscodingtest/cache/temp.mp4 - Uri destinationUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" - + mContext.getPackageName() + "/temp.mp4"); - Log.d(TAG, "Transcoding to destination: " + destinationUri); - + void testTranscodingWithExpectResult(Uri srcUri, Uri dstUri, int expectedResult) + throws Exception { Semaphore transcodeCompleteSemaphore = new Semaphore(0); TranscodingTestConfig testConfig = new TranscodingTestConfig(); testConfig.passThroughMode = true; @@ -397,8 +381,8 @@ public class MediaTranscodeManagerWithMockServiceTest TranscodingRequest request = new TranscodingRequest.Builder() - .setSourceUri(invalidSrcUri) - .setDestinationUri(destinationUri) + .setSourceUri(srcUri) + .setDestinationUri(dstUri) .setType(MediaTranscodeManager.TRANSCODING_TYPE_VIDEO) .setPriority(MediaTranscodeManager.PRIORITY_REALTIME) .setVideoTrackFormat(createMediaFormat()) @@ -410,7 +394,7 @@ public class MediaTranscodeManagerWithMockServiceTest transcodingJob -> { Log.d(TAG, "Transcoding completed with result: " + transcodingJob.getResult()); assertTrue("Transcoding should failed.", - transcodingJob.getResult() == TranscodingJob.RESULT_ERROR); + transcodingJob.getResult() == expectedResult); transcodeCompleteSemaphore.release(); }); assertNotNull(job); @@ -421,8 +405,35 @@ public class MediaTranscodeManagerWithMockServiceTest TRANSCODE_TIMEOUT_SECONDS, TimeUnit.SECONDS); assertTrue("Transcode failed to complete in time.", finishedOnTime); } + + if (expectedResult == TranscodingJob.RESULT_SUCCESS) { + // Checks the destination file get generated. + File file = new File(dstUri.getPath()); + assertTrue("Failed to create destination file", file.exists()); + + // Removes the file. + file.delete(); + } } + // Tests transcoding from invalid a invalid and expects failure. + @Test + public void testTranscodingInvalidSrcUri() throws Exception { + Log.d(TAG, "Starting: testMediaTranscodeManager"); + + Uri invalidSrcUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + + mContext.getPackageName() + "/source.mp4"); + Log.d(TAG, "Transcoding from source: " + invalidSrcUri); + + // Create a file Uri: file:///data/user/0/com.android.mediatranscodingtest/cache/temp.mp4 + // The full path of this file is: + // /data/user/0/com.android.mediatranscodingtest/cache/temp.mp4 + Uri destinationUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + + mContext.getPackageName() + "/temp.mp4"); + Log.d(TAG, "Transcoding to destination: " + destinationUri); + + testTranscodingWithExpectResult(invalidSrcUri, destinationUri, TranscodingJob.RESULT_ERROR); + } // Tests transcoding to a uri in res folder and expects failure as we could not write to res // folder. @@ -437,37 +448,8 @@ public class MediaTranscodeManagerWithMockServiceTest + mContext.getPackageName() + "/temp.mp4"); Log.d(TAG, "Transcoding to destination: " + destinationUri); - Semaphore transcodeCompleteSemaphore = new Semaphore(0); - TranscodingTestConfig testConfig = new TranscodingTestConfig(); - testConfig.passThroughMode = true; - testConfig.processingTotalTimeMs = 300; // minimum time spent on transcoding. - - TranscodingRequest request = - new TranscodingRequest.Builder() - .setSourceUri(mSourceHEVCVideoUri) - .setDestinationUri(destinationUri) - .setType(MediaTranscodeManager.TRANSCODING_TYPE_VIDEO) - .setPriority(MediaTranscodeManager.PRIORITY_REALTIME) - .setVideoTrackFormat(createMediaFormat()) - .setTestConfig(testConfig) - .build(); - Executor listenerExecutor = Executors.newSingleThreadExecutor(); - - TranscodingJob job = mMediaTranscodeManager.enqueueRequest(request, listenerExecutor, - transcodingJob -> { - Log.d(TAG, "Transcoding completed with result: " + transcodingJob.getResult()); - assertTrue("Transcoding should failed.", - transcodingJob.getResult() == TranscodingJob.RESULT_ERROR); - transcodeCompleteSemaphore.release(); - }); - assertNotNull(job); - - if (job != null) { - Log.d(TAG, "testMediaTranscodeManager - Waiting for transcode to complete."); - boolean finishedOnTime = transcodeCompleteSemaphore.tryAcquire( - TRANSCODE_TIMEOUT_SECONDS, TimeUnit.SECONDS); - assertTrue("Transcode failed to complete in time.", finishedOnTime); - } + testTranscodingWithExpectResult(mSourceHEVCVideoUri, destinationUri, + TranscodingJob.RESULT_ERROR); } // Tests transcoding to a uri in internal storage folder and expects success. @@ -481,79 +463,41 @@ public class MediaTranscodeManagerWithMockServiceTest Uri destinationUri = Uri.parse(ContentResolver.SCHEME_FILE + "://" + mContext.getCacheDir().getAbsolutePath() + "/temp.mp4"); - Semaphore transcodeCompleteSemaphore = new Semaphore(0); - TranscodingTestConfig testConfig = new TranscodingTestConfig(); - testConfig.passThroughMode = true; - testConfig.processingTotalTimeMs = 300; // minimum time spent on transcoding. - - TranscodingRequest request = - new TranscodingRequest.Builder() - .setSourceUri(mSourceHEVCVideoUri) - .setDestinationUri(destinationUri) - .setType(MediaTranscodeManager.TRANSCODING_TYPE_VIDEO) - .setPriority(MediaTranscodeManager.PRIORITY_REALTIME) - .setVideoTrackFormat(createMediaFormat()) - .setTestConfig(testConfig) - .build(); - Executor listenerExecutor = Executors.newSingleThreadExecutor(); - - TranscodingJob job = mMediaTranscodeManager.enqueueRequest(request, listenerExecutor, - transcodingJob -> { - Log.d(TAG, "Transcoding completed with result: " + transcodingJob.getResult()); - assertTrue("Transcoding failed.", - transcodingJob.getResult() == TranscodingJob.RESULT_SUCCESS); - transcodeCompleteSemaphore.release(); - }); - assertNotNull(job); + testTranscodingWithExpectResult(mSourceHEVCVideoUri, destinationUri, + TranscodingJob.RESULT_SUCCESS); + } - if (job != null) { - Log.d(TAG, "testMediaTranscodeManager - Waiting for transcode to complete."); - boolean finishedOnTime = transcodeCompleteSemaphore.tryAcquire( - TRANSCODE_TIMEOUT_SECONDS, TimeUnit.SECONDS); - assertTrue("Transcode failed to complete in time.", finishedOnTime); - } + // Tests transcoding to a uri in internal files directory and expects success. + @Test + public void testTranscodingToInternalFilesDir() throws Exception { + Log.d(TAG, "Starting: testMediaTranscodeManager"); - // Checks the destination file get generated. - File file = new File(destinationUri.getPath()); - assertTrue("Failed to create destination file", file.exists()); + // Create a file Uri: + // file:///storage/emulated/0/Android/data/com.android.mediatranscodingtest/files/temp.mp4 + Uri destinationUri = Uri.fromFile(new File(mContext.getFilesDir(), "temp.mp4")); + Log.i(TAG, "Transcoding to files dir: " + destinationUri); - // Removes the file. - file.delete(); + testTranscodingWithExpectResult(mSourceHEVCVideoUri, destinationUri, + TranscodingJob.RESULT_SUCCESS); } - + // Tests transcoding to a uri in external files directory and expects success. @Test - public void testTranscodingOneVideo() throws Exception { + public void testTranscodingToExternalFilesDir() throws Exception { Log.d(TAG, "Starting: testMediaTranscodeManager"); - Semaphore transcodeCompleteSemaphore = new Semaphore(0); - TranscodingTestConfig testConfig = new TranscodingTestConfig(); - testConfig.passThroughMode = true; - testConfig.processingTotalTimeMs = 300; // minimum time spent on transcoding. - - TranscodingRequest request = - new TranscodingRequest.Builder() - .setSourceUri(mSourceHEVCVideoUri) - .setDestinationUri(mDestinationUri) - .setType(MediaTranscodeManager.TRANSCODING_TYPE_VIDEO) - .setPriority(MediaTranscodeManager.PRIORITY_REALTIME) - .setVideoTrackFormat(createMediaFormat()) - .setTestConfig(testConfig) - .build(); - Executor listenerExecutor = Executors.newSingleThreadExecutor(); + // Create a file Uri: file:///data/user/0/com.android.mediatranscodingtest/files/temp.mp4 + Uri destinationUri = Uri.fromFile(new File(mContext.getExternalFilesDir(null), "temp.mp4")); + Log.i(TAG, "Transcoding to files dir: " + destinationUri); - TranscodingJob job = mMediaTranscodeManager.enqueueRequest(request, listenerExecutor, - transcodingJob -> { - Log.d(TAG, "Transcoding completed with result: "); - transcodeCompleteSemaphore.release(); - }); - assertNotNull(job); + testTranscodingWithExpectResult(mSourceHEVCVideoUri, destinationUri, + TranscodingJob.RESULT_SUCCESS); + } - if (job != null) { - Log.d(TAG, "testMediaTranscodeManager - Waiting for transcode to complete."); - boolean finishedOnTime = transcodeCompleteSemaphore.tryAcquire( - TRANSCODE_TIMEOUT_SECONDS, TimeUnit.SECONDS); - assertTrue("Transcode failed to complete in time.", finishedOnTime); - } + @Test + public void testTranscodingOneVideo() throws Exception { + Log.d(TAG, "Starting: testMediaTranscodeManager"); + testTranscodingWithExpectResult(mSourceHEVCVideoUri, mDestinationUri, + TranscodingJob.RESULT_SUCCESS); } } |