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

Side by Side Diff: services/video_capture/video_capture_device_proxy_impl.cc

Issue 2378943002: Let clients interact with VideoCaptureDeviceClient instead of VideoCaptureDevice (Closed)
Patch Set: Remove method AsClientBuffer() 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/video_capture/video_capture_device_proxy_impl.h"
6
5 #include "base/logging.h" 7 #include "base/logging.h"
6 #include "services/video_capture/device_client_mojo_to_media_adapter.h" 8 #include "media/capture/video/video_capture_buffer_pool_impl.h"
7 #include "services/video_capture/video_capture_device_proxy_impl.h" 9 #include "media/capture/video/video_capture_jpeg_decoder.h"
10 #include "services/video_capture/buffer_tracker_factory_impl.h"
11 #include "services/video_capture/receiver_mojo_to_media_adapter.h"
8 12
9 namespace video_capture { 13 namespace video_capture {
10 14
11 VideoCaptureDeviceProxyImpl::VideoCaptureDeviceProxyImpl( 15 VideoCaptureDeviceProxyImpl::VideoCaptureDeviceProxyImpl(
12 std::unique_ptr<media::VideoCaptureDevice> device) 16 std::unique_ptr<media::VideoCaptureDevice> device,
13 : device_(std::move(device)) {} 17 const media::VideoCaptureJpegDecoderFactoryCB&
18 jpeg_decoder_factory_callback)
19 : device_(std::move(device)),
20 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback),
21 device_running_(false) {}
14 22
15 VideoCaptureDeviceProxyImpl::~VideoCaptureDeviceProxyImpl() { 23 VideoCaptureDeviceProxyImpl::~VideoCaptureDeviceProxyImpl() {
16 if (device_running_) 24 if (device_running_)
17 device_->StopAndDeAllocate(); 25 device_->StopAndDeAllocate();
18 } 26 }
19 27
20 void VideoCaptureDeviceProxyImpl::Start( 28 void VideoCaptureDeviceProxyImpl::Start(
21 const media::VideoCaptureFormat& requested_format, 29 const media::VideoCaptureFormat& requested_format,
22 media::ResolutionChangePolicy resolution_change_policy, 30 media::ResolutionChangePolicy resolution_change_policy,
23 media::PowerLineFrequency power_line_frequency, 31 media::PowerLineFrequency power_line_frequency,
24 mojom::VideoCaptureDeviceClientPtr client) { 32 mojom::VideoFrameReceiverPtr receiver) {
25 media::VideoCaptureParams params; 33 media::VideoCaptureParams params;
26 params.requested_format = requested_format; 34 params.requested_format = requested_format;
27 params.resolution_change_policy = resolution_change_policy; 35 params.resolution_change_policy = resolution_change_policy;
28 params.power_line_frequency = power_line_frequency; 36 params.power_line_frequency = power_line_frequency;
29 client.set_connection_error_handler( 37 receiver.set_connection_error_handler(
30 base::Bind(&VideoCaptureDeviceProxyImpl::OnClientConnectionErrorOrClose, 38 base::Bind(&VideoCaptureDeviceProxyImpl::OnClientConnectionErrorOrClose,
31 base::Unretained(this))); 39 base::Unretained(this)));
32 auto media_client = 40
33 base::MakeUnique<DeviceClientMojoToMediaAdapter>(std::move(client)); 41 auto media_receiver =
34 device_->AllocateAndStart(params, std::move(media_client)); 42 base::MakeUnique<ReceiverMojoToMediaAdapter>(std::move(receiver));
43
44 // Create a dedicated buffer pool for the device usage session.
45 const int kMaxBufferCount = 2;
46 auto buffer_tracker_factory = base::MakeUnique<BufferTrackerFactoryImpl>();
47 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool(
48 new media::VideoCaptureBufferPoolImpl(std::move(buffer_tracker_factory),
49 kMaxBufferCount));
50
51 auto device_client = base::MakeUnique<media::VideoCaptureDeviceClient>(
52 std::move(media_receiver), buffer_pool, jpeg_decoder_factory_callback_);
53
54 device_->AllocateAndStart(params, std::move(device_client));
35 device_running_ = true; 55 device_running_ = true;
36 } 56 }
37 57
38 void VideoCaptureDeviceProxyImpl::Stop() { 58 void VideoCaptureDeviceProxyImpl::Stop() {
39 device_->StopAndDeAllocate(); 59 device_->StopAndDeAllocate();
40 device_running_ = false; 60 device_running_ = false;
41 } 61 }
42 62
43 void VideoCaptureDeviceProxyImpl::OnClientConnectionErrorOrClose() { 63 void VideoCaptureDeviceProxyImpl::OnClientConnectionErrorOrClose() {
44 device_->StopAndDeAllocate(); 64 if (device_running_) {
65 device_->StopAndDeAllocate();
66 device_running_ = false;
67 }
45 } 68 }
46 69
47 } // namespace video_capture 70 } // namespace video_capture
OLDNEW
« no previous file with comments | « services/video_capture/video_capture_device_proxy_impl.h ('k') | services/video_capture/video_capture_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698