Home | History | Annotate | Download | only in enc
      1 /*
      2  * Copyright (C) 2012 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 SOFT_MPEG4_ENCODER_H_
     18 #define SOFT_MPEG4_ENCODER_H_
     19 
     20 #include <media/stagefright/MediaBuffer.h>
     21 #include <media/stagefright/foundation/ABase.h>
     22 #include "SimpleSoftOMXComponent.h"
     23 #include "mp4enc_api.h"
     24 
     25 
     26 namespace android {
     27 
     28 struct MediaBuffer;
     29 
     30 struct SoftMPEG4Encoder : public SimpleSoftOMXComponent {
     31     SoftMPEG4Encoder(
     32             const char *name,
     33             const OMX_CALLBACKTYPE *callbacks,
     34             OMX_PTR appData,
     35             OMX_COMPONENTTYPE **component);
     36 
     37     // Override SimpleSoftOMXComponent methods
     38     virtual OMX_ERRORTYPE internalGetParameter(
     39             OMX_INDEXTYPE index, OMX_PTR params);
     40 
     41     virtual OMX_ERRORTYPE internalSetParameter(
     42             OMX_INDEXTYPE index, const OMX_PTR params);
     43 
     44     virtual void onQueueFilled(OMX_U32 portIndex);
     45 
     46     // Override SoftOMXComponent methods
     47 
     48     virtual OMX_ERRORTYPE getExtensionIndex(
     49             const char *name, OMX_INDEXTYPE *index);
     50 
     51 protected:
     52     virtual ~SoftMPEG4Encoder();
     53 
     54 private:
     55     enum {
     56         kNumBuffers = 2,
     57     };
     58 
     59     enum {
     60         kStoreMetaDataExtensionIndex = OMX_IndexVendorStartUnused + 1
     61     };
     62 
     63     // OMX input buffer's timestamp and flags
     64     typedef struct {
     65         int64_t mTimeUs;
     66         int32_t mFlags;
     67     } InputBufferInfo;
     68 
     69     MP4EncodingMode mEncodeMode;
     70     int32_t  mVideoWidth;
     71     int32_t  mVideoHeight;
     72     int32_t  mVideoFrameRate;
     73     int32_t  mVideoBitRate;
     74     int32_t  mVideoColorFormat;
     75     bool     mStoreMetaDataInBuffers;
     76     int32_t  mIDRFrameRefreshIntervalInSec;
     77 
     78     int64_t  mNumInputFrames;
     79     bool     mStarted;
     80     bool     mSawInputEOS;
     81     bool     mSignalledError;
     82 
     83     tagvideoEncControls   *mHandle;
     84     tagvideoEncOptions    *mEncParams;
     85     uint8_t               *mInputFrameData;
     86     Vector<InputBufferInfo> mInputBufferInfoVec;
     87 
     88     void initPorts();
     89     OMX_ERRORTYPE initEncParams();
     90     OMX_ERRORTYPE initEncoder();
     91     OMX_ERRORTYPE releaseEncoder();
     92 
     93     uint8_t* extractGrallocData(void *data, buffer_handle_t *buffer);
     94     void releaseGrallocData(buffer_handle_t buffer);
     95 
     96     DISALLOW_EVIL_CONSTRUCTORS(SoftMPEG4Encoder);
     97 };
     98 
     99 }  // namespace android
    100 
    101 #endif  // SOFT_MPEG4_ENCODER_H_
    102