| 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_FRAME_BUFFER_H_ |
| 6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_ | 6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_FRAME_BUFFER_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 "base/synchronization/lock.h" |
| 14 #include "ppapi/shared_impl/media_stream_frame.h" | 15 #include "ppapi/shared_impl/media_stream_frame.h" |
| 15 #include "ppapi/shared_impl/ppapi_shared_export.h" | 16 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 16 | 17 |
| 17 namespace ppapi { | 18 namespace ppapi { |
| 18 | 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 frames 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 |frame_buffer_.Dequeue()| to get a free |
| (...skipping 17 matching lines...) Expand all Loading... |
| 41 // It is called when a new frame is enqueued. | 42 // It is called when a new frame is enqueued. |
| 42 virtual void OnNewFrameEnqueued(); | 43 virtual void OnNewFrameEnqueued(); |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 // MediaStreamFrameBuffer doesn't own |delegate|, the caller should keep | 46 // MediaStreamFrameBuffer doesn't own |delegate|, the caller should keep |
| 46 // it alive during the MediaStreamFrameBuffer's lifecycle. | 47 // it alive during the MediaStreamFrameBuffer's lifecycle. |
| 47 explicit MediaStreamFrameBuffer(Delegate* delegate); | 48 explicit MediaStreamFrameBuffer(Delegate* delegate); |
| 48 | 49 |
| 49 ~MediaStreamFrameBuffer(); | 50 ~MediaStreamFrameBuffer(); |
| 50 | 51 |
| 51 int32_t number_of_frames() const { return number_of_frames_; } | 52 int32_t number_of_frames() const { |
| 53 base::AutoLock lock(mutex_); |
| 54 return number_of_frames_; |
| 55 } |
| 52 | 56 |
| 53 int32_t frame_size() const { return frame_size_; } | 57 int32_t frame_size() const { |
| 58 base::AutoLock lock(mutex_); |
| 59 return frame_size_; |
| 60 } |
| 54 | 61 |
| 55 // Initializes shared memory for frames transmission. | 62 // Initializes shared memory for frames transmission. |
| 56 bool SetFrames(int32_t number_of_frames, | 63 bool SetFrames(int32_t number_of_frames, |
| 57 int32_t frame_size, | 64 int32_t frame_size, |
| 58 scoped_ptr<base::SharedMemory> shm, | 65 scoped_ptr<base::SharedMemory> shm, |
| 59 bool enqueue_all_frames); | 66 bool enqueue_all_frames); |
| 60 | 67 |
| 61 // Dequeues a frame from |frame_queue_|. | 68 // Dequeues a frame from |frame_queue_|. |
| 62 int32_t DequeueFrame(); | 69 int32_t DequeueFrame(); |
| 63 | 70 |
| 64 // Puts a frame into |frame_queue_|. | 71 // Puts a frame into |frame_queue_|. |
| 65 void EnqueueFrame(int32_t index); | 72 void EnqueueFrame(int32_t index); |
| 66 | 73 |
| 67 // Gets the frame address for the given frame index. | 74 // Gets the frame address for the given frame index. |
| 68 MediaStreamFrame* GetFramePointer(int32_t index); | 75 MediaStreamFrame* GetFramePointer(int32_t index); |
| 69 | 76 |
| 70 private: | 77 private: |
| 71 Delegate* delegate_; | 78 Delegate* delegate_; |
| 72 | 79 |
| 80 // A mutex to protect below fields. |
| 81 mutable base::Lock mutex_; |
| 82 |
| 73 // A queue of frame indexes. | 83 // A queue of frame indexes. |
| 74 std::deque<int32_t> frame_queue_; | 84 std::deque<int32_t> frame_queue_; |
| 75 | 85 |
| 76 // A vector of frame pointers. It is used for index to pointer converting. | 86 // A vector of frame pointers. It is used for index to pointer converting. |
| 77 std::vector<MediaStreamFrame*> frames_; | 87 std::vector<MediaStreamFrame*> frames_; |
| 78 | 88 |
| 79 // The frame size in bytes. | 89 // The frame size in bytes. |
| 80 int32_t frame_size_; | 90 int32_t frame_size_; |
| 81 | 91 |
| 82 // The number of frames in the shared memory. | 92 // The number of frames in the shared memory. |
| 83 int32_t number_of_frames_; | 93 int32_t number_of_frames_; |
| 84 | 94 |
| 85 // A memory block shared between renderer process and plugin process. | 95 // A memory block shared between renderer process and plugin process. |
| 86 scoped_ptr<base::SharedMemory> shm_; | 96 scoped_ptr<base::SharedMemory> shm_; |
| 87 | 97 |
| 88 DISALLOW_COPY_AND_ASSIGN(MediaStreamFrameBuffer); | 98 DISALLOW_COPY_AND_ASSIGN(MediaStreamFrameBuffer); |
| 89 }; | 99 }; |
| 90 | 100 |
| 91 } // namespace ppapi | 101 } // namespace ppapi |
| 92 | 102 |
| 93 #endif // PPAPI_SHAERD_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_ | 103 #endif // PPAPI_SHAERD_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_ |
| OLD | NEW |