未验证 提交 62b26058 编写于 作者: O openharmony_ci 提交者: Gitee

!22090 翻译完成:20907 修改获取源码步骤,以及一些格式问题。

Merge pull request !22090 from wusongqing/TR20907
# Camera Overview<a name="EN-US_TOPIC_0000001051690589"></a> # Camera Overview
## Basic Concepts<a name="section175012297491"></a>
## Basic Concepts
Camera is one of the services provided by the OpenHarmony multimedia subsystem. The camera module provides recording, preview, and photographing features and supports concurrent stream reading by multiple users. Camera is one of the services provided by the OpenHarmony multimedia subsystem. The camera module provides recording, preview, and photographing features and supports concurrent stream reading by multiple users.
It is considered good practice that you understand the following concepts before starting development: It is considered good practice that you understand the following concepts before starting development:
- Video frame - Video frame
A video frame is formed by the stream data of a video image. Video data streams are formed by a series of image data arranged at a fixed time interval.
- Frame per second \(FPS\)
FPS is used to represent the frame rate at which images are refreshed during video playback, or the number of frames per second during video playback. A higher frame rate means smoother video playback.
- Resolution
Information about each image frame consists of pixels. The number of pixels in an image is presented by the resolution. For example, 1080p \(1920 x 1080\) indicates that the image width is 1920 pixels and the image height is 1080 pixels.
## Working Principles<a name="section193961322175011"></a>
- Multimedia services
Multimedia services are started by the **Init** process upon system startup, and media hardware resources \(such as memory, display hardware, image sensors, and codecs\) are initialized and allocated. During the initialization, the configuration file is parsed, which determines the upper limit of capabilities and resources of each service. Generally, the upper limit is configured by original equipment manufacturers \(OEMs\) in the configuration file. The following configuration items are available for the camera service during multimedia service initialization:
- Memory pool: Memory blocks in the memory pool are accessed and released continuously by all multimedia services.
- Image sensor: sensor type, resolution, ISP, and more
- Image processor: resolution, bit rate, image inversion, and more
- Image encoder: encoding format, bit rate, resolution, and more
- Major classes
You can use the **Camera** class and its asynchronous callback classes to configure and access the camera functionalities. The three callback classes correspond to different asynchronous processing scenarios, as described in [Table 1](#table486418149411). A video frame is formed by the stream data of a video image. Video data streams are formed by a series of image data arranged at a fixed time interval.
**Table 1** Class description - Frames per second (FPS)
<a name="table486418149411"></a> FPS is used to represent the frame rate at which images are refreshed during video playback, or the number of frames per second during video playback. A higher frame rate means smoother video playback.
<table><thead align="left"><tr id="row19864414104115"><th class="cellrowborder" valign="top" width="22.322232223222326%" id="mcps1.2.4.1.1"><p id="p128641914114112"><a name="p128641914114112"></a><a name="p128641914114112"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="44.34443444344435%" id="mcps1.2.4.1.2"><p id="p1386471410411"><a name="p1386471410411"></a><a name="p1386471410411"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p1486541484116"><a name="p1486541484116"></a><a name="p1486541484116"></a>Examples</p>
</th>
</tr>
</thead>
<tbody><tr id="row138651914104113"><td class="cellrowborder" valign="top" width="22.322232223222326%" headers="mcps1.2.4.1.1 "><p id="p1886515147416"><a name="p1886515147416"></a><a name="p1886515147416"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="44.34443444344435%" headers="mcps1.2.4.1.2 "><p id="p48653148414"><a name="p48653148414"></a><a name="p48653148414"></a>Configures the static camera capability through the configuration class to use basic camera functionalities.</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p986510145416"><a name="p986510145416"></a><a name="p986510145416"></a>Photographing, video recording, and previewing</p>
</td>
</tr>
<tr id="row98656144413"><td class="cellrowborder" valign="top" width="22.322232223222326%" headers="mcps1.2.4.1.1 "><p id="p13865161412412"><a name="p13865161412412"></a><a name="p13865161412412"></a>CameraDeviceCallback</p>
</td>
<td class="cellrowborder" valign="top" width="44.34443444344435%" headers="mcps1.2.4.1.2 "><p id="p1986517141413"><a name="p1986517141413"></a><a name="p1986517141413"></a>Handles camera hardware state changes.</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p286531413419"><a name="p286531413419"></a><a name="p286531413419"></a>Available or unavailable</p>
</td>
</tr>
<tr id="row167872310411"><td class="cellrowborder" valign="top" width="22.322232223222326%" headers="mcps1.2.4.1.1 "><p id="p196793230419"><a name="p196793230419"></a><a name="p196793230419"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="44.34443444344435%" headers="mcps1.2.4.1.2 "><p id="p14679823144110"><a name="p14679823144110"></a><a name="p14679823144110"></a>Handles camera instance state changes.</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p6679102354112"><a name="p6679102354112"></a><a name="p6679102354112"></a>Created or released</p>
</td>
</tr>
<tr id="row886581414118"><td class="cellrowborder" valign="top" width="22.322232223222326%" headers="mcps1.2.4.1.1 "><p id="p1865614194116"><a name="p1865614194116"></a><a name="p1865614194116"></a>FrameStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="44.34443444344435%" headers="mcps1.2.4.1.2 "><p id="p1865171420410"><a name="p1865171420410"></a><a name="p1865171420410"></a>Handles frame status changes.</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p486541444119"><a name="p486541444119"></a><a name="p486541444119"></a>Start and end of photographing, and frame rate changes</p>
</td>
</tr>
</tbody>
</table>
- Stream transfer - Resolution
A surface is the basic data structure for transferring audio and video data. A camera is generally used as the data producer of a surface and has specific consumers in different scenarios. Information about each image frame consists of pixels. The number of pixels in an image is presented by the resolution. For example, 1080p (1920 x 1080) indicates that the image width is 1920 pixels and the image height is 1080 pixels.
Camera preview and recording outputs are video streams, and photographing outputs are image frames. The outputs are transferred through the **Surface** class. A surface can transmit media information streams within and cross processes.
Take video recording as an example. You create a **Recorder** instance, obtain the surface of the **Recorder** instance, and then transfer the surface to the **Camera** instance. In this case, the **Camera** instance works as a producer to inject video streams to the surface, and the **Recorder** instance act as the consumer to obtain video streams from the surface for storage. In this case, you connect the recorder and camera through the surface. ## Working Principles
Similarly, you can create a surface, implement consumer logic for it, and transfer it to the **Camera** instance. For example, transmit video streams over the network or save captured frame data as an image file. - Multimedia services
Multimedia services are started by the **Init** process upon system startup, and media hardware resources (such as memory, display hardware, image sensors, and codecs) are initialized and allocated. During the initialization, the configuration file is parsed, which determines the upper limit of capabilities and resources of each service. Generally, the upper limit is configured by original equipment manufacturers (OEMs) in the configuration file. The following configuration items are available for the camera service during multimedia service initialization:
The graphics module also obtains stream resources from the camera module through surfaces. For details, see development guidelines on [Graphic](subsys-graphics-overview.md). - Memory pool: Memory blocks in the memory pool are accessed and released continuously by all multimedia services.
- Image sensor: sensor type, resolution, ISP, and more.
- Image processor: resolution, bit rate, image inversion, and more.
- Image encoder: encoding format, bit rate, resolution, and more.
- Camera running process - Major classes
1. Creating a camera
You can use the **Camera** class and its asynchronous callback classes to configure and access the camera functionalities. The three callback classes correspond to different asynchronous processing scenarios, as described in the table below.
**Table 1** Class description
| Class| Description| Example|
| -------- | -------- | -------- |
| Camera | Configures the static camera capability through the configuration class to use basic camera functionalities.| Photographing, video recording, and previewing|
| CameraDeviceCallback | Handles camera hardware state changes.| Available/Unavailable|
| CameraStateCallback | Handles camera instance state changes.| Created or released|
| FrameStateCallback | Handles frame status changes.| Start and end of photographing, and frame rate changes|
This process creates a **Camera** instance by **CameraManager**, binds the camera device to the server, and asynchronously notifies you of the successful creation. The following figure shows the time sequence between classes. - Stream transfer
A surface is the basic data structure for transferring audio and video data. A camera is generally used as the data producer of a surface and has specific consumers in different scenarios.
**Figure 1** Sequence diagram for creating a camera<a name="fig9882125184416"></a> Camera preview and recording outputs are video streams, and photographing outputs are image frames. The outputs are transferred through the **Surface** class. A surface can transmit media information streams within and cross processes.
![](figures/en-us_image_0000001054101094.png) Take video recording as an example. You create a **Recorder** instance, obtain the surface of the **Recorder** instance, and then transfer the surface to the **Camera** instance. In this case, the **Camera** instance works as a producer to inject video streams to the surface, and the **Recorder** instance act as the consumer to obtain video streams from the surface for storage. In this case, you connect the recorder and camera through the surface.
1. Taking a video/Previewing Similarly, you can create a surface, implement consumer logic for it, and transfer it to the **Camera** instance. For example, transmit video streams over the network or save captured frame data as an image file.
This process creates a **Camera** instance via **CameraKit**, and configures frame attributes via **FrameConfig** for recording or previewing. The following figure shows the time sequence. The graphics module also obtains stream resources from the camera module through surfaces. For details, see [Overview of Small-System Graphics](../subsystems/subsys-graphics-overview.md).
**Figure 2** Sequence diagram for recording/previewing<a name="fig642695404512"></a> - Camera running process
![](figures/en-us_image_0000001054421113.png) 1. Creating a camera
This process creates a **Camera** instance by **CameraManager**, binds the camera device to the server, and asynchronously notifies you of the successful creation. The following figure shows the time sequence between classes.
**Figure 1** Sequence diagram for creating a camera
![en-us_image_0000001200114819](figures/en-us_image_0000001200114819.png)
2. Taking a video/Previewing
This process creates a **Camera** instance via **CameraKit**, and configures frame attributes via **FrameConfig** for recording or previewing. The following figure shows the time sequence.
**Figure 2** Sequence diagram for recording/previewing
![en-us_image_0000001200115193](figures/en-us_image_0000001200115193.png)
# Photographing Development<a name="EN-US_TOPIC_0000001052170554"></a> # Photographing Development
## When to Use<a name="section1963312376119"></a>
## When to Use
Use the camera module APIs to capture frames \(photographing\).
Use the camera module APIs to capture frames (photographing).
## Available APIs<a name="section56549532016"></a>
**Table 1** APIs for photographing ## Available APIs
<a name="table2069447114914"></a> **Table 1** APIs for photographing
<table><thead align="left"><tr id="row4903852104914"><th class="cellrowborder" valign="top" width="18.811881188118814%" id="mcps1.2.4.1.1"><p id="p2903252174918"><a name="p2903252174918"></a><a name="p2903252174918"></a>Class</p>
</th> | Class| API| Description|
<th class="cellrowborder" valign="top" width="46.534653465346544%" id="mcps1.2.4.1.2"><p id="p1595113912507"><a name="p1595113912507"></a><a name="p1595113912507"></a>Function</p> | -------- | -------- | -------- |
</th> | CameraKit | int32_t&nbsp;GetCameraIds(std::list&lt;string&gt;&nbsp;cameraList) | Obtains IDs of cameras that are currently available.|
<th class="cellrowborder" valign="top" width="34.65346534653466%" id="mcps1.2.4.1.3"><p id="p15951597508"><a name="p15951597508"></a><a name="p15951597508"></a>Description</p> | CameraKit | CameraAbility&amp;&nbsp;GetCameraAbility(string&nbsp;cameraId) | Obtains the camera capability.|
</th> | CameraKit | void&nbsp;RegisterCameraDeviceCallback(CameraDeviceCallback\*&nbsp;callback,&nbsp;EventHandler\*&nbsp;handler) | Registers a camera callback for camera status changes.|
</tr> | CameraKit | void&nbsp;UnregisterCameraDeviceCallback(CameraDeviceCallback\*&nbsp;callback) | Unregisters a camera callback.|
</thead> | CameraKit | void&nbsp;CreateCamera(string&nbsp;cameraId,&nbsp;CameraStateCallback\*&nbsp;callback,&nbsp;EventHandler\*&nbsp;handler) | Creates a **Camera** instance.|
<tbody><tr id="row492815717494"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1592812716495"><a name="p1592812716495"></a><a name="p1592812716495"></a>CameraKit</p> | Camera | string&nbsp;GetCameraId() | Obtains the camera ID.|
</td> | Camera | CameraConfig&amp;&nbsp;GetCameraConfig() | Obtains the camera configuration.|
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1492837144919"><a name="p1492837144919"></a><a name="p1492837144919"></a>int32_t GetCameraIds(std::list&lt;string&gt; cameraList)</p> | Camera | FrameConfig&amp;&nbsp;GetFrameConfig(int32_t&nbsp;type) | Obtains the frame configuration.|
</td> | Camera | void&nbsp;Configure(CameraConfig&amp;&nbsp;config) | Configures the camera using a **CameraConfig** instance.|
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p2092807134919"><a name="p2092807134919"></a><a name="p2092807134919"></a>Obtains IDs of cameras that are currently available.</p> | Camera | void&nbsp;Release() | Releases the **Camera** object and associated resources.|
</td> | Camera | int&nbsp;TriggerLoopingCapture(FrameConfig&amp;&nbsp;frameConfig) | Starts looping-frame capture.|
</tr> | Camera | void&nbsp;StopLoopingCapture() | Stops looping-frame capture.|
<tr id="row11928157114912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p139287774911"><a name="p139287774911"></a><a name="p139287774911"></a>CameraKit</p> | Camera | int32_t&nbsp;TriggerSingleCapture(FrameConfig&amp;&nbsp;frameConfig) | Starts single-frame capture.|
</td> | CameraConfig | void&nbsp;SetFrameStateCallback(FrameStateCallback\*&nbsp;callback,&nbsp;EventHandler\*&nbsp;handler); | Sets a frame state callback to respond to state changes.|
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p9928107174915"><a name="p9928107174915"></a><a name="p9928107174915"></a>CameraAbility&amp; GetCameraAbility(string cameraId)</p> | CameraConfig | static&nbsp;CameraConfig\*&nbsp;CreateCameraConfig() | Creates a **CameraConfig** instance.|
</td> | CameraAbility | std::list&lt;Size&gt;&nbsp;GetSupportedSizes(int&nbsp;format) | Obtains the supported image sizes for a specified image format.|
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p139281171494"><a name="p139281171494"></a><a name="p139281171494"></a>Obtains the camera capability</p> | CameraAbility | std::list&lt;T&gt;&nbsp;GetParameterRange(uint32_t&nbsp;key) | Obtains the parameter value range based on a specified parameter key.|
</td> | CameraDevice | CameraDeviceCallback() | A constructor used to create a **CameraDeviceCallback** instance.|
</tr> | CameraDevice | void&nbsp;OnCameraStatus​(std::string&nbsp;cameraId,&nbsp;int32_t&nbsp;status) | Called when the camera device status changes.|
<tr id="row119282719496"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p159288734914"><a name="p159288734914"></a><a name="p159288734914"></a>CameraKit</p> | CameraStateCallback | CameraStateCallback​() | A constructor used to create a **CameraStateCallback** instance.|
</td> | CameraStateCallback | void&nbsp;OnConfigured​(Camera&amp;&nbsp;camera) | Called when the camera is configured successfully.|
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p99280794913"><a name="p99280794913"></a><a name="p99280794913"></a>void RegisterCameraDeviceCallback(CameraDeviceCallback* callback, EventHandler* handler)</p> | CameraStateCallback | void&nbsp;OnConfigureFailed​(Camera&amp;&nbsp;camera,int32_t&nbsp;errorCode) | Called when the camera fails to be configured.|
</td> | CameraStateCallback | void&nbsp;OnCreated​(Camera&amp;&nbsp;camera) | Called when the camera is created successfully.|
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p8928197134910"><a name="p8928197134910"></a><a name="p8928197134910"></a>Registers a camera callback for camera status changes.</p> | CameraStateCallback | void&nbsp;OnCreateFailed​(std::string&nbsp;cameraId,int32_t&nbsp;errorCode) | Called when the camera fails to be created.|
</td> | CameraStateCallback | void&nbsp;OnReleased​(Camera&amp;&nbsp;camera) | Called when the camera is released.|
</tr> | FrameStateCallback | FrameStateCallback​() | A constructor used to create a **FrameStateCallback** instance.|
<tr id="row4928673496"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p14928770497"><a name="p14928770497"></a><a name="p14928770497"></a>CameraKit</p> | FrameStateCallback | void&nbsp;OnFrameFinished(Camera&amp;&nbsp;camera,&nbsp;FrameConfig&amp;&nbsp;frameConfig,&nbsp;FrameResult&amp;&nbsp;frameResult) | Called when the frame capture is completed.|
</td> | FrameStateCallback | void&nbsp;OnFrameError​(Camera&amp;&nbsp;camera,&nbsp;FrameConfig&amp;&nbsp;frameConfig,&nbsp;int32_t&nbsp;errorCode,&nbsp;FrameResult&amp;&nbsp;frameResult) | Called when the frame capture fails.|
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p14928197194915"><a name="p14928197194915"></a><a name="p14928197194915"></a>void UnregisterCameraDeviceCallback(CameraDeviceCallback* callback)</p> | FrameConfig | int32_t&nbsp;GetFrameConfigType() | Obtains the frame configuration type.|
</td> | FrameConfig | std::list&lt;OHOS::Surface&gt;&nbsp;GetSurfaces() | Obtains a list of surface objects.|
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p17929197134913"><a name="p17929197134913"></a><a name="p17929197134913"></a>Unregisters a camera callback.</p> | FrameConfig | void&nbsp;AddSurface(OHOS::AGP::UISurface&amp;&nbsp;surface); | Adds a surface.|
</td> | FrameConfig | void&nbsp;RemoveSurface(OHOS::AGP::UISurface&amp;&nbsp;surface); | Removes a surface.|
</tr>
<tr id="row16929187104912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p6929157184911"><a name="p6929157184911"></a><a name="p6929157184911"></a>CameraKit</p>
</td> ## Constraints
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1192910704914"><a name="p1192910704914"></a><a name="p1192910704914"></a>void CreateCamera(string cameraId, CameraStateCallback* callback, EventHandler* handler)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p12929167154912"><a name="p12929167154912"></a><a name="p12929167154912"></a>Creates a <strong id="b1512582132318"><a name="b1512582132318"></a><a name="b1512582132318"></a>Camera</strong> instance.</p>
</td>
</tr>
<tr id="row16929187104913"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p6929157184911"><a name="p6929157184911"></a><a name="p6929157184911"></a>CameraKit</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p1192910704914"><a name="p1192910704914"></a><a name="p1192910704914"></a>const CameraInfo *GetCameraInfo(std::string cameraId);</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p12929167154912"><a name="p12929167154912"></a><a name="p12929167154912"></a>Creates a <strong id="b1512582132318"><a name="b1512582132318"></a><a name="b1512582132318"></a>CameraInfo</strong> instance.</p>
</td>
</tr>
<tr id="row592967184912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p9929127134915"><a name="p9929127134915"></a><a name="p9929127134915"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p0929107204913"><a name="p0929107204913"></a><a name="p0929107204913"></a>string GetCameraId()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1592914710490"><a name="p1592914710490"></a><a name="p1592914710490"></a>Obtains the camera ID.</p>
</td>
</tr>
<tr id="row13929197104913"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p16929167134913"><a name="p16929167134913"></a><a name="p16929167134913"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p15929175491"><a name="p15929175491"></a><a name="p15929175491"></a>CameraConfig&amp; GetCameraConfig()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p19298714917"><a name="p19298714917"></a><a name="p19298714917"></a>Obtains the camera configuration.</p>
</td>
</tr>
<tr id="row1892918764915"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p69291072495"><a name="p69291072495"></a><a name="p69291072495"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p5930172494"><a name="p5930172494"></a><a name="p5930172494"></a>FrameConfig&amp; GetFrameConfig(int32_t type)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p19301176495"><a name="p19301176495"></a><a name="p19301176495"></a>Obtains the frame configuration.</p>
</td>
</tr>
<tr id="row893019794915"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p893016714919"><a name="p893016714919"></a><a name="p893016714919"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1093067134915"><a name="p1093067134915"></a><a name="p1093067134915"></a>void Configure(CameraConfig&amp; config)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1493037114912"><a name="p1493037114912"></a><a name="p1493037114912"></a>Configures the camera using the <strong id="b1158653521815"><a name="b1158653521815"></a><a name="b1158653521815"></a>CameraConfig</strong> object.</p>
</td>
</tr>
<tr id="row11930197174917"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p4930197184914"><a name="p4930197184914"></a><a name="p4930197184914"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p19304717492"><a name="p19304717492"></a><a name="p19304717492"></a>void Release()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p189301479494"><a name="p189301479494"></a><a name="p189301479494"></a>Releases the <strong id="b12391143101812"><a name="b12391143101812"></a><a name="b12391143101812"></a>Camera</strong> object and associated resources.</p>
</td>
</tr>
<tr id="row109304717499"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p4930873496"><a name="p4930873496"></a><a name="p4930873496"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1893017720490"><a name="p1893017720490"></a><a name="p1893017720490"></a>int TriggerLoopingCapture(FrameConfig&amp; frameConfig)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p149307754918"><a name="p149307754918"></a><a name="p149307754918"></a>Starts looping-frame capture.</p>
</td>
</tr>
<tr id="row19306794915"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p6930167194910"><a name="p6930167194910"></a><a name="p6930167194910"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p139311577499"><a name="p139311577499"></a><a name="p139311577499"></a>void StopLoopingCapture()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p693115764914"><a name="p693115764914"></a><a name="p693115764914"></a>Stops looping-frame capture.</p>
</td>
</tr>
<tr id="row593116713492"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1193187174913"><a name="p1193187174913"></a><a name="p1193187174913"></a>Camera</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1493111713496"><a name="p1493111713496"></a><a name="p1493111713496"></a>int32_t TriggerSingleCapture(FrameConfig&amp; frameConfig)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1193137104919"><a name="p1193137104919"></a><a name="p1193137104919"></a>Starts single-frame capture.</p>
</td>
</tr>
<tr id="row1693112711491"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p89312716494"><a name="p89312716494"></a><a name="p89312716494"></a>CameraConfig</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p199312784912"><a name="p199312784912"></a><a name="p199312784912"></a>void SetFrameStateCallback(FrameStateCallback* callback, EventHandler* handler);</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p49312714495"><a name="p49312714495"></a><a name="p49312714495"></a>Sets a frame state callback to respond to state changes.</p>
</td>
</tr>
<tr id="row9931076492"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p59317784917"><a name="p59317784917"></a><a name="p59317784917"></a>CameraConfig</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p17931197124912"><a name="p17931197124912"></a><a name="p17931197124912"></a>static CameraConfig* CreateCameraConfig()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p5931177164912"><a name="p5931177164912"></a><a name="p5931177164912"></a>Creates a <strong id="b101608165182"><a name="b101608165182"></a><a name="b101608165182"></a>CameraConfig</strong> instance.</p>
</td>
</tr>
<tr id="row29321744917"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1093219716492"><a name="p1093219716492"></a><a name="p1093219716492"></a>CameraAbility</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p12932979493"><a name="p12932979493"></a><a name="p12932979493"></a>std::list&lt;Size&gt; GetSupportedSizes(int format)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1493210764918"><a name="p1493210764918"></a><a name="p1493210764918"></a>Obtains the supported image sizes for a specified image format.</p>
</td>
</tr>
<tr id="row1193267184910"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1393214717492"><a name="p1393214717492"></a><a name="p1393214717492"></a>CameraAbility</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p119321477495"><a name="p119321477495"></a><a name="p119321477495"></a>std::list&lt;T&gt; GetParameterRange(uint32_t key)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p139331079491"><a name="p139331079491"></a><a name="p139331079491"></a>Obtains the parameter value range based on a specified parameter key.</p>
</td>
</tr>
<tr id="row1193267184911"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1393214717492"><a name="p1393214717492"></a><a name="p1393214717492"></a>CameraAbility</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p119321477495"><a name="p119321477495"></a><a name="p119321477495"></a>std::list&lt;int32_t&gt; GetSupportedAfModes() const;</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p139331079491"><a name="p139331079491"></a><a name="p139331079491"></a>Gets a list of supported autofocus modes.</p>
</td>
</tr>
<tr id="row1193267184912"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1393214717492"><a name="p1393214717492"></a><a name="p1393214717492"></a>CameraAbility</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p119321477495"><a name="p119321477495"></a><a name="p119321477495"></a>std::list&lt;int32_t&gt; GetSupportedAeModes() const;</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p139331079491"><a name="p139331079491"></a><a name="p139331079491"></a>Gets a list of supported auto exposure modes.</p>
</td>
</tr>
<tr id="row0933197134920"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1493310764917"><a name="p1493310764917"></a><a name="p1493310764917"></a>CameraDevice</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p493313724915"><a name="p493313724915"></a><a name="p493313724915"></a>CameraDeviceCallback()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p993416724915"><a name="p993416724915"></a><a name="p993416724915"></a>A constructor used to create a <strong id="b99481043111719"><a name="b99481043111719"></a><a name="b99481043111719"></a>CameraDeviceCallback</strong> instance.</p>
</td>
</tr>
<tr id="row093418712498"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p159341779492"><a name="p159341779492"></a><a name="p159341779492"></a>CameraDevice</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1493411774912"><a name="p1493411774912"></a><a name="p1493411774912"></a>void OnCameraStatus​(std::string cameraId, int32_t status)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1393419715491"><a name="p1393419715491"></a><a name="p1393419715491"></a>Called when the camera device status changes.</p>
</td>
</tr>
<tr id="row109348711497"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p993419724914"><a name="p993419724914"></a><a name="p993419724914"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p993418720497"><a name="p993418720497"></a><a name="p993418720497"></a>CameraStateCallback​()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p693511794919"><a name="p693511794919"></a><a name="p693511794919"></a>A constructor used to create a <strong id="b10634201491717"><a name="b10634201491717"></a><a name="b10634201491717"></a>CameraStateCallback</strong> instance.</p>
</td>
</tr>
<tr id="row159358717497"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1992012253527"><a name="p1992012253527"></a><a name="p1992012253527"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p29351077497"><a name="p29351077497"></a><a name="p29351077497"></a>void OnConfigured​(Camera&amp; camera)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p093515774914"><a name="p093515774914"></a><a name="p093515774914"></a>Called when the camera is configured.</p>
</td>
</tr>
<tr id="row9935147184918"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p117291328135211"><a name="p117291328135211"></a><a name="p117291328135211"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p19935174496"><a name="p19935174496"></a><a name="p19935174496"></a>void OnConfigureFailed​(Camera&amp; camera,int32_t errorCode)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p159352077495"><a name="p159352077495"></a><a name="p159352077495"></a>Called when the camera fails to be configured.</p>
</td>
</tr>
<tr id="row1935279498"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1514619311525"><a name="p1514619311525"></a><a name="p1514619311525"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p493512744915"><a name="p493512744915"></a><a name="p493512744915"></a>void OnCreated​(Camera&amp; camera)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1493511784914"><a name="p1493511784914"></a><a name="p1493511784914"></a>Called when the camera is successfully created.</p>
</td>
</tr>
<tr id="row189351877493"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p172071933175218"><a name="p172071933175218"></a><a name="p172071933175218"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p129361977498"><a name="p129361977498"></a><a name="p129361977498"></a>void OnCreateFailed​(std::string cameraId,int32_t errorCode)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p2936197114919"><a name="p2936197114919"></a><a name="p2936197114919"></a>Called when the camera fails to be created.</p>
</td>
</tr>
<tr id="row20936472491"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p61213391523"><a name="p61213391523"></a><a name="p61213391523"></a>CameraStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p793697174919"><a name="p793697174919"></a><a name="p793697174919"></a>void OnReleased​(Camera&amp; camera)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p49361719495"><a name="p49361719495"></a><a name="p49361719495"></a>Called when the camera is released.</p>
</td>
</tr>
<tr id="row159361179493"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p10936147194918"><a name="p10936147194918"></a><a name="p10936147194918"></a>FrameStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p9936279496"><a name="p9936279496"></a><a name="p9936279496"></a>FrameStateCallback​()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p49367718499"><a name="p49367718499"></a><a name="p49367718499"></a>A constructor used to create a <strong id="b225612012172"><a name="b225612012172"></a><a name="b225612012172"></a>FrameStateCallback</strong> instance.</p>
</td>
</tr>
<tr id="row1893617744916"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p136968511524"><a name="p136968511524"></a><a name="p136968511524"></a>FrameStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p209379744911"><a name="p209379744911"></a><a name="p209379744911"></a>void OnFrameFinished(Camera&amp; camera, FrameConfig&amp; frameConfig, FrameResult&amp; frameResult)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p19374724913"><a name="p19374724913"></a><a name="p19374724913"></a>Called when the frame capture is completed.</p>
</td>
</tr>
<tr id="row093719718495"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p772975317527"><a name="p772975317527"></a><a name="p772975317527"></a>FrameStateCallback</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p189371471498"><a name="p189371471498"></a><a name="p189371471498"></a>void OnFrameError​(Camera&amp; camera, FrameConfig&amp; frameConfig, int32_t errorCode, FrameResult&amp; frameResult)</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p109371778497"><a name="p109371778497"></a><a name="p109371778497"></a>Called when the frame capture fails.</p>
</td>
</tr>
<tr id="row179381979499"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p169381975499"><a name="p169381975499"></a><a name="p169381975499"></a>FrameConfig</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1793867124910"><a name="p1793867124910"></a><a name="p1793867124910"></a>int32_t GetFrameConfigType()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1993817744915"><a name="p1993817744915"></a><a name="p1993817744915"></a>Obtains the frame configuration type.</p>
</td>
</tr>
<tr id="row793817784912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p69381724914"><a name="p69381724914"></a><a name="p69381724914"></a>FrameConfig</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p149382077496"><a name="p149382077496"></a><a name="p149382077496"></a>std::list&lt;OHOS::Surface&gt; GetSurfaces()</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p893867114919"><a name="p893867114919"></a><a name="p893867114919"></a>Obtains a list of surface objects (shared memories).</p>
</td>
</tr>
<tr id="row109401570498"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p294019712492"><a name="p294019712492"></a><a name="p294019712492"></a>FrameConfig</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p19940170499"><a name="p19940170499"></a><a name="p19940170499"></a>void AddSurface(OHOS::AGP::UISurface&amp; surface);</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p11940197144915"><a name="p11940197144915"></a><a name="p11940197144915"></a>Adds a surface.</p>
</td>
</tr>
<tr id="row994018711492"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>FrameConfig</p>
</td>
<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>void RemoveSurface(OHOS::AGP::UISurface&amp; surface);</p>
</td>
<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Removes a surface.</p>
</td>
</tr>
<tr id="row994018711493"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>FrameConfig</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>void GetVendorParameter(uint8_t *value, uint32_t len);</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Gets a vendor parameter.</p>
</td>
</tr>
<tr id="row994018711494"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>FrameConfig</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>void SetVendorParameter(uint8_t *value, uint32_t len);</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Sets a vendor parameter.</p>
</td>
</tr>
<tr id="row994018711495"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>CameraInfo</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>int32_t GetCameraType() const;</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Gets a camera type.</p>
</td>
</tr>
<tr id="row994018711496"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>CameraInfo</p>
</td>
<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>int32_t GetCameraFacingType() const;</p>
</td>
<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Gets a camera facing type.</p>
</td>
</tr>
</tbody>
</table>
## Limitations and Constraints<a name="section1165911177314"></a>
None None
## How to Develop<a name="section138543918214"></a>
1. <a name="li378084192111"></a>Extend the **CameraDeviceCallback** class and call **OnCameraStatus** to customize operations when the camera device changes, for example, when a camera becomes available or unavailable.
```
class SampleCameraDeviceCallback : public CameraDeviceCallback {
void OnCameraStatus(std::string cameraId, int32_t status) override
{
// Do something when camera is available or unavailable.
}
};
```
2. <a name="li8716104682913"></a>Extend the **FrameStateCallback** class. After obtaining the frame data, save the data as a file.
```
static void SampleSaveCapture(const char *p, uint32_t size)
{
cout << "Start saving picture" << endl;
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm *ltm = localtime(&tv.tv_sec);
if (ltm != nullptr) {
ostringstream ss("Capture_");
ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg";
ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc);
cout << "write " << size << " bytes" << endl;
pic.write(p, size);
cout << "Saving picture end" << endl;
}
}
class TestFrameStateCallback : public FrameStateCallback {
void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override
{
cout << "Receive frame complete inform." << endl;
if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
cout << "Capture frame received." << endl;
list<Surface *> surfaceList = fc.GetSurfaces();
for (Surface *surface : surfaceList) {
SurfaceBuffer *buffer = surface->AcquireBuffer();
if (buffer != nullptr) {
char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
if (virtAddr != nullptr) {
SampleSaveCapture(virtAddr, buffer->GetSize());
}
surface->ReleaseBuffer(buffer);
}
delete surface;
}
delete &fc;
}
}
};
```
3. <a name="li6671035102514"></a>Extend the **CameraStateCallback** class and customize operations when the camera state changes \(configuration successful or failed, and creation successful or failed\).
```
class SampleCameraStateMng : public CameraStateCallback {
public:
SampleCameraStateMng() = delete;
SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {}
~SampleCameraStateMng()
{
if (recordFd_ != -1) {
close(recordFd_);
}
}
void OnCreated(Camera &c) override
{
cout << "Sample recv OnCreate camera." << endl;
auto config = CameraConfig::CreateCameraConfig();
config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
c.Configure(*config);
cam_ = &c;
}
void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {}
void OnReleased(Camera &c) override {}
};
```
4. Create a **CameraKit** instance to set and obtain camera information.
```
CameraKit *camKit = CameraKit::GetInstance();
list<string> camList = camKit->GetCameraIds();
string camId;
for (auto &cam : camList) {
cout << "camera name:" << cam << endl;
const CameraAbility *ability = camKit->GetCameraAbility(cam);
/* Find the camera that fits your ability. */
list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) {
camId = cam;
break;
}
}
```
5. Create a **Camera** instance.
```
EventHandler eventHdlr; // Create a thread to handle callback events.
SampleCameraStateMng CamStateMng(eventHdlr);
camKit->CreateCamera(camId, CamStateMng, eventHdlr);
```
6. In the main process, synchronize configurations set by callback functions implemented in [step 1](#li378084192111), [step 2](#li8716104682913), and [step 3](#li6671035102514).
```
void OnCreated(Camera &c) override
{
cout << "Sample recv OnCreate camera." << endl;
auto config = CameraConfig::CreateCameraConfig();
config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
c.Configure(*config);
cam_ = &c;
}
void Capture()
{
if (cam_ == nullptr) {
cout << "Camera is not ready." << endl;
return;
}
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
if (surface == nullptr) {
delete fc;
return;
}
surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
fc->AddSurface(*surface);
cam_->TriggerSingleCapture(*fc);
}
```
## How to Develop
1. Implement the **CameraDeviceCallback** class and call **OnCameraStatus** to customize operations when the camera device changes, for example, when a camera becomes available or unavailable.
```
class SampleCameraDeviceCallback : public CameraDeviceCallback {
void OnCameraStatus(std::string cameraId, int32_t status) override
{
//do something when camera is available/unavailable
}
};
```
2. Implement the **FrameStateCallback** class. After obtaining the frame data, save the data as a file.
```
static void SampleSaveCapture(const char *p, uint32_t size)
{
cout << "Start saving picture" << endl;
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm *ltm = localtime(&tv.tv_sec);
if (ltm != nullptr) {
ostringstream ss("Capture_");
ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg";
ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc);
cout << "write " << size << " bytes" << endl;
pic.write(p, size);
cout << "Saving picture end" << endl;
}
}
class TestFrameStateCallback : public FrameStateCallback {
void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override
{
cout << "Receive frame complete inform." << endl;
if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
cout << "Capture frame received." << endl;
list<Surface *> surfaceList = fc.GetSurfaces();
for (Surface *surface : surfaceList) {
SurfaceBuffer *buffer = surface->AcquireBuffer();
if (buffer != nullptr) {
char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
if (virtAddr != nullptr) {
SampleSaveCapture(virtAddr, buffer->GetSize());
}
surface->ReleaseBuffer(buffer);
}
delete surface;
}
delete &fc;
}
}
};
```
3. Implement the **CameraStateCallback** class and customize operations when the camera state changes (configuration successful or failed, and creation successful or failed).
```
class SampleCameraStateMng : public CameraStateCallback {
public:
SampleCameraStateMng() = delete;
SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {}
~SampleCameraStateMng()
{
if (recordFd_ != -1) {
close(recordFd_);
}
}
void OnCreated(Camera &c) override
{
cout << "Sample recv OnCreate camera." << endl;
auto config = CameraConfig::CreateCameraConfig();
config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
c.Configure(*config);
cam_ = &c;
}
void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {}
void OnReleased(Camera &c) override {}
};
```
4. Create a **CameraKit** instance to set and obtain camera information.
```
CameraKit *camKit = CameraKit::GetInstance();
list<string> camList = camKit->GetCameraIds();
string camId;
for (auto &cam : camList) {
cout << "camera name:" << cam << endl;
const CameraAbility *ability = camKit->GetCameraAbility(cam);
/* find camera which fits user's ability */
list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) {
camId = cam;
break;
}
}
```
5. Create a **Camera** instance.
```
EventHandler eventHdlr; // Create a thread to handle callback events
SampleCameraStateMng CamStateMng(eventHdlr);
camKit->CreateCamera(camId, CamStateMng, eventHdlr);
```
6. Based on the callback design in steps 1, 2, and 3, perform related operations until the **OnCreated** callback obtains **cam_**.
```
void OnCreated(Camera &c) override
{
cout << "Sample recv OnCreate camera." << endl;
auto config = CameraConfig::CreateCameraConfig();
config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
c.Configure(*config);
cam_ = &c;
}
void Capture()
{
if (cam_ == nullptr) {
cout << "Camera is not ready." << endl;
return;
}
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
if (surface == nullptr) {
delete fc;
return;
}
surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
fc->AddSurface(*surface);
cam_->TriggerSingleCapture(*fc);
}
```
# Previewing Development<a name="EN-US_TOPIC_0000001051930577"></a> # Previewing Development
## When to Use<a name="section186634310418"></a>
Use the camera module APIs to generate and play video streams. ## When to Use
## Available APIs<a name="section125479541744"></a>
For details, see the available APIs described in development guidelines on photographing.
## Limitations and Constraints<a name="section1165911177314"></a> Use the camera module APIs to generate and play video streams.
None
## How to Develop<a name="section34171333656"></a> ## Available APIs
1. Perform step 1 through step 4 described in development guidelines on photographing. For details, see [Available APIs](subsys-multimedia-camera-photo-guide.md#available-apis).
2. Set the preview area.
```
Surface *surface = Surface::CreateSurface();
/* Set the display area. */
surface->SetUserData("region_position_x", "480"); // X-coordinate of the upper left corner of the rectangle
surface->SetUserData("region_position_y", "270"); // Y-coordinate of the upper left corner of the rectangle
surface->SetUserData("region_width", "960"); // Width
surface->SetUserData("region_height", "540"); // Height
fc->AddSurface(*surface);
```
3. Start and stop previewing. ## Constraints
``` None
stateCallback->camera_->TriggerLoopingCapture(*fc); // Start previewing.
stateCallback->camera_->StopLoopingCapture(); // Stop previewing.
```
## How to Develop
1. Perform step 1 through step 4 described in [Photographing Development](subsys-multimedia-camera-photo-guide.md).
2. Set the preview area.
```
Surface *surface = Surface::CreateSurface();
/* Set the display area. */
surface->SetUserData("region_position_x", "480"); // X-coordinate of the upper left corner of the rectangle.
surface->SetUserData("region_position_y", "270"); // Y-coordinate of the upper left corner of the rectangle.
surface->SetUserData("region_width", "960"); // Width.
surface->SetUserData("region_height", "540"); // Height.
fc->AddSurface(*surface);
```
3. Start and stop previewing.
```
stateCallback->camera_->TriggerLoopingCapture(*fc); // Start previewing.
stateCallback->camera_->StopLoopingCapture(); // Stop previewing.
```
# Video Recording Development<a name="EN-US_TOPIC_0000001051451869"></a> # Video Recording Development
## When to Use<a name="section186634310418"></a>
Use the camera module APIs to capture video streams. ## When to Use
## Available APIs<a name="section125479541744"></a>
For details, see the available APIs described in development guidelines on photographing.
## Limitations and Constraints<a name="section1165911177314"></a> Use the camera module APIs to capture video streams.
None
## How to Develop<a name="section1196016315516"></a> ## Available APIs
1. Perform step 1 through step 4 described in development guidelines on photographing. For details, see [Available APIs](subsys-multimedia-camera-photo-guide.md#available-apis).
2. Obtain the **FrameConfig** instance for audio recording.
```
/* Obtain the surface from the recorder. */
Surface *surface = recorder_->GetSurface(0);
surface->SetWidthAndHeight(1920, 1080);
surface->SetQueueSize(3);
surface->SetSize(1024 * 1024);
/* Add the surface to the FrameConfig instance. */
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD);
fc->AddSurface(*surface);
```
3. Start and stop video recording. ## Constraints
``` None
stateCallback->camera_->TriggerLoopingCapture(*fc); // Start recording.
stateCallback->camera_->StopLoopingCapture(); // Stop recording.
```
## How to Develop
1. Perform step 1 through step 4 described in [Photographing Development](subsys-multimedia-camera-photo-guide.md).
2. Obtain the **FrameConfig** instance for video recording.
```
/* Obtain the surface from the recorder. */
Surface *surface = recorder_->GetSurface(0);
surface->SetWidthAndHeight(1920, 1080);
surface->SetQueueSize(3);
surface->SetSize(1024 * 1024);
/* Add the surface to the FrameConfig instance. */
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD);
fc->AddSurface(*surface);
```
3. Start and stop video recording.
```
stateCallback->camera_->TriggerLoopingCapture(*fc); // Start recording.
stateCallback->camera_->StopLoopingCapture(); // Stop recording.
```
# Audio/Video Overview # Audio/Video Overview
OpenHarmony multimedia services help you to develop for audio and video playback and recording.
- The media playback module facilitates the development of audio and video playback, including media file and stream playback, volume control, and playback progress control. OpenHarmony multimedia services help you to develop audio and video playback and recording.
- The media recording module supports the development of audio and video recording and provides functions to set the size of captured video, encoding bit rate, encoder type, video frame rate, audio sampling rate, and output file format.
## Basic Concepts
It is considered good practice that you understand the following concepts before starting development: - The media playback module facilitates the development of audio and video playback, including media file and stream playback, volume control, and playback progress control.
- Streaming media technology - The media recording module supports the development of audio and video recording and provides functions to set the size of captured video, encoding bit rate, encoder type, video frame rate, audio sampling rate, and output file format.
The streaming media technology refers to a process to encode continuous video and audio data and store the data on a network server. A viewer can watch and listen to the video and audio during download with no need to wait for the completion of download.
## Basic Concepts
It is considered good practice that you understand the following concepts before starting development:
- Video frame rate - Streaming media technology
The frame rate is used to measure the number of displayed frames, which is the number of images transmitted per second. The more frames per second \(FPS\), the smoother the video. The streaming media technology refers to a process to encode continuous video and audio data and store the data on a network server. A viewer can watch and listen to the video and audio during download with no need to wait for the completion of download.
- Bit rate - Video frame rate
The frame rate is used to measure the number of displayed frames, which is the number of images transmitted per second. The more frames per second (FPS), the smoother the video.
Bit rate is the number of bits transmitted per unit of time. The commonly used unit is kbit/s. - Bit rate
- Sampling rate Bit rate is the number of bits transmitted per unit of time. The commonly used unit is kbit/s.
The sampling rate is the number of samples per second taken from continuous signals to form discrete signals. The unit is hertz \(Hz\). - Sampling rate
The sampling rate is the number of samples per second taken from continuous signals to form discrete signals. The unit is hertz (Hz).
## Encoding and Decoding
Available audio and video encoding and decoding capabilities vary depending on device types. The following table lists supported specifications for available development boards. ## Codec Specifications
**Table 1** Encoding and decoding specifications for different development boards Available audio and video codecs vary depending on device types. The following table lists supported specifications for available development boards.
| Device Type | Development Board | Decoding | Encoding | **Table 1** Codec specifications for different development boards
| ------------------------ | ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| Cameras with a screen | Hi3516 | - Audio: MPEG-4 AAC Profile (AAC LC), MPEG Audio Layer 3 (MP3), mono and dual channels, MPEG-4 (.mp4 and .m4a), and MP3 (.mp3) are supported.<br>- Video: The H.265 (HEVC) and H.264 (AVC) (for streams encoded using a chip of the same type) and the MPEG-4 (.mp4) container format are supported. | - Audio: AAC-LC encoding, mono and dual channels, and the MPEG-4 (.mp4) container format are supported.<br/>- Video: H.264 and H.265 encoding and the MPEG-4 (.mp4) container format are supported.</li></ul> |
| Cameras without a screen | Hi3518 | - Audio: MPEG-4 AAC Profile (AAC LC), MPEG Audio Layer 3 (MP3), mono and dual channels, MPEG-4 (.mp4 and .m4a), and MP3 (.mp3) are supported.<br/>- Video: none | <ul><li>Audio: AAC-LC encoding, mono and dual channels, and the MPEG-4 (.mp4) container format are supported.<br/>- Video: H.264 and H.265 encoding and the MPEG-4 (.mp4) container format are supported. |
| WLAN connecting devices | Hi3861 | N/A | N/A |
For details about the encoding and decoding specifications of Hi3516 and Hi3518, refer to their documentation. | Device Type| Development Board| Decoding| Encoding|
| -------- | -------- | -------- | -------- |
| Cameras with a screen| Hi3516 | - Audio: MPEG-4 AAC Profile (AAC LC), mono and dual channels, MPEG-4 (.mp4 and .m4a) <br>- Video: The H.265 (HEVC) and H.264 (AVC) (for streams encoded using a chip of the same type) and the MPEG-4 (.mp4) container format are supported.| - Audio: AAC-LC encoding, mono and dual channels, and the MPEG-4 (.mp4) container format are supported.<br>- Video: H.264 and H.265 encoding and the MPEG-4 (.mp4) container format are supported.|
| Cameras without a screen| Hi3518 | - Audio: MPEG-4 AAC Profile (AAC LC), mono and dual channels, and the MPEG-4 (.mp4 and .m4a) container format are supported.<br>- Video: none| - Audio: AAC-LC encoding, mono and dual channels, and the MPEG-4 (.mp4) container format are supported.<br>- Video: H.264 and H.265 encoding and the MPEG-4 (.mp4) container format are supported.|
| WLAN connecting devices| Hi3861 | N/A| N/A|
For details about the codec specifications of Hi3516 and Hi3518, refer to their documentation.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册