diff options
author | 2010-07-02 08:00:30 -0700 | |
---|---|---|
committer | 2010-07-02 08:00:30 -0700 | |
commit | 5460d126f024a8d6597ce4eb127b51c101724960 (patch) | |
tree | 13659bb9870ce956267d30e52d3e22fcb2c5fa41 | |
parent | 3ef6ebe874022c4ec8fbb00067833a6f636c1e2f (diff) | |
parent | 03431d2fa6ee51c122a987322cf1dbd4f89a077b (diff) |
Merge "Added AMessage::debugString() for debugging purposes." into gingerbread
-rw-r--r-- | include/media/stagefright/foundation/AMessage.h | 2 | ||||
-rw-r--r-- | media/libstagefright/foundation/AMessage.cpp | 103 |
2 files changed, 105 insertions, 0 deletions
diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h index 139c6205529f..c674cbaf3471 100644 --- a/include/media/stagefright/foundation/AMessage.h +++ b/include/media/stagefright/foundation/AMessage.h @@ -60,6 +60,8 @@ struct AMessage : public RefBase { sp<AMessage> dup() const; + AString debugString(int32_t indent = 0) const; + protected: virtual ~AMessage(); diff --git a/media/libstagefright/foundation/AMessage.cpp b/media/libstagefright/foundation/AMessage.cpp index dfd1ae335098..26c6d42ca606 100644 --- a/media/libstagefright/foundation/AMessage.cpp +++ b/media/libstagefright/foundation/AMessage.cpp @@ -16,6 +16,8 @@ #include "AMessage.h" +#include <ctype.h> + #include "AAtomizer.h" #include "ADebug.h" #include "ALooperRoster.h" @@ -238,4 +240,105 @@ sp<AMessage> AMessage::dup() const { return msg; } +static void appendIndent(AString *s, int32_t indent) { + static const char kWhitespace[] = + " " + " "; + + CHECK_LT((size_t)indent, sizeof(kWhitespace)); + + s->append(kWhitespace, indent); +} + +static bool isFourcc(uint32_t what) { + return isprint(what & 0xff) + && isprint((what >> 8) & 0xff) + && isprint((what >> 16) & 0xff) + && isprint((what >> 24) & 0xff); +} + +AString AMessage::debugString(int32_t indent) const { + AString s = "AMessage(what = "; + + AString tmp; + if (isFourcc(mWhat)) { + tmp = StringPrintf( + "'%c%c%c%c'", + (char)(mWhat >> 24), + (char)((mWhat >> 16) & 0xff), + (char)((mWhat >> 8) & 0xff), + (char)(mWhat & 0xff)); + } else { + tmp = StringPrintf("0x%08x", mWhat); + } + s.append(tmp); + + if (mTarget != 0) { + tmp = StringPrintf(", target = %d", mTarget); + s.append(tmp); + } + s.append(") = {\n"); + + for (size_t i = 0; i < mNumItems; ++i) { + const Item &item = mItems[i]; + + switch (item.mType) { + case kTypeInt32: + tmp = StringPrintf( + "int32_t %s = %d", item.mName, item.u.int32Value); + break; + case kTypeInt64: + tmp = StringPrintf( + "int64_t %s = %lld", item.mName, item.u.int64Value); + break; + case kTypeSize: + tmp = StringPrintf( + "size_t %s = %d", item.mName, item.u.sizeValue); + break; + case kTypeFloat: + tmp = StringPrintf( + "float %s = %f", item.mName, item.u.floatValue); + break; + case kTypeDouble: + tmp = StringPrintf( + "double %s = %f", item.mName, item.u.doubleValue); + break; + case kTypePointer: + tmp = StringPrintf( + "void *%s = %p", item.mName, item.u.ptrValue); + break; + case kTypeString: + tmp = StringPrintf( + "string %s = \"%s\"", + item.mName, + item.u.stringValue->c_str()); + break; + case kTypeObject: + tmp = StringPrintf( + "RefBase *%s = %p", item.mName, item.u.refValue); + break; + case kTypeMessage: + tmp = StringPrintf( + "AMessage %s = %s", + item.mName, + static_cast<AMessage *>( + item.u.refValue)->debugString( + indent + strlen(item.mName) + 14).c_str()); + break; + default: + TRESPASS(); + } + + appendIndent(&s, indent); + s.append(" "); + s.append(tmp); + s.append("\n"); + } + + appendIndent(&s, indent); + s.append("}"); + + return s; +} + } // namespace android |