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

Commit e24e6624 authored by Manish Singh's avatar Manish Singh Committed by Android (Google) Code Review
Browse files

Merge "Support transcode via MTP"

parents b2448e50 e3b5ba0d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ public:
                                            int64_t& outFileLength,
                                            MtpObjectFormat& outFormat) = 0;

    virtual int                     openFilePath(const char* path, bool transcode) = 0;

    virtual MtpResponseCode         beginDeleteObject(MtpObjectHandle handle) = 0;
    virtual void                    endDeleteObject(MtpObjectHandle handle, bool succeeded) = 0;

+27 −7
Original line number Diff line number Diff line
@@ -791,10 +791,33 @@ MtpResponseCode MtpServer::doGetObject() {

    const char* filePath = (const char *)pathBuf;
    mtp_file_range mfr;
    struct stat sstat;
    uint64_t finalsize;
    bool transcode = android::base::GetBoolProperty("sys.fuse.transcode_mtp", true);
    if (!transcode) {
        ALOGD("Mtp transcode disabled");
        mfr.fd = mDatabase->openFilePath(filePath, false);
        // Doing this here because we want to update fileLength only for this case and leave the
        // regular path as unchanged as possible.
        if (mfr.fd >= 0) {
            fstat(mfr.fd, &sstat);
            finalsize = sstat.st_size;
            fileLength = finalsize;
        } else {
            ALOGW("Mtp open with no transcoding failed for %s. Falling back to the original",
                    filePath);
        }
    }

    if (transcode || mfr.fd < 0) {
        mfr.fd = open(filePath, O_RDONLY);
        if (mfr.fd < 0) {
            return MTP_RESPONSE_GENERAL_ERROR;
        }
        fstat(mfr.fd, &sstat);
        finalsize = sstat.st_size;
    }

    mfr.offset = 0;
    mfr.length = fileLength;
    mfr.command = mRequest.getOperationCode();
@@ -815,9 +838,6 @@ MtpResponseCode MtpServer::doGetObject() {

    auto end = std::chrono::steady_clock::now();
    std::chrono::duration<double> diff = end - start;
    struct stat sstat;
    fstat(mfr.fd, &sstat);
    uint64_t finalsize = sstat.st_size;
    ALOGV("Sent a file over MTP. Time: %f s, Size: %" PRIu64 ", Rate: %f bytes/s",
            diff.count(), finalsize, ((double) finalsize) / diff.count());
    closeObjFd(mfr.fd, filePath);
+5 −0
Original line number Diff line number Diff line
@@ -252,6 +252,11 @@ MtpResponseCode MtpMockDatabase::getObjectFilePath(MtpObjectHandle handle,
    return MTP_RESPONSE_OK;
}

int MtpMockDatabase::openFilePath(const char* path, bool transcode) {
    ALOGD("MockDatabase %s: filePath=%s transcode=%d\n", __func__, path, transcode);
    return 0;
}

MtpResponseCode MtpMockDatabase::beginDeleteObject(MtpObjectHandle handle) {
    ALOGD("MockDatabase %s: ohandle=%u\n", __func__, handle);
    return MTP_RESPONSE_OK;
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ public:
    MtpResponseCode getObjectFilePath(MtpObjectHandle handle, MtpStringBuffer& outFilePath,
                                      int64_t& outFileLength, MtpObjectFormat& outFormat);

    int openFilePath(const char* path, bool transcode);

    MtpResponseCode beginDeleteObject(MtpObjectHandle handle);
    void endDeleteObject(MtpObjectHandle handle, bool succeeded);