| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Dolby Vision RPU decoder | ||
| 3 | * | ||
| 4 | * Copyright (C) 2021 Jan Ekström | ||
| 5 | * Copyright (C) 2021-2024 Niklas Haas | ||
| 6 | * | ||
| 7 | * This file is part of FFmpeg. | ||
| 8 | * | ||
| 9 | * FFmpeg is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with FFmpeg; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include "libavutil/attributes.h" | ||
| 25 | #include "libavutil/mem.h" | ||
| 26 | |||
| 27 | #include "dovi_rpu.h" | ||
| 28 | #include "libavutil/refstruct.h" | ||
| 29 | |||
| 30 | 545 | void ff_dovi_ctx_unref(DOVIContext *s) | |
| 31 | { | ||
| 32 | 545 | av_refstruct_unref(&s->dm); | |
| 33 |
2/2✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 545 times.
|
9265 | for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) |
| 34 | 8720 | av_refstruct_unref(&s->vdr[i]); | |
| 35 | 545 | av_refstruct_unref(&s->ext_blocks); | |
| 36 | 545 | av_free(s->rpu_buf); | |
| 37 | |||
| 38 | 545 | *s = (DOVIContext) { | |
| 39 | 545 | .logctx = s->logctx, | |
| 40 | }; | ||
| 41 | 545 | } | |
| 42 | |||
| 43 | 10 | av_cold void ff_dovi_ctx_flush(DOVIContext *s) | |
| 44 | { | ||
| 45 | 10 | av_refstruct_unref(&s->dm); | |
| 46 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 10 times.
|
170 | for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) |
| 47 | 160 | av_refstruct_unref(&s->vdr[i]); | |
| 48 | 10 | av_refstruct_unref(&s->ext_blocks); | |
| 49 | |||
| 50 | 10 | *s = (DOVIContext) { | |
| 51 | 10 | .logctx = s->logctx, | |
| 52 | 10 | .cfg = s->cfg, | |
| 53 | /* preserve temporary buffer */ | ||
| 54 | 10 | .rpu_buf = s->rpu_buf, | |
| 55 | 10 | .rpu_buf_sz = s->rpu_buf_sz, | |
| 56 | }; | ||
| 57 | 10 | } | |
| 58 | |||
| 59 | 32 | void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) | |
| 60 | { | ||
| 61 | 32 | s->logctx = s0->logctx; | |
| 62 | 32 | s->cfg = s0->cfg; | |
| 63 | 32 | s->header = s0->header; | |
| 64 | 32 | s->mapping = s0->mapping; | |
| 65 | 32 | s->color = s0->color; | |
| 66 | 32 | av_refstruct_replace(&s->dm, s0->dm); | |
| 67 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 32 times.
|
544 | for (int i = 0; i <= DOVI_MAX_DM_ID; i++) |
| 68 | 512 | av_refstruct_replace(&s->vdr[i], s0->vdr[i]); | |
| 69 | 32 | av_refstruct_replace(&s->ext_blocks, s0->ext_blocks); | |
| 70 | 32 | } | |
| 71 | |||
| 72 | ✗ | int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr) | |
| 73 | { | ||
| 74 | ✗ | switch (hdr->vdr_rpu_profile) { | |
| 75 | ✗ | case 0: | |
| 76 | ✗ | if (hdr->bl_video_full_range_flag) | |
| 77 | ✗ | return 5; | |
| 78 | ✗ | break; | |
| 79 | ✗ | case 1: | |
| 80 | ✗ | if (hdr->el_spatial_resampling_filter_flag && !hdr->disable_residual_flag) { | |
| 81 | ✗ | if (hdr->vdr_bit_depth == 12) { | |
| 82 | ✗ | return 7; | |
| 83 | } else { | ||
| 84 | ✗ | return 4; | |
| 85 | } | ||
| 86 | } else { | ||
| 87 | ✗ | return 8; | |
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | ✗ | return 0; /* unknown */ | |
| 92 | } | ||
| 93 | |||
| 94 | const AVDOVIColorMetadata ff_dovi_color_default = { | ||
| 95 | .dm_metadata_id = 0, | ||
| 96 | .scene_refresh_flag = 0, | ||
| 97 | .ycc_to_rgb_matrix = { | ||
| 98 | { 9575, 8192 }, | ||
| 99 | { 0, 8192 }, | ||
| 100 | { 14742, 8192 }, | ||
| 101 | { 9575, 8192 }, | ||
| 102 | { 1754, 8192 }, | ||
| 103 | { 4383, 8192 }, | ||
| 104 | { 9575, 8192 }, | ||
| 105 | { 17372, 8192 }, | ||
| 106 | { 0, 8192 }, | ||
| 107 | }, | ||
| 108 | .ycc_to_rgb_offset = { | ||
| 109 | { 1, 4 }, | ||
| 110 | { 2, 1 }, | ||
| 111 | { 2, 1 }, | ||
| 112 | }, | ||
| 113 | .rgb_to_lms_matrix = { | ||
| 114 | { 5845, 16384 }, | ||
| 115 | { 9702, 16384 }, | ||
| 116 | { 837, 16384 }, | ||
| 117 | { 2568, 16384 }, | ||
| 118 | { 12256, 16384 }, | ||
| 119 | { 1561, 16384 }, | ||
| 120 | { 0, 16384 }, | ||
| 121 | { 679, 16384 }, | ||
| 122 | { 15705, 16384 }, | ||
| 123 | }, | ||
| 124 | .signal_eotf = 39322, | ||
| 125 | .signal_eotf_param0 = 15867, | ||
| 126 | .signal_eotf_param1 = 228, | ||
| 127 | .signal_eotf_param2 = 1383604, | ||
| 128 | .signal_bit_depth = 14, | ||
| 129 | .signal_color_space = 0, | ||
| 130 | .signal_chroma_format = 0, | ||
| 131 | .signal_full_range_flag = 1, | ||
| 132 | .source_min_pq = 62, | ||
| 133 | .source_max_pq = 3696, | ||
| 134 | .source_diagonal = 42, | ||
| 135 | }; | ||
| 136 |