Home | History | Annotate | Download | only in media
      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 <utils/Errors.h>  // for status_t
     22 #include <utils/threads.h>
     23 #include <binder/IMemory.h>
     24 #include <media/IMediaMetadataRetriever.h>
     25 
     26 namespace android {
     27 
     28 class IDataSource;
     29 struct IMediaHTTPService;
     30 class IMediaPlayerService;
     31 class IMediaMetadataRetriever;
     32 
     33 // Keep these in synch with the constants defined in MediaMetadataRetriever.java
     34 // class.
     35 enum {
     36     METADATA_KEY_CD_TRACK_NUMBER = 0,
     37     METADATA_KEY_ALBUM           = 1,
     38     METADATA_KEY_ARTIST          = 2,
     39     METADATA_KEY_AUTHOR          = 3,
     40     METADATA_KEY_COMPOSER        = 4,
     41     METADATA_KEY_DATE            = 5,
     42     METADATA_KEY_GENRE           = 6,
     43     METADATA_KEY_TITLE           = 7,
     44     METADATA_KEY_YEAR            = 8,
     45     METADATA_KEY_DURATION        = 9,
     46     METADATA_KEY_NUM_TRACKS      = 10,
     47     METADATA_KEY_WRITER          = 11,
     48     METADATA_KEY_MIMETYPE        = 12,
     49     METADATA_KEY_ALBUMARTIST     = 13,
     50     METADATA_KEY_DISC_NUMBER     = 14,
     51     METADATA_KEY_COMPILATION     = 15,
     52     METADATA_KEY_HAS_AUDIO       = 16,
     53     METADATA_KEY_HAS_VIDEO       = 17,
     54     METADATA_KEY_VIDEO_WIDTH     = 18,
     55     METADATA_KEY_VIDEO_HEIGHT    = 19,
     56     METADATA_KEY_BITRATE         = 20,
     57     METADATA_KEY_TIMED_TEXT_LANGUAGES      = 21,
     58     METADATA_KEY_IS_DRM          = 22,
     59     METADATA_KEY_LOCATION        = 23,
     60     METADATA_KEY_VIDEO_ROTATION  = 24,
     61     METADATA_KEY_CAPTURE_FRAMERATE = 25,
     62     METADATA_KEY_HAS_IMAGE       = 26,
     63     METADATA_KEY_IMAGE_COUNT     = 27,
     64     METADATA_KEY_IMAGE_PRIMARY   = 28,
     65     METADATA_KEY_IMAGE_WIDTH     = 29,
     66     METADATA_KEY_IMAGE_HEIGHT    = 30,
     67     METADATA_KEY_IMAGE_ROTATION  = 31,
     68     METADATA_KEY_VIDEO_FRAME_COUNT  = 32,
     69     METADATA_KEY_EXIF_OFFSET     = 33,
     70     METADATA_KEY_EXIF_LENGTH     = 34,
     71 
     72     // Add more here...
     73 };
     74 
     75 class MediaMetadataRetriever: public RefBase
     76 {
     77 public:
     78     MediaMetadataRetriever();
     79     ~MediaMetadataRetriever();
     80     void disconnect();
     81 
     82     status_t setDataSource(
     83             const sp<IMediaHTTPService> &httpService,
     84             const char *dataSourceUrl,
     85             const KeyedVector<String8, String8> *headers = NULL);
     86 
     87     status_t setDataSource(int fd, int64_t offset, int64_t length);
     88     status_t setDataSource(
     89             const sp<IDataSource>& dataSource, const char *mime = NULL);
     90     sp<IMemory> getFrameAtTime(int64_t timeUs, int option,
     91             int colorFormat = HAL_PIXEL_FORMAT_RGB_565, bool metaOnly = false);
     92     sp<IMemory> getImageAtIndex(int index,
     93             int colorFormat = HAL_PIXEL_FORMAT_RGB_565, bool metaOnly = false, bool thumbnail = false);
     94     sp<IMemory> getImageRectAtIndex(
     95             int index, int colorFormat, int left, int top, int right, int bottom);
     96     status_t getFrameAtIndex(
     97             std::vector<sp<IMemory> > *frames, int frameIndex, int numFrames = 1,
     98             int colorFormat = HAL_PIXEL_FORMAT_RGB_565, bool metaOnly = false);
     99     sp<IMemory> extractAlbumArt();
    100     const char* extractMetadata(int keyCode);
    101 
    102 private:
    103     static const sp<IMediaPlayerService> getService();
    104 
    105     class DeathNotifier: public IBinder::DeathRecipient
    106     {
    107     public:
    108         DeathNotifier() {}
    109         virtual ~DeathNotifier();
    110         virtual void binderDied(const wp<IBinder>& who);
    111     };
    112 
    113     static sp<DeathNotifier>                  sDeathNotifier;
    114     static Mutex                              sServiceLock;
    115     static sp<IMediaPlayerService>            sService;
    116 
    117     Mutex                                     mLock;
    118     sp<IMediaMetadataRetriever>               mRetriever;
    119 
    120 };
    121 
    122 }; // namespace android
    123 
    124 #endif // MEDIAMETADATARETRIEVER_H
    125