summaryrefslogtreecommitdiff
path: root/devices/EmulatedCamera/hwl/EmulatedCameraProviderHWLImpl.h
blob: f9b0e6690a8d7c71ed1f34c9ee991da1af8d44a1 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EMULATOR_CAMERA_HAL_HWL_CAMERA_PROVIDER_HWL_H
#define EMULATOR_CAMERA_HAL_HWL_CAMERA_PROVIDER_HWL_H

#include <camera_provider_hwl.h>
#include <hal_types.h>
#include <json/json.h>
#include <json/reader.h>
#include <future>

namespace android {

using google_camera_hal::CameraBufferAllocatorHwl;
using google_camera_hal::CameraDeviceHwl;
using google_camera_hal::CameraDeviceStatus;
using google_camera_hal::CameraIdAndStreamConfiguration;
using google_camera_hal::CameraProviderHwl;
using google_camera_hal::HalCameraMetadata;
using google_camera_hal::HwlCameraProviderCallback;
using google_camera_hal::HwlPhysicalCameraDeviceStatusChangeFunc;
using google_camera_hal::HwlTorchModeStatusChangeFunc;
using google_camera_hal::VendorTagSection;

class EmulatedCameraProviderHwlImpl : public CameraProviderHwl {
 public:
  // Return a unique pointer to EmulatedCameraProviderHwlImpl. Calling Create()
  // again before the previous one is destroyed will fail.
  static std::unique_ptr<EmulatedCameraProviderHwlImpl> Create();

  virtual ~EmulatedCameraProviderHwlImpl() {
    WaitForStatusCallbackFuture();
  }

  // Override functions in CameraProviderHwl.
  status_t SetCallback(const HwlCameraProviderCallback& callback) override;
  status_t TriggerDeferredCallbacks() override;

  status_t GetVendorTags(
      std::vector<VendorTagSection>* vendor_tag_sections) override;

  status_t GetVisibleCameraIds(std::vector<std::uint32_t>* camera_ids) override;

  bool IsSetTorchModeSupported() override {
    return true;
  }

  status_t GetConcurrentStreamingCameraIds(
      std::vector<std::unordered_set<uint32_t>>*) override;

  status_t IsConcurrentStreamCombinationSupported(
      const std::vector<CameraIdAndStreamConfiguration>&, bool*) override;

  status_t CreateCameraDeviceHwl(
      uint32_t camera_id,
      std::unique_ptr<CameraDeviceHwl>* camera_device_hwl) override;

  status_t CreateBufferAllocatorHwl(std::unique_ptr<CameraBufferAllocatorHwl>*
                                        camera_buffer_allocator_hwl) override;
  // End of override functions in CameraProviderHwl.

 private:
  status_t Initialize();
  uint32_t ParseCharacteristics(const Json::Value& root, ssize_t id);
  status_t GetTagFromName(const char* name, uint32_t* tag);
  status_t WaitForQemuSfFakeCameraPropertyAvailable();
  bool Supports720pYUVAndPrivate(uint32_t camera_id);

  static const char* kConfigurationFileLocation[];

  std::vector<std::unique_ptr<HalCameraMetadata>> static_metadata_;
  // Logical to physical camera Id mapping. Empty value vector in case
  // of regular non-logical device.
  std::unordered_map<uint32_t, std::vector<std::pair<CameraDeviceStatus, uint32_t>>> camera_id_map_;
  HwlTorchModeStatusChangeFunc torch_cb_;
  HwlPhysicalCameraDeviceStatusChangeFunc physical_camera_status_cb_;

  std::mutex status_callback_future_lock_;
  std::future<void> status_callback_future_;
  void WaitForStatusCallbackFuture();
  void NotifyPhysicalCameraUnavailable();
};

extern "C" CameraProviderHwl* CreateCameraProviderHwl() {
  auto provider = EmulatedCameraProviderHwlImpl::Create();
  return provider.release();
}

}  // namespace android

#endif  // EMULATOR_CAMERA_HAL_HWL_CAMERA_PROVIDER_HWL_H