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

Commit 3da47b3b authored by Rakesh Kumar's avatar Rakesh Kumar Committed by android-build-merger
Browse files

Merge "Benchmark: add Muxer" am: 47f98f62 am: 63ef1152 am: 1a10f576

am: ea3445f4

Change-Id: I97205c6f2cc4b96f1d809de18e2fd2ddc2e42aa0
parents fd77d057 ea3445f4
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -38,3 +38,13 @@ Setup steps are same as extractor.
```
adb shell /data/local/tmp/decoderTest -P /sdcard/res/
```

## Muxer

The test muxes elementary stream and benchmarks the muxers available in NDK.

Setup steps are same as extractor.

```
adb shell /data/local/tmp/muxerTest -P /sdcard/res/
```
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

cc_library_static {
    name: "libbenchmark_muxer",
    defaults: [
        "libbenchmark_common-defaults",
        "libbenchmark_soft_sanitize_all-defaults",
    ],

    srcs: ["Muxer.cpp"],

    static_libs: ["libbenchmark_extractor"],

    export_include_dirs: ["."],

    ldflags: ["-Wl,-Bsymbolic"]
}
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "muxer"

#include <fstream>
#include <iostream>

#include "Muxer.h"

int32_t Muxer::initMuxer(int32_t fd, MUXER_OUTPUT_T outputFormat) {
    if (!mFormat) mFormat = mExtractor->getFormat();
    if (!mTimer) mTimer = new Timer();

    int64_t sTime = mTimer->getCurTime();
    mMuxer = AMediaMuxer_new(fd, (OutputFormat)outputFormat);
    if (!mMuxer) {
        cout << "[   WARN   ] Test Skipped. Unable to create muxer \n";
        return AMEDIA_ERROR_INVALID_OBJECT;
    }
    /*
     * AMediaMuxer_addTrack returns the index of the new track or a negative value
     * in case of failure, which can be interpreted as a media_status_t.
     */
    ssize_t index = AMediaMuxer_addTrack(mMuxer, mFormat);
    if (index < 0) {
        cout << "[   WARN   ] Test Skipped. Format not supported \n";
        return index;
    }
    AMediaMuxer_start(mMuxer);
    int64_t eTime = mTimer->getCurTime();
    int64_t timeTaken = mTimer->getTimeDiff(sTime, eTime);
    mTimer->setInitTime(timeTaken);
    return AMEDIA_OK;
}

void Muxer::deInitMuxer() {
    int64_t sTime = mTimer->getCurTime();
    if (mFormat) {
        AMediaFormat_delete(mFormat);
        mFormat = nullptr;
    }
    if (!mMuxer) return;
    AMediaMuxer_stop(mMuxer);
    AMediaMuxer_delete(mMuxer);
    int64_t eTime = mTimer->getCurTime();
    int64_t timeTaken = mTimer->getTimeDiff(sTime, eTime);
    mTimer->setDeInitTime(timeTaken);
}

void Muxer::resetMuxer() {
    if (mTimer) mTimer->resetTimers();
}

void Muxer::dumpStatistics(string inputReference) {
    string operation = "mux";
    mTimer->dumpStatistics(operation, inputReference, mExtractor->getClipDuration());
}

int32_t Muxer::mux(uint8_t *inputBuffer, vector<AMediaCodecBufferInfo> &frameInfos) {
    // Mux frame data
    size_t frameIdx = 0;
    mTimer->setStartTime();
    while (frameIdx < frameInfos.size()) {
        AMediaCodecBufferInfo info = frameInfos.at(frameIdx);
        media_status_t status = AMediaMuxer_writeSampleData(mMuxer, 0, inputBuffer, &info);
        if (status != 0) {
            ALOGE("Error in AMediaMuxer_writeSampleData");
            return status;
        }
        mTimer->addOutputTime();
        frameIdx++;
    }
    return AMEDIA_OK;
}
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __MUXER_H__
#define __MUXER_H__

#include <media/NdkMediaMuxer.h>

#include "BenchmarkCommon.h"
#include "Timer.h"
#include "Extractor.h"

typedef enum {
    MUXER_OUTPUT_FORMAT_MPEG_4 = 0,
    MUXER_OUTPUT_FORMAT_WEBM = 1,
    MUXER_OUTPUT_FORMAT_3GPP = 2,
    MUXER_OUTPUT_FORMAT_OGG = 4,
    MUXER_OUTPUT_FORMAT_INVALID = 5,
} MUXER_OUTPUT_T;

class Muxer {
  public:
    Muxer() : mFormat(nullptr), mMuxer(nullptr), mTimer(nullptr) { mExtractor = new Extractor(); }

    virtual ~Muxer() {
        if (mTimer) delete mTimer;
        if (mExtractor) delete mExtractor;
    }

    Timer *getTimer() { return mTimer; }
    Extractor *getExtractor() { return mExtractor; }

    /* Muxer related utilities */
    int32_t initMuxer(int32_t fd, MUXER_OUTPUT_T outputFormat);
    void deInitMuxer();
    void resetMuxer();

    /* Process the frames and give Muxed output */
    int32_t mux(uint8_t *inputBuffer, vector<AMediaCodecBufferInfo> &frameSizes);

    void dumpStatistics(string inputReference);

  private:
    AMediaFormat *mFormat;
    AMediaMuxer *mMuxer;
    Extractor *mExtractor;
    Timer *mTimer;
};

#endif  // __MUXER_H__
+16 −0
Original line number Diff line number Diff line
@@ -42,3 +42,19 @@ cc_test {
        "libbenchmark_decoder",
    ],
}

cc_test {
    name: "muxerTest",
    gtest: true,
    defaults: [
        "libbenchmark_common-defaults",
        "libbenchmark_soft_sanitize_all-defaults",
    ],

    srcs: ["MuxerTest.cpp"],

    static_libs: [
        "libbenchmark_extractor",
        "libbenchmark_muxer",
    ],
}
Loading