mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
avformat/mxfdec: use binary search in mxf_absolute_bodysid_offset
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
3aaf97e773
commit
90756e67a0
@ -1347,24 +1347,30 @@ static int mxf_get_sorted_table_segments(MXFContext *mxf, int *nb_sorted_segment
|
|||||||
*/
|
*/
|
||||||
static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t offset, int64_t *offset_out)
|
static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t offset, int64_t *offset_out)
|
||||||
{
|
{
|
||||||
int x;
|
|
||||||
MXFPartition *last_p = NULL;
|
MXFPartition *last_p = NULL;
|
||||||
|
int a, b, m, m0;
|
||||||
|
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
for (x = 0; x < mxf->partitions_count; x++) {
|
a = -1;
|
||||||
MXFPartition *p = &mxf->partitions[x];
|
b = mxf->partitions_count;
|
||||||
|
|
||||||
if (p->body_sid != body_sid)
|
while (b - a > 1) {
|
||||||
continue;
|
m0 = m = (a + b) >> 1;
|
||||||
|
|
||||||
if (p->body_offset > offset)
|
while (m < b && mxf->partitions[m].body_sid != body_sid)
|
||||||
break;
|
m++;
|
||||||
|
|
||||||
last_p = p;
|
if (m < b && mxf->partitions[m].body_offset <= offset)
|
||||||
|
a = m;
|
||||||
|
else
|
||||||
|
b = m0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a >= 0)
|
||||||
|
last_p = &mxf->partitions[a];
|
||||||
|
|
||||||
if (last_p && (!last_p->essence_length || last_p->essence_length > (offset - last_p->body_offset))) {
|
if (last_p && (!last_p->essence_length || last_p->essence_length > (offset - last_p->body_offset))) {
|
||||||
*offset_out = last_p->essence_offset + (offset - last_p->body_offset);
|
*offset_out = last_p->essence_offset + (offset - last_p->body_offset);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user