+/**
+ * \brief filters out interesting tags from material information.
+ * \param len lenght of tag section, will be adjusted to contain remaining bytes
+ * \param si struct to store collected information into
+ */
+static void gxf_material_tags(ByteIOContext *pb, int *len, st_info_t *si) {
+ si->first_field = AV_NOPTS_VALUE;
+ si->last_field = AV_NOPTS_VALUE;
+ while (*len >= 2) {
+ mat_tag_t tag = get_byte(pb);
+ int tlen = get_byte(pb);
+ *len -= 2;
+ if (tlen > *len)
+ return;
+ *len -= tlen;
+ if (tlen == 4) {
+ uint32_t value = get_be32(pb);
+ if (tag == MAT_FIRST_FIELD)
+ si->first_field = value;
+ else if (tag == MAT_LAST_FIELD)
+ si->last_field = value;
+ } else
+ url_fskip(pb, tlen);
+ }
+}
+
+/**
+ * \brief convert fps tag value to AVRational fps
+ * \param fps fps value from tag
+ * \return fps as AVRational, or 0 / 0 if unknown
+ */
+static AVRational fps_tag2avr(int32_t fps) {
+ extern const AVRational ff_frame_rate_tab[];
+ if (fps < 1 || fps > 9) fps = 9;
+ return ff_frame_rate_tab[9 - fps]; // values have opposite order
+}
+
+/**
+ * \brief convert UMF attributes flags to AVRational fps
+ * \param fps fps value from flags
+ * \return fps as AVRational, or 0 / 0 if unknown
+ */
+static AVRational fps_umf2avr(uint32_t flags) {
+ static const AVRational map[] = {{50, 1}, {60000, 1001}, {24, 1},
+ {25, 1}, {30000, 1001}};
+ int idx = av_log2((flags & 0x7c0) >> 6);
+ return map[idx];
+}
+
+/**
+ * \brief filters out interesting tags from track information.
+ * \param len length of tag section, will be adjusted to contain remaining bytes
+ * \param si struct to store collected information into
+ */
+static void gxf_track_tags(ByteIOContext *pb, int *len, st_info_t *si) {
+ si->frames_per_second = (AVRational){0, 0};
+ si->fields_per_frame = 0;
+ while (*len >= 2) {
+ track_tag_t tag = get_byte(pb);
+ int tlen = get_byte(pb);
+ *len -= 2;
+ if (tlen > *len)
+ return;
+ *len -= tlen;
+ if (tlen == 4) {
+ uint32_t value = get_be32(pb);
+ if (tag == TRACK_FPS)
+ si->frames_per_second = fps_tag2avr(value);
+ else if (tag == TRACK_FPF && (value == 1 || value == 2))
+ si->fields_per_frame = value;
+ } else
+ url_fskip(pb, tlen);
+ }
+}
+
+/**
+ * \brief read index from FLT packet into stream 0 av_index
+ */
+static void gxf_read_index(AVFormatContext *s, int pkt_len) {
+ ByteIOContext *pb = &s->pb;
+ AVStream *st = s->streams[0];
+ uint32_t fields_per_map = get_le32(pb);
+ uint32_t map_cnt = get_le32(pb);
+ int i;
+ pkt_len -= 8;
+ if (map_cnt > 1000) {
+ av_log(s, AV_LOG_ERROR, "GXF: too many index entries %u (%x)\n", map_cnt, map_cnt);
+ map_cnt = 1000;
+ }
+ if (pkt_len < 4 * map_cnt) {
+ av_log(s, AV_LOG_ERROR, "GXF: invalid index length\n");
+ url_fskip(pb, pkt_len);
+ return;
+ }
+ pkt_len -= 4 * map_cnt;
+ av_add_index_entry(st, 0, 0, 0, 0, 0);
+ for (i = 0; i < map_cnt; i++)
+ av_add_index_entry(st, (uint64_t)get_le32(pb) * 1024,
+ i * (uint64_t)fields_per_map + 1, 0, 0, 0);
+ url_fskip(pb, pkt_len);
+}
+