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

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

Issue 1903193002: Revert 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 VideoCodecType codec_type) 21 RtpVideoCodecTypes 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(const std::string& file_name, 37 std::unique_ptr<IvfFileWriter> IvfFileWriter::Open(
38 VideoCodecType codec_type) { 38 const std::string& file_name,
39 RtpVideoCodecTypes codec_type) {
39 std::unique_ptr<IvfFileWriter> file_writer; 40 std::unique_ptr<IvfFileWriter> file_writer;
40 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); 41 std::unique_ptr<FileWrapper> file(FileWrapper::Create());
41 if (file->OpenFile(file_name.c_str(), false) != 0) 42 if (file->OpenFile(file_name.c_str(), false) != 0)
42 return file_writer; 43 return file_writer;
43 44
44 file_writer.reset(new IvfFileWriter( 45 file_writer.reset(new IvfFileWriter(
45 file_name, std::unique_ptr<FileWrapper>(std::move(file)), codec_type)); 46 file_name, std::unique_ptr<FileWrapper>(std::move(file)), codec_type));
46 if (!file_writer->WriteHeader()) 47 if (!file_writer->WriteHeader())
47 file_writer.reset(); 48 file_writer.reset();
48 49
49 return file_writer; 50 return file_writer;
50 } 51 }
51 52
52 bool IvfFileWriter::WriteHeader() { 53 bool IvfFileWriter::WriteHeader() {
53 if (file_->Rewind() != 0) { 54 if (file_->Rewind() != 0) {
54 LOG(LS_WARNING) << "Unable to rewind output file " << file_name_; 55 LOG(LS_WARNING) << "Unable to rewind output file " << file_name_;
55 return false; 56 return false;
56 } 57 }
57 58
58 uint8_t ivf_header[kIvfHeaderSize] = {0}; 59 uint8_t ivf_header[kIvfHeaderSize] = {0};
59 ivf_header[0] = 'D'; 60 ivf_header[0] = 'D';
60 ivf_header[1] = 'K'; 61 ivf_header[1] = 'K';
61 ivf_header[2] = 'I'; 62 ivf_header[2] = 'I';
62 ivf_header[3] = 'F'; 63 ivf_header[3] = 'F';
63 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[4], 0); // Version. 64 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[4], 0); // Version.
64 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[6], 32); // Header size. 65 ByteWriter<uint16_t>::WriteLittleEndian(&ivf_header[6], 32); // Header size.
65 66
66 switch (codec_type_) { 67 switch (codec_type_) {
67 case kVideoCodecVP8: 68 case kRtpVideoVp8:
68 ivf_header[8] = 'V'; 69 ivf_header[8] = 'V';
69 ivf_header[9] = 'P'; 70 ivf_header[9] = 'P';
70 ivf_header[10] = '8'; 71 ivf_header[10] = '8';
71 ivf_header[11] = '0'; 72 ivf_header[11] = '0';
72 break; 73 break;
73 case kVideoCodecVP9: 74 case kRtpVideoVp9:
74 ivf_header[8] = 'V'; 75 ivf_header[8] = 'V';
75 ivf_header[9] = 'P'; 76 ivf_header[9] = 'P';
76 ivf_header[10] = '9'; 77 ivf_header[10] = '9';
77 ivf_header[11] = '0'; 78 ivf_header[11] = '0';
78 break; 79 break;
79 case kVideoCodecH264: 80 case kRtpVideoH264:
80 ivf_header[8] = 'H'; 81 ivf_header[8] = 'H';
81 ivf_header[9] = '2'; 82 ivf_header[9] = '2';
82 ivf_header[10] = '6'; 83 ivf_header[10] = '6';
83 ivf_header[11] = '4'; 84 ivf_header[11] = '4';
84 break; 85 break;
85 default: 86 default:
86 LOG(LS_ERROR) << "Unknown CODEC type: " << codec_type_; 87 LOG(LS_ERROR) << "Unknown CODEC type: " << codec_type_;
87 return false; 88 return false;
88 } 89 }
89 90
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (remove(file_name_.c_str()) != 0) 188 if (remove(file_name_.c_str()) != 0)
188 LOG(LS_WARNING) << "Failed to remove empty IVF file " << file_name_; 189 LOG(LS_WARNING) << "Failed to remove empty IVF file " << file_name_;
189 190
190 return true; 191 return true;
191 } 192 }
192 193
193 return WriteHeader() && (file_->CloseFile() == 0); 194 return WriteHeader() && (file_->CloseFile() == 0);
194 } 195 }
195 196
196 } // namespace webrtc 197 } // 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