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

Commit 5295e44d authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6185678 from dbaafe08 to rvc-release

Change-Id: I28faf094778eb51a198ede477299d078db74317c
parents d7810308 dbaafe08
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -84,4 +84,14 @@ interface IResourceManagerService {
     * @return true if the reclaim was successful and false otherwise.
     */
    boolean reclaimResource(int callingPid, in MediaResourceParcel[] resources);

    /**
     * Override the pid of original calling process with the pid of the process
     * who actually use the requested resources.
     *
     * @param originalPid pid of the original calling process.
     * @param newPid pid of the actual process who use the resources.
     *        remove existing override on originalPid if newPid is -1.
     */
    void overridePid(int originalPid, int newPid);
}
+19 −4
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.media.benchmark.tests;
import android.content.Context;
import android.media.MediaCodec;
import android.media.MediaFormat;

import static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Flexible;

import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
@@ -65,6 +68,7 @@ public class EncoderTest {
    private static final int ENCODE_DEFAULT_FRAME_RATE = 25;
    private static final int ENCODE_DEFAULT_BIT_RATE = 8000000 /* 8 Mbps */;
    private static final int ENCODE_MIN_BIT_RATE = 600000 /* 600 Kbps */;
    private static final int ENCODE_DEFAULT_AUDIO_BIT_RATE = 128000 /* 128 Kbps */;
    private String mInputFile;

    @Parameterized.Parameters
@@ -107,6 +111,7 @@ public class EncoderTest {
        int profile = 0;
        int level = 0;
        int frameRate = 0;

        //Parameters for audio
        int bitRate = 0;
        int sampleRate = 0;
@@ -122,6 +127,7 @@ public class EncoderTest {
        ArrayList<ByteBuffer> inputBuffer = new ArrayList<>();
        ArrayList<MediaCodec.BufferInfo> frameInfo = new ArrayList<>();
        for (int currentTrack = 0; currentTrack < trackCount; currentTrack++) {
            int colorFormat = COLOR_FormatYUV420Flexible;
            extractor.selectExtractorTrack(currentTrack);
            MediaFormat format = extractor.getFormat(currentTrack);
            // Get samples from extractor
@@ -148,6 +154,7 @@ public class EncoderTest {
            status = decoder.decode(inputBuffer, frameInfo, false, format, "");
            assertEquals("Decoder returned error " + status + " for file: " + mInputFile, 0,
                    status);
            MediaFormat decoderFormat = decoder.getFormat();
            decoder.deInitCodec();
            extractor.unselectExtractorTrack(currentTrack);
            inputBuffer.clear();
@@ -203,10 +210,17 @@ public class EncoderTest {
                        if (format.containsKey(MediaFormat.KEY_PROFILE)) {
                            level = format.getInteger(MediaFormat.KEY_LEVEL);
                        }
                        if (decoderFormat.containsKey(MediaFormat.KEY_COLOR_FORMAT)) {
                            colorFormat = decoderFormat.getInteger(MediaFormat.KEY_COLOR_FORMAT);
                        }
                    } else {
                        sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
                        numChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
                        bitRate = sampleRate * numChannels * 16;
                        if (decoderFormat.containsKey(MediaFormat.KEY_BIT_RATE)) {
                            bitRate = decoderFormat.getInteger(MediaFormat.KEY_BIT_RATE);
                        } else {
                            bitRate = ENCODE_DEFAULT_AUDIO_BIT_RATE;
                        }
                    }
                    /*Setup Encode Format*/
                    MediaFormat encodeFormat;
@@ -219,6 +233,7 @@ public class EncoderTest {
                        encodeFormat.setInteger(MediaFormat.KEY_LEVEL, level);
                        encodeFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
                        encodeFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, frameSize);
                        encodeFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
                    } else {
                        encodeFormat = MediaFormat.createAudioFormat(mime, sampleRate, numChannels);
                        encodeFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
@@ -255,7 +270,7 @@ public class EncoderTest {
        fileInput.close();
    }

    @Test
    @Test(timeout = PER_TEST_TIMEOUT_MS)
    public void testNativeEncoder() throws Exception {
        File inputFile = new File(mInputFilePath + mInputFile);
        assertTrue("Cannot find " + mInputFile + " in directory " + mInputFilePath,
@@ -275,8 +290,8 @@ public class EncoderTest {
            // Encoding the decoder's output
            for (String codecName : mediaCodecs) {
                Native nativeEncoder = new Native();
                int status = nativeEncoder.Encode(
                        mInputFilePath, mInputFile, mDecodedFile, mStatsFile, codecName);
                int status = nativeEncoder
                        .Encode(mInputFilePath, mInputFile, mDecodedFile, mStatsFile, codecName);
                assertEquals(
                        codecName + " encoder returned error " + status + " for " + "file:" + " " +
                                mInputFile, 0, status);
+26 −10
Original line number Diff line number Diff line
@@ -18,9 +18,9 @@
#define LOG_TAG "NativeEncoder"

#include <jni.h>
#include <sys/stat.h>
#include <fstream>
#include <iostream>
#include <sys/stat.h>

#include <android/log.h>

@@ -29,6 +29,11 @@

#include <stdio.h>

constexpr int32_t ENCODE_DEFAULT_FRAME_RATE = 25;
constexpr int32_t ENCODE_DEFAULT_AUDIO_BIT_RATE = 128000 /* 128 Kbps */;
constexpr int32_t ENCODE_DEFAULT_BIT_RATE = 8000000 /* 8 Mbps */;
constexpr int32_t ENCODE_MIN_BIT_RATE = 600000 /* 600 Kbps */;

extern "C" JNIEXPORT int JNICALL Java_com_android_media_benchmark_library_Native_Encode(
        JNIEnv *env, jobject thiz, jstring jFilePath, jstring jFileName, jstring jOutFilePath,
        jstring jStatsFile, jstring jCodecName) {
@@ -110,6 +115,8 @@ extern "C" JNIEXPORT int JNICALL Java_com_android_media_benchmark_library_Native
            free(inputBuffer);
            return -1;
        }

        AMediaFormat *decoderFormat = decoder->getFormat();
        AMediaFormat *format = extractor->getFormat();
        if (inputBuffer) {
            free(inputBuffer);
@@ -146,29 +153,34 @@ extern "C" JNIEXPORT int JNICALL Java_com_android_media_benchmark_library_Native
                AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_FRAME_RATE, &encParams.frameRate);
                AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_BIT_RATE, &encParams.bitrate);
                if (encParams.bitrate <= 0 || encParams.frameRate <= 0) {
                    encParams.frameRate = 25;
                    encParams.frameRate = ENCODE_DEFAULT_FRAME_RATE;
                    if (!strcmp(mime, "video/3gpp") || !strcmp(mime, "video/mp4v-es")) {
                        encParams.bitrate = 600000 /* 600 Kbps */;
                        encParams.bitrate = ENCODE_MIN_BIT_RATE /* 600 Kbps */;
                    } else {
                        encParams.bitrate = 8000000 /* 8 Mbps */;
                        encParams.bitrate = ENCODE_DEFAULT_BIT_RATE /* 8 Mbps */;
                    }
                }
                AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_PROFILE, &encParams.profile);
                AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_LEVEL, &encParams.level);
                AMediaFormat_getInt32(decoderFormat, AMEDIAFORMAT_KEY_COLOR_FORMAT,
                                      &encParams.colorFormat);
            } else {
                AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_SAMPLE_RATE, &encParams.sampleRate);
                AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_CHANNEL_COUNT,
                                      &encParams.numChannels);
                encParams.bitrate =
                        encParams.sampleRate * encParams.numChannels * 16 /* bitsPerSample */;
                encParams.bitrate = ENCODE_DEFAULT_AUDIO_BIT_RATE;
            }
            Encoder *encoder = new Encoder();
            encoder->setupEncoder();
            status = encoder->encode(sCodecName, eleStream, eleSize, asyncMode[i], encParams,
                                     (char *)mime);
            if (status != AMEDIA_OK) {
                ALOGE("Encoder returned error");
                return -1;
            }
            ALOGV("Encoding complete with codec %s for asyncMode = %d", sCodecName.c_str(),
                  asyncMode[i]);
            encoder->deInitCodec();
            cout << "codec : " << codecName << endl;
            ALOGV(" asyncMode = %d \n", asyncMode[i]);
            const char *statsFile = env->GetStringUTFChars(jStatsFile, nullptr);
            encoder->dumpStatistics(sInputReference, extractor->getClipDuration(), sCodecName,
                                    (asyncMode[i] ? "async" : "sync"), statsFile);
@@ -189,6 +201,10 @@ extern "C" JNIEXPORT int JNICALL Java_com_android_media_benchmark_library_Native
            AMediaFormat_delete(format);
            format = nullptr;
        }
        if (decoderFormat) {
            AMediaFormat_delete(decoderFormat);
            decoderFormat = nullptr;
        }
        decoder->deInitCodec();
        decoder->resetDecoder();
    }
+13 −7
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ public class Decoder {
                    mStats.addOutputTime();
                    onOutputAvailable(mediaCodec, outputBufferId, bufferInfo);
                    if (mSawOutputEOS) {
                        Log.i(TAG, "Saw output EOS");
                        synchronized (mLock) { mLock.notify(); }
                    }
                }
@@ -211,9 +210,6 @@ public class Decoder {
                    }
                    onOutputAvailable(mCodec, outputBufferId, outputBufferInfo);
                }
                if (outputBufferInfo.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) {
                    Log.i(TAG, "Saw output EOS");
                }
            }
        }
        mInputBuffer.clear();
@@ -256,14 +252,21 @@ public class Decoder {
     */
    public void resetDecoder() { mStats.reset(); }

    /**
     * Returns the format of the output buffers
     */
    public MediaFormat getFormat() {
        return mCodec.getOutputFormat();
    }

    private void onInputAvailable(int inputBufferId, MediaCodec mediaCodec) {
        if ((inputBufferId >= 0) && !mSawInputEOS) {
            ByteBuffer inputCodecBuffer = mediaCodec.getInputBuffer(inputBufferId);
            BufferInfo bufInfo = mInputBufferInfo.get(mIndex);
            inputCodecBuffer.put(mInputBuffer.get(mIndex).array());
            mIndex++;
            if (bufInfo.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) {
                mSawInputEOS = true;
            mSawInputEOS = (bufInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
            if (mSawInputEOS) {
                Log.i(TAG, "Saw input EOS");
            }
            mStats.addFrameSize(bufInfo.size);
@@ -301,6 +304,9 @@ public class Decoder {
            }
        }
        mediaCodec.releaseOutputBuffer(outputBufferId, false);
        mSawOutputEOS = (outputBufferInfo.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        mSawOutputEOS = (outputBufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
        if (mSawOutputEOS) {
            Log.i(TAG, "Saw output EOS");
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -260,12 +260,12 @@ public class Encoder {
        }
        mStats.addFrameSize(outputBuffer.remaining());
        mediaCodec.releaseOutputBuffer(outputBufferId, false);
        mSawOutputEOS = (outputBufferInfo.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        mSawOutputEOS = (outputBufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
    }

    private void onInputAvailable(MediaCodec mediaCodec, int inputBufferId) throws IOException {
        if (mSawOutputEOS || inputBufferId < 0) {
            if (mSawOutputEOS) {
        if (mSawInputEOS || inputBufferId < 0) {
            if (mSawInputEOS) {
                Log.i(TAG, "Saw input EOS");
            }
            return;
Loading