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 // THREAD SAFETY | 5 // THREAD SAFETY |
6 // | 6 // |
7 // AlsaPcmOutputStream object is *not* thread-safe and should only be used | 7 // AlsaPcmOutputStream object is *not* thread-safe and should only be used |
8 // from the audio thread. We DCHECK on this assumption whenever we can. | 8 // from the audio thread. We DCHECK on this assumption whenever we can. |
9 // | 9 // |
10 // SEMANTICS OF Close() | 10 // SEMANTICS OF Close() |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "base/message_loop.h" | 42 #include "base/message_loop.h" |
43 #include "base/stl_util.h" | 43 #include "base/stl_util.h" |
44 #include "base/time.h" | 44 #include "base/time.h" |
45 #include "media/audio/audio_util.h" | 45 #include "media/audio/audio_util.h" |
46 #include "media/audio/linux/alsa_util.h" | 46 #include "media/audio/linux/alsa_util.h" |
47 #include "media/audio/linux/alsa_wrapper.h" | 47 #include "media/audio/linux/alsa_wrapper.h" |
48 #include "media/audio/linux/audio_manager_linux.h" | 48 #include "media/audio/linux/audio_manager_linux.h" |
49 #include "media/base/data_buffer.h" | 49 #include "media/base/data_buffer.h" |
50 #include "media/base/seekable_buffer.h" | 50 #include "media/base/seekable_buffer.h" |
51 | 51 |
52 namespace { | |
53 // Amount of time to wait if we've exhausted the data source. This is to avoid | 52 // Amount of time to wait if we've exhausted the data source. This is to avoid |
54 // busy looping. | 53 // busy looping. |
55 static const uint32 kNoDataSleepMilliseconds = 10; | 54 static const uint32 kNoDataSleepMilliseconds = 10; |
56 | 55 |
57 // Mininum interval between OnMoreData() calls. | 56 // Mininum interval between OnMoreData() calls. |
58 const uint32 kMinIntervalBetweenOnMoreDataCallsInMs = 5; | 57 const uint32 kMinIntervalBetweenOnMoreDataCallsInMs = 5; |
59 | 58 |
60 // According to the linux nanosleep manpage, nanosleep on linux can miss the | 59 // According to the linux nanosleep manpage, nanosleep on linux can miss the |
61 // deadline by up to 10ms because the kernel timeslice is 10ms. Give a 2x | 60 // deadline by up to 10ms because the kernel timeslice is 10ms. Give a 2x |
62 // buffer to compensate for the timeslice, and any additional slowdowns. | 61 // buffer to compensate for the timeslice, and any additional slowdowns. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { | 135 for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { |
137 memcpy(aac, b, sizeof(aac)); | 136 memcpy(aac, b, sizeof(aac)); |
138 b[0] = aac[1]; // L | 137 b[0] = aac[1]; // L |
139 b[1] = aac[2]; // R | 138 b[1] = aac[2]; // R |
140 b[2] = aac[3]; // Ls | 139 b[2] = aac[3]; // Ls |
141 b[3] = aac[4]; // Rs | 140 b[3] = aac[4]; // Rs |
142 b[4] = aac[0]; // C | 141 b[4] = aac[0]; // C |
143 b[5] = aac[5]; // LFE | 142 b[5] = aac[5]; // LFE |
144 } | 143 } |
145 } | 144 } |
146 } // end namespace | |
147 | 145 |
148 std::ostream& operator<<(std::ostream& os, | 146 std::ostream& operator<<(std::ostream& os, |
149 AlsaPcmOutputStream::InternalState state) { | 147 AlsaPcmOutputStream::InternalState state) { |
150 switch (state) { | 148 switch (state) { |
151 case AlsaPcmOutputStream::kInError: | 149 case AlsaPcmOutputStream::kInError: |
152 os << "kInError"; | 150 os << "kInError"; |
153 break; | 151 break; |
154 case AlsaPcmOutputStream::kCreated: | 152 case AlsaPcmOutputStream::kCreated: |
155 os << "kCreated"; | 153 os << "kCreated"; |
156 break; | 154 break; |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 if (source_callback_) | 837 if (source_callback_) |
840 source_callback_->OnError(this, code); | 838 source_callback_->OnError(this, code); |
841 } | 839 } |
842 | 840 |
843 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to | 841 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to |
844 // release ownership of the currently registered callback. | 842 // release ownership of the currently registered callback. |
845 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { | 843 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { |
846 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); | 844 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); |
847 source_callback_ = callback; | 845 source_callback_ = callback; |
848 } | 846 } |
OLD | NEW |