OLD | NEW |
(Empty) | |
| 1 /* Copyright 2014 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. |
| 4 */ |
| 5 |
| 6 #ifndef PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ |
| 7 #define PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ |
| 8 |
| 9 #include "ppapi/c/private/ppb_image_capture_private.h" |
| 10 #include "ppapi/cpp/completion_callback.h" |
| 11 #include "ppapi/cpp/private/camera_capabilities_private.h" |
| 12 #include "ppapi/cpp/private/image_capture_config_private.h" |
| 13 #include "ppapi/cpp/resource.h" |
| 14 #include "ppapi/cpp/var.h" |
| 15 |
| 16 /// @file |
| 17 /// Defines the <code>ImageCapture_Private</code> interface. Used for |
| 18 /// acquiring a single still image from a camera source. |
| 19 namespace pp { |
| 20 |
| 21 /// To capture a still image with this class, use the following steps. |
| 22 /// 1. Create an ImageCapture_Private object by the constructor. |
| 23 /// 2. Call GetCameraCapabilities to get the supported preview sizes. |
| 24 /// 3. For optimal performance, set one of the supported preview size as the |
| 25 /// constraints of getUserMedia. Use the created MediaStreamVideoTrack for |
| 26 /// camera previews. |
| 27 /// 4. Set the same preview size and other settings by SetConfig. |
| 28 /// 5. Call CaptureStillImage to capture a still image. Play the shutter sound |
| 29 /// in the shutter callback. The image from the preview callback can be used |
| 30 /// for display. JPEG image will be returned to the JPEG callback. |
| 31 class ImageCapture_Private { |
| 32 public: |
| 33 /// Default constructor for creating an is_null() |
| 34 /// <code>ImageCapture_Private</code> object. |
| 35 ImageCapture_Private(); |
| 36 |
| 37 /// Creates an ImageCapture_Private resource. |
| 38 /// |
| 39 /// @param[in] instance A <code>PP_Instance</code> identifying one instance |
| 40 /// of a module. |
| 41 /// @param[in] camera_source_id A <code>Var</code> identifying a camera |
| 42 /// source. The type is string. The ID can be obtained from |
| 43 /// MediaStreamTrack.getSources() or MediaStreamVideoTrack.id. If a |
| 44 /// MediaStreamVideoTrack is associated with the same source and the track |
| 45 /// is closed, this ImageCapture_Private object can still do image capture. |
| 46 /// @param[in] error_callback A <code>ImageCapture_Private_ErrorCallback |
| 47 /// </code> callback to indicate the image capture has failed. |
| 48 /// @param[inout] user_data An opaque pointer that will be passed to the |
| 49 /// callbacks of ImageCapture_Private. |
| 50 ImageCapture_Private(const InstanceHandle& instance, |
| 51 const Var& camera_source_id, |
| 52 PPB_ImageCapture_Private_ErrorCallback error_callback, |
| 53 void* user_data); |
| 54 |
| 55 /// Constructs a <code>ImageCapture_Private</code> from a <code> |
| 56 /// Resource</code>. |
| 57 /// |
| 58 /// @param[in] resource A <code>ImageCapture_Private</code> |
| 59 /// resource. |
| 60 explicit ImageCapture_Private(const Resource& resource); |
| 61 |
| 62 /// A constructor used when you have received a <code>PP_Resource</code> as a |
| 63 /// return value that has had 1 ref added for you. |
| 64 /// |
| 65 /// @param[in] resource A <code>ImageCapture_Private</code> |
| 66 /// resource. |
| 67 ImageCapture_Private(PassRef, PP_Resource resource); |
| 68 |
| 69 // Destructor. |
| 70 ~ImageCapture_Private(); |
| 71 |
| 72 /// Disconnects from the camera and cancels all pending capture requests. |
| 73 /// After this returns, no callbacks will be called. If <code> |
| 74 /// ImageCapture_Private</code> is destroyed and is not closed yet, this |
| 75 /// function will be automatically called. Calling this more than once has no |
| 76 /// effect. |
| 77 /// |
| 78 /// @param[in] callback <code>CompletionCallback</code> to be called upon |
| 79 /// completion of <code>Close()</code>. |
| 80 /// |
| 81 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 82 int32_t Close(const CompletionCallback& callback); |
| 83 |
| 84 /// Sets the configuration of the image capture. |
| 85 /// If <code>SetConfig()</code> is not called, default settings will be used. |
| 86 /// |
| 87 /// @param[in] config A <code>ImageCaptureConfig_Private</code> object. |
| 88 /// @param[in] callback <code>CompletionCallback</code> to be called upon |
| 89 /// completion of <code>SetConfig()</code>. |
| 90 /// |
| 91 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 92 /// Returns <code>PP_ERROR_INPROGRESS</code> if there is a pending call of |
| 93 /// <code>SetConfig()</code> or <code>CaptureStillImage()</code>. |
| 94 /// If an error is returned, the configuration will not be changed. |
| 95 int32_t SetConfig(const ImageCaptureConfig_Private& config, |
| 96 const CompletionCallback& callback); |
| 97 |
| 98 /// Gets the configuration of the image capture. |
| 99 /// |
| 100 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> |
| 101 /// to be called upon completion. |
| 102 /// |
| 103 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 104 int32_t GetConfig( |
| 105 const CompletionCallbackWithOutput<ImageCaptureConfig_Private>& callback); |
| 106 |
| 107 /// Gets the camera capabilities. |
| 108 /// |
| 109 /// The camera capabilities do not change for a given camera source. |
| 110 /// |
| 111 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> |
| 112 /// to be called upon completion. |
| 113 /// |
| 114 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 115 int32_t GetCameraCapabilities( |
| 116 const CompletionCallbackWithOutput<CameraCapabilities_Private>& callback); |
| 117 |
| 118 /// Captures a still JPEG image from the camera. |
| 119 /// |
| 120 /// Triggers an asynchronous image capture. The camera will initiate a series |
| 121 /// of callbacks to the application as the image capture progresses. The |
| 122 /// callbacks will be invoked in the order of shutter callback, preview |
| 123 /// callback, and JPEG callback. The shutter callback occurs after the image |
| 124 /// is captured. This can be used to trigger a sound to let the user know that |
| 125 /// image has been captured. The preview callback occurs when a scaled, fully |
| 126 /// processed preview image is available. The JPEG callback occurs when the |
| 127 /// compressed image is available. If there is an error after the capture is |
| 128 /// in progress, the error callback passed to <code> |
| 129 /// ImageCapture_Private.Create()</code> will be invoked. All the callbacks |
| 130 /// are invoked by the thread that calls this function. |
| 131 /// |
| 132 /// The size of the preview image in preview callback is determined by |
| 133 /// <code>ImageCaptureConfig_Private.SetPreviewSize</code>. The format is |
| 134 /// decided by the camera and can be got from <code>VideoFrame.GetFormat |
| 135 /// </code>. The size of the JPEG image is determined by <code> |
| 136 /// ImageCaptureConfig_Private.SetJpegSize</code>. |
| 137 /// |
| 138 /// The camera may need to stop and re-start streaming during image capture. |
| 139 /// If some MediaStreamVideoTrack are associated with the camera source, they |
| 140 /// will receive mute and unmute events. The mute event will be received |
| 141 /// before all the callbacks. The unmute event will be received after all the |
| 142 /// callbacks. The preview image will not be sent to the video tracks |
| 143 /// associated with the camera. |
| 144 /// |
| 145 /// @param[in] shutter_callback A <code> |
| 146 /// ImageCapture_Private_ShutterCallback</code> callback to indicate the |
| 147 /// image has been taken. |
| 148 /// @param[in] preview_callback A <code> |
| 149 /// ImageCapture_Private_PreviewCallback</code> callback to return a |
| 150 /// preview of the captured image. |
| 151 /// @param[in] jpeg_callback A <code> |
| 152 /// ImageCapture_Private_JpegCallback</code> callback to return captured |
| 153 /// JPEG image. |
| 154 /// @param[out] sequence_id The sequence ID is a unique monotonically |
| 155 /// increasing value starting from 0, incremented every time a new request |
| 156 /// like image capture is submitted. |
| 157 /// |
| 158 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 159 /// PP_OK means the callbacks will be triggered. Other values mean the |
| 160 /// callbacks will not be triggered. |
| 161 int32_t CaptureStillImage( |
| 162 PPB_ImageCapture_Private_ShutterCallback shutter_callback, |
| 163 PPB_ImageCapture_Private_PreviewCallback preview_callback, |
| 164 PPB_ImageCapture_Private_JpegCallback jpeg_callback, |
| 165 int64_t* sequence_id); |
| 166 |
| 167 /// Determines if a resource is an image capture resource. |
| 168 /// |
| 169 /// @param[in] resource The <code>Resource</code> to test. |
| 170 /// |
| 171 /// @return true if the given resource is an image capture resource or false |
| 172 /// otherwise. |
| 173 static bool IsImageCapture(const Resource& resource); |
| 174 }; |
| 175 |
| 176 } // namespace pp |
| 177 |
| 178 #endif /* PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ */ |
| 179 |
OLD | NEW |