/src/avm/av2/common/timing.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, 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 "av2/common/annexA.h" |
14 | | #include "av2/common/blockd.h" |
15 | | #include "av2/common/timing.h" |
16 | | #include "av2/common/av2_common_int.h" |
17 | | |
18 | | /* Tables for AV2 max bitrates for different levels of main and high tier. |
19 | | * The tables are in Kbps instead of Mbps in the specification. |
20 | | * Note that depending on the profile, a multiplier is needed. |
21 | | */ |
22 | | #define UNDEFINED_RATE \ |
23 | | (1 << 21) // Placeholder rate for levels with undefined rate |
24 | | #define INVALID_RATE \ |
25 | | (0) // For invalid profile-level configuration, set rate to 0 |
26 | | |
27 | | /* Max Bitrates for levels of Main Tier in kbps. Bitrate in main_kbps [31] */ |
28 | | /* is a dummy value. The decoder model is not applicable for level 31. */ |
29 | | static int32_t main_kbps[1 << LEVEL_BITS] = { |
30 | | 1500, 3000, 6000, 10000, |
31 | | 12000, 20000, 30000, 40000, |
32 | | 60000, 60000, 60000, 100000, |
33 | | 160000, 160000, 160000, 200000, |
34 | | 320000, 320000, 320000, 400000, |
35 | | 640000, 640000, UNDEFINED_RATE, UNDEFINED_RATE, |
36 | | UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE, |
37 | | UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE |
38 | | }; |
39 | | |
40 | | /* Max Bitrates for levels of High Tier in kbps. Bitrate in high_kbps [31] */ |
41 | | /* is a dummy value. The decoder model is not applicable for level 31. */ |
42 | | static int32_t high_kbps[1 << LEVEL_BITS] = { |
43 | | INVALID_RATE, INVALID_RATE, INVALID_RATE, INVALID_RATE, |
44 | | 30000, 50000, 100000, 160000, |
45 | | 240000, 240000, 240000, 480000, |
46 | | 800000, 800000, 800000, 960000, |
47 | | 1600000, 1600000, 1600000, 1920000, |
48 | | 3200000, 3200000, UNDEFINED_RATE, UNDEFINED_RATE, |
49 | | UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE, |
50 | | UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE, UNDEFINED_RATE |
51 | | }; |
52 | | |
53 | | // Callers treat a zero bitrate as "profile, level, and tier combination not |
54 | | // supported". |
55 | | int64_t av2_max_level_bitrate(BITSTREAM_PROFILE seq_profile, int seq_level_idx, |
56 | 2.54k | int seq_tier) { |
57 | 2.54k | const int profile_factor_row = |
58 | 2.54k | get_profile_factor_table_row_index(seq_profile); |
59 | 2.54k | const double bitrate_profile_factor = |
60 | 2.54k | get_bitrate_profile_factor(profile_factor_row); |
61 | 2.54k | const int32_t bitrate_kbps = |
62 | 2.54k | seq_tier ? high_kbps[seq_level_idx] : main_kbps[seq_level_idx]; |
63 | | |
64 | 2.54k | const int64_t bitrate = (int64_t)(bitrate_kbps * bitrate_profile_factor); |
65 | | |
66 | 2.54k | return bitrate * 1000; |
67 | 2.54k | } |
68 | | |
69 | 0 | void av2_set_avm_dec_model_info(avm_dec_model_info_t *decoder_model) { |
70 | 0 | decoder_model->encoder_decoder_buffer_delay_length = 16; |
71 | 0 | decoder_model->buffer_removal_time_length = 10; |
72 | 0 | } |
73 | | |
74 | 0 | void av2_set_dec_model_op_parameters(avm_dec_model_op_parameters_t *op_params) { |
75 | 0 | op_params->decoder_model_param_present_flag = 1; |
76 | 0 | op_params->decoder_buffer_delay = 90000 >> 1; // 0.5 s |
77 | 0 | op_params->encoder_buffer_delay = 90000 >> 1; // 0.5 s |
78 | 0 | op_params->low_delay_mode_flag = 0; |
79 | 0 | op_params->display_model_param_present_flag = 1; |
80 | 0 | op_params->initial_display_delay = 8; // 8 frames delay |
81 | 0 | } |
82 | | |
83 | | void av2_set_resource_availability_parameters( |
84 | 0 | avm_dec_model_op_parameters_t *op_params) { |
85 | 0 | op_params->decoder_model_param_present_flag = 0; |
86 | 0 | op_params->decoder_buffer_delay = |
87 | 0 | 70000; // Resource availability mode default |
88 | 0 | op_params->encoder_buffer_delay = |
89 | 0 | 20000; // Resource availability mode default |
90 | 0 | op_params->low_delay_mode_flag = 0; // Resource availability mode default |
91 | 0 | op_params->display_model_param_present_flag = 1; |
92 | 0 | op_params->initial_display_delay = 8; // 8 frames delay |
93 | 0 | } |