mirror of https://git.ffmpeg.org/ffmpeg.git
cbs_mpeg2: Rearrange start code search
1. Currently, cbs_mpeg2_split_fragment uses essentially three variables
to hold the start code values found by avpriv_find_start_code. By
rearranging the code, one of them can be omitted.
2. The return value of avpriv_find_start_code points to the byte after
the byte containing the start code identifier (or to the byte after the
last byte of the fragment's data if no start code was found), but
cbs_mpeg2_split_fragment needs to work with the pointer to the byte
containing the start code identifier; it already did this, but in a
clumsy way. This has been changed.
3. Also use the correct type for the variable holding the
CodedBitstreamUnitType.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 276b21a586
)
This commit is contained in:
parent
2852aa5084
commit
c1fb94fcac
|
@ -167,41 +167,40 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
|
|||
int header)
|
||||
{
|
||||
const uint8_t *start, *end;
|
||||
uint8_t *unit_data;
|
||||
uint32_t start_code = -1, next_start_code = -1;
|
||||
CodedBitstreamUnitType unit_type;
|
||||
uint32_t start_code = -1;
|
||||
size_t unit_size;
|
||||
int err, i, unit_type;
|
||||
int err, i;
|
||||
|
||||
start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
|
||||
&start_code);
|
||||
for (i = 0;; i++) {
|
||||
end = avpriv_find_start_code(start, frag->data + frag->data_size,
|
||||
&next_start_code);
|
||||
|
||||
unit_type = start_code & 0xff;
|
||||
|
||||
// The start and end pointers point at to the byte following the
|
||||
// start_code_identifier in the start code that they found.
|
||||
end = avpriv_find_start_code(start--, frag->data + frag->data_size,
|
||||
&start_code);
|
||||
|
||||
// start points to the byte containing the start_code_identifier
|
||||
// (or to the last byte of fragment->data); end points to the byte
|
||||
// following the byte containing the start code identifier (or to
|
||||
// the end of fragment->data).
|
||||
if (end == frag->data + frag->data_size) {
|
||||
// We didn't find a start code, so this is the final unit.
|
||||
unit_size = end - (start - 1);
|
||||
unit_size = end - start;
|
||||
} else {
|
||||
// Unit runs from start to the beginning of the start code
|
||||
// pointed to by end (including any padding zeroes).
|
||||
unit_size = (end - 4) - (start - 1);
|
||||
unit_size = (end - 4) - start;
|
||||
}
|
||||
|
||||
unit_data = (uint8_t *)start - 1;
|
||||
|
||||
err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type,
|
||||
unit_data, unit_size, frag->data_ref);
|
||||
err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type, (uint8_t*)start,
|
||||
unit_size, frag->data_ref);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (end == frag->data + frag->data_size)
|
||||
break;
|
||||
|
||||
start_code = next_start_code;
|
||||
start = end;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue