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 PPAPI_SHARED_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_ | 5 #ifndef PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_MANAGER_H_ |
6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_ | 6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
14 #include "ppapi/shared_impl/media_stream_frame.h" | |
15 #include "ppapi/shared_impl/ppapi_shared_export.h" | 14 #include "ppapi/shared_impl/ppapi_shared_export.h" |
16 | 15 |
17 namespace ppapi { | 16 namespace ppapi { |
18 | 17 |
| 18 union MediaStreamBuffer; |
| 19 |
19 // This class is used by both read side and write side of a MediaStreamTrack to | 20 // This class is used by both read side and write side of a MediaStreamTrack to |
20 // maintain a queue of frames for reading or writing. | 21 // maintain a queue of buffers for reading or writing. |
21 // | 22 // |
22 // An example: | 23 // An example: |
23 // 1. The writer calls the writer's |frame_buffer_.Dequeue()| to get a free | 24 // 1. The writer calls the writer's |buffer_manager_.Dequeue()| to get a free |
24 // frame. | 25 // buffer. |
25 // 2. The writer fills data into the frame. | 26 // 2. The writer fills data into the buffer. |
26 // 3. The writer sends the frame index to the reader via an IPC message. | 27 // 3. The writer sends the buffer index to the reader via an IPC message. |
27 // 4. The reader receives the frame index and calls the reader's | 28 // 4. The reader receives the buffer index and calls the reader's |
28 // |frame_buffer.Enqueue()| to put the frame into the read's queue. | 29 // |buffer_buffer.Enqueue()| to put the buffer into the read's queue. |
29 // 5. The reader calls reader's |frame_buffer_.Dequeue()| to get a received | 30 // 5. The reader calls reader's |buffer_buffer_.Dequeue()| to get a received |
30 // frame. | 31 // buffer. |
31 // 6. When the frame from the step 5 is consumed, the reader sends the frame | 32 // 6. When the buffer from the step 5 is consumed, the reader sends the buffer |
32 // index back to writer via an IPC message. | 33 // index back to writer via an IPC message. |
33 // 7. The writer receives the frame index and puts it back to the writer's free | 34 // 7. The writer receives the buffer index and puts it back to the writer's |
34 // frame queue by calling the writer's |frame_buffer_.Enqueue()|. | 35 // free buffer queue by calling the writer's |buffer_manager_.Enqueue()|. |
35 // 8. Go back to step 1. | 36 // 8. Go back to step 1. |
36 class PPAPI_SHARED_EXPORT MediaStreamFrameBuffer { | 37 class PPAPI_SHARED_EXPORT MediaStreamBufferManager { |
37 public: | 38 public: |
38 class PPAPI_SHARED_EXPORT Delegate { | 39 class PPAPI_SHARED_EXPORT Delegate { |
39 public: | 40 public: |
40 virtual ~Delegate(); | 41 virtual ~Delegate(); |
41 // It is called when a new frame is enqueued. | 42 // It is called when a new buffer is enqueued. |
42 virtual void OnNewFrameEnqueued(); | 43 virtual void OnNewBufferEnqueued(); |
43 }; | 44 }; |
44 | 45 |
45 // MediaStreamFrameBuffer doesn't own |delegate|, the caller should keep | 46 // MediaStreamBufferManager doesn't own |delegate|, the caller should keep |
46 // it alive during the MediaStreamFrameBuffer's lifecycle. | 47 // it alive during the MediaStreamBufferManager's lifecycle. |
47 explicit MediaStreamFrameBuffer(Delegate* delegate); | 48 explicit MediaStreamBufferManager(Delegate* delegate); |
48 | 49 |
49 ~MediaStreamFrameBuffer(); | 50 ~MediaStreamBufferManager(); |
50 | 51 |
51 int32_t number_of_frames() const { return number_of_frames_; } | 52 int32_t number_of_buffers() const { return number_of_buffers_; } |
52 | 53 |
53 int32_t frame_size() const { return frame_size_; } | 54 int32_t buffer_size() const { return buffer_size_; } |
54 | 55 |
55 // Initializes shared memory for frames transmission. | 56 // Initializes shared memory for buffers transmission. |
56 bool SetFrames(int32_t number_of_frames, | 57 bool SetBuffers(int32_t number_of_buffers, |
57 int32_t frame_size, | 58 int32_t buffer_size, |
58 scoped_ptr<base::SharedMemory> shm, | 59 scoped_ptr<base::SharedMemory> shm, |
59 bool enqueue_all_frames); | 60 bool enqueue_all_buffers); |
60 | 61 |
61 // Dequeues a frame from |frame_queue_|. | 62 // Dequeues a buffer from |buffer_queue_|. |
62 int32_t DequeueFrame(); | 63 int32_t DequeueBuffer(); |
63 | 64 |
64 // Puts a frame into |frame_queue_|. | 65 // Puts a buffer into |buffer_queue_|. |
65 void EnqueueFrame(int32_t index); | 66 void EnqueueBuffer(int32_t index); |
66 | 67 |
67 // Gets the frame address for the given frame index. | 68 // Gets the buffer address for the given buffer index. |
68 MediaStreamFrame* GetFramePointer(int32_t index); | 69 MediaStreamBuffer* GetBufferPointer(int32_t index); |
69 | 70 |
70 private: | 71 private: |
71 Delegate* delegate_; | 72 Delegate* delegate_; |
72 | 73 |
73 // A queue of frame indexes. | 74 // A queue of buffer indices. |
74 std::deque<int32_t> frame_queue_; | 75 std::deque<int32_t> buffer_queue_; |
75 | 76 |
76 // A vector of frame pointers. It is used for index to pointer converting. | 77 // A vector of buffer pointers. It is used for index to pointer converting. |
77 std::vector<MediaStreamFrame*> frames_; | 78 std::vector<MediaStreamBuffer*> buffers_; |
78 | 79 |
79 // The frame size in bytes. | 80 // The buffer size in bytes. |
80 int32_t frame_size_; | 81 int32_t buffer_size_; |
81 | 82 |
82 // The number of frames in the shared memory. | 83 // The number of buffers in the shared memory. |
83 int32_t number_of_frames_; | 84 int32_t number_of_buffers_; |
84 | 85 |
85 // A memory block shared between renderer process and plugin process. | 86 // A memory block shared between renderer process and plugin process. |
86 scoped_ptr<base::SharedMemory> shm_; | 87 scoped_ptr<base::SharedMemory> shm_; |
87 | 88 |
88 DISALLOW_COPY_AND_ASSIGN(MediaStreamFrameBuffer); | 89 DISALLOW_COPY_AND_ASSIGN(MediaStreamBufferManager); |
89 }; | 90 }; |
90 | 91 |
91 } // namespace ppapi | 92 } // namespace ppapi |
92 | 93 |
93 #endif // PPAPI_SHAERD_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_ | 94 #endif // PPAPI_SHAERD_IMPL_MEDIA_STREAM_BUFFER_MANAGER_H_ |
OLD | NEW |