Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/av1_parse.c |
Date: | 2022-07-05 19:52:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 38 | 45 | 84.4% |
Branches: | 12 | 20 | 60.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * AV1 common parsing code | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include "config.h" | ||
22 | |||
23 | #include "libavutil/mem.h" | ||
24 | |||
25 | #include "av1.h" | ||
26 | #include "av1_parse.h" | ||
27 | #include "bytestream.h" | ||
28 | |||
29 | 76 | int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx) | |
30 | { | ||
31 | int64_t obu_size; | ||
32 | int start_pos, type, temporal_id, spatial_id; | ||
33 | int len; | ||
34 | |||
35 | 76 | len = parse_obu_header(buf, length, &obu_size, &start_pos, | |
36 | &type, &temporal_id, &spatial_id); | ||
37 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (len < 0) |
38 | ✗ | return len; | |
39 | |||
40 | 76 | obu->type = type; | |
41 | 76 | obu->temporal_id = temporal_id; | |
42 | 76 | obu->spatial_id = spatial_id; | |
43 | |||
44 | 76 | obu->data = buf + start_pos; | |
45 | 76 | obu->size = obu_size; | |
46 | 76 | obu->raw_data = buf; | |
47 | 76 | obu->raw_size = len; | |
48 | |||
49 | 76 | av_log(logctx, AV_LOG_DEBUG, | |
50 | "obu_type: %d, temporal_id: %d, spatial_id: %d, payload size: %d\n", | ||
51 | obu->type, obu->temporal_id, obu->spatial_id, obu->size); | ||
52 | |||
53 | 76 | return len; | |
54 | } | ||
55 | |||
56 | 19 | int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *logctx) | |
57 | { | ||
58 | GetByteContext bc; | ||
59 | int ret, consumed; | ||
60 | |||
61 | 19 | bytestream2_init(&bc, buf, length); | |
62 | 19 | pkt->nb_obus = 0; | |
63 | |||
64 |
2/2✓ Branch 1 taken 76 times.
✓ Branch 2 taken 19 times.
|
95 | while (bytestream2_get_bytes_left(&bc) > 0) { |
65 | AV1OBU *obu; | ||
66 | |||
67 |
1/2✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
|
76 | if (pkt->obus_allocated < pkt->nb_obus + 1) { |
68 | 76 | int new_size = pkt->obus_allocated + 1; | |
69 | AV1OBU *tmp; | ||
70 | |||
71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (new_size >= INT_MAX / sizeof(*tmp)) |
72 | ✗ | return AVERROR(ENOMEM); | |
73 | 76 | tmp = av_fast_realloc(pkt->obus, &pkt->obus_allocated_size, new_size * sizeof(*tmp)); | |
74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (!tmp) |
75 | ✗ | return AVERROR(ENOMEM); | |
76 | |||
77 | 76 | pkt->obus = tmp; | |
78 | 76 | memset(pkt->obus + pkt->obus_allocated, 0, sizeof(*pkt->obus)); | |
79 | 76 | pkt->obus_allocated = new_size; | |
80 | } | ||
81 | 76 | obu = &pkt->obus[pkt->nb_obus]; | |
82 | |||
83 | 76 | consumed = ff_av1_extract_obu(obu, bc.buffer, bytestream2_get_bytes_left(&bc), logctx); | |
84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (consumed < 0) |
85 | ✗ | return consumed; | |
86 | |||
87 | 76 | bytestream2_skip(&bc, consumed); | |
88 | |||
89 | 76 | obu->size_bits = get_obu_bit_length(obu->data, obu->size, obu->type); | |
90 | |||
91 |
4/6✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
|
76 | if (obu->size_bits < 0 || (!obu->size_bits && obu->type != AV1_OBU_TEMPORAL_DELIMITER)) { |
92 | ✗ | av_log(logctx, AV_LOG_ERROR, "Invalid OBU of type %d, skipping.\n", obu->type); | |
93 | ✗ | continue; | |
94 | } | ||
95 | |||
96 | 76 | pkt->nb_obus++; | |
97 | |||
98 | 76 | ret = init_get_bits(&obu->gb, obu->data, obu->size_bits); | |
99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (ret < 0) |
100 | ✗ | return ret; | |
101 | } | ||
102 | |||
103 | 19 | return 0; | |
104 | } | ||
105 | |||
106 | 684 | void ff_av1_packet_uninit(AV1Packet *pkt) | |
107 | { | ||
108 | 684 | av_freep(&pkt->obus); | |
109 | 684 | pkt->obus_allocated = pkt->obus_allocated_size = 0; | |
110 | 684 | } | |
111 |