mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-03-17 20:17:55 +02:00
compute essence containers in mxf_write_header, this simplifies the code
Originally committed as revision 15072 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
a2f55f22b3
commit
c18d208ae2
@ -48,6 +48,8 @@ typedef struct MXFContext {
|
|||||||
int64_t header_byte_count_offset;
|
int64_t header_byte_count_offset;
|
||||||
int64_t header_footer_partition_offset;
|
int64_t header_footer_partition_offset;
|
||||||
int essence_container_count;
|
int essence_container_count;
|
||||||
|
uint8_t essence_containers_indices[sizeof(ff_mxf_essence_container_uls)/
|
||||||
|
sizeof(*ff_mxf_essence_container_uls)];
|
||||||
} MXFContext;
|
} MXFContext;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -182,14 +184,16 @@ static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const UID *mxf_get_essence_container_ul(enum CodecID type)
|
/*
|
||||||
|
* Get essence container ul and return its index position
|
||||||
|
*/
|
||||||
|
static const UID *mxf_get_essence_container_ul(enum CodecID type, int *index)
|
||||||
{
|
{
|
||||||
const MXFCodecUL *uls = ff_mxf_essence_container_uls;
|
const MXFCodecUL *uls = ff_mxf_essence_container_uls;
|
||||||
while (uls->id != CODEC_ID_NONE) {
|
for (*index = 0; *index < sizeof(ff_mxf_essence_container_uls)/sizeof(ff_mxf_essence_container_uls[0]); (*index)++)
|
||||||
if (uls->id == type)
|
if (ff_mxf_essence_container_uls[*index].id == type)
|
||||||
return &uls->uid;
|
return &uls->uid;
|
||||||
uls++;
|
*index = -1;
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,37 +252,19 @@ static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type
|
|||||||
|
|
||||||
static int mxf_write_essence_container_refs(AVFormatContext *s, int write)
|
static int mxf_write_essence_container_refs(AVFormatContext *s, int write)
|
||||||
{
|
{
|
||||||
|
MXFContext *c = s->priv_data;
|
||||||
ByteIOContext *pb = s->pb;
|
ByteIOContext *pb = s->pb;
|
||||||
AVStream *st;
|
int i;
|
||||||
int i, count = 0, j = 0;
|
|
||||||
const MXFCodecUL *codec_ul;
|
|
||||||
int essence_container_ul_sign[sizeof(ff_mxf_essence_container_uls) / sizeof(MXFCodecUL)] = { 0 };
|
|
||||||
|
|
||||||
for (codec_ul = ff_mxf_essence_container_uls; codec_ul->id; codec_ul++) {
|
|
||||||
for (i = 0; i < s->nb_streams; i++) {
|
|
||||||
st = s->streams[i];
|
|
||||||
if (st->codec->codec_id == codec_ul->id) {
|
|
||||||
essence_container_ul_sign[count] = j;
|
|
||||||
count++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
// considering WAV/AES3 frame wrapped, when get the first CODEC_ID_PCM_S16LE, break;
|
|
||||||
// this is a temporary method, when we can get more information, modify this.
|
|
||||||
if (codec_ul->id == CODEC_ID_PCM_S16LE)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
mxf_write_refs_count(pb, count);
|
mxf_write_refs_count(pb, c->essence_container_count);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < c->essence_container_count; i++)
|
||||||
put_buffer(pb, ff_mxf_essence_container_uls[essence_container_ul_sign[i]].uid, 16);
|
put_buffer(pb, ff_mxf_essence_container_uls[c->essence_containers_indices[i]].uid, 16);
|
||||||
av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", count);
|
av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < c->essence_container_count; i++)
|
||||||
PRINT_KEY(s, "essence container ul:\n", ff_mxf_essence_container_uls[essence_container_ul_sign[i]].uid);
|
PRINT_KEY(s, "essence container ul:\n", ff_mxf_essence_container_uls[c->essence_containers_indices[i]].uid);
|
||||||
}
|
}
|
||||||
return count;
|
return c->essence_container_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mxf_write_preface(AVFormatContext *s)
|
static void mxf_write_preface(AVFormatContext *s)
|
||||||
@ -756,7 +742,9 @@ static int mux_write_header(AVFormatContext *s)
|
|||||||
MXFContext *mxf = s->priv_data;
|
MXFContext *mxf = s->priv_data;
|
||||||
ByteIOContext *pb = s->pb;
|
ByteIOContext *pb = s->pb;
|
||||||
int64_t header_metadata_start, offset_now;
|
int64_t header_metadata_start, offset_now;
|
||||||
int i;
|
int i, index;
|
||||||
|
uint8_t present[sizeof(ff_mxf_essence_container_uls)/
|
||||||
|
sizeof(*ff_mxf_essence_container_uls)] = {0};
|
||||||
|
|
||||||
for (i = 0; i < s->nb_streams; i++) {
|
for (i = 0; i < s->nb_streams; i++) {
|
||||||
AVStream *st = s->streams[i];
|
AVStream *st = s->streams[i];
|
||||||
@ -769,12 +757,16 @@ static int mux_write_header(AVFormatContext *s)
|
|||||||
av_set_pts_info(st, 64, 1, st->codec->time_base.den);
|
av_set_pts_info(st, 64, 1, st->codec->time_base.den);
|
||||||
else if (st->codec->codec_type == CODEC_TYPE_AUDIO)
|
else if (st->codec->codec_type == CODEC_TYPE_AUDIO)
|
||||||
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
|
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
|
||||||
sc->essence_container_ul = mxf_get_essence_container_ul(st->codec->codec_id);
|
sc->essence_container_ul = mxf_get_essence_container_ul(st->codec->codec_id, &index);
|
||||||
if (!sc->essence_container_ul) {
|
if (!sc->essence_container_ul) {
|
||||||
av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
|
av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
|
||||||
"codec not currently supported in container\n", i);
|
"codec not currently supported in container\n", i);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!present[index]) {
|
||||||
|
mxf->essence_containers_indices[mxf->essence_container_count++] = index;
|
||||||
|
present[index] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mxf_write_partition(s, 0, 1, header_partition_key);
|
mxf_write_partition(s, 0, 1, header_partition_key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user