SoftAVCEncoder.h revision a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5
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_AVC_ENCODER_H_
18#define SOFT_AVC_ENCODER_H_
19
20#include <media/stagefright/MediaBuffer.h>
21#include <media/stagefright/foundation/ABase.h>
22#include <utils/Vector.h>
23
24#include "avcenc_api.h"
25#include "SoftVideoEncoderOMXComponent.h"
26
27namespace android {
28
29struct MediaBuffer;
30
31struct SoftAVCEncoder : public MediaBufferObserver,
32                        public SoftVideoEncoderOMXComponent {
33    SoftAVCEncoder(
34            const char *name,
35            const OMX_CALLBACKTYPE *callbacks,
36            OMX_PTR appData,
37            OMX_COMPONENTTYPE **component);
38
39    // Override SimpleSoftOMXComponent methods
40    virtual OMX_ERRORTYPE internalGetParameter(
41            OMX_INDEXTYPE index, OMX_PTR params);
42
43    virtual OMX_ERRORTYPE internalSetParameter(
44            OMX_INDEXTYPE index, const OMX_PTR params);
45
46    virtual void onQueueFilled(OMX_U32 portIndex);
47
48    // Implement MediaBufferObserver
49    virtual void signalBufferReturned(MediaBuffer *buffer);
50
51
52    // Callbacks required by PV's encoder
53    int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers);
54    void    unbindOutputBuffer(int32_t index);
55    int32_t bindOutputBuffer(int32_t index, uint8_t **yuv);
56
57protected:
58    virtual ~SoftAVCEncoder();
59
60private:
61    enum {
62        kNumBuffers = 2,
63    };
64
65    // OMX input buffer's timestamp and flags
66    typedef struct {
67        int64_t mTimeUs;
68        int32_t mFlags;
69    } InputBufferInfo;
70
71    int32_t  mIDRFrameRefreshIntervalInSec;
72    AVCProfile mAVCEncProfile;
73    AVCLevel   mAVCEncLevel;
74
75    int64_t  mNumInputFrames;
76    int64_t  mPrevTimestampUs;
77    bool     mStarted;
78    bool     mSpsPpsHeaderReceived;
79    bool     mReadyForNextFrame;
80    bool     mSawInputEOS;
81    bool     mSignalledError;
82    bool     mIsIDRFrame;
83
84    tagAVCHandle          *mHandle;
85    tagAVCEncParam        *mEncParams;
86    uint8_t               *mInputFrameData;
87    uint32_t              *mSliceGroup;
88    Vector<MediaBuffer *> mOutputBuffers;
89    Vector<InputBufferInfo> mInputBufferInfoVec;
90
91    OMX_ERRORTYPE initEncParams();
92    OMX_ERRORTYPE initEncoder();
93    OMX_ERRORTYPE releaseEncoder();
94    void releaseOutputBuffers();
95
96    DISALLOW_EVIL_CONSTRUCTORS(SoftAVCEncoder);
97};
98
99}  // namespace android
100
101#endif  // SOFT_AVC_ENCODER_H_
102