1 /*
2 * Copyright (c) 2009-2011 Intel Corporation.  All rights reserved.
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 __PV_SOFT_MPEG4_ENCODER__
18 #define __PV_SOFT_MPEG4_ENCODER__
19 
20 #include <va/va.h>
21 #include <va/va_tpi.h>
22 #include "VideoEncoderDef.h"
23 #include "VideoEncoderInterface.h"
24 #include "IntelMetadataBuffer.h"
25 
26 #include <media/stagefright/MediaBuffer.h>
27 #include <media/stagefright/foundation/ABase.h>
28 #include "SimpleSoftOMXComponent.h"
29 #include "mp4enc_api.h"
30 
31 class PVSoftMPEG4Encoder : IVideoEncoder {
32 
33 public:
34     PVSoftMPEG4Encoder(const char *name);
35     virtual ~PVSoftMPEG4Encoder();
36 
start(void)37     virtual Encode_Status start(void) {return initEncoder();}
flush(void)38     virtual void flush(void) { }
stop(void)39     virtual Encode_Status stop(void) {return releaseEncoder();}
40     virtual Encode_Status encode(VideoEncRawBuffer *inBuffer, uint32_t timeout);
41 
42     virtual Encode_Status getOutput(VideoEncOutputBuffer *outBuffer, uint32_t timeout);
43 
44     virtual Encode_Status getParameters(VideoParamConfigSet *videoEncParams);
45     virtual Encode_Status setParameters(VideoParamConfigSet *videoEncParams);
setConfig(VideoParamConfigSet * videoEncConfig)46     virtual Encode_Status setConfig(VideoParamConfigSet *videoEncConfig) {return ENCODE_SUCCESS;}
getConfig(VideoParamConfigSet * videoEncConfig)47     virtual Encode_Status getConfig(VideoParamConfigSet *videoEncConfig) {return ENCODE_SUCCESS;}
getMaxOutSize(uint32_t * maxSize)48     virtual Encode_Status getMaxOutSize(uint32_t *maxSize) {return ENCODE_SUCCESS;}
49 
50 private:
51     void setDefaultParams(void);
52     VideoParamsCommon mComParams;
53 
54     MP4EncodingMode mEncodeMode;
55     int32_t  mVideoWidth;
56     int32_t  mVideoHeight;
57     int32_t  mVideoFrameRate;
58     int32_t  mVideoBitRate;
59     int32_t  mVideoColorFormat;
60     bool     mStoreMetaDataInBuffers;
61     int32_t  mIDRFrameRefreshIntervalInSec;
62 
63     int64_t  mNumInputFrames;
64     bool     mStarted;
65     bool     mSawInputEOS;
66     bool     mSignalledError;
67     int64_t mCurTimestampUs;
68     int64_t mLastTimestampUs;
69 
70     tagvideoEncControls   *mHandle;
71     tagvideoEncOptions    *mEncParams;
72     uint8_t               *mInputFrameData;
73     uint8_t               *mTrimedInputData;
74     uint8_t mVolHeader[256];
75     int32_t mVolHeaderLength;
76 
77     Encode_Status initEncParams();
78     Encode_Status initEncoder();
79     Encode_Status releaseEncoder();
80 
81     DISALLOW_EVIL_CONSTRUCTORS(PVSoftMPEG4Encoder);
82 };
83 
84 #endif
85