OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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 #include "webrtc/base/checks.h" |
| 12 #include "webrtc/test/testsupport/frame_writer.h" |
| 13 |
| 14 namespace webrtc { |
| 15 namespace test { |
| 16 |
| 17 Y4mFrameWriterImpl::Y4mFrameWriterImpl(std::string output_filename, |
| 18 int width, |
| 19 int height, |
| 20 int frame_rate) |
| 21 : YuvFrameWriterImpl(output_filename, width, height), |
| 22 frame_rate_(frame_rate) {} |
| 23 |
| 24 Y4mFrameWriterImpl::~Y4mFrameWriterImpl() = default; |
| 25 |
| 26 bool Y4mFrameWriterImpl::Init() { |
| 27 if (!YuvFrameWriterImpl::Init()) { |
| 28 return false; |
| 29 } |
| 30 int bytes_written = fprintf(output_file_, "YUV4MPEG2 W%d H%d F%d:1 C420\n", |
| 31 width_, height_, frame_rate_); |
| 32 if (bytes_written < 0) { |
| 33 fprintf(stderr, "Failed to write Y4M file header to file %s\n", |
| 34 output_filename_.c_str()); |
| 35 return false; |
| 36 } |
| 37 return true; |
| 38 } |
| 39 |
| 40 bool Y4mFrameWriterImpl::WriteFrame(uint8_t* frame_buffer) { |
| 41 if (output_file_ == nullptr) { |
| 42 fprintf(stderr, |
| 43 "Y4mFrameWriterImpl is not initialized (output file is NULL)\n"); |
| 44 return false; |
| 45 } |
| 46 int bytes_written = fprintf(output_file_, "FRAME\n"); |
| 47 if (bytes_written < 0) { |
| 48 fprintf(stderr, "Failed to write Y4M frame header to file %s\n", |
| 49 output_filename_.c_str()); |
| 50 return false; |
| 51 } |
| 52 return YuvFrameWriterImpl::WriteFrame(frame_buffer); |
| 53 } |
| 54 |
| 55 } // namespace test |
| 56 } // namespace webrtc |
OLD | NEW |