Home | History | Annotate | Download | only in media
      1 /*
      2 
      3  * Copyright (C) 2009 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #ifndef MEDIA_SOURCE_H_
     19 
     20 #define MEDIA_SOURCE_H_
     21 
     22 #include <sys/types.h>
     23 
     24 #include <media/stagefright/MediaErrors.h>
     25 #include <media/stagefright/MetaData.h>
     26 #include <utils/RefBase.h>
     27 
     28 #include <media/MediaTrack.h>
     29 
     30 namespace android {
     31 
     32 class MediaBuffer;
     33 
     34 struct MediaSource : public virtual RefBase {
     35     MediaSource();
     36 
     37     // To be called before any other methods on this object, except
     38     // getFormat().
     39     virtual status_t start(MetaData *params = NULL) = 0;
     40 
     41     // Any blocking read call returns immediately with a result of NO_INIT.
     42     // It is an error to call any methods other than start after this call
     43     // returns. Any buffers the object may be holding onto at the time of
     44     // the stop() call are released.
     45     // Also, it is imperative that any buffers output by this object and
     46     // held onto by callers be released before a call to stop() !!!
     47     virtual status_t stop() = 0;
     48 
     49     // Returns the format of the data output by this media source.
     50     virtual sp<MetaData> getFormat() = 0;
     51 
     52     // Options that modify read() behaviour. The default is to
     53     // a) not request a seek
     54     // b) not be late, i.e. lateness_us = 0
     55     typedef MediaTrack::ReadOptions ReadOptions;
     56 
     57     // Returns a new buffer of data. Call blocks until a
     58     // buffer is available, an error is encountered of the end of the stream
     59     // is reached.
     60     // End of stream is signalled by a result of ERROR_END_OF_STREAM.
     61     // A result of INFO_FORMAT_CHANGED indicates that the format of this
     62     // MediaSource has changed mid-stream, the client can continue reading
     63     // but should be prepared for buffers of the new configuration.
     64     virtual status_t read(
     65             MediaBufferBase **buffer, const ReadOptions *options = NULL) = 0;
     66 
     67     // Causes this source to suspend pulling data from its upstream source
     68     // until a subsequent read-with-seek. This is currently not supported
     69     // as such by any source. E.g. MediaCodecSource does not suspend its
     70     // upstream source, and instead discard upstream data while paused.
     71     virtual status_t pause() {
     72         return ERROR_UNSUPPORTED;
     73     }
     74 
     75     // The consumer of this media source requests the source stops sending
     76     // buffers with timestamp larger than or equal to stopTimeUs. stopTimeUs
     77     // must be in the same time base as the startTime passed in start(). If
     78     // source does not support this request, ERROR_UNSUPPORTED will be returned.
     79     // If stopTimeUs is invalid, BAD_VALUE will be returned. This could be
     80     // called at any time even before source starts and it could be called
     81     // multiple times. Setting stopTimeUs to be -1 will effectively cancel the stopTimeUs
     82     // set previously. If stopTimeUs is larger than or equal to last buffer's timestamp,
     83     // source will start to drop buffer when it gets a buffer with timestamp larger
     84     // than or equal to stopTimeUs. If stopTimeUs is smaller than or equal to last
     85     // buffer's timestamp, source will drop all the incoming buffers immediately.
     86     // After setting stopTimeUs, source may still stop sending buffers with timestamp
     87     // less than stopTimeUs if it is stopped by the consumer.
     88     virtual status_t setStopTimeUs(int64_t /* stopTimeUs */) {
     89         return ERROR_UNSUPPORTED;
     90     }
     91 
     92 protected:
     93     virtual ~MediaSource();
     94 
     95 private:
     96     MediaSource(const MediaSource &);
     97     MediaSource &operator=(const MediaSource &);
     98 };
     99 
    100 }  // namespace android
    101 
    102 #endif  // MEDIA_SOURCE_H_
    103