|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @brief Common media streaming functions for WebRTC examples |
| 9 | + */ |
| 10 | + |
| 11 | +#pragma once |
| 12 | + |
| 13 | +#include <stdint.h> |
| 14 | +#include <stdbool.h> |
| 15 | +#include "esp_err.h" |
| 16 | +#include "audio_capture.h" |
| 17 | +#include "video_capture.h" |
| 18 | +#include "audio_player.h" |
| 19 | +#include "video_player.h" |
| 20 | +#include "com/amazonaws/kinesis/video/webrtcclient/Include.h" |
| 21 | + |
| 22 | +#ifdef __cplusplus |
| 23 | +extern "C" { |
| 24 | +#endif |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Initialize video and audio handles with default configurations |
| 28 | + * |
| 29 | + * @param video_handle Pointer to store the video handle |
| 30 | + * @param audio_handle Pointer to store the audio handle |
| 31 | + * @return esp_err_t ESP_OK on success |
| 32 | + */ |
| 33 | +esp_err_t app_media_init(video_capture_handle_t *video_handle, audio_capture_handle_t *audio_handle); |
| 34 | + |
| 35 | +/** |
| 36 | + * @brief Start media capture (video and audio) |
| 37 | + * |
| 38 | + * @param video_handle Video capture handle |
| 39 | + * @param audio_handle Audio capture handle |
| 40 | + * @return esp_err_t ESP_OK on success |
| 41 | + */ |
| 42 | +esp_err_t app_media_start(video_capture_handle_t video_handle, audio_capture_handle_t audio_handle); |
| 43 | + |
| 44 | +/** |
| 45 | + * @brief Stop media capture (video and audio) |
| 46 | + * |
| 47 | + * @param video_handle Video capture handle |
| 48 | + * @param audio_handle Audio capture handle |
| 49 | + * @return esp_err_t ESP_OK on success |
| 50 | + */ |
| 51 | +esp_err_t app_media_stop(video_capture_handle_t video_handle, audio_capture_handle_t audio_handle); |
| 52 | + |
| 53 | +/** |
| 54 | + * @brief Send video packets thread function for WebRTC |
| 55 | + * |
| 56 | + * @param args PSampleConfiguration pointer |
| 57 | + * @return PVOID Status code |
| 58 | + */ |
| 59 | +PVOID sendMediaStreamVideoPackets(PVOID args); |
| 60 | + |
| 61 | +/** |
| 62 | + * @brief Send audio packets thread function for WebRTC |
| 63 | + * |
| 64 | + * @param args PSampleConfiguration pointer |
| 65 | + * @return PVOID Status code |
| 66 | + */ |
| 67 | +PVOID sendMediaStreamAudioPackets(PVOID args); |
| 68 | + |
| 69 | +/** |
| 70 | + * @brief Handler for received video frames |
| 71 | + * |
| 72 | + * @param customData User-defined data |
| 73 | + * @param pFrame Received video frame |
| 74 | + */ |
| 75 | +VOID appMediaVideoFrameHandler(UINT64 customData, PFrame pFrame); |
| 76 | + |
| 77 | +/** |
| 78 | + * @brief Handler for received audio frames |
| 79 | + * |
| 80 | + * @param customData User-defined data |
| 81 | + * @param pFrame Received audio frame |
| 82 | + */ |
| 83 | +VOID appMediaAudioFrameHandler(UINT64 customData, PFrame pFrame); |
| 84 | + |
| 85 | +/** |
| 86 | + * @brief Clean up media resources |
| 87 | + * |
| 88 | + * @param video_handle Video capture handle |
| 89 | + * @param audio_handle Audio capture handle |
| 90 | + * @return esp_err_t ESP_OK on success |
| 91 | + */ |
| 92 | +esp_err_t app_media_deinit(video_capture_handle_t video_handle, audio_capture_handle_t audio_handle); |
| 93 | + |
| 94 | +/** |
| 95 | + * @brief Read a media frame from disk |
| 96 | + * |
| 97 | + * @param pFrame Buffer to store the frame data |
| 98 | + * @param pSize Pointer to size of buffer (in) and actual size read (out) |
| 99 | + * @param frameFilePath Path to the frame file |
| 100 | + * @return STATUS STATUS_SUCCESS on success, otherwise an error code |
| 101 | + */ |
| 102 | +STATUS app_media_read_frame_from_disk(PBYTE pFrame, PUINT32 pSize, PCHAR frameFilePath); |
| 103 | + |
| 104 | +/** |
| 105 | + * @brief Send video packets from sample files |
| 106 | + * |
| 107 | + * @param args PSampleConfiguration pointer |
| 108 | + * @return PVOID Status code |
| 109 | + */ |
| 110 | +PVOID sendFileVideoPackets(PVOID args); |
| 111 | + |
| 112 | +/** |
| 113 | + * @brief Send audio packets from sample files |
| 114 | + * |
| 115 | + * @param args PSampleConfiguration pointer |
| 116 | + * @return PVOID Status code |
| 117 | + */ |
| 118 | +PVOID sendFileAudioPackets(PVOID args); |
| 119 | + |
| 120 | +#ifdef __cplusplus |
| 121 | +} |
| 122 | +#endif |
0 commit comments