Merge change I0f9a53d4 into eclair
* changes: Set metadata retriever thread group to the caller's group.
This commit is contained in:
@@ -21,6 +21,51 @@
|
|||||||
#include <SkBitmap.h>
|
#include <SkBitmap.h>
|
||||||
#include <media/IMediaMetadataRetriever.h>
|
#include <media/IMediaMetadataRetriever.h>
|
||||||
|
|
||||||
|
// The binder is supposed to propagate the scheduler group across
|
||||||
|
// the binder interface so that remote calls are executed with
|
||||||
|
// the same priority as local calls. This is currently not working
|
||||||
|
// so this change puts in a temporary hack to fix the issue with
|
||||||
|
// metadata retrieval which can be a huge CPU hit if done on a
|
||||||
|
// foreground thread.
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
|
||||||
|
/* desktop Linux needs a little help with gettid() */
|
||||||
|
#if defined(HAVE_GETTID) && !defined(HAVE_ANDROID_OS)
|
||||||
|
#define __KERNEL__
|
||||||
|
# include <linux/unistd.h>
|
||||||
|
#ifdef _syscall0
|
||||||
|
_syscall0(pid_t,gettid)
|
||||||
|
#else
|
||||||
|
pid_t gettid() { return syscall(__NR_gettid);}
|
||||||
|
#endif
|
||||||
|
#undef __KERNEL__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LOG_TAG "IMediaMetadataRetriever"
|
||||||
|
#include <utils/Log.h>
|
||||||
|
#include <cutils/sched_policy.h>
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
|
||||||
|
static void sendSchedPolicy(Parcel& data)
|
||||||
|
{
|
||||||
|
SchedPolicy policy;
|
||||||
|
get_sched_policy(gettid(), &policy);
|
||||||
|
data.writeInt32(policy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setSchedPolicy(const Parcel& data)
|
||||||
|
{
|
||||||
|
SchedPolicy policy = (SchedPolicy) data.readInt32();
|
||||||
|
set_sched_policy(gettid(), policy);
|
||||||
|
}
|
||||||
|
static void restoreSchedPolicy()
|
||||||
|
{
|
||||||
|
set_sched_policy(gettid(), SP_FOREGROUND);
|
||||||
|
}
|
||||||
|
}; // end namespace android
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -30,7 +75,7 @@ enum {
|
|||||||
SET_MODE,
|
SET_MODE,
|
||||||
GET_MODE,
|
GET_MODE,
|
||||||
CAPTURE_FRAME,
|
CAPTURE_FRAME,
|
||||||
EXTARCT_ALBUM_ART,
|
EXTRACT_ALBUM_ART,
|
||||||
EXTRACT_METADATA,
|
EXTRACT_METADATA,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,6 +137,9 @@ public:
|
|||||||
{
|
{
|
||||||
Parcel data, reply;
|
Parcel data, reply;
|
||||||
data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
|
data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
sendSchedPolicy(data);
|
||||||
|
#endif
|
||||||
remote()->transact(CAPTURE_FRAME, data, &reply);
|
remote()->transact(CAPTURE_FRAME, data, &reply);
|
||||||
status_t ret = reply.readInt32();
|
status_t ret = reply.readInt32();
|
||||||
if (ret != NO_ERROR) {
|
if (ret != NO_ERROR) {
|
||||||
@@ -104,7 +152,10 @@ public:
|
|||||||
{
|
{
|
||||||
Parcel data, reply;
|
Parcel data, reply;
|
||||||
data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
|
data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
|
||||||
remote()->transact(EXTARCT_ALBUM_ART, data, &reply);
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
sendSchedPolicy(data);
|
||||||
|
#endif
|
||||||
|
remote()->transact(EXTRACT_ALBUM_ART, data, &reply);
|
||||||
status_t ret = reply.readInt32();
|
status_t ret = reply.readInt32();
|
||||||
if (ret != NO_ERROR) {
|
if (ret != NO_ERROR) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -116,6 +167,9 @@ public:
|
|||||||
{
|
{
|
||||||
Parcel data, reply;
|
Parcel data, reply;
|
||||||
data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
|
data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
sendSchedPolicy(data);
|
||||||
|
#endif
|
||||||
data.writeInt32(keyCode);
|
data.writeInt32(keyCode);
|
||||||
remote()->transact(EXTRACT_METADATA, data, &reply);
|
remote()->transact(EXTRACT_METADATA, data, &reply);
|
||||||
status_t ret = reply.readInt32();
|
status_t ret = reply.readInt32();
|
||||||
@@ -169,6 +223,9 @@ status_t BnMediaMetadataRetriever::onTransact(
|
|||||||
} break;
|
} break;
|
||||||
case CAPTURE_FRAME: {
|
case CAPTURE_FRAME: {
|
||||||
CHECK_INTERFACE(IMediaMetadataRetriever, data, reply);
|
CHECK_INTERFACE(IMediaMetadataRetriever, data, reply);
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
setSchedPolicy(data);
|
||||||
|
#endif
|
||||||
sp<IMemory> bitmap = captureFrame();
|
sp<IMemory> bitmap = captureFrame();
|
||||||
if (bitmap != 0) { // Don't send NULL across the binder interface
|
if (bitmap != 0) { // Don't send NULL across the binder interface
|
||||||
reply->writeInt32(NO_ERROR);
|
reply->writeInt32(NO_ERROR);
|
||||||
@@ -176,10 +233,16 @@ status_t BnMediaMetadataRetriever::onTransact(
|
|||||||
} else {
|
} else {
|
||||||
reply->writeInt32(UNKNOWN_ERROR);
|
reply->writeInt32(UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
restoreSchedPolicy();
|
||||||
|
#endif
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} break;
|
} break;
|
||||||
case EXTARCT_ALBUM_ART: {
|
case EXTRACT_ALBUM_ART: {
|
||||||
CHECK_INTERFACE(IMediaMetadataRetriever, data, reply);
|
CHECK_INTERFACE(IMediaMetadataRetriever, data, reply);
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
setSchedPolicy(data);
|
||||||
|
#endif
|
||||||
sp<IMemory> albumArt = extractAlbumArt();
|
sp<IMemory> albumArt = extractAlbumArt();
|
||||||
if (albumArt != 0) { // Don't send NULL across the binder interface
|
if (albumArt != 0) { // Don't send NULL across the binder interface
|
||||||
reply->writeInt32(NO_ERROR);
|
reply->writeInt32(NO_ERROR);
|
||||||
@@ -187,10 +250,16 @@ status_t BnMediaMetadataRetriever::onTransact(
|
|||||||
} else {
|
} else {
|
||||||
reply->writeInt32(UNKNOWN_ERROR);
|
reply->writeInt32(UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
restoreSchedPolicy();
|
||||||
|
#endif
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} break;
|
} break;
|
||||||
case EXTRACT_METADATA: {
|
case EXTRACT_METADATA: {
|
||||||
CHECK_INTERFACE(IMediaMetadataRetriever, data, reply);
|
CHECK_INTERFACE(IMediaMetadataRetriever, data, reply);
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
setSchedPolicy(data);
|
||||||
|
#endif
|
||||||
int keyCode = data.readInt32();
|
int keyCode = data.readInt32();
|
||||||
const char* value = extractMetadata(keyCode);
|
const char* value = extractMetadata(keyCode);
|
||||||
if (value != NULL) { // Don't send NULL across the binder interface
|
if (value != NULL) { // Don't send NULL across the binder interface
|
||||||
@@ -199,6 +268,9 @@ status_t BnMediaMetadataRetriever::onTransact(
|
|||||||
} else {
|
} else {
|
||||||
reply->writeInt32(UNKNOWN_ERROR);
|
reply->writeInt32(UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
|
#ifndef DISABLE_GROUP_SCHEDULE_HACK
|
||||||
|
restoreSchedPolicy();
|
||||||
|
#endif
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -237,7 +237,6 @@ sp<IMemory> MetadataRetrieverClient::captureFrame()
|
|||||||
{
|
{
|
||||||
LOGV("captureFrame");
|
LOGV("captureFrame");
|
||||||
Mutex::Autolock lock(mLock);
|
Mutex::Autolock lock(mLock);
|
||||||
Priority priority(ANDROID_PRIORITY_BACKGROUND);
|
|
||||||
mThumbnail.clear();
|
mThumbnail.clear();
|
||||||
mThumbnailDealer.clear();
|
mThumbnailDealer.clear();
|
||||||
if (mRetriever == NULL) {
|
if (mRetriever == NULL) {
|
||||||
@@ -279,7 +278,6 @@ sp<IMemory> MetadataRetrieverClient::extractAlbumArt()
|
|||||||
{
|
{
|
||||||
LOGV("extractAlbumArt");
|
LOGV("extractAlbumArt");
|
||||||
Mutex::Autolock lock(mLock);
|
Mutex::Autolock lock(mLock);
|
||||||
Priority priority(ANDROID_PRIORITY_BACKGROUND);
|
|
||||||
mAlbumArt.clear();
|
mAlbumArt.clear();
|
||||||
mAlbumArtDealer.clear();
|
mAlbumArtDealer.clear();
|
||||||
if (mRetriever == NULL) {
|
if (mRetriever == NULL) {
|
||||||
@@ -321,19 +319,7 @@ const char* MetadataRetrieverClient::extractMetadata(int keyCode)
|
|||||||
LOGE("retriever is not initialized");
|
LOGE("retriever is not initialized");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Priority priority(ANDROID_PRIORITY_BACKGROUND);
|
|
||||||
return mRetriever->extractMetadata(keyCode);
|
return mRetriever->extractMetadata(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataRetrieverClient::Priority::Priority(int newPriority)
|
|
||||||
{
|
|
||||||
mOldPriority = getpriority(PRIO_PROCESS, 0);
|
|
||||||
setpriority(PRIO_PROCESS, 0, newPriority);
|
|
||||||
}
|
|
||||||
|
|
||||||
MetadataRetrieverClient::Priority::~Priority()
|
|
||||||
{
|
|
||||||
setpriority(PRIO_PROCESS, 0, mOldPriority);
|
|
||||||
}
|
|
||||||
|
|
||||||
}; // namespace android
|
}; // namespace android
|
||||||
|
|||||||
@@ -54,16 +54,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class MediaPlayerService;
|
friend class MediaPlayerService;
|
||||||
|
|
||||||
class Priority
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Priority(int newPriority);
|
|
||||||
~Priority();
|
|
||||||
private:
|
|
||||||
Priority();
|
|
||||||
int mOldPriority;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit MetadataRetrieverClient(pid_t pid);
|
explicit MetadataRetrieverClient(pid_t pid);
|
||||||
virtual ~MetadataRetrieverClient();
|
virtual ~MetadataRetrieverClient();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user