Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
3aca208a
Commit
3aca208a
authored
Nov 22, 2002
by
Mark Hills
Committed by
Zdenek Kabelac
Nov 22, 2002
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* Ogg/Vorbis patch by Mark Hills
Originally committed as revision 1268 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
9a7b310d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
224 additions
and
30 deletions
+224
-30
ogg.c
libav/ogg.c
+110
-9
allcodecs.c
libavcodec/allcodecs.c
+1
-0
avcodec.h
libavcodec/avcodec.h
+1
-0
oggvorbis.c
libavcodec/oggvorbis.c
+111
-20
regression.sh
tests/regression.sh
+1
-1
No files found.
libav/ogg.c
View file @
3aca208a
...
@@ -15,12 +15,18 @@
...
@@ -15,12 +15,18 @@
#include "avformat.h"
#include "avformat.h"
#include "oggvorbis.h"
#include "oggvorbis.h"
#define DECODER_BUFFER_SIZE 4096
typedef
struct
OggContext
{
typedef
struct
OggContext
{
/* output */
ogg_stream_state
os
;
ogg_stream_state
os
;
int
header_
written
;
int
header_
handled
;
ogg_int64_t
base_packet_no
;
ogg_int64_t
base_packet_no
;
ogg_int64_t
base_granule_pos
;
ogg_int64_t
base_granule_pos
;
/* input */
ogg_sync_state
oy
;
}
OggContext
;
}
OggContext
;
...
@@ -34,8 +40,6 @@ static int ogg_write_header(AVFormatContext *avfcontext) {
...
@@ -34,8 +40,6 @@ static int ogg_write_header(AVFormatContext *avfcontext) {
ogg_packet
header
,
header_comm
,
header_code
;
ogg_packet
header
,
header_comm
,
header_code
;
int
n
;
int
n
;
fprintf
(
stderr
,
"ogg_write_header
\n
"
)
;
if
(
!
(
context
=
malloc
(
sizeof
(
OggContext
))))
if
(
!
(
context
=
malloc
(
sizeof
(
OggContext
))))
return
-
1
;
return
-
1
;
avfcontext
->
priv_data
=
context
;
avfcontext
->
priv_data
=
context
;
...
@@ -75,7 +79,7 @@ static int ogg_write_header(AVFormatContext *avfcontext) {
...
@@ -75,7 +79,7 @@ static int ogg_write_header(AVFormatContext *avfcontext) {
/* end of vorbis specific code */
/* end of vorbis specific code */
context
->
header_
written
=
0
;
context
->
header_
handled
=
0
;
context
->
base_packet_no
=
0
;
context
->
base_packet_no
=
0
;
}
}
...
@@ -94,13 +98,13 @@ static int ogg_write_packet(AVFormatContext *avfcontext,
...
@@ -94,13 +98,13 @@ static int ogg_write_packet(AVFormatContext *avfcontext,
/* flush header packets so audio starts on a new page */
/* 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
))
{
while
(
ogg_stream_flush
(
&
context
->
os
,
&
og
))
{
put_buffer
(
&
avfcontext
->
pb
,
og
.
header
,
og
.
header_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
header
,
og
.
header_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
body
,
og
.
body_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
body
,
og
.
body_len
)
;
put_flush_packet
(
&
avfcontext
->
pb
);
put_flush_packet
(
&
avfcontext
->
pb
);
}
}
context
->
header_
written
=
1
;
context
->
header_
handled
=
1
;
}
}
while
(
l
<
size
)
{
while
(
l
<
size
)
{
...
@@ -135,8 +139,6 @@ static int ogg_write_trailer(AVFormatContext *avfcontext) {
...
@@ -135,8 +139,6 @@ static int ogg_write_trailer(AVFormatContext *avfcontext) {
OggContext
*
context
=
avfcontext
->
priv_data
;
OggContext
*
context
=
avfcontext
->
priv_data
;
ogg_page
og
;
ogg_page
og
;
fprintf
(
stderr
,
"ogg_write_trailer
\n
"
)
;
while
(
ogg_stream_flush
(
&
context
->
os
,
&
og
))
{
while
(
ogg_stream_flush
(
&
context
->
os
,
&
og
))
{
put_buffer
(
&
avfcontext
->
pb
,
og
.
header
,
og
.
header_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
header
,
og
.
header_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
body
,
og
.
body_len
)
;
put_buffer
(
&
avfcontext
->
pb
,
og
.
body
,
og
.
body_len
)
;
...
@@ -159,10 +161,109 @@ static AVOutputFormat ogg_oformat = {
...
@@ -159,10 +161,109 @@ static AVOutputFormat ogg_oformat = {
ogg_write_header
,
ogg_write_header
,
ogg_write_packet
,
ogg_write_packet
,
ogg_write_trailer
,
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
)
{
int
ogg_init
(
void
)
{
av_register_output_format
(
&
ogg_oformat
)
;
av_register_output_format
(
&
ogg_oformat
)
;
av_register_input_format
(
&
ogg_iformat
);
return
0
;
return
0
;
}
}
libavcodec/allcodecs.c
View file @
3aca208a
...
@@ -41,6 +41,7 @@ void avcodec_register_all(void)
...
@@ -41,6 +41,7 @@ void avcodec_register_all(void)
#endif
#endif
#ifdef CONFIG_VORBIS
#ifdef CONFIG_VORBIS
register_avcodec
(
&
oggvorbis_encoder
);
register_avcodec
(
&
oggvorbis_encoder
);
register_avcodec
(
&
oggvorbis_decoder
);
#endif
#endif
register_avcodec
(
&
mpeg1video_encoder
);
register_avcodec
(
&
mpeg1video_encoder
);
register_avcodec
(
&
h263_encoder
);
register_avcodec
(
&
h263_encoder
);
...
...
libavcodec/avcodec.h
View file @
3aca208a
...
@@ -865,6 +865,7 @@ extern AVCodec mp3_decoder;
...
@@ -865,6 +865,7 @@ extern AVCodec mp3_decoder;
extern
AVCodec
mace3_decoder
;
extern
AVCodec
mace3_decoder
;
extern
AVCodec
mace6_decoder
;
extern
AVCodec
mace6_decoder
;
extern
AVCodec
huffyuv_decoder
;
extern
AVCodec
huffyuv_decoder
;
extern
AVCodec
oggvorbis_decoder
;
/* pcm codecs */
/* pcm codecs */
#define PCM_CODEC(id, name) \
#define PCM_CODEC(id, name) \
...
...
libavcodec/oggvorbis.c
View file @
3aca208a
...
@@ -17,22 +17,16 @@ typedef struct OggVorbisContext {
...
@@ -17,22 +17,16 @@ typedef struct OggVorbisContext {
vorbis_info
vi
;
vorbis_info
vi
;
vorbis_dsp_state
vd
;
vorbis_dsp_state
vd
;
vorbis_block
vb
;
vorbis_block
vb
;
/* decoder */
vorbis_comment
vc
;
}
OggVorbisContext
;
}
OggVorbisContext
;
int
oggvorbis_init_encoder
(
vorbis_info
*
vi
,
AVCodecContext
*
avccontext
)
{
int
oggvorbis_init_encoder
(
vorbis_info
*
vi
,
AVCodecContext
*
avccontext
)
{
if
(
avccontext
->
quality
)
{
/* VBR requested */
if
(
avccontext
->
quality
)
/* VBR requested */
fprintf
(
stderr
,
"init_encode: channels=%d quality=%d
\n
"
,
avccontext
->
channels
,
avccontext
->
quality
)
;
return
vorbis_encode_init_vbr
(
vi
,
avccontext
->
channels
,
return
vorbis_encode_init_vbr
(
vi
,
avccontext
->
channels
,
avccontext
->
sample_rate
,
(
float
)
avccontext
->
quality
/
1000
)
;
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
,
return
vorbis_encode_init
(
vi
,
avccontext
->
channels
,
avccontext
->
sample_rate
,
-
1
,
avccontext
->
bit_rate
,
-
1
)
;
avccontext
->
sample_rate
,
-
1
,
avccontext
->
bit_rate
,
-
1
)
;
...
@@ -42,15 +36,11 @@ int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
...
@@ -42,15 +36,11 @@ int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
static
int
oggvorbis_encode_init
(
AVCodecContext
*
avccontext
)
{
static
int
oggvorbis_encode_init
(
AVCodecContext
*
avccontext
)
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
fprintf
(
stderr
,
"oggvorbis_encode_init
\n
"
)
;
vorbis_info_init
(
&
context
->
vi
)
;
vorbis_info_init
(
&
context
->
vi
)
;
if
(
oggvorbis_init_encoder
(
&
context
->
vi
,
avccontext
)
<
0
)
{
if
(
oggvorbis_init_encoder
(
&
context
->
vi
,
avccontext
)
<
0
)
{
fprintf
(
stderr
,
"oggvorbis_encode_init: init_encoder failed"
)
;
fprintf
(
stderr
,
"oggvorbis_encode_init: init_encoder failed"
)
;
return
-
1
;
return
-
1
;
}
}
vorbis_analysis_init
(
&
context
->
vd
,
&
context
->
vi
)
;
vorbis_analysis_init
(
&
context
->
vd
,
&
context
->
vi
)
;
vorbis_block_init
(
&
context
->
vd
,
&
context
->
vb
)
;
vorbis_block_init
(
&
context
->
vd
,
&
context
->
vb
)
;
...
@@ -60,14 +50,15 @@ static int oggvorbis_encode_init(AVCodecContext *avccontext) {
...
@@ -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
)
int
buf_size
,
void
*
data
)
{
{
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
float
**
buffer
;
float
**
buffer
;
ogg_packet
op
;
ogg_packet
op
;
signed
char
*
audio
=
data
;
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
)
;
buffer
=
vorbis_analysis_buffer
(
&
context
->
vd
,
samples
)
;
...
@@ -100,17 +91,17 @@ int oggvorbis_encode_frame(AVCodecContext *avccontext, unsigned char *packets,
...
@@ -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
;
OggVorbisContext
*
context
=
avccontext
->
priv_data
;
/* ogg_packet op ; */
/* ogg_packet op ; */
fprintf
(
stderr
,
"oggvorbis_encode_close
\n
"
)
;
vorbis_analysis_wrote
(
&
context
->
vd
,
0
)
;
/* notify vorbisenc this is EOF */
vorbis_analysis_wrote
(
&
context
->
vd
,
0
)
;
/* notify vorbisenc this is EOF */
/* We need to write all the remaining packets into the stream
/* We need to write all the remaining packets into the stream
* on closing */
* on closing */
fprintf
(
stderr
,
"fixme: not all packets written on oggvorbis_encode_close()
\n
"
)
;
/*
/*
while(vorbis_bitrate_flushpacket(&context->vd, &op)) {
while(vorbis_bitrate_flushpacket(&context->vd, &op)) {
memcpy(packets + l, &op, sizeof(ogg_packet)) ;
memcpy(packets + l, &op, sizeof(ogg_packet)) ;
...
@@ -135,6 +126,106 @@ AVCodec oggvorbis_encoder = {
...
@@ -135,6 +126,106 @@ AVCodec oggvorbis_encoder = {
oggvorbis_encode_init
,
oggvorbis_encode_init
,
oggvorbis_encode_frame
,
oggvorbis_encode_frame
,
oggvorbis_encode_close
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
View file @
3aca208a
...
@@ -36,7 +36,7 @@ fi
...
@@ -36,7 +36,7 @@ fi
# various files
# various files
ffmpeg
=
"../ffmpeg"
ffmpeg
=
"../ffmpeg
_g
"
outfile
=
"
$datadir
/a-"
outfile
=
"
$datadir
/a-"
reffile
=
"
$2
"
reffile
=
"
$2
"
benchfile
=
"
$datadir
/ffmpeg.bench"
benchfile
=
"
$datadir
/ffmpeg.bench"
...
...
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