summaryrefslogtreecommitdiff
path: root/chromium/media/capture/video/android/video_capture_device_factory_android.h
blob: 3eef79c97acf2e65b47d3da7b3efd388191444cb (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
// 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.

#ifndef MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_FACTORY_ANDROID_H_
#define MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_FACTORY_ANDROID_H_

#include "media/capture/video/video_capture_device_factory.h"

#include <jni.h>

#include "base/android/scoped_java_ref.h"
#include "base/containers/flat_map.h"
#include "media/capture/video/video_capture_device.h"

namespace media {

// VideoCaptureDeviceFactory on Android. This class implements the static
// VideoCapture methods and the factory of VideoCaptureAndroid.
class CAPTURE_EXPORT VideoCaptureDeviceFactoryAndroid
    : public VideoCaptureDeviceFactory {
 public:
  static base::android::ScopedJavaLocalRef<jobject> createVideoCaptureAndroid(
      int id,
      jlong nativeVideoCaptureDeviceAndroid);

  VideoCaptureDeviceFactoryAndroid();

  VideoCaptureDeviceFactoryAndroid(const VideoCaptureDeviceFactoryAndroid&) =
      delete;
  VideoCaptureDeviceFactoryAndroid& operator=(
      const VideoCaptureDeviceFactoryAndroid&) = delete;

  ~VideoCaptureDeviceFactoryAndroid() override;

  VideoCaptureErrorOrDevice CreateDevice(
      const VideoCaptureDeviceDescriptor& device_descriptor) override;
  void GetDevicesInfo(GetDevicesInfoCallback callback) override;

  static bool IsLegacyOrDeprecatedDevice(const std::string& device_id);

  // Configures all subsequent CreateDevice()s in test mode.
  void ConfigureForTesting() { test_mode_ = true; }

 private:
  VideoCaptureFormats GetSupportedFormats(int device_index,
                                          const std::string& display_name);

  // Switch to indicate that all created Java capturers will be in test mode.
  bool test_mode_ = false;

  // VideoCaptureFormats and zooms are cached, so GetSupportedFormats() and
  // Java_VideoCaptureFactory_isZoomSupported() respectively don't need to be
  // called for every device every time GetDevicesInfo() is called. It also
  // allows to workaround bugs on some devices that don't handle the case when
  // an actively used camera is opened again (see https://crbug.com/1138608).
  base::flat_map<std::string, VideoCaptureFormats> supported_formats_cache_;
  base::flat_map<std::string, bool> zooms_cache_;
};

}  // namespace media

#endif  // MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_FACTORY_ANDROID_H_