• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Dolby Vision RPU decoder
3  *
4  * Copyright (C) 2021 Jan Ekström
5  * Copyright (C) 2021 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 #ifndef AVCODEC_DOVI_RPU_H
25 #define AVCODEC_DOVI_RPU_H
26 
27 #include "libavutil/dovi_meta.h"
28 #include "libavutil/frame.h"
29 
30 #define DOVI_MAX_DM_ID 15
31 typedef struct DOVIContext {
32     void *logctx;
33 
34     /**
35      * Currently active RPU data header, updates on every dovi_rpu_parse().
36      */
37     AVDOVIRpuDataHeader header;
38 
39     /**
40      * Currently active data mappings, or NULL. Points into memory owned by the
41      * corresponding rpu/vdr_ref, which becomes invalid on the next call to
42      * dovi_rpu_parse.
43      */
44     const AVDOVIDataMapping *mapping;
45     const AVDOVIColorMetadata *color;
46 
47     /**
48      * Private fields internal to dovi_rpu.c
49      */
50     AVBufferRef *vdr_ref[DOVI_MAX_DM_ID+1];
51     uint8_t dv_profile;
52 
53 } DOVIContext;
54 
55 int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0);
56 
57 /**
58  * Completely reset a DOVIContext, preserving only logctx.
59  */
60 void ff_dovi_ctx_unref(DOVIContext *s);
61 
62 /**
63  * Partially reset the internal state. Resets per-frame state while preserving
64  * fields parsed from the configuration record.
65  */
66 void ff_dovi_ctx_flush(DOVIContext *s);
67 
68 /**
69  * Read the contents of an AVDOVIDecoderConfigurationRecord (usually provided
70  * by stream side data) and update internal state accordingly.
71  */
72 void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg);
73 
74 /**
75  * Parse the contents of a Dovi RPU NAL and update the parsed values in the
76  * DOVIContext struct.
77  *
78  * Returns 0 or an error code.
79  */
80 int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size);
81 
82 /**
83  * Attach the decoded AVDOVIMetadata as side data to an AVFrame.
84  */
85 int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame);
86 
87 #endif /* AVCODEC_DOVI_RPU_H */
88