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