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