blob: 919da9fa1bd79f2f3905d9aa4400713ccfb69fc5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
kjellander@webrtc.org0a57aae2012-02-15 09:47:55 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000011// Placed first to get WEBRTC_VIDEO_ENGINE_FILE_API.
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000012#include "webrtc/engine_configurations.h"
wu@webrtc.org4ee906d2011-10-13 17:56:38 +000013
14#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000015
mikhal@webrtc.org658d4232013-01-08 19:19:59 +000016#include "webrtc/video_engine/vie_file_image.h"
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000017
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000018#include <stdio.h> // NOLINT
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000019
mikhal@webrtc.org658d4232013-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"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc {
25
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000026int ViEFileImage::ConvertJPEGToVideoFrame(int engine_id,
27 const char* file_nameUTF8,
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000028 I420VideoFrame* video_frame) {
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000029 // Read jpeg file into temporary buffer.
30 EncodedImage image_buffer;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000032 FILE* image_file = fopen(file_nameUTF8, "rb");
33 if (!image_file) {
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000034 return -1;
35 }
mflodman@webrtc.org82244512012-01-18 09:36:46 +000036 if (fseek(image_file, 0, SEEK_END) != 0) {
37 fclose(image_file);
mflodman@webrtc.org82244512012-01-18 09:36:46 +000038 return -1;
39 }
40 int buffer_size = ftell(image_file);
41 if (buffer_size == -1) {
42 fclose(image_file);
mflodman@webrtc.org82244512012-01-18 09:36:46 +000043 return -1;
44 }
45 image_buffer._size = buffer_size;
46 if (fseek(image_file, 0, SEEK_SET) != 0) {
47 fclose(image_file);
mflodman@webrtc.org82244512012-01-18 09:36:46 +000048 return -1;
49 }
pbos@webrtc.orgb238d122013-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),
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000052 image_buffer._size, image_file)) {
mflodman@webrtc.org2877bdc2012-01-17 12:18:16 +000053 fclose(image_file);
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000054 delete [] image_buffer._buffer;
55 return -1;
56 }
57 fclose(image_file);
niklase@google.com470e71d2011-07-07 08:21:25 +000058
mikhal@webrtc.org4eb3f132012-10-18 16:42:00 +000059 int ret = ConvertJpegToI420(image_buffer, video_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000061 delete [] image_buffer._buffer;
62 image_buffer._buffer = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000064 if (ret == -1) {
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000065 return -1;
66 } else if (ret == -3) {
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000067 }
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000068 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000069}
70
mikhal@webrtc.org9fedff72012-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.org658d4232013-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);
niklase@google.com470e71d2011-07-07 08:21:25 +000080}
mflodman@webrtc.org352dcd82011-12-16 08:52:41 +000081
82} // namespace webrtc
83
wu@webrtc.org4ee906d2011-10-13 17:56:38 +000084#endif // WEBRTC_VIDEO_ENGINE_FILE_API