* MXF demuxer.
* Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//#define DEBUG
#include "libavutil/aes.h"
+#include "libavutil/mathematics.h"
#include "libavcodec/bytestream.h"
#include "avformat.h"
#include "mxf.h"
static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size)
{
int i, b;
- for (i = 0; i < size && !url_feof(pb); i++) {
+ for (i = 0; i < size && !pb->eof_reached; i++) {
b = avio_r8(pb);
if (b == key[0])
i = 0;
{
if (!mxf_read_sync(pb, mxf_klv_key, 4))
return -1;
- klv->offset = url_ftell(pb) - 4;
+ klv->offset = avio_tell(pb) - 4;
memcpy(klv->key, mxf_klv_key, 4);
avio_read(pb, klv->key + 4, 12);
klv->length = klv_decode_ber_length(pb);
static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b};
MXFContext *mxf = s->priv_data;
AVIOContext *pb = s->pb;
- int64_t end = url_ftell(pb) + klv->length;
+ int64_t end = avio_tell(pb) + klv->length;
uint64_t size;
uint64_t orig_size;
uint64_t plaintext_size;
av_aes_init(mxf->aesc, s->key, 128, 1);
}
// crypto context
- url_fskip(pb, klv_decode_ber_length(pb));
+ avio_skip(pb, klv_decode_ber_length(pb));
// plaintext offset
klv_decode_ber_length(pb);
plaintext_size = avio_rb64(pb);
&pkt->data[plaintext_size], size >> 4, ivec, 1);
pkt->size = orig_size;
pkt->stream_index = index;
- url_fskip(pb, end - url_ftell(pb));
+ avio_skip(pb, end - avio_tell(pb));
return 0;
}
{
KLVPacket klv;
- while (!url_feof(s->pb)) {
+ while (!s->pb->eof_reached) {
if (klv_read_packet(&klv, s->pb) < 0)
return -1;
PRINT_KEY(s, "read packet", klv.key);
- av_dlog(s, "size %lld offset %#llx\n", klv.length, klv.offset);
+ av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);
if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {
int res = mxf_decrypt_triplet(s, pkt, &klv);
if (res < 0) {
return 0;
} else
skip:
- url_fskip(s->pb, klv.length);
+ avio_skip(s->pb, klv.length);
}
return AVERROR_EOF;
}
mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID));
if (!mxf->packages_refs)
return -1;
- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
break;
}
break;
case 0x1101:
/* UMID, only get last 16 bytes */
- url_fskip(pb, 16);
+ avio_skip(pb, 16);
avio_read(pb, source_clip->source_package_uid, 16);
break;
case 0x1102:
package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
if (!package->tracks_refs)
return -1;
- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
break;
}
sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID));
if (!sequence->structural_components_refs)
return -1;
- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
break;
}
package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
if (!package->tracks_refs)
return -1;
- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
break;
case 0x4401:
/* UMID, only get last 16 bytes */
- url_fskip(pb, 16);
+ avio_skip(pb, 16);
avio_read(pb, package->package_uid, 16);
break;
case 0x4701:
case 0x3F06: av_dlog(NULL, "IndexSID %d\n", avio_rb32(pb)); break;
case 0x3F07: av_dlog(NULL, "BodySID %d\n", avio_rb32(pb)); break;
case 0x3F0B: av_dlog(NULL, "IndexEditRate %d/%d\n", avio_rb32(pb), avio_rb32(pb)); break;
- case 0x3F0C: av_dlog(NULL, "IndexStartPosition %lld\n", avio_rb64(pb)); break;
- case 0x3F0D: av_dlog(NULL, "IndexDuration %lld\n", avio_rb64(pb)); break;
+ case 0x3F0C: av_dlog(NULL, "IndexStartPosition %"PRIu64"\n", avio_rb64(pb)); break;
+ case 0x3F0D: av_dlog(NULL, "IndexDuration %"PRIu64"\n", avio_rb64(pb)); break;
}
return 0;
}
descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));
if (!descriptor->sub_descriptors_refs)
return -1;
- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
break;
case 0x3004:
default:
/* Private uid used by SONY C0023S01.mxf */
if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) {
- descriptor->extradata = av_malloc(size);
+ descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!descriptor->extradata)
return -1;
descriptor->extradata_size = size;
{
AVIOContext *pb = mxf->fc->pb;
MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf;
- uint64_t klv_end = url_ftell(pb) + klv->length;
+ uint64_t klv_end = avio_tell(pb) + klv->length;
if (!ctx)
return -1;
- while (url_ftell(pb) + 4 < klv_end) {
+ while (avio_tell(pb) + 4 < klv_end) {
int tag = avio_rb16(pb);
int size = avio_rb16(pb); /* KLV specified by 0x53 */
- uint64_t next = url_ftell(pb) + size;
+ uint64_t next = avio_tell(pb) + size;
UID uid = {0};
av_dlog(mxf->fc, "local tag %#04x size %d\n", tag, size);
}
avio_seek(s->pb, -14, SEEK_CUR);
mxf->fc = s;
- while (!url_feof(s->pb)) {
+ while (!s->pb->eof_reached) {
const MXFMetadataReadTableEntry *metadata;
if (klv_read_packet(&klv, s->pb) < 0)
return -1;
PRINT_KEY(s, "read header", klv.key);
- av_dlog(s, "size %lld offset %#llx\n", klv.length, klv.offset);
+ av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);
if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
/* FIXME avoid seek */
}
}
if (!metadata->read)
- url_fskip(s->pb, klv.length);
+ avio_skip(s->pb, klv.length);
}
return mxf_parse_structural_metadata(mxf);
}
}
AVInputFormat ff_mxf_demuxer = {
- "mxf",
- NULL_IF_CONFIG_SMALL("Material eXchange Format"),
- sizeof(MXFContext),
- mxf_probe,
- mxf_read_header,
- mxf_read_packet,
- mxf_read_close,
- mxf_read_seek,
+ .name = "mxf",
+ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format"),
+ .priv_data_size = sizeof(MXFContext),
+ .read_probe = mxf_probe,
+ .read_header = mxf_read_header,
+ .read_packet = mxf_read_packet,
+ .read_close = mxf_read_close,
+ .read_seek = mxf_read_seek,
};