]> git.sesse.net Git - ffmpeg/blob - libavcodec/dolby_e_parser.c
avcodec/dolby_e: split decoder and parser more thoroughly
[ffmpeg] / libavcodec / dolby_e_parser.c
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 #include "parser.h"
22
23 #include "dolby_e.h"
24 #include "get_bits.h"
25 #include "put_bits.h"
26
27 typedef struct DBEParseContext {
28     ParseContext pc;
29     DBEContext dectx;
30
31     DolbyEHeaderInfo metadata;
32 } DBEParseContext;
33
34 static int dolby_e_parse(AVCodecParserContext *s2, AVCodecContext *avctx,
35                         const uint8_t **poutbuf, int *poutbuf_size,
36                         const uint8_t *buf, int buf_size)
37 {
38     DBEParseContext *s1 = s2->priv_data;
39     DBEContext *s = &s1->dectx;
40     int ret;
41
42     if ((ret = ff_dolby_e_parse_init(s, buf, buf_size)) < 0)
43         goto end;
44
45     if ((ret = ff_dolby_e_parse_header(s, &s1->metadata)) < 0)
46         goto end;
47
48     s2->duration = FRAME_SAMPLES;
49     switch (s1->metadata.nb_channels) {
50     case 4:
51         avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
52         break;
53     case 6:
54         avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
55         break;
56     case 8:
57         avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
58         break;
59     }
60
61     avctx->channels    = s1->metadata.nb_channels;
62     avctx->sample_rate = sample_rate_tab[s1->metadata.fr_code];
63     avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
64
65 end:
66     /* always return the full packet. this parser isn't doing any splitting or
67        combining, only packet analysis */
68     *poutbuf      = buf;
69     *poutbuf_size = buf_size;
70     return buf_size;
71 }
72
73 AVCodecParser ff_dolby_e_parser = {
74     .codec_ids      = { AV_CODEC_ID_DOLBY_E },
75     .priv_data_size = sizeof(DBEParseContext),
76     .parser_parse   = dolby_e_parse,
77     .parser_close   = ff_parse_close,
78 };