FFmpeg
eac3_core.c
Go to the documentation of this file.
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"
23 #include "libavcodec/get_bits.h"
25 
27 {
28  ctx->par_out->profile = AV_PROFILE_UNKNOWN;
29 
30  return 0;
31 }
32 
34 {
35  AC3HeaderInfo hdr;
36  GetBitContext gbc;
37  int ret;
38 
40  if (ret < 0)
41  return ret;
42  ret = init_get_bits8(&gbc, pkt->data, pkt->size);
43  if (ret < 0)
44  goto fail;
45 
46  ret = ff_ac3_parse_header(&gbc, &hdr);
47  if (ret < 0) {
49  goto fail;
50  }
51 
54  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) {
65  goto fail;
66  }
67 
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  return 0;
80 fail:
82  return ret;
83 }
84 
85 static const enum AVCodecID codec_ids[] = {
87 };
88 
90  .p.name = "eac3_core",
91  .p.codec_ids = codec_ids,
92  .init = eac3_core_init,
93  .filter = eac3_core_filter,
94 };
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
eac3_core_filter
static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
Definition: eac3_core.c:33
AC3HeaderInfo::frame_type
uint8_t frame_type
Definition: ac3_parser_internal.h:45
bsf_internal.h
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
AVPacket::data
uint8_t * data
Definition: packet.h:603
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
bsf.h
GetBitContext
Definition: get_bits.h:109
AC3HeaderInfo
Definition: ac3_parser_internal.h:34
AC3HeaderInfo::frame_size
uint16_t frame_size
Definition: ac3_parser_internal.h:62
EAC3_FRAME_TYPE_DEPENDENT
@ EAC3_FRAME_TYPE_DEPENDENT
Definition: ac3defs.h:112
codec_ids
static enum AVCodecID codec_ids[]
Definition: eac3_core.c:85
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
EAC3_FRAME_TYPE_INDEPENDENT
@ EAC3_FRAME_TYPE_INDEPENDENT
Definition: ac3defs.h:111
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
get_bits.h
fail
#define fail
Definition: test.h:478
FFBitStreamFilter
Definition: bsf_internal.h:29
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AV_CODEC_ID_EAC3
@ AV_CODEC_ID_EAC3
Definition: codec_id.h:493
EAC3_FRAME_TYPE_AC3_CONVERT
@ EAC3_FRAME_TYPE_AC3_CONVERT
Definition: ac3defs.h:113
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:33
ff_eac3_core_bsf
const FFBitStreamFilter ff_eac3_core_bsf
Definition: eac3_core.c:89
ac3_parser_internal.h
AVPacket::size
int size
Definition: packet.h:604
eac3_core_init
static int eac3_core_init(AVBSFContext *ctx)
Definition: eac3_core.c:26
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ret
ret
Definition: filter_design.txt:187
ff_ac3_parse_header
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
Parse AC-3 frame header.
AVPacket
This structure stores compressed data.
Definition: packet.h:580
ff_bsf_get_packet_ref
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:254
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
pkt
static AVPacket * pkt
Definition: demux_decode.c:55