• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 foo86
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_DOLBY_E_H
22 #define AVCODEC_DOLBY_E_H
23 
24 #include <stdint.h>
25 #include "get_bits.h"
26 
27 #define FRAME_SAMPLES   1792
28 
29 #define MAX_PROG_CONF   23
30 #define MAX_PROGRAMS    8
31 #define MAX_CHANNELS    8
32 
33 /**
34  * @struct DolbyEHeaderInfo
35  * Coded Dolby E header values up to end_gain element, plus derived values.
36  */
37 typedef struct DolbyEHeaderInfo {
38     /** @name Coded elements
39      * @{
40      */
41     int         prog_conf;
42     int         nb_channels;
43     int         nb_programs;
44 
45     int         fr_code;
46     int         fr_code_orig;
47 
48     int         ch_size[MAX_CHANNELS];
49     int         mtd_ext_size;
50     int         meter_size;
51 
52     int         rev_id[MAX_CHANNELS];
53     int         begin_gain[MAX_CHANNELS];
54     int         end_gain[MAX_CHANNELS];
55     /** @} */
56 
57     /** @name Derived values
58      * @{
59      */
60     int         multi_prog_warned;
61 
62     int         sample_rate;
63     /** @} */
64 } DolbyEHeaderInfo;
65 
66 /**
67  * @struct DBEContext
68  * Dolby E reading context used by decoder and parser.
69  */
70 typedef struct DBEContext {
71     void        *avctx;
72     GetBitContext   gb;
73 
74     const uint8_t *input;
75     int         input_size;
76 
77     int         word_bits;
78     int         word_bytes;
79     int         key_present;
80 
81     DolbyEHeaderInfo metadata;
82 
83     uint8_t     buffer[1024 * 3 + AV_INPUT_BUFFER_PADDING_SIZE];
84 } DBEContext;
85 
86 /**
87  * Use the provided key to transform the input into data (put into s->buffer)
88  * suitable for further processing and initialize s->gb to read said data.
89  */
90 int ff_dolby_e_convert_input(DBEContext *s, int nb_words, int key);
91 
92 /**
93  * Initialize DBEContext and parse Dolby E metadata.
94  * Set word_bits/word_bytes, input, input_size, key_present
95  * and parse the header up to the end_gain element.
96  * @param[out] s DBEContext.
97  * @param[in]  buf raw input buffer.
98  * @param[in]  buf_size must be 3 bytes at least.
99  * @return Returns 0 on success, AVERROR_INVALIDDATA on error
100  */
101 int ff_dolby_e_parse_header(DBEContext *s, const uint8_t *buf, int buf_size);
102 
103 #endif
104