blob: e33898243f11b27491b1d1902042416cfcd839cc [file] [log] [blame]
brandtrb78bc752017-02-22 01:26:59 -08001/*
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
Edward Lemurc20978e2017-07-06 19:44:34 +020011#include "webrtc/rtc_base/checks.h"
brandtrb78bc752017-02-22 01:26:59 -080012#include "webrtc/test/testsupport/frame_writer.h"
13
14namespace webrtc {
15namespace test {
16
17Y4mFrameWriterImpl::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
24Y4mFrameWriterImpl::~Y4mFrameWriterImpl() = default;
25
26bool 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
40bool 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