| OLD | NEW |
| 1 /* Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #ifndef PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ | 6 #ifndef PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ |
| 7 #define PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ | 7 #define PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ |
| 8 | 8 |
| 9 #include "ppapi/c/private/ppb_image_capture_private.h" | 9 #include "ppapi/c/private/ppb_image_capture_private.h" |
| 10 #include "ppapi/cpp/completion_callback.h" | 10 #include "ppapi/cpp/completion_callback.h" |
| 11 #include "ppapi/cpp/private/camera_capabilities_private.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" | 12 #include "ppapi/cpp/resource.h" |
| 14 #include "ppapi/cpp/var.h" | 13 #include "ppapi/cpp/var.h" |
| 15 | 14 |
| 16 /// @file | 15 /// @file |
| 17 /// Defines the <code>ImageCapture_Private</code> interface. Used for | 16 /// Defines the <code>ImageCapture_Private</code> interface. Used for |
| 18 /// acquiring a single still image from a camera source. | 17 /// acquiring a single still image from a camera source. |
| 19 namespace pp { | 18 namespace pp { |
| 20 | 19 |
| 21 /// To capture a still image with this class, use the following steps. | 20 /// To query camera capabilities: |
| 22 /// 1. Create an ImageCapture_Private object by the constructor. | 21 /// 1. Get a PPB_ImageCapture_Private object by Create(). |
| 23 /// 2. Call GetCameraCapabilities to get the supported preview sizes. | 22 /// 2. Open() camera device with track id of MediaStream video track. |
| 24 /// 3. For optimal performance, set one of the supported preview size as the | 23 /// 3. Call GetCameraCapabilities() to get a |
| 25 /// constraints of getUserMedia. Use the created MediaStreamVideoTrack for | 24 /// <code>PPB_CameraCapabilities_Private</code> object, which can be used to |
| 26 /// camera previews. | 25 /// query camera capabilities. |
| 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 { | 26 class ImageCapture_Private { |
| 32 public: | 27 public: |
| 33 /// Default constructor for creating an is_null() | 28 /// Default constructor for creating an is_null() |
| 34 /// <code>ImageCapture_Private</code> object. | 29 /// <code>ImageCapture_Private</code> object. |
| 35 ImageCapture_Private(); | 30 ImageCapture_Private(); |
| 36 | 31 |
| 37 /// Creates an ImageCapture_Private resource. | 32 /// Creates an ImageCapture_Private resource. |
| 38 /// | 33 /// |
| 39 /// @param[in] instance A <code>PP_Instance</code> identifying one instance | 34 /// @param[in] instance A <code>PP_Instance</code> identifying one instance |
| 40 /// of a module. | 35 /// of a module. |
| 41 /// @param[in] camera_source_id A <code>Var</code> identifying a camera | 36 /// @param[in] camera_source_id A <code>Var</code> identifying a camera |
| 42 /// source. The type is string. The ID can be obtained from | 37 /// source. The type is string. The ID can be obtained from |
| 43 /// MediaStreamTrack.getSources() or MediaStreamVideoTrack.id. If a | 38 /// MediaStreamTrack.getSources() or MediaStreamVideoTrack.id. If a |
| 44 /// MediaStreamVideoTrack is associated with the same source and the track | 39 /// MediaStreamVideoTrack is associated with the same source and the track |
| 45 /// is closed, this ImageCapture_Private object can still do image capture. | 40 /// is closed, this ImageCapture_Private object can still do image capture. |
| 46 /// @param[in] error_callback A <code>ImageCapture_Private_ErrorCallback | 41 /// @param[in] error_callback A <code>ImageCapture_Private_ErrorCallback |
| 47 /// </code> callback to indicate the image capture has failed. | 42 /// </code> callback to indicate the image capture has failed. |
| 48 /// @param[inout] user_data An opaque pointer that will be passed to the | 43 /// @param[inout] user_data An opaque pointer that will be passed to the |
| 49 /// callbacks of ImageCapture_Private. | 44 /// callbacks of ImageCapture_Private. |
| 50 ImageCapture_Private(const InstanceHandle& instance, | 45 ImageCapture_Private(const InstanceHandle& instance, |
| 51 const Var& camera_source_id, | 46 const Var& camera_source_id, |
| 52 PPB_ImageCapture_Private_ErrorCallback error_callback, | |
| 53 void* user_data); | 47 void* user_data); |
| 54 | 48 |
| 55 /// Constructs a <code>ImageCapture_Private</code> from a <code> | 49 /// Constructs a <code>ImageCapture_Private</code> from a <code> |
| 56 /// Resource</code>. | 50 /// Resource</code>. |
| 57 /// | 51 /// |
| 58 /// @param[in] resource A <code>ImageCapture_Private</code> | 52 /// @param[in] resource A <code>ImageCapture_Private</code> |
| 59 /// resource. | 53 /// resource. |
| 60 explicit ImageCapture_Private(const Resource& resource); | 54 explicit ImageCapture_Private(const Resource& resource); |
| 61 | 55 |
| 62 /// A constructor used when you have received a <code>PP_Resource</code> as a | 56 /// A constructor used when you have received a <code>PP_Resource</code> as a |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 /// ImageCapture_Private</code> is destroyed and is not closed yet, this | 68 /// ImageCapture_Private</code> is destroyed and is not closed yet, this |
| 75 /// function will be automatically called. Calling this more than once has no | 69 /// function will be automatically called. Calling this more than once has no |
| 76 /// effect. | 70 /// effect. |
| 77 /// | 71 /// |
| 78 /// @param[in] callback <code>CompletionCallback</code> to be called upon | 72 /// @param[in] callback <code>CompletionCallback</code> to be called upon |
| 79 /// completion of <code>Close()</code>. | 73 /// completion of <code>Close()</code>. |
| 80 /// | 74 /// |
| 81 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. | 75 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 82 int32_t Close(const CompletionCallback& callback); | 76 int32_t Close(const CompletionCallback& callback); |
| 83 | 77 |
| 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. | 78 /// Gets the camera capabilities. |
| 108 /// | 79 /// |
| 109 /// The camera capabilities do not change for a given camera source. | 80 /// The camera capabilities do not change for a given camera source. |
| 110 /// | 81 /// |
| 111 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> | 82 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> |
| 112 /// to be called upon completion. | 83 /// to be called upon completion. |
| 113 /// | 84 /// |
| 114 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. | 85 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 115 int32_t GetCameraCapabilities( | 86 int32_t GetCameraCapabilities( |
| 116 const CompletionCallbackWithOutput<CameraCapabilities_Private>& callback); | 87 const CompletionCallbackWithOutput<CameraCapabilities_Private>& callback); |
| 117 | 88 |
| 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. | 89 /// Determines if a resource is an image capture resource. |
| 168 /// | 90 /// |
| 169 /// @param[in] resource The <code>Resource</code> to test. | 91 /// @param[in] resource The <code>Resource</code> to test. |
| 170 /// | 92 /// |
| 171 /// @return true if the given resource is an image capture resource or false | 93 /// @return true if the given resource is an image capture resource or false |
| 172 /// otherwise. | 94 /// otherwise. |
| 173 static bool IsImageCapture(const Resource& resource); | 95 static bool IsImageCapture(const Resource& resource); |
| 174 }; | 96 }; |
| 175 | 97 |
| 176 } // namespace pp | 98 } // namespace pp |
| 177 | 99 |
| 178 #endif /* PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ */ | 100 #endif /* PPAPI_CPP_PRIVATE_IMAGE_CAPTURE_PRIVATE_H_ */ |
| 179 | 101 |
| OLD | NEW |