1/*
2 * Copyright (C) 2009 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 MEDIA_EXTRACTOR_H_
18
19#define MEDIA_EXTRACTOR_H_
20
21#include <media/IMediaExtractor.h>
22#include <media/IMediaSource.h>
23#include <media/MediaAnalyticsItem.h>
24
25namespace android {
26namespace media {
27class ICas;
28};
29using namespace media;
30class DataSource;
31struct MediaSource;
32class MetaData;
33
34class MediaExtractor : public BnMediaExtractor {
35public:
36    static sp<IMediaExtractor> Create(
37            const sp<DataSource> &source, const char *mime = NULL);
38    static sp<MediaExtractor> CreateFromService(
39            const sp<DataSource> &source, const char *mime = NULL);
40
41    virtual size_t countTracks() = 0;
42    virtual sp<IMediaSource> getTrack(size_t index) = 0;
43
44    enum GetTrackMetaDataFlags {
45        kIncludeExtensiveMetaData = 1
46    };
47    virtual sp<MetaData> getTrackMetaData(
48            size_t index, uint32_t flags = 0) = 0;
49
50    // Return container specific meta-data. The default implementation
51    // returns an empty metadata object.
52    virtual sp<MetaData> getMetaData();
53
54    status_t getMetrics(Parcel *reply);
55
56    enum Flags {
57        CAN_SEEK_BACKWARD  = 1,  // the "seek 10secs back button"
58        CAN_SEEK_FORWARD   = 2,  // the "seek 10secs forward button"
59        CAN_PAUSE          = 4,
60        CAN_SEEK           = 8,  // the "seek bar"
61    };
62
63    // If subclasses do _not_ override this, the default is
64    // CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_SEEK | CAN_PAUSE
65    virtual uint32_t flags() const;
66
67    // for DRM
68    virtual char* getDrmTrackInfo(size_t /*trackID*/, int * /*len*/) {
69        return NULL;
70    }
71    virtual void setUID(uid_t /*uid*/) {
72    }
73    virtual status_t setMediaCas(const sp<ICas> &cas) override {
74        return INVALID_OPERATION;
75    }
76
77    virtual const char * name() { return "<unspecified>"; }
78
79protected:
80    MediaExtractor();
81    virtual ~MediaExtractor();
82
83    MediaAnalyticsItem *mAnalyticsItem;
84
85    virtual void populateMetrics();
86
87private:
88
89    typedef bool (*SnifferFunc)(
90            const sp<DataSource> &source, String8 *mimeType,
91            float *confidence, sp<AMessage> *meta);
92
93    static Mutex gSnifferMutex;
94    static List<SnifferFunc> gSniffers;
95    static bool gSniffersRegistered;
96
97    // The sniffer can optionally fill in "meta" with an AMessage containing
98    // a dictionary of values that helps the corresponding extractor initialize
99    // its state without duplicating effort already exerted by the sniffer.
100    static void RegisterSniffer_l(SnifferFunc func);
101
102    static bool sniff(const sp<DataSource> &source,
103            String8 *mimeType, float *confidence, sp<AMessage> *meta);
104
105    static void RegisterDefaultSniffers();
106
107    MediaExtractor(const MediaExtractor &);
108    MediaExtractor &operator=(const MediaExtractor &);
109};
110
111}  // namespace android
112
113#endif  // MEDIA_EXTRACTOR_H_
114