+static MXFIndexTable *mxf_find_index_table(MXFContext *mxf, int index_sid)
+{
+ int i;
+ for (i = 0; i < mxf->nb_index_tables; i++)
+ if (mxf->index_tables[i].index_sid == index_sid)
+ return &mxf->index_tables[i];
+ return NULL;
+}
+
+/* Get the edit unit of the next packet from current_offset in a track. The returned edit unit can be original_duration as well! */
+static int mxf_get_next_track_edit_unit(MXFContext *mxf, MXFTrack *track, int64_t current_offset, int64_t *edit_unit_out)
+{
+ int64_t a, b, m, offset;
+ MXFIndexTable *t = mxf_find_index_table(mxf, track->index_sid);
+
+ if (!t || track->original_duration <= 0)
+ return -1;
+
+ a = -1;
+ b = track->original_duration;
+
+ while (b - a > 1) {
+ m = (a + b) >> 1;
+ if (mxf_edit_unit_absolute_offset(mxf, t, m, NULL, &offset, 0) < 0)
+ return -1;
+ if (offset < current_offset)
+ a = m;
+ else
+ b = m;
+ }
+
+ *edit_unit_out = b;
+
+ return 0;
+}
+