Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 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 | |
Marco Nelissen | 13aa1a4 | 2019-09-27 10:21:55 -0700 | [diff] [blame] | 23 | #include <mediadrm/ICrypto.h> |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 24 | #include <media/mediaplayer.h> |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 25 | #include <media/stagefright/foundation/AMessage.h> |
Lajos Molnar | cc22703 | 2014-07-17 15:33:06 -0700 | [diff] [blame] | 26 | #include <media/stagefright/MetaData.h> |
| 27 | #include <utils/Vector.h> |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 28 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | struct ABuffer; |
Lajos Molnar | ee4e1b1 | 2015-04-17 13:46:19 -0700 | [diff] [blame] | 32 | class MediaBuffer; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 33 | |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 34 | struct NuPlayer::Source : public AHandler { |
Andreas Huber | b7c8e91 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 35 | enum Flags { |
Andreas Huber | 9575c96 | 2013-02-05 13:59:56 -0800 | [diff] [blame] | 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, |
Hassan Shojania | 838be39 | 2017-05-23 14:14:24 -0700 | [diff] [blame] | 41 | FLAG_SECURE = 32, // Secure codec is required. |
| 42 | FLAG_PROTECTED = 64, // The screen needs to be protected (screenshot is disabled). |
Andreas Huber | 9575c96 | 2013-02-05 13:59:56 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | enum { |
| 46 | kWhatPrepared, |
| 47 | kWhatFlagsChanged, |
| 48 | kWhatVideoSizeChanged, |
Chong Zhang | 2a3cc9a | 2014-08-21 17:48:26 -0700 | [diff] [blame] | 49 | kWhatBufferingUpdate, |
Chong Zhang | efbb619 | 2015-01-30 17:13:27 -0800 | [diff] [blame] | 50 | kWhatPauseOnBufferingStart, |
| 51 | kWhatResumeOnBufferingEnd, |
| 52 | kWhatCacheStats, |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame] | 53 | kWhatSubtitleData, |
Robert Shih | d3b0bbb | 2014-07-23 15:00:25 -0700 | [diff] [blame] | 54 | kWhatTimedTextData, |
Robert Shih | 0852843 | 2015-04-08 09:06:54 -0700 | [diff] [blame] | 55 | kWhatTimedMetaData, |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 56 | kWhatQueueDecoderShutdown, |
Ronghua Wu | 8027687 | 2014-08-28 15:50:29 -0700 | [diff] [blame] | 57 | kWhatDrmNoLicense, |
Lajos Molnar | fcd3e94 | 2015-03-31 10:06:48 -0700 | [diff] [blame] | 58 | kWhatInstantiateSecureDecoders, |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 59 | // Modular DRM |
| 60 | kWhatDrmInfo, |
Kim Sungyeon | d3c6b32 | 2018-03-02 14:41:19 +0900 | [diff] [blame] | 61 | kWhatIMSRxNotice, |
Andreas Huber | b7c8e91 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 64 | // The provides message is used to notify the player about various |
| 65 | // events. |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 66 | explicit Source(const sp<AMessage> ¬ify) |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 67 | : mNotify(notify) { |
| 68 | } |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 69 | |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 70 | virtual status_t getBufferingSettings( |
Wei Jia | 48fa06d | 2016-12-20 15:30:49 -0800 | [diff] [blame] | 71 | BufferingSettings* buffering /* nonnull */) = 0; |
| 72 | virtual status_t setBufferingSettings(const BufferingSettings& buffering) = 0; |
| 73 | |
Andreas Huber | 9575c96 | 2013-02-05 13:59:56 -0800 | [diff] [blame] | 74 | virtual void prepareAsync() = 0; |
| 75 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 76 | virtual void start() = 0; |
Andreas Huber | 2bfdd42 | 2011-10-11 15:24:07 -0700 | [diff] [blame] | 77 | virtual void stop() {} |
Roger Jönsson | fba60da | 2013-01-21 17:15:45 +0100 | [diff] [blame] | 78 | virtual void pause() {} |
| 79 | virtual void resume() {} |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 80 | |
Chong Zhang | 48296b7 | 2014-09-14 14:28:45 -0700 | [diff] [blame] | 81 | // Explicitly disconnect the underling data source |
| 82 | virtual void disconnect() {} |
| 83 | |
Andreas Huber | eac68ba | 2011-09-27 12:12:25 -0700 | [diff] [blame] | 84 | // Returns OK iff more data was available, |
| 85 | // an error or ERROR_END_OF_STREAM if not. |
| 86 | virtual status_t feedMoreTSData() = 0; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 87 | |
Wei Jia | 9737d34 | 2016-12-28 14:59:59 -0800 | [diff] [blame] | 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; |
Andreas Huber | 8406678 | 2011-08-16 09:34:26 -0700 | [diff] [blame] | 91 | virtual sp<AMessage> getFormat(bool audio); |
Wei Jia | 9737d34 | 2016-12-28 14:59:59 -0800 | [diff] [blame] | 92 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 93 | virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; } |
Marco Nelissen | f0b72b5 | 2014-09-16 15:43:44 -0700 | [diff] [blame] | 94 | virtual sp<MetaData> getFileFormatMeta() const { return NULL; } |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 95 | |
| 96 | virtual status_t dequeueAccessUnit( |
| 97 | bool audio, sp<ABuffer> *accessUnit) = 0; |
| 98 | |
Andreas Huber | 84333e0 | 2014-02-07 15:36:10 -0800 | [diff] [blame] | 99 | virtual status_t getDuration(int64_t * /* durationUs */) { |
Andreas Huber | 43c3e6c | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 100 | return INVALID_OPERATION; |
| 101 | } |
| 102 | |
Chong Zhang | 404fced | 2014-06-11 14:45:31 -0700 | [diff] [blame] | 103 | virtual size_t getTrackCount() const { |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const { |
| 108 | return NULL; |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Robert Shih | 7c4f0d7 | 2014-07-09 18:53:31 -0700 | [diff] [blame] | 111 | virtual ssize_t getSelectedTrack(media_track_type /* type */) const { |
| 112 | return INVALID_OPERATION; |
| 113 | } |
| 114 | |
Robert Shih | 6ffb1fd | 2014-10-29 16:24:32 -0700 | [diff] [blame] | 115 | virtual status_t selectTrack(size_t /* trackIndex */, bool /* select */, int64_t /* timeUs*/) { |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame] | 116 | return INVALID_OPERATION; |
| 117 | } |
| 118 | |
Wei Jia | c5de091 | 2016-11-18 10:22:14 -0800 | [diff] [blame] | 119 | virtual status_t seekTo( |
| 120 | int64_t /* seekTimeUs */, |
| 121 | MediaPlayerSeekMode /* mode */ = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) { |
Andreas Huber | 43c3e6c | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 122 | return INVALID_OPERATION; |
| 123 | } |
| 124 | |
Andreas Huber | d5e5623 | 2013-03-12 11:01:43 -0700 | [diff] [blame] | 125 | virtual bool isRealTime() const { |
| 126 | return false; |
| 127 | } |
| 128 | |
Ronghua Wu | 02cb98d | 2015-05-27 11:02:54 -0700 | [diff] [blame] | 129 | virtual bool isStreaming() const { |
| 130 | return true; |
| 131 | } |
| 132 | |
Wei Jia | 14532f2 | 2015-12-29 11:28:15 -0800 | [diff] [blame] | 133 | virtual void setOffloadAudio(bool /* offload */) {} |
| 134 | |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 135 | // Modular DRM |
| 136 | virtual status_t prepareDrm( |
| 137 | const uint8_t /*uuid*/[16], const Vector<uint8_t> &/*drmSessionId*/, |
| 138 | sp<ICrypto> */*crypto*/) { |
| 139 | return INVALID_OPERATION; |
| 140 | } |
| 141 | |
| 142 | virtual status_t releaseDrm() { |
| 143 | return INVALID_OPERATION; |
| 144 | } |
| 145 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 146 | protected: |
| 147 | virtual ~Source() {} |
| 148 | |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 149 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 150 | |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 151 | sp<AMessage> dupNotify() const { return mNotify->dup(); } |
| 152 | |
Andreas Huber | 9575c96 | 2013-02-05 13:59:56 -0800 | [diff] [blame] | 153 | void notifyFlagsChanged(uint32_t flags); |
Chong Zhang | ced1c2f | 2014-08-08 15:22:35 -0700 | [diff] [blame] | 154 | void notifyVideoSizeChanged(const sp<AMessage> &format = NULL); |
Lajos Molnar | fcd3e94 | 2015-03-31 10:06:48 -0700 | [diff] [blame] | 155 | void notifyInstantiateSecureDecoders(const sp<AMessage> &reply); |
Andreas Huber | ec0c597 | 2013-02-05 14:47:13 -0800 | [diff] [blame] | 156 | void notifyPrepared(status_t err = OK); |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 157 | // Modular DRM |
| 158 | void notifyDrmInfo(const sp<ABuffer> &buffer); |
Andreas Huber | 9575c96 | 2013-02-05 13:59:56 -0800 | [diff] [blame] | 159 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 160 | private: |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 161 | sp<AMessage> mNotify; |
| 162 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 163 | DISALLOW_EVIL_CONSTRUCTORS(Source); |
| 164 | }; |
| 165 | |
| 166 | } // namespace android |
| 167 | |
| 168 | #endif // NUPLAYER_SOURCE_H_ |
| 169 | |