Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * This file is part of FFmpeg. | ||
3 | * | ||
4 | * FFmpeg is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * FFmpeg is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with FFmpeg; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | #include "golomb.h" | ||
20 | #include "evc.h" | ||
21 | #include "evc_parse.h" | ||
22 | |||
23 | // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax) | ||
24 | 900 | int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh, | |
25 | const EVCParamSets *ps, enum EVCNALUnitType nalu_type) | ||
26 | { | ||
27 | const EVCParserPPS *pps; | ||
28 | const EVCParserSPS *sps; | ||
29 | 900 | int num_tiles_in_slice = 0; | |
30 | unsigned slice_pic_parameter_set_id; | ||
31 | |||
32 | 900 | slice_pic_parameter_set_id = get_ue_golomb_31(gb); | |
33 | |||
34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT) |
35 | ✗ | return AVERROR_INVALIDDATA; | |
36 | |||
37 | 900 | pps = ps->pps[slice_pic_parameter_set_id]; | |
38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if(!pps) |
39 | ✗ | return AVERROR_INVALIDDATA; | |
40 | |||
41 | 900 | sps = ps->sps[pps->pps_seq_parameter_set_id]; | |
42 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if(!sps) |
43 | ✗ | return AVERROR_INVALIDDATA; | |
44 | |||
45 | 900 | memset(sh, 0, sizeof(*sh)); | |
46 | 900 | sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id; | |
47 | |||
48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (!pps->single_tile_in_pic_flag) { |
49 | ✗ | sh->single_tile_in_slice_flag = get_bits1(gb); | |
50 | ✗ | sh->first_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1); | |
51 | } else | ||
52 | 900 | sh->single_tile_in_slice_flag = 1; | |
53 | |||
54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (!sh->single_tile_in_slice_flag) { |
55 | ✗ | if (pps->arbitrary_slice_present_flag) | |
56 | ✗ | sh->arbitrary_slice_flag = get_bits1(gb); | |
57 | |||
58 | ✗ | if (!sh->arbitrary_slice_flag) | |
59 | ✗ | sh->last_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1); | |
60 | else { | ||
61 | ✗ | sh->num_remaining_tiles_in_slice_minus1 = get_ue_golomb_long(gb); | |
62 | ✗ | num_tiles_in_slice = sh->num_remaining_tiles_in_slice_minus1 + 2; | |
63 | ✗ | for (int i = 0; i < num_tiles_in_slice - 1; ++i) | |
64 | ✗ | sh->delta_tile_id_minus1[i] = get_ue_golomb_long(gb); | |
65 | } | ||
66 | } | ||
67 | |||
68 | 900 | sh->slice_type = get_ue_golomb_31(gb); | |
69 | |||
70 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 897 times.
|
900 | if (nalu_type == EVC_IDR_NUT) |
71 | 3 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
72 | |||
73 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
900 | if (sps->sps_mmvd_flag && ((sh->slice_type == EVC_SLICE_TYPE_B) || (sh->slice_type == EVC_SLICE_TYPE_P))) |
74 | ✗ | sh->mmvd_group_enable_flag = get_bits1(gb); | |
75 | else | ||
76 | 900 | sh->mmvd_group_enable_flag = 0; | |
77 | |||
78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (sps->sps_alf_flag) { |
79 | ✗ | int ChromaArrayType = sps->chroma_format_idc; | |
80 | |||
81 | ✗ | sh->slice_alf_enabled_flag = get_bits1(gb); | |
82 | |||
83 | ✗ | if (sh->slice_alf_enabled_flag) { | |
84 | ✗ | sh->slice_alf_luma_aps_id = get_bits(gb, 5); | |
85 | ✗ | sh->slice_alf_map_flag = get_bits1(gb); | |
86 | ✗ | sh->slice_alf_chroma_idc = get_bits(gb, 2); | |
87 | |||
88 | ✗ | if ((ChromaArrayType == 1 || ChromaArrayType == 2) && sh->slice_alf_chroma_idc > 0) | |
89 | ✗ | sh->slice_alf_chroma_aps_id = get_bits(gb, 5); | |
90 | } | ||
91 | ✗ | if (ChromaArrayType == 3) { | |
92 | ✗ | int sliceChromaAlfEnabledFlag = 0; | |
93 | ✗ | int sliceChroma2AlfEnabledFlag = 0; | |
94 | |||
95 | ✗ | if (sh->slice_alf_chroma_idc == 1) { // @see ISO_IEC_23094-1 (7.4.5) | |
96 | ✗ | sliceChromaAlfEnabledFlag = 1; | |
97 | ✗ | sliceChroma2AlfEnabledFlag = 0; | |
98 | ✗ | } else if (sh->slice_alf_chroma_idc == 2) { | |
99 | ✗ | sliceChromaAlfEnabledFlag = 0; | |
100 | ✗ | sliceChroma2AlfEnabledFlag = 1; | |
101 | ✗ | } else if (sh->slice_alf_chroma_idc == 3) { | |
102 | ✗ | sliceChromaAlfEnabledFlag = 1; | |
103 | ✗ | sliceChroma2AlfEnabledFlag = 1; | |
104 | } else { | ||
105 | ✗ | sliceChromaAlfEnabledFlag = 0; | |
106 | ✗ | sliceChroma2AlfEnabledFlag = 0; | |
107 | } | ||
108 | |||
109 | ✗ | if (!sh->slice_alf_enabled_flag) | |
110 | ✗ | sh->slice_alf_chroma_idc = get_bits(gb, 2); | |
111 | |||
112 | ✗ | if (sliceChromaAlfEnabledFlag) { | |
113 | ✗ | sh->slice_alf_chroma_aps_id = get_bits(gb, 5); | |
114 | ✗ | sh->slice_alf_chroma_map_flag = get_bits1(gb); | |
115 | } | ||
116 | |||
117 | ✗ | if (sliceChroma2AlfEnabledFlag) { | |
118 | ✗ | sh->slice_alf_chroma2_aps_id = get_bits(gb, 5); | |
119 | ✗ | sh->slice_alf_chroma2_map_flag = get_bits1(gb); | |
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 |
2/2✓ Branch 0 taken 897 times.
✓ Branch 1 taken 3 times.
|
900 | if (nalu_type != EVC_IDR_NUT) { |
125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 897 times.
|
897 | if (sps->sps_pocs_flag) |
126 | ✗ | sh->slice_pic_order_cnt_lsb = get_bits(gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4); | |
127 | } | ||
128 | |||
129 | // @note | ||
130 | // If necessary, add the missing fields to the EVCParserSliceHeader structure | ||
131 | // and then extend parser implementation | ||
132 | |||
133 | 900 | return 0; | |
134 | } | ||
135 | |||
136 | 900 | int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh, | |
137 | EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid) | ||
138 | { | ||
139 | 900 | const EVCParserPPS *pps = ps->pps[sh->slice_pic_parameter_set_id]; | |
140 | const EVCParserSPS *sps; | ||
141 | |||
142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (!pps) |
143 | ✗ | return AVERROR_INVALIDDATA; | |
144 | |||
145 | 900 | sps = ps->sps[pps->pps_seq_parameter_set_id]; | |
146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (!sps) |
147 | ✗ | return AVERROR_INVALIDDATA; | |
148 | |||
149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
|
900 | if (sps->sps_pocs_flag) { |
150 | ✗ | int PicOrderCntMsb = 0; | |
151 | ✗ | poc->prevPicOrderCntVal = poc->PicOrderCntVal; | |
152 | |||
153 | ✗ | if (nalu_type == EVC_IDR_NUT) | |
154 | ✗ | PicOrderCntMsb = 0; | |
155 | else { | ||
156 | ✗ | int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4); | |
157 | ✗ | int prevPicOrderCntLsb = poc->PicOrderCntVal & (MaxPicOrderCntLsb - 1); | |
158 | ✗ | int prevPicOrderCntMsb = poc->PicOrderCntVal - prevPicOrderCntLsb; | |
159 | |||
160 | ✗ | if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) && | |
161 | ✗ | ((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2))) | |
162 | ✗ | PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb; | |
163 | ✗ | else if ((sh->slice_pic_order_cnt_lsb > prevPicOrderCntLsb) && | |
164 | ✗ | ((sh->slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2))) | |
165 | ✗ | PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb; | |
166 | else | ||
167 | ✗ | PicOrderCntMsb = prevPicOrderCntMsb; | |
168 | } | ||
169 | ✗ | poc->PicOrderCntVal = PicOrderCntMsb + sh->slice_pic_order_cnt_lsb; | |
170 | } else { | ||
171 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 897 times.
|
900 | if (nalu_type == EVC_IDR_NUT) { |
172 | 3 | poc->PicOrderCntVal = 0; | |
173 | 3 | poc->DocOffset = -1; | |
174 | } else { | ||
175 | 897 | int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length); | |
176 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 843 times.
|
897 | if (tid == 0) { |
177 | 54 | poc->PicOrderCntVal = poc->prevPicOrderCntVal + SubGopLength; | |
178 | 54 | poc->DocOffset = 0; | |
179 | 54 | poc->prevPicOrderCntVal = poc->PicOrderCntVal; | |
180 | } else { | ||
181 | int ExpectedTemporalId; | ||
182 | int PocOffset; | ||
183 | 843 | int prevDocOffset = poc->DocOffset; | |
184 | |||
185 | 843 | poc->DocOffset = (prevDocOffset + 1) % SubGopLength; | |
186 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 840 times.
|
843 | if (poc->DocOffset == 0) { |
187 | 3 | poc->prevPicOrderCntVal += SubGopLength; | |
188 | 3 | ExpectedTemporalId = 0; | |
189 | } else | ||
190 | 840 | ExpectedTemporalId = 1 + (int)log2(poc->DocOffset); | |
191 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 843 times.
|
852 | while (tid != ExpectedTemporalId) { |
192 | 9 | poc->DocOffset = (poc->DocOffset + 1) % SubGopLength; | |
193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (poc->DocOffset == 0) |
194 | ✗ | ExpectedTemporalId = 0; | |
195 | else | ||
196 | 9 | ExpectedTemporalId = 1 + (int)log2(poc->DocOffset); | |
197 | } | ||
198 | 843 | PocOffset = (int)(SubGopLength * ((2.0 * poc->DocOffset + 1) / (int)pow(2.0, tid) - 2)); | |
199 | 843 | poc->PicOrderCntVal = poc->prevPicOrderCntVal + PocOffset; | |
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | 900 | return 0; | |
205 | } | ||
206 |