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 CodecProfileLevel;
29
30struct SoftMPEG4Encoder : public SoftVideoEncoderOMXComponent {
31    SoftMPEG4Encoder(
32            const char *name,
33            const char *componentRole,
34            OMX_VIDEO_CODINGTYPE codingType,
35            const char *mime,
36            const CodecProfileLevel *profileLevels,
37            size_t numProfileLevels,
38            const OMX_CALLBACKTYPE *callbacks,
39            OMX_PTR appData,
40            OMX_COMPONENTTYPE **component);
41
42    // Override SimpleSoftOMXComponent methods
43    virtual OMX_ERRORTYPE internalGetParameter(
44            OMX_INDEXTYPE index, OMX_PTR params);
45
46    virtual OMX_ERRORTYPE internalSetParameter(
47            OMX_INDEXTYPE index, const OMX_PTR params);
48
49    virtual void onQueueFilled(OMX_U32 portIndex);
50
51    virtual void onReset();
52
53protected:
54    virtual ~SoftMPEG4Encoder();
55
56private:
57    enum {
58        kNumBuffers = 2,
59    };
60
61    // OMX input buffer's timestamp and flags
62    typedef struct {
63        int64_t mTimeUs;
64        int32_t mFlags;
65    } InputBufferInfo;
66
67    MP4EncodingMode mEncodeMode;
68    int32_t  mKeyFrameInterval; // 1: all I-frames, <0: infinite
69
70    int64_t  mNumInputFrames;
71    bool     mStarted;
72    bool     mSawInputEOS;
73    bool     mSignalledError;
74
75    tagvideoEncControls   *mHandle;
76    tagvideoEncOptions    *mEncParams;
77    uint8_t               *mInputFrameData;
78    Vector<InputBufferInfo> mInputBufferInfoVec;
79
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