SoftMPEG4Encoder.h revision 2edda09a2ad1d112c52acd37d323f63f0a492d67
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 "SoftVideoEncoderOMXComponent.h"
23#include "mp4enc_api.h"
24
25
26namespace android {
27
28struct MediaBuffer;
29
30struct SoftMPEG4Encoder : public SoftVideoEncoderOMXComponent {
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
46protected:
47    virtual ~SoftMPEG4Encoder();
48
49private:
50    enum {
51        kNumBuffers = 2,
52    };
53
54    // OMX input buffer's timestamp and flags
55    typedef struct {
56        int64_t mTimeUs;
57        int32_t mFlags;
58    } InputBufferInfo;
59
60    MP4EncodingMode mEncodeMode;
61    int32_t  mVideoWidth;
62    int32_t  mVideoHeight;
63    int32_t  mVideoFrameRate;
64    int32_t  mVideoBitRate;
65    int32_t  mVideoColorFormat;
66    bool     mStoreMetaDataInBuffers;
67    int32_t  mIDRFrameRefreshIntervalInSec;
68
69    int64_t  mNumInputFrames;
70    bool     mStarted;
71    bool     mSawInputEOS;
72    bool     mSignalledError;
73
74    tagvideoEncControls   *mHandle;
75    tagvideoEncOptions    *mEncParams;
76    uint8_t               *mInputFrameData;
77    Vector<InputBufferInfo> mInputBufferInfoVec;
78
79    void initPorts();
80    OMX_ERRORTYPE initEncParams();
81    OMX_ERRORTYPE initEncoder();
82    OMX_ERRORTYPE releaseEncoder();
83
84    DISALLOW_EVIL_CONSTRUCTORS(SoftMPEG4Encoder);
85};
86
87}  // namespace android
88
89#endif  // SOFT_MPEG4_ENCODER_H_
90