From f3e80dddd7376aa9deeb27de25e1d50030a2ad98 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 10 Jun 2014 16:55:38 -0700 Subject: Offer a type-safe album art interface. Bug: 15514223 Change-Id: Iddfc33a00e6cd3779ca09c01a55f62b151f6ec95 --- include/media/MediaMetadataRetrieverInterface.h | 1 + include/media/mediascanner.h | 28 ++++++++++- .../media/stagefright/StagefrightMediaScanner.h | 2 +- include/private/media/VideoFrame.h | 58 ---------------------- 4 files changed, 28 insertions(+), 61 deletions(-) (limited to 'include') diff --git a/include/media/MediaMetadataRetrieverInterface.h b/include/media/MediaMetadataRetrieverInterface.h index ecc3b65..cd5bf88 100644 --- a/include/media/MediaMetadataRetrieverInterface.h +++ b/include/media/MediaMetadataRetrieverInterface.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace android { diff --git a/include/media/mediascanner.h b/include/media/mediascanner.h index a73403b..a7bb6c1 100644 --- a/include/media/mediascanner.h +++ b/include/media/mediascanner.h @@ -41,6 +41,31 @@ enum MediaScanResult { MEDIA_SCAN_RESULT_ERROR, }; +struct MediaAlbumArt { +public: + static MediaAlbumArt *fromData(int32_t size, const void* data); + + static void init(MediaAlbumArt* instance, int32_t size, const void* data); + + MediaAlbumArt *clone(); + + const char *data() { + return &mData[0]; + } + + int32_t size() { + return mSize; + } + +private: + int32_t mSize; + char mData[0]; + + // You can't construct instances of this class directly because this is a + // variable-sized object passed through the binder. + MediaAlbumArt(); +} __packed; + struct MediaScanner { MediaScanner(); virtual ~MediaScanner(); @@ -53,8 +78,7 @@ struct MediaScanner { void setLocale(const char *locale); - // extracts album art as a block of data - virtual char *extractAlbumArt(int fd) = 0; + virtual MediaAlbumArt *extractAlbumArt(int fd) = 0; protected: const char *locale() const; diff --git a/include/media/stagefright/StagefrightMediaScanner.h b/include/media/stagefright/StagefrightMediaScanner.h index 6510a59..eb3accc 100644 --- a/include/media/stagefright/StagefrightMediaScanner.h +++ b/include/media/stagefright/StagefrightMediaScanner.h @@ -30,7 +30,7 @@ struct StagefrightMediaScanner : public MediaScanner { const char *path, const char *mimeType, MediaScannerClient &client); - virtual char *extractAlbumArt(int fd); + virtual MediaAlbumArt *extractAlbumArt(int fd); private: StagefrightMediaScanner(const StagefrightMediaScanner &); diff --git a/include/private/media/VideoFrame.h b/include/private/media/VideoFrame.h index a211ed9..5dd425b 100644 --- a/include/private/media/VideoFrame.h +++ b/include/private/media/VideoFrame.h @@ -25,64 +25,6 @@ namespace android { -// A simple buffer to hold binary data -class MediaAlbumArt -{ -public: - MediaAlbumArt(): mSize(0), mData(0) {} - - explicit MediaAlbumArt(const char* url) { - mSize = 0; - mData = NULL; - FILE *in = fopen(url, "r"); - if (!in) { - return; - } - fseek(in, 0, SEEK_END); - mSize = ftell(in); // Allocating buffer of size equals to the external file size. - if (mSize == 0 || (mData = new uint8_t[mSize]) == NULL) { - fclose(in); - if (mSize != 0) { - mSize = 0; - } - return; - } - rewind(in); - if (fread(mData, 1, mSize, in) != mSize) { // Read failed. - delete[] mData; - mData = NULL; - mSize = 0; - return; - } - fclose(in); - } - - MediaAlbumArt(const MediaAlbumArt& copy) { - mSize = copy.mSize; - mData = NULL; // initialize it first - if (mSize > 0 && copy.mData != NULL) { - mData = new uint8_t[copy.mSize]; - if (mData != NULL) { - memcpy(mData, copy.mData, mSize); - } else { - mSize = 0; - } - } - } - - ~MediaAlbumArt() { - if (mData != 0) { - delete[] mData; - } - } - - // Intentional public access modifier: - // We have to know the internal structure in order to share it between - // processes? - uint32_t mSize; // Number of bytes in mData - uint8_t* mData; // Actual binary data -}; - // Represents a color converted (RGB-based) video frame // with bitmap pixels stored in FrameBuffer class VideoFrame -- cgit v1.1