Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: webrtc/test/testsupport/yuv_frame_writer.cc

Issue 2700493006: Add optional visualization file writers to VideoProcessor tests. (Closed)
Patch Set: kjellander comments 2. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/checks.h"
11 #include "webrtc/test/testsupport/frame_writer.h" 12 #include "webrtc/test/testsupport/frame_writer.h"
12 13
13 #include <assert.h>
14
15 namespace webrtc { 14 namespace webrtc {
16 namespace test { 15 namespace test {
17 16
18 FrameWriterImpl::FrameWriterImpl(std::string output_filename, 17 YuvFrameWriterImpl::YuvFrameWriterImpl(std::string output_filename,
19 size_t frame_length_in_bytes) 18 int width,
19 int height)
20 : output_filename_(output_filename), 20 : output_filename_(output_filename),
21 frame_length_in_bytes_(frame_length_in_bytes), 21 frame_length_in_bytes_(0),
22 output_file_(NULL) { 22 width_(width),
23 } 23 height_(height),
24 output_file_(nullptr) {}
24 25
25 FrameWriterImpl::~FrameWriterImpl() { 26 YuvFrameWriterImpl::~YuvFrameWriterImpl() {
26 Close(); 27 Close();
27 } 28 }
28 29
29 bool FrameWriterImpl::Init() { 30 bool YuvFrameWriterImpl::Init() {
30 if (frame_length_in_bytes_ <= 0) { 31 if (width_ <= 0 || height_ <= 0) {
31 fprintf(stderr, "Frame length must be >0, was %zu\n", 32 fprintf(stderr, "Frame width and height must be >0, was %d x %d\n", width_,
32 frame_length_in_bytes_); 33 height_);
33 return false; 34 return false;
34 } 35 }
36 frame_length_in_bytes_ =
37 width_ * height_ + 2 * ((width_ + 1) / 2) * ((height_ + 1) / 2);
38
35 output_file_ = fopen(output_filename_.c_str(), "wb"); 39 output_file_ = fopen(output_filename_.c_str(), "wb");
36 if (output_file_ == NULL) { 40 if (output_file_ == nullptr) {
37 fprintf(stderr, "Couldn't open output file for writing: %s\n", 41 fprintf(stderr, "Couldn't open output file for writing: %s\n",
38 output_filename_.c_str()); 42 output_filename_.c_str());
39 return false; 43 return false;
40 } 44 }
41 return true; 45 return true;
42 } 46 }
43 47
44 void FrameWriterImpl::Close() { 48 bool YuvFrameWriterImpl::WriteFrame(uint8_t* frame_buffer) {
45 if (output_file_ != NULL) { 49 RTC_DCHECK(frame_buffer);
46 fclose(output_file_); 50 if (output_file_ == nullptr) {
47 output_file_ = NULL; 51 fprintf(stderr,
48 } 52 "YuvFrameWriterImpl is not initialized (output file is NULL)\n");
49 }
50
51 size_t FrameWriterImpl::FrameLength() { return frame_length_in_bytes_; }
52
53 bool FrameWriterImpl::WriteFrame(uint8_t* frame_buffer) {
54 assert(frame_buffer);
55 if (output_file_ == NULL) {
56 fprintf(stderr, "FrameWriter is not initialized (output file is NULL)\n");
57 return false; 53 return false;
58 } 54 }
59 size_t bytes_written = fwrite(frame_buffer, 1, frame_length_in_bytes_, 55 size_t bytes_written =
60 output_file_); 56 fwrite(frame_buffer, 1, frame_length_in_bytes_, output_file_);
61 if (bytes_written != frame_length_in_bytes_) { 57 if (bytes_written != frame_length_in_bytes_) {
62 fprintf(stderr, "Failed to write %zu bytes to file %s\n", 58 fprintf(stderr, "Failed to write %zu bytes to file %s\n",
63 frame_length_in_bytes_, output_filename_.c_str()); 59 frame_length_in_bytes_, output_filename_.c_str());
64 return false; 60 return false;
65 } 61 }
66 return true; 62 return true;
67 } 63 }
68 64
65 void YuvFrameWriterImpl::Close() {
66 if (output_file_ != nullptr) {
67 fclose(output_file_);
68 output_file_ = nullptr;
69 }
70 }
71
72 size_t YuvFrameWriterImpl::FrameLength() {
73 return frame_length_in_bytes_;
74 }
75
69 } // namespace test 76 } // namespace test
70 } // namespace webrtc 77 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/testsupport/yuv_frame_reader_unittest.cc ('k') | webrtc/test/testsupport/yuv_frame_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698