Add MetaData::dumpToLog
Utility method for dumping the content of a MetaData object to the log.
Change-Id: I2d91b991e1d9fed2215e8995a73c2b1854205074
diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h
index 00b8679..c3ccb56 100644
--- a/include/media/stagefright/MetaData.h
+++ b/include/media/stagefright/MetaData.h
@@ -24,6 +24,7 @@
#include <utils/RefBase.h>
#include <utils/KeyedVector.h>
+#include <utils/String8.h>
namespace android {
@@ -180,6 +181,8 @@
bool findData(uint32_t key, uint32_t *type,
const void **data, size_t *size) const;
+ void dumpToLog() const;
+
protected:
virtual ~MetaData();
@@ -194,6 +197,7 @@
void clear();
void setData(uint32_t type, const void *data, size_t size);
void getData(uint32_t *type, const void **data, size_t *size) const;
+ String8 asString() const;
private:
uint32_t mType;
diff --git a/media/libstagefright/MetaData.cpp b/media/libstagefright/MetaData.cpp
index 66dec90..755594a 100644
--- a/media/libstagefright/MetaData.cpp
+++ b/media/libstagefright/MetaData.cpp
@@ -14,6 +14,10 @@
* limitations under the License.
*/
+//#define LOG_NDEBUG 0
+#define LOG_TAG "MetaData"
+#include <utils/Log.h>
+
#include <stdlib.h>
#include <string.h>
@@ -282,5 +286,60 @@
mSize = 0;
}
+String8 MetaData::typed_data::asString() const {
+ String8 out;
+ const void *data = storage();
+ switch(mType) {
+ case TYPE_NONE:
+ out = String8::format("no type, size %d)", mSize);
+ break;
+ case TYPE_C_STRING:
+ out = String8::format("(char*) %s", (const char *)data);
+ break;
+ case TYPE_INT32:
+ out = String8::format("(int32_t) %d", *(int32_t *)data);
+ break;
+ case TYPE_INT64:
+ out = String8::format("(int64_t) %lld", *(int64_t *)data);
+ break;
+ case TYPE_FLOAT:
+ out = String8::format("(float) %f", *(float *)data);
+ break;
+ case TYPE_POINTER:
+ out = String8::format("(void*) %p", *(void **)data);
+ break;
+ case TYPE_RECT:
+ {
+ const Rect *r = (const Rect *)data;
+ out = String8::format("Rect(%d, %d, %d, %d)",
+ r->mLeft, r->mTop, r->mRight, r->mBottom);
+ break;
+ }
+
+ default:
+ out = String8::format("(unknown type %d, size %d)", mType, mSize);
+ break;
+ }
+ return out;
+}
+
+static void MakeFourCCString(uint32_t x, char *s) {
+ s[0] = x >> 24;
+ s[1] = (x >> 16) & 0xff;
+ s[2] = (x >> 8) & 0xff;
+ s[3] = x & 0xff;
+ s[4] = '\0';
+}
+
+void MetaData::dumpToLog() const {
+ for (int i = mItems.size(); --i >= 0;) {
+ int32_t key = mItems.keyAt(i);
+ char cc[5];
+ MakeFourCCString(key, cc);
+ const typed_data &item = mItems.valueAt(i);
+ ALOGI("%s: %s", cc, item.asString().string());
+ }
+}
+
} // namespace android