Home | History | Annotate | Download | only in stagefright
      1 /*
      2  * Copyright (C) 2013 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_ADAPTER_H
     18 #define MEDIA_ADAPTER_H
     19 
     20 #include <media/stagefright/foundation/ABase.h>
     21 #include <media/stagefright/MediaSource.h>
     22 #include <media/stagefright/MediaBuffer.h>
     23 #include <media/stagefright/MetaData.h>
     24 #include <utils/threads.h>
     25 
     26 namespace android {
     27 
     28 // Convert the MediaMuxer's push model into MPEG4Writer's pull model.
     29 // Used only by the MediaMuxer for now.
     30 struct MediaAdapter : public MediaSource, public MediaBufferObserver {
     31 public:
     32     // MetaData is used to set the format and returned at getFormat.
     33     MediaAdapter(const sp<MetaData> &meta);
     34     virtual ~MediaAdapter();
     35     /////////////////////////////////////////////////
     36     // Inherited functions from MediaSource
     37     /////////////////////////////////////////////////
     38 
     39     virtual status_t start(MetaData *params = NULL);
     40     virtual status_t stop();
     41     virtual sp<MetaData> getFormat();
     42     virtual status_t read(
     43             MediaBuffer **buffer, const ReadOptions *options = NULL);
     44 
     45     /////////////////////////////////////////////////
     46     // Inherited functions from MediaBufferObserver
     47     /////////////////////////////////////////////////
     48 
     49     virtual void signalBufferReturned(MediaBuffer *buffer);
     50 
     51     /////////////////////////////////////////////////
     52     // Non-inherited functions:
     53     /////////////////////////////////////////////////
     54 
     55     // pushBuffer() will wait for the read() finish, and read() will have a
     56     // deep copy, such that after pushBuffer return, the buffer can be re-used.
     57     status_t pushBuffer(MediaBuffer *buffer);
     58 
     59 private:
     60     Mutex mAdapterLock;
     61     // Make sure the read() wait for the incoming buffer.
     62     Condition mBufferReadCond;
     63     // Make sure the pushBuffer() wait for the current buffer consumed.
     64     Condition mBufferReturnedCond;
     65 
     66     MediaBuffer *mCurrentMediaBuffer;
     67 
     68     bool mStarted;
     69     sp<MetaData> mOutputFormat;
     70 
     71     DISALLOW_EVIL_CONSTRUCTORS(MediaAdapter);
     72 };
     73 
     74 }  // namespace android
     75 
     76 #endif  // MEDIA_ADAPTER_H
     77