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

Side by Side Diff: webrtc/modules/audio_processing/aec_dump/write_to_file_task.cc

Issue 2865113002: AecDump implementation. (Closed)
Patch Set: Removed extra build deps from dependent CL. Created 3 years, 7 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
« no previous file with comments | « webrtc/modules/audio_processing/aec_dump/write_to_file_task.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_processing/aec_dump/write_to_file_task.h"
12
13 #include "webrtc/base/protobuf_utils.h"
14
15 namespace webrtc {
16
17 WriteToFileTask::WriteToFileTask(webrtc::FileWrapper* debug_file,
18 int64_t* num_bytes_left_for_log)
19 : debug_file_(debug_file),
20 num_bytes_left_for_log_(num_bytes_left_for_log) {}
21
22 WriteToFileTask::~WriteToFileTask() = default;
23
24 audioproc::Event* WriteToFileTask::GetEvent() {
25 return &event_;
26 }
27
28 bool WriteToFileTask::IsRoomForNextEvent(size_t event_byte_size) const {
29 int64_t next_message_size = event_byte_size + sizeof(int32_t);
30 return (*num_bytes_left_for_log_ < 0) ||
31 (*num_bytes_left_for_log_ >= next_message_size);
32 }
33
34 void WriteToFileTask::UpdateBytesLeft(size_t event_byte_size) {
35 RTC_DCHECK(IsRoomForNextEvent(event_byte_size));
36 if (*num_bytes_left_for_log_ >= 0) {
37 *num_bytes_left_for_log_ -= (sizeof(int32_t) + event_byte_size);
38 }
39 }
40
41 bool WriteToFileTask::Run() {
42 if (!debug_file_->is_open()) {
43 return true;
44 }
45
46 ProtoString event_string;
47 event_.SerializeToString(&event_string);
48
49 const size_t event_byte_size = event_.ByteSize();
50
51 if (!IsRoomForNextEvent(event_byte_size)) {
52 debug_file_->CloseFile();
53 return true;
54 }
55
56 UpdateBytesLeft(event_byte_size);
57
58 // Write message preceded by its size.
59 if (!debug_file_->Write(&event_byte_size, sizeof(int32_t))) {
60 RTC_NOTREACHED();
61 }
62 if (!debug_file_->Write(event_string.data(), event_string.length())) {
63 RTC_NOTREACHED();
64 }
65 return true; // Delete task from queue at once.
66 }
67
68 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec_dump/write_to_file_task.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698