Skip to content

Commit

Permalink
Add: support for saving video to file in st20p
Browse files Browse the repository at this point in the history
Add support for st20p RxTxApp video saving using
alraedy existing video url json parsing.
  • Loading branch information
DawidWesierski4 committed Dec 6, 2024
1 parent b7f94e5 commit 1942e33
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/app_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ struct st_app_rx_st20p_session {
pthread_t st20p_app_thread;
bool st20p_app_thread_stop;

char st20p_destination_url[ST_APP_URL_MAX_LEN];
FILE* st20p_destination_file;
struct st_display* display;
uint32_t pcapng_max_pkts;

Expand Down Expand Up @@ -717,6 +719,7 @@ struct st_app_context {
struct st_app_rx_st22p_session* rx_st22p_sessions;
int rx_st22p_session_cnt;

char rx_st20p_url[ST_APP_URL_MAX_LEN]; /* save st20p content url*/
struct st_app_rx_st20p_session* rx_st20p_sessions;
int rx_st20p_session_cnt;

Expand Down
4 changes: 4 additions & 0 deletions app/src/parse_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,10 @@ static int st_json_parse_rx_st20p(int idx, json_object* st20p_obj,
ret = parse_st20p_transport_format(st20p_obj, st20p);
if (ret < 0) return ret;

/* parse st20p url */
ret = parse_url(st20p_obj, "st20p_url", st20p->info.st20p_url);
if (ret < 0) return ret;

/* parse display option */
st20p->display =
json_object_get_boolean(st_json_object_object_get(st20p_obj, "display"));
Expand Down
19 changes: 19 additions & 0 deletions app/src/rx_st20p_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session* s,
struct st_display* d = s->display;
int idx = s->idx;

if (s->st20p_destination_file) {
if (!fwrite(frame->addr[0], 1, s->st20p_frame_size, s->st20p_destination_file)) {
err("%s(%d), failed to write frame to file %s\n", __func__, idx,
s->st20p_destination_url);
}
}

if (s->num_port > 1) {
dbg("%s(%d): pkts_total %u, pkts per port P %u R %u\n", __func__, idx,
frame->pkts_total, frame->pkts_recv[MTL_SESSION_PORT_P],
Expand Down Expand Up @@ -209,6 +216,18 @@ static int app_rx_st20p_init(struct st_app_context* ctx,
st20p ? st20p->base.udp_port : (10000 + s->idx);
}

if (st20p && st20p->info.st20p_url[0] != '\0') {
memcpy(s->st20p_destination_url, st20p->info.st20p_url, ST_APP_URL_MAX_LEN);
s->st20p_destination_file = fopen(s->st20p_destination_url, "wb");

if (!s->st20p_destination_file) {
err("%s(%d), failed to open destination file %s\n", __func__, idx,
s->st20p_destination_url);
app_rx_st20p_uinit(s);
return -EIO;
}
}

ops.width = st20p ? st20p->info.width : 1920;
ops.height = st20p ? st20p->info.height : 1080;
ops.fps = st20p ? st20p->info.fps : ST_FPS_P59_94;
Expand Down

0 comments on commit 1942e33

Please sign in to comment.