11700744ae0ce2fcf722816453ae0af2cd5646458James Dong/*
21700744ae0ce2fcf722816453ae0af2cd5646458James Dong * Copyright (C) 2012 The Android Open Source Project
31700744ae0ce2fcf722816453ae0af2cd5646458James Dong *
41700744ae0ce2fcf722816453ae0af2cd5646458James Dong * Licensed under the Apache License, Version 2.0 (the "License");
51700744ae0ce2fcf722816453ae0af2cd5646458James Dong * you may not use this file except in compliance with the License.
61700744ae0ce2fcf722816453ae0af2cd5646458James Dong * You may obtain a copy of the License at
71700744ae0ce2fcf722816453ae0af2cd5646458James Dong *
81700744ae0ce2fcf722816453ae0af2cd5646458James Dong *      http://www.apache.org/licenses/LICENSE-2.0
91700744ae0ce2fcf722816453ae0af2cd5646458James Dong *
101700744ae0ce2fcf722816453ae0af2cd5646458James Dong * Unless required by applicable law or agreed to in writing, software
111700744ae0ce2fcf722816453ae0af2cd5646458James Dong * distributed under the License is distributed on an "AS IS" BASIS,
121700744ae0ce2fcf722816453ae0af2cd5646458James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131700744ae0ce2fcf722816453ae0af2cd5646458James Dong * See the License for the specific language governing permissions and
141700744ae0ce2fcf722816453ae0af2cd5646458James Dong * limitations under the License.
151700744ae0ce2fcf722816453ae0af2cd5646458James Dong */
161700744ae0ce2fcf722816453ae0af2cd5646458James Dong
171700744ae0ce2fcf722816453ae0af2cd5646458James Dong#ifndef SOFT_MPEG4_ENCODER_H_
181700744ae0ce2fcf722816453ae0af2cd5646458James Dong#define SOFT_MPEG4_ENCODER_H_
191700744ae0ce2fcf722816453ae0af2cd5646458James Dong
201700744ae0ce2fcf722816453ae0af2cd5646458James Dong#include <media/stagefright/MediaBuffer.h>
211700744ae0ce2fcf722816453ae0af2cd5646458James Dong#include <media/stagefright/foundation/ABase.h>
222edda09a2ad1d112c52acd37d323f63f0a492d67Lajos Molnar#include "SoftVideoEncoderOMXComponent.h"
231700744ae0ce2fcf722816453ae0af2cd5646458James Dong#include "mp4enc_api.h"
241700744ae0ce2fcf722816453ae0af2cd5646458James Dong
251700744ae0ce2fcf722816453ae0af2cd5646458James Dong
261700744ae0ce2fcf722816453ae0af2cd5646458James Dongnamespace android {
271700744ae0ce2fcf722816453ae0af2cd5646458James Dong
28a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5Lajos Molnarstruct CodecProfileLevel;
291700744ae0ce2fcf722816453ae0af2cd5646458James Dongstruct MediaBuffer;
301700744ae0ce2fcf722816453ae0af2cd5646458James Dong
312edda09a2ad1d112c52acd37d323f63f0a492d67Lajos Molnarstruct SoftMPEG4Encoder : public SoftVideoEncoderOMXComponent {
321700744ae0ce2fcf722816453ae0af2cd5646458James Dong    SoftMPEG4Encoder(
331700744ae0ce2fcf722816453ae0af2cd5646458James Dong            const char *name,
34a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5Lajos Molnar            const char *componentRole,
35a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5Lajos Molnar            OMX_VIDEO_CODINGTYPE codingType,
36a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5Lajos Molnar            const char *mime,
37a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5Lajos Molnar            const CodecProfileLevel *profileLevels,
38a0940a569f2bc24b00dc10ce0fa7658b1dc3a3a5Lajos Molnar            size_t numProfileLevels,
391700744ae0ce2fcf722816453ae0af2cd5646458James Dong            const OMX_CALLBACKTYPE *callbacks,
401700744ae0ce2fcf722816453ae0af2cd5646458James Dong            OMX_PTR appData,
411700744ae0ce2fcf722816453ae0af2cd5646458James Dong            OMX_COMPONENTTYPE **component);
421700744ae0ce2fcf722816453ae0af2cd5646458James Dong
431700744ae0ce2fcf722816453ae0af2cd5646458James Dong    // Override SimpleSoftOMXComponent methods
441700744ae0ce2fcf722816453ae0af2cd5646458James Dong    virtual OMX_ERRORTYPE internalGetParameter(
451700744ae0ce2fcf722816453ae0af2cd5646458James Dong            OMX_INDEXTYPE index, OMX_PTR params);
461700744ae0ce2fcf722816453ae0af2cd5646458James Dong
471700744ae0ce2fcf722816453ae0af2cd5646458James Dong    virtual OMX_ERRORTYPE internalSetParameter(
481700744ae0ce2fcf722816453ae0af2cd5646458James Dong            OMX_INDEXTYPE index, const OMX_PTR params);
491700744ae0ce2fcf722816453ae0af2cd5646458James Dong
501700744ae0ce2fcf722816453ae0af2cd5646458James Dong    virtual void onQueueFilled(OMX_U32 portIndex);
511700744ae0ce2fcf722816453ae0af2cd5646458James Dong
521700744ae0ce2fcf722816453ae0af2cd5646458James Dongprotected:
531700744ae0ce2fcf722816453ae0af2cd5646458James Dong    virtual ~SoftMPEG4Encoder();
541700744ae0ce2fcf722816453ae0af2cd5646458James Dong
551700744ae0ce2fcf722816453ae0af2cd5646458James Dongprivate:
561700744ae0ce2fcf722816453ae0af2cd5646458James Dong    enum {
571700744ae0ce2fcf722816453ae0af2cd5646458James Dong        kNumBuffers = 2,
581700744ae0ce2fcf722816453ae0af2cd5646458James Dong    };
591700744ae0ce2fcf722816453ae0af2cd5646458James Dong
601700744ae0ce2fcf722816453ae0af2cd5646458James Dong    // OMX input buffer's timestamp and flags
611700744ae0ce2fcf722816453ae0af2cd5646458James Dong    typedef struct {
621700744ae0ce2fcf722816453ae0af2cd5646458James Dong        int64_t mTimeUs;
631700744ae0ce2fcf722816453ae0af2cd5646458James Dong        int32_t mFlags;
641700744ae0ce2fcf722816453ae0af2cd5646458James Dong    } InputBufferInfo;
651700744ae0ce2fcf722816453ae0af2cd5646458James Dong
661700744ae0ce2fcf722816453ae0af2cd5646458James Dong    MP4EncodingMode mEncodeMode;
671700744ae0ce2fcf722816453ae0af2cd5646458James Dong    int32_t  mIDRFrameRefreshIntervalInSec;
681700744ae0ce2fcf722816453ae0af2cd5646458James Dong
691700744ae0ce2fcf722816453ae0af2cd5646458James Dong    int64_t  mNumInputFrames;
701700744ae0ce2fcf722816453ae0af2cd5646458James Dong    bool     mStarted;
711700744ae0ce2fcf722816453ae0af2cd5646458James Dong    bool     mSawInputEOS;
721700744ae0ce2fcf722816453ae0af2cd5646458James Dong    bool     mSignalledError;
731700744ae0ce2fcf722816453ae0af2cd5646458James Dong
741700744ae0ce2fcf722816453ae0af2cd5646458James Dong    tagvideoEncControls   *mHandle;
751700744ae0ce2fcf722816453ae0af2cd5646458James Dong    tagvideoEncOptions    *mEncParams;
761700744ae0ce2fcf722816453ae0af2cd5646458James Dong    uint8_t               *mInputFrameData;
771700744ae0ce2fcf722816453ae0af2cd5646458James Dong    Vector<InputBufferInfo> mInputBufferInfoVec;
781700744ae0ce2fcf722816453ae0af2cd5646458James Dong
791700744ae0ce2fcf722816453ae0af2cd5646458James Dong    OMX_ERRORTYPE initEncParams();
801700744ae0ce2fcf722816453ae0af2cd5646458James Dong    OMX_ERRORTYPE initEncoder();
811700744ae0ce2fcf722816453ae0af2cd5646458James Dong    OMX_ERRORTYPE releaseEncoder();
821700744ae0ce2fcf722816453ae0af2cd5646458James Dong
831700744ae0ce2fcf722816453ae0af2cd5646458James Dong    DISALLOW_EVIL_CONSTRUCTORS(SoftMPEG4Encoder);
841700744ae0ce2fcf722816453ae0af2cd5646458James Dong};
851700744ae0ce2fcf722816453ae0af2cd5646458James Dong
861700744ae0ce2fcf722816453ae0af2cd5646458James Dong}  // namespace android
871700744ae0ce2fcf722816453ae0af2cd5646458James Dong
881700744ae0ce2fcf722816453ae0af2cd5646458James Dong#endif  // SOFT_MPEG4_ENCODER_H_
89