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

Commit 6e3fa444 authored by Andreas Huber's avatar Andreas Huber
Browse files

Remove stagefright foundation's incompatible logging interface and update callsites.

Change-Id: I45fba7d60530ea0f233ac3695a97306b6dc1795c
parent 8217eac0
Loading
Loading
Loading
Loading
+12 −37
Original line number Diff line number Diff line
@@ -22,45 +22,18 @@

#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/AString.h>
#include <utils/Log.h>

namespace android {

enum LogType {
    VERBOSE,
    INFO,
    WARNING,
    ERROR,
    FATAL,
};

struct Logger {
    Logger(LogType type);
    virtual ~Logger();

    template<class T> Logger &operator<<(const T &x) {
        mMessage.append(x);

        return *this;
    }

private:
    android::AString mMessage;
    LogType mLogType;

    DISALLOW_EVIL_CONSTRUCTORS(Logger);
};

const char *LeafName(const char *s);

#undef LOG
#define LOG(type)    Logger(type) << LeafName(__FILE__) << ":" << __LINE__ << " "
#define LITERAL_TO_STRING_INTERNAL(x)    #x
#define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)

#define CHECK(condition)                                \
    do {                                                \
        if (!(condition)) {                             \
            LOG(FATAL) << "CHECK(" #condition ") failed.";    \
        }                                               \
    } while (false)
    LOG_ALWAYS_FATAL_IF(                                \
            !(condition),                               \
            __FILE__ ":" LITERAL_TO_STRING(__LINE__)    \
            " CHECK(" #condition ") failed.")

#define MAKE_COMPARATOR(suffix,op)                          \
    template<class A, class B>                              \
@@ -85,8 +58,10 @@ MAKE_COMPARATOR(GT,>)
    do {                                                                \
        AString ___res = Compare_##suffix(x, y);                        \
        if (!___res.empty()) {                                          \
            LOG(FATAL) << "CHECK_" #suffix "(" #x "," #y ") failed: "   \
                       << ___res;                                       \
            LOG_ALWAYS_FATAL(                                           \
                    __FILE__ ":" LITERAL_TO_STRING(__LINE__)            \
                    " CHECK_" #suffix "( " #x "," #y ") failed: %s",    \
                    ___res.c_str());                                    \
        }                                                               \
    } while (false)

@@ -97,7 +72,7 @@ MAKE_COMPARATOR(GT,>)
#define CHECK_GE(x,y)   CHECK_OP(x,y,GE,>=)
#define CHECK_GT(x,y)   CHECK_OP(x,y,GT,>)

#define TRESPASS()      LOG(FATAL) << "Should not be here."
#define TRESPASS()      LOG_ALWAYS_FATAL("Should not be here.")

}  // namespace android

+14 −14
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ size_t PageCache::releaseFromStart(size_t maxBytes) {
}

void PageCache::copy(size_t from, void *data, size_t size) {
    LOG(VERBOSE) << "copy from " << from << " size " << size;
    LOGV("copy from %d size %d", from, size);

    CHECK_LE(from + size, mTotalSize);

@@ -228,7 +228,7 @@ void NuCachedSource2::onMessageReceived(const sp<AMessage> &msg) {
}

void NuCachedSource2::fetchInternal() {
    LOG(VERBOSE) << "fetchInternal";
    LOGV("fetchInternal");

    CHECK_EQ(mFinalStatus, (status_t)OK);

@@ -240,11 +240,11 @@ void NuCachedSource2::fetchInternal() {
    Mutex::Autolock autoLock(mLock);

    if (n < 0) {
        LOG(ERROR) << "source returned error " << n;
        LOGE("source returned error %ld", n);
        mFinalStatus = n;
        mCache->releasePage(page);
    } else if (n == 0) {
        LOG(INFO) << "ERROR_END_OF_STREAM";
        LOGI("ERROR_END_OF_STREAM");
        mFinalStatus = ERROR_END_OF_STREAM;
        mCache->releasePage(page);
    } else {
@@ -254,10 +254,10 @@ void NuCachedSource2::fetchInternal() {
}

void NuCachedSource2::onFetch() {
    LOG(VERBOSE) << "onFetch";
    LOGV("onFetch");

    if (mFinalStatus != OK) {
        LOG(VERBOSE) << "EOS reached, done prefetching for now";
        LOGV("EOS reached, done prefetching for now");
        mFetching = false;
    }

@@ -268,7 +268,7 @@ void NuCachedSource2::onFetch() {

    if (mFetching || keepAlive) {
        if (keepAlive) {
            LOG(INFO) << "Keep alive";
            LOGI("Keep alive");
        }

        fetchInternal();
@@ -276,7 +276,7 @@ void NuCachedSource2::onFetch() {
        mLastFetchTimeUs = ALooper::GetNowUs();

        if (mFetching && mCache->totalSize() >= kHighWaterThreshold) {
            LOG(INFO) << "Cache full, done prefetching for now";
            LOGI("Cache full, done prefetching for now");
            mFetching = false;
        }
    } else {
@@ -289,7 +289,7 @@ void NuCachedSource2::onFetch() {
}

void NuCachedSource2::onRead(const sp<AMessage> &msg) {
    LOG(VERBOSE) << "onRead";
    LOGV("onRead");

    int64_t offset;
    CHECK(msg->findInt64("offset", &offset));
@@ -339,14 +339,14 @@ void NuCachedSource2::restartPrefetcherIfNecessary_l() {
    size_t actualBytes = mCache->releaseFromStart(maxBytes);
    mCacheOffset += actualBytes;

    LOG(INFO) << "restarting prefetcher, totalSize = " << mCache->totalSize();
    LOGI("restarting prefetcher, totalSize = %d", mCache->totalSize());
    mFetching = true;
}

ssize_t NuCachedSource2::readAt(off_t offset, void *data, size_t size) {
    Mutex::Autolock autoSerializer(mSerializer);

    LOG(VERBOSE) << "readAt offset " << offset << " size " << size;
    LOGV("readAt offset %ld, size %d", offset, size);

    Mutex::Autolock autoLock(mLock);

@@ -406,7 +406,7 @@ size_t NuCachedSource2::approxDataRemaining_l(bool *eos) {
}

ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) {
    LOG(VERBOSE) << "readInternal offset " << offset << " size " << size;
    LOGV("readInternal offset %ld size %d", offset, size);

    Mutex::Autolock autoLock(mLock);

@@ -442,7 +442,7 @@ ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) {
        return size;
    }

    LOG(VERBOSE) << "deferring read";
    LOGV("deferring read");

    return -EAGAIN;
}
@@ -455,7 +455,7 @@ status_t NuCachedSource2::seekInternal_l(off_t offset) {
        return OK;
    }

    LOG(INFO) << "new range: offset= " << offset;
    LOGI("new range: offset= %ld", offset);

    mCacheOffset = offset;

+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@
 * limitations under the License.
 */

#define LOG_TAG "ThreadedSource"
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include "include/ThreadedSource.h"

#include <media/stagefright/foundation/ADebug.h>
+0 −76
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.
 */

#include "ADebug.h"

#include <stdio.h>
#include <stdlib.h>

#ifdef ANDROID
#include <cutils/log.h>
#endif

namespace android {

Logger::Logger(LogType type)
    : mLogType(type) {
    switch (mLogType) {
        case VERBOSE:
            mMessage = "V ";
            break;
        case INFO:
            mMessage = "I ";
            break;
        case WARNING:
            mMessage = "W ";
            break;
        case ERROR:
            mMessage = "E ";
            break;
        case FATAL:
            mMessage = "F ";
            break;

        default:
            break;
    }
}

Logger::~Logger() {
    if (mLogType == VERBOSE) {
        return;
    }

    mMessage.append("\n");

#if defined(ANDROID) && 1
    LOG_PRI(ANDROID_LOG_INFO, "ADebug", "%s", mMessage.c_str());
#else
    fprintf(stderr, mMessage.c_str());
    fflush(stderr);
#endif

    if (mLogType == FATAL) {
        abort();
    }
}

const char *LeafName(const char *s) {
    const char *lastSlash = strrchr(s, '/');
    return lastSlash != NULL ? lastSlash + 1 : s;
}

}  // namespace android
+6 −7
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ void ALooperRoster::postMessage(
    ssize_t index = mHandlers.indexOfKey(msg->target());

    if (index < 0) {
        LOG(WARNING) << "failed to post message. Target handler not registered.";
        LOGW("failed to post message. Target handler not registered.");
        return;
    }

@@ -83,8 +83,8 @@ void ALooperRoster::postMessage(
    sp<ALooper> looper = info.mLooper.promote();

    if (looper == NULL) {
        LOG(WARNING) << "failed to post message. "
                        "Target handler still registered, but object gone.";
        LOGW("failed to post message. "
             "Target handler still registered, but object gone.");

        mHandlers.removeItemsAt(index);
        return;
@@ -102,8 +102,7 @@ void ALooperRoster::deliverMessage(const sp<AMessage> &msg) {
        ssize_t index = mHandlers.indexOfKey(msg->target());

        if (index < 0) {
            LOG(WARNING) << "failed to deliver message. "
                         << "Target handler not registered.";
            LOGW("failed to deliver message. Target handler not registered.");
            return;
        }

@@ -111,8 +110,8 @@ void ALooperRoster::deliverMessage(const sp<AMessage> &msg) {
        handler = info.mHandler.promote();

        if (handler == NULL) {
            LOG(WARNING) << "failed to deliver message. "
                            "Target handler registered, but object gone.";
            LOGW("failed to deliver message. "
                 "Target handler registered, but object gone.");

            mHandlers.removeItemsAt(index);
            return;
Loading