Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: support for saving audio to file in sample #1020

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/app_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ struct st_app_rx_st30p_session {

uint8_t num_port;
uint64_t last_stat_time_ns;
char st30p_destination_url[ST_APP_URL_MAX_LEN];
FILE* st30p_destination_file;

/* stat */
int stat_frame_received;
Expand Down
5 changes: 5 additions & 0 deletions app/src/rx_st20p_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ static int app_rx_st20p_uinit(struct st_app_rx_st20p_session* s) {
s->handle = NULL;
}

if (s->st20p_destination_file) {
fclose(s->st20p_destination_file);
s->st20p_destination_file = NULL;
}

return 0;
}

Expand Down
28 changes: 24 additions & 4 deletions app/src/rx_st30p_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

static void app_rx_st30p_consume_frame(struct st_app_rx_st30p_session* s,
struct st30_frame* frame) {
// int idx = s->idx;
// todo
MTL_MAY_UNUSED(s);
MTL_MAY_UNUSED(frame);
int idx = s->idx;

if (s->st30p_destination_file) {
if (!fwrite(frame->addr, 1, s->st30p_frame_size, s->st30p_destination_file)) {
err("%s(%d), failed to write frame to file %s\n", __func__, idx,
s->st30p_destination_url);
}
}
}

static void* app_rx_st30p_frame_thread(void* arg) {
Expand Down Expand Up @@ -69,6 +73,11 @@ static int app_rx_st30p_uinit(struct st_app_rx_st30p_session* s) {
s->handle = NULL;
}

if (s->st30p_destination_file) {
fclose(s->st30p_destination_file);
s->st30p_destination_file = NULL;
}

return 0;
}

Expand Down Expand Up @@ -114,6 +123,17 @@ static int app_rx_st30p_init(struct st_app_context* ctx,
ops.port.udp_port[MTL_SESSION_PORT_R] =
st30p ? st30p->base.udp_port : (10000 + s->idx);
}
if (st30p && st30p->info.audio_url[0] != '\0') {
memcpy(s->st30p_destination_url, st30p->info.audio_url, ST_APP_URL_MAX_LEN);
s->st30p_destination_file = fopen(s->st30p_destination_url, "wb");

if (!s->st30p_destination_file) {
err("%s(%d), failed to open destination file %s\n", __func__, idx,
s->st30p_destination_url);
app_rx_st30p_uinit(s);
return -EIO;
}
}
ops.port.payload_type = st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO;

ops.fmt = st30p ? st30p->info.audio_format : ST30_FMT_PCM24;
Expand Down
Loading