| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2018 Paul B Mahol | ||
| 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 "libavcodec/bsf.h" | ||
| 22 | #include "libavcodec/bsf_internal.h" | ||
| 23 | #include "libavcodec/get_bits.h" | ||
| 24 | #include "libavcodec/ac3_parser_internal.h" | ||
| 25 | |||
| 26 | 1 | static int eac3_core_init(AVBSFContext *ctx) | |
| 27 | { | ||
| 28 | 1 | ctx->par_out->profile = AV_PROFILE_UNKNOWN; | |
| 29 | |||
| 30 | 1 | return 0; | |
| 31 | } | ||
| 32 | |||
| 33 | 315 | static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt) | |
| 34 | { | ||
| 35 | AC3HeaderInfo hdr; | ||
| 36 | GetBitContext gbc; | ||
| 37 | int ret; | ||
| 38 | |||
| 39 | 315 | ret = ff_bsf_get_packet_ref(ctx, pkt); | |
| 40 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 157 times.
|
315 | if (ret < 0) |
| 41 | 158 | return ret; | |
| 42 | 157 | ret = init_get_bits8(&gbc, pkt->data, pkt->size); | |
| 43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
|
157 | if (ret < 0) |
| 44 | ✗ | goto fail; | |
| 45 | |||
| 46 | 157 | ret = ff_ac3_parse_header(&gbc, &hdr); | |
| 47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
|
157 | if (ret < 0) { |
| 48 | ✗ | ret = AVERROR_INVALIDDATA; | |
| 49 | ✗ | goto fail; | |
| 50 | } | ||
| 51 | |||
| 52 |
1/2✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
|
157 | if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT || |
| 53 |
1/2✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
|
157 | hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) { |
| 54 | 157 | pkt->size = FFMIN(hdr.frame_size, pkt->size); | |
| 55 | ✗ | } else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size > hdr.frame_size) { | |
| 56 | AC3HeaderInfo hdr2; | ||
| 57 | |||
| 58 | ✗ | ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size - hdr.frame_size); | |
| 59 | ✗ | if (ret < 0) | |
| 60 | ✗ | goto fail; | |
| 61 | |||
| 62 | ✗ | ret = ff_ac3_parse_header(&gbc, &hdr2); | |
| 63 | ✗ | if (ret < 0) { | |
| 64 | ✗ | ret = AVERROR_INVALIDDATA; | |
| 65 | ✗ | goto fail; | |
| 66 | } | ||
| 67 | |||
| 68 | ✗ | if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT || | |
| 69 | ✗ | hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) { | |
| 70 | ✗ | pkt->size -= hdr.frame_size; | |
| 71 | ✗ | pkt->data += hdr.frame_size; | |
| 72 | } else { | ||
| 73 | ✗ | pkt->size = 0; | |
| 74 | } | ||
| 75 | } else { | ||
| 76 | ✗ | pkt->size = 0; | |
| 77 | } | ||
| 78 | |||
| 79 | 157 | return 0; | |
| 80 | ✗ | fail: | |
| 81 | ✗ | av_packet_unref(pkt); | |
| 82 | ✗ | return ret; | |
| 83 | } | ||
| 84 | |||
| 85 | static const enum AVCodecID codec_ids[] = { | ||
| 86 | AV_CODEC_ID_EAC3, AV_CODEC_ID_NONE, | ||
| 87 | }; | ||
| 88 | |||
| 89 | const FFBitStreamFilter ff_eac3_core_bsf = { | ||
| 90 | .p.name = "eac3_core", | ||
| 91 | .p.codec_ids = codec_ids, | ||
| 92 | .init = eac3_core_init, | ||
| 93 | .filter = eac3_core_filter, | ||
| 94 | }; | ||
| 95 |