Skip to content

Commit

Permalink
st41 working for frame and rtp modes
Browse files Browse the repository at this point in the history
  • Loading branch information
skolelis committed Sep 6, 2024
1 parent 2387edc commit 8056e0e
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 56 deletions.
3 changes: 3 additions & 0 deletions app/src/app_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ struct st_app_tx_fmd_session {
int st41_source_fd;
pcap_t* st41_pcap;
bool st41_pcap_input;
uint32_t fmd_dit;
uint32_t fmd_k_bit;

bool st41_rtp_input;
uint8_t* st41_source_begin;
uint8_t* st41_source_end;
Expand Down
1 change: 1 addition & 0 deletions app/src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ static int app_args_json(struct st_app_context* ctx, struct mtl_init_params* p,
ctx->json_ctx = NULL;
return ret;
}

ctx->tx_video_session_cnt = ctx->json_ctx->tx_video_session_cnt;
ctx->tx_audio_session_cnt = ctx->json_ctx->tx_audio_session_cnt;
ctx->tx_anc_session_cnt = ctx->json_ctx->tx_anc_session_cnt;
Expand Down
40 changes: 30 additions & 10 deletions app/src/parse_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,15 +1229,35 @@ static int st_json_parse_tx_fmd(int idx, json_object* fmd_obj,
err("%s, invalid fmd type %s\n", __func__, type);
return -ST_JSON_NOT_VALID;
}
/* parse fmd format */
const char* fmd_format =
json_object_get_string(st_json_object_object_get(fmd_obj, "fastmetadata_format"));
REQUIRED_ITEM(fmd_format);
if (strcmp(fmd_format, "closed_caption") == 0) {
fmd->info.fmd_format = FMD_FORMAT_CLOSED_CAPTION;

/* parse fmd data item type */
json_object* fmd_dit_obj = st_json_object_object_get(fmd_obj, "fastmetadata_data_item_type");
if (fmd_dit_obj) {
uint32_t fmd_dit = json_object_get_int(fmd_dit_obj);
if (fmd_dit < 0 || fmd_dit > 0x3fffff) {
err("%s, invalid fastmetadata_data_item_type 0x%x\n", __func__, fmd_dit);
return -ST_JSON_NOT_VALID;
}
fmd->info.fmd_dit = fmd_dit;
info("%s, fastmetadata_data_item_type = 0x%x\n", __func__, fmd_dit);
} else {
err("%s, invalid fmd format %s\n", __func__, fmd_format);
return -ST_JSON_NOT_VALID;
err("%s, No fastmetadata_data_item_type !\n", __func__);
return -ST_JSON_NULL;
}

/* parse fmd data item K-bit */
json_object* fmd_k_bit_obj = st_json_object_object_get(fmd_obj, "fastmetadata_k_bit");
if (fmd_k_bit_obj) {
uint8_t fmd_k_bit = json_object_get_int(fmd_k_bit_obj);
if (fmd_k_bit < 0 || fmd_k_bit > 1) {
err("%s, invalid fastmetadata_k_bit 0x%x\n", __func__, fmd_k_bit);
return -ST_JSON_NOT_VALID;
}
fmd->info.fmd_k_bit = fmd_k_bit;
info("%s, fastmetadata_k_bit = 0x%x\n", __func__, fmd_k_bit);
} else {
err("%s, No fastmetadata_k_bit !\n", __func__);
return -ST_JSON_NULL;
}

/* parse fmd fps */
Expand Down Expand Up @@ -1338,7 +1358,7 @@ static int parse_st22p_fps(json_object* st22p_obj, st_json_st22p_session_t* st22
} else if (strcmp(fps, "p29") == 0) {
st22p->info.fps = ST_FPS_P29_97;
} else {
err("%s, invalid anc fps %s\n", __func__, fps); //skolelis tbd: here I dont see corelation for st41(fmd), but why there is st40(anc) actually?
err("%s, invalid st22 fps %s\n", __func__, fps);
return -ST_JSON_NOT_VALID;
}
return ST_JSON_SUCCESS;
Expand Down Expand Up @@ -1646,7 +1666,7 @@ static int parse_st20p_fps(json_object* st20p_obj, st_json_st20p_session_t* st20
} else if (strcmp(fps, "p29") == 0) {
st20p->info.fps = ST_FPS_P29_97;
} else {
err("%s, invalid anc fps %s\n", __func__, fps); //skolelis tbd: here I dont see corelation for st41(fmd), but why there is st40(anc) actually?
err("%s, invalid st20 fps %s\n", __func__, fps);
return -ST_JSON_NOT_VALID;
}
return ST_JSON_SUCCESS;
Expand Down
8 changes: 2 additions & 6 deletions app/src/parse_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ enum anc_format {
ANC_FORMAT_MAX,
};

enum fmd_format {
FMD_FORMAT_CLOSED_CAPTION,
FMD_FORMAT_MAX,
}; // skolelis tbd: I don't think closed caption is relevant here in st41. The enum to be removed or changed.

struct st_video_fmt_desc {
enum video_format fmt;
char* name;
Expand Down Expand Up @@ -187,7 +182,8 @@ typedef struct st_json_ancillary_info {

typedef struct st_json_fastmetadata_info {
enum st41_type type;
enum fmd_format fmd_format;
uint32_t fmd_dit;
uint8_t fmd_k_bit;
enum st_fps fmd_fps;
bool interlaced;

Expand Down
22 changes: 15 additions & 7 deletions app/src/rx_fastmetadata_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@

#include "rx_fastmetadata_app.h"

static void app_rx_fmd_handle_rtp(struct st_app_rx_fmd_session* s) { //skolelis tbd remove }, void* usrptr) {
// skolelis tbd remove this line struct st41_rtp_hdr* hdr = (struct st41_rtp_hdr*)usrptr;
// skolelis tbd remove this line struct st41_rfc8331_payload_hdr* payload_hdr =
// skolelis tbd remove this line (struct st41_rfc8331_payload_hdr*)(&hdr[1]);
static void app_rx_fmd_handle_rtp(struct st_app_rx_fmd_session* s) { // skolelis tbd: remove }, void* usrptr) {
// skolelis tbd: struct st41_rtp_hdr* hdr = (struct st41_rtp_hdr*)usrptr;
// skolelis tbd: struct st41_rfc8331_payload_hdr* payload_hdr = (struct st41_rfc8331_payload_hdr*)(&hdr[1]);

dbg("%s(%d).\n", __func__, s->idx);

// skolelis what for this nthol() 2x ? payload_hdr->swaped_second_hdr_chunk = ntohl(payload_hdr->swaped_second_hdr_chunk);
// skolelis what for this nthol() 2x ? payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk);
// skolelis tbd: payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk);

/* // skolelis tbd: some checking should be done. in st40 here we were checking if checksums and parities are correct.
// skolelis tbd: here in st41 we dont have such mechanisms to verify. so what else?
if (!st41_check_parity_bits(payload_hdr->second_hdr_chunk.did) ||
!st41_check_parity_bits(payload_hdr->second_hdr_chunk.sdid) ||
!st41_check_parity_bits(payload_hdr->second_hdr_chunk.data_count)) {
err("%s(%d), fmd RTP checkParityBits error\n", __func__, s->idx);
return;
}
*/
s->stat_frame_total_received++;
if (!s->stat_frame_first_rx_time)
s->stat_frame_first_rx_time = st_app_get_monotonic_time();
Expand All @@ -37,7 +45,7 @@ static void* app_rx_fmd_read_thread(void* arg) {
continue;
}
/* parse the packet */
app_rx_fmd_handle_rtp(s); // skolelis tbd remove: , usrptr);
app_rx_fmd_handle_rtp(s); // skolelis tbd: remove: , usrptr);
st41_rx_put_mbuf(s->handle, mbuf);
}
info("%s(%d), stop\n", __func__, idx);
Expand Down
33 changes: 24 additions & 9 deletions app/src/tx_fastmetadata_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include "tx_fastmetadata_app.h"


// skolelis tbd: where it shoud be defined?
#define ST_PKT_ST41_PAYLOAD_MAX_BYTES \
(1460 - sizeof(struct st41_rtp_hdr))
(1460 - sizeof(struct st41_rtp_hdr) - 8) // skolelis tbd: why here we have "-8" ? (value found experimentally. "-7" would be not enough!)

static int app_tx_fmd_next_frame(void* priv, uint16_t* next_frame_idx,
struct st41_tx_frame_meta* meta) {
Expand Down Expand Up @@ -79,6 +79,7 @@ static void app_tx_fmd_build_frame(struct st_app_tx_fmd_session* s,
uint16_t data_item_length_bytes = s->st41_source_end - s->st41_frame_cursor > ST_PKT_ST41_PAYLOAD_MAX_BYTES
? ST_PKT_ST41_PAYLOAD_MAX_BYTES
: s->st41_source_end - s->st41_frame_cursor;

dst->data_item_length_bytes = data_item_length_bytes;
dst->data = s->st41_frame_cursor;
s->st41_frame_cursor += data_item_length_bytes;
Expand Down Expand Up @@ -108,7 +109,7 @@ static void* app_tx_fmd_frame_thread(void* arg) {

struct st41_frame* frame_addr = st41_tx_get_framebuffer(s->handle, producer_idx);
app_tx_fmd_build_frame(s, frame_addr);

st_pthread_mutex_lock(&s->st41_wake_mutex);
framebuff->size = sizeof(*frame_addr);
framebuff->stat = ST_TX_FRAME_READY;
Expand Down Expand Up @@ -191,9 +192,11 @@ static void app_tx_fmd_build_rtp(struct st_app_tx_fmd_session* s, void* usrptr,
/* generate one fmd rtp for test purpose */
struct st41_rtp_hdr* hdr = (struct st41_rtp_hdr*)usrptr;
uint8_t* payload_hdr = (uint8_t*)(&hdr[1]);
uint16_t data_item_length_bytes = s->st41_source_end - s->st41_frame_cursor > ST_PKT_ST41_PAYLOAD_MAX_BYTES
? ST_PKT_ST41_PAYLOAD_MAX_BYTES
uint16_t data_item_length_bytes = s->st41_source_end - s->st41_frame_cursor > (MTL_PKT_MAX_RTP_BYTES-16)
? (MTL_PKT_MAX_RTP_BYTES-16)
: s->st41_source_end - s->st41_frame_cursor;
// skolelis tbd: (MTL_PKT_MAX_RTP_BYTES-16) - this is limit found in experimental way. no ST_PKT_ST41_PAYLOAD_MAX_BYTES !!!

uint16_t data_item_length;
data_item_length = (data_item_length_bytes + 3) / 4; /* expressed in number of 4-byte words */
hdr->base.marker = 1;
Expand All @@ -209,17 +212,22 @@ static void app_tx_fmd_build_rtp(struct st_app_tx_fmd_session* s, void* usrptr,
s->st41_seq_id++;
s->st41_rtp_tmstamp++;

// skolelis what for we have her this htonl() ??? payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk);
// skolelis tbd: what for we have her this htonl() ??? payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk);
for (int i = 0; i < data_item_length_bytes; i++) {
payload_hdr[i] = s->st41_frame_cursor[i]; //skolelis tu ustal dobrze wskaznik na start paylodu a moze nawet 4-bajtowy?
payload_hdr[i] = s->st41_frame_cursor[i]; // skolelis tbd: here have the proper pointer on payload start, and maybe even 4-byte word?
}
/* filling with 0's the remianing bytes of last 4-byte word */
for (int i = data_item_length_bytes; i < data_item_length * 4; i++) {
payload_hdr[i] = 0;
}

*mbuf_len = sizeof(struct st41_rtp_hdr) + data_item_length * 4;
hdr->data_item_length = htons(data_item_length); //tbd skolelis htons() ???
hdr->st41_hdr_chunk.data_item_length = data_item_length; // skolelis tbd: htons() ???
hdr->st41_hdr_chunk.data_item_type = s->fmd_dit;
hdr->st41_hdr_chunk.data_item_k_bit = s->fmd_k_bit;

hdr->swaped_st41_hdr_chunk = htonl(hdr->swaped_st41_hdr_chunk); // skolelis tbd: and I added it instead of htons() 1 line above

s->st41_frame_cursor += data_item_length_bytes;
if (s->st41_frame_cursor == s->st41_source_end)
s->st41_frame_cursor = s->st41_source_begin;
Expand Down Expand Up @@ -320,7 +328,7 @@ static int app_tx_fmd_close_source(struct st_app_tx_fmd_session* s) {
static int app_tx_fmd_start_source(struct st_app_tx_fmd_session* s) {
int ret = -EINVAL;
int idx = s->idx;

s->st41_app_thread_stop = false;
if (s->st41_pcap_input)
ret = pthread_create(&s->st41_app_thread, NULL, app_tx_fmd_pcap_thread, (void*)s);
Expand Down Expand Up @@ -435,6 +443,8 @@ static int app_tx_fmd_init(struct st_app_context* ctx, st_json_fastmetadata_sess
ops.notify_rtp_done = app_tx_fmd_rtp_done;
ops.framebuff_cnt = s->framebuff_cnt;
ops.fps = fmd ? fmd->info.fmd_fps : ST_FPS_P59_94;
ops.fmd_dit = fmd->info.fmd_dit;
ops.fmd_k_bit = fmd->info.fmd_k_bit;
s->st41_pcap_input = false;
ops.type = fmd ? fmd->info.type : ST41_TYPE_FRAME_LEVEL;
ops.interlaced = fmd ? fmd->info.interlaced : false;
Expand Down Expand Up @@ -464,6 +474,10 @@ static int app_tx_fmd_init(struct st_app_context* ctx, st_json_fastmetadata_sess
return -EIO;
}

/* added this s... = fmd... for RTP mode to function (by skolelis)*/
s->fmd_dit = fmd->info.fmd_dit;
s->fmd_k_bit = fmd->info.fmd_k_bit;

s->handle = handle;
snprintf(s->st41_source_url, sizeof(s->st41_source_url), "%s",
fmd ? fmd->info.fmd_url : ctx->tx_fmd_url);
Expand Down Expand Up @@ -508,6 +522,7 @@ int st_app_tx_fmd_sessions_init(struct st_app_context* ctx) {
s->idx = i;
ret = app_tx_fmd_init(ctx, ctx->json_ctx ? &ctx->json_ctx->tx_fmd_sessions[i] : NULL,
s);

if (ret < 0) {
err("%s(%d), app_tx_fmd_session_init fail %d\n", __func__, i, ret);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion include/st40_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ struct st40_meta {
/**
* Max number of meta in one ST2110-40(ancillary) frame
*/
#define ST40_MAX_META (20) //skolelis tbd according to rf8331 the limit is 255 (if it is the proper field for that) !!!
#define ST40_MAX_META (20) // skolelis tbd: according to rf8331 the limit is 255 (if it is the proper field for that) !!!

/**
* Structure for ST2110-40(ancillary) frame
Expand Down
47 changes: 39 additions & 8 deletions include/st41_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,44 @@ enum st41_type {
};

/**
* A structure describing a st2110-41 (fast metadata framework) rtp header
* A structure describing a st2110-41(fast metadata) rtp header
*/
#ifdef MTL_LITTLE_ENDIAN
MTL_PACK(struct st41_rtp_hdr { // skolelis tbd: should we add little/big endian (double) versions struct to this structure (like in other places)?
/** Rtp rfc3550 base hdr */
struct st_rfc3550_rtp_hdr base;

/** Data Item Type */
uint32_t data_item_type : 22;
/** Data Item K-bit */
uint8_t data_item_k_bit : 1; // skolelis tbd: is it not better to have here uint_32_t type for compatibility with other 22 bits?
/** Data Item Contents - Number of 32-bit data elements that follow */
uint16_t data_item_length : 9; // skolelis tbd: is it not better to have here uint_32_t type for compatibility with other 22 bits?
union {
struct {
/** Data Item Contents - Number of 32-bit data elements that follow */
uint32_t data_item_length : 9; // skolelis tbd: is it not better to have here uint_32_t type for compatibility with other 22 bits?
/** Data Item K-bit */
uint32_t data_item_k_bit : 1; // skolelis tbd: is it not better to have here uint_32_t type for compatibility with other 22 bits?
/** Data Item Type */
uint32_t data_item_type : 22;
} st41_hdr_chunk;
/** Handle to make operating on st41_hdr_chunk buffer easier */
uint32_t swaped_st41_hdr_chunk;
};
});
#else
MTL_PACK(struct st41_rtp_hdr { // skolelis tbd: should we add little/big endian (double) versions struct to this structure (like in other places)?
/** Rtp rfc3550 base hdr */
struct st_rfc3550_rtp_hdr base;
union {
struct {
/** Data Item Type */
uint32_t data_item_type : 22;
/** Data Item K-bit */
uint32_t data_item_k_bit : 1; // skolelis tbd: is it not better to have here uint_32_t type for compatibility with other 22 bits?
/** Data Item Contents - Number of 32-bit data elements that follow */
uint32_t data_item_length : 9; // skolelis tbd: is it not better to have here uint_32_t type for compatibility with other 22 bits?
} st41_hdr_chunk;
/** Handle to make operating on st41_hdr_chunk buffer easier */
uint32_t swaped_st41_hdr_chunk;
};
});
#endif


/**
* Structure for ST2110-41(fast metadata) frame
Expand Down Expand Up @@ -142,6 +167,11 @@ struct st41_tx_ops {
enum st_fps fps;
/** Mandatory. 7 bits payload type define in RFC3550 */
uint8_t payload_type;
/** Mandatory. 22 bits data item type */
uint32_t fmd_dit;
/** Mandatory. 1 bit data item K-bit */
uint8_t fmd_k_bit;

/** Mandatory. interlaced or not */
bool interlaced;

Expand Down Expand Up @@ -233,6 +263,7 @@ struct st41_rx_ops {
/** Optional. see ST41_RX_FLAG_* for possible flags */
uint32_t flags;


/** Mandatory. rtp ring queue size, must be power of 2 */
uint32_t rtp_ring_size;
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/src/st2110/st_fastmetadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#include "../mt_log.h"


//skolelis tbd remove this file if empty
// skolelis tbd: remove this file if empty
2 changes: 1 addition & 1 deletion lib/src/st2110/st_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct st_frame_trans {
struct st30_tx_frame_meta ta_meta;
struct st30_rx_frame_meta ra_meta; /* not use now */
struct st40_tx_frame_meta tc_meta;
struct st41_tx_frame_meta tf_meta; //skolelis TBD - field for st41 transport ? (fast meta data -> "f") !!!
struct st41_tx_frame_meta tf_meta; // skolelis tbd: - field for st41 transport ? (fast meta data -> "f") !!!
};
};

Expand Down
Loading

0 comments on commit 8056e0e

Please sign in to comment.