1e41f4b71Sopenharmony_ci# Camera Overview
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Basic Concepts
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciCamera 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.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciIt is considered good practice that you understand the following concepts before starting development:
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci- Video frame
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci  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.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci- Frames per second (FPS)
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci  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.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci- Resolution
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci  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.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## Working Principles
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci- Multimedia services
26e41f4b71Sopenharmony_ci  
27e41f4b71Sopenharmony_ci  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:
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci  - Memory pool: Memory blocks in the memory pool are accessed and released continuously by all multimedia services.
30e41f4b71Sopenharmony_ci  - Image sensor: sensor type, resolution, ISP, and more.
31e41f4b71Sopenharmony_ci  - Image processor: resolution, bit rate, image inversion, and more.
32e41f4b71Sopenharmony_ci  - Image encoder: encoding format, bit rate, resolution, and more.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci- Major classes
35e41f4b71Sopenharmony_ci    
36e41f4b71Sopenharmony_ci  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.
37e41f4b71Sopenharmony_ci    
38e41f4b71Sopenharmony_ci  **Table 1** Class description
39e41f4b71Sopenharmony_ci  
40e41f4b71Sopenharmony_ci  | Class| Description| Example| 
41e41f4b71Sopenharmony_ci  | -------- | -------- | -------- |
42e41f4b71Sopenharmony_ci  | Camera | Configures the static camera capability through the configuration class to use basic camera functionalities.| Photographing, video recording, and previewing| 
43e41f4b71Sopenharmony_ci  | CameraDeviceCallback | Handles camera hardware state changes.| Available/Unavailable| 
44e41f4b71Sopenharmony_ci  | CameraStateCallback | Handles camera instance state changes.| Created or released| 
45e41f4b71Sopenharmony_ci  | FrameStateCallback | Handles frame status changes.| Start and end of photographing, and frame rate changes| 
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci- Stream transfer
48e41f4b71Sopenharmony_ci  
49e41f4b71Sopenharmony_ci  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.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci  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.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci  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.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci  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.
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci  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).
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci- Camera running process
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci  1. Creating a camera
62e41f4b71Sopenharmony_ci      
63e41f4b71Sopenharmony_ci     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.
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci     **Figure 1** Sequence diagram for creating a camera
66e41f4b71Sopenharmony_ci     
67e41f4b71Sopenharmony_ci     ![en-us_image_0000001200114819](figures/en-us_image_0000001200114819.png)
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci  2. Taking a video/Previewing
70e41f4b71Sopenharmony_ci      
71e41f4b71Sopenharmony_ci     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.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci     **Figure 2** Sequence diagram for recording/previewing
74e41f4b71Sopenharmony_ci     
75e41f4b71Sopenharmony_ci     ![en-us_image_0000001200115193](figures/en-us_image_0000001200115193.png)
76