Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
eb35ef29
Commit
eb35ef29
authored
Feb 28, 2012
by
Justin Ruggles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libvorbis: cosmetics: renaming/pretty-printing/comments/unused code
parent
4e99501f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
109 deletions
+115
-109
libvorbis.c
libavcodec/libvorbis.c
+115
-109
No files found.
libavcodec/libvorbis.c
View file @
eb35ef29
...
...
@@ -20,7 +20,7 @@
/**
* @file
*
Ogg Vorbis codec
support via libvorbisenc.
*
Vorbis encoding
support via libvorbisenc.
* @author Mark Hills <mark@pogo.org.uk>
*/
...
...
@@ -35,24 +35,26 @@
#undef NDEBUG
#include <assert.h>
/* Number of samples the user should send in each call.
* This value is used because it is the LCD of all possible frame sizes, so
* an output packet will always start at the same point as one of the input
* packets.
*/
#define OGGVORBIS_FRAME_SIZE 64
#define BUFFER_SIZE (1024 * 64)
typedef
struct
OggVorbisContext
{
AVClass
*
av_class
;
vorbis_info
vi
;
vorbis_dsp_state
vd
;
vorbis_block
vb
;
uint8_t
buffer
[
BUFFER_SIZE
];
int
buffer_index
;
int
eof
;
/* decoder */
vorbis_comment
vc
;
ogg_packet
op
;
double
iblock
;
AVClass
*
av_class
;
/**< class for AVOptions */
vorbis_info
vi
;
/**< vorbis_info used during init */
vorbis_dsp_state
vd
;
/**< DSP state used for analysis */
vorbis_block
vb
;
/**< vorbis_block used for analysis */
uint8_t
buffer
[
BUFFER_SIZE
];
/**< output packet buffer */
int
buffer_index
;
/**< current buffer position */
int
eof
;
/**< end-of-file flag */
vorbis_comment
vc
;
/**< VorbisComment info */
ogg_packet
op
;
/**< ogg packet */
double
iblock
;
/**< impulse block bias option */
}
OggVorbisContext
;
static
const
AVOption
options
[]
=
{
...
...
@@ -61,6 +63,7 @@ static const AVOption options[] = {
};
static
const
AVClass
class
=
{
"libvorbis"
,
av_default_item_name
,
options
,
LIBAVUTIL_VERSION_INT
};
static
int
vorbis_error_to_averror
(
int
ov_err
)
{
switch
(
ov_err
)
{
...
...
@@ -71,27 +74,31 @@ static int vorbis_error_to_averror(int ov_err)
}
}
static
av_cold
int
oggvorbis_init_encoder
(
vorbis_info
*
vi
,
AVCodecContext
*
avccontext
)
static
av_cold
int
oggvorbis_init_encoder
(
vorbis_info
*
vi
,
AVCodecContext
*
avctx
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
OggVorbisContext
*
s
=
avctx
->
priv_data
;
double
cfreq
;
int
ret
;
if
(
avccontext
->
flags
&
CODEC_FLAG_QSCALE
)
{
/* variable bitrate */
float
q
=
avccontext
->
global_quality
/
(
float
)
FF_QP2LAMBDA
;
if
((
ret
=
vorbis_encode_setup_vbr
(
vi
,
avccontext
->
channels
,
avccontext
->
sample_rate
,
if
(
avctx
->
flags
&
CODEC_FLAG_QSCALE
)
{
/* variable bitrate
* NOTE: we use the oggenc range of -1 to 10 for global_quality for
* user convenience, but libvorbis uses -0.1 to 1.0
*/
float
q
=
avctx
->
global_quality
/
(
float
)
FF_QP2LAMBDA
;
if
((
ret
=
vorbis_encode_setup_vbr
(
vi
,
avctx
->
channels
,
avctx
->
sample_rate
,
q
/
10
.
0
)))
goto
error
;
}
else
{
int
minrate
=
avc
context
->
rc_min_rate
>
0
?
avccontext
->
rc_min_rate
:
-
1
;
int
maxrate
=
avc
context
->
rc_min_rate
>
0
?
avccontext
->
rc_max_rate
:
-
1
;
int
minrate
=
avc
tx
->
rc_min_rate
>
0
?
avctx
->
rc_min_rate
:
-
1
;
int
maxrate
=
avc
tx
->
rc_min_rate
>
0
?
avctx
->
rc_max_rate
:
-
1
;
/*
constant
bitrate */
if
((
ret
=
vorbis_encode_setup_managed
(
vi
,
avc
context
->
channels
,
avc
context
->
sample_rate
,
minrate
,
avc
context
->
bit_rate
,
maxrate
)))
/*
average
bitrate */
if
((
ret
=
vorbis_encode_setup_managed
(
vi
,
avc
tx
->
channels
,
avc
tx
->
sample_rate
,
minrate
,
avc
tx
->
bit_rate
,
maxrate
)))
goto
error
;
/* variable bitrate by estimate, disable slow rate management */
...
...
@@ -101,14 +108,15 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco
}
/* cutoff frequency */
if
(
avc
context
->
cutoff
>
0
)
{
cfreq
=
avc
context
->
cutoff
/
1000
.
0
;
if
(
avc
tx
->
cutoff
>
0
)
{
cfreq
=
avc
tx
->
cutoff
/
1000
.
0
;
if
((
ret
=
vorbis_encode_ctl
(
vi
,
OV_ECTL_LOWPASS_SET
,
&
cfreq
)))
goto
error
;
}
if
(
context
->
iblock
)
{
if
((
ret
=
vorbis_encode_ctl
(
vi
,
OV_ECTL_IBLOCK_SET
,
&
context
->
iblock
)))
/* impulse block bias */
if
(
s
->
iblock
)
{
if
((
ret
=
vorbis_encode_ctl
(
vi
,
OV_ECTL_IBLOCK_SET
,
&
s
->
iblock
)))
goto
error
;
}
...
...
@@ -126,59 +134,59 @@ static int xiph_len(int l)
return
1
+
l
/
255
+
l
;
}
static
av_cold
int
oggvorbis_encode_close
(
AVCodecContext
*
avc
context
)
static
av_cold
int
oggvorbis_encode_close
(
AVCodecContext
*
avc
tx
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
/* ogg_packet op ; */
OggVorbisContext
*
s
=
avctx
->
priv_data
;
vorbis_analysis_wrote
(
&
context
->
vd
,
0
);
/* notify vorbisenc this is EOF */
/* notify vorbisenc this is EOF */
vorbis_analysis_wrote
(
&
s
->
vd
,
0
);
vorbis_block_clear
(
&
context
->
vb
);
vorbis_dsp_clear
(
&
context
->
vd
);
vorbis_info_clear
(
&
context
->
vi
);
vorbis_block_clear
(
&
s
->
vb
);
vorbis_dsp_clear
(
&
s
->
vd
);
vorbis_info_clear
(
&
s
->
vi
);
av_freep
(
&
avc
context
->
coded_frame
);
av_freep
(
&
avc
context
->
extradata
);
av_freep
(
&
avc
tx
->
coded_frame
);
av_freep
(
&
avc
tx
->
extradata
);
return
0
;
}
static
av_cold
int
oggvorbis_encode_init
(
AVCodecContext
*
avc
context
)
static
av_cold
int
oggvorbis_encode_init
(
AVCodecContext
*
avc
tx
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
OggVorbisContext
*
s
=
avctx
->
priv_data
;
ogg_packet
header
,
header_comm
,
header_code
;
uint8_t
*
p
;
unsigned
int
offset
;
int
ret
;
vorbis_info_init
(
&
context
->
vi
);
if
((
ret
=
oggvorbis_init_encoder
(
&
context
->
vi
,
avccontext
)))
{
av_log
(
avc
context
,
AV_LOG_ERROR
,
"oggvorbis_encode_init: init_encoder failed
\n
"
);
vorbis_info_init
(
&
s
->
vi
);
if
((
ret
=
oggvorbis_init_encoder
(
&
s
->
vi
,
avctx
)))
{
av_log
(
avc
tx
,
AV_LOG_ERROR
,
"oggvorbis_encode_init: init_encoder failed
\n
"
);
goto
error
;
}
if
((
ret
=
vorbis_analysis_init
(
&
context
->
vd
,
&
context
->
vi
)))
{
if
((
ret
=
vorbis_analysis_init
(
&
s
->
vd
,
&
s
->
vi
)))
{
ret
=
vorbis_error_to_averror
(
ret
);
goto
error
;
}
if
((
ret
=
vorbis_block_init
(
&
context
->
vd
,
&
context
->
vb
)))
{
if
((
ret
=
vorbis_block_init
(
&
s
->
vd
,
&
s
->
vb
)))
{
ret
=
vorbis_error_to_averror
(
ret
);
goto
error
;
}
vorbis_comment_init
(
&
context
->
vc
);
vorbis_comment_add_tag
(
&
context
->
vc
,
"encoder"
,
LIBAVCODEC_IDENT
);
vorbis_comment_init
(
&
s
->
vc
);
vorbis_comment_add_tag
(
&
s
->
vc
,
"encoder"
,
LIBAVCODEC_IDENT
);
if
((
ret
=
vorbis_analysis_headerout
(
&
context
->
vd
,
&
context
->
vc
,
&
header
,
&
header_co
mm
,
&
header_co
de
)))
{
if
((
ret
=
vorbis_analysis_headerout
(
&
s
->
vd
,
&
s
->
vc
,
&
header
,
&
header_comm
,
&
header_code
)))
{
ret
=
vorbis_error_to_averror
(
ret
);
goto
error
;
}
avc
context
->
extradata_size
=
1
+
xiph_len
(
header
.
bytes
)
+
xiph_len
(
header_comm
.
bytes
)
+
header_code
.
bytes
;
p
=
avc
context
->
extradata
=
av_malloc
(
avccontext
->
extradata_size
+
FF_INPUT_BUFFER_PADDING_SIZE
);
avc
tx
->
extradata_size
=
1
+
xiph_len
(
header
.
bytes
)
+
xiph_len
(
header_comm
.
bytes
)
+
header_code
.
bytes
;
p
=
avc
tx
->
extradata
=
av_malloc
(
avctx
->
extradata_size
+
FF_INPUT_BUFFER_PADDING_SIZE
);
if
(
!
p
)
{
ret
=
AVERROR
(
ENOMEM
);
goto
error
;
...
...
@@ -193,100 +201,97 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
offset
+=
header_comm
.
bytes
;
memcpy
(
&
p
[
offset
],
header_code
.
packet
,
header_code
.
bytes
);
offset
+=
header_code
.
bytes
;
assert
(
offset
==
avc
context
->
extradata_size
);
assert
(
offset
==
avc
tx
->
extradata_size
);
#if 0
vorbis_block_clear(&context->vb);
vorbis_dsp_clear(&context->vd);
vorbis_info_clear(&context->vi);
#endif
vorbis_comment_clear
(
&
context
->
vc
);
vorbis_comment_clear
(
&
s
->
vc
);
avc
context
->
frame_size
=
OGGVORBIS_FRAME_SIZE
;
avc
tx
->
frame_size
=
OGGVORBIS_FRAME_SIZE
;
avc
context
->
coded_frame
=
avcodec_alloc_frame
();
if
(
!
avc
context
->
coded_frame
)
{
avc
tx
->
coded_frame
=
avcodec_alloc_frame
();
if
(
!
avc
tx
->
coded_frame
)
{
ret
=
AVERROR
(
ENOMEM
);
goto
error
;
}
return
0
;
error:
oggvorbis_encode_close
(
avc
context
);
oggvorbis_encode_close
(
avc
tx
);
return
ret
;
}
static
int
oggvorbis_encode_frame
(
AVCodecContext
*
avccontext
,
unsigned
char
*
packets
,
static
int
oggvorbis_encode_frame
(
AVCodecContext
*
avctx
,
unsigned
char
*
packets
,
int
buf_size
,
void
*
data
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
OggVorbisContext
*
s
=
avctx
->
priv_data
;
ogg_packet
op
;
signed
short
*
audio
=
data
;
int
l
;
int
pkt_size
;
/* send samples to libvorbis */
if
(
data
)
{
const
int
samples
=
avc
context
->
frame_size
;
const
int
samples
=
avc
tx
->
frame_size
;
float
**
buffer
;
int
c
,
channels
=
context
->
vi
.
channels
;
int
c
,
channels
=
s
->
vi
.
channels
;
buffer
=
vorbis_analysis_buffer
(
&
context
->
vd
,
samples
);
buffer
=
vorbis_analysis_buffer
(
&
s
->
vd
,
samples
);
for
(
c
=
0
;
c
<
channels
;
c
++
)
{
int
i
;
int
co
=
(
channels
>
8
)
?
c
:
ff_vorbis_encoding_channel_layout_offsets
[
channels
-
1
][
c
];
for
(
l
=
0
;
l
<
samples
;
l
++
)
buffer
[
c
][
l
]
=
audio
[
l
*
channels
+
co
]
/
32768
.
f
;
for
(
i
=
0
;
i
<
samples
;
i
++
)
buffer
[
c
][
i
]
=
audio
[
i
*
channels
+
co
]
/
32768
.
f
;
}
vorbis_analysis_wrote
(
&
context
->
vd
,
samples
);
vorbis_analysis_wrote
(
&
s
->
vd
,
samples
);
}
else
{
if
(
!
context
->
eof
)
vorbis_analysis_wrote
(
&
context
->
vd
,
0
);
context
->
eof
=
1
;
if
(
!
s
->
eof
)
vorbis_analysis_wrote
(
&
s
->
vd
,
0
);
s
->
eof
=
1
;
}
while
(
vorbis_analysis_blockout
(
&
context
->
vd
,
&
context
->
vb
)
==
1
)
{
vorbis_analysis
(
&
context
->
vb
,
NULL
);
vorbis_bitrate_addblock
(
&
context
->
vb
);
/* retrieve available packets from libvorbis */
while
(
vorbis_analysis_blockout
(
&
s
->
vd
,
&
s
->
vb
)
==
1
)
{
vorbis_analysis
(
&
s
->
vb
,
NULL
);
vorbis_bitrate_addblock
(
&
s
->
vb
);
while
(
vorbis_bitrate_flushpacket
(
&
context
->
vd
,
&
op
))
{
/* add any available packets to the output packet buffer */
while
(
vorbis_bitrate_flushpacket
(
&
s
->
vd
,
&
op
))
{
/* i'd love to say the following line is a hack, but sadly it's
* not, apparently the end of stream decision is in libogg. */
if
(
op
.
bytes
==
1
&&
op
.
e_o_s
)
continue
;
if
(
context
->
buffer_index
+
sizeof
(
ogg_packet
)
+
op
.
bytes
>
BUFFER_SIZE
)
{
av_log
(
avc
context
,
AV_LOG_ERROR
,
"libvorbis: buffer overflow."
);
if
(
s
->
buffer_index
+
sizeof
(
ogg_packet
)
+
op
.
bytes
>
BUFFER_SIZE
)
{
av_log
(
avc
tx
,
AV_LOG_ERROR
,
"libvorbis: buffer overflow."
);
return
-
1
;
}
memcpy
(
context
->
buffer
+
context
->
buffer_index
,
&
op
,
sizeof
(
ogg_packet
));
context
->
buffer_index
+=
sizeof
(
ogg_packet
);
memcpy
(
context
->
buffer
+
context
->
buffer_index
,
op
.
packet
,
op
.
bytes
);
context
->
buffer_index
+=
op
.
bytes
;
// av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes);
memcpy
(
s
->
buffer
+
s
->
buffer_index
,
&
op
,
sizeof
(
ogg_packet
));
s
->
buffer_index
+=
sizeof
(
ogg_packet
);
memcpy
(
s
->
buffer
+
s
->
buffer_index
,
op
.
packet
,
op
.
bytes
);
s
->
buffer_index
+=
op
.
bytes
;
}
}
l
=
0
;
if
(
context
->
buffer_index
)
{
ogg_packet
*
op2
=
(
ogg_packet
*
)
context
->
buffer
;
o
p2
->
packet
=
context
->
buffer
+
sizeof
(
ogg_packet
)
;
l
=
op2
->
bytes
;
avccontext
->
coded_frame
->
pts
=
ff_samples_to_time_base
(
avccontext
,
op2
->
granulepos
);
//FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
if
(
l
>
buf_size
)
{
av_log
(
avc
context
,
AV_LOG_ERROR
,
"libvorbis: buffer overflow."
);
/* output then next packet from the output buffer, if available */
pkt_size
=
0
;
if
(
s
->
buffer_index
)
{
o
gg_packet
*
op2
=
(
ogg_packet
*
)
s
->
buffer
;
op2
->
packet
=
s
->
buffer
+
sizeof
(
ogg_packet
);
pkt_size
=
op2
->
bytes
;
// FIXME: we should use the user-supplied pts and duration
avctx
->
coded_frame
->
pts
=
ff_samples_to_time_base
(
avctx
,
op2
->
granulepos
);
if
(
pkt_size
>
buf_size
)
{
av_log
(
avc
tx
,
AV_LOG_ERROR
,
"libvorbis: buffer overflow."
);
return
-
1
;
}
memcpy
(
packets
,
op2
->
packet
,
l
);
context
->
buffer_index
-=
l
+
sizeof
(
ogg_packet
);
memmove
(
context
->
buffer
,
context
->
buffer
+
l
+
sizeof
(
ogg_packet
),
context
->
buffer_index
);
// av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l
);
memcpy
(
packets
,
op2
->
packet
,
pkt_size
);
s
->
buffer_index
-=
pkt_size
+
sizeof
(
ogg_packet
);
memmove
(
s
->
buffer
,
s
->
buffer
+
pkt_size
+
sizeof
(
ogg_packet
),
s
->
buffer_index
);
}
return
l
;
return
pkt_size
;
}
AVCodec
ff_libvorbis_encoder
=
{
...
...
@@ -298,7 +303,8 @@ AVCodec ff_libvorbis_encoder = {
.
encode
=
oggvorbis_encode_frame
,
.
close
=
oggvorbis_encode_close
,
.
capabilities
=
CODEC_CAP_DELAY
,
.
sample_fmts
=
(
const
enum
AVSampleFormat
[])
{
AV_SAMPLE_FMT_S16
,
AV_SAMPLE_FMT_NONE
},
.
sample_fmts
=
(
const
enum
AVSampleFormat
[])
{
AV_SAMPLE_FMT_S16
,
AV_SAMPLE_FMT_NONE
},
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"libvorbis Vorbis"
),
.
priv_class
=
&
class
,
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment