make use of media_use_ffmpeg in BUILD.gn
[chromium-blink-merge.git] / extensions / browser / api / webcam_private / visca_webcam.h
bloba24c747658b3ee7a32d69067fc831dad78dbf0f0
1 // Copyright 2015 The Chromium Authors. 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.
5 #ifndef EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_
6 #define EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_
8 #include <deque>
10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "extensions/browser/api/serial/serial_connection.h"
13 #include "extensions/browser/api/webcam_private/webcam.h"
14 #include "extensions/common/api/serial.h"
16 namespace extensions {
18 class ViscaWebcam : public Webcam {
19 public:
20 ViscaWebcam(const std::string& path, const std::string& extension_id);
22 using OpenCompleteCallback = base::Callback<void(bool)>;
24 // Open and initialize the web camera. This is done by the following three
25 // steps (in order): 1. Open the serial port; 2. Request address; 3. Clear
26 // the command buffer. After these three steps completes, |open_callback| will
27 // be called.
28 void Open(const OpenCompleteCallback& open_callback);
30 private:
31 ~ViscaWebcam() override;
33 enum CommandType {
34 COMMAND,
35 INQUIRY_PAN,
36 INQUIRY_TILT,
37 INQUIRY_PAN_TILT,
38 INQUIRY_ZOOM,
41 using CommandCompleteCallback =
42 base::Callback<void(bool, const std::vector<char>&)>;
44 void OpenOnIOThread(const OpenCompleteCallback& open_callback);
45 // Callback function that will be called after the serial connection has been
46 // opened successfully.
47 void OnConnected(const OpenCompleteCallback& open_callback, bool success);
48 // Callback function that will be called after the address has been set
49 // successfully.
50 void OnAddressSetCompleted(const OpenCompleteCallback& open_callback,
51 bool success,
52 const std::vector<char>& response);
53 // Callback function that will be called after the command buffer has been
54 // cleared successfully.
55 void OnClearAllCompleted(const OpenCompleteCallback& open_callback,
56 bool success,
57 const std::vector<char>& response);
59 // Send or queue a command and wait for the camera's response.
60 void Send(const std::vector<char>& command,
61 const CommandCompleteCallback& callback);
62 void OnSendCompleted(const CommandCompleteCallback& callback,
63 int bytes_sent,
64 api::serial::SendError error);
65 void ReceiveLoop(const CommandCompleteCallback& callback);
66 void OnReceiveCompleted(const CommandCompleteCallback& callback,
67 const std::vector<char>& data,
68 api::serial::ReceiveError error);
69 // Callback function that will be called after the send and reply of a command
70 // are both completed. Update |value| according to |type| and |response| if
71 // necessory.
72 void OnCommandCompleted(CommandType type,
73 int* value,
74 bool success,
75 const std::vector<char>& response);
77 // Webcam Overrides:
78 void Reset(bool pan, bool tilt, bool zoom) override;
79 bool GetPan(int* value) override;
80 bool GetTilt(int* value) override;
81 bool GetZoom(int* value) override;
82 bool SetPan(int value) override;
83 bool SetTilt(int value) override;
84 bool SetZoom(int value) override;
85 bool SetPanDirection(PanDirection direction) override;
86 bool SetTiltDirection(TiltDirection direction) override;
88 const std::string path_;
89 const std::string extension_id_;
91 scoped_ptr<SerialConnection> serial_connection_;
93 // Stores the response for the current command.
94 std::vector<char> data_buffer_;
95 // Queues commands till the current command completes.
96 std::deque<std::pair<std::vector<char>, CommandCompleteCallback>> commands_;
98 // Visca webcam always get/set pan-tilt together. |pan| and |tilt| are used to
99 // store the current value of pan and tilt positions.
100 int pan_;
101 int tilt_;
103 base::WeakPtrFactory<ViscaWebcam> weak_ptr_factory_;
105 DISALLOW_COPY_AND_ASSIGN(ViscaWebcam);
108 } // namespace extensions
110 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_VISCA_WEBCAM_H_