blob: 919da9fa1bd79f2f3905d9aa4400713ccfb69fc5 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// Placed first to get WEBRTC_VIDEO_ENGINE_FILE_API.
pbos@webrtc.org281cff82013-05-17 13:44:48 +000012#include "webrtc/engine_configurations.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000013
14#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
15
mikhal@webrtc.org026e6b62013-01-08 19:19:59 +000016#include "webrtc/video_engine/vie_file_image.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000017
18#include <stdio.h> // NOLINT
19
mikhal@webrtc.org026e6b62013-01-08 19:19:59 +000020#include "webrtc/common_video/interface/video_image.h"
21#include "webrtc/common_video/jpeg/include/jpeg.h"
22#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000023
24namespace webrtc {
25
26int ViEFileImage::ConvertJPEGToVideoFrame(int engine_id,
27 const char* file_nameUTF8,
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000028 I420VideoFrame* video_frame) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000029 // Read jpeg file into temporary buffer.
30 EncodedImage image_buffer;
31
32 FILE* image_file = fopen(file_nameUTF8, "rb");
33 if (!image_file) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000034 return -1;
35 }
36 if (fseek(image_file, 0, SEEK_END) != 0) {
37 fclose(image_file);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000038 return -1;
39 }
40 int buffer_size = ftell(image_file);
41 if (buffer_size == -1) {
42 fclose(image_file);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000043 return -1;
44 }
45 image_buffer._size = buffer_size;
46 if (fseek(image_file, 0, SEEK_SET) != 0) {
47 fclose(image_file);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000048 return -1;
49 }
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000050 image_buffer._buffer = new uint8_t[ image_buffer._size + 1];
51 if (image_buffer._size != fread(image_buffer._buffer, sizeof(uint8_t),
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000052 image_buffer._size, image_file)) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000053 fclose(image_file);
54 delete [] image_buffer._buffer;
55 return -1;
56 }
57 fclose(image_file);
58
59 int ret = ConvertJpegToI420(image_buffer, video_frame);
60
61 delete [] image_buffer._buffer;
62 image_buffer._buffer = NULL;
63
64 if (ret == -1) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000065 return -1;
66 } else if (ret == -3) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000067 }
68 return 0;
69}
70
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000071int ViEFileImage::ConvertPictureToI420VideoFrame(int engine_id,
72 const ViEPicture& picture,
73 I420VideoFrame* video_frame) {
74 int half_width = (picture.width + 1) / 2;
mikhal@webrtc.org026e6b62013-01-08 19:19:59 +000075 video_frame->CreateEmptyFrame(picture.width, picture.height,
76 picture.width, half_width, half_width);
77 return ConvertToI420(kI420, picture.data, 0, 0,
78 picture.width, picture.height,
79 0, kRotateNone, video_frame);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000080}
81
82} // namespace webrtc
83
84#endif // WEBRTC_VIDEO_ENGINE_FILE_API