NuPlayerSource.h revision 48fa06d1e80a872c7495804979256e021e566ae0
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 NUPLAYER_SOURCE_H_
18
19#define NUPLAYER_SOURCE_H_
20
21#include "NuPlayer.h"
22
23#include <media/stagefright/foundation/AMessage.h>
24#include <media/stagefright/MetaData.h>
25#include <media/mediaplayer.h>
26#include <utils/Vector.h>
27
28namespace android {
29
30struct ABuffer;
31class MediaBuffer;
32
33struct NuPlayer::Source : public AHandler {
34    enum Flags {
35        FLAG_CAN_PAUSE          = 1,
36        FLAG_CAN_SEEK_BACKWARD  = 2,  // the "10 sec back button"
37        FLAG_CAN_SEEK_FORWARD   = 4,  // the "10 sec forward button"
38        FLAG_CAN_SEEK           = 8,  // the "seek bar"
39        FLAG_DYNAMIC_DURATION   = 16,
40        FLAG_SECURE             = 32,
41        FLAG_PROTECTED          = 64,
42    };
43
44    enum {
45        kWhatPrepared,
46        kWhatFlagsChanged,
47        kWhatVideoSizeChanged,
48        kWhatBufferingUpdate,
49        kWhatPauseOnBufferingStart,
50        kWhatResumeOnBufferingEnd,
51        kWhatCacheStats,
52        kWhatSubtitleData,
53        kWhatTimedTextData,
54        kWhatTimedMetaData,
55        kWhatQueueDecoderShutdown,
56        kWhatDrmNoLicense,
57        kWhatInstantiateSecureDecoders,
58    };
59
60    // The provides message is used to notify the player about various
61    // events.
62    explicit Source(const sp<AMessage> &notify)
63        : mNotify(notify) {
64    }
65
66    virtual status_t getDefaultBufferingSettings(
67            BufferingSettings* buffering /* nonnull */) = 0;
68    virtual status_t setBufferingSettings(const BufferingSettings& buffering) = 0;
69
70    virtual void prepareAsync() = 0;
71
72    virtual void start() = 0;
73    virtual void stop() {}
74    virtual void pause() {}
75    virtual void resume() {}
76
77    // Explicitly disconnect the underling data source
78    virtual void disconnect() {}
79
80    // Returns OK iff more data was available,
81    // an error or ERROR_END_OF_STREAM if not.
82    virtual status_t feedMoreTSData() = 0;
83
84    virtual sp<AMessage> getFormat(bool audio);
85    virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
86    virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
87
88    virtual status_t dequeueAccessUnit(
89            bool audio, sp<ABuffer> *accessUnit) = 0;
90
91    virtual status_t getDuration(int64_t * /* durationUs */) {
92        return INVALID_OPERATION;
93    }
94
95    virtual size_t getTrackCount() const {
96        return 0;
97    }
98
99    virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
100        return NULL;
101    }
102
103    virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
104        return INVALID_OPERATION;
105    }
106
107    virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
108        return INVALID_OPERATION;
109    }
110
111    virtual status_t seekTo(
112            int64_t /* seekTimeUs */,
113            MediaPlayerSeekMode /* mode */ = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) {
114        return INVALID_OPERATION;
115    }
116
117    virtual status_t setBuffers(bool /* audio */, Vector<MediaBuffer *> &/* buffers */) {
118        return INVALID_OPERATION;
119    }
120
121    virtual bool isRealTime() const {
122        return false;
123    }
124
125    virtual bool isStreaming() const {
126        return true;
127    }
128
129    virtual void setOffloadAudio(bool /* offload */) {}
130
131protected:
132    virtual ~Source() {}
133
134    virtual void onMessageReceived(const sp<AMessage> &msg);
135
136    sp<AMessage> dupNotify() const { return mNotify->dup(); }
137
138    void notifyFlagsChanged(uint32_t flags);
139    void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
140    void notifyInstantiateSecureDecoders(const sp<AMessage> &reply);
141    void notifyPrepared(status_t err = OK);
142
143private:
144    sp<AMessage> mNotify;
145
146    DISALLOW_EVIL_CONSTRUCTORS(Source);
147};
148
149}  // namespace android
150
151#endif  // NUPLAYER_SOURCE_H_
152
153