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

Commit 3975a491 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "MPEG4Writer:Print longest 5 write durations" into rvc-dev am: 9ce151cc

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/12048499

Change-Id: I1f443e76ff3707245a9e2172e295f5d2ef66ea1e
parents 22568387 9ce151cc
Loading
Loading
Loading
Loading
+28 −0
Original line number Original line Diff line number Diff line
@@ -1110,6 +1110,21 @@ void MPEG4Writer::writeCompositionMatrix(int degrees) {
    writeInt32(0x40000000);  // w
    writeInt32(0x40000000);  // w
}
}


void MPEG4Writer::printWriteDurations() {
    if (mWriteDurationPQ.empty()) {
        return;
    }
    std::string writeDurationsString =
            "Top " + std::to_string(mWriteDurationPQ.size()) + " write durations(microseconds):";
    uint8_t i = 0;
    while (!mWriteDurationPQ.empty()) {
        writeDurationsString +=
                " #" + std::to_string(++i) + ":" + std::to_string(mWriteDurationPQ.top().count());
        mWriteDurationPQ.pop();
    }
    ALOGD("%s", writeDurationsString.c_str());
}

status_t MPEG4Writer::release() {
status_t MPEG4Writer::release() {
    ALOGD("release()");
    ALOGD("release()");
    status_t err = OK;
    status_t err = OK;
@@ -1138,6 +1153,9 @@ status_t MPEG4Writer::release() {
    mStarted = false;
    mStarted = false;
    free(mInMemoryCache);
    free(mInMemoryCache);
    mInMemoryCache = NULL;
    mInMemoryCache = NULL;

    printWriteDurations();

    return err;
    return err;
}
}


@@ -1594,7 +1612,17 @@ size_t MPEG4Writer::write(
void MPEG4Writer::writeOrPostError(int fd, const void* buf, size_t count) {
void MPEG4Writer::writeOrPostError(int fd, const void* buf, size_t count) {
    if (mWriteSeekErr == true)
    if (mWriteSeekErr == true)
        return;
        return;

    auto beforeTP = std::chrono::high_resolution_clock::now();
    ssize_t bytesWritten = ::write(fd, buf, count);
    ssize_t bytesWritten = ::write(fd, buf, count);
    auto afterTP = std::chrono::high_resolution_clock::now();
    auto writeDuration =
            std::chrono::duration_cast<std::chrono::microseconds>(afterTP - beforeTP).count();
    mWriteDurationPQ.emplace(writeDuration);
    if (mWriteDurationPQ.size() > kWriteDurationsCount) {
        mWriteDurationPQ.pop();
    }

    /* Write as much as possible during stop() execution when there was an error
    /* Write as much as possible during stop() execution when there was an error
     * (mWriteSeekErr == true) in the previous call to write() or lseek64().
     * (mWriteSeekErr == true) in the previous call to write() or lseek64().
     */
     */
+6 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@
#include <media/stagefright/foundation/AHandlerReflector.h>
#include <media/stagefright/foundation/AHandlerReflector.h>
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/ALooper.h>
#include <mutex>
#include <mutex>
#include <queue>


namespace android {
namespace android {


@@ -125,6 +126,10 @@ private:
    bool mWriteSeekErr;
    bool mWriteSeekErr;
    bool mFallocateErr;
    bool mFallocateErr;
    bool mPreAllocationEnabled;
    bool mPreAllocationEnabled;
    // Queue to hold top long write durations
    std::priority_queue<std::chrono::microseconds, std::vector<std::chrono::microseconds>,
                        std::greater<std::chrono::microseconds>> mWriteDurationPQ;
    const uint8_t kWriteDurationsCount = 5;


    sp<ALooper> mLooper;
    sp<ALooper> mLooper;
    sp<AHandlerReflector<MPEG4Writer> > mReflector;
    sp<AHandlerReflector<MPEG4Writer> > mReflector;
@@ -149,6 +154,7 @@ private:
    int64_t estimateMoovBoxSize(int32_t bitRate);
    int64_t estimateMoovBoxSize(int32_t bitRate);
    int64_t estimateFileLevelMetaSize(MetaData *params);
    int64_t estimateFileLevelMetaSize(MetaData *params);
    void writeCachedBoxToFile(const char *type);
    void writeCachedBoxToFile(const char *type);
    void printWriteDurations();


    struct Chunk {
    struct Chunk {
        Track               *mTrack;        // Owner
        Track               *mTrack;        // Owner