H.264 Codec for ESP32-S3
Loading...
Searching...
No Matches
esp_h264_enc_single.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#pragma once
8
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/**
17 * @brief H.264 single stream encoder handle
18 */
20
21/**
22 * @brief The H.264 single stream encoder interface
23 */
24typedef struct esp_h264_enc_if {
25 esp_h264_err_t (*open)(esp_h264_enc_handle_t enc); /*<! The open function */
26 esp_h264_err_t (*process)(esp_h264_enc_handle_t enc, esp_h264_enc_in_frame_t *in_frame,
27 esp_h264_enc_out_frame_t *out_frame); /*<! The process function */
28 esp_h264_err_t (*close)(esp_h264_enc_handle_t enc); /*<! The close function */
29 esp_h264_err_t (*del)(esp_h264_enc_handle_t enc); /*<! The delete function */
30} esp_h264_enc_t;
31
32/**
33 * @brief This function opens an H.264 encoder in single stream
34 *
35 * @param[in] enc A pointer to the H.264 encoder instance
36 *
37 * @return
38 * - ESP_H264_ERR_OK Succeeded
39 * - ESP_H264_ERR_FAIL Failed
40 * - ESP_H264_ERR_ARG Invalid arguments passed
41 * - ESP_H264_ERR_UNSUPPORTED Open feature is not supported by the encoder
42 */
44
45/**
46 * @brief This function performs single encoding of H.264 video frames.
47 * To encode one image using an image encoder, the IDR frame will automatically add SPS and PPS NALU.
48 *
49 * @note The function will return ESP_H264_ERR_TIMEOUT if `out_frame.raw_data.len` is less than actual encoded data length using hardware encoder.
50 * If the width or height of image is not multi of 16, please do the follow operation.
51 * `width = ((width +15) >> 4 << 4);`
52 * `height = ((height+15) >> 4 << 4);`
53 * `in_frame.raw_data.len = ( width * height + (width * height >> 1));`
54 * `in_frame.raw_data.buffer = esp_h264_aligned_calloc(16, 1, in_frame.raw_data.len, &in_frame.raw_data.len, MALLOC_CAP_DEFAULT);`
55 * The `out_frame.raw_data.buffer` should be allocated by the user for in_frame.raw_data.len bytes to avoid the encoded image size exceeding the `out_frame.raw_data.buffer` size.
56 * If the encoder image size is larger than `out_frame.raw_data.buffer`, it will result in ESP_H264_ERR_MEM.
57 *
58 * @param[in] enc A pointer to the H.264 encoder instance
59 * @param[in] in_frame A pointer to unencoded input frame
60 * @param[in/out] out_frame A pointer to encoded output frame
61 *
62 * @return
63 * - ESP_H264_ERR_OK Succeeded
64 * - ESP_H264_ERR_ARG Invalid arguments passed
65 * - ESP_H264_ERR_MEM Insufficient memory
66 * - ESP_H264_ERR_FAIL Failed
67 * - ESP_H264_ERR_TIMEOUT Timeout
68 * - ESP_H264_ERR_OVERFLOW The size of encoder image is greater than `in_frame.raw_data.len`
69 * - ESP_H264_ERR_UNSUPPORTED Process feature is not supported by the encoder
70 *
71 */
72esp_h264_err_t esp_h264_enc_process(esp_h264_enc_handle_t enc, esp_h264_enc_in_frame_t *in_frame, esp_h264_enc_out_frame_t *out_frame);
73
74/**
75 * @brief This function closes the H.264 encoder instance specified by `enc`
76 *
77 * @param[in] enc A pointer to the H.264 encoder instance
78 *
79 * @return
80 * - ESP_H264_ERR_OK Succeeded
81 * - ESP_H264_ERR_ARG Invalid arguments passed
82 * - ESP_H264_ERR_UNSUPPORTED Close feature is not supported by the encoder
83 */
85
86/**
87 * @brief This function is used to delete an H.264 encoder
88 *
89 * @param[in] enc A pointer to the H.264 encoder instance
90 *
91 * @return
92 * - ESP_H264_ERR_OK Succeeded
93 * - ESP_H264_ERR_ARG Invalid arguments passed
94 * - ESP_H264_ERR_UNSUPPORTED Delete feature is not supported by the encoder
95 */
96esp_h264_err_t esp_h264_enc_del(esp_h264_enc_handle_t enc);
97
98#ifdef __cplusplus
99}
100#endif
esp_h264_err_t esp_h264_enc_close(esp_h264_enc_handle_t enc)
This function closes the H.264 encoder instance specified by enc
Definition: esp_h264_enc_single.c:28
esp_h264_err_t esp_h264_enc_open(esp_h264_enc_handle_t enc)
This function opens an H.264 encoder in single stream.
Definition: esp_h264_enc_single.c:12
esp_h264_err_t esp_h264_enc_process(esp_h264_enc_handle_t enc, esp_h264_enc_in_frame_t *in_frame, esp_h264_enc_out_frame_t *out_frame)
This function performs single encoding of H.264 video frames. To encode one image using an image enco...
Definition: esp_h264_enc_single.c:19
esp_h264_err_t esp_h264_enc_del(esp_h264_enc_handle_t enc)
This function is used to delete an H.264 encoder.
Definition: esp_h264_enc_single.c:35
struct esp_h264_enc_if * esp_h264_enc_handle_t
H.264 single stream encoder handle.
Definition: esp_h264_enc_single.h:19
The H.264 single stream encoder interface.
Definition: esp_h264_enc_single.h:24