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

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

Issue 2865113002: AecDump implementation. (Closed)
Patch Set: Clean up of impl code. 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
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 namespace webrtc {
14
15 WriteToFileTask::WriteToFileTask(webrtc::FileWrapper* debug_file,
16 std::unique_ptr<audioproc::Event> event,
17 int64_t* num_bytes_left_for_log)
18 : debug_file_(debug_file),
19 event_(std::move(event)),
20 num_bytes_left_for_log_(num_bytes_left_for_log) {}
21
22 WriteToFileTask::~WriteToFileTask() = default;
23
24 bool WriteToFileTask::IsRoomForNextEvent(size_t event_byte_size) const {
25 int64_t next_message_size = event_byte_size + sizeof(int32_t);
26 return (*num_bytes_left_for_log_ < 0) ||
27 (*num_bytes_left_for_log_ >= next_message_size);
28 }
29
30 void WriteToFileTask::UpdateBytesLeft(size_t event_byte_size) {
31 RTC_DCHECK(IsRoomForNextEvent(event_byte_size));
32 if (*num_bytes_left_for_log_ >= 0) {
33 *num_bytes_left_for_log_ -= (sizeof(int32_t) + event_byte_size);
34 }
35 }
36
37 bool WriteToFileTask::Run() {
38 if (!debug_file_->is_open()) {
39 return true;
40 }
41
42 std::string event_string;
43 event_->SerializeToString(&event_string);
44
45 const size_t event_byte_size = event_->ByteSize();
46
47 if (!IsRoomForNextEvent(event_byte_size)) {
48 debug_file_->CloseFile();
49 return true;
50 }
51
52 UpdateBytesLeft(event_byte_size);
53
54 // Write message preceded by its size.
55 if (!debug_file_->Write(&event_byte_size, sizeof(int32_t))) {
56 RTC_NOTREACHED();
57 }
58 if (!debug_file_->Write(event_string.data(), event_string.length())) {
59 RTC_NOTREACHED();
60 }
61 return true; // Delete task from queue at once.
62 }
63
64 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698