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 #ifndef REMOTING_CAPTURER_SHARED_BUFFER_H_ | 5 #ifndef MEDIA_VIDEO_CAPTURE_SCREEN_SHARED_BUFFER_H_ |
6 #define REMOTING_CAPTURER_SHARED_BUFFER_H_ | 6 #define MEDIA_VIDEO_CAPTURE_SCREEN_SHARED_BUFFER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 12 #include "media/base/media_export.h" |
12 | 13 |
13 namespace remoting { | 14 namespace media { |
14 | 15 |
15 // Represents a memory buffer that can be shared between multiple processes. | 16 // Represents a memory buffer that can be shared between multiple processes. |
16 // It is more or less a convenience wrapper around base::SharedMemory providing | 17 // It is more or less a convenience wrapper around base::SharedMemory providing |
17 // ref-counted lifetime management and unique buffer identifiers. | 18 // ref-counted lifetime management and unique buffer identifiers. |
18 class SharedBuffer | 19 class MEDIA_EXPORT SharedBuffer |
19 : public base::RefCountedThreadSafe<SharedBuffer> { | 20 : public base::RefCountedThreadSafe<SharedBuffer> { |
20 public: | 21 public: |
21 // Creates a new shared memory buffer of the given size and maps it to | 22 // Creates a new shared memory buffer of the given size and maps it to |
22 // the memory of the calling process. If the operation fails for any reason, | 23 // the memory of the calling process. If the operation fails for any reason, |
23 // ptr() method will return NULL. This constructor set the identifier of this | 24 // ptr() method will return NULL. This constructor set the identifier of this |
24 // buffer to 0. | 25 // buffer to 0. |
25 explicit SharedBuffer(uint32 size); | 26 explicit SharedBuffer(uint32 size); |
26 | 27 |
27 // Opens an existing shared memory buffer and maps it to the memory of | 28 // Opens an existing shared memory buffer and maps it to the memory of |
28 // the calling process (in read only mode). If the operation fails for any | 29 // the calling process (in read only mode). If the operation fails for any |
29 // reason, ptr() method will return NULL. | 30 // reason, ptr() method will return NULL. |
30 SharedBuffer(int id, base::SharedMemoryHandle handle, uint32 size); | 31 SharedBuffer(int id, base::SharedMemoryHandle handle, uint32 size); |
31 | 32 |
32 // Opens an existing shared memory buffer created by a different process and | 33 // Opens an existing shared memory buffer created by a different process and |
33 // maps it to the memory of the calling process (in read only mode). If | 34 // maps it to the memory of the calling process (in read only mode). If |
34 // the operation fails for any reason, ptr() method will return NULL. | 35 // the operation fails for any reason, ptr() method will return NULL. |
35 SharedBuffer(int id, base::SharedMemoryHandle handle, | 36 SharedBuffer(int id, base::SharedMemoryHandle handle, |
36 base::ProcessHandle process, uint32 size); | 37 base::ProcessHandle process, uint32 size); |
37 | 38 |
38 // Returns pointer to the beginning of the allocated data buffer. Returns NULL | 39 // Returns pointer to the beginning of the allocated data buffer. Returns NULL |
39 // if the object initialization failed for any reason. | 40 // if the object initialization failed for any reason. |
40 void* ptr() const { return shared_memory_.memory(); } | 41 void* ptr() const { return shared_memory_.memory(); } |
41 | 42 |
42 // Returns handle of the shared memory section containing the allocated | 43 // Returns handle of the shared memory section containing the allocated |
43 // data buffer. | 44 // data buffer. |
44 base::SharedMemoryHandle handle() const { return shared_memory_.handle(); } | 45 base::SharedMemoryHandle handle() const { return shared_memory_.handle(); } |
45 | 46 |
| 47 // Calls SharedMemory::ShareToProcess to share the handle with a different |
| 48 // process. |
| 49 bool ShareToProcess(base::ProcessHandle process, |
| 50 base::SharedMemoryHandle* new_handle); |
| 51 |
46 int id() const { return id_; } | 52 int id() const { return id_; } |
47 uint32 size() const { return size_; } | 53 uint32 size() const { return size_; } |
48 | 54 |
49 void set_id(int id) { id_ = id; } | 55 void set_id(int id) { id_ = id; } |
50 | 56 |
51 private: | 57 private: |
52 friend class base::RefCountedThreadSafe<SharedBuffer>; | 58 friend class base::RefCountedThreadSafe<SharedBuffer>; |
53 virtual ~SharedBuffer(); | 59 virtual ~SharedBuffer(); |
54 | 60 |
55 // Unique identifier of the buffer or 0 if ID hasn't been set. | 61 // Unique identifier of the buffer or 0 if ID hasn't been set. |
56 int id_; | 62 int id_; |
57 | 63 |
58 // Shared memory section backing up the buffer. | 64 // Shared memory section backing up the buffer. |
59 base::SharedMemory shared_memory_; | 65 base::SharedMemory shared_memory_; |
60 | 66 |
61 // Size of the buffer in bytes. | 67 // Size of the buffer in bytes. |
62 uint32 size_; | 68 uint32 size_; |
63 | 69 |
64 DISALLOW_COPY_AND_ASSIGN(SharedBuffer); | 70 DISALLOW_COPY_AND_ASSIGN(SharedBuffer); |
65 }; | 71 }; |
66 | 72 |
67 } // namespace remoting | 73 } // namespace media |
68 | 74 |
69 #endif // REMOTING_CAPTURER_SHARED_BUFFER_H_ | 75 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_SHARED_BUFFER_H_ |
OLD | NEW |