d7e4e242eda34084832658792bb061e475d341e4
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2016 Samsung Electronics Inc. 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.
4
5 #ifndef MEDIA_CAPTURE_VIDEO_TIZEN_CAMERA_DEVICE_TIZEN_H_
6 #define MEDIA_CAPTURE_VIDEO_TIZEN_CAMERA_DEVICE_TIZEN_H_
7
8 #include <camera.h>
9 #include <map>
10 #include <vector>
11
12 #include "base/memory/singleton.h"
13 #include "media/base/video_types.h"
14 #include "media/mojo/interfaces/image_capture.mojom.h"
15 #include "ui/gfx/gpu_memory_buffer.h"
16
17 namespace media {
18
19 struct VideoCaptureFormat;
20 typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
21
22 struct CameraCapability {
23   typedef gfx::Size Resolution;
24   typedef int Fps;
25
26   CameraCapability() : fps(0) {}
27
28   CameraCapability(gfx::Size frame, int rate) : resolution(frame), fps(rate) {}
29
30   Resolution resolution;
31   Fps fps;
32 };
33
34 struct Range {
35   int min = -1;
36   int max = -1;
37 };
38
39 class PhotoCapabilities {
40  public:
41   bool IsRedEyeReductionOn();
42   mojom::MeteringMode GetWhiteBalanceMode() {
43     return mojom::MeteringMode::NONE;
44   }
45   mojom::MeteringMode GetExposureMode() { return mojom::MeteringMode::NONE; }
46   mojom::MeteringMode GetFocusMode() { return mojom::MeteringMode::NONE; }
47   mojom::RangePtr GetColorTemperature() { return mojom::Range::New(); }
48   mojom::RangePtr GetExposureCompensation();
49   mojom::RangePtr GetIso();
50   mojom::RangePtr GetBrightness();
51   mojom::RangePtr GetContrast();
52   mojom::RangePtr GetSaturation() { return mojom::Range::New(); }
53   mojom::RangePtr GetSharpness() { return mojom::Range::New(); }
54   mojom::RangePtr GetImageHeight();
55   mojom::RangePtr GetImageWidth();
56   mojom::RangePtr GetZoom();
57
58  private:
59   PhotoCapabilities(camera_h camera) : camera_(camera) {}
60
61   camera_h camera_;
62   Range exposureCompensation_;
63   Range brightness_;
64   Range contrast_;
65   Range zoom_;
66
67   friend class CameraHandle;
68 };
69
70 class CameraHandleClient {
71  public:
72   virtual void OnStreamStopped() {}
73
74  protected:
75   virtual ~CameraHandleClient() {}
76 };
77
78 class CameraHandle final {
79  public:
80   static CameraHandle* GetInstance();
81
82   camera_h GetCameraHandle() { return camera_handle_; };
83   camera_device_e GetDeviceName() { return device_name_; };
84
85   bool IsValid();
86   bool GetSupportedPreviewResolutions(
87       std::vector<CameraCapability::Resolution>& supported_resolutions) const;
88   bool GetSupportedPreviewPixelFormats(
89       std::vector<media::VideoPixelFormat>& supported_formats) const;
90   bool GetSupportedPreviewCapabilities(std::vector<CameraCapability>&) const;
91   void GetDeviceSupportedFormats(media::VideoCaptureFormats& supported_formats);
92   int GetMaxFrameRate(CameraCapability::Resolution) const;
93   int GetDeviceCounts();
94   void ResetHandle(camera_device_e device_name);
95   void SetClient(CameraHandleClient* client);
96   void UnsetClient(CameraHandleClient* client);
97
98   // Set Photo Capabilities
99   bool SetZoom(int value);
100   bool SetResolution(int width, int height);
101   bool SetBrightness(int value);
102   bool SetContrast(int value);
103   bool SetIso(int value);
104   bool SetExposure(int value);
105
106   std::unique_ptr<PhotoCapabilities> capabilities_;
107
108  private:
109   CameraHandle();
110   ~CameraHandle();
111
112   camera_h camera_handle_;
113   camera_device_e device_name_;
114   CameraHandleClient* client_;
115
116   friend struct base::DefaultSingletonTraits<CameraHandle>;
117   DISALLOW_COPY_AND_ASSIGN(CameraHandle);
118 };
119
120 }  // namespace media
121
122 #endif  // MEDIA_CAPTURE_VIDEO_TIZEN_CAMERA_DEVICE_TIZEN_H_