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/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 }; 62 63 // The provides message is used to notify the player about various 64 // events. SourceSource65 explicit Source(const sp<AMessage> ¬ify) 66 : mNotify(notify) { 67 } 68 69 virtual status_t getBufferingSettings( 70 BufferingSettings* buffering /* nonnull */) = 0; 71 virtual status_t setBufferingSettings(const BufferingSettings& buffering) = 0; 72 73 virtual void prepareAsync() = 0; 74 75 virtual void start() = 0; stopSource76 virtual void stop() {} pauseSource77 virtual void pause() {} resumeSource78 virtual void resume() {} 79 80 // Explicitly disconnect the underling data source disconnectSource81 virtual void disconnect() {} 82 83 // Returns OK iff more data was available, 84 // an error or ERROR_END_OF_STREAM if not. 85 virtual status_t feedMoreTSData() = 0; 86 87 // Returns non-NULL format when the specified track exists. 88 // When the format has "err" set to -EWOULDBLOCK, source needs more time to get valid meta data. 89 // Returns NULL if the specified track doesn't exist or is invalid; 90 virtual sp<AMessage> getFormat(bool audio); 91 getFormatMetaSource92 virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; } getFileFormatMetaSource93 virtual sp<MetaData> getFileFormatMeta() const { return NULL; } 94 95 virtual status_t dequeueAccessUnit( 96 bool audio, sp<ABuffer> *accessUnit) = 0; 97 getDurationSource98 virtual status_t getDuration(int64_t * /* durationUs */) { 99 return INVALID_OPERATION; 100 } 101 getTrackCountSource102 virtual size_t getTrackCount() const { 103 return 0; 104 } 105 getTrackInfoSource106 virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const { 107 return NULL; 108 } 109 getSelectedTrackSource110 virtual ssize_t getSelectedTrack(media_track_type /* type */) const { 111 return INVALID_OPERATION; 112 } 113 selectTrackSource114 virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) { 115 return INVALID_OPERATION; 116 } 117 118 virtual status_t seekTo( 119 int64_t /* seekTimeUs */, 120 MediaPlayerSeekMode /* mode */ = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) { 121 return INVALID_OPERATION; 122 } 123 isRealTimeSource124 virtual bool isRealTime() const { 125 return false; 126 } 127 isStreamingSource128 virtual bool isStreaming() const { 129 return true; 130 } 131 setOffloadAudioSource132 virtual void setOffloadAudio(bool /* offload */) {} 133 134 // Modular DRM prepareDrmSource135 virtual status_t prepareDrm( 136 const uint8_t /*uuid*/[16], const Vector<uint8_t> &/*drmSessionId*/, 137 sp<ICrypto> */*crypto*/) { 138 return INVALID_OPERATION; 139 } 140 releaseDrmSource141 virtual status_t releaseDrm() { 142 return INVALID_OPERATION; 143 } 144 145 protected: ~SourceSource146 virtual ~Source() {} 147 148 virtual void onMessageReceived(const sp<AMessage> &msg); 149 dupNotifySource150 sp<AMessage> dupNotify() const { return mNotify->dup(); } 151 152 void notifyFlagsChanged(uint32_t flags); 153 void notifyVideoSizeChanged(const sp<AMessage> &format = NULL); 154 void notifyInstantiateSecureDecoders(const sp<AMessage> &reply); 155 void notifyPrepared(status_t err = OK); 156 // Modular DRM 157 void notifyDrmInfo(const sp<ABuffer> &buffer); 158 159 private: 160 sp<AMessage> mNotify; 161 162 DISALLOW_EVIL_CONSTRUCTORS(Source); 163 }; 164 165 } // namespace android 166 167 #endif // NUPLAYER_SOURCE_H_ 168 169