Merge "Mediacodec to use C interface to mediametrics"

gugelfrei
Marco Nelissen 5 years ago committed by Gerrit Code Review
commit 0bab538b5c

@ -29,6 +29,7 @@
#include <android/hardware/cas/native/1.0/IDescrambler.h> #include <android/hardware/cas/native/1.0/IDescrambler.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <binder/MemoryDealer.h> #include <binder/MemoryDealer.h>
#include <cutils/properties.h>
#include <gui/Surface.h> #include <gui/Surface.h>
#include <media/openmax/OMX_Core.h> #include <media/openmax/OMX_Core.h>
#include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ABuffer.h>

@ -64,6 +64,16 @@ MediaAnalyticsItem *MediaAnalyticsItem::create(MediaAnalyticsItem::Key key)
return item; return item;
} }
MediaAnalyticsItem* MediaAnalyticsItem::convert(mediametrics_handle_t handle) {
MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
return item;
}
mediametrics_handle_t MediaAnalyticsItem::convert(MediaAnalyticsItem *item ) {
mediametrics_handle_t handle = (mediametrics_handle_t) item;
return handle;
}
// access functions for the class // access functions for the class
MediaAnalyticsItem::MediaAnalyticsItem() MediaAnalyticsItem::MediaAnalyticsItem()
: mPid(-1), : mPid(-1),

@ -169,6 +169,11 @@ bool mediametrics_selfRecord(mediametrics_handle_t handle) {
return item->selfrecord(); return item->selfrecord();
} }
mediametrics_handle_t mediametrics_dup(mediametrics_handle_t handle) {
android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
if (item == NULL) return android::MediaAnalyticsItem::convert(item);
return android::MediaAnalyticsItem::convert(item->dup());
}
const char *mediametrics_readable(mediametrics_handle_t handle) { const char *mediametrics_readable(mediametrics_handle_t handle) {
android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle; android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;

@ -17,6 +17,8 @@
#ifndef ANDROID_MEDIA_MEDIAANALYTICSITEM_H #ifndef ANDROID_MEDIA_MEDIAANALYTICSITEM_H
#define ANDROID_MEDIA_MEDIAANALYTICSITEM_H #define ANDROID_MEDIA_MEDIAANALYTICSITEM_H
#include "MediaMetrics.h"
#include <string> #include <string>
#include <sys/types.h> #include <sys/types.h>
@ -94,6 +96,9 @@ class MediaAnalyticsItem {
static MediaAnalyticsItem* create(Key key); static MediaAnalyticsItem* create(Key key);
static MediaAnalyticsItem* create(); static MediaAnalyticsItem* create();
static MediaAnalyticsItem* convert(mediametrics_handle_t);
static mediametrics_handle_t convert(MediaAnalyticsItem *);
// access functions for the class // access functions for the class
~MediaAnalyticsItem(); ~MediaAnalyticsItem();

@ -79,6 +79,7 @@ void mediametrics_freeCString(char *value);
// # of attributes set within this record. // # of attributes set within this record.
int32_t mediametrics_count(mediametrics_handle_t handle); int32_t mediametrics_count(mediametrics_handle_t handle);
mediametrics_handle_t mediametrics_dup(mediametrics_handle_t handle);
bool mediametrics_selfRecord(mediametrics_handle_t handle); bool mediametrics_selfRecord(mediametrics_handle_t handle);
const char *mediametrics_readable(mediametrics_handle_t handle); const char *mediametrics_readable(mediametrics_handle_t handle);

@ -527,7 +527,7 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid)
mFlags(0), mFlags(0),
mStickyError(OK), mStickyError(OK),
mSoftRenderer(NULL), mSoftRenderer(NULL),
mAnalyticsItem(NULL), mMetricsHandle(0),
mIsVideo(false), mIsVideo(false),
mVideoWidth(0), mVideoWidth(0),
mVideoHeight(0), mVideoHeight(0),
@ -548,19 +548,19 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid)
mResourceManagerClient = new ResourceManagerClient(this); mResourceManagerClient = new ResourceManagerClient(this);
mResourceManagerService = new ResourceManagerServiceProxy(pid, mUid); mResourceManagerService = new ResourceManagerServiceProxy(pid, mUid);
initAnalyticsItem(); initMediametrics();
} }
MediaCodec::~MediaCodec() { MediaCodec::~MediaCodec() {
CHECK_EQ(mState, UNINITIALIZED); CHECK_EQ(mState, UNINITIALIZED);
mResourceManagerService->removeClient(getId(mResourceManagerClient)); mResourceManagerService->removeClient(getId(mResourceManagerClient));
flushAnalyticsItem(); flushMediametrics();
} }
void MediaCodec::initAnalyticsItem() { void MediaCodec::initMediametrics() {
if (mAnalyticsItem == NULL) { if (mMetricsHandle == 0) {
mAnalyticsItem = MediaAnalyticsItem::create(kCodecKeyName); mMetricsHandle = mediametrics_create(kCodecKeyName);
} }
mLatencyHist.setup(kLatencyHistBuckets, kLatencyHistWidth, kLatencyHistFloor); mLatencyHist.setup(kLatencyHistBuckets, kLatencyHistWidth, kLatencyHistFloor);
@ -574,38 +574,39 @@ void MediaCodec::initAnalyticsItem() {
} }
} }
void MediaCodec::updateAnalyticsItem() { void MediaCodec::updateMediametrics() {
ALOGV("MediaCodec::updateAnalyticsItem"); ALOGV("MediaCodec::updateMediametrics");
if (mAnalyticsItem == NULL) { if (mMetricsHandle == 0) {
return; return;
} }
if (mLatencyHist.getCount() != 0 ) { if (mLatencyHist.getCount() != 0 ) {
mAnalyticsItem->setInt64(kCodecLatencyMax, mLatencyHist.getMax()); mediametrics_setInt64(mMetricsHandle, kCodecLatencyMax, mLatencyHist.getMax());
mAnalyticsItem->setInt64(kCodecLatencyMin, mLatencyHist.getMin()); mediametrics_setInt64(mMetricsHandle, kCodecLatencyMin, mLatencyHist.getMin());
mAnalyticsItem->setInt64(kCodecLatencyAvg, mLatencyHist.getAvg()); mediametrics_setInt64(mMetricsHandle, kCodecLatencyAvg, mLatencyHist.getAvg());
mAnalyticsItem->setInt64(kCodecLatencyCount, mLatencyHist.getCount()); mediametrics_setInt64(mMetricsHandle, kCodecLatencyCount, mLatencyHist.getCount());
if (kEmitHistogram) { if (kEmitHistogram) {
// and the histogram itself // and the histogram itself
std::string hist = mLatencyHist.emit(); std::string hist = mLatencyHist.emit();
mAnalyticsItem->setCString(kCodecLatencyHist, hist.c_str()); mediametrics_setCString(mMetricsHandle, kCodecLatencyHist, hist.c_str());
} }
} }
if (mLatencyUnknown > 0) { if (mLatencyUnknown > 0) {
mAnalyticsItem->setInt64(kCodecLatencyUnknown, mLatencyUnknown); mediametrics_setInt64(mMetricsHandle, kCodecLatencyUnknown, mLatencyUnknown);
} }
#if 0 #if 0
// enable for short term, only while debugging // enable for short term, only while debugging
updateEphemeralAnalytics(mAnalyticsItem); updateEphemeralMediametrics(mMetricsHandle);
#endif #endif
} }
void MediaCodec::updateEphemeralAnalytics(MediaAnalyticsItem *item) { void MediaCodec::updateEphemeralMediametrics(mediametrics_handle_t item) {
ALOGD("MediaCodec::updateEphemeralAnalytics()"); ALOGD("MediaCodec::updateEphemeralMediametrics()");
if (item == NULL) { if (item == 0) {
return; return;
} }
@ -628,28 +629,27 @@ void MediaCodec::updateEphemeralAnalytics(MediaAnalyticsItem *item) {
// spit the data (if any) into the supplied analytics record // spit the data (if any) into the supplied analytics record
if (recentHist.getCount()!= 0 ) { if (recentHist.getCount()!= 0 ) {
item->setInt64(kCodecRecentLatencyMax, recentHist.getMax()); mediametrics_setInt64(item, kCodecRecentLatencyMax, recentHist.getMax());
item->setInt64(kCodecRecentLatencyMin, recentHist.getMin()); mediametrics_setInt64(item, kCodecRecentLatencyMin, recentHist.getMin());
item->setInt64(kCodecRecentLatencyAvg, recentHist.getAvg()); mediametrics_setInt64(item, kCodecRecentLatencyAvg, recentHist.getAvg());
item->setInt64(kCodecRecentLatencyCount, recentHist.getCount()); mediametrics_setInt64(item, kCodecRecentLatencyCount, recentHist.getCount());
if (kEmitHistogram) { if (kEmitHistogram) {
// and the histogram itself // and the histogram itself
std::string hist = recentHist.emit(); std::string hist = recentHist.emit();
item->setCString(kCodecRecentLatencyHist, hist.c_str()); mediametrics_setCString(item, kCodecRecentLatencyHist, hist.c_str());
} }
} }
} }
void MediaCodec::flushAnalyticsItem() { void MediaCodec::flushMediametrics() {
updateAnalyticsItem(); updateMediametrics();
if (mAnalyticsItem != NULL) { if (mMetricsHandle != 0) {
// don't log empty records if (mediametrics_count(mMetricsHandle) > 0) {
if (mAnalyticsItem->count() > 0) { mediametrics_selfRecord(mMetricsHandle);
mAnalyticsItem->selfrecord();
} }
delete mAnalyticsItem; mediametrics_delete(mMetricsHandle);
mAnalyticsItem = NULL; mMetricsHandle = 0;
} }
} }
@ -981,9 +981,10 @@ status_t MediaCodec::init(const AString &name) {
// ".secure" // ".secure"
msg->setString("name", name); msg->setString("name", name);
if (mAnalyticsItem != NULL) { if (mMetricsHandle != 0) {
mAnalyticsItem->setCString(kCodecCodec, name.c_str()); mediametrics_setCString(mMetricsHandle, kCodecCodec, name.c_str());
mAnalyticsItem->setCString(kCodecMode, mIsVideo ? kCodecModeVideo : kCodecModeAudio); mediametrics_setCString(mMetricsHandle, kCodecMode,
mIsVideo ? kCodecModeVideo : kCodecModeAudio);
} }
if (mIsVideo) { if (mIsVideo) {
@ -1044,16 +1045,17 @@ status_t MediaCodec::configure(
uint32_t flags) { uint32_t flags) {
sp<AMessage> msg = new AMessage(kWhatConfigure, this); sp<AMessage> msg = new AMessage(kWhatConfigure, this);
if (mAnalyticsItem != NULL) { if (mMetricsHandle != 0) {
int32_t profile = 0; int32_t profile = 0;
if (format->findInt32("profile", &profile)) { if (format->findInt32("profile", &profile)) {
mAnalyticsItem->setInt32(kCodecProfile, profile); mediametrics_setInt32(mMetricsHandle, kCodecProfile, profile);
} }
int32_t level = 0; int32_t level = 0;
if (format->findInt32("level", &level)) { if (format->findInt32("level", &level)) {
mAnalyticsItem->setInt32(kCodecLevel, level); mediametrics_setInt32(mMetricsHandle, kCodecLevel, level);
} }
mAnalyticsItem->setInt32(kCodecEncoder, (flags & CONFIGURE_FLAG_ENCODE) ? 1 : 0); mediametrics_setInt32(mMetricsHandle, kCodecEncoder,
(flags & CONFIGURE_FLAG_ENCODE) ? 1 : 0);
} }
if (mIsVideo) { if (mIsVideo) {
@ -1063,17 +1065,17 @@ status_t MediaCodec::configure(
mRotationDegrees = 0; mRotationDegrees = 0;
} }
if (mAnalyticsItem != NULL) { if (mMetricsHandle != 0) {
mAnalyticsItem->setInt32(kCodecWidth, mVideoWidth); mediametrics_setInt32(mMetricsHandle, kCodecWidth, mVideoWidth);
mAnalyticsItem->setInt32(kCodecHeight, mVideoHeight); mediametrics_setInt32(mMetricsHandle, kCodecHeight, mVideoHeight);
mAnalyticsItem->setInt32(kCodecRotation, mRotationDegrees); mediametrics_setInt32(mMetricsHandle, kCodecRotation, mRotationDegrees);
int32_t maxWidth = 0; int32_t maxWidth = 0;
if (format->findInt32("max-width", &maxWidth)) { if (format->findInt32("max-width", &maxWidth)) {
mAnalyticsItem->setInt32(kCodecMaxWidth, maxWidth); mediametrics_setInt32(mMetricsHandle, kCodecMaxWidth, maxWidth);
} }
int32_t maxHeight = 0; int32_t maxHeight = 0;
if (format->findInt32("max-height", &maxHeight)) { if (format->findInt32("max-height", &maxHeight)) {
mAnalyticsItem->setInt32(kCodecMaxHeight, maxHeight); mediametrics_setInt32(mMetricsHandle, kCodecMaxHeight, maxHeight);
} }
} }
@ -1095,8 +1097,8 @@ status_t MediaCodec::configure(
} else { } else {
msg->setPointer("descrambler", descrambler.get()); msg->setPointer("descrambler", descrambler.get());
} }
if (mAnalyticsItem != NULL) { if (mMetricsHandle != 0) {
mAnalyticsItem->setInt32(kCodecCrypto, 1); mediametrics_setInt32(mMetricsHandle, kCodecCrypto, 1);
} }
} else if (mFlags & kFlagIsSecure) { } else if (mFlags & kFlagIsSecure) {
ALOGW("Crypto or descrambler should be given for secure codec"); ALOGW("Crypto or descrambler should be given for secure codec");
@ -1561,22 +1563,22 @@ status_t MediaCodec::getCodecInfo(sp<MediaCodecInfo> *codecInfo) const {
return OK; return OK;
} }
status_t MediaCodec::getMetrics(MediaAnalyticsItem * &reply) { status_t MediaCodec::getMetrics(mediametrics_handle_t &reply) {
reply = NULL; reply = 0;
// shouldn't happen, but be safe // shouldn't happen, but be safe
if (mAnalyticsItem == NULL) { if (mMetricsHandle == 0) {
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }
// update any in-flight data that's not carried within the record // update any in-flight data that's not carried within the record
updateAnalyticsItem(); updateMediametrics();
// send it back to the caller. // send it back to the caller.
reply = mAnalyticsItem->dup(); reply = mediametrics_dup(mMetricsHandle);
updateEphemeralAnalytics(reply); updateEphemeralMediametrics(reply);
return OK; return OK;
} }
@ -1890,10 +1892,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
case CONFIGURING: case CONFIGURING:
{ {
if (actionCode == ACTION_CODE_FATAL) { if (actionCode == ACTION_CODE_FATAL) {
mAnalyticsItem->setInt32(kCodecError, err); mediametrics_setInt32(mMetricsHandle, kCodecError, err);
mAnalyticsItem->setCString(kCodecErrorState, stateString(mState).c_str()); mediametrics_setCString(mMetricsHandle, kCodecErrorState,
flushAnalyticsItem(); stateString(mState).c_str());
initAnalyticsItem(); flushMediametrics();
initMediametrics();
} }
setState(actionCode == ACTION_CODE_FATAL ? setState(actionCode == ACTION_CODE_FATAL ?
UNINITIALIZED : INITIALIZED); UNINITIALIZED : INITIALIZED);
@ -1903,10 +1906,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
case STARTING: case STARTING:
{ {
if (actionCode == ACTION_CODE_FATAL) { if (actionCode == ACTION_CODE_FATAL) {
mAnalyticsItem->setInt32(kCodecError, err); mediametrics_setInt32(mMetricsHandle, kCodecError, err);
mAnalyticsItem->setCString(kCodecErrorState, stateString(mState).c_str()); mediametrics_setCString(mMetricsHandle, kCodecErrorState,
flushAnalyticsItem(); stateString(mState).c_str());
initAnalyticsItem(); flushMediametrics();
initMediametrics();
} }
setState(actionCode == ACTION_CODE_FATAL ? setState(actionCode == ACTION_CODE_FATAL ?
UNINITIALIZED : CONFIGURED); UNINITIALIZED : CONFIGURED);
@ -1944,10 +1948,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
case FLUSHING: case FLUSHING:
{ {
if (actionCode == ACTION_CODE_FATAL) { if (actionCode == ACTION_CODE_FATAL) {
mAnalyticsItem->setInt32(kCodecError, err); mediametrics_setInt32(mMetricsHandle, kCodecError, err);
mAnalyticsItem->setCString(kCodecErrorState, stateString(mState).c_str()); mediametrics_setCString(mMetricsHandle, kCodecErrorState,
flushAnalyticsItem(); stateString(mState).c_str());
initAnalyticsItem(); flushMediametrics();
initMediametrics();
setState(UNINITIALIZED); setState(UNINITIALIZED);
} else { } else {
@ -1977,10 +1982,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
setState(INITIALIZED); setState(INITIALIZED);
break; break;
default: default:
mAnalyticsItem->setInt32(kCodecError, err); mediametrics_setInt32(mMetricsHandle, kCodecError, err);
mAnalyticsItem->setCString(kCodecErrorState, stateString(mState).c_str()); mediametrics_setCString(mMetricsHandle, kCodecErrorState,
flushAnalyticsItem(); stateString(mState).c_str());
initAnalyticsItem(); flushMediametrics();
initMediametrics();
setState(UNINITIALIZED); setState(UNINITIALIZED);
break; break;
} }
@ -2037,7 +2043,8 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
CHECK(msg->findString("componentName", &mComponentName)); CHECK(msg->findString("componentName", &mComponentName));
if (mComponentName.c_str()) { if (mComponentName.c_str()) {
mAnalyticsItem->setCString(kCodecCodec, mComponentName.c_str()); mediametrics_setCString(mMetricsHandle, kCodecCodec,
mComponentName.c_str());
} }
const char *owner = mCodecInfo->getOwnerName(); const char *owner = mCodecInfo->getOwnerName();
@ -2053,11 +2060,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
if (mComponentName.endsWith(".secure")) { if (mComponentName.endsWith(".secure")) {
mFlags |= kFlagIsSecure; mFlags |= kFlagIsSecure;
resourceType = MediaResource::kSecureCodec; resourceType = MediaResource::kSecureCodec;
mAnalyticsItem->setInt32(kCodecSecure, 1); mediametrics_setInt32(mMetricsHandle, kCodecSecure, 1);
} else { } else {
mFlags &= ~kFlagIsSecure; mFlags &= ~kFlagIsSecure;
resourceType = MediaResource::kNonSecureCodec; resourceType = MediaResource::kNonSecureCodec;
mAnalyticsItem->setInt32(kCodecSecure, 0); mediametrics_setInt32(mMetricsHandle, kCodecSecure, 0);
} }
if (mIsVideo) { if (mIsVideo) {
@ -2105,14 +2112,15 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
(new AMessage)->postReply(mReplyID); (new AMessage)->postReply(mReplyID);
// augment our media metrics info, now that we know more things // augment our media metrics info, now that we know more things
if (mAnalyticsItem != NULL) { if (mMetricsHandle != 0) {
sp<AMessage> format; sp<AMessage> format;
if (mConfigureMsg != NULL && if (mConfigureMsg != NULL &&
mConfigureMsg->findMessage("format", &format)) { mConfigureMsg->findMessage("format", &format)) {
// format includes: mime // format includes: mime
AString mime; AString mime;
if (format->findString("mime", &mime)) { if (format->findString("mime", &mime)) {
mAnalyticsItem->setCString(kCodecMime, mime.c_str()); mediametrics_setCString(mMetricsHandle, kCodecMime,
mime.c_str());
} }
} }
} }

@ -25,7 +25,7 @@
#include <media/hardware/CryptoAPI.h> #include <media/hardware/CryptoAPI.h>
#include <media/MediaCodecInfo.h> #include <media/MediaCodecInfo.h>
#include <media/MediaResource.h> #include <media/MediaResource.h>
#include <media/MediaAnalyticsItem.h> #include <media/MediaMetrics.h>
#include <media/stagefright/foundation/AHandler.h> #include <media/stagefright/foundation/AHandler.h>
#include <media/stagefright/FrameRenderTracker.h> #include <media/stagefright/FrameRenderTracker.h>
#include <utils/Vector.h> #include <utils/Vector.h>
@ -189,7 +189,7 @@ struct MediaCodec : public AHandler {
status_t getCodecInfo(sp<MediaCodecInfo> *codecInfo) const; status_t getCodecInfo(sp<MediaCodecInfo> *codecInfo) const;
status_t getMetrics(MediaAnalyticsItem * &reply); status_t getMetrics(mediametrics_handle_t &reply);
status_t setParameters(const sp<AMessage> &params); status_t setParameters(const sp<AMessage> &params);
@ -328,11 +328,11 @@ private:
sp<Surface> mSurface; sp<Surface> mSurface;
SoftwareRenderer *mSoftRenderer; SoftwareRenderer *mSoftRenderer;
MediaAnalyticsItem *mAnalyticsItem; mediametrics_handle_t mMetricsHandle;
void initAnalyticsItem(); void initMediametrics();
void updateAnalyticsItem(); void updateMediametrics();
void flushAnalyticsItem(); void flushMediametrics();
void updateEphemeralAnalytics(MediaAnalyticsItem *item); void updateEphemeralMediametrics(mediametrics_handle_t item);
sp<AMessage> mOutputFormat; sp<AMessage> mOutputFormat;
sp<AMessage> mInputFormat; sp<AMessage> mInputFormat;

Loading…
Cancel
Save