Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: webrtc/modules/video_coding/utility/ivf_file_writer.cc

Issue 1905583002: Reland of Deprecate VCMPacketizationCallback::SendData and use EncodedImageCallback instead. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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/modules/video_coding/utility/ivf_file_writer.h" 11 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 IvfFileWriter::IvfFileWriter(const std::string& file_name, 19 IvfFileWriter::IvfFileWriter(const std::string& file_name,
20 std::unique_ptr<FileWrapper> file, 20 std::unique_ptr<FileWrapper> file,
21 RtpVideoCodecTypes codec_type) 21 VideoCodecType codec_type)
22 : codec_type_(codec_type), 22 : codec_type_(codec_type),
23 num_frames_(0), 23 num_frames_(0),
24 width_(0), 24 width_(0),
25 height_(0), 25 height_(0),
26 last_timestamp_(-1), 26 last_timestamp_(-1),
27 using_capture_timestamps_(false), 27 using_capture_timestamps_(false),
28 file_name_(file_name), 28 file_name_(file_name),
29 file_(std::move(file)) {} 29 file_(std::move(file)) {}
30 30
31 IvfFileWriter::~IvfFileWriter() { 31 IvfFileWriter::~IvfFileWriter() {
32 Close(); 32 Close();
33 } 33 }
34 34
35 const size_t kIvfHeaderSize = 32; 35 const size_t kIvfHeaderSize = 32;
36 36
37 std::unique_ptr<IvfFileWriter> IvfFileWriter::Open( 37 std::unique_ptr<IvfFileWriter> IvfFileWriter::Open(const std::string& file_name,
38 const std::string& file_name, 38 VideoCodecType codec_type) {
39 RtpVideoCodecTypes codec_type) {
40 std::unique_ptr<IvfFileWriter> file_writer; 39 std::unique_ptr<IvfFileWriter> file_writer;
41 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); 40 std::unique_ptr<FileWrapper> file(FileWrapper::Create());
42 if (file->OpenFile(file_name.c_str(), false) != 0) 41 if (file->OpenFile(file_name.c_str(), false) != 0)
43 return file_writer; 42 return file_writer;
44 43
45 file_writer.reset(new IvfFileWriter( 44 file_writer.reset(new IvfFileWriter(
46 file_name, std::unique_ptr<FileWrapper>(std::move(file)), codec_type)); 45 file_name, std::unique_ptr<FileWrapper>(std::move(file)), codec_type));
47 if (!file_writer->WriteHeader()) 46 if (!file_writer->WriteHeader())
48 file_writer.reset(); 47 file_writer.reset();
49 48
50 return file_writer; 49 return file_writer;
51 } 50 }
52 51
53 bool IvfFileWriter::WriteHeader() { 52 bool IvfFileWriter::WriteHeader() {
54 if (file_->Rewind() != 0) { 53 if (file_->Rewind() != 0) {
55 LOG(LS_WARNING) << "Unable to rewind output file " << file_name_; 54 LOG(LS_WARNING) << "Unable to rewind output file " << file_name_;
56 return false; 55 return false;
57 } 56 }
58 57
59 uint8_t ivf_header[kIvfHeaderSize] = {0}; 58 uint8_t ivf_header[kIvfHeaderSize] = {0};
60 ivf_header[0] = 'D'; 59 ivf_header[0] = 'D';
61 ivf_header[1] = 'K'; 60 ivf_header[1] = 'K';
62 ivf_header[2] = 'I'; 61 ivf_header[2] = 'I';
63 ivf_header[3] = 'F'; 62 ivf_header[3] = 'F';
64 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[4], 0); // Version. 63 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[4], 0); // Version.
65 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[6], 32); // Header size. 64 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[6], 32); // Header size.
66 65
67 switch (codec_type_) { 66 switch (codec_type_) {
68 case kRtpVideoVp8: 67 case kVideoCodecVP8:
69 ivf_header[8] = 'V'; 68 ivf_header[8] = 'V';
70 ivf_header[9] = 'P'; 69 ivf_header[9] = 'P';
71 ivf_header[10] = '8'; 70 ivf_header[10] = '8';
72 ivf_header[11] = '0'; 71 ivf_header[11] = '0';
73 break; 72 break;
74 case kRtpVideoVp9: 73 case kVideoCodecVP9:
75 ivf_header[8] = 'V'; 74 ivf_header[8] = 'V';
76 ivf_header[9] = 'P'; 75 ivf_header[9] = 'P';
77 ivf_header[10] = '9'; 76 ivf_header[10] = '9';
78 ivf_header[11] = '0'; 77 ivf_header[11] = '0';
79 break; 78 break;
80 case kRtpVideoH264: 79 case kVideoCodecH264:
81 ivf_header[8] = 'H'; 80 ivf_header[8] = 'H';
82 ivf_header[9] = '2'; 81 ivf_header[9] = '2';
83 ivf_header[10] = '6'; 82 ivf_header[10] = '6';
84 ivf_header[11] = '4'; 83 ivf_header[11] = '4';
85 break; 84 break;
86 default: 85 default:
87 LOG(LS_ERROR) << "Unknown CODEC type: " << codec_type_; 86 LOG(LS_ERROR) << "Unknown CODEC type: " << codec_type_;
88 return false; 87 return false;
89 } 88 }
90 89
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (remove(file_name_.c_str()) != 0) 187 if (remove(file_name_.c_str()) != 0)
189 LOG(LS_WARNING) << "Failed to remove empty IVF file " << file_name_; 188 LOG(LS_WARNING) << "Failed to remove empty IVF file " << file_name_;
190 189
191 return true; 190 return true;
192 } 191 }
193 192
194 return WriteHeader() && (file_->CloseFile() == 0); 193 return WriteHeader() && (file_->CloseFile() == 0);
195 } 194 }
196 195
197 } // namespace webrtc 196 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/utility/ivf_file_writer.h ('k') | webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698