OLD | NEW |
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 Loading... |
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, AudioTimestamp()}; |
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 break; | 73 break; |
74 | 74 |
75 // std::numeric_limits<uint32_t>::max() is a special signal which is | 75 // std::numeric_limits<uint32_t>::max() is a special signal which is |
76 // returned after the browser stops the output device in response to a | 76 // returned after the browser stops the output device in response to a |
77 // renderer side request. | 77 // renderer side request. |
78 // | 78 // |
79 // Avoid running Process() for the paused signal, we still need to update | 79 // Avoid running Process() for the paused signal, we still need to update |
80 // the buffer index for synchronized buffers though. | 80 // the buffer index for synchronized buffers though. |
81 // | 81 // |
82 // See comments in AudioOutputController::DoPause() for details on why. | 82 // See comments in AudioOutputController::DoPause() for details on why. |
83 if (pending_data != std::numeric_limits<uint32_t>::max()) | 83 if (packet.pending_data != std::numeric_limits<uint32_t>::max()) |
84 callback_->Process(pending_data); | 84 callback_->Process(packet.pending_data, packet.timestamp); |
85 | 85 |
86 // The usage of synchronized buffers differs between input and output cases. | 86 // The usage of synchronized buffers differs between input and output cases. |
87 // | 87 // |
88 // Input: Let the other end know that we have read data, so that it can | 88 // 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| | 89 // verify it doesn't overwrite any data before read. The |buffer_index| |
90 // value is not used. For more details, see AudioInputSyncWriter::Write(). | 90 // value is not used. For more details, see AudioInputSyncWriter::Write(). |
91 // | 91 // |
92 // Output: Let the other end know which buffer we just filled. The | 92 // 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 | 93 // |buffer_index| is used to ensure the other end is getting the buffer it |
94 // expects. For more details on how this works see | 94 // expects. For more details on how this works see |
95 // AudioSyncReader::WaitUntilDataIsReady(). | 95 // AudioSyncReader::WaitUntilDataIsReady(). |
96 ++buffer_index; | 96 ++buffer_index; |
97 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); | 97 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); |
98 if (bytes_sent != sizeof(buffer_index)) | 98 if (bytes_sent != sizeof(buffer_index)) |
99 break; | 99 break; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 } // namespace media. | 103 } // namespace media. |
OLD | NEW |