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

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: Compiles! 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
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 // When transferring data in the shared memory, first word is size of data
17 // in bytes. Actual data starts immediately after it.
nfullagar 2012/08/17 00:52:07 Comment above: ...last word is size of data in byt
DaleCurtis 2012/08/17 02:27:45 Done.
18
19 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
20 // Need to reserve extra 4 bytes for size of data.
21 return packet_size + sizeof(Atomic32);
22 }
23
24 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) {
25 return shared_memory_created_size - sizeof(Atomic32);
26 }
27
28 uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
29 uint32 shared_memory_size) {
30 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
31 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
32
33 // Actual data size stored at the end of the buffer.
34 uint32 actual_data_size =
35 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
36 return std::min(actual_data_size, shared_memory_size);
37 }
38
39 void SetActualDataSizeInBytes(void* shared_memory_ptr,
40 uint32 shared_memory_size,
41 uint32 actual_data_size) {
42 char* ptr = static_cast<char*>(shared_memory_ptr) + shared_memory_size;
43 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
44
45 // Set actual data size at the end of the buffer.
46 base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
47 actual_data_size);
48 }
49
50 void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
51 uint32 shared_memory_size,
52 uint32 actual_data_size) {
53 SetActualDataSizeInBytes(shared_memory->memory(),
54 shared_memory_size, actual_data_size);
55 }
56
57 void SetUnknownDataSize(base::SharedMemory* shared_memory,
58 uint32 shared_memory_size) {
59 SetActualDataSizeInBytes(shared_memory, shared_memory_size, kUnknownDataSize);
60 }
61
62 bool IsUnknownDataSize(base::SharedMemory* shared_memory,
63 uint32 shared_memory_size) {
64 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
65 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
66
67 // Actual data size stored at the end of the buffer.
68 uint32 actual_data_size =
69 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
70 return actual_data_size == kUnknownDataSize;
71 }
72
73 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698