2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-15 09:47:55 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-16 08:52:41 +00:00
|
|
|
// Placed first to get WEBRTC_VIDEO_ENGINE_FILE_API.
|
2013-05-17 13:44:48 +00:00
|
|
|
#include "webrtc/engine_configurations.h"
|
2011-10-13 17:56:38 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
|
2011-12-16 08:52:41 +00:00
|
|
|
|
2013-01-08 19:19:59 +00:00
|
|
|
#include "webrtc/video_engine/vie_file_image.h"
|
2011-12-16 08:52:41 +00:00
|
|
|
|
2012-06-21 12:11:50 +00:00
|
|
|
#include <stdio.h> // NOLINT
|
2011-12-16 08:52:41 +00:00
|
|
|
|
2013-01-08 19:19:59 +00:00
|
|
|
#include "webrtc/common_video/interface/video_image.h"
|
|
|
|
|
#include "webrtc/common_video/jpeg/include/jpeg.h"
|
|
|
|
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2011-12-16 08:52:41 +00:00
|
|
|
int ViEFileImage::ConvertJPEGToVideoFrame(int engine_id,
|
|
|
|
|
const char* file_nameUTF8,
|
2012-10-24 18:33:04 +00:00
|
|
|
I420VideoFrame* video_frame) {
|
2011-12-16 08:52:41 +00:00
|
|
|
// Read jpeg file into temporary buffer.
|
|
|
|
|
EncodedImage image_buffer;
|
|
|
|
|
|
|
|
|
|
FILE* image_file = fopen(file_nameUTF8, "rb");
|
|
|
|
|
if (!image_file) {
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"%s could not open file %s", __FUNCTION__, file_nameUTF8);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-18 09:36:46 +00:00
|
|
|
if (fseek(image_file, 0, SEEK_END) != 0) {
|
|
|
|
|
fclose(image_file);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"ConvertJPEGToVideoFrame fseek SEEK_END error for file %s",
|
|
|
|
|
file_nameUTF8);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
int buffer_size = ftell(image_file);
|
|
|
|
|
if (buffer_size == -1) {
|
|
|
|
|
fclose(image_file);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"ConvertJPEGToVideoFrame could tell file size for file %s",
|
|
|
|
|
file_nameUTF8);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
image_buffer._size = buffer_size;
|
|
|
|
|
if (fseek(image_file, 0, SEEK_SET) != 0) {
|
|
|
|
|
fclose(image_file);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"ConvertJPEGToVideoFrame fseek SEEK_SET error for file %s",
|
|
|
|
|
file_nameUTF8);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-04-09 13:41:51 +00:00
|
|
|
image_buffer._buffer = new uint8_t[ image_buffer._size + 1];
|
|
|
|
|
if (image_buffer._size != fread(image_buffer._buffer, sizeof(uint8_t),
|
2011-12-16 08:52:41 +00:00
|
|
|
image_buffer._size, image_file)) {
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"%s could not read file %s", __FUNCTION__, file_nameUTF8);
|
2012-01-17 12:18:16 +00:00
|
|
|
fclose(image_file);
|
2011-12-16 08:52:41 +00:00
|
|
|
delete [] image_buffer._buffer;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fclose(image_file);
|
|
|
|
|
|
2012-10-18 16:42:00 +00:00
|
|
|
int ret = ConvertJpegToI420(image_buffer, video_frame);
|
2011-12-16 08:52:41 +00:00
|
|
|
|
|
|
|
|
delete [] image_buffer._buffer;
|
|
|
|
|
image_buffer._buffer = NULL;
|
|
|
|
|
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"%s could decode file %s from jpeg format", __FUNCTION__,
|
|
|
|
|
file_nameUTF8);
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (ret == -3) {
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, engine_id,
|
|
|
|
|
"%s could not convert jpeg's data to i420 format",
|
|
|
|
|
__FUNCTION__, file_nameUTF8);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-24 18:33:04 +00:00
|
|
|
int ViEFileImage::ConvertPictureToI420VideoFrame(int engine_id,
|
|
|
|
|
const ViEPicture& picture,
|
|
|
|
|
I420VideoFrame* video_frame) {
|
|
|
|
|
int half_width = (picture.width + 1) / 2;
|
2013-01-08 19:19:59 +00:00
|
|
|
video_frame->CreateEmptyFrame(picture.width, picture.height,
|
|
|
|
|
picture.width, half_width, half_width);
|
|
|
|
|
return ConvertToI420(kI420, picture.data, 0, 0,
|
|
|
|
|
picture.width, picture.height,
|
|
|
|
|
0, kRotateNone, video_frame);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-12-16 08:52:41 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2011-10-13 17:56:38 +00:00
|
|
|
#endif // WEBRTC_VIDEO_ENGINE_FILE_API
|