Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
3aca208a
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3aca208a
编写于
11月 22, 2002
作者:
M
Mark Hills
提交者:
Zdenek Kabelac
11月 22, 2002
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* Ogg/Vorbis patch by Mark Hills
Originally committed as revision 1268 to
svn://svn.ffmpeg.org/ffmpeg/trunk
上级
9a7b310d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
224 addition
and
30 deletion
+224
-30
libav/ogg.c
libav/ogg.c
+110
-9
libavcodec/allcodecs.c
libavcodec/allcodecs.c
+1
-0
libavcodec/avcodec.h
libavcodec/avcodec.h
+1
-0
libavcodec/oggvorbis.c
libavcodec/oggvorbis.c
+111
-20
tests/regression.sh
tests/regression.sh
+1
-1
未找到文件。
libav/ogg.c
浏览文件 @
3aca208a
...
...
@@ -15,12 +15,18 @@
#include "avformat.h"
#include "oggvorbis.h"
#define DECODER_BUFFER_SIZE 4096
typedef
struct
OggContext
{
/* output */
ogg_stream_state
os
;
int
header_
written
;
int
header_
handled
;
ogg_int64_t
base_packet_no
;
ogg_int64_t
base_granule_pos
;
/* input */
ogg_sync_state
oy
;
}
OggContext
;
...
...
@@ -34,8 +40,6 @@ static int ogg_write_header(AVFormatContext *avfcontext) {
ogg_packet
header
,
header_comm
,
header_code
;
int
n
;
fprintf
(
stderr
,
"ogg_write_header
\n
"
)
;
if
(
!
(
context
=
malloc
(
sizeof
(
OggContext
))))
return
-
1
;
avfcontext
->
priv_data
=
context
;
...
...
@@ -75,7 +79,7 @@ static int ogg_write_header(AVFormatContext *avfcontext) {
/* end of vorbis specific code */
context
->
header_
written
=
0
;
context
->
header_
handled
=
0
;
context
->
base_packet_no
=
0
;
}
...
...
@@ -94,13 +98,13 @@ static int ogg_write_packet(AVFormatContext *avfcontext,
/* flush header packets so audio starts on a new page */
if
(
!
context
->
header_
written
)
{
if
(
!
context
->
header_
handled
)
{
while
(
ogg_stream_flush
(
&
context
->
os
,
&
og
))
{
put_buffer
(
&
avfcontext
->
pb
,
og
.
header
,
og
.
header_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
body
,
og
.
body_len
)
;
put_flush_packet
(
&
avfcontext
->
pb
);
}
context
->
header_
written
=
1
;
context
->
header_
handled
=
1
;
}
while
(
l
<
size
)
{
...
...
@@ -135,8 +139,6 @@ static int ogg_write_trailer(AVFormatContext *avfcontext) {
OggContext
*
context
=
avfcontext
->
priv_data
;
ogg_page
og
;
fprintf
(
stderr
,
"ogg_write_trailer
\n
"
)
;
while
(
ogg_stream_flush
(
&
context
->
os
,
&
og
))
{
put_buffer
(
&
avfcontext
->
pb
,
og
.
header
,
og
.
header_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
body
,
og
.
body_len
)
;
...
...
@@ -159,10 +161,109 @@ static AVOutputFormat ogg_oformat = {
ogg_write_header
,
ogg_write_packet
,
ogg_write_trailer
,
};
}
;
static
int
next_packet
(
AVFormatContext
*
avfcontext
,
ogg_packet
*
op
)
{
OggContext
*
context
=
avfcontext
->
priv_data
;
ogg_page
og
;
char
*
buf
;
while
(
ogg_stream_packetout
(
&
context
->
os
,
op
)
!=
1
)
{
/* while no pages are available, read in more data to the sync */
while
(
ogg_sync_pageout
(
&
context
->
oy
,
&
og
)
!=
1
)
{
buf
=
ogg_sync_buffer
(
&
context
->
oy
,
DECODER_BUFFER_SIZE
)
;
if
(
get_buffer
(
&
avfcontext
->
pb
,
buf
,
DECODER_BUFFER_SIZE
)
<=
0
)
return
1
;
ogg_sync_wrote
(
&
context
->
oy
,
DECODER_BUFFER_SIZE
)
;
}
/* got a page. Feed it into the stream and get the packet */
if
(
ogg_stream_pagein
(
&
context
->
os
,
&
og
)
!=
0
)
return
1
;
}
return
0
;
}
static
int
ogg_read_header
(
AVFormatContext
*
avfcontext
,
AVFormatParameters
*
ap
)
{
OggContext
*
context
;
char
*
buf
;
ogg_page
og
;
AVStream
*
ast
;
if
(
!
(
context
=
malloc
(
sizeof
(
OggContext
))))
{
perror
(
"malloc"
)
;
return
-
1
;
}
avfcontext
->
priv_data
=
context
;
ogg_sync_init
(
&
context
->
oy
)
;
buf
=
ogg_sync_buffer
(
&
context
->
oy
,
DECODER_BUFFER_SIZE
)
;
if
(
get_buffer
(
&
avfcontext
->
pb
,
buf
,
DECODER_BUFFER_SIZE
)
<=
0
)
return
-
EIO
;
ogg_sync_wrote
(
&
context
->
oy
,
DECODER_BUFFER_SIZE
)
;
ogg_sync_pageout
(
&
context
->
oy
,
&
og
)
;
ogg_stream_init
(
&
context
->
os
,
ogg_page_serialno
(
&
og
))
;
ogg_stream_pagein
(
&
context
->
os
,
&
og
)
;
/* currently only one vorbis stream supported */
ast
=
av_new_stream
(
avfcontext
,
0
)
;
if
(
!
ast
)
return
AVERROR_NOMEM
;
ast
->
codec
.
codec_type
=
CODEC_TYPE_AUDIO
;
ast
->
codec
.
codec_id
=
CODEC_ID_VORBIS
;
return
0
;
}
static
int
ogg_read_packet
(
AVFormatContext
*
avfcontext
,
AVPacket
*
pkt
)
{
ogg_packet
op
;
if
(
next_packet
(
avfcontext
,
&
op
))
return
-
EIO
;
if
(
av_new_packet
(
pkt
,
sizeof
(
ogg_packet
)
+
op
.
bytes
)
<
0
)
return
-
EIO
;
pkt
->
stream_index
=
0
;
memcpy
(
pkt
->
data
,
&
op
,
sizeof
(
ogg_packet
))
;
memcpy
(
pkt
->
data
+
sizeof
(
ogg_packet
),
op
.
packet
,
op
.
bytes
)
;
return
sizeof
(
ogg_packet
)
+
op
.
bytes
;
}
static
int
ogg_read_close
(
AVFormatContext
*
avfcontext
)
{
OggContext
*
context
=
avfcontext
->
priv_data
;
ogg_stream_clear
(
&
context
->
os
)
;
ogg_sync_clear
(
&
context
->
oy
)
;
return
0
;
}
static
AVInputFormat
ogg_iformat
=
{
"ogg"
,
"Ogg Vorbis"
,
sizeof
(
OggContext
),
NULL
,
ogg_read_header
,
ogg_read_packet
,
ogg_read_close
,
.
extensions
=
"ogg"
,
}
;
int
ogg_init
(
void
)
{
av_register_output_format
(
&
ogg_oformat
)
;
av_register_input_format
(
&
ogg_iformat
);
return
0
;
}
libavcodec/allcodecs.c
浏览文件 @
3aca208a
...
...
@@ -41,6 +41,7 @@ void avcodec_register_all(void)
#endif
#ifdef CONFIG_VORBIS
register_avcodec
(
&
oggvorbis_encoder
);
register_avcodec
(
&
oggvorbis_decoder
);
#endif
register_avcodec
(
&
mpeg1video_encoder
);
register_avcodec
(
&
h263_encoder
);
...
...
libavcodec/avcodec.h
浏览文件 @
3aca208a
...
...
@@ -865,6 +865,7 @@ extern AVCodec mp3_decoder;
extern
AVCodec
mace3_decoder
;
extern
AVCodec
mace6_decoder
;
extern
AVCodec
huffyuv_decoder
;
extern
AVCodec
oggvorbis_decoder
;
/* pcm codecs */
#define PCM_CODEC(id, name) \
...
...
libavcodec/oggvorbis.c
浏览文件 @
3aca208a
...
...
@@ -17,22 +17,16 @@ typedef struct OggVorbisContext {
vorbis_info
vi
;
vorbis_dsp_state
vd
;
vorbis_block
vb
;
/* decoder */
vorbis_comment
vc
;
}
OggVorbisContext
;
int
oggvorbis_init_encoder
(
vorbis_info
*
vi
,
AVCodecContext
*
avccontext
)
{
if
(
avccontext
->
quality
)
{
/* VBR requested */
fprintf
(
stderr
,
"init_encode: channels=%d quality=%d
\n
"
,
avccontext
->
channels
,
avccontext
->
quality
)
;
if
(
avccontext
->
quality
)
/* VBR requested */
return
vorbis_encode_init_vbr
(
vi
,
avccontext
->
channels
,
avccontext
->
sample_rate
,
(
float
)
avccontext
->
quality
/
1000
)
;
}
fprintf
(
stderr
,
"init_encoder: channels=%d bitrate=%d tolerance=%d
\n
"
,
avccontext
->
channels
,
avccontext
->
bit_rate
,
avccontext
->
bit_rate_tolerance
)
;
return
vorbis_encode_init
(
vi
,
avccontext
->
channels
,
avccontext
->
sample_rate
,
-
1
,
avccontext
->
bit_rate
,
-
1
)
;
...
...
@@ -42,15 +36,11 @@ int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
static
int
oggvorbis_encode_init
(
AVCodecContext
*
avccontext
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
fprintf
(
stderr
,
"oggvorbis_encode_init
\n
"
)
;
vorbis_info_init
(
&
context
->
vi
)
;
if
(
oggvorbis_init_encoder
(
&
context
->
vi
,
avccontext
)
<
0
)
{
fprintf
(
stderr
,
"oggvorbis_encode_init: init_encoder failed"
)
;
return
-
1
;
}
vorbis_analysis_init
(
&
context
->
vd
,
&
context
->
vi
)
;
vorbis_block_init
(
&
context
->
vd
,
&
context
->
vb
)
;
...
...
@@ -60,14 +50,15 @@ static int oggvorbis_encode_init(AVCodecContext *avccontext) {
}
int
oggvorbis_encode_frame
(
AVCodecContext
*
avccontext
,
unsigned
char
*
packets
,
static
int
oggvorbis_encode_frame
(
AVCodecContext
*
avccontext
,
unsigned
char
*
packets
,
int
buf_size
,
void
*
data
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
float
**
buffer
;
ogg_packet
op
;
signed
char
*
audio
=
data
;
int
l
,
samples
=
buf_size
/
16
;
/* samples = OGGVORBIS_FRAME_SIZE */
;
int
l
,
samples
=
OGGVORBIS_FRAME_SIZE
;
buffer
=
vorbis_analysis_buffer
(
&
context
->
vd
,
samples
)
;
...
...
@@ -100,17 +91,17 @@ int oggvorbis_encode_frame(AVCodecContext *avccontext, unsigned char *packets,
}
int
oggvorbis_encode_close
(
AVCodecContext
*
avccontext
)
{
static
int
oggvorbis_encode_close
(
AVCodecContext
*
avccontext
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
/* ogg_packet op ; */
fprintf
(
stderr
,
"oggvorbis_encode_close
\n
"
)
;
vorbis_analysis_wrote
(
&
context
->
vd
,
0
)
;
/* notify vorbisenc this is EOF */
/* We need to write all the remaining packets into the stream
* on closing */
fprintf
(
stderr
,
"fixme: not all packets written on oggvorbis_encode_close()
\n
"
)
;
/*
while(vorbis_bitrate_flushpacket(&context->vd, &op)) {
memcpy(packets + l, &op, sizeof(ogg_packet)) ;
...
...
@@ -135,6 +126,106 @@ AVCodec oggvorbis_encoder = {
oggvorbis_encode_init
,
oggvorbis_encode_frame
,
oggvorbis_encode_close
};
}
;
static
int
oggvorbis_decode_init
(
AVCodecContext
*
avccontext
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
vorbis_info_init
(
&
context
->
vi
)
;
vorbis_comment_init
(
&
context
->
vc
)
;
return
0
;
}
static
inline
int
conv
(
int
samples
,
float
**
pcm
,
char
*
buf
,
int
channels
)
{
int
i
,
j
,
val
;
ogg_int16_t
*
ptr
,
*
data
=
(
ogg_int16_t
*
)
buf
;
float
*
mono
;
for
(
i
=
0
;
i
<
channels
;
i
++
){
ptr
=
&
data
[
i
];
mono
=
pcm
[
i
]
;
for
(
j
=
0
;
j
<
samples
;
j
++
)
{
val
=
mono
[
j
]
*
32767
.
f
;
if
(
val
>
32767
)
val
=
32767
;
if
(
val
<
-
32768
)
val
=
-
32768
;
*
ptr
=
val
;
ptr
+=
channels
;
}
}
return
0
;
}
static
int
oggvorbis_decode_frame
(
AVCodecContext
*
avccontext
,
void
*
data
,
int
*
data_size
,
UINT8
*
buf
,
int
buf_size
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
ogg_packet
*
op
=
(
ogg_packet
*
)
buf
;
float
**
pcm
;
int
samples
,
total_samples
,
total_bytes
;
op
->
packet
=
(
char
*
)
op
+
sizeof
(
ogg_packet
)
;
/* correct data pointer */
if
(
op
->
packetno
<
3
)
{
vorbis_synthesis_headerin
(
&
context
->
vi
,
&
context
->
vc
,
op
)
;
return
buf_size
;
}
if
(
op
->
packetno
==
3
)
{
fprintf
(
stderr
,
"vorbis_decode: %d channel, %ldHz, encoder `%s'
\n
"
,
context
->
vi
.
channels
,
context
->
vi
.
rate
,
context
->
vc
.
vendor
);
avccontext
->
channels
=
context
->
vi
.
channels
;
avccontext
->
sample_rate
=
context
->
vi
.
rate
;
vorbis_synthesis_init
(
&
context
->
vd
,
&
context
->
vi
)
;
vorbis_block_init
(
&
context
->
vd
,
&
context
->
vb
);
}
if
(
vorbis_synthesis
(
&
context
->
vb
,
op
)
==
0
)
vorbis_synthesis_blockin
(
&
context
->
vd
,
&
context
->
vb
)
;
total_samples
=
0
;
total_bytes
=
0
;
while
((
samples
=
vorbis_synthesis_pcmout
(
&
context
->
vd
,
&
pcm
))
>
0
)
{
conv
(
samples
,
pcm
,
(
char
*
)
data
+
total_bytes
,
context
->
vi
.
channels
)
;
total_bytes
+=
samples
*
2
*
context
->
vi
.
channels
;
total_samples
+=
samples
;
vorbis_synthesis_read
(
&
context
->
vd
,
samples
)
;
}
*
data_size
=
total_bytes
;
return
buf_size
;
}
static
int
oggvorbis_decode_close
(
AVCodecContext
*
avccontext
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
vorbis_info_clear
(
&
context
->
vi
)
;
vorbis_comment_clear
(
&
context
->
vc
)
;
return
0
;
}
AVCodec
oggvorbis_decoder
=
{
"vorbis"
,
CODEC_TYPE_AUDIO
,
CODEC_ID_VORBIS
,
sizeof
(
OggVorbisContext
),
oggvorbis_decode_init
,
NULL
,
oggvorbis_decode_close
,
oggvorbis_decode_frame
,
}
;
tests/regression.sh
浏览文件 @
3aca208a
...
...
@@ -36,7 +36,7 @@ fi
# various files
ffmpeg
=
"../ffmpeg"
ffmpeg
=
"../ffmpeg
_g
"
outfile
=
"
$datadir
/a-"
reffile
=
"
$2
"
benchfile
=
"
$datadir
/ffmpeg.bench"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录