aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-07-29 21:56:55 +0200
committerJames Almer <jamrial@gmail.com>2019-12-31 16:57:37 -0300
commitc1fb94fcacf3208ea8396953351a00af56e3f336 (patch)
treec14ba9980255af8e9ca871317ad3bbc5007f8aa1
parent2852aa50842dae99fc1f2988e256fef1052e7b57 (diff)
downloadffmpeg-c1fb94fcacf3208ea8396953351a00af56e3f336.tar.gz
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 276b21a586900b4692efbb99e4789e05d927708e)
-rw-r--r--libavcodec/cbs_mpeg2.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 9a8603e8c2..464bd7add7 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -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;
}