| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_device_client.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 private: | 131 private: |
| 132 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } | 132 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } |
| 133 | 133 |
| 134 const int id_; | 134 const int id_; |
| 135 const scoped_refptr<VideoCaptureBufferPool> pool_; | 135 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 136 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; | 136 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 // Internal ref-counted class wrapping an incoming GpuMemoryBuffer into a | 139 // Internal ref-counted class wrapping an incoming GpuMemoryBuffer into a |
| 140 // Texture backed VideoFrame. This VideoFrame creation is balanced by a waiting | 140 // Texture backed VideoFrame. This VideoFrame creation is balanced by a waiting |
| 141 // on the associated |sync_point|. After VideoFrame consumption the inserted | 141 // on the associated |sync_token|. After VideoFrame consumption the inserted |
| 142 // ReleaseCallback() will be called, where the Texture is destroyed. | 142 // ReleaseCallback() will be called, where the Texture is destroyed. |
| 143 // | 143 // |
| 144 // This class jumps between threads due to GPU-related thread limitations, i.e. | 144 // This class jumps between threads due to GPU-related thread limitations, i.e. |
| 145 // some objects cannot be accessed from IO Thread whereas others need to be | 145 // some objects cannot be accessed from IO Thread whereas others need to be |
| 146 // constructed on UI Thread. For this reason most of the operations are carried | 146 // constructed on UI Thread. For this reason most of the operations are carried |
| 147 // out on Capture Thread (|capture_task_runner_|). | 147 // out on Capture Thread (|capture_task_runner_|). |
| 148 class VideoCaptureDeviceClient::TextureWrapHelper final | 148 class VideoCaptureDeviceClient::TextureWrapHelper final |
| 149 : public base::RefCountedThreadSafe<TextureWrapHelper> { | 149 : public base::RefCountedThreadSafe<TextureWrapHelper> { |
| 150 public: | 150 public: |
| 151 TextureWrapHelper( | 151 TextureWrapHelper( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 165 | 165 |
| 166 // Creates some necessary members in |capture_task_runner_|. | 166 // Creates some necessary members in |capture_task_runner_|. |
| 167 void Init(); | 167 void Init(); |
| 168 // Runs the bottom half of the GlHelper creation. | 168 // Runs the bottom half of the GlHelper creation. |
| 169 void CreateGlHelper( | 169 void CreateGlHelper( |
| 170 scoped_refptr<ContextProviderCommandBuffer> capture_thread_context); | 170 scoped_refptr<ContextProviderCommandBuffer> capture_thread_context); |
| 171 | 171 |
| 172 // Recycles |memory_buffer|, deletes Image and Texture on VideoFrame release. | 172 // Recycles |memory_buffer|, deletes Image and Texture on VideoFrame release. |
| 173 void ReleaseCallback(const std::vector<GLuint>& image_ids, | 173 void ReleaseCallback(const std::vector<GLuint>& image_ids, |
| 174 const std::vector<GLuint>& texture_ids, | 174 const std::vector<GLuint>& texture_ids, |
| 175 uint32 sync_point); | 175 const gpu::SyncToken& sync_token); |
| 176 | 176 |
| 177 // The Command Buffer lost the GL context, f.i. GPU process crashed. Signal | 177 // The Command Buffer lost the GL context, f.i. GPU process crashed. Signal |
| 178 // error to our owner so the capture can be torn down. | 178 // error to our owner so the capture can be torn down. |
| 179 void LostContextCallback(); | 179 void LostContextCallback(); |
| 180 | 180 |
| 181 // Prints the error |message| and notifies |controller_| of an error. | 181 // Prints the error |message| and notifies |controller_| of an error. |
| 182 void OnError(const std::string& message); | 182 void OnError(const std::string& message); |
| 183 | 183 |
| 184 // |controller_| should only be used on IO thread. | 184 // |controller_| should only be used on IO thread. |
| 185 const base::WeakPtr<VideoCaptureController> controller_; | 185 const base::WeakPtr<VideoCaptureController> controller_; |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 texture_id); | 641 texture_id); |
| 642 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 642 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
| 643 } | 643 } |
| 644 texture_ids.push_back(texture_id); | 644 texture_ids.push_back(texture_id); |
| 645 | 645 |
| 646 const gpu::MailboxHolder& mailbox_holder( | 646 const gpu::MailboxHolder& mailbox_holder( |
| 647 gl_helper_->ProduceMailboxHolderFromTexture(texture_id)); | 647 gl_helper_->ProduceMailboxHolderFromTexture(texture_id)); |
| 648 DCHECK(!mailbox_holder.mailbox.IsZero()); | 648 DCHECK(!mailbox_holder.mailbox.IsZero()); |
| 649 DCHECK(mailbox_holder.mailbox.Verify()); | 649 DCHECK(mailbox_holder.mailbox.Verify()); |
| 650 DCHECK(mailbox_holder.texture_target); | 650 DCHECK(mailbox_holder.texture_target); |
| 651 DCHECK(mailbox_holder.sync_point); | 651 DCHECK(mailbox_holder.sync_token.HasData()); |
| 652 mailbox_holders.push_back(mailbox_holder); | 652 mailbox_holders.push_back(mailbox_holder); |
| 653 } | 653 } |
| 654 | 654 |
| 655 scoped_refptr<media::VideoFrame> video_frame = | 655 scoped_refptr<media::VideoFrame> video_frame = |
| 656 VideoFrame::WrapYUV420NativeTextures( | 656 VideoFrame::WrapYUV420NativeTextures( |
| 657 mailbox_holders[VideoFrame::kYPlane], | 657 mailbox_holders[VideoFrame::kYPlane], |
| 658 mailbox_holders[VideoFrame::kUPlane], | 658 mailbox_holders[VideoFrame::kUPlane], |
| 659 mailbox_holders[VideoFrame::kVPlane], | 659 mailbox_holders[VideoFrame::kVPlane], |
| 660 media::BindToCurrentLoop(base::Bind( | 660 media::BindToCurrentLoop(base::Bind( |
| 661 &VideoCaptureDeviceClient::TextureWrapHelper::ReleaseCallback, | 661 &VideoCaptureDeviceClient::TextureWrapHelper::ReleaseCallback, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 // At this point, |capture_thread_context| is a cc::ContextProvider. Creation | 732 // At this point, |capture_thread_context| is a cc::ContextProvider. Creation |
| 733 // of our GLHelper should happen on Capture Thread. | 733 // of our GLHelper should happen on Capture Thread. |
| 734 gl_helper_.reset(new GLHelper(capture_thread_context->ContextGL(), | 734 gl_helper_.reset(new GLHelper(capture_thread_context->ContextGL(), |
| 735 capture_thread_context->ContextSupport())); | 735 capture_thread_context->ContextSupport())); |
| 736 DCHECK(gl_helper_); | 736 DCHECK(gl_helper_); |
| 737 } | 737 } |
| 738 | 738 |
| 739 void VideoCaptureDeviceClient::TextureWrapHelper::ReleaseCallback( | 739 void VideoCaptureDeviceClient::TextureWrapHelper::ReleaseCallback( |
| 740 const std::vector<GLuint>& image_ids, | 740 const std::vector<GLuint>& image_ids, |
| 741 const std::vector<GLuint>& texture_ids, | 741 const std::vector<GLuint>& texture_ids, |
| 742 uint32 sync_point) { | 742 const gpu::SyncToken& sync_token) { |
| 743 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 743 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 744 DCHECK_EQ(image_ids.size(), texture_ids.size()); | 744 DCHECK_EQ(image_ids.size(), texture_ids.size()); |
| 745 | 745 |
| 746 if (!gl_helper_) | 746 if (!gl_helper_) |
| 747 return; | 747 return; |
| 748 for (size_t i = 0; i < image_ids.size(); ++i) { | 748 for (size_t i = 0; i < image_ids.size(); ++i) { |
| 749 gl_helper_->DeleteTexture(texture_ids[i]); | 749 gl_helper_->DeleteTexture(texture_ids[i]); |
| 750 capture_thread_context_->ContextGL()->DestroyImageCHROMIUM(image_ids[i]); | 750 capture_thread_context_->ContextGL()->DestroyImageCHROMIUM(image_ids[i]); |
| 751 } | 751 } |
| 752 } | 752 } |
| 753 | 753 |
| 754 void VideoCaptureDeviceClient::TextureWrapHelper::LostContextCallback() { | 754 void VideoCaptureDeviceClient::TextureWrapHelper::LostContextCallback() { |
| 755 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 755 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 756 // Prevent incoming frames from being processed while OnError gets groked. | 756 // Prevent incoming frames from being processed while OnError gets groked. |
| 757 gl_helper_.reset(); | 757 gl_helper_.reset(); |
| 758 OnError("GLContext lost"); | 758 OnError("GLContext lost"); |
| 759 } | 759 } |
| 760 | 760 |
| 761 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( | 761 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( |
| 762 const std::string& message) { | 762 const std::string& message) { |
| 763 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 763 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 764 DLOG(ERROR) << message; | 764 DLOG(ERROR) << message; |
| 765 BrowserThread::PostTask( | 765 BrowserThread::PostTask( |
| 766 BrowserThread::IO, FROM_HERE, | 766 BrowserThread::IO, FROM_HERE, |
| 767 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); | 767 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); |
| 768 } | 768 } |
| 769 | 769 |
| 770 } // namespace content | 770 } // namespace content |
| OLD | NEW |