Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2010 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 AVC_ENCODER_H_
     18 
     19 #define AVC_ENCODER_H_
     20 
     21 #include <media/stagefright/MediaBuffer.h>
     22 #include <media/stagefright/MediaSource.h>
     23 #include <utils/Vector.h>
     24 
     25 struct tagAVCHandle;
     26 struct tagAVCEncParam;
     27 
     28 namespace android {
     29 
     30 struct MediaBuffer;
     31 struct MediaBufferGroup;
     32 
     33 struct AVCEncoder : public MediaSource,
     34                     public MediaBufferObserver {
     35     AVCEncoder(const sp<MediaSource> &source,
     36             const sp<MetaData>& meta);
     37 
     38     virtual status_t start(MetaData *params);
     39     virtual status_t stop();
     40 
     41     virtual sp<MetaData> getFormat();
     42 
     43     virtual status_t read(
     44             MediaBuffer **buffer, const ReadOptions *options);
     45 
     46     virtual void signalBufferReturned(MediaBuffer *buffer);
     47 
     48     // Callbacks required by the encoder
     49     int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers);
     50     void    unbindOutputBuffer(int32_t index);
     51     int32_t bindOutputBuffer(int32_t index, uint8_t **yuv);
     52 
     53 protected:
     54     virtual ~AVCEncoder();
     55 
     56 private:
     57     sp<MediaSource> mSource;
     58     sp<MetaData>    mFormat;
     59     sp<MetaData>    mMeta;
     60 
     61     int32_t  mVideoWidth;
     62     int32_t  mVideoHeight;
     63     int32_t  mVideoFrameRate;
     64     int32_t  mVideoBitRate;
     65     int32_t  mVideoColorFormat;
     66     int64_t  mNumInputFrames;
     67     int64_t  mPrevTimestampUs;
     68     status_t mInitCheck;
     69     bool     mStarted;
     70     bool     mSpsPpsHeaderReceived;
     71     bool     mReadyForNextFrame;
     72     int32_t  mIsIDRFrame;  // for set kKeyIsSyncFrame
     73 
     74     tagAVCHandle          *mHandle;
     75     tagAVCEncParam        *mEncParams;
     76     MediaBuffer           *mInputBuffer;
     77     uint8_t               *mInputFrameData;
     78     MediaBufferGroup      *mGroup;
     79     Vector<MediaBuffer *> mOutputBuffers;
     80 
     81 
     82     status_t initCheck(const sp<MetaData>& meta);
     83     void releaseOutputBuffers();
     84 
     85     AVCEncoder(const AVCEncoder &);
     86     AVCEncoder &operator=(const AVCEncoder &);
     87 };
     88 
     89 }  // namespace android
     90 
     91 #endif  // AVC_ENCODER_H_
     92