blob: ef57bc08342eb4e4705eb07d7eba4750e189ded2 [file] [log] [blame]
Wei Jia53692fa2017-12-11 10:33:46 -08001/*
2 * Copyright 2017 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 NUPLAYER2_SOURCE_H_
18
19#define NUPLAYER2_SOURCE_H_
20
21#include "NuPlayer2.h"
22
Wei Jia53692fa2017-12-11 10:33:46 -080023#include <media/stagefright/foundation/AMessage.h>
24#include <media/stagefright/MetaData.h>
Wei Jia51b69562018-02-05 16:17:13 -080025#include <mediaplayer2/mediaplayer2.h>
Wei Jia53692fa2017-12-11 10:33:46 -080026#include <utils/Vector.h>
27
28namespace android {
29
30struct ABuffer;
31struct AMediaCryptoWrapper;
32class MediaBuffer;
33
34struct NuPlayer2::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.
65 explicit Source(const sp<AMessage> &notify)
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;
76 virtual void stop() {}
77 virtual void pause() {}
78 virtual void resume() {}
79
80 // Explicitly disconnect the underling data source
81 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
92 virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
93 virtual sp<MetaData> getFileFormatMeta() const { return NULL; }
94
95 virtual status_t dequeueAccessUnit(
96 bool audio, sp<ABuffer> *accessUnit) = 0;
97
98 virtual status_t getDuration(int64_t * /* durationUs */) {
99 return INVALID_OPERATION;
100 }
101
102 virtual size_t getTrackCount() const {
103 return 0;
104 }
105
106 virtual sp<AMessage> getTrackInfo(size_t /* trackIndex */) const {
107 return NULL;
108 }
109
110 virtual ssize_t getSelectedTrack(media_track_type /* type */) const {
111 return INVALID_OPERATION;
112 }
113
114 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 MediaPlayer2SeekMode /* mode */ = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) {
121 return INVALID_OPERATION;
122 }
123
Wei Jia53692fa2017-12-11 10:33:46 -0800124 virtual bool isRealTime() const {
125 return false;
126 }
127
128 virtual bool isStreaming() const {
129 return true;
130 }
131
132 virtual void setOffloadAudio(bool /* offload */) {}
133
134 // Modular DRM
135 virtual status_t prepareDrm(
136 const uint8_t /* uuid */[16], const Vector<uint8_t> & /* drmSessionId */,
137 sp<AMediaCryptoWrapper> * /* crypto */) {
138 return INVALID_OPERATION;
139 }
140
141 virtual status_t releaseDrm() {
142 return INVALID_OPERATION;
143 }
144
145protected:
146 virtual ~Source() {}
147
148 virtual void onMessageReceived(const sp<AMessage> &msg);
149
150 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
159private:
160 sp<AMessage> mNotify;
161
162 DISALLOW_EVIL_CONSTRUCTORS(Source);
163};
164
165} // namespace android
166
167#endif // NUPLAYER2_SOURCE_H_
168