OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media/webrtc_rtp_dump_writer.h" | 5 #include "chrome/browser/media/webrtc_rtp_dump_writer.h" |
6 | 6 |
7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "third_party/zlib/zlib.h" | 12 #include "third_party/zlib/zlib.h" |
12 | 13 |
13 using content::BrowserThread; | 14 using content::BrowserThread; |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 static const size_t kMinimumGzipOutputBufferSize = 256; // In bytes. | 18 static const size_t kMinimumGzipOutputBufferSize = 256; // In bytes. |
18 | 19 |
19 const unsigned char kRtpDumpFileHeaderFirstLine[] = "#!rtpplay1.0 0.0.0.0/0\n"; | 20 const unsigned char kRtpDumpFileHeaderFirstLine[] = "#!rtpplay1.0 0.0.0.0/0\n"; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 std::vector<uint8> compressed_buffer; | 159 std::vector<uint8> compressed_buffer; |
159 if (!Compress(buffer, &compressed_buffer)) { | 160 if (!Compress(buffer, &compressed_buffer)) { |
160 DVLOG(2) << "Compressing buffer failed."; | 161 DVLOG(2) << "Compressing buffer failed."; |
161 *result = FLUSH_RESULT_FAILURE; | 162 *result = FLUSH_RESULT_FAILURE; |
162 return 0; | 163 return 0; |
163 } | 164 } |
164 | 165 |
165 int bytes_written = -1; | 166 int bytes_written = -1; |
166 | 167 |
167 if (base::PathExists(dump_path_)) { | 168 if (base::PathExists(dump_path_)) { |
168 bytes_written = base::AppendToFile( | 169 bytes_written = |
169 dump_path_, | 170 base::AppendToFile(dump_path_, |
170 reinterpret_cast<const char*>(&compressed_buffer[0]), | 171 reinterpret_cast<const char*>( |
171 compressed_buffer.size()); | 172 vector_as_array(&compressed_buffer)), |
| 173 compressed_buffer.size()) |
| 174 ? compressed_buffer.size() |
| 175 : -1; |
172 } else { | 176 } else { |
173 bytes_written = base::WriteFile( | 177 bytes_written = base::WriteFile( |
174 dump_path_, | 178 dump_path_, |
175 reinterpret_cast<const char*>(&compressed_buffer[0]), | 179 reinterpret_cast<const char*>(&compressed_buffer[0]), |
176 compressed_buffer.size()); | 180 compressed_buffer.size()); |
177 } | 181 } |
178 | 182 |
179 if (bytes_written == -1) { | 183 if (bytes_written == -1) { |
180 DVLOG(2) << "Writing file failed: " << dump_path_.value(); | 184 DVLOG(2) << "Writing file failed: " << dump_path_.value(); |
181 *result = FLUSH_RESULT_FAILURE; | 185 *result = FLUSH_RESULT_FAILURE; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 DCHECK_EQ(Z_STREAM_END, result); | 230 DCHECK_EQ(Z_STREAM_END, result); |
227 | 231 |
228 result = deflateEnd(&stream_); | 232 result = deflateEnd(&stream_); |
229 DCHECK_EQ(Z_OK, result); | 233 DCHECK_EQ(Z_OK, result); |
230 | 234 |
231 output_buffer.resize(output_buffer.size() - stream_.avail_out); | 235 output_buffer.resize(output_buffer.size() - stream_.avail_out); |
232 | 236 |
233 memset(&stream_, 0, sizeof(z_stream)); | 237 memset(&stream_, 0, sizeof(z_stream)); |
234 | 238 |
235 DCHECK(!output_buffer.empty()); | 239 DCHECK(!output_buffer.empty()); |
236 int bytes_written = | 240 return base::AppendToFile(dump_path_, |
237 base::AppendToFile(dump_path_, | 241 reinterpret_cast<const char*>( |
238 reinterpret_cast<const char*>(&output_buffer[0]), | 242 vector_as_array(&output_buffer)), |
239 output_buffer.size()); | 243 output_buffer.size()); |
240 | |
241 return bytes_written > 0; | |
242 } | 244 } |
243 | 245 |
244 const base::FilePath dump_path_; | 246 const base::FilePath dump_path_; |
245 | 247 |
246 z_stream stream_; | 248 z_stream stream_; |
247 | 249 |
248 base::ThreadChecker thread_checker_; | 250 base::ThreadChecker thread_checker_; |
249 | 251 |
250 DISALLOW_COPY_AND_ASSIGN(FileThreadWorker); | 252 DISALLOW_COPY_AND_ASSIGN(FileThreadWorker); |
251 }; | 253 }; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 base::Bind(&WebRtcRtpDumpWriter::OnDumpEnded, | 445 base::Bind(&WebRtcRtpDumpWriter::OnDumpEnded, |
444 weak_ptr_factory_.GetWeakPtr(), | 446 weak_ptr_factory_.GetWeakPtr(), |
445 context, | 447 context, |
446 false)); | 448 false)); |
447 return; | 449 return; |
448 } | 450 } |
449 | 451 |
450 // This object might be deleted after running the callback. | 452 // This object might be deleted after running the callback. |
451 context.callback.Run(context.incoming_succeeded, context.outgoing_succeeded); | 453 context.callback.Run(context.incoming_succeeded, context.outgoing_succeeded); |
452 } | 454 } |
OLD | NEW |