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

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

Issue 2838133003: Implementation of new AecDump interface. (Closed)
Patch Set: Changed CaptureStreamInfo behaviour. 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 int64_t* num_bytes_left_for_log)
17 : debug_file_(debug_file),
18 num_bytes_left_for_log_(num_bytes_left_for_log) {}
19
20 WriteToFileTask::~WriteToFileTask() = default;
21
22 audioproc::Event* WriteToFileTask::GetEvent() {
23 return &event_;
24 }
25
26 bool WriteToFileTask::IsRoomForNextEvent(size_t event_byte_size) const {
27 int64_t next_message_size = event_byte_size + sizeof(int32_t);
28 return (*num_bytes_left_for_log_ < 0) ||
29 (*num_bytes_left_for_log_ >= next_message_size);
30 }
31
32 void WriteToFileTask::UpdateBytesLeft(size_t event_byte_size) {
33 RTC_DCHECK(IsRoomForNextEvent(event_byte_size));
34 if (*num_bytes_left_for_log_ >= 0) {
35 *num_bytes_left_for_log_ -= (sizeof(int32_t) + event_byte_size);
36 }
37 }
38
39 bool WriteToFileTask::Run() {
40 if (!debug_file_->is_open()) {
41 return true;
42 }
43
44 std::string event_string;
45 event_.SerializeToString(&event_string);
46
47 const size_t event_byte_size = event_.ByteSize();
48
49 if (!IsRoomForNextEvent(event_byte_size)) {
50 debug_file_->CloseFile();
51 return true;
52 }
53
54 UpdateBytesLeft(event_byte_size);
55
56 // Write message preceded by its size.
57 if (!debug_file_->Write(&event_byte_size, sizeof(int32_t))) {
58 RTC_NOTREACHED();
59 }
60 if (!debug_file_->Write(event_string.data(), event_string.length())) {
61 RTC_NOTREACHED();
62 }
63 return true; // Delete task from queue at once.
64 }
65
66 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec_dump/write_to_file_task.h ('k') | webrtc/modules/audio_processing/audio_processing_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698