86 uint8_t track_number[4];
155 static const uint8_t
mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
156 static const uint8_t
mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
159 static const uint8_t
mxf_crypto_source_container_ul[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 };
160 static const uint8_t
mxf_encrypted_triplet_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 };
161 static const uint8_t
mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 };
162 static const uint8_t
mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 };
164 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
170 int bytes_num = size & 0x7f;
176 size = size << 8 |
avio_r8(pb);
188 else if (b != key[i])
202 return klv->
length == -1 ? -1 : 0;
222 const uint8_t *buf_ptr, *end_ptr;
231 data_ptr = pkt->
data;
232 end_ptr = pkt->
data + length;
233 buf_ptr = pkt->
data + 4;
236 uint32_t sample = bytestream_get_le32(&buf_ptr);
238 bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff);
240 bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff);
250 static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b};
256 uint64_t plaintext_size;
283 if (orig_size < plaintext_size)
287 if (size < 32 || size - 32 < orig_size)
293 if (memcmp(tmpbuf, checkv, 16))
299 else if (size < plaintext_size)
301 size -= plaintext_size;
304 &pkt->
data[plaintext_size], size >> 4, ivec, 1);
338 if (klv.
key[12] == 0x06 && klv.
key[13] == 0x01 && klv.
key[14] == 0x10) {
364 if (item_len != 18) {
369 if (item_num > UINT_MAX / item_len)
447 if (package->tracks_count >= UINT_MAX /
sizeof(
UID))
449 package->tracks_refs =
av_malloc(package->tracks_count *
sizeof(
UID));
450 if (!package->tracks_refs)
453 avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count *
sizeof(
UID));
510 if (package->tracks_count >= UINT_MAX /
sizeof(
UID))
512 package->tracks_refs =
av_malloc(package->tracks_count *
sizeof(
UID));
513 if (!package->tracks_refs)
516 avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count *
sizeof(
UID));
524 avio_read(pb, package->descriptor_ref, 16);
545 int code, value, ofs = 0;
554 layout[ofs++] = code;
555 layout[ofs++] = value;
632 for (i = 0; i <
len; i++) {
633 if (i != 7 && key[i] != uid[i])
641 while (uls->
uid[0]) {
666 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, 14,
CODEC_ID_MPEG2VIDEO },
667 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, 14,
CODEC_ID_DVVIDEO },
669 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, 14,
CODEC_ID_PCM_S16LE },
670 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, 14,
CODEC_ID_MP2 },
671 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, 14,
CODEC_ID_PCM_S16LE },
672 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
CODEC_ID_NONE },
685 if (material_package)
break;
687 if (!material_package) {
699 UID *essence_container_ul =
NULL;
726 source_package = temp_package;
730 if (!source_package) {
740 source_track = temp_track;
780 if (!sub_descriptor) {
785 descriptor = sub_descriptor;
806 essence_container_ul = &((
MXFCryptoContext *)metadata)->source_container_ul;
819 container_ul =
mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul);
828 container_ul =
mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul);
838 "found for stream #%d, time base forced to 1/48000\n",
868 { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 },
mxf_read_primer_pack },
869 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 },
mxf_read_content_storage, 0,
AnyType },
870 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 },
mxf_read_source_package,
sizeof(
MXFPackage),
SourcePackage },
871 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 },
mxf_read_material_package,
sizeof(
MXFPackage),
MaterialPackage },
872 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 },
mxf_read_sequence,
sizeof(
MXFSequence),
Sequence },
873 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 },
mxf_read_source_clip,
sizeof(
MXFStructuralComponent),
SourceClip },
874 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
MultipleDescriptor },
875 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
876 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
877 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
878 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
879 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
880 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
881 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 },
mxf_read_track,
sizeof(
MXFTrack),
Track },
882 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 },
mxf_read_track,
sizeof(
MXFTrack),
Track },
883 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 },
mxf_read_cryptographic_context,
sizeof(
MXFCryptoContext),
CryptoContext },
884 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 },
mxf_read_index_table_segment,
sizeof(
MXFIndexTableSegment),
IndexTableSegment },
885 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
NULL, 0,
AnyType },
903 av_dlog(mxf->
fc,
"local tag %#04x size %d\n", tag, size);
912 if (local_tag == tag) {
914 av_dlog(mxf->
fc,
"local tag %#04x\n", local_tag);
919 if (ctx_size && tag == 0x3C0A)
921 else if ((ret = read_child(ctx, pb, tag, size, uid)) < 0)
926 if (ctx_size) ctx->
type = type;
956 for (metadata = mxf_metadata_read_table; metadata->
read; metadata++) {
959 if (klv.
key[5] == 0x53) {
1010 uint8_t *bufp = p->
buf;
1018 for (; bufp < end; bufp++) {
1034 if (sample_time < 0)
static const uint8_t mxf_crypto_source_container_ul[]
int MXFMetadataReadFunc(void *arg, AVIOContext *pb, int tag, int size, UID uid)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
struct MXFContext MXFContext
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
static int mxf_parse_structural_metadata(MXFContext *mxf)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
static int mxf_read_source_clip(void *arg, AVIOContext *pb, int tag, int size, UID uid)
AV_WL32 AV_WL24 AV_WL16 AV_RB32
static const MXFMetadataReadTableEntry mxf_metadata_read_table[]
#define PRINT_KEY(pc, s, x)
static int klv_read_packet(KLVPacket *klv, AVIOContext *pb)
UID * structural_components_refs
int64_t pos
byte position in stream, -1 if unknown
static int mxf_probe(AVProbeData *p)
#define AV_LOG_WARNING
Something somehow does not look correct.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
int index
stream index in AVFormatContext
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
enum MXFMetadataSetType type
void av_aes_crypt(AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
Encrypt or decrypt a buffer using a previously initialized context.
static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
unsigned int avio_rb16(AVIOContext *s)
static const MXFCodecUL mxf_essence_container_uls[]
static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int size, UID uid)
enum MXFMetadataSetType type
static int mxf_read_content_storage(void *arg, AVIOContext *pb, int tag, int size, UID uid)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadFunc *read_child, int ctx_size, enum MXFMetadataSetType type)
static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
Opaque data information usually continuous.
unsigned int avio_rb32(AVIOContext *s)
enum AVStreamParseType need_parsing
int id
format-specific stream ID
static int mxf_read_close(AVFormatContext *s)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int mxf_read_track(void *arg, AVIOContext *pb, int tag, int size, UID uid)
static const uint8_t mxf_klv_key[]
static int read_header(FFV1Context *f)
const MXFCodecUL ff_mxf_codec_uls[]
static int mxf_read_primer_pack(void *arg, AVIOContext *pb, int tag, int size, UID uid)
static const uint8_t mxf_sony_mpeg4_extradata[]
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
preferred ID for MPEG-1/2 video decoding
static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size)
static void mxf_read_pixel_layout(AVIOContext *pb, MXFDescriptor *descriptor)
MXFDescriptor * descriptor
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int mxf_read_sequence(void *arg, AVIOContext *pb, int tag, int size, UID uid)
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
static AVDictionary * metadata
static int mxf_match_uid(const UID key, const UID uid, int len)
int avio_r8(AVIOContext *s)
AVCodecContext * codec
codec context
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
A list of all streams in the file.
static const MXFCodecUL * mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid)
static const uint8_t mxf_essence_element_key[]
static void * mxf_resolve_strong_ref(MXFContext *mxf, UID *strong_ref, enum MXFMetadataSetType type)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static const uint8_t mxf_encrypted_triplet_key[]
int width
picture width / height.
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static const uint8_t mxf_header_partition_pack_key[]
static int read_probe(AVProbeData *p)
static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv)
static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv)
const MXFCodecUL ff_mxf_data_definition_uls[]
SMPTE RP224 http://www.smpte-ra.org/mdd/index.html.
UID * sub_descriptors_refs
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
Initialize an AVAES context.
enum AVMediaType codec_type
static int mxf_read_material_package(void *arg, AVIOContext *pb, int tag, int size, UID uid)
int sub_descriptors_count
int sample_rate
samples per second
static const uint8_t mxf_encrypted_essence_container[]
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum PixelFormat *pix_fmt)
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
rational number numerator/denominator
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
This structure contains the data a format has to probe a file.
static int64_t klv_decode_ber_length(AVIOContext *pb)
static int mxf_read_cryptographic_context(void *arg, AVIOContext *pb, int tag, int size, UID uid)
int64_t duration
Decoding: duration of the stream, in stream time base.
static int mxf_read_index_table_segment(void *arg, AVIOContext *pb, int tag, int size, UID uid)
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
MXFMetadataReadFunc * read
AVInputFormat ff_mxf_demuxer
int structural_components_count
int eof_reached
true if eof reached
int channels
number of audio channels
static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
void * priv_data
Format private data.
static int mxf_read_source_package(void *arg, AVIOContext *pb, int tag, int size, UID uid)
int bit_rate
Decoding: total stream bitrate in bit/s, 0 if not available.
MXFMetadataSet ** metadata_sets
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
#define AV_NOPTS_VALUE
Undefined timestamp value.