Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c0d20a7 authored by Dave Sparks's avatar Dave Sparks
Browse files

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.
parent 6897e36b
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@


#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <dirent.h>
#include <dirent.h>
#include <unistd.h>
#include <unistd.h>


@@ -38,6 +39,18 @@
#include "MidiMetadataRetriever.h"
#include "MidiMetadataRetriever.h"
#include "MetadataRetrieverClient.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 {
namespace android {


extern player_type getPlayerType(const char* url);
extern player_type getPlayerType(const char* url);
@@ -212,6 +225,7 @@ 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) {
@@ -253,6 +267,7 @@ 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) {
@@ -294,7 +309,19 @@ 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
+10 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,16 @@ 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();