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

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

Issue 7831050: Revert 99236 - Very short-term change: while working on proper long-term solution, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_util.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Software adjust volume of samples, allows each audio stream its own 5 // Software adjust volume of samples, allows each audio stream its own
6 // volume without impacting master volume for chrome and other applications. 6 // volume without impacting master volume for chrome and other applications.
7 7
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. 8 // Implemented as templates to allow 8, 16 and 32 bit implementations.
9 // 8 bit is unsigned and biased by 128. 9 // 8 bit is unsigned and biased by 128.
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/shared_memory.h" 16 #include "base/shared_memory.h"
17 #include "media/audio/audio_util.h" 17 #include "media/audio/audio_util.h"
18 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
19 #include "media/audio/mac/audio_low_latency_output_mac.h" 19 #include "media/audio/mac/audio_low_latency_output_mac.h"
20 #endif 20 #endif
21 21
22 using base::subtle::Atomic32; 22 using base::subtle::Atomic32;
23 23
24 const uint32 kUnknownDataSize = static_cast<uint32>(-1);
25
26 namespace media { 24 namespace media {
27 25
28 // TODO(fbarchard): Convert to intrinsics for better efficiency. 26 // TODO(fbarchard): Convert to intrinsics for better efficiency.
29 template<class Fixed> 27 template<class Fixed>
30 static int ScaleChannel(int channel, int volume) { 28 static int ScaleChannel(int channel, int volume) {
31 return static_cast<int>((static_cast<Fixed>(channel) * volume) >> 16); 29 return static_cast<int>((static_cast<Fixed>(channel) * volume) >> 16);
32 } 30 }
33 31
34 template<class Format, class Fixed, int bias> 32 template<class Format, class Fixed, int bias>
35 static void AdjustVolume(Format* buf_out, 33 static void AdjustVolume(Format* buf_out,
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 250
253 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) { 251 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) {
254 return shared_memory_created_size - sizeof(Atomic32); 252 return shared_memory_created_size - sizeof(Atomic32);
255 } 253 }
256 254
257 uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory, 255 uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
258 uint32 shared_memory_size) { 256 uint32 shared_memory_size) {
259 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; 257 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
260 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); 258 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
261 259
262 // Actual data size stored at the end of the buffer. 260 // Actual data size stored in the beginning of the buffer.
263 uint32 actual_data_size = 261 uint32 actual_data_size =
264 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr)); 262 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
265 return std::min(actual_data_size, shared_memory_size); 263 return std::min(actual_data_size, shared_memory_size);
266 } 264 }
267 265
268 void SetActualDataSizeInBytes(base::SharedMemory* shared_memory, 266 void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
269 uint32 shared_memory_size, 267 uint32 shared_memory_size,
270 uint32 actual_data_size) { 268 uint32 actual_data_size) {
271 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; 269 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
272 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); 270 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
273 271
274 // Set actual data size in at the end of the buffer. 272 // Set actual data size in the beginning of the buffer.
275 base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr), 273 base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
276 actual_data_size); 274 actual_data_size);
277 } 275 }
278 276
279 void SetUnknownDataSize(base::SharedMemory* shared_memory,
280 uint32 shared_memory_size) {
281 SetActualDataSizeInBytes(shared_memory, shared_memory_size, kUnknownDataSize);
282 }
283
284 bool IsUnknownDataSize(base::SharedMemory* shared_memory,
285 uint32 shared_memory_size) {
286 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
287 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
288
289 // Actual data size stored at the end of the buffer.
290 uint32 actual_data_size =
291 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
292 return actual_data_size == kUnknownDataSize;
293 }
294
295 } // namespace media 277 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698