Skip to content

Commit

Permalink
Add support for saving audio to file in sample
Browse files Browse the repository at this point in the history
Signed-off-by: Kasiewicz, Marek <[email protected]>
  • Loading branch information
Sakoram committed Dec 13, 2024
1 parent 0de0be7 commit d3fa46d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
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

0 comments on commit d3fa46d

Please sign in to comment.