summaryrefslogtreecommitdiff
path: root/chromium/media/capture/video/file_video_capture_device_factory.cc
blob: 29fd7c77a0edd3475265a1883e7432756a8ac2a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 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 "media/capture/video/file_video_capture_device_factory.h"

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "media/base/media_switches.h"
#include "media/capture/video/file_video_capture_device.h"

namespace media {

const char kFileVideoCaptureDeviceName[] =
    "/dev/placeholder-for-file-backed-fake-capture-device";

// Inspects the command line and retrieves the file path parameter.
base::FilePath GetFilePathFromCommandLine() {
  base::FilePath command_line_file_path =
      base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
          switches::kUseFileForFakeVideoCapture);
  CHECK(!command_line_file_path.empty());
  return command_line_file_path;
}

std::unique_ptr<VideoCaptureDevice> FileVideoCaptureDeviceFactory::CreateDevice(
    const VideoCaptureDeviceDescriptor& device_descriptor) {
  DCHECK(thread_checker_.CalledOnValidThread());
  base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
                                                base::BlockingType::MAY_BLOCK);
#if defined(OS_WIN)
  return std::unique_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice(
      base::FilePath(base::SysUTF8ToWide(device_descriptor.display_name()))));
#else
  return std::unique_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice(
      base::FilePath(device_descriptor.display_name())));
#endif
}

void FileVideoCaptureDeviceFactory::GetDevicesInfo(
    GetDevicesInfoCallback callback) {
  DCHECK(thread_checker_.CalledOnValidThread());
  base::ThreadRestrictions::SetIOAllowed(true);

  std::vector<VideoCaptureDeviceInfo> devices_info;

  auto api =
#if defined(OS_WIN)
      VideoCaptureApi::WIN_DIRECT_SHOW;
#elif defined(OS_MAC)
      VideoCaptureApi::MACOSX_AVFOUNDATION;
#elif defined(OS_LINUX) || defined(OS_CHROMEOS)
      VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE;
#else
      VideoCaptureApi::UNKNOWN;
#endif

  devices_info.emplace_back(
      VideoCaptureDeviceDescriptor(GetFilePathFromCommandLine().AsUTF8Unsafe(),
                                   kFileVideoCaptureDeviceName, api));

  VideoCaptureFormat capture_format;
  if (!FileVideoCaptureDevice::GetVideoCaptureFormat(
          GetFilePathFromCommandLine(), &capture_format)) {
    std::move(callback).Run({});
    return;
  }
  devices_info.back().supported_formats.push_back(capture_format);

  std::move(callback).Run(std::move(devices_info));
}

}  // namespace media