Refine VP8 encode middleware
BZ: 103440
Add VP8 encoder option in mix_encoder test tool;
Add render slice parameter for vp8 encode;
Change ref frame management for vp8 encode;
Clean up unused code for vp8 encode.
Change-Id: If57158788baa18a71fdd57ccbcef93e5ac552f39
Signed-off-by: Liu, Bolun <bolun.liu@intel.com>
Reviewed-on: http://android.intel.com:8080/109160
Reviewed-by: cactus <cactus@intel.com>
Reviewed-by: Ding, Haitao <haitao.ding@intel.com>
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/test/mix_encoder.cpp b/test/mix_encoder.cpp
index 83bc76b..a9c3ebb 100644
--- a/test/mix_encoder.cpp
+++ b/test/mix_encoder.cpp
@@ -21,6 +21,7 @@
static const char *AVC_MIME_TYPE = "video/h264";
static const char *MPEG4_MIME_TYPE = "video/mpeg4";
static const char *H263_MIME_TYPE = "video/h263";
+static const char *VPX_MIME_TYPE = "video/x-webm";
static const int box_width = 128;
@@ -30,7 +31,7 @@
static VideoParamsStoreMetaDataInBuffers gStoreMetaDataInBuffers;
static VideoRateControl gRC = RATE_CONTROL_CBR;
-static int gCodec = 0; //0: H264, 1: MPEG4, 2: H263
+static int gCodec = 0; //0: H264, 1: MPEG4, 2: H263 3: VPX
static int gRCMode = 1; //0: NO_RC, 1: CBR, 2: VBR, 3: VCM
static int gBitrate = 1280000;
@@ -686,8 +687,8 @@
default:
printf("\n./mix_encode -c <Codec> -b <Bit rate> -r <Rate control> -w <SrcWidth> -h <SrcHeight> -k <EncodeWidth> -g <EncodeHight> -n <Frame_num> -m <Mode> -s <Sync mode> -f <Output file>\n");
printf("\nCodec:\n");
- printf("0: H264 (default)\n1: MPEG4\n2: H263\n");
- printf("\nRate control:\n");
+ printf("0: H264 (default)\n1: MPEG4\n2: H263\n3: VPX\n");
+ printf("\nRate control:\n");
printf("0: NO_RC \n1: CBR (default)\n2: VBR\n3: VCM\n");
printf("\nMode:\n");
printf("0: Camera malloc (default)\n1: WiDi clone\n2: WiDi ext\n3: WiDi user\n4: Raw\n5: GrallocSource(Composer)\n6: GrallocSource(Gralloc)\n7: GrallocSource(Camera)\n");
@@ -738,6 +739,10 @@
case 2:
codec = H263_MIME_TYPE;
break;
+ case 3:
+ codec = VPX_MIME_TYPE;
+ break;
+
default:
printf("Not support this type codec\n");
return 1;
diff --git a/videoencoder/VideoEncoderVP8.cpp b/videoencoder/VideoEncoderVP8.cpp
index eb1b294..06c23b2 100644
--- a/videoencoder/VideoEncoderVP8.cpp
+++ b/videoencoder/VideoEncoderVP8.cpp
@@ -65,8 +65,8 @@
vp8SeqParam.hrd_buf_size = mVideoParamsVP8.hrd_buf_size;
vp8SeqParam.hrd_buf_initial_fullness = mVideoParamsVP8.hrd_buf_initial_fullness;
vp8SeqParam.hrd_buf_optimal_fullness = mVideoParamsVP8.hrd_buf_optimal_fullness;
- memcpy(vp8SeqParam.reference_frames, mVP8InternalFrames, sizeof(mVP8InternalFrames));
-
+// memcpy(vp8SeqParam.reference_frames, mVP8InternalFrames, sizeof(mVP8InternalFrames));
+ memcpy(vp8SeqParam.reference_frames, mAutoRefSurfaces, sizeof(mAutoRefSurfaces) * mAutoReferenceSurfaceNum);
vaStatus = vaCreateBuffer(
mVADisplay, mVAContext,
@@ -110,6 +110,47 @@
return ret;
}
+Encode_Status VideoEncoderVP8::renderSliceParams(EncodeTask *task) {
+
+ VAStatus vaStatus = VA_STATUS_SUCCESS;
+ uint32_t sliceHeight;
+ uint32_t sliceHeightInMB;
+
+ VAEncSliceParameterBuffer sliceParams;
+
+ LOG_V( "Begin\n\n");
+
+ sliceHeight = mComParams.resolution.height;
+ sliceHeight += 15;
+ sliceHeight &= (~15);
+ sliceHeightInMB = sliceHeight / 16;
+
+ sliceParams.start_row_number = 0;
+ sliceParams.slice_height = sliceHeightInMB;
+ sliceParams.slice_flags.bits.is_intra = (task->type == FTYPE_I)?1:0;
+ sliceParams.slice_flags.bits.disable_deblocking_filter_idc = 0;
+
+ LOG_V("======VP8 slice params======\n");
+ LOG_I( "start_row_number = %d\n", (int) sliceParams.start_row_number);
+ LOG_I( "sliceHeightInMB = %d\n", (int) sliceParams.slice_height);
+ LOG_I( "is_intra = %d\n", (int) sliceParams.slice_flags.bits.is_intra);
+
+ vaStatus = vaCreateBuffer(
+ mVADisplay, mVAContext,
+ VAEncSliceParameterBufferType,
+ sizeof(VAEncSliceParameterBuffer),
+ 1, &sliceParams,
+ &mSliceParamBuf);
+ CHECK_VA_STATUS_RETURN("vaCreateBuffer");
+
+ vaStatus = vaRenderPicture(mVADisplay, mVAContext, &mSliceParamBuf, 1);
+ CHECK_VA_STATUS_RETURN("vaRenderPicture");
+
+ LOG_V( "end\n");
+ return ENCODE_SUCCESS;
+}
+
+
Encode_Status VideoEncoderVP8::sendEncodeCommand(EncodeTask *task) {
Encode_Status ret = ENCODE_SUCCESS;
@@ -123,58 +164,13 @@
ret = renderPictureParams(task);
CHECK_ENCODE_STATUS_RETURN("renderPictureParams");
+ ret = renderSliceParams(task);
+ CHECK_ENCODE_STATUS_RETURN("renderSliceParams");
+
LOG_V( "End\n");
return ret;
}
-Encode_Status VideoEncoderVP8::start() {
- Encode_Status ret = ENCODE_SUCCESS;
- LOG_V( "Begin\n");
-
- ret = VideoEncoderBase::start ();
- CHECK_ENCODE_STATUS_RETURN("VideoEncoderBase::start");
-
- uint32_t stride_aligned = 0;
- uint32_t height_aligned = 0;
-
- VASurfaceAttributeTPI attribute_tpi;
- VAStatus vaStatus = VA_STATUS_SUCCESS;
-
- stride_aligned = ((mComParams.resolution.width + 15) / 16 ) * 16;
- height_aligned = ((mComParams.resolution.height + 15) / 16 ) * 16;
-
- attribute_tpi.size = stride_aligned * height_aligned * 3 / 2;
- attribute_tpi.luma_stride = stride_aligned;
- attribute_tpi.chroma_u_stride = stride_aligned;
- attribute_tpi.chroma_v_stride = stride_aligned;
- attribute_tpi.luma_offset = 0;
- attribute_tpi.chroma_u_offset = stride_aligned * height_aligned;
- attribute_tpi.chroma_v_offset = stride_aligned * height_aligned;
- attribute_tpi.pixel_format = VA_FOURCC_NV12;
- attribute_tpi.type = VAExternalMemoryNULL;
-
- vaStatus = vaCreateSurfacesWithAttribute(mVADisplay, stride_aligned, height_aligned,
- VA_RT_FORMAT_YUV420, VP8_INTERNAL_FRAME_LAST, mVP8InternalFrames, &attribute_tpi);
- CHECK_VA_STATUS_RETURN("vaCreateSurfacesWithAttribute");
- LOG_V( "end\n");
- return ret;
-}
-
-Encode_Status VideoEncoderVP8::stop() {
- Encode_Status ret = ENCODE_SUCCESS;
- LOG_V( "Begin\n");
-
- VAStatus vaStatus = VA_STATUS_SUCCESS;
- vaStatus = vaDestroySurfaces(mVADisplay, mVP8InternalFrames, VP8_INTERNAL_FRAME_LAST);
- CHECK_VA_STATUS_RETURN("vaDestroySurfaces");
-
- ret = VideoEncoderBase::stop ();
- CHECK_ENCODE_STATUS_RETURN("VideoEncoderBase::stop");
-
- LOG_V( "end\n");
-
- return ret;
-}
Encode_Status VideoEncoderVP8::derivedSetParams(VideoParamConfigSet *videoEncParams) {
diff --git a/videoencoder/VideoEncoderVP8.h b/videoencoder/VideoEncoderVP8.h
index 671b279..ebf2df9 100644
--- a/videoencoder/VideoEncoderVP8.h
+++ b/videoencoder/VideoEncoderVP8.h
@@ -19,8 +19,7 @@
VideoEncoderVP8();
virtual ~VideoEncoderVP8();
- virtual Encode_Status start(void);
- virtual Encode_Status stop(void);
+
protected:
virtual Encode_Status sendEncodeCommand(EncodeTask *task);
@@ -34,20 +33,12 @@
// Local Methods
private:
- enum {
- LRF = 0,
- GRF = 1,
- ARF = 2,
- RCF = 3,
- VP8_INTERNAL_FRAME_LAST
- };
-
Encode_Status renderSequenceParams();
Encode_Status renderPictureParams(EncodeTask *task);
+ Encode_Status renderSliceParams(EncodeTask *task);
VideoConfigVP8 mVideoConfigVP8;
VideoParamsVP8 mVideoParamsVP8;
- VASurfaceID mVP8InternalFrames[VP8_INTERNAL_FRAME_LAST];
};
#endif /* __VIDEO_ENCODER_VP8_H__ */