Stop retring GCM unregistration requests after reaching maximum number
[chromium-blink-merge.git] / ppapi / shared_impl / media_stream_buffer_manager.h
blob28d8e806ae57a47991435314a0215e202ac07a88
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_MANAGER_H_
6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_MANAGER_H_
8 #include <deque>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/shared_memory.h"
14 #include "ppapi/shared_impl/ppapi_shared_export.h"
16 namespace ppapi {
18 union MediaStreamBuffer;
20 // This class is used by both read side and write side of a MediaStreamTrack to
21 // maintain a queue of buffers for reading or writing.
23 // An example:
24 // 1. The writer calls the writer's |buffer_manager_.Dequeue()| to get a free
25 // buffer.
26 // 2. The writer fills data into the buffer.
27 // 3. The writer sends the buffer index to the reader via an IPC message.
28 // 4. The reader receives the buffer index and calls the reader's
29 // |buffer_buffer.Enqueue()| to put the buffer into the read's queue.
30 // 5. The reader calls reader's |buffer_buffer_.Dequeue()| to get a received
31 // buffer.
32 // 6. When the buffer from the step 5 is consumed, the reader sends the buffer
33 // index back to writer via an IPC message.
34 // 7. The writer receives the buffer index and puts it back to the writer's
35 // free buffer queue by calling the writer's |buffer_manager_.Enqueue()|.
36 // 8. Go back to step 1.
37 class PPAPI_SHARED_EXPORT MediaStreamBufferManager {
38 public:
39 class PPAPI_SHARED_EXPORT Delegate {
40 public:
41 virtual ~Delegate();
42 // It is called when a new buffer is enqueued.
43 virtual void OnNewBufferEnqueued();
46 // MediaStreamBufferManager doesn't own |delegate|, the caller should keep
47 // it alive during the MediaStreamBufferManager's lifecycle.
48 explicit MediaStreamBufferManager(Delegate* delegate);
50 ~MediaStreamBufferManager();
52 int32_t number_of_buffers() const { return number_of_buffers_; }
54 int32_t buffer_size() const { return buffer_size_; }
56 base::SharedMemory* shm() { return shm_.get(); }
58 // Initializes shared memory for buffers transmission.
59 bool SetBuffers(int32_t number_of_buffers,
60 int32_t buffer_size,
61 scoped_ptr<base::SharedMemory> shm,
62 bool enqueue_all_buffers);
64 // Dequeues a buffer from |buffer_queue_|.
65 int32_t DequeueBuffer();
67 // Dequeues all the buffers from |buffer_queue_|.
68 std::vector<int32_t> DequeueBuffers();
70 // Puts a buffer into |buffer_queue_|.
71 void EnqueueBuffer(int32_t index);
73 // Gets the buffer address for the given buffer index.
74 MediaStreamBuffer* GetBufferPointer(int32_t index);
76 private:
77 Delegate* delegate_;
79 // A queue of buffer indices.
80 std::deque<int32_t> buffer_queue_;
82 // A vector of buffer pointers. It is used for index to pointer converting.
83 std::vector<MediaStreamBuffer*> buffers_;
85 // The buffer size in bytes.
86 int32_t buffer_size_;
88 // The number of buffers in the shared memory.
89 int32_t number_of_buffers_;
91 // A memory block shared between renderer process and plugin process.
92 scoped_ptr<base::SharedMemory> shm_;
94 DISALLOW_COPY_AND_ASSIGN(MediaStreamBufferManager);
97 } // namespace ppapi
99 #endif // PPAPI_SHAERD_IMPL_MEDIA_STREAM_BUFFER_MANAGER_H_