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 #include "ppapi/shared_impl/media_stream_frame_buffer.h" | 5 #include "ppapi/shared_impl/media_stream_frame_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 | 9 |
10 namespace ppapi { | 10 namespace ppapi { |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 MediaStreamFrameBuffer::~MediaStreamFrameBuffer() { | 24 MediaStreamFrameBuffer::~MediaStreamFrameBuffer() { |
25 } | 25 } |
26 | 26 |
27 bool MediaStreamFrameBuffer::SetFrames( | 27 bool MediaStreamFrameBuffer::SetFrames( |
28 int32_t number_of_frames, | 28 int32_t number_of_frames, |
29 int32_t frame_size, | 29 int32_t frame_size, |
30 scoped_ptr<base::SharedMemory> shm, | 30 scoped_ptr<base::SharedMemory> shm, |
31 bool enqueue_all_frames) { | 31 bool enqueue_all_frames) { |
| 32 base::AutoLock lock(mutex_); |
32 DCHECK(shm); | 33 DCHECK(shm); |
33 DCHECK(!shm_); | 34 DCHECK(!shm_); |
34 DCHECK_GT(number_of_frames, 0); | 35 DCHECK_GT(number_of_frames, 0); |
35 DCHECK_GT(frame_size, static_cast<int32_t>(sizeof(MediaStreamFrame::Header))); | 36 DCHECK_GT(frame_size, static_cast<int32_t>(sizeof(MediaStreamFrame::Header))); |
36 DCHECK_EQ(frame_size & 0x3, 0); | 37 DCHECK_EQ(frame_size & 0x3, 0); |
37 | 38 |
38 number_of_frames_ = number_of_frames; | 39 number_of_frames_ = number_of_frames; |
39 frame_size_ = frame_size; | 40 frame_size_ = frame_size; |
40 | 41 |
41 int32_t size = number_of_frames_ * frame_size; | 42 int32_t size = number_of_frames_ * frame_size; |
42 shm_ = shm.Pass(); | 43 shm_ = shm.Pass(); |
43 if (!shm_->Map(size)) | 44 if (!shm_->Map(size)) |
44 return false; | 45 return false; |
45 | 46 |
46 uint8_t* p = reinterpret_cast<uint8_t*>(shm_->memory()); | 47 uint8_t* p = reinterpret_cast<uint8_t*>(shm_->memory()); |
47 for (int32_t i = 0; i < number_of_frames; ++i) { | 48 for (int32_t i = 0; i < number_of_frames; ++i) { |
48 if (enqueue_all_frames) | 49 if (enqueue_all_frames) |
49 frame_queue_.push_back(i); | 50 frame_queue_.push_back(i); |
50 frames_.push_back(reinterpret_cast<MediaStreamFrame*>(p)); | 51 frames_.push_back(reinterpret_cast<MediaStreamFrame*>(p)); |
51 p += frame_size_; | 52 p += frame_size_; |
52 } | 53 } |
53 return true; | 54 return true; |
54 } | 55 } |
55 | 56 |
56 int32_t MediaStreamFrameBuffer::DequeueFrame() { | 57 int32_t MediaStreamFrameBuffer::DequeueFrame() { |
| 58 base::AutoLock lock(mutex_); |
57 if (frame_queue_.empty()) | 59 if (frame_queue_.empty()) |
58 return PP_ERROR_FAILED; | 60 return PP_ERROR_FAILED; |
59 int32_t frame = frame_queue_.front(); | 61 int32_t frame = frame_queue_.front(); |
60 frame_queue_.pop_front(); | 62 frame_queue_.pop_front(); |
61 return frame; | 63 return frame; |
62 } | 64 } |
63 | 65 |
64 void MediaStreamFrameBuffer::EnqueueFrame(int32_t index) { | 66 void MediaStreamFrameBuffer::EnqueueFrame(int32_t index) { |
65 DCHECK_GE(index, 0); | 67 DCHECK_GE(index, 0); |
66 DCHECK_LT(index, number_of_frames_); | 68 DCHECK_LT(index, number_of_frames_); |
67 frame_queue_.push_back(index); | 69 { |
| 70 base::AutoLock lock(mutex_); |
| 71 frame_queue_.push_back(index); |
| 72 } |
68 delegate_->OnNewFrameEnqueued(); | 73 delegate_->OnNewFrameEnqueued(); |
69 } | 74 } |
70 | 75 |
71 MediaStreamFrame* MediaStreamFrameBuffer::GetFramePointer( | 76 MediaStreamFrame* MediaStreamFrameBuffer::GetFramePointer( |
72 int32_t index) { | 77 int32_t index) { |
| 78 base::AutoLock lock(mutex_); |
73 DCHECK_GE(index, 0); | 79 DCHECK_GE(index, 0); |
74 DCHECK_LT(index, number_of_frames_); | 80 DCHECK_LT(index, number_of_frames_); |
75 return frames_[index]; | 81 return frames_[index]; |
76 } | 82 } |
77 | 83 |
78 } // namespace ppapi | 84 } // namespace ppapi |
OLD | NEW |