1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-09-07 16:40:10 +02:00
ffmpeg/libavcodec/dolby_e_parser.c
James Almer 81d070dd09 avcodec/dolby_e: split decoder and parser more thoroughly
Neither module should depend on the other.

Move shared functions to its own file for this purpose, and ensure
source files are compiled only when the required modules are enabled.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-01-25 16:45:20 -03:00

79 lines
2.3 KiB
C

/*
* Copyright (C) 2017 foo86
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "parser.h"
#include "dolby_e.h"
#include "get_bits.h"
#include "put_bits.h"
typedef struct DBEParseContext {
ParseContext pc;
DBEContext dectx;
DolbyEHeaderInfo metadata;
} DBEParseContext;
static int dolby_e_parse(AVCodecParserContext *s2, AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
DBEParseContext *s1 = s2->priv_data;
DBEContext *s = &s1->dectx;
int ret;
if ((ret = ff_dolby_e_parse_init(s, buf, buf_size)) < 0)
goto end;
if ((ret = ff_dolby_e_parse_header(s, &s1->metadata)) < 0)
goto end;
s2->duration = FRAME_SAMPLES;
switch (s1->metadata.nb_channels) {
case 4:
avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
break;
case 6:
avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
break;
case 8:
avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
break;
}
avctx->channels = s1->metadata.nb_channels;
avctx->sample_rate = sample_rate_tab[s1->metadata.fr_code];
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
end:
/* always return the full packet. this parser isn't doing any splitting or
combining, only packet analysis */
*poutbuf = buf;
*poutbuf_size = buf_size;
return buf_size;
}
AVCodecParser ff_dolby_e_parser = {
.codec_ids = { AV_CODEC_ID_DOLBY_E },
.priv_data_size = sizeof(DBEParseContext),
.parser_parse = dolby_e_parse,
.parser_close = ff_parse_close,
};