blob: fc670ada93d0253a210e613b20afa52f1f4c4480 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 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
Henrik Kjellander2557b862015-11-18 22:00:21 +010011#include "webrtc/modules/video_coding/test/test_util.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
14#include <math.h>
15
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000016#include <iomanip>
17#include <sstream>
18
19#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010020#include "webrtc/modules/video_coding/internal_defines.h"
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000021#include "webrtc/test/testsupport/fileutils.h"
22
23CmdArgs::CmdArgs()
24 : codecName("VP8"),
25 codecType(webrtc::kVideoCodecVP8),
26 width(352),
27 height(288),
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000028 rtt(0),
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000029 inputFile(webrtc::test::ProjectRootPath() + "/resources/foreman_cif.yuv"),
30 outputFile(webrtc::test::OutputPath() +
pbos@webrtc.orgd21406d2015-03-19 08:18:53 +000031 "video_coding_test_output_352x288.yuv") {
mikhal@webrtc.org46171cf2011-08-29 23:38:04 +000032}
33
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000034namespace {
35
36void SplitFilename(const std::string& filename, std::string* basename,
37 std::string* extension) {
38 assert(basename);
39 assert(extension);
40
41 std::string::size_type idx;
42 idx = filename.rfind('.');
43
44 if(idx != std::string::npos) {
45 *basename = filename.substr(0, idx);
46 *extension = filename.substr(idx + 1);
47 } else {
48 *basename = filename;
49 *extension = "";
50 }
niklase@google.com470e71d2011-07-07 08:21:25 +000051}
52
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000053std::string AppendWidthHeightCount(const std::string& filename, int width,
54 int height, int count) {
55 std::string basename;
56 std::string extension;
57 SplitFilename(filename, &basename, &extension);
58 std::stringstream ss;
59 ss << basename << "_" << count << "." << width << "_" << height << "." <<
60 extension;
61 return ss.str();
62}
63
64} // namespace
65
66FileOutputFrameReceiver::FileOutputFrameReceiver(
67 const std::string& base_out_filename, uint32_t ssrc)
68 : out_filename_(),
69 out_file_(NULL),
70 timing_file_(NULL),
71 width_(0),
72 height_(0),
73 count_(0) {
74 std::string basename;
75 std::string extension;
pbosbb36fdf2015-07-09 07:48:14 -070076 if (base_out_filename.empty()) {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000077 basename = webrtc::test::OutputPath() + "rtp_decoded";
78 extension = "yuv";
79 } else {
80 SplitFilename(base_out_filename, &basename, &extension);
81 }
82 std::stringstream ss;
83 ss << basename << "_" << std::hex << std::setw(8) << std::setfill('0') <<
84 ssrc << "." << extension;
85 out_filename_ = ss.str();
86}
87
88FileOutputFrameReceiver::~FileOutputFrameReceiver() {
89 if (timing_file_ != NULL) {
90 fclose(timing_file_);
91 }
92 if (out_file_ != NULL) {
93 fclose(out_file_);
94 }
95}
96
pbos@webrtc.org77f6b212013-05-03 12:02:11 +000097int32_t FileOutputFrameReceiver::FrameToRender(
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070098 webrtc::VideoFrame& video_frame) {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000099 if (timing_file_ == NULL) {
100 std::string basename;
101 std::string extension;
102 SplitFilename(out_filename_, &basename, &extension);
103 timing_file_ = fopen((basename + "_renderTiming.txt").c_str(), "w");
104 if (timing_file_ == NULL) {
105 return -1;
106 }
107 }
magjed@webrtc.org2056ee32015-03-16 13:46:52 +0000108 if (out_file_ == NULL || video_frame.width() != width_ ||
109 video_frame.height() != height_) {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +0000110 if (out_file_) {
111 fclose(out_file_);
112 }
magjed@webrtc.org2056ee32015-03-16 13:46:52 +0000113 printf("New size: %dx%d\n", video_frame.width(), video_frame.height());
114 width_ = video_frame.width();
115 height_ = video_frame.height();
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +0000116 std::string filename_with_width_height = AppendWidthHeightCount(
117 out_filename_, width_, height_, count_);
118 ++count_;
119 out_file_ = fopen(filename_with_width_height.c_str(), "wb");
120 if (out_file_ == NULL) {
121 return -1;
122 }
123 }
magjed@webrtc.org2056ee32015-03-16 13:46:52 +0000124 fprintf(timing_file_, "%u, %u\n", video_frame.timestamp(),
125 webrtc::MaskWord64ToUWord32(video_frame.render_time_ms()));
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700126 if (PrintVideoFrame(video_frame, out_file_) < 0) {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +0000127 return -1;
128 }
129 return 0;
130}
131
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000132webrtc::RtpVideoCodecTypes ConvertCodecType(const char* plname) {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +0000133 if (strncmp(plname,"VP8" , 3) == 0) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000134 return webrtc::kRtpVideoVp8;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +0000135 } else {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000136 // Default value.
137 return webrtc::kRtpVideoGeneric;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +0000138 }
139}