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

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: 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 const uint32 kUnknownDataSize = static_cast<uint32>(-1);
scherkus (not reviewing) 2012/08/14 19:27:33 static
DaleCurtis 2012/08/15 01:11:14 Done.
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.
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(base::SharedMemory* shared_memory,
40 uint32 shared_memory_size,
41 uint32 actual_data_size) {
42 char* ptr = static_cast<char*>(shared_memory->memory()) + 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 SetUnknownDataSize(base::SharedMemory* shared_memory,
51 uint32 shared_memory_size) {
52 SetActualDataSizeInBytes(shared_memory, shared_memory_size, kUnknownDataSize);
53 }
54
55 bool IsUnknownDataSize(base::SharedMemory* shared_memory,
56 uint32 shared_memory_size) {
57 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
58 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
59
60 // Actual data size stored at the end of the buffer.
61 uint32 actual_data_size =
62 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
63 return actual_data_size == kUnknownDataSize;
64 }
65
66 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698