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

Commit 23906185 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Benchmark: Add support to configure encoders through test parameters"

parents 10685e62 487e4f5f
Loading
Loading
Loading
Loading
+197 −174
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.media.benchmark.library.Extractor;
import com.android.media.benchmark.library.Native;
import com.android.media.benchmark.library.Stats;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,40 +58,87 @@ import static org.junit.Assert.assertEquals;
public class EncoderTest {
    private static final Context mContext =
            InstrumentationRegistry.getInstrumentation().getTargetContext();
    private static final String mFileDirPath = mContext.getFilesDir() + "/";
    private static final String mInputFilePath = mContext.getString(R.string.input_file_path);
    private static final String mOutputFilePath = mContext.getString(R.string.output_file_path);
    private static final String mStatsFile =
            mContext.getExternalFilesDir(null) + "/Encoder." + System.currentTimeMillis() + ".csv";
    private static final String TAG = "EncoderTest";
    private static final long PER_TEST_TIMEOUT_MS = 120000;
    private static final boolean DEBUG = false;
    private static final boolean WRITE_OUTPUT = false;
    private static final long PER_TEST_TIMEOUT_MS = 120000;
    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_VIDEO_BIT_RATE = 8000000 /* 8 Mbps */;
    private static final int ENCODE_MIN_VIDEO_BIT_RATE = 600000 /* 600 Kbps */;
    private static final int ENCODE_DEFAULT_AUDIO_BIT_RATE = 128000 /* 128 Kbps */;
    private static int mColorFormat = COLOR_FormatYUV420Flexible;
    private static File mDecodedFileQcif;
    private static File mDecodedFileFullHd;
    private static File mDecodedFileAudio;
    private String mInputFile;
    private String mMime;
    private int mBitRate;
    private int mIFrameInterval;
    private int mWidth;
    private int mHeight;
    private int mProfile;
    private int mLevel;
    private int mSampleRate;
    private int mNumChannel;
    private static final String DECODE_FULLHD_INPUT = "crowd_1920x1080_25fps_4000kbps_h265.mkv";
    private static final String DECODE_QCIF_INPUT = "crowd_176x144_25fps_6000kbps_mpeg4.mp4";
    private static final String DECODE_AUDIO_INPUT = "bbb_48000hz_2ch_100kbps_opus_30sec.webm";
    private static final String DECODE_FULLHD_UNPACKED = "crowd_1920x1080_25fps_4000kbps_h265.yuv";
    private static final String DECODE_QCIF_UNPACKED = "crowd_176x144_25fps_6000kbps_mpeg4.yuv";
    private static final String DECODE_AUDIO_UNPACKED = "bbb_48000hz_2ch_100kbps_opus_30sec.raw";

    @Parameterized.Parameters
    public static Collection<Object[]> inputFiles() {
        return Arrays.asList(new Object[][]{
                // Audio Test
                {"bbb_44100hz_2ch_128kbps_aac_30sec.mp4"},
                {"bbb_8000hz_1ch_8kbps_amrnb_30sec.3gp"},
                {"bbb_16000hz_1ch_9kbps_amrwb_30sec.3gp"},
                {"bbb_44100hz_2ch_600kbps_flac_30sec.mp4"},
                {"bbb_48000hz_2ch_100kbps_opus_30sec.webm"},
                // Parameters: Filename, mimeType, bitrate, width, height, iFrameInterval,
                // profile, level, sampleRate, channelCount
                {DECODE_AUDIO_UNPACKED, MediaFormat.MIMETYPE_AUDIO_AAC,
                        ENCODE_DEFAULT_AUDIO_BIT_RATE, -1, -1, -1, -1, -1, 44100, 2},
                {DECODE_AUDIO_UNPACKED, MediaFormat.MIMETYPE_AUDIO_AMR_NB,
                        ENCODE_DEFAULT_AUDIO_BIT_RATE, -1, -1, -1, -1, -1, 8000, 1},
                {DECODE_AUDIO_UNPACKED, MediaFormat.MIMETYPE_AUDIO_AMR_WB,
                        ENCODE_DEFAULT_AUDIO_BIT_RATE, -1, -1, -1, -1, -1, 16000, 1},
                {DECODE_AUDIO_UNPACKED, MediaFormat.MIMETYPE_AUDIO_FLAC,
                        ENCODE_DEFAULT_AUDIO_BIT_RATE, -1, -1, -1, -1, -1, 44100, 2},
                {DECODE_AUDIO_UNPACKED, MediaFormat.MIMETYPE_AUDIO_OPUS,
                        ENCODE_DEFAULT_AUDIO_BIT_RATE, -1, -1, -1, -1, -1, 48000, 2},

                // Video Test
                {"crowd_1920x1080_25fps_4000kbps_vp8.webm"},
                {"crowd_1920x1080_25fps_6700kbps_h264.ts"},
                {"crowd_1920x1080_25fps_4000kbps_h265.mkv"},
                {"crowd_1920x1080_25fps_4000kbps_vp9.webm"},
                {"crowd_176x144_25fps_6000kbps_mpeg4.mp4"},
                {"crowd_176x144_25fps_6000kbps_h263.3gp"}});
                // Parameters: Filename, mimeType, bitrate, width, height, iFrameInterval,
                // profile, level, sampleRate, channelCount
                {DECODE_FULLHD_UNPACKED, MediaFormat.MIMETYPE_VIDEO_VP8,
                        ENCODE_DEFAULT_VIDEO_BIT_RATE, 1920, 1080, 1, -1, -1, -1, -1},
                {DECODE_FULLHD_UNPACKED, MediaFormat.MIMETYPE_VIDEO_AVC,
                        ENCODE_DEFAULT_VIDEO_BIT_RATE, 1920, 1080, 1, -1, -1, -1, -1},
                {DECODE_FULLHD_UNPACKED, MediaFormat.MIMETYPE_VIDEO_HEVC,
                        ENCODE_DEFAULT_VIDEO_BIT_RATE, 1920, 1080, 1, -1, -1, -1, -1},
                {DECODE_FULLHD_UNPACKED, MediaFormat.MIMETYPE_VIDEO_VP9,
                        ENCODE_DEFAULT_VIDEO_BIT_RATE, 1920, 1080, 1, -1, -1, -1, -1},
                {DECODE_QCIF_UNPACKED, MediaFormat.MIMETYPE_VIDEO_MPEG4, ENCODE_MIN_VIDEO_BIT_RATE,
                        176, 144, 1, -1, -1, -1, -1},
                {DECODE_QCIF_UNPACKED, MediaFormat.MIMETYPE_VIDEO_H263, ENCODE_MIN_VIDEO_BIT_RATE,
                        176, 144, 1, -1, -1, -1, -1}});
    }

    public EncoderTest(String inputFileName) {
        this.mInputFile = inputFileName;
    public EncoderTest(String filename, String mime, int bitrate, int width, int height,
                       int frameInterval, int profile, int level, int samplerate,
                       int channelCount) {
        this.mInputFile = filename;
        this.mMime = mime;
        this.mBitRate = bitrate;
        this.mIFrameInterval = frameInterval;
        this.mWidth = width;
        this.mHeight = height;
        this.mProfile = profile;
        this.mLevel = level;
        this.mSampleRate = samplerate;
        this.mNumChannel = channelCount;
    }

    @BeforeClass
@@ -101,33 +149,36 @@ public class EncoderTest {
        Log.d(TAG, "Saving Benchmark results in: " + mStatsFile);
    }

    @Test(timeout = PER_TEST_TIMEOUT_MS)
    public void testEncoder() throws Exception {
        int status;
        int frameSize;
        //Parameters for video
        int width = 0;
        int height = 0;
        int profile = 0;
        int level = 0;
        int frameRate = 0;
    @BeforeClass
    public static void prepareInput() throws IOException {

        mDecodedFileFullHd = new File(mFileDirPath + DECODE_FULLHD_UNPACKED);
        int status = decodeFile(mInputFilePath + DECODE_FULLHD_INPUT, mDecodedFileFullHd);
        assertEquals("Decoder returned error " + status, 0, status);

        //Parameters for audio
        int bitRate = 0;
        int sampleRate = 0;
        int numChannels = 0;
        File inputFile = new File(mInputFilePath + mInputFile);
        assertTrue("Cannot find " + mInputFile + " in directory " + mInputFilePath,
                inputFile.exists());
        mDecodedFileQcif = new File(mFileDirPath + DECODE_QCIF_UNPACKED);
        status = decodeFile(mInputFilePath + DECODE_QCIF_INPUT, mDecodedFileQcif);
        assertEquals("Decoder returned error " + status, 0, status);

        mDecodedFileAudio = new File(mFileDirPath + DECODE_AUDIO_UNPACKED);
        status = decodeFile(mInputFilePath + DECODE_AUDIO_INPUT, mDecodedFileAudio);
        assertEquals("Decoder returned error " + status, 0, status);
    }

    private static int decodeFile(String inputFileName, File outputDecodeFile) throws IOException {
        int status = -1;
        File inputFile = new File(inputFileName);
        assertTrue("Cannot open input file " + inputFileName, inputFile.exists());
        FileInputStream fileInput = new FileInputStream(inputFile);
        FileDescriptor fileDescriptor = fileInput.getFD();
        FileOutputStream decodeOutputStream = new FileOutputStream(outputDecodeFile);

        Extractor extractor = new Extractor();
        int trackCount = extractor.setUpExtractor(fileDescriptor);
        assertTrue("Extraction failed. No tracks for file: " + mInputFile, (trackCount > 0));
        assertTrue("Extraction failed. No tracks for the given input file", (trackCount > 0));
        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
@@ -146,28 +197,33 @@ public class EncoderTest {
                            bufInfo.presentationTimeUs + " size = " + bufInfo.size);
                }
            } while (sampleSize > 0);
            int tid = android.os.Process.myTid();
            File decodedFile = new File(mContext.getFilesDir() + "/decoder_" + tid + ".out");
            FileOutputStream decodeOutputStream = new FileOutputStream(decodedFile);
            Decoder decoder = new Decoder();
            decoder.setupDecoder(decodeOutputStream);
            status = decoder.decode(inputBuffer, frameInfo, false, format, "");
            assertEquals("Decoder returned error " + status + " for file: " + mInputFile, 0,
                    status);
            MediaFormat decoderFormat = decoder.getFormat();
            if (decoderFormat.containsKey(MediaFormat.KEY_COLOR_FORMAT)) {
                mColorFormat = decoderFormat.getInteger(MediaFormat.KEY_COLOR_FORMAT);
            }
            decoder.deInitCodec();
            extractor.unselectExtractorTrack(currentTrack);
            inputBuffer.clear();
            frameInfo.clear();
            if (decodeOutputStream != null) {
        }
        extractor.deinitExtractor();
        fileInput.close();
        decodeOutputStream.close();
        return status;
    }
            String mime = format.getString(MediaFormat.KEY_MIME);
            ArrayList<String> mediaCodecs = CodecUtils.selectCodecs(mime, true);
            assertTrue("No suitable codecs found for file: " + mInputFile + " track : " +
                    currentTrack + " mime: " + mime, (mediaCodecs.size() > 0));

    @Test(timeout = PER_TEST_TIMEOUT_MS)
    public void testEncoder() throws Exception {
        int status;
        int frameSize;

        ArrayList<String> mediaCodecs = CodecUtils.selectCodecs(mMime, true);
        assertTrue("No suitable codecs found for mimetype: " + mMime, (mediaCodecs.size() > 0));
        Boolean[] encodeMode = {true, false};
            /* Encoding the decoder's output */
        // Encoding the decoded input file
        for (Boolean asyncMode : encodeMode) {
            for (String codecName : mediaCodecs) {
                FileOutputStream encodeOutputStream = null;
@@ -181,128 +237,95 @@ public class EncoderTest {
                            outEncodeFile.toString(), outEncodeFile.createNewFile());
                    encodeOutputStream = new FileOutputStream(outEncodeFile);
                }
                    File rawFile = new File(mContext.getFilesDir() + "/decoder_" + tid + ".out");
                    assertTrue("Cannot open file to write decoded output", rawFile.exists());
                File rawFile = new File(mFileDirPath + mInputFile);
                assertTrue("Cannot open decoded input file", rawFile.exists());
                if (DEBUG) {
                    Log.i(TAG, "Path of decoded input file: " + rawFile.toString());
                }
                FileInputStream eleStream = new FileInputStream(rawFile);
                    if (mime.startsWith("video/")) {
                        width = format.getInteger(MediaFormat.KEY_WIDTH);
                        height = format.getInteger(MediaFormat.KEY_HEIGHT);
                        if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
                            frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
                        } else if (frameRate <= 0) {
                            frameRate = ENCODE_DEFAULT_FRAME_RATE;
                        }
                        if (format.containsKey(MediaFormat.KEY_BIT_RATE)) {
                            bitRate = format.getInteger(MediaFormat.KEY_BIT_RATE);
                        } else if (bitRate <= 0) {
                            if (mime.contains("video/3gpp") || mime.contains("video/mp4v-es")) {
                                bitRate = ENCODE_MIN_BIT_RATE;
                            } else {
                                bitRate = ENCODE_DEFAULT_BIT_RATE;
                            }
                        }
                        if (format.containsKey(MediaFormat.KEY_PROFILE)) {
                            profile = format.getInteger(MediaFormat.KEY_PROFILE);
                        }
                        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);
                        if (decoderFormat.containsKey(MediaFormat.KEY_BIT_RATE)) {
                            bitRate = decoderFormat.getInteger(MediaFormat.KEY_BIT_RATE);
                        } else {
                            bitRate = ENCODE_DEFAULT_AUDIO_BIT_RATE;
                        }
                    }
                    /*Setup Encode Format*/
                // Setup Encode Format
                MediaFormat encodeFormat;
                    if (mime.startsWith("video/")) {
                        frameSize = width * height * 3 / 2;
                        encodeFormat = MediaFormat.createVideoFormat(mime, width, height);
                        encodeFormat.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
                        encodeFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
                        encodeFormat.setInteger(MediaFormat.KEY_PROFILE, profile);
                        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);
                if (mMime.startsWith("video/")) {
                    frameSize = mWidth * mHeight * 3 / 2;
                    encodeFormat = MediaFormat.createVideoFormat(mMime, mWidth, mHeight);
                    encodeFormat.setInteger(MediaFormat.KEY_FRAME_RATE, ENCODE_DEFAULT_FRAME_RATE);
                    encodeFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, mIFrameInterval);
                    encodeFormat.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
                    encodeFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, mColorFormat);
                    if (mProfile != -1 && mLevel != -1) {
                        encodeFormat.setInteger(MediaFormat.KEY_PROFILE, mProfile);
                        encodeFormat.setInteger(MediaFormat.KEY_LEVEL, mLevel);
                    }
                } else {
                        encodeFormat = MediaFormat.createAudioFormat(mime, sampleRate, numChannels);
                        encodeFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
                    frameSize = 4096;
                    encodeFormat = MediaFormat.createAudioFormat(mMime, mSampleRate, mNumChannel);
                    encodeFormat.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
                }
                Encoder encoder = new Encoder();
                encoder.setupEncoder(encodeOutputStream, eleStream);
                    status = encoder.encode(codecName, encodeFormat, mime, frameRate, sampleRate,
                            frameSize, asyncMode);
                status = encoder.encode(codecName, encodeFormat, mMime, ENCODE_DEFAULT_FRAME_RATE,
                        mSampleRate, frameSize, asyncMode);
                encoder.deInitEncoder();
                assertEquals(
                            codecName + " encoder returned error " + status + " for " + "file:" +
                                    " " + mInputFile, 0, status);
                    encoder.dumpStatistics(mInputFile, codecName, (asyncMode ? "async" : "sync"),
                            extractor.getClipDuration(), mStatsFile);
                    Log.i(TAG, "Encoding complete for file: " + mInputFile + " with codec: " +
                            codecName + " for aSyncMode = " + asyncMode);
                        codecName + " encoder returned error " + status + " for " + "mime:" + " " +
                                mMime, 0, status);
                String inputReference;
                long durationUs;
                if (mMime.startsWith("video/")) {
                    inputReference =
                            mInputFile + "_" + mWidth + "x" + mHeight + "_" + mBitRate + "bps";
                    durationUs = (((eleStream.getChannel().size() + frameSize - 1) / frameSize) /
                            ENCODE_DEFAULT_FRAME_RATE) * 1000000;
                } else {
                    inputReference = mInputFile + "_" + mSampleRate + "hz_" + mNumChannel + "ch_" +
                            mBitRate + "bps";
                    durationUs =
                            (eleStream.getChannel().size() / (mSampleRate * mNumChannel)) * 1000000;
                }
                encoder.dumpStatistics(inputReference, codecName, (asyncMode ? "async" : "sync"),
                        durationUs, mStatsFile);
                Log.i(TAG, "Encoding complete for mime: " + mMime + " with codec: " + codecName +
                        " for aSyncMode = " + asyncMode);
                encoder.resetEncoder();
                eleStream.close();
                if (encodeOutputStream != null) {
                    encodeOutputStream.close();
                }

                }
            }
            //Cleanup temporary input file
            if (decodedFile.exists()) {
                assertTrue(" Unable to delete decoded file" + decodedFile.toString(),
                        decodedFile.delete());
                Log.i(TAG, "Successfully deleted decoded file");
            }
        }
        extractor.deinitExtractor();
        fileInput.close();
    }

    @Test(timeout = PER_TEST_TIMEOUT_MS)
    public void testNativeEncoder() throws Exception {
        File inputFile = new File(mInputFilePath + mInputFile);
        assertTrue("Cannot find " + mInputFile + " in directory " + mInputFilePath,
                inputFile.exists());
        int tid = android.os.Process.myTid();
        final String mDecodedFile = mContext.getFilesDir() + "/decoder_" + tid + ".out";
        FileInputStream fileInput = new FileInputStream(inputFile);
        FileDescriptor fileDescriptor = fileInput.getFD();
        Extractor extractor = new Extractor();
        int trackCount = extractor.setUpExtractor(fileDescriptor);
        assertTrue("Extraction failed. No tracks for file: ", trackCount > 0);
        for (int currentTrack = 0; currentTrack < trackCount; currentTrack++) {
            extractor.selectExtractorTrack(currentTrack);
            MediaFormat format = extractor.getFormat(currentTrack);
            String mime = format.getString(MediaFormat.KEY_MIME);
            ArrayList<String> mediaCodecs = CodecUtils.selectCodecs(mime, true);
            // Encoding the decoder's output
    public void testNativeEncoder() {
        ArrayList<String> mediaCodecs = CodecUtils.selectCodecs(mMime, true);
        assertTrue("No suitable codecs found for mimetype: " + mMime, (mediaCodecs.size() > 0));
        for (String codecName : mediaCodecs) {
            Native nativeEncoder = new Native();
            int status = nativeEncoder
                        .Encode(mInputFilePath, mInputFile, mDecodedFile, mStatsFile, codecName);
                assertEquals(
                        codecName + " encoder returned error " + status + " for " + "file:" + " " +
                                mInputFile, 0, status);
                    .Encode(mFileDirPath, mInputFile, mStatsFile, codecName, mMime, mBitRate,
                            mColorFormat, mIFrameInterval, mWidth, mHeight, mProfile, mLevel,
                            mSampleRate, mNumChannel);
            assertEquals(codecName + " encoder returned error " + status + " for " + "mime:" + " " +
                    mMime, 0, status);
        }
    }
        File decodedFile = new File(mDecodedFile);
        // Cleanup temporary input file
        if (decodedFile.exists()) {
            assertTrue("Unable to delete - " + mDecodedFile, decodedFile.delete());
            Log.i(TAG, "Successfully deleted - " + mDecodedFile);

    @AfterClass
    public static void deleteDecodedFiles() {
        if (mDecodedFileFullHd.exists()) {
            assertTrue(" Unable to delete decoded file" + mDecodedFileFullHd.toString(),
                    mDecodedFileFullHd.delete());
            Log.i(TAG, "Successfully deleted decoded file" + mDecodedFileFullHd.toString());
        }
        if (mDecodedFileQcif.exists()) {
            assertTrue(" Unable to delete decoded file" + mDecodedFileQcif.toString(),
                    mDecodedFileQcif.delete());
            Log.i(TAG, "Successfully deleted decoded file" + mDecodedFileQcif.toString());
        }
        if (mDecodedFileAudio.exists()) {
            assertTrue(" Unable to delete decoded file" + mDecodedFileAudio.toString(),
                    mDecodedFileAudio.delete());
            Log.i(TAG, "Successfully deleted decoded file" + mDecodedFileAudio.toString());
        }
        fileInput.close();
    }
}
+61 −169

File changed.

Preview size limit exceeded, changes collapsed.

+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ public class Native {
    public native int Decode(String inputFilePath, String inputFileName, String statsFile,
            String codecName, boolean asyncMode);

    public native int Encode(String inputFilePath, String inputFileName, String outputFilePath,
            String statsFile, String codecName);
    public native int Encode(String inputFilePath, String inputFileName, String statsFile,
            String codecName, String mime, int bitRate, int colorFormat, int frameInterval,
            int width, int height, int profile, int level, int sampleRate, int numChannel);
}
+3 −3
Original line number Diff line number Diff line
@@ -203,13 +203,13 @@ int32_t Encoder::encode(string &codecName, ifstream &eleStream, size_t eleSize,
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_WIDTH, mParams.width);
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_HEIGHT, mParams.height);
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_FRAME_RATE, mParams.frameRate);
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, mParams.iFrameInterval);
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_BIT_RATE, mParams.bitrate);
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, 1);
        if (mParams.profile && mParams.level) {
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_COLOR_FORMAT, mParams.colorFormat);
        if (mParams.profile != -1 && mParams.level != -1) {
            AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_PROFILE, mParams.profile);
            AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_LEVEL, mParams.level);
        }
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_COLOR_FORMAT, mParams.colorFormat);
    } else {
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_SAMPLE_RATE, mParams.sampleRate);
        AMediaFormat_setInt32(mFormat, AMEDIAFORMAT_KEY_CHANNEL_COUNT, mParams.numChannels);
+6 −4
Original line number Diff line number Diff line
@@ -23,10 +23,11 @@
#include <queue>
#include <thread>

#include "media/NdkImage.h"
#include "BenchmarkCommon.h"
#include "Stats.h"

// constant not defined in NDK api
constexpr int32_t COLOR_FormatYUV420Flexible = 0x7F420888;

struct encParameter {
    int32_t bitrate = -1;
@@ -38,9 +39,10 @@ struct encParameter {
    int32_t width = 0;
    int32_t height = 0;
    int32_t frameRate = -1;
    int32_t profile = 0;
    int32_t level = 0;
    int32_t colorFormat = AIMAGE_FORMAT_YUV_420_888;
    int32_t iFrameInterval = 0;
    int32_t profile = -1;
    int32_t level = -1;
    int32_t colorFormat = COLOR_FormatYUV420Flexible;
};

class Encoder : public CallBackHandle {
Loading