• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
12 
13 #include <string>
14 
15 #include "rtc_base/logging.h"
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     RTC_LOG(LS_ERROR) << "Failed to write Y4M file header to file: "
38                       << output_filename_.c_str();
39     return false;
40   }
41   return true;
42 }
43 
WriteFrame(const uint8_t * frame_buffer)44 bool Y4mFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
45   if (output_file_ == nullptr) {
46     RTC_LOG(LS_ERROR) << "Y4mFrameWriterImpl is not initialized.";
47     return false;
48   }
49   int bytes_written = fprintf(output_file_, "FRAME\n");
50   if (bytes_written < 0) {
51     RTC_LOG(LS_ERROR) << "Couldn't write Y4M frame header to file: "
52                       << output_filename_.c_str();
53     return false;
54   }
55   return YuvFrameWriterImpl::WriteFrame(frame_buffer);
56 }
57 
58 }  // namespace test
59 }  // namespace webrtc
60