Skip to content

Commit 673b037

Browse files
committed
Restructure and moved media APIs to app_common
- These are re-used from streaming_only and webrtc_classic examples
1 parent 369c3a9 commit 673b037

File tree

10 files changed

+732
-501
lines changed

10 files changed

+732
-501
lines changed

esp_port/components/media_stream/src/audio_capture_adapter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ esp_err_t audio_capture_release_frame(audio_capture_handle_t handle, audio_frame
110110
return ESP_ERR_INVALID_ARG;
111111
}
112112

113-
// In the current implementation, we don't need to release the buffer
114-
// but we should free the frame structure we allocated
113+
if (frame->buffer != NULL) {
114+
free(frame->buffer);
115+
}
115116
free(frame);
116117
return ESP_OK;
117118
}

esp_port/components/media_stream/src/video_capture_adapter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ esp_err_t video_capture_release_frame(video_capture_handle_t handle, video_frame
125125
return ESP_ERR_INVALID_ARG;
126126
}
127127

128-
// In the current implementation, we don't need to release the buffer
129-
// but we should free the frame structure we allocated
128+
if (frame->buffer != NULL) {
129+
free(frame->buffer);
130+
}
130131
free(frame);
131132
return ESP_OK;
132133
}

esp_port/examples/app_common/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
set(srcs "src/app_wifi.c" "src/app_storage.c" "src/sample_config.c")
1+
set(srcs "src/app_wifi.c" "src/app_storage.c" "src/sample_config.c" "src/app_media.c")
22

3-
set(requires esp_wifi fatfs spiffs)
3+
set(requires esp_wifi fatfs spiffs media_stream)
44

55
idf_component_register(SRCS "${srcs}"
66
REQUIRES ${requires}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

esp_port/examples/app_common/include/sample_config.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ extern "C" {
1212

1313
#include <com/amazonaws/kinesis/video/webrtcclient/Include.h>
1414

15-
#define NUMBER_OF_H264_FRAME_FILES 60 //1500
16-
#define NUMBER_OF_H265_FRAME_FILES 1500
17-
#define NUMBER_OF_OPUS_FRAME_FILES 618
18-
#define DEFAULT_FPS_VALUE 25
19-
#define DEFAULT_VIDEO_HEIGHT_PIXELS 720
20-
#define DEFAULT_VIDEO_WIDTH_PIXELS 1280
21-
#define DEFAULT_AUDIO_OPUS_CHANNELS 2
22-
#define DEFAULT_AUDIO_OPUS_SAMPLE_RATE_HZ 48000
23-
#define DEFAULT_AUDIO_OPUS_BITS_PER_SAMPLE 16
2415
#define DEFAULT_MAX_CONCURRENT_STREAMING_SESSION 2
2516

2617
#define AUDIO_CODEC_NAME_ALAW "alaw"
@@ -34,11 +25,7 @@ extern "C" {
3425
#define SAMPLE_VIEWER_CLIENT_ID "ConsumerViewer"
3526
#define SAMPLE_CHANNEL_NAME (PCHAR) "ScaryTestChannel"
3627

37-
#define DEFAULT_AUDIO_OPUS_BYTE_RATE (DEFAULT_AUDIO_OPUS_SAMPLE_RATE_HZ * DEFAULT_AUDIO_OPUS_CHANNELS * DEFAULT_AUDIO_OPUS_BITS_PER_SAMPLE) / 8
38-
39-
#define SAMPLE_AUDIO_FRAME_DURATION (20 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
4028
#define SAMPLE_STATS_DURATION (60 * HUNDREDS_OF_NANOS_IN_A_SECOND)
41-
#define SAMPLE_VIDEO_FRAME_DURATION (HUNDREDS_OF_NANOS_IN_A_SECOND / DEFAULT_FPS_VALUE)
4229

4330
#define SAMPLE_PRE_GENERATE_CERT TRUE
4431
#define SAMPLE_PRE_GENERATE_CERT_PERIOD (1000 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)

0 commit comments

Comments
 (0)