mxftypes: Add function to serialize an index table segment to a buffer

This commit is contained in:
Sebastian Dröge 2015-12-07 19:34:25 +02:00
parent 01f0d16db3
commit 47da7565ce
2 changed files with 121 additions and 0 deletions

View file

@ -22,6 +22,7 @@
#endif #endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/gstbytewriter.h>
#include <string.h> #include <string.h>
#include "mxftypes.h" #include "mxftypes.h"
@ -1299,6 +1300,125 @@ mxf_index_table_segment_reset (MXFIndexTableSegment * segment)
memset (segment, 0, sizeof (MXFIndexTableSegment)); memset (segment, 0, sizeof (MXFIndexTableSegment));
} }
GstBuffer *
mxf_index_table_segment_to_buffer (const MXFIndexTableSegment * segment)
{
guint len, slen, i;
guint8 ber[9];
GstBuffer *ret;
GstMapInfo map;
GstByteWriter bw;
g_return_val_if_fail (segment != NULL, NULL);
g_return_val_if_fail (segment->n_delta_entries * 6 < G_MAXUINT16, NULL);
g_return_val_if_fail (segment->n_index_entries * (11 +
4 * segment->slice_count + 8 * segment->pos_table_count) <
G_MAXUINT16, NULL);
len =
16 + 4 + 8 + 4 + 8 + 4 + 8 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 1 + 4 + 1 + 4 +
4 + 8 + segment->n_delta_entries * 6 + 4 + 8 +
segment->n_index_entries * (11 + 4 * segment->slice_count +
8 * segment->pos_table_count);
slen = mxf_ber_encode_size (len, ber);
ret = gst_buffer_new_and_alloc (16 + slen + len);
gst_buffer_map (ret, &map, GST_MAP_WRITE);
gst_byte_writer_init_with_data (&bw, map.data, map.size, FALSE);
gst_byte_writer_put_data_unchecked (&bw,
(const guint8 *) MXF_UL (INDEX_TABLE_SEGMENT), 16);
gst_byte_writer_put_data_unchecked (&bw, ber, slen);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3c0a);
gst_byte_writer_put_uint16_be_unchecked (&bw, 16);
gst_byte_writer_put_data_unchecked (&bw,
(const guint8 *) &segment->instance_id, 16);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f0b);
gst_byte_writer_put_uint16_be_unchecked (&bw, 8);
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->index_edit_rate.n);
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->index_edit_rate.d);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f0c);
gst_byte_writer_put_uint16_be_unchecked (&bw, 8);
gst_byte_writer_put_uint64_be_unchecked (&bw, segment->index_start_position);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f0d);
gst_byte_writer_put_uint16_be_unchecked (&bw, 8);
gst_byte_writer_put_uint64_be_unchecked (&bw, segment->index_duration);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f05);
gst_byte_writer_put_uint16_be_unchecked (&bw, 4);
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->edit_unit_byte_count);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f06);
gst_byte_writer_put_uint16_be_unchecked (&bw, 4);
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->index_sid);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f07);
gst_byte_writer_put_uint16_be_unchecked (&bw, 4);
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->body_sid);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f08);
gst_byte_writer_put_uint16_be_unchecked (&bw, 1);
gst_byte_writer_put_uint8 (&bw, segment->slice_count);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f0e);
gst_byte_writer_put_uint16_be_unchecked (&bw, 1);
gst_byte_writer_put_uint8 (&bw, segment->pos_table_count);
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f09);
gst_byte_writer_put_uint16_be_unchecked (&bw,
8 + segment->n_delta_entries * 6);
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->n_delta_entries);
gst_byte_writer_put_uint32_be_unchecked (&bw, 6);
for (i = 0; i < segment->n_delta_entries; i++) {
gst_byte_writer_put_uint8_unchecked (&bw,
segment->delta_entries[i].pos_table_index);
gst_byte_writer_put_uint8_unchecked (&bw, segment->delta_entries[i].slice);
gst_byte_writer_put_uint32_be_unchecked (&bw,
segment->delta_entries[i].element_delta);
}
gst_byte_writer_put_uint16_be_unchecked (&bw, 0x3f0a);
gst_byte_writer_put_uint16_be_unchecked (&bw,
8 + segment->n_index_entries * (11 + 4 * segment->slice_count +
8 * segment->pos_table_count));
gst_byte_writer_put_uint32_be_unchecked (&bw, segment->n_index_entries);
gst_byte_writer_put_uint32_be_unchecked (&bw,
(11 + 4 * segment->slice_count + 8 * segment->pos_table_count));
for (i = 0; i < segment->n_index_entries; i++) {
guint j;
gst_byte_writer_put_uint8_unchecked (&bw,
segment->index_entries[i].temporal_offset);
gst_byte_writer_put_uint8_unchecked (&bw,
segment->index_entries[i].key_frame_offset);
gst_byte_writer_put_uint8_unchecked (&bw, segment->index_entries[i].flags);
gst_byte_writer_put_uint64_be_unchecked (&bw,
segment->index_entries[i].stream_offset);
for (j = 0; j < segment->slice_count; j++)
gst_byte_writer_put_uint32_be_unchecked (&bw,
segment->index_entries[i].slice_offset[j]);
for (j = 0; j < segment->pos_table_count; j++) {
gst_byte_writer_put_uint32_be_unchecked (&bw,
segment->index_entries[i].pos_table[j].n);
gst_byte_writer_put_uint32_be_unchecked (&bw,
segment->index_entries[i].pos_table[j].d);
}
}
g_assert (gst_byte_writer_get_pos (&bw) == map.size);
gst_buffer_unmap (ret, &map);
return ret;
}
/* SMPTE 377M 8.2 Table 1 and 2 */ /* SMPTE 377M 8.2 Table 1 and 2 */
static void static void

View file

@ -257,6 +257,7 @@ GstBuffer * mxf_random_index_pack_to_buffer (const GArray *array);
gboolean mxf_index_table_segment_parse (const MXFUL *ul, MXFIndexTableSegment *segment, const guint8 *data, guint size); gboolean mxf_index_table_segment_parse (const MXFUL *ul, MXFIndexTableSegment *segment, const guint8 *data, guint size);
void mxf_index_table_segment_reset (MXFIndexTableSegment *segment); void mxf_index_table_segment_reset (MXFIndexTableSegment *segment);
GstBuffer * mxf_index_table_segment_to_buffer (const MXFIndexTableSegment *segment);
gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag, gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag,
guint16 * tag_size, const guint8 ** tag_data); guint16 * tag_size, const guint8 ** tag_data);