1 /*
2  * Copyright (C) 2010 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 #ifndef STAGEFRIGHT_METADATA_RETRIEVER_H_
18 
19 #define STAGEFRIGHT_METADATA_RETRIEVER_H_
20 
21 #include <android/IMediaExtractor.h>
22 #include <media/MediaMetadataRetrieverInterface.h>
23 
24 #include <utils/KeyedVector.h>
25 
26 namespace android {
27 
28 class DataSource;
29 struct FrameDecoder;
30 struct FrameRect;
31 
32 struct StagefrightMetadataRetriever : public MediaMetadataRetrieverBase {
33     StagefrightMetadataRetriever();
34     virtual ~StagefrightMetadataRetriever();
35 
36     virtual status_t setDataSource(
37             const sp<IMediaHTTPService> &httpService,
38             const char *url,
39             const KeyedVector<String8, String8> *headers);
40 
41     virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
42     virtual status_t setDataSource(const sp<DataSource>& source, const char *mime);
43 
44     virtual sp<IMemory> getFrameAtTime(
45             int64_t timeUs, int option, int colorFormat, bool metaOnly);
46     virtual sp<IMemory> getImageAtIndex(
47             int index, int colorFormat, bool metaOnly, bool thumbnail);
48     virtual sp<IMemory> getImageRectAtIndex(
49             int index, int colorFormat, int left, int top, int right, int bottom);
50     virtual sp<IMemory> getFrameAtIndex(
51             int index, int colorFormat, bool metaOnly);
52 
53     virtual MediaAlbumArt *extractAlbumArt();
54     virtual const char *extractMetadata(int keyCode);
55 
56 private:
57     sp<DataSource> mSource;
58     sp<IMediaExtractor> mExtractor;
59 
60     bool mParsedMetaData;
61     KeyedVector<int, String8> mMetaData;
62     MediaAlbumArt *mAlbumArt;
63 
64     sp<FrameDecoder> mDecoder;
65     int mLastDecodedIndex;
66     void parseMetaData();
67     void parseColorAspects(const sp<MetaData>& meta);
68     // Delete album art and clear metadata.
69     void clearMetadata();
70 
71     sp<IMemory> getFrameInternal(
72             int64_t timeUs, int option, int colorFormat, bool metaOnly);
73 
74     sp<IMemory> getImageInternal(
75             int index, int colorFormat, bool metaOnly, bool thumbnail, FrameRect* rect);
76 
77     StagefrightMetadataRetriever(const StagefrightMetadataRetriever &);
78 
79     StagefrightMetadataRetriever &operator=(
80             const StagefrightMetadataRetriever &);
81 };
82 
83 }  // namespace android
84 
85 #endif  // STAGEFRIGHT_METADATA_RETRIEVER_H_
86