Run the metadataretriever at background priority. Bug 2187133.

This change forces metadata retreiver threads to background priority.
Uses an inner class to encapsulate the priority change so that it
automatically restores priority when returning to the client.
This commit is contained in:
Dave Sparks
2009-10-26 16:28:26 -07:00
parent 6897e36b89
commit 7c0d20a753
2 changed files with 37 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <dirent.h>
#include <unistd.h>
@@ -38,6 +39,18 @@
#include "MidiMetadataRetriever.h"
#include "MetadataRetrieverClient.h"
/* 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
namespace android {
extern player_type getPlayerType(const char* url);
@@ -212,6 +225,7 @@ sp<IMemory> MetadataRetrieverClient::captureFrame()
{
LOGV("captureFrame");
Mutex::Autolock lock(mLock);
Priority priority(ANDROID_PRIORITY_BACKGROUND);
mThumbnail.clear();
mThumbnailDealer.clear();
if (mRetriever == NULL) {
@@ -253,6 +267,7 @@ sp<IMemory> MetadataRetrieverClient::extractAlbumArt()
{
LOGV("extractAlbumArt");
Mutex::Autolock lock(mLock);
Priority priority(ANDROID_PRIORITY_BACKGROUND);
mAlbumArt.clear();
mAlbumArtDealer.clear();
if (mRetriever == NULL) {
@@ -294,7 +309,19 @@ const char* MetadataRetrieverClient::extractMetadata(int keyCode)
LOGE("retriever is not initialized");
return NULL;
}
Priority priority(ANDROID_PRIORITY_BACKGROUND);
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

View File

@@ -54,6 +54,16 @@ public:
private:
friend class MediaPlayerService;
class Priority
{
public:
Priority(int newPriority);
~Priority();
private:
Priority();
int mOldPriority;
};
explicit MetadataRetrieverClient(pid_t pid);
virtual ~MetadataRetrieverClient();