Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-07-29 22:56:55 +0300
committerMark Thompson <sw@jkqxz.net>2019-07-30 00:25:10 +0300
commit276b21a586900b4692efbb99e4789e05d927708e (patch)
tree8701407fcf9cf4241a9e78ba6be39df5a3c7fb4c /libavcodec/cbs_mpeg2.c
parent0e66e1b61ea2fd8fd85ebe3b86ff48dad78233dd (diff)
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>
Diffstat (limited to 'libavcodec/cbs_mpeg2.c')
-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 9a584246c9..c529038fd9 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;
}