| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 5 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/callback.h" | 8 #include "base/callback.h" | 
| 9 #include "base/logging.h" | 9 #include "base/logging.h" | 
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 121       DCHECK(buffer->held_by_producer); | 121       DCHECK(buffer->held_by_producer); | 
| 122       return buffer_id; | 122       return buffer_id; | 
| 123     } | 123     } | 
| 124   } | 124   } | 
| 125   return -1;  // Buffer is not from our pool. | 125   return -1;  // Buffer is not from our pool. | 
| 126 } | 126 } | 
| 127 | 127 | 
| 128 scoped_refptr<media::VideoFrame> VideoCaptureBufferPool::ReserveI420VideoFrame( | 128 scoped_refptr<media::VideoFrame> VideoCaptureBufferPool::ReserveI420VideoFrame( | 
| 129     const gfx::Size& size, | 129     const gfx::Size& size, | 
| 130     int rotation) { | 130     int rotation) { | 
| 131   if (static_cast<size_t>(size.GetArea() * 3 / 2) != GetMemorySize()) | 131   if (GetMemorySize() != | 
|  | 132       media::VideoFrame::AllocationSize(media::VideoFrame::I420, size)) { | 
|  | 133     DCHECK_EQ(GetMemorySize(), | 
|  | 134               media::VideoFrame::AllocationSize(media::VideoFrame::I420, size)); | 
| 132     return NULL; | 135     return NULL; | 
|  | 136   } | 
| 133 | 137 | 
| 134   base::AutoLock lock(lock_); | 138   base::AutoLock lock(lock_); | 
| 135 | 139 | 
| 136   int buffer_id = ReserveForProducerInternal(); | 140   int buffer_id = ReserveForProducerInternal(); | 
| 137   if (buffer_id < 0) | 141   if (buffer_id < 0) | 
| 138     return NULL; | 142     return NULL; | 
| 139 | 143 | 
| 140   base::Closure disposal_handler = base::Bind( | 144   base::Closure disposal_handler = base::Bind( | 
| 141       &VideoCaptureBufferPool::RelinquishProducerReservation, | 145       &VideoCaptureBufferPool::RelinquishProducerReservation, | 
| 142       this, | 146       this, | 
| 143       buffer_id); | 147       buffer_id); | 
| 144 | 148 | 
| 145   Buffer* buffer = buffers_[buffer_id]; | 149   Buffer* buffer = buffers_[buffer_id]; | 
| 146   // Wrap the buffer in a VideoFrame container. | 150   // Wrap the buffer in a VideoFrame container. | 
| 147   scoped_refptr<media::VideoFrame> frame = | 151   scoped_refptr<media::VideoFrame> frame = | 
| 148       media::VideoFrame::WrapExternalSharedMemory( | 152       media::VideoFrame::WrapExternalSharedMemory( | 
| 149           media::VideoFrame::I420, | 153           media::VideoFrame::I420, | 
| 150           size, | 154           size, | 
| 151           gfx::Rect(size), | 155           gfx::Rect(size), | 
| 152           size, | 156           size, | 
| 153           static_cast<uint8*>(buffer->shared_memory.memory()), | 157           static_cast<uint8*>(buffer->shared_memory.memory()), | 
|  | 158           GetMemorySize(), | 
| 154           buffer->shared_memory.handle(), | 159           buffer->shared_memory.handle(), | 
| 155           base::TimeDelta(), | 160           base::TimeDelta(), | 
| 156           disposal_handler); | 161           disposal_handler); | 
| 157 | 162 | 
| 158   if (buffer->rotation != rotation) { | 163   if (buffer->rotation != rotation) { | 
| 159     // TODO(nick): Generalize the |rotation| mechanism. | 164     // TODO(nick): Generalize the |rotation| mechanism. | 
| 160     media::FillYUV(frame.get(), 0, 128, 128); | 165     media::FillYUV(frame.get(), 0, 128, 128); | 
| 161     buffer->rotation = rotation; | 166     buffer->rotation = rotation; | 
| 162   } | 167   } | 
| 163 | 168 | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 200   return buffer_id; | 205   return buffer_id; | 
| 201 } | 206 } | 
| 202 | 207 | 
| 203 bool VideoCaptureBufferPool::IsAllocated() const { | 208 bool VideoCaptureBufferPool::IsAllocated() const { | 
| 204   lock_.AssertAcquired(); | 209   lock_.AssertAcquired(); | 
| 205   return !buffers_.empty(); | 210   return !buffers_.empty(); | 
| 206 } | 211 } | 
| 207 | 212 | 
| 208 }  // namespace content | 213 }  // namespace content | 
| 209 | 214 | 
| OLD | NEW | 
|---|