OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 namespace webrtc { | 29 namespace webrtc { |
30 namespace test { | 30 namespace test { |
31 | 31 |
32 JpegFrameWriter::JpegFrameWriter(const std::string &output_filename) | 32 JpegFrameWriter::JpegFrameWriter(const std::string &output_filename) |
33 : frame_written_(false), | 33 : frame_written_(false), |
34 output_filename_(output_filename), | 34 output_filename_(output_filename), |
35 output_file_(nullptr) {} | 35 output_file_(nullptr) {} |
36 | 36 |
37 bool JpegFrameWriter::WriteFrame(const VideoFrame& input_frame, int quality) { | 37 bool JpegFrameWriter::WriteFrame(const VideoFrame& input_frame, int quality) { |
38 RTC_CHECK(!frame_written_) << "Only a single frame can be saved to Jpeg."; | 38 if (frame_written_) { |
| 39 LOG(LS_ERROR) << "Only a single frame can be saved to Jpeg."; |
| 40 return false; |
| 41 } |
39 const int kColorPlanes = 3; // R, G and B. | 42 const int kColorPlanes = 3; // R, G and B. |
40 size_t rgb_len = input_frame.height() * input_frame.width() * kColorPlanes; | 43 size_t rgb_len = input_frame.height() * input_frame.width() * kColorPlanes; |
41 std::unique_ptr<uint8_t[]> rgb_buf(new uint8_t[rgb_len]); | 44 std::unique_ptr<uint8_t[]> rgb_buf(new uint8_t[rgb_len]); |
42 | 45 |
43 // kRGB24 actually corresponds to FourCC 24BG which is 24-bit BGR. | 46 // kRGB24 actually corresponds to FourCC 24BG which is 24-bit BGR. |
44 if (ConvertFromI420(input_frame, VideoType::kRGB24, 0, rgb_buf.get()) < 0) { | 47 if (ConvertFromI420(input_frame, VideoType::kRGB24, 0, rgb_buf.get()) < 0) { |
45 LOG(LS_ERROR) << "Could not convert input frame to RGB."; | 48 LOG(LS_ERROR) << "Could not convert input frame to RGB."; |
46 return false; | 49 return false; |
47 } | 50 } |
48 output_file_ = fopen(output_filename_.c_str(), "wb"); | 51 output_file_ = fopen(output_filename_.c_str(), "wb"); |
(...skipping 29 matching lines...) Expand all Loading... |
78 jpeg_finish_compress(&cinfo); | 81 jpeg_finish_compress(&cinfo); |
79 jpeg_destroy_compress(&cinfo); | 82 jpeg_destroy_compress(&cinfo); |
80 fclose(output_file_); | 83 fclose(output_file_); |
81 | 84 |
82 frame_written_ = true; | 85 frame_written_ = true; |
83 return true; | 86 return true; |
84 } | 87 } |
85 | 88 |
86 } // namespace test | 89 } // namespace test |
87 } // namespace webrtc | 90 } // namespace webrtc |
OLD | NEW |