Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19ca683f authored by Hangyu Kuang's avatar Hangyu Kuang Committed by Android (Google) Code Review
Browse files

Merge "Transcoding: Bring up first real transcoding with Java API."

parents 4cb8c983 cfdbc0d3
Loading
Loading
Loading
Loading

1

0 → 100644
+21 −0
Original line number Diff line number Diff line
transcoding: Add tests for transcoding to internal/external storage.

Bug: 145628554
Test: unit testing

Change-Id: If0a75ba3101c7d9261ccae95f8b82f8b41704592

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Jun 15 15:44:21 2020 -0700
# Committer: hkuang <hkuang@google.com>
#
# On branch drv6
# Your branch and 'goog/master' have diverged,
# and have 1 and 29 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
#	modified:   media/tests/MediaTranscodingTest/src/com/android/mediatranscodingtest/MediaTranscodeManagerWithMockServiceTest.java
#
+31 −0
Original line number Diff line number Diff line
#!/bin/bash
#
# Run tests in this directory.
#

if [ -z "$ANDROID_BUILD_TOP" ]; then
    echo "Android build environment not set"
    exit -1
fi

# ensure we have mm
. $ANDROID_BUILD_TOP/build/envsetup.sh

mm

# Push the files onto the device.
. $ANDROID_BUILD_TOP/frameworks/av/media/libmediatranscoding/tests/assets/push_assets.sh

echo "[==========] waiting for device"
adb root && adb wait-for-device remount

echo "[==========] set to use real transcoder"
adb shell setprop debug.transcoding.simulated_transcoder false;
adb shell kill -9 `pid media.transcoding`

echo "[==========] build test apk"
mmm -j16 .
adb install -r -g ${OUT}/testcases/mediatranscodingtest/arm64/mediatranscodingtest.apk

echo "[==========] running real transcoding tests"
adb shell am instrument -e class com.android.mediatranscodingtest.MediaTranscodeManagerTest -w com.android.mediatranscodingtest/.MediaTranscodingTestRunner
+803 KiB

File added.

No diff preview for this file type.

+108 KiB

File added.

No diff preview for this file type.

+36 −12
Original line number Diff line number Diff line
@@ -22,14 +22,17 @@ import android.media.MediaFormat;
import android.media.MediaTranscodeManager;
import android.media.MediaTranscodeManager.TranscodingJob;
import android.media.MediaTranscodeManager.TranscodingRequest;
import android.media.TranscodingTestConfig;
import android.net.Uri;
import android.os.FileUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
@@ -59,6 +62,7 @@ public class MediaTranscodeManagerTest
    private Context mContext;
    private MediaTranscodeManager mMediaTranscodeManager = null;
    private Uri mSourceHEVCVideoUri = null;
    private Uri mSourceAVCVideoUri = null;
    private Uri mDestinationUri = null;

    // Setting for transcoding to H.264.
@@ -72,14 +76,24 @@ public class MediaTranscodeManagerTest
    }


    private static Uri resourceToUri(Context context, int resId) {
        Uri uri = new Uri.Builder()
    // Copy the resource to cache.
    private Uri resourceToUri(Context context, int resId, String name) throws IOException {
        Uri resUri = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
                .authority(context.getResources().getResourcePackageName(resId))
                .appendPath(context.getResources().getResourceTypeName(resId))
                .appendPath(context.getResources().getResourceEntryName(resId))
                .build();
        return uri;

        Uri cacheUri = Uri.parse(ContentResolver.SCHEME_FILE + "://"
                + mContext.getCacheDir().getAbsolutePath() + "/" + name);

        InputStream is = mContext.getResources().openRawResource(resId);
        OutputStream os = mContext.getContentResolver().openOutputStream(cacheUri);

        FileUtils.copy(is, os);

        return cacheUri;
    }

    private static Uri generateNewUri(Context context, String filename) {
@@ -111,7 +125,11 @@ public class MediaTranscodeManagerTest
        assertNotNull(mMediaTranscodeManager);

        // Setup source HEVC file uri.
        mSourceHEVCVideoUri = resourceToUri(mContext, R.raw.VideoOnlyHEVC);
        mSourceHEVCVideoUri = resourceToUri(mContext, R.raw.VideoOnlyHEVC, "VideoOnlyHEVC.mp4");

        // Setup source AVC file uri.
        mSourceAVCVideoUri = resourceToUri(mContext, R.raw.VideoOnlyAVC,
                "VideoOnlyAVC.mp4");

        // Setup destination file.
        mDestinationUri = generateNewUri(mContext, "transcoded.mp4");
@@ -123,22 +141,26 @@ public class MediaTranscodeManagerTest
    }

    @Test
    public void testTranscodingOneVideo() throws Exception {
    public void testTranscodingFromAvcToAvc() 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.

        // 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_FILE + "://"
                + mContext.getCacheDir().getAbsolutePath() + "/temp.mp4");

        Log.d(TAG, "Transcoding to " + destinationUri.getPath());

        TranscodingRequest request =
                new TranscodingRequest.Builder()
                        .setSourceUri(mSourceHEVCVideoUri)
                        .setDestinationUri(mDestinationUri)
                        .setSourceUri(mSourceAVCVideoUri)
                        .setDestinationUri(destinationUri)
                        .setType(MediaTranscodeManager.TRANSCODING_TYPE_VIDEO)
                        .setPriority(MediaTranscodeManager.PRIORITY_REALTIME)
                        .setVideoTrackFormat(createMediaFormat())
                        .setTestConfig(testConfig)
                        .build();
        Executor listenerExecutor = Executors.newSingleThreadExecutor();

@@ -156,6 +178,8 @@ public class MediaTranscodeManagerTest
                    TRANSCODE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            assertTrue("Transcode failed to complete in time.", finishedOnTime);
        }

        //TODO(hkuang): Verify the transcoded video's psnr to make sure it is correct.
    }

}