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

Commit 67738486 authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "Remove stagefright foundation's incompatible logging interface and...

Merge "Remove stagefright foundation's incompatible logging interface and update callsites." into gingerbread
parents 34d3aeaf 6e3fa444
Loading
Loading
Loading
Loading
+12 −37
Original line number Original line Diff line number Diff line
@@ -22,45 +22,18 @@


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


namespace android {
namespace android {


enum LogType {
#define LITERAL_TO_STRING_INTERNAL(x)    #x
    VERBOSE,
#define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)
    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 CHECK(condition)                                \
#define CHECK(condition)                                \
    do {                                                \
    LOG_ALWAYS_FATAL_IF(                                \
        if (!(condition)) {                             \
            !(condition),                               \
            LOG(FATAL) << "CHECK(" #condition ") failed.";    \
            __FILE__ ":" LITERAL_TO_STRING(__LINE__)    \
        }                                               \
            " CHECK(" #condition ") failed.")
    } while (false)


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


@@ -97,7 +72,7 @@ MAKE_COMPARATOR(GT,>)
#define CHECK_GE(x,y)   CHECK_OP(x,y,GE,>=)
#define CHECK_GE(x,y)   CHECK_OP(x,y,GE,>=)
#define CHECK_GT(x,y)   CHECK_OP(x,y,GT,>)
#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
}  // namespace android


+14 −14
Original line number Original line 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) {
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);
    CHECK_LE(from + size, mTotalSize);


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


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


    CHECK_EQ(mFinalStatus, (status_t)OK);
    CHECK_EQ(mFinalStatus, (status_t)OK);


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


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


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


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


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


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


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


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


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


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


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


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


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


    Mutex::Autolock autoLock(mLock);
    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) {
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);
    Mutex::Autolock autoLock(mLock);


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


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


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


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


    mCacheOffset = offset;
    mCacheOffset = offset;


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


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

#include "include/ThreadedSource.h"
#include "include/ThreadedSource.h"


#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ADebug.h>
+0 −76
Original line number Original line 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 Original line Diff line number Diff line
@@ -74,7 +74,7 @@ void ALooperRoster::postMessage(
    ssize_t index = mHandlers.indexOfKey(msg->target());
    ssize_t index = mHandlers.indexOfKey(msg->target());


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


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


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


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


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


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


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


            mHandlers.removeItemsAt(index);
            mHandlers.removeItemsAt(index);
            return;
            return;
Loading