• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MEDIA_SOURCE_H_
18 
19 #define MEDIA_SOURCE_H_
20 
21 #include <sys/types.h>
22 
23 #include <utils/RefBase.h>
24 
25 namespace android {
26 
27 class MediaBuffer;
28 class MetaData;
29 
30 struct MediaSource : public RefBase {
31     MediaSource();
32 
33     // To be called before any other methods on this object, except
34     // getFormat().
35     virtual status_t start(MetaData *params = NULL) = 0;
36 
37     // Any blocking read call returns immediately with a result of NO_INIT.
38     // It is an error to call any methods other than start after this call
39     // returns. Any buffers the object may be holding onto at the time of
40     // the stop() call are released.
41     // Also, it is imperative that any buffers output by this object and
42     // held onto by callers be released before a call to stop() !!!
43     virtual status_t stop() = 0;
44 
45     // Returns the format of the data output by this media source.
46     virtual sp<MetaData> getFormat() = 0;
47 
48     struct ReadOptions;
49 
50     // Returns a new buffer of data. Call blocks until a
51     // buffer is available, an error is encountered of the end of the stream
52     // is reached.
53     // End of stream is signalled by a result of ERROR_END_OF_STREAM.
54     virtual status_t read(
55             MediaBuffer **buffer, const ReadOptions *options = NULL) = 0;
56 
57     // Options that modify read() behaviour. The default is to
58     // a) not request a seek
59     // b) not be late, i.e. lateness_us = 0
60     struct ReadOptions {
61         ReadOptions();
62 
63         // Reset everything back to defaults.
64         void reset();
65 
66         void setSeekTo(int64_t time_us);
67         void clearSeekTo();
68         bool getSeekTo(int64_t *time_us) const;
69 
70         void setLateBy(int64_t lateness_us);
71         int64_t getLateBy() const;
72 
73     private:
74         enum Options {
75             kSeekTo_Option      = 1,
76         };
77 
78         uint32_t mOptions;
79         int64_t mSeekTimeUs;
80         int64_t mLatenessUs;
81     };
82 
83 protected:
84     virtual ~MediaSource();
85 
86 private:
87     MediaSource(const MediaSource &);
88     MediaSource &operator=(const MediaSource &);
89 };
90 
91 }  // namespace android
92 
93 #endif  // MEDIA_SOURCE_H_
94