forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mojo Video Capture] Stop service when last client disconnects.
This CL is part of the Mojo Video Capture work. For the bigger picture, see [1] CL23. Purpose of this CL: Stop service when last client disconnects. Once we host it in a separate process, this will allow the service to automatically restart when a new request comes in. Changes in this CL: * Split class video_capture::ServiceImpl into two classes ServiceManagerServiceImpl and VideoCaptureServiceImpl. * In class ServiceManagerServiceImpl, following the example of ImageDecoder [2], use a ServiceContextRefFactory to manage service lifetime and implement a delayed service shutdown when there are no clients. * Add tests ServiceQuitsWhenNoClientConnected and ServiceQuitsWhenClientDisconnectsWhileUsingDevice * In service.mojom, add a method for setting the service shutdown delay. For the automated tests, set the delay to zero. * In DeviceFactoryMediaToMojoAdapter, make sure that |capture_system_->GetDeviceInfosAsync()| is called before |capture_system_->CreateDevice()|. This is required by the implementation VideoCaptureSystemImpl in order to fill the cache |devices_info_cache_|. * In DeviceMediaToMojoAdapter, unsubscibe from |receiver.set_connection_error_handler()| in order to avoid use after free on service shutdown. * In ReceiverMojoToMediaAdapter, introduce class ReceiverOnTaskRunner in order to ensure that mojom.Receiver methods are posted to the correct thread. * In VideoCaptureDeviceClient, allow |external_jpeg_decoder_| to be nullptr, since in the context of the video_capture service, this will (for now) be the case. BUG=584797 TEST= service_unittests --gtest_filter="*Video*" content_unittests --gtest_filter="*Video*" content_browsertests --gtest_filter="VideoCaptureBrowserTest.*" [1] https://docs.google.com/a/chromium.org/document/d/1Qw7rw1AJy0QHXjha36jZNiEuxsxWslJ_X-zpOhijvI8/edit?usp=sharing [2] https://cs.chromium.org/chromium/src/services/data_decoder/data_decoder_service.cc?dr=CSs Review-Url: https://codereview.chromium.org/2824883005 Cr-Commit-Position: refs/heads/master@{#468358}
- Loading branch information
chfremer
authored and
Commit bot
committed
May 1, 2017
1 parent
ced3697
commit 9fe5b74
Showing
29 changed files
with
634 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "services/video_capture/device_factory_provider_impl.h" | ||
|
||
#include "base/memory/ptr_util.h" | ||
#include "media/capture/video/fake_video_capture_device_factory.h" | ||
#include "media/capture/video/video_capture_buffer_pool.h" | ||
#include "media/capture/video/video_capture_buffer_tracker.h" | ||
#include "media/capture/video/video_capture_jpeg_decoder.h" | ||
#include "media/capture/video/video_capture_system_impl.h" | ||
#include "services/service_manager/public/cpp/service_info.h" | ||
#include "services/video_capture/device_factory_media_to_mojo_adapter.h" | ||
|
||
namespace { | ||
|
||
// TODO(chfremer): Replace with an actual decoder factory. | ||
// https://crbug.com/584797 | ||
std::unique_ptr<media::VideoCaptureJpegDecoder> CreateJpegDecoder() { | ||
return nullptr; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
namespace video_capture { | ||
|
||
DeviceFactoryProviderImpl::DeviceFactoryProviderImpl( | ||
std::unique_ptr<service_manager::ServiceContextRef> service_ref, | ||
base::Callback<void(float)> set_shutdown_delay_cb) | ||
: service_ref_(std::move(service_ref)), | ||
set_shutdown_delay_cb_(std::move(set_shutdown_delay_cb)) {} | ||
|
||
DeviceFactoryProviderImpl::~DeviceFactoryProviderImpl() {} | ||
|
||
void DeviceFactoryProviderImpl::ConnectToDeviceFactory( | ||
mojom::DeviceFactoryRequest request) { | ||
LazyInitializeDeviceFactory(); | ||
factory_bindings_.AddBinding(device_factory_.get(), std::move(request)); | ||
} | ||
|
||
void DeviceFactoryProviderImpl::ConnectToFakeDeviceFactory( | ||
mojom::DeviceFactoryRequest request) { | ||
LazyInitializeFakeDeviceFactory(); | ||
fake_factory_bindings_.AddBinding(fake_device_factory_.get(), | ||
std::move(request)); | ||
} | ||
|
||
void DeviceFactoryProviderImpl::SetShutdownDelayInSeconds(float seconds) { | ||
set_shutdown_delay_cb_.Run(seconds); | ||
} | ||
|
||
void DeviceFactoryProviderImpl::LazyInitializeDeviceFactory() { | ||
if (device_factory_) | ||
return; | ||
|
||
// Create the platform-specific device factory. | ||
// The task runner passed to CreateFactory is used for things that need to | ||
// happen on a "UI thread equivalent", e.g. obtaining screen rotation on | ||
// Chrome OS. | ||
std::unique_ptr<media::VideoCaptureDeviceFactory> media_device_factory = | ||
media::VideoCaptureDeviceFactory::CreateFactory( | ||
base::ThreadTaskRunnerHandle::Get()); | ||
auto video_capture_system = base::MakeUnique<media::VideoCaptureSystemImpl>( | ||
std::move(media_device_factory)); | ||
|
||
device_factory_ = base::MakeUnique<DeviceFactoryMediaToMojoAdapter>( | ||
service_ref_->Clone(), std::move(video_capture_system), | ||
base::Bind(CreateJpegDecoder)); | ||
} | ||
|
||
void DeviceFactoryProviderImpl::LazyInitializeFakeDeviceFactory() { | ||
if (fake_device_factory_) | ||
return; | ||
|
||
auto factory = base::MakeUnique<media::FakeVideoCaptureDeviceFactory>(); | ||
auto video_capture_system = | ||
base::MakeUnique<media::VideoCaptureSystemImpl>(std::move(factory)); | ||
|
||
fake_device_factory_ = base::MakeUnique<DeviceFactoryMediaToMojoAdapter>( | ||
service_ref_->Clone(), std::move(video_capture_system), | ||
base::Bind(&CreateJpegDecoder)); | ||
} | ||
|
||
} // namespace video_capture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_PROVIDER_H_ | ||
#define SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_PROVIDER_H_ | ||
|
||
#include <memory> | ||
|
||
#include "mojo/public/cpp/bindings/binding_set.h" | ||
#include "services/service_manager/public/cpp/interface_factory.h" | ||
#include "services/service_manager/public/cpp/service.h" | ||
#include "services/service_manager/public/cpp/service_context_ref.h" | ||
#include "services/video_capture/public/interfaces/device_factory_provider.mojom.h" | ||
|
||
namespace video_capture { | ||
|
||
class DeviceFactoryMediaToMojoAdapter; | ||
|
||
class DeviceFactoryProviderImpl : public mojom::DeviceFactoryProvider { | ||
public: | ||
DeviceFactoryProviderImpl( | ||
std::unique_ptr<service_manager::ServiceContextRef> service_ref, | ||
base::Callback<void(float)> set_shutdown_delay_cb); | ||
~DeviceFactoryProviderImpl() override; | ||
|
||
// mojom::DeviceFactoryProvider implementation. | ||
void ConnectToDeviceFactory(mojom::DeviceFactoryRequest request) override; | ||
void ConnectToFakeDeviceFactory(mojom::DeviceFactoryRequest request) override; | ||
void SetShutdownDelayInSeconds(float seconds) override; | ||
|
||
private: | ||
void LazyInitializeDeviceFactory(); | ||
void LazyInitializeFakeDeviceFactory(); | ||
|
||
mojo::BindingSet<mojom::DeviceFactory> factory_bindings_; | ||
mojo::BindingSet<mojom::DeviceFactory> fake_factory_bindings_; | ||
std::unique_ptr<DeviceFactoryMediaToMojoAdapter> device_factory_; | ||
std::unique_ptr<DeviceFactoryMediaToMojoAdapter> fake_device_factory_; | ||
|
||
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_; | ||
base::Callback<void(float)> set_shutdown_delay_cb_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DeviceFactoryProviderImpl); | ||
}; | ||
|
||
} // namespace video_capture | ||
|
||
#endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_PROVIDER_H_ |
Oops, something went wrong.