2 * Copyright (c) 2018 Paul B Mahol
4 * This file is part of FFmpeg.
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.
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.
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
22 #include "bsf_internal.h"
24 #include "ac3_parser_internal.h"
26 static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
32 ret = ff_bsf_get_packet_ref(ctx, pkt);
35 ret = init_get_bits8(&gbc, pkt->data, pkt->size);
39 ret = ff_ac3_parse_header(&gbc, &hdr);
41 ret = AVERROR_INVALIDDATA;
45 if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
46 hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
47 pkt->size = FFMIN(hdr.frame_size, pkt->size);
48 } else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size > hdr.frame_size) {
51 ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size - hdr.frame_size);
55 ret = ff_ac3_parse_header(&gbc, &hdr2);
57 ret = AVERROR_INVALIDDATA;
61 if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
62 hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
63 pkt->size -= hdr.frame_size;
64 pkt->data += hdr.frame_size;
78 static const enum AVCodecID codec_ids[] = {
79 AV_CODEC_ID_EAC3, AV_CODEC_ID_NONE,
82 const AVBitStreamFilter ff_eac3_core_bsf = {
84 .filter = eac3_core_filter,
85 .codec_ids = codec_ids,