History

avcodec/hevc: Rewrite scalability_mask_flag parse in decode_vps_ext

Remove a for loop and make it easy to extend to support other types of scalability. Move ScalabilityMask to hevc header file so it can be used in hevc decoder.

Zhao Zhili committed 1 year ago

Commit d3220ed1 parent 01f74bf3 files · +24 −18Browse files

Showing the changes to libavcodec (3 of 3 files). Show all

Unified · Split

3 files
  1. libavcodec/hevc/hevc.h +7 −0
  2. libavcodec/hevc/ps.c +15 −18
  3. libavcodec/hevc/ps.h +2 −0
libavcodec/hevc/hevc.h+7−0
@@ -162,5 +162,12 @@ enum { · 161 unmodified lines
162162 HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
163163 };
164164
165+enum HEVCScalabilityMask {
166+ HEVC_SCALABILITY_DEPTH = 1 << (15 - 0),
167+ HEVC_SCALABILITY_MULTIVIEW = 1 << (15 - 1),
168+ HEVC_SCALABILITY_SPATIAL = 1 << (15 - 2),
169+ HEVC_SCALABILITY_AUXILIARY = 1 << (15 - 3),
170+ HEVC_SCALABILITY_MASK_MAX = 0xFFFF,
171+};
165172
166173 #endif /* AVCODEC_HEVC_HEVC_H */
libavcodec/hevc/ps.c+15−18
@@ -450,14 +450,6 @@ static void hevc_vps_free(AVRefStructOpaque opaque, void *obj) · 449 unmodified lines
450450 av_freep(&vps->data);
451451 }
452452
453−enum ScalabilityMask {
454− HEVC_SCALABILITY_DEPTH = 0,
455− HEVC_SCALABILITY_MULTIVIEW = 1,
456− HEVC_SCALABILITY_SPATIAL = 2,
457− HEVC_SCALABILITY_AUXILIARY = 3,
458− HEVC_SCALABILITY_MASK_MAX = 15,
459−};
460−
461453 enum DependencyType {
462454 HEVC_DEP_TYPE_SAMPLE = 0,
463455 HEVC_DEP_TYPE_MV = 1,
@@ -532,17 +524,22 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext *avctx, HEVCVPS *vps · 68 unmodified lines
532524 return AVERROR_INVALIDDATA;
533525
534526 splitting_flag = get_bits1(gb);
535− num_scalability_types = 0;
536− for (int i = 0; i <= HEVC_SCALABILITY_MASK_MAX; i++) {
537− int scalability_mask_flag = get_bits1(gb);
538− if (scalability_mask_flag && (i != HEVC_SCALABILITY_MULTIVIEW)) {
539− av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n", i);
540− return AVERROR_PATCHWELCOME;
541− }
542− num_scalability_types += scalability_mask_flag;
543− }
544− if (num_scalability_types != 1)
527+ vps->scalability_mask_flag = get_bits(gb, 16);
528+ num_scalability_types = av_popcount(vps->scalability_mask_flag);
529+ if (!num_scalability_types) {
530+ av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n");
545531 return AVERROR_INVALIDDATA;
532+ } else if (num_scalability_types > 1) {
533+ av_log(avctx, AV_LOG_ERROR, "Scalability number %d not supported\n",
534+ num_scalability_types);
535+ return AVERROR_PATCHWELCOME;
536+ }
537+
538+ if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
539+ av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
540+ 15 - ff_ctz(vps->scalability_mask_flag));
541+ return AVERROR_PATCHWELCOME;
542+ }
546543
547544 if (!splitting_flag)
548545 dimension_id_len = get_bits(gb, 3) + 1;
libavcodec/hevc/ps.h+2−0
@@ -205,6 +205,8 @@ typedef struct HEVCVPS { · 204 unmodified lines
205205 */
206206 int nb_layers;
207207
208+ uint16_t scalability_mask_flag;
209+
208210 // LayerIdxInVps[nuh_layer_id], i.e. a mapping of nuh_layer_id to VPS layer
209211 // indices. Valid values are between 0 and HEVC_VPS_MAX_LAYERS. Entries for
210212 // unmapped values of nuh_layer_id are set to -1.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t