Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.cc

Issue 2361173002: Move classses VideoCaptureDeviceClient and VideoCaptureBufferPool to media/capture/video (Closed)
Patch Set: mcasas@ comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_controller.h" 5 #include "content/browser/renderer_host/media/video_capture_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/metrics/sparse_histogram.h" 17 #include "base/metrics/sparse_histogram.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "components/display_compositor/gl_helper.h" 19 #include "components/display_compositor/gl_helper.h"
20 #include "content/browser/renderer_host/media/media_stream_manager.h" 20 #include "content/browser/renderer_host/media/media_stream_manager.h"
21 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" 21 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto ry_impl.h"
22 #include "content/browser/renderer_host/media/video_capture_device_client.h"
23 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" 22 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h"
24 #include "content/browser/renderer_host/media/video_capture_manager.h" 23 #include "content/browser/renderer_host/media/video_capture_manager.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
27 #include "media/base/video_frame.h" 26 #include "media/base/video_frame.h"
27 #include "media/capture/video/video_capture_buffer_pool_impl.h"
28 #include "media/capture/video/video_capture_device_client.h"
28 29
29 #if !defined(OS_ANDROID) 30 #if !defined(OS_ANDROID)
30 #include "content/browser/compositor/image_transport_factory.h" 31 #include "content/browser/compositor/image_transport_factory.h"
31 #endif 32 #endif
32 33
33 using media::VideoCaptureFormat; 34 using media::VideoCaptureFormat;
34 using media::VideoFrame; 35 using media::VideoFrame;
35 using media::VideoFrameMetadata; 36 using media::VideoFrameMetadata;
36 37
37 namespace content { 38 namespace content {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // UpdateReleaseSyncToken() creates a new sync_token using |gl_helper|, so 73 // UpdateReleaseSyncToken() creates a new sync_token using |gl_helper|, so
73 // wait the given |sync_token| using |gl_helper|. 74 // wait the given |sync_token| using |gl_helper|.
74 if (gl_helper) { 75 if (gl_helper) {
75 gl_helper->WaitSyncToken(sync_token); 76 gl_helper->WaitSyncToken(sync_token);
76 SyncTokenClientImpl client(gl_helper); 77 SyncTokenClientImpl client(gl_helper);
77 video_frame->UpdateReleaseSyncToken(&client); 78 video_frame->UpdateReleaseSyncToken(&client);
78 } 79 }
79 #endif 80 #endif
80 } 81 }
81 82
82 std::unique_ptr<VideoCaptureJpegDecoder> CreateGpuJpegDecoder( 83 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder(
83 const VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { 84 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) {
84 return base::MakeUnique<VideoCaptureGpuJpegDecoder>(decode_done_cb); 85 return base::MakeUnique<VideoCaptureGpuJpegDecoder>(decode_done_cb);
85 } 86 }
86 87
87 // Decorator for VideoFrameReceiver that forwards all incoming calls 88 // Decorator for media::VideoFrameReceiver that forwards all incoming calls
88 // to the Browser IO thread. 89 // to the Browser IO thread.
89 class VideoFrameReceiverOnIOThread : public VideoFrameReceiver { 90 class VideoFrameReceiverOnIOThread : public media::VideoFrameReceiver {
90 public: 91 public:
91 explicit VideoFrameReceiverOnIOThread( 92 explicit VideoFrameReceiverOnIOThread(
92 const base::WeakPtr<VideoFrameReceiver>& receiver) 93 const base::WeakPtr<VideoFrameReceiver>& receiver)
93 : receiver_(receiver) {} 94 : receiver_(receiver) {}
94 95
95 void OnIncomingCapturedVideoFrame( 96 void OnIncomingCapturedVideoFrame(
96 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, 97 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
97 const scoped_refptr<media::VideoFrame>& frame) override { 98 const scoped_refptr<media::VideoFrame>& frame) override {
98 BrowserThread::PostTask( 99 BrowserThread::PostTask(
99 BrowserThread::IO, FROM_HERE, 100 BrowserThread::IO, FROM_HERE,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // implicitly), we could avoid tracking this state here in the Controller, and 170 // implicitly), we could avoid tracking this state here in the Controller, and
170 // simplify the code in both places. 171 // simplify the code in both places.
171 bool session_closed; 172 bool session_closed;
172 173
173 // Indicates whether the client is paused, if true, VideoCaptureController 174 // Indicates whether the client is paused, if true, VideoCaptureController
174 // stops updating its buffer. 175 // stops updating its buffer.
175 bool paused; 176 bool paused;
176 }; 177 };
177 178
178 VideoCaptureController::VideoCaptureController(int max_buffers) 179 VideoCaptureController::VideoCaptureController(int max_buffers)
179 : buffer_pool_(new VideoCaptureBufferPoolImpl(max_buffers)), 180 : buffer_pool_(new media::VideoCaptureBufferPoolImpl(
181 base::MakeUnique<VideoCaptureBufferTrackerFactoryImpl>(),
182 max_buffers)),
180 state_(VIDEO_CAPTURE_STATE_STARTED), 183 state_(VIDEO_CAPTURE_STATE_STARTED),
181 has_received_frames_(false), 184 has_received_frames_(false),
182 weak_ptr_factory_(this) { 185 weak_ptr_factory_(this) {
183 DCHECK_CURRENTLY_ON(BrowserThread::IO); 186 DCHECK_CURRENTLY_ON(BrowserThread::IO);
184 } 187 }
185 188
186 base::WeakPtr<VideoCaptureController> 189 base::WeakPtr<VideoCaptureController>
187 VideoCaptureController::GetWeakPtrForIOThread() { 190 VideoCaptureController::GetWeakPtrForIOThread() {
188 return weak_ptr_factory_.GetWeakPtr(); 191 return weak_ptr_factory_.GetWeakPtr();
189 } 192 }
190 193
191 std::unique_ptr<media::VideoCaptureDevice::Client> 194 std::unique_ptr<media::VideoCaptureDevice::Client>
192 VideoCaptureController::NewDeviceClient() { 195 VideoCaptureController::NewDeviceClient() {
193 DCHECK_CURRENTLY_ON(BrowserThread::IO); 196 DCHECK_CURRENTLY_ON(BrowserThread::IO);
194 return base::MakeUnique<VideoCaptureDeviceClient>( 197 return base::MakeUnique<media::VideoCaptureDeviceClient>(
195 base::MakeUnique<VideoFrameReceiverOnIOThread>( 198 base::MakeUnique<VideoFrameReceiverOnIOThread>(
196 this->GetWeakPtrForIOThread()), 199 this->GetWeakPtrForIOThread()),
197 buffer_pool_, 200 buffer_pool_,
198 base::Bind(&CreateGpuJpegDecoder, 201 base::Bind(&CreateGpuJpegDecoder,
199 base::Bind(&VideoFrameReceiver::OnIncomingCapturedVideoFrame, 202 base::Bind(&VideoFrameReceiver::OnIncomingCapturedVideoFrame,
200 this->GetWeakPtrForIOThread()))); 203 this->GetWeakPtrForIOThread())));
201 } 204 }
202 205
203 void VideoCaptureController::AddClient( 206 void VideoCaptureController::AddClient(
204 VideoCaptureControllerID id, 207 VideoCaptureControllerID id,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 404 }
402 405
403 VideoCaptureController::~VideoCaptureController() { 406 VideoCaptureController::~VideoCaptureController() {
404 } 407 }
405 408
406 void VideoCaptureController::OnIncomingCapturedVideoFrame( 409 void VideoCaptureController::OnIncomingCapturedVideoFrame(
407 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, 410 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
408 const scoped_refptr<VideoFrame>& frame) { 411 const scoped_refptr<VideoFrame>& frame) {
409 DCHECK_CURRENTLY_ON(BrowserThread::IO); 412 DCHECK_CURRENTLY_ON(BrowserThread::IO);
410 const int buffer_id = buffer->id(); 413 const int buffer_id = buffer->id();
411 DCHECK_NE(buffer_id, VideoCaptureBufferPool::kInvalidId); 414 DCHECK_NE(buffer_id, media::VideoCaptureBufferPool::kInvalidId);
412 415
413 int count = 0; 416 int count = 0;
414 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 417 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
415 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { 418 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) {
416 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, 419 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE,
417 video_capture_format_.frame_rate); 420 video_capture_format_.frame_rate);
418 } 421 }
419 std::unique_ptr<base::DictionaryValue> metadata( 422 std::unique_ptr<base::DictionaryValue> metadata(
420 new base::DictionaryValue()); 423 new base::DictionaryValue());
421 frame->metadata()->MergeInternalValuesInto(metadata.get()); 424 frame->metadata()->MergeInternalValuesInto(metadata.get());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 int session_id, 558 int session_id,
556 const ControllerClients& clients) { 559 const ControllerClients& clients) {
557 for (const auto& client : clients) { 560 for (const auto& client : clients) {
558 if (client->session_id == session_id) 561 if (client->session_id == session_id)
559 return client.get(); 562 return client.get();
560 } 563 }
561 return nullptr; 564 return nullptr;
562 } 565 }
563 566
564 } // namespace content 567 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698