Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
d405237b
Commit
d405237b
authored
13 years ago
by
Justin Ruggles
Browse files
Options
Downloads
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
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavcodec/g726.c
+35
-14
35 additions, 14 deletions
libavcodec/g726.c
with
35 additions
and
14 deletions
libavcodec/g726.c
+
35
−
14
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"
),
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment