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

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

Issue 10826296: Introduce shared_memory_support media target for PPAPI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 4 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/shared_memory_util.h ('k') | media/base/channel_layout.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/audio/shared_memory_util.h"
6
7 #include "base/atomicops.h"
8 #include "base/logging.h"
9
10 using base::subtle::Atomic32;
11
12 static const uint32 kUnknownDataSize = static_cast<uint32>(-1);
13
14 namespace media {
15
16 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
17 // Need to reserve extra 4 bytes for size of data.
18 return packet_size + sizeof(Atomic32);
19 }
20
21 uint32 PacketSizeInBytes(uint32 shared_memory_created_size) {
22 return shared_memory_created_size - sizeof(Atomic32);
23 }
24
25 uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
26 uint32 shared_memory_size) {
27 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
28 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
29
30 // Actual data size stored at the end of the buffer.
31 uint32 actual_data_size =
32 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
33 return std::min(actual_data_size, shared_memory_size);
34 }
35
36 void SetActualDataSizeInBytes(void* shared_memory_ptr,
37 uint32 shared_memory_size,
38 uint32 actual_data_size) {
39 char* ptr = static_cast<char*>(shared_memory_ptr) + shared_memory_size;
40 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
41
42 // Set actual data size at the end of the buffer.
43 base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
44 actual_data_size);
45 }
46
47 void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
48 uint32 shared_memory_size,
49 uint32 actual_data_size) {
50 SetActualDataSizeInBytes(shared_memory->memory(),
51 shared_memory_size, actual_data_size);
52 }
53
54 void SetUnknownDataSize(base::SharedMemory* shared_memory,
55 uint32 shared_memory_size) {
56 SetActualDataSizeInBytes(shared_memory, shared_memory_size, kUnknownDataSize);
57 }
58
59 bool IsUnknownDataSize(base::SharedMemory* shared_memory,
60 uint32 shared_memory_size) {
61 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
62 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
63
64 // Actual data size stored at the end of the buffer.
65 uint32 actual_data_size =
66 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
67 return actual_data_size == kUnknownDataSize;
68 }
69
70 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/shared_memory_util.h ('k') | media/base/channel_layout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698