niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 11 | #include "webrtc/modules/video_coding/test/test_util.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | #include <math.h> |
| 15 | |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 16 | #include <iomanip> |
| 17 | #include <sstream> |
| 18 | |
| 19 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 20 | #include "webrtc/modules/video_coding/internal_defines.h" |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 21 | #include "webrtc/test/testsupport/fileutils.h" |
| 22 | |
| 23 | CmdArgs::CmdArgs() |
| 24 | : codecName("VP8"), |
| 25 | codecType(webrtc::kVideoCodecVP8), |
| 26 | width(352), |
| 27 | height(288), |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 28 | rtt(0), |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 29 | inputFile(webrtc::test::ProjectRootPath() + "/resources/foreman_cif.yuv"), |
| 30 | outputFile(webrtc::test::OutputPath() + |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 31 | "video_coding_test_output_352x288.yuv") {} |
mikhal@webrtc.org | 46171cf | 2011-08-29 23:38:04 +0000 | [diff] [blame] | 32 | |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 33 | namespace { |
| 34 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 35 | void SplitFilename(const std::string& filename, |
| 36 | std::string* basename, |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 37 | std::string* extension) { |
| 38 | assert(basename); |
| 39 | assert(extension); |
| 40 | |
| 41 | std::string::size_type idx; |
| 42 | idx = filename.rfind('.'); |
| 43 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 44 | if (idx != std::string::npos) { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 45 | *basename = filename.substr(0, idx); |
| 46 | *extension = filename.substr(idx + 1); |
| 47 | } else { |
| 48 | *basename = filename; |
| 49 | *extension = ""; |
| 50 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | } |
| 52 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 53 | std::string AppendWidthHeightCount(const std::string& filename, |
| 54 | int width, |
| 55 | int height, |
| 56 | int count) { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 57 | std::string basename; |
| 58 | std::string extension; |
| 59 | SplitFilename(filename, &basename, &extension); |
| 60 | std::stringstream ss; |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 61 | ss << basename << "_" << count << "." << width << "_" << height << "." |
| 62 | << extension; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 63 | return ss.str(); |
| 64 | } |
| 65 | |
| 66 | } // namespace |
| 67 | |
| 68 | FileOutputFrameReceiver::FileOutputFrameReceiver( |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 69 | const std::string& base_out_filename, |
| 70 | uint32_t ssrc) |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 71 | : out_filename_(), |
| 72 | out_file_(NULL), |
| 73 | timing_file_(NULL), |
| 74 | width_(0), |
| 75 | height_(0), |
| 76 | count_(0) { |
| 77 | std::string basename; |
| 78 | std::string extension; |
pbos | bb36fdf | 2015-07-09 07:48:14 -0700 | [diff] [blame] | 79 | if (base_out_filename.empty()) { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 80 | basename = webrtc::test::OutputPath() + "rtp_decoded"; |
| 81 | extension = "yuv"; |
| 82 | } else { |
| 83 | SplitFilename(base_out_filename, &basename, &extension); |
| 84 | } |
| 85 | std::stringstream ss; |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 86 | ss << basename << "_" << std::hex << std::setw(8) << std::setfill('0') << ssrc |
| 87 | << "." << extension; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 88 | out_filename_ = ss.str(); |
| 89 | } |
| 90 | |
| 91 | FileOutputFrameReceiver::~FileOutputFrameReceiver() { |
| 92 | if (timing_file_ != NULL) { |
| 93 | fclose(timing_file_); |
| 94 | } |
| 95 | if (out_file_ != NULL) { |
| 96 | fclose(out_file_); |
| 97 | } |
| 98 | } |
| 99 | |
pbos@webrtc.org | 77f6b21 | 2013-05-03 12:02:11 +0000 | [diff] [blame] | 100 | int32_t FileOutputFrameReceiver::FrameToRender( |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 101 | webrtc::VideoFrame& video_frame) { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 102 | if (timing_file_ == NULL) { |
| 103 | std::string basename; |
| 104 | std::string extension; |
| 105 | SplitFilename(out_filename_, &basename, &extension); |
| 106 | timing_file_ = fopen((basename + "_renderTiming.txt").c_str(), "w"); |
| 107 | if (timing_file_ == NULL) { |
| 108 | return -1; |
| 109 | } |
| 110 | } |
magjed@webrtc.org | 2056ee3 | 2015-03-16 13:46:52 +0000 | [diff] [blame] | 111 | if (out_file_ == NULL || video_frame.width() != width_ || |
| 112 | video_frame.height() != height_) { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 113 | if (out_file_) { |
| 114 | fclose(out_file_); |
| 115 | } |
magjed@webrtc.org | 2056ee3 | 2015-03-16 13:46:52 +0000 | [diff] [blame] | 116 | printf("New size: %dx%d\n", video_frame.width(), video_frame.height()); |
| 117 | width_ = video_frame.width(); |
| 118 | height_ = video_frame.height(); |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 119 | std::string filename_with_width_height = |
| 120 | AppendWidthHeightCount(out_filename_, width_, height_, count_); |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 121 | ++count_; |
| 122 | out_file_ = fopen(filename_with_width_height.c_str(), "wb"); |
| 123 | if (out_file_ == NULL) { |
| 124 | return -1; |
| 125 | } |
| 126 | } |
magjed@webrtc.org | 2056ee3 | 2015-03-16 13:46:52 +0000 | [diff] [blame] | 127 | fprintf(timing_file_, "%u, %u\n", video_frame.timestamp(), |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 128 | webrtc::MaskWord64ToUWord32(video_frame.render_time_ms())); |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 129 | if (PrintVideoFrame(video_frame, out_file_) < 0) { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 130 | return -1; |
| 131 | } |
| 132 | return 0; |
| 133 | } |
| 134 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 135 | webrtc::RtpVideoCodecTypes ConvertCodecType(const char* plname) { |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame^] | 136 | if (strncmp(plname, "VP8", 3) == 0) { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 137 | return webrtc::kRtpVideoVp8; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 138 | } else { |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 +0000 | [diff] [blame] | 139 | // Default value. |
| 140 | return webrtc::kRtpVideoGeneric; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 141 | } |
| 142 | } |