mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-02 03:06:28 +02:00
lavf/mxfdec: Speed up klv_read_packet()
This commit is contained in:
parent
262e6f8430
commit
e3fa469a55
@ -458,10 +458,26 @@ static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size)
|
|||||||
return i == size;
|
return i == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// special case of mxf_read_sync for mxf_klv_key
|
||||||
|
static int mxf_read_sync_klv(AVIOContext *pb)
|
||||||
|
{
|
||||||
|
uint32_t key = avio_rb32(pb);
|
||||||
|
// key will never match mxf_klv_key on EOF
|
||||||
|
if (key == AV_RB32(mxf_klv_key))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
while (!avio_feof(pb)) {
|
||||||
|
key = (key << 8) | avio_r8(pb);
|
||||||
|
if (key == AV_RB32(mxf_klv_key))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int klv_read_packet(MXFContext *mxf, KLVPacket *klv, AVIOContext *pb)
|
static int klv_read_packet(MXFContext *mxf, KLVPacket *klv, AVIOContext *pb)
|
||||||
{
|
{
|
||||||
int64_t length, pos;
|
int64_t length, pos;
|
||||||
if (!mxf_read_sync(pb, mxf_klv_key, 4))
|
if (!mxf_read_sync_klv(pb))
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
klv->offset = avio_tell(pb) - 4;
|
klv->offset = avio_tell(pb) - 4;
|
||||||
if (klv->offset < mxf->run_in)
|
if (klv->offset < mxf->run_in)
|
||||||
@ -3982,6 +3998,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
ret = klv_read_packet(mxf, &klv, s->pb);
|
ret = klv_read_packet(mxf, &klv, s->pb);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
// klv.key[0..3] == mxf_klv_key from here forward
|
||||||
max_data_size = klv.length;
|
max_data_size = klv.length;
|
||||||
pos = klv.next_klv - klv.length;
|
pos = klv.next_klv - klv.length;
|
||||||
PRINT_KEY(s, "read packet", klv.key);
|
PRINT_KEY(s, "read packet", klv.key);
|
||||||
|
Loading…
Reference in New Issue
Block a user