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

Side by Side Diff: media/audio/audio_device_thread.cc

Issue 2437863004: Make more media APIs aware of |delay| and |delay_timestamp| (Closed)
Patch Set: fixed excessive logging Created 4 years, 1 month 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 | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/audio/audio_device_thread.h" 5 #include "media/audio/audio_device_thread.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::PlatformThread::Join(thread_handle_); 60 base::PlatformThread::Join(thread_handle_);
61 } 61 }
62 62
63 void AudioDeviceThread::ThreadMain() { 63 void AudioDeviceThread::ThreadMain() {
64 base::PlatformThread::SetName(thread_name_); 64 base::PlatformThread::SetName(thread_name_);
65 base::ThreadRestrictions::SetSingletonAllowed(true); 65 base::ThreadRestrictions::SetSingletonAllowed(true);
66 callback_->InitializeOnAudioThread(); 66 callback_->InitializeOnAudioThread();
67 67
68 uint32_t buffer_index = 0; 68 uint32_t buffer_index = 0;
69 while (true) { 69 while (true) {
70 uint32_t pending_data = 0; 70 Packet packet = {0, 0};
71 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); 71 size_t bytes_read = socket_.Receive(&packet, sizeof(packet));
72 if (bytes_read != sizeof(pending_data)) 72 if (bytes_read != sizeof(packet)) {
73 LOG(ERROR) << "Failed to receive.";
chcunningham 2016/10/31 20:08:35 I'm surprised this ever happens. What am I missing
miu 2016/10/31 20:59:04 It seems legitimate for Receive() to return zero w
73 break; 74 break;
75 }
74 76
75 // std::numeric_limits<uint32_t>::max() is a special signal which is 77 // std::numeric_limits<int64_t>::max() is a special signal which is
76 // returned after the browser stops the output device in response to a 78 // returned after the browser stops the output device in response to a
77 // renderer side request. 79 // renderer side request.
78 // 80 //
79 // Avoid running Process() for the paused signal, we still need to update 81 // Avoid running Process() for the paused signal, we still need to update
80 // the buffer index for synchronized buffers though. 82 // the buffer index for synchronized buffers though.
81 // 83 //
82 // See comments in AudioOutputController::DoPause() for details on why. 84 // See comments in AudioOutputController::DoPause() for details on why.
83 if (pending_data != std::numeric_limits<uint32_t>::max()) 85 if (packet.pending_data != std::numeric_limits<int64_t>::max()) {
84 callback_->Process(pending_data); 86 callback_->Process(packet.pending_data,
87 base::TimeTicks() + base::TimeDelta::FromMicroseconds(
88 packet.data_timestamp_us));
89 }
85 90
86 // The usage of synchronized buffers differs between input and output cases. 91 // The usage of synchronized buffers differs between input and output cases.
87 // 92 //
88 // Input: Let the other end know that we have read data, so that it can 93 // Input: Let the other end know that we have read data, so that it can
89 // verify it doesn't overwrite any data before read. The |buffer_index| 94 // verify it doesn't overwrite any data before read. The |buffer_index|
90 // value is not used. For more details, see AudioInputSyncWriter::Write(). 95 // value is not used. For more details, see AudioInputSyncWriter::Write().
91 // 96 //
92 // Output: Let the other end know which buffer we just filled. The 97 // Output: Let the other end know which buffer we just filled. The
93 // |buffer_index| is used to ensure the other end is getting the buffer it 98 // |buffer_index| is used to ensure the other end is getting the buffer it
94 // expects. For more details on how this works see 99 // expects. For more details on how this works see
95 // AudioSyncReader::WaitUntilDataIsReady(). 100 // AudioSyncReader::WaitUntilDataIsReady().
96 ++buffer_index; 101 ++buffer_index;
97 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); 102 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index));
98 if (bytes_sent != sizeof(buffer_index)) 103 if (bytes_sent != sizeof(buffer_index))
99 break; 104 break;
100 } 105 }
101 } 106 }
102 107
103 } // namespace media. 108 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698