|
|
@@ -56,13 +56,10 @@ VideoCaptureImpl::VideoCaptureImpl(ICaptureCallback* pCallback)
|
|
|
m_deviceId = -1;
|
|
|
m_deviceFd = -1;
|
|
|
|
|
|
- m_in_cap_width = 0;
|
|
|
- m_in_cap_height = 0;
|
|
|
- m_real_cap_width = 0;
|
|
|
- m_real_cap_height = 0;
|
|
|
- m_out_cap_width = 0;
|
|
|
- m_out_cap_height = 0;
|
|
|
-
|
|
|
+ m_capture_width = 0;
|
|
|
+ m_capture_height = 0;
|
|
|
+ m_dest_cap_width = 0;
|
|
|
+ m_dest_cap_height = 0;
|
|
|
m_rotate = libyuv::kRotate0;
|
|
|
m_frame_fmt = VIDEO_FORMAT_I420;
|
|
|
m_captureVideoType = VideoType::kI420;
|
|
|
@@ -220,12 +217,12 @@ int VideoCaptureImpl::VideoCaptureSetParam(videocap_param_t* param)
|
|
|
|
|
|
m_rotate = RotateTrans(param->irotate);
|
|
|
|
|
|
- m_in_cap_width = m_out_cap_width = mode_width[m_capture->param.cap_mode];
|
|
|
- m_in_cap_height = m_out_cap_height = mode_height[m_capture->param.cap_mode];
|
|
|
+ m_dest_cap_width = mode_width[m_capture->param.cap_mode];
|
|
|
+ m_dest_cap_height = mode_height[m_capture->param.cap_mode];
|
|
|
|
|
|
if (libyuv::kRotate90 == m_rotate || libyuv::kRotate270 == m_rotate){
|
|
|
- m_out_cap_width = mode_height[m_capture->param.cap_mode];
|
|
|
- m_out_cap_height = mode_width[m_capture->param.cap_mode];
|
|
|
+ m_dest_cap_width = mode_height[m_capture->param.cap_mode];
|
|
|
+ m_dest_cap_height = mode_width[m_capture->param.cap_mode];
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
@@ -348,7 +345,7 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
|
|
|
if (0 == m_ilogcount){
|
|
|
if (m_callback){
|
|
|
- m_callback->Debug("IncomingFrame capture_time is %d, videoType=%d, rotate=%d, videoFrameLength=%d, width=%d, height=%d, and destination width=%d, height=%d.", captureTime, frameInfo.videoType, m_rotate, videoFrameLength, width, height, m_out_cap_width, m_out_cap_height);
|
|
|
+ m_callback->Debug("IncomingFrame capture_time is %d, videoType=%d, rotate=%d, videoFrameLength=%d, width=%d, height=%d, and destination width=%d, height=%d.", captureTime, frameInfo.videoType, m_rotate, videoFrameLength, width, height, m_dest_cap_width, m_dest_cap_height);
|
|
|
}
|
|
|
m_ilogcount++;
|
|
|
}
|
|
|
@@ -363,9 +360,9 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- int stride_y = m_in_cap_width;
|
|
|
- int stride_u = (m_in_cap_width + 1)/2;
|
|
|
- int stride_v = (m_in_cap_width + 1)/2;
|
|
|
+ int stride_y = width;
|
|
|
+ int stride_u = (width + 1)/2;
|
|
|
+ int stride_v = (width + 1)/2;
|
|
|
|
|
|
//uint8_t* i420y = (uint8_t*)AlignedMalloc(I420DataSize(height, stride_y, stride_u, stride_v), kBufferAlignment);
|
|
|
//uint8_t* brg24 = (uint8_t*)AlignedMalloc(RGB24DataSize(m_dest_cap_height, m_dest_cap_width, (m_dest_cap_width+1)/2, (m_dest_cap_width + 1) / 2), kBufferAlignment);
|
|
|
@@ -373,16 +370,16 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
int conversionResult = libyuv::ConvertToI420(videoFrame, videoFrameLength,
|
|
|
m_i420,
|
|
|
stride_y,
|
|
|
- m_i420 + stride_y * m_in_cap_height,
|
|
|
+ m_i420 + stride_y * height,
|
|
|
stride_u,
|
|
|
- m_i420 + stride_y * m_in_cap_height + stride_u * ((m_in_cap_height + 1) / 2),
|
|
|
+ m_i420 + stride_y * height + stride_u * ((height + 1) / 2),
|
|
|
stride_v,
|
|
|
0,
|
|
|
- (height - m_in_cap_height) / 2, // No Cropping
|
|
|
+ 0, // No Cropping
|
|
|
width,
|
|
|
height,
|
|
|
width,
|
|
|
- m_in_cap_height,
|
|
|
+ height,
|
|
|
libyuv::kRotate180,
|
|
|
ConvertVideoType(frameInfo.videoType)
|
|
|
);
|
|
|
@@ -397,27 +394,27 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
//{
|
|
|
// video_frame frmi420 = { 0 };
|
|
|
// frmi420.data[0] = m_i420;
|
|
|
- // frmi420.linesize[0] = m_in_cap_height * 3 / 2;
|
|
|
- // frmi420.width = m_in_cap_width;
|
|
|
- // frmi420.height = m_in_cap_height;
|
|
|
+ // frmi420.linesize[0] = m_dest_cap_width * 3 / 2;
|
|
|
+ // frmi420.width = m_dest_cap_width;
|
|
|
+ // frmi420.height = m_dest_cap_height;
|
|
|
// frmi420.format = VIDEO_FORMAT_I420;
|
|
|
// //m_capture->param.on_frame_i420(m_capture->param.user_data, &frmi420);
|
|
|
// char stroptname[260] = { 0 };
|
|
|
- // snprintf(stroptname, 260, "%d_%d_%d_%d_i420.bmp", m_ilogcount, (int)m_rotate, m_in_cap_width, m_in_cap_height);
|
|
|
+ // snprintf(stroptname, 260, "%d_%d_%d_%d_i420.bmp", m_ilogcount, (int)m_rotate, m_dest_cap_width, m_dest_cap_height);
|
|
|
// video_frame_save_bmpfile(stroptname, &frmi420);
|
|
|
//}
|
|
|
|
|
|
if (libyuv::kRotate0 == m_rotate || libyuv::kRotate180 == m_rotate){
|
|
|
conversionResult = libyuv::ConvertFromI420(m_i420,
|
|
|
stride_y,
|
|
|
- m_i420 + stride_y * m_in_cap_height,
|
|
|
+ m_i420 + stride_y * m_capture_height,
|
|
|
stride_u,
|
|
|
- m_i420 + stride_y * m_in_cap_height + stride_u * ((m_in_cap_height + 1) / 2),
|
|
|
+ m_i420 + stride_y * m_capture_height + stride_u * ((m_capture_height + 1) / 2),
|
|
|
stride_v,
|
|
|
m_rgb24,
|
|
|
- m_out_cap_width * 3,
|
|
|
- m_out_cap_width,
|
|
|
- m_out_cap_height,
|
|
|
+ m_dest_cap_width * 3,
|
|
|
+ m_dest_cap_width,
|
|
|
+ m_dest_cap_height,
|
|
|
ConvertVideoType(kRGB24));
|
|
|
if (conversionResult < 0) {
|
|
|
if (m_callback) {
|
|
|
@@ -432,24 +429,24 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
if (libyuv::kRotate90 == m_rotate) {
|
|
|
erotate = libyuv::kRotate270;
|
|
|
}
|
|
|
- int opt_stride_y = m_out_cap_width;
|
|
|
- int opt_stride_u = (m_out_cap_width + 1) / 2;
|
|
|
- int opt_stride_v = (m_out_cap_width + 1) / 2;
|
|
|
+ int opt_stride_y = m_dest_cap_width;
|
|
|
+ int opt_stride_u = (m_dest_cap_width + 1) / 2;
|
|
|
+ int opt_stride_v = (m_dest_cap_width + 1) / 2;
|
|
|
//uint8_t* iopt420 = (uint8_t*)AlignedMalloc(I420DataSize(m_dest_cap_height, opt_stride_y, opt_stride_u, opt_stride_v), kBufferAlignment);
|
|
|
int rotateResult = libyuv::I420Rotate(m_i420,
|
|
|
stride_y,
|
|
|
- m_i420 + stride_y * m_in_cap_height,
|
|
|
+ m_i420 + stride_y * height,
|
|
|
stride_u,
|
|
|
- m_i420 + stride_y * m_in_cap_height + stride_u * ((m_in_cap_height + 1) / 2),
|
|
|
+ m_i420 + stride_y * height + stride_u * ((height + 1) / 2),
|
|
|
stride_v,
|
|
|
m_opti420,
|
|
|
opt_stride_y,
|
|
|
- m_opti420 + opt_stride_y * m_out_cap_height,
|
|
|
+ m_opti420 + opt_stride_y * m_dest_cap_height,
|
|
|
opt_stride_u,
|
|
|
- m_opti420 + opt_stride_y * m_out_cap_height + opt_stride_u * ((m_out_cap_height + 1) / 2),
|
|
|
+ m_opti420 + opt_stride_y * m_dest_cap_height + opt_stride_u * ((m_dest_cap_height + 1) / 2),
|
|
|
opt_stride_v,
|
|
|
- m_in_cap_width,
|
|
|
- m_in_cap_height,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
erotate);
|
|
|
|
|
|
if (rotateResult < 0) {
|
|
|
@@ -462,27 +459,27 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
//{
|
|
|
// video_frame frmi420 = { 0 };
|
|
|
// frmi420.data[0] = m_opti420;
|
|
|
- // frmi420.linesize[0] = m_out_cap_width * 3 / 2;
|
|
|
- // frmi420.width = m_out_cap_width;
|
|
|
- // frmi420.height = m_out_cap_height;
|
|
|
+ // frmi420.linesize[0] = m_dest_cap_width * 3 / 2;
|
|
|
+ // frmi420.width = m_dest_cap_width;
|
|
|
+ // frmi420.height = m_dest_cap_height;
|
|
|
// frmi420.format = VIDEO_FORMAT_I420;
|
|
|
// //m_capture->param.on_frame_i420(m_capture->param.user_data, &frmi420);
|
|
|
// char stroptname[260] = { 0 };
|
|
|
- // snprintf(stroptname, 260, "%d_%d_%d_%d_i420.bmp", m_ilogcount, (int)m_rotate, m_out_cap_width, m_out_cap_height);
|
|
|
+ // snprintf(stroptname, 260, "%d_%d_%d_%d_i420.bmp", m_ilogcount, (int)m_rotate, m_dest_cap_width, m_dest_cap_height);
|
|
|
// video_frame_save_bmpfile(stroptname, &frmi420);
|
|
|
//}
|
|
|
//yu12_to_dib24(brg24, iopt420, m_dest_cap_width, m_dest_cap_height);
|
|
|
|
|
|
conversionResult = libyuv::ConvertFromI420(m_opti420,
|
|
|
opt_stride_y,
|
|
|
- m_opti420 + opt_stride_y * m_out_cap_height,
|
|
|
+ m_opti420 + opt_stride_y * m_dest_cap_height,
|
|
|
opt_stride_u,
|
|
|
- m_opti420 + opt_stride_y * m_out_cap_height + opt_stride_u * ((m_out_cap_height + 1) / 2),
|
|
|
+ m_opti420 + opt_stride_y * m_dest_cap_height + opt_stride_u * ((m_dest_cap_height + 1) / 2),
|
|
|
opt_stride_v,
|
|
|
m_rgb24,
|
|
|
- m_out_cap_width * 3,
|
|
|
- m_out_cap_width,
|
|
|
- m_out_cap_height,
|
|
|
+ m_dest_cap_width * 3,
|
|
|
+ m_dest_cap_width,
|
|
|
+ m_dest_cap_height,
|
|
|
ConvertVideoType(kRGB24));
|
|
|
|
|
|
if (conversionResult < 0) {
|
|
|
@@ -499,14 +496,14 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
|
|
|
if (NULL != m_capture->param.on_frame) {
|
|
|
video_frame frm = { 0 };
|
|
|
frm.data[0] = m_rgb24;
|
|
|
- frm.linesize[0] = m_out_cap_width * 3;
|
|
|
- frm.width = m_out_cap_width;
|
|
|
- frm.height = m_out_cap_height;
|
|
|
+ frm.linesize[0] = m_dest_cap_width * 3;
|
|
|
+ frm.width = m_dest_cap_width;
|
|
|
+ frm.height = m_dest_cap_height;
|
|
|
frm.format = VIDEO_FORMAT_RGB24;
|
|
|
|
|
|
m_capture->param.on_frame(m_capture->param.user_data, &frm);
|
|
|
//char strrgbname[260] = { 0 };
|
|
|
- //snprintf(strrgbname, 260, "%d_%d_%d_%d_rgb.bmp", m_ilogcount, (int)m_rotate, m_out_cap_width, m_out_cap_height);
|
|
|
+ //snprintf(strrgbname, 260, "%d_%d_%d_%d_rgb.bmp", m_ilogcount, (int)m_rotate, m_dest_cap_width, m_dest_cap_height);
|
|
|
//video_frame_save_bmpfile(strrgbname, &frm);
|
|
|
//m_ilogcount++;
|
|
|
}
|
|
|
@@ -607,8 +604,8 @@ static void* VideoCaptureProcess(void *arg)
|
|
|
int VideoCaptureImpl::StartVideoCapture()
|
|
|
{
|
|
|
if (m_bCaptureStarted){
|
|
|
- if (m_real_cap_width == mode_width[m_capture->param.cap_mode] &&
|
|
|
- m_real_cap_height == mode_height[m_capture->param.cap_mode] &&
|
|
|
+ if (m_capture_width == mode_width[m_capture->param.cap_mode] &&
|
|
|
+ m_capture_height == mode_height[m_capture->param.cap_mode] &&
|
|
|
m_frame_fmt == m_capture->param.frame_fmt){
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -724,10 +721,10 @@ int VideoCaptureImpl::StartVideoCapture()
|
|
|
else
|
|
|
{
|
|
|
// initialize current width and height
|
|
|
- m_real_cap_width = video_fmt.fmt.pix.width;
|
|
|
- m_real_cap_height = video_fmt.fmt.pix.height;
|
|
|
+ m_capture_width = video_fmt.fmt.pix.width;
|
|
|
+ m_capture_height = video_fmt.fmt.pix.height;
|
|
|
if (m_callback){
|
|
|
- m_callback->Debug("real camera capture m_capture_width = %d, m_capture_height = %d.", m_real_cap_width, m_real_cap_height);
|
|
|
+ m_callback->Debug("real camera capture m_capture_width = %d, m_capture_height = %d.", m_capture_width, m_capture_height);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -780,7 +777,7 @@ int VideoCaptureImpl::StartVideoCapture()
|
|
|
// If driver doesn't support framerate control, need to hardcode.
|
|
|
// Hardcoding the value based on the frame size.
|
|
|
if (!driver_framerate_support) {
|
|
|
- if (m_in_cap_width >= 800 && m_captureVideoType != VideoType::kMJPEG) {
|
|
|
+ if (m_capture_width >= 800 && m_captureVideoType != VideoType::kMJPEG) {
|
|
|
m_currentFrameRate = 15;
|
|
|
}
|
|
|
else {
|
|
|
@@ -916,17 +913,17 @@ bool VideoCaptureImpl::DeAllocateVideoBuffers()
|
|
|
bool VideoCaptureImpl::AlignedMallocVideoBuffer()
|
|
|
{
|
|
|
bool bret = false;
|
|
|
- int stride_y = m_in_cap_width;
|
|
|
- int stride_u = (m_in_cap_width + 1) / 2;
|
|
|
- int stride_v = (m_in_cap_width + 1) / 2;
|
|
|
+ int stride_y = m_capture_width;
|
|
|
+ int stride_u = (m_capture_width + 1) / 2;
|
|
|
+ int stride_v = (m_capture_width + 1) / 2;
|
|
|
|
|
|
- m_i420 = (uint8_t*)AlignedMalloc(I420DataSize(m_in_cap_height, stride_y, stride_u, stride_v), kBufferAlignment);
|
|
|
- m_rgb24 = (uint8_t*)AlignedMalloc(RGB24DataSize(m_out_cap_height, m_out_cap_width, (m_out_cap_width + 1) / 2, (m_out_cap_width + 1) / 2), kBufferAlignment);
|
|
|
+ m_i420 = (uint8_t*)AlignedMalloc(I420DataSize(m_capture_height, stride_y, stride_u, stride_v), kBufferAlignment);
|
|
|
+ m_rgb24 = (uint8_t*)AlignedMalloc(RGB24DataSize(m_dest_cap_height, m_dest_cap_width, (m_dest_cap_width + 1) / 2, (m_dest_cap_width + 1) / 2), kBufferAlignment);
|
|
|
|
|
|
- int opt_stride_y = m_out_cap_width;
|
|
|
- int opt_stride_u = (m_out_cap_width + 1) / 2;
|
|
|
- int opt_stride_v = (m_out_cap_width + 1) / 2;
|
|
|
- m_opti420 = (uint8_t*)AlignedMalloc(I420DataSize(m_out_cap_height, opt_stride_y, opt_stride_u, opt_stride_v), kBufferAlignment);
|
|
|
+ int opt_stride_y = m_dest_cap_width;
|
|
|
+ int opt_stride_u = (m_dest_cap_width + 1) / 2;
|
|
|
+ int opt_stride_v = (m_dest_cap_width + 1) / 2;
|
|
|
+ m_opti420 = (uint8_t*)AlignedMalloc(I420DataSize(m_dest_cap_height, opt_stride_y, opt_stride_u, opt_stride_v), kBufferAlignment);
|
|
|
|
|
|
if (m_i420 && m_rgb24 && m_opti420){
|
|
|
bret = true;
|
|
|
@@ -980,12 +977,12 @@ VideoType VideoCaptureImpl::GetCaptureVideoType()
|
|
|
|
|
|
int VideoCaptureImpl::GetCapture_Width()
|
|
|
{
|
|
|
- return m_real_cap_width;
|
|
|
+ return m_capture_width;
|
|
|
}
|
|
|
|
|
|
int VideoCaptureImpl::GetCapture_Height()
|
|
|
{
|
|
|
- return m_real_cap_height;
|
|
|
+ return m_capture_height;
|
|
|
}
|
|
|
|
|
|
bool VideoCaptureImpl::GetStopCaptureFlag()
|