summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/cbs_mpeg2.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 2bf38c6001..11c43c2a47 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -149,7 +149,6 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
uint32_t start_code = -1;
size_t unit_size;
int err;
- int final = 0;
start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
&start_code);
@@ -161,14 +160,11 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
do {
unit_type = start_code & 0xff;
- if (start == frag->data + frag->data_size) {
- // The last four bytes form a start code which constitutes
- // a unit of its own. In this situation avpriv_find_start_code
- // won't modify start_code at all so modify start_code so that
- // the next unit will be treated as the last unit.
- start_code = 0;
- }
-
+ // Reset start_code to ensure that avpriv_find_start_code()
+ // really reads a new start code and does not reuse the old
+ // start code in any way (as e.g. happens when there is a
+ // Sequence End unit at the very end of a packet).
+ start_code = UINT32_MAX;
end = avpriv_find_start_code(start--, frag->data + frag->data_size,
&start_code);
@@ -183,7 +179,6 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
} else {
// We didn't find a start code, so this is the final unit.
unit_size = end - start;
- final = 1;
}
err = ff_cbs_append_unit_data(frag, unit_type, (uint8_t*)start,
@@ -192,7 +187,9 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
return err;
start = end;
- } while (!final);
+
+ // Do we have a further unit to add to the fragment?
+ } while ((start_code >> 8) == 0x000001);
return 0;
}