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
d405237b
Commit
d405237b
authored
Oct 27, 2011
by
Justin Ruggles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
g726: split the init function for the encoder and decoder
This also allows for not having a decoder close function.
parent
c8d36d25
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
14 deletions
+35
-14
g726.c
libavcodec/g726.c
+35
-14
No files found.
libavcodec/g726.c
View file @
d405237b
...
@@ -295,11 +295,10 @@ static int16_t g726_encode(G726Context* c, int16_t sig)
...
@@ -295,11 +295,10 @@ static int16_t g726_encode(G726Context* c, int16_t sig)
g726_decode
(
c
,
i
);
g726_decode
(
c
,
i
);
return
i
;
return
i
;
}
}
#endif
/* Interfacing to the libavcodec */
/* Interfacing to the libavcodec */
static
av_cold
int
g726_
init
(
AVCodecContext
*
avctx
)
static
av_cold
int
g726_
encode_init
(
AVCodecContext
*
avctx
)
{
{
G726Context
*
c
=
avctx
->
priv_data
;
G726Context
*
c
=
avctx
->
priv_data
;
unsigned
int
index
;
unsigned
int
index
;
...
@@ -311,7 +310,7 @@ static av_cold int g726_init(AVCodecContext * avctx)
...
@@ -311,7 +310,7 @@ static av_cold int g726_init(AVCodecContext * avctx)
index
=
(
avctx
->
bit_rate
+
avctx
->
sample_rate
/
2
)
/
avctx
->
sample_rate
-
2
;
index
=
(
avctx
->
bit_rate
+
avctx
->
sample_rate
/
2
)
/
avctx
->
sample_rate
-
2
;
if
(
avctx
->
bit_rate
%
avctx
->
sample_rate
&&
avctx
->
codec
->
encode
)
{
if
(
avctx
->
bit_rate
%
avctx
->
sample_rate
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Bitrate - Samplerate combination is invalid
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Bitrate - Samplerate combination is invalid
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -331,24 +330,19 @@ static av_cold int g726_init(AVCodecContext * avctx)
...
@@ -331,24 +330,19 @@ static av_cold int g726_init(AVCodecContext * avctx)
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
avctx
->
coded_frame
->
key_frame
=
1
;
avctx
->
coded_frame
->
key_frame
=
1
;
if
(
avctx
->
codec
->
decode
)
avctx
->
sample_fmt
=
AV_SAMPLE_FMT_S16
;
/* select a frame size that will end on a byte boundary and have a size of
/* select a frame size that will end on a byte boundary and have a size of
approximately 1024 bytes */
approximately 1024 bytes */
if
(
avctx
->
codec
->
encode
)
avctx
->
frame_size
=
((
int
[]){
4096
,
2736
,
2048
,
1640
})[
index
];
avctx
->
frame_size
=
((
int
[]){
4096
,
2736
,
2048
,
1640
})[
index
];
return
0
;
return
0
;
}
}
static
av_cold
int
g726_close
(
AVCodecContext
*
avctx
)
static
av_cold
int
g726_
encode_
close
(
AVCodecContext
*
avctx
)
{
{
av_freep
(
&
avctx
->
coded_frame
);
av_freep
(
&
avctx
->
coded_frame
);
return
0
;
return
0
;
}
}
#if CONFIG_ADPCM_G726_ENCODER
static
int
g726_encode_frame
(
AVCodecContext
*
avctx
,
static
int
g726_encode_frame
(
AVCodecContext
*
avctx
,
uint8_t
*
dst
,
int
buf_size
,
void
*
data
)
uint8_t
*
dst
,
int
buf_size
,
void
*
data
)
{
{
...
@@ -368,6 +362,34 @@ static int g726_encode_frame(AVCodecContext *avctx,
...
@@ -368,6 +362,34 @@ static int g726_encode_frame(AVCodecContext *avctx,
}
}
#endif
#endif
static
av_cold
int
g726_decode_init
(
AVCodecContext
*
avctx
)
{
G726Context
*
c
=
avctx
->
priv_data
;
unsigned
int
index
;
if
(
avctx
->
sample_rate
<=
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Samplerate is invalid
\n
"
);
return
-
1
;
}
index
=
(
avctx
->
bit_rate
+
avctx
->
sample_rate
/
2
)
/
avctx
->
sample_rate
-
2
;
if
(
avctx
->
channels
!=
1
){
av_log
(
avctx
,
AV_LOG_ERROR
,
"Only mono is supported
\n
"
);
return
-
1
;
}
if
(
index
>
3
){
av_log
(
avctx
,
AV_LOG_ERROR
,
"Unsupported number of bits %d
\n
"
,
index
+
2
);
return
-
1
;
}
g726_reset
(
c
,
index
);
c
->
code_size
=
index
+
2
;
avctx
->
sample_fmt
=
AV_SAMPLE_FMT_S16
;
return
0
;
}
static
int
g726_decode_frame
(
AVCodecContext
*
avctx
,
static
int
g726_decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
int
*
data_size
,
void
*
data
,
int
*
data_size
,
AVPacket
*
avpkt
)
AVPacket
*
avpkt
)
...
@@ -404,9 +426,9 @@ AVCodec ff_adpcm_g726_encoder = {
...
@@ -404,9 +426,9 @@ AVCodec ff_adpcm_g726_encoder = {
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
id
=
CODEC_ID_ADPCM_G726
,
.
id
=
CODEC_ID_ADPCM_G726
,
.
priv_data_size
=
sizeof
(
G726Context
),
.
priv_data_size
=
sizeof
(
G726Context
),
.
init
=
g726_init
,
.
init
=
g726_
encode_
init
,
.
encode
=
g726_encode_frame
,
.
encode
=
g726_encode_frame
,
.
close
=
g726_close
,
.
close
=
g726_
encode_
close
,
.
capabilities
=
CODEC_CAP_SMALL_LAST_FRAME
,
.
capabilities
=
CODEC_CAP_SMALL_LAST_FRAME
,
.
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
(
"G.726 ADPCM"
),
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"G.726 ADPCM"
),
...
@@ -418,8 +440,7 @@ AVCodec ff_adpcm_g726_decoder = {
...
@@ -418,8 +440,7 @@ AVCodec ff_adpcm_g726_decoder = {
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
id
=
CODEC_ID_ADPCM_G726
,
.
id
=
CODEC_ID_ADPCM_G726
,
.
priv_data_size
=
sizeof
(
G726Context
),
.
priv_data_size
=
sizeof
(
G726Context
),
.
init
=
g726_init
,
.
init
=
g726_decode_init
,
.
close
=
g726_close
,
.
decode
=
g726_decode_frame
,
.
decode
=
g726_decode_frame
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"G.726 ADPCM"
),
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"G.726 ADPCM"
),
};
};
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