/src/avm/av2/decoder/obu_buf.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2025, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 3-Clause Clear License |
5 | | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
6 | | * License was not distributed with this source code in the LICENSE file, you |
7 | | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
8 | | * Alliance for Open Media Patent License 1.0 was not distributed with this |
9 | | * source code in the PATENTS file, you can obtain it at |
10 | | * aomedia.org/license/patent-license/. |
11 | | */ |
12 | | |
13 | | #include <assert.h> |
14 | | |
15 | | #include "config/avm_config.h" |
16 | | #include "config/avm_scale_rtcd.h" |
17 | | |
18 | | #include "avm/avm_codec.h" |
19 | | #include "avm_dsp/bitreader_buffer.h" |
20 | | #include "avm_ports/mem_ops.h" |
21 | | |
22 | | #include "av2/common/common.h" |
23 | | #include "av2/common/obu_util.h" |
24 | | #include "av2/common/timing.h" |
25 | | #include "av2/decoder/decoder.h" |
26 | | #include "av2/decoder/decodeframe.h" |
27 | | #include "av2/decoder/obu.h" |
28 | | |
29 | | uint32_t av2_read_buffer_removal_timing_obu(struct AV2Decoder *pbi, |
30 | | struct avm_read_bit_buffer *rb, |
31 | 120 | int xlayer_id) { |
32 | 120 | AV2_COMMON *const cm = &pbi->common; |
33 | 120 | const uint32_t saved_bit_offset = rb->bit_offset; |
34 | | |
35 | 120 | assert(rb->error_handler); |
36 | | |
37 | 120 | BufferRemovalTimingInfo *const brt_info = &cm->brt_info; |
38 | | |
39 | | // br_ops_id |
40 | 120 | brt_info->br_ops_dependent_flag = avm_rb_read_bit(rb); |
41 | 120 | if (brt_info->br_ops_dependent_flag) { |
42 | 0 | brt_info->br_ops_id = avm_rb_read_literal(rb, 4); |
43 | 0 | brt_info->br_ops_cnt[brt_info->br_ops_id] = avm_rb_read_literal(rb, 3); |
44 | | // Find the corresponding OPS in pbi->ops_list where |
45 | | // ops_id == br_ops_id. |
46 | | // It is a requirement of bitstream conformance that if a buffer removal |
47 | | // time OBU with a buffer br_ops_id is present in the |
48 | | // bitstream, an operating point set OBU shall also be present in the |
49 | | // bitstream with a value of ops_id equal to br_ops_id." |
50 | | // ops_list is indexed as [xlayer_id][ops_id] |
51 | 0 | if (!pbi->ops_list[xlayer_id][brt_info->br_ops_id].valid || |
52 | 0 | pbi->ops_list[xlayer_id][brt_info->br_ops_id].ops_id != |
53 | 0 | brt_info->br_ops_id) { |
54 | 0 | avm_internal_error( |
55 | 0 | &cm->error, AVM_CODEC_UNSUP_BITSTREAM, |
56 | 0 | "No matching operating point set OBU found for br_ops_id = %d. " |
57 | 0 | "Bitstream conformance requires an OPS OBU with ops_id = %d.", |
58 | 0 | brt_info->br_ops_id, brt_info->br_ops_id); |
59 | 0 | return 0; |
60 | 0 | } |
61 | | // It is a requirement of bitstream conformance that br_ops_cnt[br_ops_id] |
62 | | // when present shall be equal to the value of ops_cnt of the corresponding |
63 | | // operating point set OBU. |
64 | 0 | if (brt_info->br_ops_cnt[brt_info->br_ops_id] != |
65 | 0 | pbi->ops_list[xlayer_id][brt_info->br_ops_id].ops_cnt) { |
66 | 0 | avm_internal_error( |
67 | 0 | &cm->error, AVM_CODEC_UNSUP_BITSTREAM, |
68 | 0 | "Mismatch between the operating point count in Buffer Removal Timing " |
69 | 0 | "OBU (%d) and Operating Point set OBU (%d).", |
70 | 0 | brt_info->br_ops_cnt[brt_info->br_ops_id], |
71 | 0 | pbi->ops_list[xlayer_id][brt_info->br_ops_id].ops_cnt); |
72 | 0 | return 0; |
73 | 0 | } |
74 | | // decoder model |
75 | 0 | for (int i = 0; i < brt_info->br_ops_cnt[brt_info->br_ops_id]; i++) { |
76 | 0 | brt_info->br_decoder_model_present_op_flag[brt_info->br_ops_id][i] = |
77 | 0 | avm_rb_read_bit(rb); |
78 | 0 | if (brt_info->br_decoder_model_present_op_flag[brt_info->br_ops_id][i]) |
79 | 0 | brt_info->br_time_op[brt_info->br_ops_id][i] = |
80 | 0 | avm_rb_read_rice_golomb(rb, 4); |
81 | 0 | } |
82 | 120 | } else { |
83 | 120 | brt_info->br_time = avm_rb_read_rice_golomb(rb, 4); |
84 | 120 | } |
85 | 120 | if (av2_check_trailing_bits(pbi, rb) != 0) { |
86 | | // cm->error.error_code is already set. |
87 | 2 | return 0; |
88 | 2 | } |
89 | 118 | return ((rb->bit_offset - saved_bit_offset + 7) >> 3); |
90 | 120 | } |