summaryrefslogtreecommitdiff
path: root/common/hal/aidl_service/aidl_camera_device.h
blob: 86b72638265d9661dbf74f5fe396c266b00535a1 (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
106
/*
 * Copyright (C) 2022 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 HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_

#include <aidl/android/hardware/camera/device/BnCameraDevice.h>
#include <aidl/android/hardware/camera/device/ICameraDeviceCallback.h>

#include "aidl_profiler.h"
#include "camera_device.h"

namespace android {
namespace hardware {
namespace camera {
namespace device {
namespace implementation {

using aidl::android::hardware::camera::common::CameraResourceCost;
using aidl::android::hardware::camera::device::BnCameraDevice;
using aidl::android::hardware::camera::device::CameraMetadata;
using aidl::android::hardware::camera::device::ICameraDevice;
using aidl::android::hardware::camera::device::ICameraDeviceCallback;
using aidl::android::hardware::camera::device::ICameraDeviceSession;
using aidl::android::hardware::camera::device::ICameraInjectionSession;
using aidl::android::hardware::camera::device::StreamConfiguration;
using ::android::hardware::camera::implementation::AidlProfiler;
using ndk::ScopedAStatus;
using ndk::ScopedFileDescriptor;

using ::android::google_camera_hal::CameraDevice;

// AidlCameraDevice implements the AIDL camera device interface, ICameraDevice,
// using Google Camera HAL to provide information about the associated camera
// device.
class AidlCameraDevice : public BnCameraDevice {
 public:
  static const std::string kDeviceVersion;

  // Create a AidlCameraDevice.
  // google_camera_device is a google camera device that AidlCameraDevice
  // is going to manage. Creating a AidlCameraDevice will fail if
  // google_camera_device is nullptr.
  static std::shared_ptr<AidlCameraDevice> Create(
      std::unique_ptr<CameraDevice> google_camera_device);
  virtual ~AidlCameraDevice() = default;

  binder_status_t dump(int fd, const char**, uint32_t) override;

  // Override functions in ICameraDevice
  ScopedAStatus getCameraCharacteristics(
      CameraMetadata* characteristics) override;

  ScopedAStatus getPhysicalCameraCharacteristics(
      const std::string& in_physicalCameraId,
      CameraMetadata* characteristics) override;

  ScopedAStatus getResourceCost(CameraResourceCost* resource_cost) override;

  ScopedAStatus isStreamCombinationSupported(
      const StreamConfiguration& in_streams, bool* supported) override;

  ScopedAStatus open(const std::shared_ptr<ICameraDeviceCallback>& in_callback,
                     std::shared_ptr<ICameraDeviceSession>* session) override;

  ScopedAStatus openInjectionSession(
      const std::shared_ptr<ICameraDeviceCallback>& in_callback,
      std::shared_ptr<ICameraInjectionSession>* session) override;

  ScopedAStatus setTorchMode(bool on) override;

  ScopedAStatus turnOnTorchWithStrengthLevel(int32_t torchStrength) override;

  ScopedAStatus getTorchStrengthLevel(int32_t* strength_level) override;

  // End of override functions in ICameraDevice
  AidlCameraDevice() = default;

 private:
  status_t Initialize(std::unique_ptr<CameraDevice> google_camera_device);

  std::unique_ptr<CameraDevice> google_camera_device_;
  uint32_t camera_id_ = 0;
  std::shared_ptr<AidlProfiler> aidl_profiler_;
};

}  // namespace implementation
}  // namespace device
}  // namespace camera
}  // namespace hardware
}  // namespace android

#endif  // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_