Skip to content

Commit

Permalink
Merge pull request #116 from Sean-Der/clang-format
Browse files Browse the repository at this point in the history
Add .clang-format to project
  • Loading branch information
sepfy authored Sep 1, 2024
2 parents 68b3c5a + dfd7c24 commit dfb7f4c
Show file tree
Hide file tree
Showing 54 changed files with 1,233 additions and 1,677 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Chromium
ColumnLimit: 0
19 changes: 19 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: clang-format Check
on: [push, pull_request]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'examples'
- 'src'
- 'tests'
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected]
with:
clang-format-version: '17'
check-path: ${{ matrix.path }}
68 changes: 28 additions & 40 deletions examples/esp32/main/app_main.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/param.h>
#include "esp_system.h"
#include "esp_partition.h"
#include "nvs_flash.h"
#include <sys/time.h>
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_mac.h"
#include "mdns.h"
#include "esp_log.h"
#include "esp_tls.h"
#include "esp_mac.h"
#include "esp_netif.h"
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "esp_system.h"
#include "esp_tls.h"
#include "freertos/FreeRTOS.h"
#include "mdns.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"

#include "peer.h"

static const char *TAG = "webrtc";
static const char* TAG = "webrtc";

static TaskHandle_t xPcTaskHandle = NULL;
static TaskHandle_t xPsTaskHandle = NULL;
Expand All @@ -28,24 +28,22 @@ static TaskHandle_t xAudioTaskHandle = NULL;

extern esp_err_t camera_init();
extern esp_err_t audio_init();
extern void camera_task(void *pvParameters);
extern void audio_task(void *pvParameters);
extern void camera_task(void* pvParameters);
extern void audio_task(void* pvParameters);

SemaphoreHandle_t xSemaphore = NULL;

PeerConnection *g_pc;
PeerConnection* g_pc;
PeerConnectionState eState = PEER_CONNECTION_CLOSED;
int gDataChannelOpened = 0;

int64_t get_timestamp() {

struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000LL + (tv.tv_usec / 1000LL));
}

static void oniceconnectionstatechange(PeerConnectionState state, void *user_data) {

static void oniceconnectionstatechange(PeerConnectionState state, void* user_data) {
ESP_LOGI(TAG, "PeerConnectionState: %d", state);
eState = state;
// not support datachannel close event
Expand All @@ -54,60 +52,50 @@ static void oniceconnectionstatechange(PeerConnectionState state, void *user_dat
}
}

static void onmessage(char *msg, size_t len, void *userdata, uint16_t sid) {

static void onmessage(char* msg, size_t len, void* userdata, uint16_t sid) {
ESP_LOGI(TAG, "Datachannel message: %.*s", len, msg);
}

void onopen(void *userdata) {

void onopen(void* userdata) {
ESP_LOGI(TAG, "Datachannel opened");
gDataChannelOpened = 1;
}

static void onclose(void *userdata) {

static void onclose(void* userdata) {
}

void peer_signaling_task(void *arg) {

void peer_signaling_task(void* arg) {
ESP_LOGI(TAG, "peer_signaling_task started");

for(;;) {

for (;;) {
peer_signaling_loop();

vTaskDelay(pdMS_TO_TICKS(10));
}

}

void peer_connection_task(void *arg) {

void peer_connection_task(void* arg) {
ESP_LOGI(TAG, "peer_connection_task started");

for(;;) {

for (;;) {
if (xSemaphoreTake(xSemaphore, portMAX_DELAY)) {
peer_connection_loop(g_pc);
xSemaphoreGive(xSemaphore);
peer_connection_loop(g_pc);
xSemaphoreGive(xSemaphore);
}

vTaskDelay(pdMS_TO_TICKS(1));
}
}

void app_main(void) {

static char deviceid[32] = {0};
uint8_t mac[8] = {0};

PeerConfiguration config = {
.ice_servers = {
{ .urls = "stun:stun.l.google.com:19302" }
},
.audio_codec = CODEC_PCMA,
.datachannel = DATA_CHANNEL_BINARY,
.ice_servers = {
{.urls = "stun:stun.l.google.com:19302"}},
.audio_codec = CODEC_PCMA,
.datachannel = DATA_CHANNEL_BINARY,
};

ESP_LOGI(TAG, "[APP] Startup..");
Expand Down
54 changes: 21 additions & 33 deletions examples/esp32/main/audio.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
#include "driver/i2s_pdm.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/i2s_pdm.h"

#include "esp_audio_enc.h"
#include "esp_audio_enc_default.h"
#include "esp_audio_enc_reg.h"
#include "esp_g711_enc.h"
#include "esp_audio_enc.h"

#include "peer_connection.h"

#define I2S_CLK_GPIO 42
#define I2S_DATA_GPIO 41

static const char *TAG = "AUDIO";
static const char* TAG = "AUDIO";

extern PeerConnection *g_pc;
extern PeerConnection* g_pc;
extern PeerConnectionState eState;
extern int get_timestamp();

i2s_chan_handle_t rx_handle = NULL;

esp_audio_enc_handle_t enc_handle = NULL;
esp_audio_enc_in_frame_t aenc_in_frame = { 0 };
esp_audio_enc_out_frame_t aenc_out_frame = { 0 };
esp_audio_enc_in_frame_t aenc_in_frame = {0};
esp_audio_enc_out_frame_t aenc_out_frame = {0};
esp_g711_enc_config_t g711_cfg;
esp_audio_enc_config_t enc_cfg;

esp_err_t audio_codec_init() {

uint8_t *read_buf = NULL;
uint8_t *write_buf = NULL;
uint8_t* read_buf = NULL;
uint8_t* write_buf = NULL;
int read_size = 0;
int out_size = 0;

Expand Down Expand Up @@ -77,20 +76,19 @@ esp_err_t audio_codec_init() {
}

esp_err_t audio_init(void) {

i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, NULL, &rx_handle));

i2s_pdm_rx_config_t pdm_rx_cfg = {
.clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(8000),
.slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
.gpio_cfg = {
.clk = I2S_CLK_GPIO,
.din = I2S_DATA_GPIO,
.invert_flags = {
.clk_inv = false,
},
},
.clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(8000),
.slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
.gpio_cfg = {
.clk = I2S_CLK_GPIO,
.din = I2S_DATA_GPIO,
.invert_flags = {
.clk_inv = false,
},
},
};

ESP_ERROR_CHECK(i2s_channel_init_pdm_rx_mode(rx_handle, &pdm_rx_cfg));
Expand All @@ -100,24 +98,21 @@ esp_err_t audio_init(void) {
}

void audio_deinit(void) {

ESP_ERROR_CHECK(i2s_channel_disable(rx_handle));
ESP_ERROR_CHECK(i2s_del_channel(rx_handle));
}

int32_t audio_get_samples(uint8_t *buf, size_t size) {

int32_t audio_get_samples(uint8_t* buf, size_t size) {
size_t bytes_read;

if (i2s_channel_read(rx_handle, (char *)buf, size, &bytes_read, 1000) != ESP_OK) {
if (i2s_channel_read(rx_handle, (char*)buf, size, &bytes_read, 1000) != ESP_OK) {
ESP_LOGE(TAG, "i2s read error");
}

return bytes_read;
}

void audio_task(void *arg) {

void audio_task(void* arg) {
int ret;
static int64_t last_time;
int64_t curr_time;
Expand All @@ -127,20 +122,15 @@ void audio_task(void *arg) {
ESP_LOGI(TAG, "audio task started");

for (;;) {

if (eState == PEER_CONNECTION_COMPLETED) {

ret = audio_get_samples(aenc_in_frame.buffer, aenc_in_frame.len);

if (ret == aenc_in_frame.len) {

if (esp_audio_enc_process(enc_handle, &aenc_in_frame, &aenc_out_frame) == ESP_AUDIO_ERR_OK) {

peer_connection_send_audio(g_pc, aenc_out_frame.buffer, aenc_out_frame.encoded_bytes);

bytes += aenc_out_frame.encoded_bytes;
if (bytes > 50000) {

curr_time = get_timestamp();
ESP_LOGI(TAG, "audio bitrate: %.1f bps", 1000.0 * (bytes * 8.0 / (float)(curr_time - last_time)));
last_time = curr_time;
Expand All @@ -151,9 +141,7 @@ void audio_task(void *arg) {
vTaskDelay(pdMS_TO_TICKS(5));

} else {

vTaskDelay(pdMS_TO_TICKS(100));
}
}
}

Loading

0 comments on commit dfb7f4c

Please sign in to comment.