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
f7c5fd81
Commit
f7c5fd81
authored
Mar 04, 2014
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resample: implement flushing
parent
801c39e1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
8 deletions
+40
-8
resample.c
libavresample/resample.c
+39
-7
libavresample.mak
tests/fate/libavresample.mak
+1
-1
No files found.
libavresample/resample.c
View file @
f7c5fd81
...
@@ -52,6 +52,8 @@ struct ResampleContext {
...
@@ -52,6 +52,8 @@ struct ResampleContext {
int
padding_size
;
int
padding_size
;
int
initial_padding_filled
;
int
initial_padding_filled
;
int
initial_padding_samples
;
int
initial_padding_samples
;
int
final_padding_filled
;
int
final_padding_samples
;
};
};
...
@@ -433,27 +435,57 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
...
@@ -433,27 +435,57 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
ret
=
ff_audio_data_combine
(
c
->
buffer
,
in_leftover
,
src
,
0
,
in_samples
);
ret
=
ff_audio_data_combine
(
c
->
buffer
,
in_leftover
,
src
,
0
,
in_samples
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
}
else
if
(
!
in_leftover
)
{
}
else
if
(
in_leftover
<=
c
->
final_padding_samples
)
{
/* no remaining samples to flush */
/* no remaining samples to flush */
return
0
;
return
0
;
}
else
{
/* TODO: pad buffer to flush completely */
}
}
if
(
!
c
->
initial_padding_filled
)
{
if
(
!
c
->
initial_padding_filled
)
{
int
bps
=
av_get_bytes_per_sample
(
c
->
avr
->
internal_sample_fmt
);
int
bps
=
av_get_bytes_per_sample
(
c
->
avr
->
internal_sample_fmt
);
int
i
;
int
i
;
if
(
c
->
buffer
->
nb_samples
<
2
*
c
->
padding_size
)
if
(
src
&&
c
->
buffer
->
nb_samples
<
2
*
c
->
padding_size
)
return
0
;
return
0
;
for
(
i
=
0
;
i
<
c
->
padding_size
;
i
++
)
for
(
i
=
0
;
i
<
c
->
padding_size
;
i
++
)
for
(
ch
=
0
;
ch
<
c
->
buffer
->
channels
;
ch
++
)
for
(
ch
=
0
;
ch
<
c
->
buffer
->
channels
;
ch
++
)
{
if
(
c
->
buffer
->
nb_samples
>
2
*
c
->
padding_size
-
i
)
{
memcpy
(
c
->
buffer
->
data
[
ch
]
+
bps
*
i
,
memcpy
(
c
->
buffer
->
data
[
ch
]
+
bps
*
i
,
c
->
buffer
->
data
[
ch
]
+
bps
*
(
2
*
c
->
padding_size
-
i
),
bps
);
c
->
buffer
->
data
[
ch
]
+
bps
*
(
2
*
c
->
padding_size
-
i
),
bps
);
}
else
{
memset
(
c
->
buffer
->
data
[
ch
]
+
bps
*
i
,
0
,
bps
);
}
}
c
->
initial_padding_filled
=
1
;
c
->
initial_padding_filled
=
1
;
}
}
if
(
!
src
&&
!
c
->
final_padding_filled
)
{
int
bps
=
av_get_bytes_per_sample
(
c
->
avr
->
internal_sample_fmt
);
int
i
;
ret
=
ff_audio_data_realloc
(
c
->
buffer
,
in_samples
+
c
->
padding_size
);
if
(
ret
<
0
)
{
av_log
(
c
->
avr
,
AV_LOG_ERROR
,
"Error reallocating resampling buffer
\n
"
);
return
AVERROR
(
ENOMEM
);
}
for
(
i
=
0
;
i
<
c
->
padding_size
;
i
++
)
for
(
ch
=
0
;
ch
<
c
->
buffer
->
channels
;
ch
++
)
{
if
(
in_leftover
>
i
)
{
memcpy
(
c
->
buffer
->
data
[
ch
]
+
bps
*
(
in_leftover
+
i
),
c
->
buffer
->
data
[
ch
]
+
bps
*
(
in_leftover
-
i
-
1
),
bps
);
}
else
{
memset
(
c
->
buffer
->
data
[
ch
]
+
bps
*
(
in_leftover
+
i
),
0
,
bps
);
}
}
c
->
buffer
->
nb_samples
+=
c
->
padding_size
;
c
->
final_padding_samples
=
c
->
padding_size
;
c
->
final_padding_filled
=
1
;
}
/* calculate output size and reallocate output buffer if needed */
/* calculate output size and reallocate output buffer if needed */
/* TODO: try to calculate this without the dummy resample() run */
/* TODO: try to calculate this without the dummy resample() run */
if
(
!
dst
->
read_only
&&
dst
->
allow_realloc
)
{
if
(
!
dst
->
read_only
&&
dst
->
allow_realloc
)
{
...
...
tests/fate/libavresample.mak
View file @
f7c5fd81
...
@@ -38,7 +38,7 @@ fate-lavr-resample-$(3)-$(1)-$(2): CMD = avconv -i $(TARGET_PATH)/tests/data/asy
...
@@ -38,7 +38,7 @@ fate-lavr-resample-$(3)-$(1)-$(2): CMD = avconv -i $(TARGET_PATH)/tests/data/asy
fate-lavr-resample-$(3)-$(1)-$(2): CMP = oneoff
fate-lavr-resample-$(3)-$(1)-$(2): CMP = oneoff
fate-lavr-resample-$(3)-$(1)-$(2): CMP_UNIT = $(5)
fate-lavr-resample-$(3)-$(1)-$(2): CMP_UNIT = $(5)
fate-lavr-resample-$(3)-$(1)-$(2): FUZZ = 6
fate-lavr-resample-$(3)-$(1)-$(2): FUZZ = 6
fate-lavr-resample-$(3)-$(1)-$(2): REF = $(SAMPLES)/lavr/lavr-resample-$(3)-$(1)-$(2)
fate-lavr-resample-$(3)-$(1)-$(2): REF = $(SAMPLES)/lavr/lavr-resample-$(3)-$(1)-$(2)
-v2
endef
endef
$(call CROSS_TEST,$(SAMPLERATES),RESAMPLE,s16p,s16le,s16)
$(call CROSS_TEST,$(SAMPLERATES),RESAMPLE,s16p,s16le,s16)
...
...
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