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 
28 namespace android {
29 
30 struct ABuffer;
31 struct MetaData;
32 struct MediaBuffer;
33 
34 struct NuPlayer::Source : public AHandler {
35     enum Flags {
36         FLAG_CAN_PAUSE          = 1,
37         FLAG_CAN_SEEK_BACKWARD  = 2,  // the "10 sec back button"
38         FLAG_CAN_SEEK_FORWARD   = 4,  // the "10 sec forward button"
39         FLAG_CAN_SEEK           = 8,  // the "seek bar"
40         FLAG_DYNAMIC_DURATION   = 16,
41         FLAG_SECURE             = 32,
42         FLAG_PROTECTED          = 64,
43     };
44 
45     enum {
46         kWhatPrepared,
47         kWhatFlagsChanged,
48         kWhatVideoSizeChanged,
49         kWhatBufferingUpdate,
50         kWhatBufferingStart,
51         kWhatBufferingEnd,
52         kWhatPauseOnBufferingStart,
53         kWhatResumeOnBufferingEnd,
54         kWhatCacheStats,
55         kWhatSubtitleData,
56         kWhatTimedTextData,
57         kWhatQueueDecoderShutdown,
58         kWhatDrmNoLicense,
59     };
60 
61     // The provides message is used to notify the player about various
62     // events.
SourceSource63     Source(const sp<AMessage> &notify)
64         : mNotify(notify) {
65     }
66 
67     virtual void prepareAsync() = 0;
68 
69     virtual void start() = 0;
stopSource70     virtual void stop() {}
pauseSource71     virtual void pause() {}
resumeSource72     virtual void resume() {}
73 
74     // Explicitly disconnect the underling data source
disconnectSource75     virtual void disconnect() {}
76 
77     // Returns OK iff more data was available,
78     // an error or ERROR_END_OF_STREAM if not.
79     virtual status_t feedMoreTSData() = 0;
80 
81     virtual sp<AMessage> getFormat(bool audio);
getFormatMetaSource82     virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
getFileFormatMetaSource83     virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
84 
85     virtual status_t dequeueAccessUnit(
86             bool audio, sp<ABuffer> *accessUnit) = 0;
87 
getDurationSource88     virtual status_t getDuration(int64_t * /* durationUs */) {
89         return INVALID_OPERATION;
90     }
91 
getTrackCountSource92     virtual size_t getTrackCount() const {
93         return 0;
94     }
95 
getTrackInfoSource96     virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
97         return NULL;
98     }
99 
getSelectedTrackSource100     virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
101         return INVALID_OPERATION;
102     }
103 
selectTrackSource104     virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
105         return INVALID_OPERATION;
106     }
107 
seekToSource108     virtual status_t seekTo(int64_t /* seekTimeUs */) {
109         return INVALID_OPERATION;
110     }
111 
setBuffersSource112     virtual status_t setBuffers(bool /* audio */, Vector<MediaBuffer *> &/* buffers */) {
113         return INVALID_OPERATION;
114     }
115 
isRealTimeSource116     virtual bool isRealTime() const {
117         return false;
118     }
119 
120 protected:
~SourceSource121     virtual ~Source() {}
122 
123     virtual void onMessageReceived(const sp<AMessage> &msg);
124 
dupNotifySource125     sp<AMessage> dupNotify() const { return mNotify->dup(); }
126 
127     void notifyFlagsChanged(uint32_t flags);
128     void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
129     void notifyPrepared(status_t err = OK);
130 
131 private:
132     sp<AMessage> mNotify;
133 
134     DISALLOW_EVIL_CONSTRUCTORS(Source);
135 };
136 
137 }  // namespace android
138 
139 #endif  // NUPLAYER_SOURCE_H_
140 
141