mediametadataretriever.h revision 2729ea9262ca60d93047e984739887cfc89e82eb
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#ifndef MEDIAMETADATARETRIEVER_H
19#define MEDIAMETADATARETRIEVER_H
20
21#include <graphics/SkBitmap.h>      // for SkBitmap
22
23namespace android {
24
25// Keep these in synch with the constants defined in MediaMetadataRetriever.java
26// class.
27enum {
28    METADATA_KEY_CD_TRACK_NUMBER = 0,
29    METADATA_KEY_ALBUM           = 1,
30    METADATA_KEY_ARTIST          = 2,
31    METADATA_KEY_AUTHOR          = 3,
32    METADATA_KEY_COMPOSER        = 4,
33    METADATA_KEY_DATE            = 5,
34    METADATA_KEY_GENRE           = 6,
35    METADATA_KEY_TITLE           = 7,
36    METADATA_KEY_YEAR            = 8,
37    METADATA_KEY_DURATION        = 9,
38    METADATA_KEY_NUM_TRACKS      = 10,
39    METADATA_KEY_IS_DRM_CRIPPLED = 11,
40    METADATA_KEY_CODEC           = 12,
41    // Add more here...
42};
43
44// A utility class that holds the size and actual data in album art.
45class MediaAlbumArt {
46public:
47    MediaAlbumArt(): length(0), data(NULL) {}
48    MediaAlbumArt(const MediaAlbumArt& copy) {
49        // Don't be caught by uninitialized variables!!
50        length = 0;
51        data = NULL;
52        setData(copy.length, copy.data);
53    }
54    MediaAlbumArt(const char* url);
55    ~MediaAlbumArt() { clearData(); }
56
57    void clearData();
58    status_t setData(unsigned int len, const char* buf);
59    char *getData() const { return copyData(length, data); }
60    unsigned int getLength() const { return length; }
61
62private:
63    // Disable copy assignment operator!
64    MediaAlbumArt& operator=(const MediaAlbumArt& rhs);
65    static char* copyData(unsigned int len, const char* buf);
66
67    unsigned int length;    // Number of bytes in data.
68    char *data;             // Actual binary data.
69};
70
71class MediaMetadataRetrieverImpl
72{
73public:
74    virtual ~MediaMetadataRetrieverImpl() {};
75    virtual status_t setDataSource(const char* dataSourceUrl) = 0;
76    virtual SkBitmap *captureFrame() = 0;
77    virtual const char* extractMetadata(int keyCode) = 0;
78    virtual MediaAlbumArt* extractAlbumArt() = 0;
79    virtual void setMode(int mode) = 0;
80};
81
82class MediaMetadataRetriever
83{
84public:
85    static status_t setDataSource(const char* dataSourceUrl);
86    static SkBitmap *captureFrame();
87    static const char* extractMetadata(int keyCode);
88    static MediaAlbumArt* extractAlbumArt();
89    static void setMode(int mode);
90    static void release();
91    static void create();
92
93private:
94    MediaMetadataRetriever() {}
95    static MediaMetadataRetrieverImpl *mRetriever;
96    static void                       *mLibHandler;
97};
98
99}; // namespace android
100
101#endif // MEDIAMETADATARETRIEVER_H
102