Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
7d532f47
Commit
7d532f47
authored
Jan 20, 2022
by
James Almer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: convert to new channel layout-API
Signed-off-by:
James Almer
<
jamrial@gmail.com
>
parent
0995e1f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
16 deletions
+19
-16
avcodec.c
libavcodec/tests/avcodec.c
+1
-1
api-flac-test.c
tests/api/api-flac-test.c
+18
-15
No files found.
libavcodec/tests/avcodec.c
View file @
7d532f47
...
@@ -76,7 +76,7 @@ int main(void){
...
@@ -76,7 +76,7 @@ int main(void){
ERR_EXT
(
"Codec %s has unsupported type %s
\n
"
,
ERR_EXT
(
"Codec %s has unsupported type %s
\n
"
,
get_type_string
(
codec
->
type
));
get_type_string
(
codec
->
type
));
if
(
codec
->
type
!=
AVMEDIA_TYPE_AUDIO
)
{
if
(
codec
->
type
!=
AVMEDIA_TYPE_AUDIO
)
{
if
(
codec
->
ch
annel
_layouts
||
codec
->
sample_fmts
||
if
(
codec
->
ch_layouts
||
codec
->
sample_fmts
||
codec
->
supported_samplerates
)
codec
->
supported_samplerates
)
ERR
(
"Non-audio codec %s has audio-only fields set
\n
"
);
ERR
(
"Non-audio codec %s has audio-only fields set
\n
"
);
if
(
codec
->
capabilities
&
(
AV_CODEC_CAP_SMALL_LAST_FRAME
|
if
(
codec
->
capabilities
&
(
AV_CODEC_CAP_SMALL_LAST_FRAME
|
...
...
tests/api/api-flac-test.c
View file @
7d532f47
...
@@ -50,13 +50,13 @@ static int generate_raw_frame(uint16_t *frame_data, int i, int sample_rate,
...
@@ -50,13 +50,13 @@ static int generate_raw_frame(uint16_t *frame_data, int i, int sample_rate,
}
}
static
int
init_encoder
(
const
AVCodec
*
enc
,
AVCodecContext
**
enc_ctx
,
static
int
init_encoder
(
const
AVCodec
*
enc
,
AVCodecContext
**
enc_ctx
,
int64_t
ch_layout
,
int
sample_rate
)
const
AVChannelLayout
*
ch_layout
,
int
sample_rate
)
{
{
AVCodecContext
*
ctx
;
AVCodecContext
*
ctx
;
int
result
;
int
result
;
char
name_buff
[
NAME_BUFF_SIZE
];
char
name_buff
[
NAME_BUFF_SIZE
];
av_
get_channel_layout_string
(
name_buff
,
NAME_BUFF_SIZE
,
0
,
ch_layout
);
av_
channel_layout_describe
(
ch_layout
,
name_buff
,
NAME_BUFF_SIZE
);
av_log
(
NULL
,
AV_LOG_INFO
,
"channel layout: %s, sample rate: %i
\n
"
,
name_buff
,
sample_rate
);
av_log
(
NULL
,
AV_LOG_INFO
,
"channel layout: %s, sample rate: %i
\n
"
,
name_buff
,
sample_rate
);
ctx
=
avcodec_alloc_context3
(
enc
);
ctx
=
avcodec_alloc_context3
(
enc
);
...
@@ -67,7 +67,7 @@ static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
...
@@ -67,7 +67,7 @@ static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
ctx
->
sample_fmt
=
AV_SAMPLE_FMT_S16
;
ctx
->
sample_fmt
=
AV_SAMPLE_FMT_S16
;
ctx
->
sample_rate
=
sample_rate
;
ctx
->
sample_rate
=
sample_rate
;
ctx
->
channel_layout
=
ch_layout
;
av_channel_layout_copy
(
&
ctx
->
ch_layout
,
ch_layout
)
;
result
=
avcodec_open2
(
ctx
,
enc
,
NULL
);
result
=
avcodec_open2
(
ctx
,
enc
,
NULL
);
if
(
result
<
0
)
{
if
(
result
<
0
)
{
...
@@ -80,7 +80,7 @@ static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
...
@@ -80,7 +80,7 @@ static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
}
}
static
int
init_decoder
(
const
AVCodec
*
dec
,
AVCodecContext
**
dec_ctx
,
static
int
init_decoder
(
const
AVCodec
*
dec
,
AVCodecContext
**
dec_ctx
,
int64_t
ch_layout
)
const
AVChannelLayout
*
ch_layout
)
{
{
AVCodecContext
*
ctx
;
AVCodecContext
*
ctx
;
int
result
;
int
result
;
...
@@ -92,9 +92,7 @@ static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx,
...
@@ -92,9 +92,7 @@ static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx,
}
}
ctx
->
request_sample_fmt
=
AV_SAMPLE_FMT_S16
;
ctx
->
request_sample_fmt
=
AV_SAMPLE_FMT_S16
;
/* XXX: FLAC ignores it for some reason */
av_channel_layout_copy
(
&
ctx
->
ch_layout
,
ch_layout
);
ctx
->
request_channel_layout
=
ch_layout
;
ctx
->
channel_layout
=
ch_layout
;
result
=
avcodec_open2
(
ctx
,
dec
,
NULL
);
result
=
avcodec_open2
(
ctx
,
dec
,
NULL
);
if
(
result
<
0
)
{
if
(
result
<
0
)
{
...
@@ -131,7 +129,9 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
...
@@ -131,7 +129,9 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
in_frame
->
nb_samples
=
enc_ctx
->
frame_size
;
in_frame
->
nb_samples
=
enc_ctx
->
frame_size
;
in_frame
->
format
=
enc_ctx
->
sample_fmt
;
in_frame
->
format
=
enc_ctx
->
sample_fmt
;
in_frame
->
channel_layout
=
enc_ctx
->
channel_layout
;
result
=
av_channel_layout_copy
(
&
in_frame
->
ch_layout
,
&
enc_ctx
->
ch_layout
);
if
(
result
<
0
)
return
result
;
if
(
av_frame_get_buffer
(
in_frame
,
0
)
!=
0
)
{
if
(
av_frame_get_buffer
(
in_frame
,
0
)
!=
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Can't allocate a buffer for input frame
\n
"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"Can't allocate a buffer for input frame
\n
"
);
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
...
@@ -161,8 +161,8 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
...
@@ -161,8 +161,8 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
return
result
;
return
result
;
generate_raw_frame
((
uint16_t
*
)(
in_frame
->
data
[
0
]),
i
,
enc_ctx
->
sample_rate
,
generate_raw_frame
((
uint16_t
*
)(
in_frame
->
data
[
0
]),
i
,
enc_ctx
->
sample_rate
,
enc_ctx
->
channels
,
enc_ctx
->
frame_size
);
enc_ctx
->
ch
_layout
.
nb_ch
annels
,
enc_ctx
->
frame_size
);
in_frame_bytes
=
in_frame
->
nb_samples
*
in_frame
->
channels
*
sizeof
(
uint16_t
);
in_frame_bytes
=
in_frame
->
nb_samples
*
in_frame
->
ch
_layout
.
nb_ch
annels
*
sizeof
(
uint16_t
);
if
(
in_frame_bytes
>
in_frame
->
linesize
[
0
])
{
if
(
in_frame_bytes
>
in_frame
->
linesize
[
0
])
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Incorrect value of input frame linesize
\n
"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"Incorrect value of input frame linesize
\n
"
);
return
1
;
return
1
;
...
@@ -209,7 +209,7 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
...
@@ -209,7 +209,7 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
return
AVERROR_UNKNOWN
;
return
AVERROR_UNKNOWN
;
}
}
if
(
in_frame
->
channel_layout
!=
out_frame
->
channel_layout
)
{
if
(
av_channel_layout_compare
(
&
in_frame
->
ch_layout
,
&
out_frame
->
ch_layout
)
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error frames before and after decoding has different channel layout
\n
"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error frames before and after decoding has different channel layout
\n
"
);
return
AVERROR_UNKNOWN
;
return
AVERROR_UNKNOWN
;
}
}
...
@@ -218,7 +218,7 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
...
@@ -218,7 +218,7 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error frames before and after decoding has different sample format
\n
"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error frames before and after decoding has different sample format
\n
"
);
return
AVERROR_UNKNOWN
;
return
AVERROR_UNKNOWN
;
}
}
out_frame_bytes
=
out_frame
->
nb_samples
*
out_frame
->
channels
*
sizeof
(
uint16_t
);
out_frame_bytes
=
out_frame
->
nb_samples
*
out_frame
->
ch
_layout
.
nb_ch
annels
*
sizeof
(
uint16_t
);
if
(
out_frame_bytes
>
out_frame
->
linesize
[
0
])
{
if
(
out_frame_bytes
>
out_frame
->
linesize
[
0
])
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Incorrect value of output frame linesize
\n
"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"Incorrect value of output frame linesize
\n
"
);
return
1
;
return
1
;
...
@@ -247,7 +247,10 @@ int main(void)
...
@@ -247,7 +247,10 @@ int main(void)
{
{
const
AVCodec
*
enc
=
NULL
,
*
dec
=
NULL
;
const
AVCodec
*
enc
=
NULL
,
*
dec
=
NULL
;
AVCodecContext
*
enc_ctx
=
NULL
,
*
dec_ctx
=
NULL
;
AVCodecContext
*
enc_ctx
=
NULL
,
*
dec_ctx
=
NULL
;
uint64_t
channel_layouts
[]
=
{
AV_CH_LAYOUT_STEREO
,
AV_CH_LAYOUT_5POINT1_BACK
,
AV_CH_LAYOUT_SURROUND
,
AV_CH_LAYOUT_STEREO_DOWNMIX
};
const
AVChannelLayout
channel_layouts
[]
=
{
AV_CHANNEL_LAYOUT_STEREO
,
AV_CHANNEL_LAYOUT_5POINT1_BACK
,
AV_CHANNEL_LAYOUT_SURROUND
,
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
};
int
sample_rates
[]
=
{
8000
,
44100
,
48000
,
192000
};
int
sample_rates
[]
=
{
8000
,
44100
,
48000
,
192000
};
int
cl
,
sr
;
int
cl
,
sr
;
...
@@ -265,9 +268,9 @@ int main(void)
...
@@ -265,9 +268,9 @@ int main(void)
for
(
cl
=
0
;
cl
<
FF_ARRAY_ELEMS
(
channel_layouts
);
cl
++
)
{
for
(
cl
=
0
;
cl
<
FF_ARRAY_ELEMS
(
channel_layouts
);
cl
++
)
{
for
(
sr
=
0
;
sr
<
FF_ARRAY_ELEMS
(
sample_rates
);
sr
++
)
{
for
(
sr
=
0
;
sr
<
FF_ARRAY_ELEMS
(
sample_rates
);
sr
++
)
{
if
(
init_encoder
(
enc
,
&
enc_ctx
,
channel_layouts
[
cl
],
sample_rates
[
sr
])
!=
0
)
if
(
init_encoder
(
enc
,
&
enc_ctx
,
&
channel_layouts
[
cl
],
sample_rates
[
sr
])
!=
0
)
return
1
;
return
1
;
if
(
init_decoder
(
dec
,
&
dec_ctx
,
channel_layouts
[
cl
])
!=
0
)
if
(
init_decoder
(
dec
,
&
dec_ctx
,
&
channel_layouts
[
cl
])
!=
0
)
return
1
;
return
1
;
if
(
run_test
(
enc
,
dec
,
enc_ctx
,
dec_ctx
)
!=
0
)
if
(
run_test
(
enc
,
dec
,
enc_ctx
,
dec_ctx
)
!=
0
)
return
1
;
return
1
;
...
...
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