FFmpeg
libavcodec
eac3_core_bsf.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 "
bsf.h
"
22
#include "
bsf_internal.h
"
23
#include "
get_bits.h
"
24
#include "
ac3_parser_internal.h
"
25
26
static
int
eac3_core_filter
(
AVBSFContext
*
ctx
,
AVPacket
*
pkt
)
27
{
28
AC3HeaderInfo
hdr;
29
GetBitContext
gbc;
30
int
ret
;
31
32
ret
=
ff_bsf_get_packet_ref
(
ctx
,
pkt
);
33
if
(
ret
< 0)
34
return
ret
;
35
ret
=
init_get_bits8
(&gbc,
pkt
->
data
,
pkt
->
size
);
36
if
(
ret
< 0)
37
goto
fail
;
38
39
ret
=
ff_ac3_parse_header
(&gbc, &hdr);
40
if
(
ret
< 0) {
41
ret
=
AVERROR_INVALIDDATA
;
42
goto
fail
;
43
}
44
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
) {
49
AC3HeaderInfo
hdr2;
50
51
ret
=
init_get_bits8
(&gbc,
pkt
->
data
+ hdr.
frame_size
,
pkt
->
size
- hdr.
frame_size
);
52
if
(
ret
< 0)
53
goto
fail
;
54
55
ret
=
ff_ac3_parse_header
(&gbc, &hdr2);
56
if
(
ret
< 0) {
57
ret
=
AVERROR_INVALIDDATA
;
58
goto
fail
;
59
}
60
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
;
65
}
else
{
66
pkt
->
size
= 0;
67
}
68
}
else
{
69
pkt
->
size
= 0;
70
}
71
72
return
0;
73
fail
:
74
av_packet_unref
(
pkt
);
75
return
ret
;
76
}
77
78
static
const
enum
AVCodecID
codec_ids
[] = {
79
AV_CODEC_ID_EAC3
,
AV_CODEC_ID_NONE
,
80
};
81
82
const
FFBitStreamFilter
ff_eac3_core_bsf
= {
83
.
p
.
name
=
"eac3_core"
,
84
.p.codec_ids =
codec_ids
,
85
.filter =
eac3_core_filter
,
86
};
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition:
avpacket.c:422
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:374
AVBSFContext
The bitstream filter state.
Definition:
bsf.h:68
ff_eac3_core_bsf
const FFBitStreamFilter ff_eac3_core_bsf
Definition:
eac3_core_bsf.c:82
bsf.h
fail
#define fail()
Definition:
checkasm.h:134
GetBitContext
Definition:
get_bits.h:107
AC3HeaderInfo
Definition:
ac3_parser_internal.h:34
AC3HeaderInfo::frame_size
uint16_t frame_size
Definition:
ac3_parser_internal.h:61
EAC3_FRAME_TYPE_DEPENDENT
@ EAC3_FRAME_TYPE_DEPENDENT
Definition:
ac3defs.h:99
pkt
AVPacket * pkt
Definition:
movenc.c:59
eac3_core_filter
static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
Definition:
eac3_core_bsf.c:26
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition:
get_bits.h:524
EAC3_FRAME_TYPE_INDEPENDENT
@ EAC3_FRAME_TYPE_INDEPENDENT
Definition:
ac3defs.h:98
ctx
AVFormatContext * ctx
Definition:
movenc.c:48
get_bits.h
FFBitStreamFilter
Definition:
bsf_internal.h:27
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition:
codec_id.h:49
AV_CODEC_ID_EAC3
@ AV_CODEC_ID_EAC3
Definition:
codec_id.h:478
EAC3_FRAME_TYPE_AC3_CONVERT
@ EAC3_FRAME_TYPE_AC3_CONVERT
Definition:
ac3defs.h:100
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition:
bsf_internal.h:31
ac3_parser_internal.h
AVPacket::size
int size
Definition:
packet.h:375
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition:
codec_id.h:50
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:351
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:257
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition:
error.h:61
codec_ids
static enum AVCodecID codec_ids[]
Definition:
eac3_core_bsf.c:78
Generated on Tue Feb 28 2023 21:33:14 for FFmpeg by
1.8.17