FFmpeg
dovi_rpu.c
Go to the documentation of this file.
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/mem.h"
25 
26 #include "dovi_rpu.h"
27 #include "refstruct.h"
28 
30 {
31  for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
32  ff_refstruct_unref(&s->vdr[i]);
33  ff_refstruct_unref(&s->ext_blocks);
34  av_free(s->rpu_buf);
35 
36  *s = (DOVIContext) {
37  .logctx = s->logctx,
38  };
39 }
40 
42 {
43  for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
44  ff_refstruct_unref(&s->vdr[i]);
45  ff_refstruct_unref(&s->ext_blocks);
46 
47  *s = (DOVIContext) {
48  .logctx = s->logctx,
49  .cfg = s->cfg,
50  /* preserve temporary buffer */
51  .rpu_buf = s->rpu_buf,
52  .rpu_buf_sz = s->rpu_buf_sz,
53  };
54 }
55 
57 {
58  s->logctx = s0->logctx;
59  s->cfg = s0->cfg;
60  s->header = s0->header;
61  s->mapping = s0->mapping;
62  s->color = s0->color;
63  for (int i = 0; i <= DOVI_MAX_DM_ID; i++)
64  ff_refstruct_replace(&s->vdr[i], s0->vdr[i]);
65  ff_refstruct_replace(&s->ext_blocks, s0->ext_blocks);
66 }
67 
69 {
70  switch (hdr->vdr_rpu_profile) {
71  case 0:
72  if (hdr->bl_video_full_range_flag)
73  return 5;
74  break;
75  case 1:
77  if (hdr->vdr_bit_depth == 12) {
78  return 7;
79  } else {
80  return 4;
81  }
82  } else {
83  return 8;
84  }
85  }
86 
87  return 0; /* unknown */
88 }
ff_dovi_ctx_unref
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition: dovi_rpu.c:29
DOVI_MAX_DM_ID
#define DOVI_MAX_DM_ID
Definition: dovi_rpu.h:31
AVDOVIRpuDataHeader
Dolby Vision RPU data header.
Definition: dovi_meta.h:78
DOVIContext
Definition: dovi_rpu.h:32
dovi_rpu.h
refstruct.h
AVDOVIRpuDataHeader::el_spatial_resampling_filter_flag
uint8_t el_spatial_resampling_filter_flag
Definition: dovi_meta.h:92
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVDOVIRpuDataHeader::vdr_bit_depth
uint8_t vdr_bit_depth
Definition: dovi_meta.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_dovi_ctx_flush
void ff_dovi_ctx_flush(DOVIContext *s)
Partially reset the internal state.
Definition: dovi_rpu.c:41
AVDOVIRpuDataHeader::vdr_rpu_profile
uint8_t vdr_rpu_profile
Definition: dovi_meta.h:81
AVDOVIRpuDataHeader::bl_video_full_range_flag
uint8_t bl_video_full_range_flag
Definition: dovi_meta.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_refstruct_replace
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
mem.h
s0
#define s0
Definition: regdef.h:37
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDOVIRpuDataHeader::disable_residual_flag
uint8_t disable_residual_flag
Definition: dovi_meta.h:93
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
ff_dovi_ctx_replace
void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
Definition: dovi_rpu.c:56
ff_dovi_guess_profile_hevc
int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
Internal helper function to guess the correct DV profile for HEVC.
Definition: dovi_rpu.c:68