• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 /*!\file
13  * \brief A table mapping from time to corresponding film grain parameters.
14  *
15  * In order to apply grain synthesis in the decoder, the film grain parameters
16  * need to be signalled in the encoder. The film grain parameters are time
17  * varying, and for two-pass encoding (and denoiser implementation flexibility)
18  * it is common to denoise the video and do parameter estimation before encoding
19  * the denoised video.
20  *
21  * The film grain table is used to provide this flexibility and is used as a
22  * parameter that is passed to the encoder.
23  *
24  * Further, if regraining is to be done in say a single pass mode, or in two
25  * pass within the encoder (before frames are added to the lookahead buffer),
26  * this data structure can be used to keep track of on-the-fly estimated grain
27  * parameters, that are then extracted from the table before the encoded frame
28  * is written.
29  */
30 #ifndef AOM_AOM_DSP_GRAIN_TABLE_H_
31 #define AOM_AOM_DSP_GRAIN_TABLE_H_
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include "aom_dsp/grain_params.h"
38 #include "aom/internal/aom_codec_internal.h"
39 
40 typedef struct aom_film_grain_table_entry_t {
41   aom_film_grain_t params;
42   int64_t start_time;
43   int64_t end_time;
44   struct aom_film_grain_table_entry_t *next;
45 } aom_film_grain_table_entry_t;
46 
47 typedef struct {
48   aom_film_grain_table_entry_t *head;
49   aom_film_grain_table_entry_t *tail;
50 } aom_film_grain_table_t;
51 
52 /*!\brief Add a mapping from [time_stamp, end_time) to the given grain
53  * parameters
54  *
55  * \param[in/out] table      The grain table
56  * \param[in]     time_stamp The start time stamp
57  * \param[in]     end_stamp  The end time_stamp
58  * \param[in]     grain      The grain parameters
59  */
60 void aom_film_grain_table_append(aom_film_grain_table_t *table,
61                                  int64_t time_stamp, int64_t end_time,
62                                  const aom_film_grain_t *grain);
63 
64 /*!\brief Look-up (and optionally erase) the grain parameters for the given time
65  *
66  * \param[in]  table      The grain table
67  * \param[in]  time_stamp The start time stamp
68  * \param[in]  end_stamp  The end time_stamp
69  * \param[in]  erase      Whether the time segment can be deleted
70  * \param[out] grain      The output grain parameters
71  */
72 int aom_film_grain_table_lookup(aom_film_grain_table_t *t, int64_t time_stamp,
73                                 int64_t end_time, int erase,
74                                 aom_film_grain_t *grain);
75 
76 /*!\brief Reads the grain table from a file.
77  *
78  * \param[out]  table       The grain table
79  * \param[in]   filename    The file to read from
80  * \param[in]   error_info  Error info for tracking errors
81  */
82 aom_codec_err_t aom_film_grain_table_read(
83     aom_film_grain_table_t *table, const char *filename,
84     struct aom_internal_error_info *error_info);
85 
86 /*!\brief Writes the grain table from a file.
87  *
88  * \param[out]  table       The grain table
89  * \param[in]   filename    The file to read from
90  * \param[in]   error_info  Error info for tracking errors
91  */
92 aom_codec_err_t aom_film_grain_table_write(
93     const aom_film_grain_table_t *t, const char *filename,
94     struct aom_internal_error_info *error_info);
95 
96 void aom_film_grain_table_free(aom_film_grain_table_t *t);
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif  // AOM_AOM_DSP_GRAIN_TABLE_H_
103