| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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/test/testsupport/frame_writer.h" | 11 #include "webrtc/test/testsupport/frame_writer.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 namespace test { | 16 namespace test { |
| 17 | 17 |
| 18 FrameWriterImpl::FrameWriterImpl(std::string output_filename, | 18 FrameWriterImpl::FrameWriterImpl(std::string output_filename, |
| 19 size_t frame_length_in_bytes) | 19 size_t frame_length_in_bytes) |
| 20 : output_filename_(output_filename), | 20 : output_filename_(output_filename), |
| 21 frame_length_in_bytes_(frame_length_in_bytes), | 21 frame_length_in_bytes_(frame_length_in_bytes), |
| 22 output_file_(NULL) { | 22 output_file_(nullptr) {} |
| 23 } | |
| 24 | 23 |
| 25 FrameWriterImpl::~FrameWriterImpl() { | 24 FrameWriterImpl::~FrameWriterImpl() { |
| 26 Close(); | 25 Close(); |
| 27 } | 26 } |
| 28 | 27 |
| 29 bool FrameWriterImpl::Init() { | 28 bool FrameWriterImpl::Init() { |
| 30 if (frame_length_in_bytes_ <= 0) { | 29 if (frame_length_in_bytes_ <= 0) { |
| 31 fprintf(stderr, "Frame length must be >0, was %zu\n", | 30 fprintf(stderr, "Frame length must be >0, was %zu\n", |
| 32 frame_length_in_bytes_); | 31 frame_length_in_bytes_); |
| 33 return false; | 32 return false; |
| 34 } | 33 } |
| 35 output_file_ = fopen(output_filename_.c_str(), "wb"); | 34 output_file_ = fopen(output_filename_.c_str(), "wb"); |
| 36 if (output_file_ == NULL) { | 35 if (output_file_ == nullptr) { |
| 37 fprintf(stderr, "Couldn't open output file for writing: %s\n", | 36 fprintf(stderr, "Couldn't open output file for writing: %s\n", |
| 38 output_filename_.c_str()); | 37 output_filename_.c_str()); |
| 39 return false; | 38 return false; |
| 40 } | 39 } |
| 41 return true; | 40 return true; |
| 42 } | 41 } |
| 43 | 42 |
| 44 void FrameWriterImpl::Close() { | 43 void FrameWriterImpl::Close() { |
| 45 if (output_file_ != NULL) { | 44 if (output_file_ != nullptr) { |
| 46 fclose(output_file_); | 45 fclose(output_file_); |
| 47 output_file_ = NULL; | 46 output_file_ = nullptr; |
| 48 } | 47 } |
| 49 } | 48 } |
| 50 | 49 |
| 51 size_t FrameWriterImpl::FrameLength() { return frame_length_in_bytes_; } | 50 size_t FrameWriterImpl::FrameLength() { return frame_length_in_bytes_; } |
| 52 | 51 |
| 53 bool FrameWriterImpl::WriteFrame(uint8_t* frame_buffer) { | 52 bool FrameWriterImpl::WriteFrame(uint8_t* frame_buffer) { |
| 54 assert(frame_buffer); | 53 assert(frame_buffer); |
| 55 if (output_file_ == NULL) { | 54 if (output_file_ == nullptr) { |
| 56 fprintf(stderr, "FrameWriter is not initialized (output file is NULL)\n"); | 55 fprintf(stderr, "FrameWriter is not initialized (output file is null)\n"); |
| 57 return false; | 56 return false; |
| 58 } | 57 } |
| 59 size_t bytes_written = fwrite(frame_buffer, 1, frame_length_in_bytes_, | 58 size_t bytes_written = fwrite(frame_buffer, 1, frame_length_in_bytes_, |
| 60 output_file_); | 59 output_file_); |
| 61 if (bytes_written != frame_length_in_bytes_) { | 60 if (bytes_written != frame_length_in_bytes_) { |
| 62 fprintf(stderr, "Failed to write %zu bytes to file %s\n", | 61 fprintf(stderr, "Failed to write %zu bytes to file %s\n", |
| 63 frame_length_in_bytes_, output_filename_.c_str()); | 62 frame_length_in_bytes_, output_filename_.c_str()); |
| 64 return false; | 63 return false; |
| 65 } | 64 } |
| 66 return true; | 65 return true; |
| 67 } | 66 } |
| 68 | 67 |
| 69 } // namespace test | 68 } // namespace test |
| 70 } // namespace webrtc | 69 } // namespace webrtc |
| OLD | NEW |