* SMPTE RP224: Registry of SMPTE Universal Labels
*/
-//#define DEBUG
-
+#include <inttypes.h>
#include <math.h>
#include <time.h>
#include "libavutil/random_seed.h"
+#include "libavutil/time_internal.h"
#include "libavcodec/bytestream.h"
#include "audiointerleave.h"
#include "avformat.h"
#define EDIT_UNITS_PER_BODY 250
#define KAG_SIZE 512
-typedef struct {
+typedef struct MXFLocalTagPair {
int local_tag;
UID uid;
} MXFLocalTagPair;
-typedef struct {
+typedef struct MXFIndexEntry {
uint8_t flags;
uint64_t offset;
unsigned slice_offset; ///< offset of audio slice
uint16_t temporal_ref;
} MXFIndexEntry;
-typedef struct {
+typedef struct MXFStreamContext {
AudioInterleaveContext aic;
UID track_essence_element_key;
int index; ///< index in mxf_essence_container_uls table
int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing
} MXFStreamContext;
-typedef struct {
+typedef struct MXFContainerEssenceEntry {
UID container_ul;
UID element_ul;
UID codec_ul;
} MXFContainerEssenceEntry;
static const struct {
- enum CodecID id;
+ enum AVCodecID id;
int index;
} mxf_essence_mappings[] = {
- { CODEC_ID_MPEG2VIDEO, 0 },
- { CODEC_ID_PCM_S24LE, 1 },
- { CODEC_ID_PCM_S16LE, 1 },
- { CODEC_ID_NONE }
+ { AV_CODEC_ID_MPEG2VIDEO, 0 },
+ { AV_CODEC_ID_PCM_S24LE, 1 },
+ { AV_CODEC_ID_PCM_S16LE, 1 },
+ { AV_CODEC_ID_NONE }
};
static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st);
/*
* Get essence container ul index
*/
-static int mxf_get_essence_container_ul_index(enum CodecID id)
+static int mxf_get_essence_container_ul_index(enum AVCodecID id)
{
int i;
for (i = 0; mxf_essence_mappings[i].id; i++)
mxf_write_metadata_key(pb, 0x012f00);
PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
- klv_encode_ber_length(pb, 130 + 16 * mxf->essence_container_count);
+ klv_encode_ber_length(pb, 130 + 16LL * mxf->essence_container_count);
// write preface set uid
mxf_write_local_tag(pb, 16, 0x3C0A);
mxf_write_metadata_key(pb, 0x013000);
PRINT_KEY(s, "identification key", pb->buf_ptr - 16);
- version = s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT ?
+ version = s->flags & AVFMT_FLAG_BITEXACT ?
"0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION);
length = 84 + (strlen(company)+strlen(product)+strlen(version))*2; // utf-16
klv_encode_ber_length(pb, length);
if (st == mxf->timecode_track)
avio_write(pb, smpte_12m_timecode_track_data_ul, 16);
else {
- const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type);
+ const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codecpar->codec_type);
avio_write(pb, data_def_ul->uid, 16);
}
mxf_write_metadata_key(pb, 0x014400);
PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16);
- klv_encode_ber_length(pb, 64 + 16 * s->nb_streams);
+ klv_encode_ber_length(pb, 64 + 16LL * s->nb_streams);
mxf_write_local_tag(pb, 16, 0x3C0A);
mxf_write_uuid(pb, MultipleDescriptor, 0);
{
MXFStreamContext *sc = st->priv_data;
AVIOContext *pb = s->pb;
- int stored_height = (st->codec->height+15)/16*16;
+ int stored_height = (st->codecpar->height+15)/16*16;
int display_height;
int f1, f2;
mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20);
mxf_write_local_tag(pb, 4, 0x3203);
- avio_wb32(pb, st->codec->width);
+ avio_wb32(pb, st->codecpar->width);
mxf_write_local_tag(pb, 4, 0x3202);
avio_wb32(pb, stored_height>>sc->interlaced);
mxf_write_local_tag(pb, 4, 0x3209);
- avio_wb32(pb, st->codec->width);
+ avio_wb32(pb, st->codecpar->width);
- if (st->codec->height == 608) // PAL + VBI
+ if (st->codecpar->height == 608) // PAL + VBI
display_height = 576;
- else if (st->codec->height == 512) // NTSC + VBI
+ else if (st->codecpar->height == 512) // NTSC + VBI
display_height = 486;
else
- display_height = st->codec->height;
+ display_height = st->codecpar->height;
mxf_write_local_tag(pb, 4, 0x3208);
avio_wb32(pb, display_height>>sc->interlaced);
avio_w8(pb, sc->interlaced);
// video line map
- switch (st->codec->height) {
+ switch (st->codecpar->height) {
case 576: f1 = 23; f2 = 336; break;
case 608: f1 = 7; f2 = 320; break;
case 480: f1 = 20; f2 = 283; break;
static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
{
AVIOContext *pb = s->pb;
- int profile_and_level = (st->codec->profile<<4) | st->codec->level;
+ int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level;
mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
// bit rate
mxf_write_local_tag(pb, 4, 0x8000);
- avio_wb32(pb, st->codec->bit_rate);
+ avio_wb32(pb, st->codecpar->bit_rate);
// profile and level
mxf_write_local_tag(pb, 1, 0x8007);
- if (!st->codec->profile)
+ if (!st->codecpar->profile)
profile_and_level |= 0x80; // escape bit
avio_w8(pb, profile_and_level);
}
// write audio sampling rate
mxf_write_local_tag(pb, 8, 0x3D03);
- avio_wb32(pb, st->codec->sample_rate);
+ avio_wb32(pb, st->codecpar->sample_rate);
avio_wb32(pb, 1);
mxf_write_local_tag(pb, 4, 0x3D07);
- avio_wb32(pb, st->codec->channels);
+ avio_wb32(pb, st->codecpar->channels);
mxf_write_local_tag(pb, 4, 0x3D01);
- avio_wb32(pb, av_get_bits_per_sample(st->codec->codec_id));
+ avio_wb32(pb, av_get_bits_per_sample(st->codecpar->codec_id));
}
static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
mxf_write_generic_sound_common(s, st, key, size+6+8);
mxf_write_local_tag(pb, 2, 0x3D0A);
- avio_wb16(pb, st->codec->block_align);
+ avio_wb16(pb, st->codecpar->block_align);
// avg bytes per sec
mxf_write_local_tag(pb, 4, 0x3D09);
- avio_wb32(pb, st->codec->block_align*st->codec->sample_rate);
+ avio_wb32(pb, st->codecpar->block_align*st->codecpar->sample_rate);
}
static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st)
if (mxf->edit_unit_byte_count) {
klv_encode_ber_length(pb, 80);
} else {
- klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1)*6 +
- 12+mxf->edit_units_count*(11+mxf->slice_count*4));
+ klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1LL)*6 +
+ 12+mxf->edit_units_count*(11+mxf->slice_count*4LL));
}
// instance id
for (i = 0; i < mxf->edit_units_count; i++) {
int temporal_offset = 0;
- if (!(mxf->index_entries[i].flags & 0x33)) { // I frame
+ if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame
mxf->last_key_index = key_index;
key_index = i;
}
mxf->last_key_index = key_index;
}
- if (!(mxf->index_entries[i].flags & 0x33) && // I frame
+ if (!(mxf->index_entries[i].flags & 0x33) && // I-frame
mxf->index_entries[i].flags & 0x40 && !temporal_offset)
mxf->index_entries[i].flags |= 0x80; // random access
avio_w8(pb, mxf->index_entries[i].flags);
}
}
-static void mxf_write_partition(AVFormatContext *s, int bodysid,
+static int mxf_write_partition(AVFormatContext *s, int bodysid,
int indexsid,
const uint8_t *key, int write_metadata)
{
int64_t header_byte_count_offset;
unsigned index_byte_count = 0;
uint64_t partition_offset = avio_tell(pb);
+ int err;
if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
}
if (!memcmp(key, body_partition_key, 16)) {
- mxf->body_partition_offset =
- av_realloc(mxf->body_partition_offset,
- (mxf->body_partitions_count+1)*
- sizeof(*mxf->body_partition_offset));
+ if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1,
+ sizeof(*mxf->body_partition_offset))) < 0) {
+ mxf->body_partitions_count = 0;
+ return err;
+ }
mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
}
// write klv
avio_write(pb, key, 16);
- klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);
+ klv_encode_ber_length(pb, 88 + 16LL * mxf->essence_container_count);
// write partition value
avio_wb16(pb, 1); // majorVersion
}
avio_flush(pb);
+
+ return 0;
}
static const UID mxf_mpeg2_codec_uls[] = {
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
};
-static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx)
+static const UID *mxf_get_mpeg2_codec_ul(AVCodecParameters *par)
{
- int long_gop = avctx->gop_size > 1 || avctx->has_b_frames;
+ int long_gop = 1;
- if (avctx->profile == 4) { // Main
- if (avctx->level == 8) // Main
+ if (par->profile == 4) { // Main
+ if (par->level == 8) // Main
return &mxf_mpeg2_codec_uls[0+long_gop];
- else if (avctx->level == 4) // High
+ else if (par->level == 4) // High
return &mxf_mpeg2_codec_uls[4+long_gop];
- else if (avctx->level == 6) // High 14
+ else if (par->level == 6) // High 14
return &mxf_mpeg2_codec_uls[8+long_gop];
- } else if (avctx->profile == 0) { // 422
- if (avctx->level == 5) // Main
+ } else if (par->profile == 0) { // 422
+ if (par->level == 5) // Main
return &mxf_mpeg2_codec_uls[2+long_gop];
- else if (avctx->level == 2) // High
+ else if (par->level == 2) // High
return &mxf_mpeg2_codec_uls[6+long_gop];
}
return NULL;
c = (c<<8) + pkt->data[i];
if (c == 0x1b5) {
if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
- st->codec->profile = pkt->data[i+1] & 0x07;
- st->codec->level = pkt->data[i+2] >> 4;
+ st->codecpar->profile = pkt->data[i+1] & 0x07;
+ st->codecpar->level = pkt->data[i+2] >> 4;
} else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
break;
case 4: sc->aspect_ratio = (AVRational){221,100}; break;
default:
av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
- st->codec->width, st->codec->height, 1024*1024);
+ st->codecpar->width, st->codecpar->height, 1024*1024);
}
} else if (c == 0x100) { // pic
int pict_type = (pkt->data[i+2]>>3) & 0x07;
e->temporal_ref = (pkt->data[i+1]<<2) | (pkt->data[i+2]>>6);
- if (pict_type == 2) { // P frame
+ if (pict_type == 2) { // P-frame
e->flags |= 0x22;
- sc->closed_gop = 0; // reset closed gop, don't matter anymore
- } else if (pict_type == 3) { // B frame
+ sc->closed_gop = 0; // reset closed GOP, don't matter anymore
+ } else if (pict_type == 3) { // B-frame
if (sc->closed_gop)
e->flags |= 0x13; // only backward prediction
else
}
}
if (s->oformat != &ff_mxf_d10_muxer)
- sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec);
+ sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar);
return !!sc->codec_ul;
}
static uint64_t mxf_parse_timestamp(time_t timestamp)
{
- struct tm *time = gmtime(×tamp);
+ struct tm tmbuf;
+ struct tm *time = gmtime_r(×tamp, &tmbuf);
if (!time)
return 0;
return (uint64_t)(time->tm_year+1900) << 48 |
return AVERROR(ENOMEM);
st->priv_data = sc;
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
if (i != 0) {
av_log(s, AV_LOG_ERROR, "video stream must be first track\n");
return -1;
}
- if (fabs(av_q2d(st->codec->time_base) - 1/25.0) < 0.0001) {
+ // TODO: should be avg_frame_rate
+ if (fabs(av_q2d(st->time_base) - 1/25.0) < 0.0001) {
samples_per_frame = PAL_samples_per_frame;
mxf->time_base = (AVRational){ 1, 25 };
mxf->timecode_base = 25;
- } else if (fabs(av_q2d(st->codec->time_base) - 1001/30000.0) < 0.0001) {
+ } else if (fabs(av_q2d(st->time_base) - 1001/30000.0) < 0.0001) {
samples_per_frame = NTSC_samples_per_frame;
mxf->time_base = (AVRational){ 1001, 30000 };
mxf->timecode_base = 30;
}
avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
if (s->oformat == &ff_mxf_d10_muxer) {
- if (st->codec->bit_rate == 50000000)
+ if (st->codecpar->bit_rate == 50000000)
if (mxf->time_base.den == 25) sc->index = 3;
else sc->index = 5;
- else if (st->codec->bit_rate == 40000000)
+ else if (st->codecpar->bit_rate == 40000000)
if (mxf->time_base.den == 25) sc->index = 7;
else sc->index = 9;
- else if (st->codec->bit_rate == 30000000)
+ else if (st->codecpar->bit_rate == 30000000)
if (mxf->time_base.den == 25) sc->index = 11;
else sc->index = 13;
else {
}
mxf->edit_unit_byte_count = KAG_SIZE; // system element
- mxf->edit_unit_byte_count += 16 + 4 + (uint64_t)st->codec->bit_rate *
+ mxf->edit_unit_byte_count += 16 + 4 + (uint64_t)st->codecpar->bit_rate *
mxf->time_base.num / (8*mxf->time_base.den);
mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
mxf->edit_unit_byte_count += 16 + 4 + 4 + samples_per_frame[0]*8*4;
mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
}
- } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- if (st->codec->sample_rate != 48000) {
+ } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (st->codecpar->sample_rate != 48000) {
av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n");
return -1;
}
- avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
if (s->oformat == &ff_mxf_d10_muxer) {
if (st->index != 1) {
av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n");
return -1;
}
- if (st->codec->codec_id != CODEC_ID_PCM_S16LE &&
- st->codec->codec_id != CODEC_ID_PCM_S24LE) {
+ if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE &&
+ st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) {
av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
}
sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1;
}
if (!sc->index) {
- sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
+ sc->index = mxf_get_essence_container_ul_index(st->codecpar->codec_id);
if (sc->index == -1) {
av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
"codec not currently supported in container\n", i);
mxf->essence_container_count = 1;
}
- if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
+ if (!(s->flags & AVFMT_FLAG_BITEXACT))
mxf_gen_umid(s);
for (i = 0; i < s->nb_streams; i++) {
sc->order = AV_RB32(sc->track_essence_element_key+12);
}
-#if FF_API_TIMESTAMP
- if (s->timestamp)
- timestamp = s->timestamp;
- else
-#endif
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
timestamp = ff_iso8601_to_unix_time(t->value);
if (timestamp)
static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 };
static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 };
-static uint32_t ff_framenum_to_12m_time_code(unsigned frame, int drop, int fps)
+static uint32_t framenum_to_12m_time_code(unsigned frame, int drop, int fps)
{
return (0 << 31) | // color frame flag
(drop << 30) | // drop frame flag
avio_wb64(pb, 0); // creation date/time stamp
avio_w8(pb, 0x81); // SMPTE 12M time code
- time_code = ff_framenum_to_12m_time_code(frame, mxf->timecode_drop_frame, mxf->timecode_base);
+ time_code = framenum_to_12m_time_code(frame, mxf->timecode_drop_frame,
+ mxf->timecode_base);
avio_wb32(pb, time_code);
avio_wb32(pb, 0); // binary group data
avio_wb64(pb, 0);
{
MXFContext *mxf = s->priv_data;
AVIOContext *pb = s->pb;
- int packet_size = (uint64_t)st->codec->bit_rate*mxf->time_base.num /
+ int packet_size = (uint64_t)st->codecpar->bit_rate*mxf->time_base.num /
(8*mxf->time_base.den); // frame size
int pad;
{
MXFContext *mxf = s->priv_data;
AVIOContext *pb = s->pb;
- int frame_size = pkt->size / st->codec->block_align;
+ int frame_size = pkt->size / st->codecpar->block_align;
uint8_t *samples = pkt->data;
uint8_t *end = pkt->data + pkt->size;
int i;
avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
avio_wl16(pb, frame_size);
- avio_w8(pb, (1<<st->codec->channels)-1);
+ avio_w8(pb, (1<<st->codecpar->channels)-1);
while (samples < end) {
- for (i = 0; i < st->codec->channels; i++) {
+ for (i = 0; i < st->codecpar->channels; i++) {
uint32_t sample;
- if (st->codec->codec_id == CODEC_ID_PCM_S24LE) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) {
sample = AV_RL24(samples)<< 4;
samples += 3;
} else {
AVStream *st = s->streams[pkt->stream_index];
MXFStreamContext *sc = st->priv_data;
MXFIndexEntry ie = {0};
+ int err;
if (!mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {
- mxf->index_entries = av_realloc(mxf->index_entries,
- (mxf->edit_units_count + EDIT_UNITS_PER_BODY)*sizeof(*mxf->index_entries));
- if (!mxf->index_entries) {
+ if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count
+ + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {
+ mxf->edit_units_count = 0;
av_log(s, AV_LOG_ERROR, "could not allocate index entries\n");
- return -1;
+ return err;
}
}
- if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
return -1;
if (!mxf->header_written) {
if (mxf->edit_unit_byte_count) {
- mxf_write_partition(s, 1, 2, header_open_partition_key, 1);
+ if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0)
+ return err;
mxf_write_klv_fill(s);
mxf_write_index_table_segment(s);
} else {
- mxf_write_partition(s, 0, 0, header_open_partition_key, 1);
+ if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
+ return err;
}
mxf->header_written = 1;
}
if (st->index == 0) {
if (!mxf->edit_unit_byte_count &&
(!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) &&
- !(ie.flags & 0x33)) { // I frame, Gop start
+ !(ie.flags & 0x33)) { // I-frame, GOP start
mxf_write_klv_fill(s);
- mxf_write_partition(s, 1, 2, body_partition_key, 0);
-
+ if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0)
+ return err;
mxf_write_klv_fill(s);
mxf_write_index_table_segment(s);
}
mxf_write_klv_fill(s);
avio_write(pb, sc->track_essence_element_key, 16); // write key
if (s->oformat == &ff_mxf_d10_muxer) {
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
mxf_write_d10_video_packet(s, st, pkt);
else
mxf_write_d10_audio_packet(s, st, pkt);
int i;
avio_write(pb, random_index_pack_key, 16);
- klv_encode_ber_length(pb, 28 + 12*mxf->body_partitions_count);
+ klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count);
if (mxf->edit_unit_byte_count)
avio_wb32(pb, 1); // BodySID of header partition
{
MXFContext *mxf = s->priv_data;
AVIOContext *pb = s->pb;
+ int err;
mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count;
mxf_write_klv_fill(s);
mxf->footer_partition_offset = avio_tell(pb);
if (mxf->edit_unit_byte_count) { // no need to repeat index
- mxf_write_partition(s, 0, 0, footer_partition_key, 0);
+ if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)
+ return err;
} else {
- mxf_write_partition(s, 0, 2, footer_partition_key, 0);
-
+ if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)
+ return err;
mxf_write_klv_fill(s);
mxf_write_index_table_segment(s);
}
mxf_write_klv_fill(s);
mxf_write_random_index_pack(s);
- if (s->pb->seekable) {
+ if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
avio_seek(pb, 0, SEEK_SET);
if (mxf->edit_unit_byte_count) {
- mxf_write_partition(s, 1, 2, header_closed_partition_key, 1);
+ if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0)
+ return err;
mxf_write_klv_fill(s);
mxf_write_index_table_segment(s);
} else {
- mxf_write_partition(s, 0, 0, header_closed_partition_key, 1);
+ if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0)
+ return err;
}
}
- avio_flush(pb);
-
ff_audio_interleave_close(s);
av_freep(&mxf->index_entries);
stream_count += !!s->streams[i]->last_in_packet_buffer;
if (stream_count && (s->nb_streams == stream_count || flush)) {
- AVPacketList *pktl = s->packet_buffer;
+ AVPacketList *pktl = s->internal->packet_buffer;
if (s->nb_streams != stream_count) {
AVPacketList *last = NULL;
// find last packet in edit unit
if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
- av_free_packet(&pktl->pkt);
+ av_packet_unref(&pktl->pkt);
av_freep(&pktl);
pktl = next;
}
if (last)
last->next = NULL;
else {
- s->packet_buffer = NULL;
- s->packet_buffer_end= NULL;
+ s->internal->packet_buffer = NULL;
+ s->internal->packet_buffer_end= NULL;
goto out;
}
- pktl = s->packet_buffer;
+ pktl = s->internal->packet_buffer;
}
*out = pktl->pkt;
- //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts);
- s->packet_buffer = pktl->next;
+ av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts);
+ s->internal->packet_buffer = pktl->next;
if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
- if(!s->packet_buffer)
- s->packet_buffer_end= NULL;
+ if(!s->internal->packet_buffer)
+ s->internal->packet_buffer_end= NULL;
av_freep(&pktl);
return 1;
} else {
AVOutputFormat ff_mxf_muxer = {
.name = "mxf",
- .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format"),
+ .long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"),
.mime_type = "application/mxf",
.extensions = "mxf",
.priv_data_size = sizeof(MXFContext),
- .audio_codec = CODEC_ID_PCM_S16LE,
- .video_codec = CODEC_ID_MPEG2VIDEO,
+ .audio_codec = AV_CODEC_ID_PCM_S16LE,
+ .video_codec = AV_CODEC_ID_MPEG2VIDEO,
.write_header = mxf_write_header,
.write_packet = mxf_write_packet,
.write_trailer = mxf_write_footer,
AVOutputFormat ff_mxf_d10_muxer = {
.name = "mxf_d10",
- .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"),
+ .long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) D-10 Mapping"),
.mime_type = "application/mxf",
.priv_data_size = sizeof(MXFContext),
- .audio_codec = CODEC_ID_PCM_S16LE,
- .video_codec = CODEC_ID_MPEG2VIDEO,
+ .audio_codec = AV_CODEC_ID_PCM_S16LE,
+ .video_codec = AV_CODEC_ID_MPEG2VIDEO,
.write_header = mxf_write_header,
.write_packet = mxf_write_packet,
.write_trailer = mxf_write_footer,