Commit b92c61e0 authored by Baptiste Coudurier's avatar Baptiste Coudurier

simplify using function table

Originally committed as revision 5871 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 80d0ded2
...@@ -143,21 +143,10 @@ typedef struct MXFCodecUL { ...@@ -143,21 +143,10 @@ typedef struct MXFCodecUL {
enum CodecID id; enum CodecID id;
} MXFCodecUL; } MXFCodecUL;
static const UID mxf_metadata_preface_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2F,0x00 }; typedef struct MXFMetadataReadTableEntry {
static const UID mxf_metadata_content_storage_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }; const UID key;
static const UID mxf_metadata_source_package_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }; int (*read)(MXFContext *mxf, KLVPacket *klv);
static const UID mxf_metadata_material_package_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }; } MXFMetadataReadTableEntry;
static const UID mxf_metadata_sequence_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 };
static const UID mxf_metadata_source_clip_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 };
static const UID mxf_metadata_multiple_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 };
static const UID mxf_metadata_generic_sound_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 };
static const UID mxf_metadata_cdci_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 };
static const UID mxf_metadata_rgba_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 };
static const UID mxf_metadata_mpegvideo_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
static const UID mxf_metadata_wave_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 };
static const UID mxf_metadata_aes3_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 };
static const UID mxf_metadata_static_track_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 };
static const UID mxf_metadata_track_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3b,0x00 };
/* partial keys to match */ /* partial keys to match */
static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 }; static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
...@@ -838,14 +827,34 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) ...@@ -838,14 +827,34 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
return 0; return 0;
} }
static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2F,0x00 }, mxf_read_metadata_preface },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_metadata_sequence },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_metadata_source_clip },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_metadata_multiple_descriptor },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_metadata_generic_descriptor }, /* Generic Sound */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_metadata_generic_descriptor }, /* CDCI */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_metadata_generic_descriptor }, /* RGBA */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_metadata_generic_descriptor }, /* MPEG 2 Video */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_metadata_generic_descriptor }, /* Wave */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_metadata_generic_descriptor }, /* AES3 */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_metadata_track }, /* Static Track */
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_metadata_track }, /* Generic Track */
{ { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL },
};
static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{ {
MXFContext *mxf = s->priv_data; MXFContext *mxf = s->priv_data;
KLVPacket klv; KLVPacket klv;
int ret = 0;
mxf->fc = s; mxf->fc = s;
while (!url_feof(&s->pb)) { while (!url_feof(&s->pb)) {
const MXFMetadataReadTableEntry *function;
if (klv_read_packet(&klv, &s->pb) < 0) { if (klv_read_packet(&klv, &s->pb) < 0) {
av_log(s, AV_LOG_ERROR, "error reading KLV packet\n"); av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
return -1; return -1;
...@@ -853,46 +862,23 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -853,46 +862,23 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
#ifdef DEBUG #ifdef DEBUG
PRINT_KEY(klv.key); PRINT_KEY(klv.key);
#endif #endif
if (IS_KLV_KEY(klv.key, mxf_metadata_track_key)) if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
ret = mxf_read_metadata_track(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_static_track_key))
ret = mxf_read_metadata_track(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_source_package_key))
ret = mxf_read_metadata_source_package(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_sequence_key))
ret = mxf_read_metadata_sequence(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_material_package_key))
ret = mxf_read_metadata_material_package(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_source_clip_key))
ret = mxf_read_metadata_source_clip(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_multiple_descriptor_key))
ret = mxf_read_metadata_multiple_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_wave_descriptor_key))
ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_mpegvideo_descriptor_key))
ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_cdci_descriptor_key))
ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_rgba_descriptor_key))
ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_generic_sound_descriptor_key))
ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_aes3_descriptor_key))
ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_preface_key))
ret = mxf_read_metadata_preface(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_metadata_content_storage_key))
ret = mxf_read_metadata_content_storage(mxf, &klv);
else if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
/* FIXME avoid seek */ /* FIXME avoid seek */
url_fseek(&s->pb, klv.offset, SEEK_SET); url_fseek(&s->pb, klv.offset, SEEK_SET);
break; break;
} else }
url_fskip(&s->pb, klv.length);
if (ret < 0) { for (function = mxf_metadata_read_table; function->read; function++) {
if (IS_KLV_KEY(klv.key, function->key)) {
if (function->read(mxf, &klv) < 0) {
av_log(s, AV_LOG_ERROR, "error reading header metadata\n"); av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
return ret; return -1;
}
break;
}
} }
if (!function->read)
url_fskip(&s->pb, klv.length);
} }
return mxf_parse_structural_metadata(mxf); return mxf_parse_structural_metadata(mxf);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment