Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / media / video / capture / file_video_capture_device_factory.cc
blob4749c2f8a976b3d9bd9db7fdad57f8466a2e4863
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/video/capture/file_video_capture_device_factory.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "media/base/media_switches.h"
11 #include "media/video/capture/file_video_capture_device.h"
13 namespace media {
15 const char kFileVideoCaptureDeviceName[] =
16 "/dev/placeholder-for-file-backed-fake-capture-device";
18 // Inspects the command line and retrieves the file path parameter.
19 base::FilePath GetFilePathFromCommandLine() {
20 base::FilePath command_line_file_path =
21 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
22 switches::kUseFileForFakeVideoCapture);
23 CHECK(!command_line_file_path.empty());
24 return command_line_file_path;
27 scoped_ptr<VideoCaptureDevice> FileVideoCaptureDeviceFactory::Create(
28 const VideoCaptureDevice::Name& device_name) {
29 DCHECK(thread_checker_.CalledOnValidThread());
30 #if defined(OS_WIN)
31 return scoped_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice(
32 base::FilePath(base::SysUTF8ToWide(device_name.name()))));
33 #else
34 return scoped_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice(
35 base::FilePath(device_name.name())));
36 #endif
39 void FileVideoCaptureDeviceFactory::GetDeviceNames(
40 VideoCaptureDevice::Names* const device_names) {
41 DCHECK(thread_checker_.CalledOnValidThread());
42 DCHECK(device_names->empty());
43 base::FilePath command_line_file_path = GetFilePathFromCommandLine();
44 #if defined(OS_WIN)
45 device_names->push_back(VideoCaptureDevice::Name(
46 base::SysWideToUTF8(command_line_file_path.value()),
47 kFileVideoCaptureDeviceName,
48 VideoCaptureDevice::Name::DIRECT_SHOW));
49 #elif defined(OS_MACOSX)
50 device_names->push_back(VideoCaptureDevice::Name(
51 command_line_file_path.value(),
52 kFileVideoCaptureDeviceName,
53 VideoCaptureDevice::Name::AVFOUNDATION));
54 #else
55 device_names->push_back(VideoCaptureDevice::Name(
56 command_line_file_path.value(),
57 kFileVideoCaptureDeviceName));
58 #endif
61 void FileVideoCaptureDeviceFactory::GetDeviceSupportedFormats(
62 const VideoCaptureDevice::Name& device,
63 VideoCaptureFormats* supported_formats) {
64 DCHECK(thread_checker_.CalledOnValidThread());
65 base::File file =
66 FileVideoCaptureDevice::OpenFileForRead(GetFilePathFromCommandLine());
67 VideoCaptureFormat capture_format;
68 FileVideoCaptureDevice::ParseFileAndExtractVideoFormat(&file,
69 &capture_format);
70 supported_formats->push_back(capture_format);
73 } // namespace media