Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 IMEDIA_SOURCE_BASE_H_ |
| 18 | |
| 19 | #define IMEDIA_SOURCE_BASE_H_ |
| 20 | |
| 21 | #include <binder/IInterface.h> |
| 22 | #include <media/stagefright/MediaErrors.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | struct MediaSource; |
| 27 | class MetaData; |
| 28 | class MediaBuffer; |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame^] | 29 | class MediaBufferGroup; |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 30 | |
| 31 | class IMediaSource : public IInterface { |
| 32 | public: |
| 33 | DECLARE_META_INTERFACE(MediaSource); |
| 34 | |
| 35 | // To be called before any other methods on this object, except |
| 36 | // getFormat(). |
| 37 | virtual status_t start(MetaData *params = NULL) = 0; |
| 38 | |
| 39 | // Any blocking read call returns immediately with a result of NO_INIT. |
| 40 | // It is an error to call any methods other than start after this call |
| 41 | // returns. Any buffers the object may be holding onto at the time of |
| 42 | // the stop() call are released. |
| 43 | // Also, it is imperative that any buffers output by this object and |
| 44 | // held onto by callers be released before a call to stop() !!! |
| 45 | virtual status_t stop() = 0; |
| 46 | |
| 47 | // Returns the format of the data output by this media source. |
| 48 | virtual sp<MetaData> getFormat() = 0; |
| 49 | |
| 50 | // Options that modify read() behaviour. The default is to |
| 51 | // a) not request a seek |
| 52 | // b) not be late, i.e. lateness_us = 0 |
| 53 | struct ReadOptions { |
| 54 | enum SeekMode { |
| 55 | SEEK_PREVIOUS_SYNC, |
| 56 | SEEK_NEXT_SYNC, |
| 57 | SEEK_CLOSEST_SYNC, |
| 58 | SEEK_CLOSEST, |
| 59 | }; |
| 60 | |
| 61 | ReadOptions(); |
| 62 | |
| 63 | // Reset everything back to defaults. |
| 64 | void reset(); |
| 65 | |
| 66 | void setSeekTo(int64_t time_us, SeekMode mode = SEEK_CLOSEST_SYNC); |
| 67 | void clearSeekTo(); |
| 68 | bool getSeekTo(int64_t *time_us, SeekMode *mode) const; |
| 69 | |
| 70 | void setLateBy(int64_t lateness_us); |
| 71 | int64_t getLateBy() const; |
| 72 | |
| 73 | void setNonBlocking(); |
| 74 | void clearNonBlocking(); |
| 75 | bool getNonBlocking() const; |
| 76 | |
| 77 | private: |
| 78 | enum Options { |
| 79 | kSeekTo_Option = 1, |
| 80 | }; |
| 81 | |
| 82 | uint32_t mOptions; |
| 83 | int64_t mSeekTimeUs; |
| 84 | SeekMode mSeekMode; |
| 85 | int64_t mLatenessUs; |
| 86 | bool mNonBlocking; |
| 87 | }; |
| 88 | |
| 89 | // Returns a new buffer of data. Call blocks until a |
| 90 | // buffer is available, an error is encountered of the end of the stream |
| 91 | // is reached. |
| 92 | // End of stream is signalled by a result of ERROR_END_OF_STREAM. |
| 93 | // A result of INFO_FORMAT_CHANGED indicates that the format of this |
| 94 | // MediaSource has changed mid-stream, the client can continue reading |
| 95 | // but should be prepared for buffers of the new configuration. |
| 96 | virtual status_t read( |
| 97 | MediaBuffer **buffer, const ReadOptions *options = NULL) = 0; |
| 98 | |
| 99 | // Causes this source to suspend pulling data from its upstream source |
| 100 | // until a subsequent read-with-seek. Currently only supported by |
| 101 | // OMXCodec. |
| 102 | virtual status_t pause() = 0; |
| 103 | |
| 104 | // The consumer of this media source requests that the given buffers |
| 105 | // are to be returned exclusively in response to read calls. |
| 106 | // This will be called after a successful start() and before the |
| 107 | // first read() call. |
| 108 | // Callee assumes ownership of the buffers if no error is returned. |
| 109 | virtual status_t setBuffers(const Vector<MediaBuffer *> & /* buffers */) = 0; |
| 110 | |
| 111 | }; |
| 112 | |
| 113 | class BnMediaSource: public BnInterface<IMediaSource> |
| 114 | { |
| 115 | public: |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame^] | 116 | BnMediaSource(); |
| 117 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 118 | virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 119 | uint32_t flags = 0); |
| 120 | |
| 121 | virtual status_t pause() { |
| 122 | return ERROR_UNSUPPORTED; |
| 123 | } |
| 124 | |
| 125 | virtual status_t setBuffers(const Vector<MediaBuffer *> & /* buffers */) { |
| 126 | return ERROR_UNSUPPORTED; |
| 127 | } |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame^] | 128 | |
| 129 | protected: |
| 130 | virtual ~BnMediaSource(); |
| 131 | |
| 132 | private: |
| 133 | MediaBufferGroup *mGroup; |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | |
| 137 | } // namespace android |
| 138 | |
| 139 | #endif // IMEDIA_SOURCE_BASE_H_ |