OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_FIFO_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_FIFO_H_ |
6 #define CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_FIFO_H_ | 6 #define CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_FIFO_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // return; | 75 // return; |
76 // } | 76 // } |
77 // // Parse the message using Read functions of MediaMessage: | 77 // // Parse the message using Read functions of MediaMessage: |
78 // // ... | 78 // // ... |
79 // // Once the message is going out of scope, MediaMessageFifo will receive | 79 // // Once the message is going out of scope, MediaMessageFifo will receive |
80 // // a notification that the underlying memory can be released | 80 // // a notification that the underlying memory can be released |
81 // // (i.e. the external read pointer can be updated). | 81 // // (i.e. the external read pointer can be updated). |
82 // | 82 // |
83 // | 83 // |
84 class MediaMessageFifo { | 84 class MediaMessageFifo { |
| 85 private: |
| 86 struct Descriptor { |
| 87 size_t size; |
| 88 size_t rd_offset; |
| 89 size_t wr_offset; |
| 90 |
| 91 // Ensure the first item has the same alignment as an int64. |
| 92 int64 first_item; |
| 93 }; |
| 94 |
85 public: | 95 public: |
| 96 static const int kDescriptorSize = sizeof(Descriptor); |
| 97 |
86 // Creates a media message fifo using |mem| as the underlying serialized | 98 // Creates a media message fifo using |mem| as the underlying serialized |
87 // structure. | 99 // structure. |
88 // If |init| is true, the underlying fifo structure is initialized. | 100 // If |init| is true, the underlying fifo structure is initialized. |
89 MediaMessageFifo(scoped_ptr<MediaMemoryChunk> mem, bool init); | 101 MediaMessageFifo(scoped_ptr<MediaMemoryChunk> mem, bool init); |
90 ~MediaMessageFifo(); | 102 ~MediaMessageFifo(); |
91 | 103 |
92 // When the consumer and the feeder are living in two different processes, | 104 // When the consumer and the feeder are living in two different processes, |
93 // we might want to convey some messages between these two processes to notify | 105 // we might want to convey some messages between these two processes to notify |
94 // about some fifo activity. | 106 // about some fifo activity. |
95 void ObserveReadActivity(const base::Closure& read_event_cb); | 107 void ObserveReadActivity(const base::Closure& read_event_cb); |
96 void ObserveWriteActivity(const base::Closure& write_event_cb); | 108 void ObserveWriteActivity(const base::Closure& write_event_cb); |
97 | 109 |
98 // Reserves a writeable block of memory at the back of the fifo, | 110 // Reserves a writeable block of memory at the back of the fifo, |
99 // corresponding to the serialized structure of the message. | 111 // corresponding to the serialized structure of the message. |
100 // Returns NULL if the required size cannot be allocated. | 112 // Returns NULL if the required size cannot be allocated. |
101 scoped_ptr<MediaMemoryChunk> ReserveMemory(size_t size); | 113 scoped_ptr<MediaMemoryChunk> ReserveMemory(size_t size); |
102 | 114 |
103 // Pop a message from the queue. | 115 // Pop a message from the queue. |
104 // Returns a null pointer if there is no message left. | 116 // Returns a null pointer if there is no message left. |
105 scoped_ptr<MediaMessage> Pop(); | 117 scoped_ptr<MediaMessage> Pop(); |
106 | 118 |
107 // Flush the fifo. | 119 // Flush the fifo. |
108 void Flush(); | 120 void Flush(); |
109 | 121 |
110 private: | 122 private: |
111 struct Descriptor { | |
112 size_t size; | |
113 size_t rd_offset; | |
114 size_t wr_offset; | |
115 | |
116 // Ensure the first item has the same alignment as an int64. | |
117 int64 first_item; | |
118 }; | |
119 | |
120 // Add some accessors to ensure security on the browser process side. | 123 // Add some accessors to ensure security on the browser process side. |
121 size_t current_rd_offset() const; | 124 size_t current_rd_offset() const; |
122 size_t current_wr_offset() const; | 125 size_t current_wr_offset() const; |
123 size_t internal_rd_offset() const { | 126 size_t internal_rd_offset() const { |
124 DCHECK_LT(internal_rd_offset_, size_); | 127 DCHECK_LT(internal_rd_offset_, size_); |
125 return internal_rd_offset_; | 128 return internal_rd_offset_; |
126 } | 129 } |
127 size_t internal_wr_offset() const { | 130 size_t internal_wr_offset() const { |
128 DCHECK_LT(internal_wr_offset_, size_); | 131 DCHECK_LT(internal_wr_offset_, size_); |
129 return internal_wr_offset_; | 132 return internal_wr_offset_; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 base::WeakPtr<MediaMessageFifo> weak_this_; | 202 base::WeakPtr<MediaMessageFifo> weak_this_; |
200 base::WeakPtrFactory<MediaMessageFifo> weak_factory_; | 203 base::WeakPtrFactory<MediaMessageFifo> weak_factory_; |
201 | 204 |
202 DISALLOW_COPY_AND_ASSIGN(MediaMessageFifo); | 205 DISALLOW_COPY_AND_ASSIGN(MediaMessageFifo); |
203 }; | 206 }; |
204 | 207 |
205 } // namespace media | 208 } // namespace media |
206 } // namespace chromecast | 209 } // namespace chromecast |
207 | 210 |
208 #endif // CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_FIFO_H_ | 211 #endif // CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_FIFO_H_ |
OLD | NEW |