• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <mediadrm/ICrypto.h>
24 #include <media/mediaplayer.h>
25 #include <media/stagefright/foundation/AMessage.h>
26 #include <media/stagefright/MetaData.h>
27 #include <utils/Vector.h>
28 
29 namespace android {
30 
31 struct ABuffer;
32 class 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, // Secure codec is required.
42         FLAG_PROTECTED          = 64, // The screen needs to be protected (screenshot is disabled).
43     };
44 
45     enum {
46         kWhatPrepared,
47         kWhatFlagsChanged,
48         kWhatVideoSizeChanged,
49         kWhatBufferingUpdate,
50         kWhatPauseOnBufferingStart,
51         kWhatResumeOnBufferingEnd,
52         kWhatCacheStats,
53         kWhatSubtitleData,
54         kWhatTimedTextData,
55         kWhatTimedMetaData,
56         kWhatQueueDecoderShutdown,
57         kWhatDrmNoLicense,
58         kWhatInstantiateSecureDecoders,
59         // Modular DRM
60         kWhatDrmInfo,
61         kWhatIMSRxNotice,
62     };
63 
64     // The provides message is used to notify the player about various
65     // events.
SourceSource66     explicit Source(const sp<AMessage> &notify)
67         : mNotify(notify) {
68     }
69 
70     virtual status_t getBufferingSettings(
71             BufferingSettings* buffering /* nonnull */) = 0;
72     virtual status_t setBufferingSettings(const BufferingSettings& buffering) = 0;
73 
74     virtual void prepareAsync() = 0;
75 
76     virtual void start() = 0;
stopSource77     virtual void stop() {}
pauseSource78     virtual void pause() {}
resumeSource79     virtual void resume() {}
80 
81     // Explicitly disconnect the underling data source
disconnectSource82     virtual void disconnect() {}
83 
84     // Returns OK iff more data was available,
85     // an error or ERROR_END_OF_STREAM if not.
86     virtual status_t feedMoreTSData() = 0;
87 
88     // Returns non-NULL format when the specified track exists.
89     // When the format has "err" set to -EWOULDBLOCK, source needs more time to get valid meta data.
90     // Returns NULL if the specified track doesn't exist or is invalid;
91     virtual sp<AMessage> getFormat(bool audio);
92 
getFormatMetaSource93     virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
getFileFormatMetaSource94     virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
95 
96     virtual status_t dequeueAccessUnit(
97             bool audio, sp<ABuffer> *accessUnit) = 0;
98 
getDurationSource99     virtual status_t getDuration(int64_t * /* durationUs */) {
100         return INVALID_OPERATION;
101     }
102 
getTrackCountSource103     virtual size_t getTrackCount() const {
104         return 0;
105     }
106 
getTrackInfoSource107     virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
108         return NULL;
109     }
110 
getSelectedTrackSource111     virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
112         return INVALID_OPERATION;
113     }
114 
selectTrackSource115     virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) {
116         return INVALID_OPERATION;
117     }
118 
119     virtual status_t seekTo(
120             int64_t /* seekTimeUs */,
121             MediaPlayerSeekMode /* mode */ = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) {
122         return INVALID_OPERATION;
123     }
124 
isRealTimeSource125     virtual bool isRealTime() const {
126         return false;
127     }
128 
isStreamingSource129     virtual bool isStreaming() const {
130         return true;
131     }
132 
setOffloadAudioSource133     virtual void setOffloadAudio(bool /* offload */) {}
134 
setTargetBitrateSource135     virtual void setTargetBitrate(int32_t) {}
136 
137     // Modular DRM
prepareDrmSource138     virtual status_t prepareDrm(
139             const uint8_t /*uuid*/[16], const Vector<uint8_t> &/*drmSessionId*/,
140             sp<ICrypto> */*crypto*/) {
141         return INVALID_OPERATION;
142     }
143 
releaseDrmSource144     virtual status_t releaseDrm() {
145         return INVALID_OPERATION;
146     }
147 
148 protected:
~SourceSource149     virtual ~Source() {}
150 
151     virtual void onMessageReceived(const sp<AMessage> &msg);
152 
dupNotifySource153     sp<AMessage> dupNotify() const { return mNotify->dup(); }
154 
155     void notifyFlagsChanged(uint32_t flags);
156     void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
157     void notifyInstantiateSecureDecoders(const sp<AMessage> &reply);
158     void notifyPrepared(status_t err = OK);
159     // Modular DRM
160     void notifyDrmInfo(const sp<ABuffer> &buffer);
161 
162 private:
163     sp<AMessage> mNotify;
164 
165     DISALLOW_EVIL_CONSTRUCTORS(Source);
166 };
167 
168 }  // namespace android
169 
170 #endif  // NUPLAYER_SOURCE_H_
171 
172