Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6d14c168
authored
Feb 19, 2020
by
xufulong
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
use swresample instead of avresample, since avresample module has been deprecated.
parent
ab21f885
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
extensions/ffmpeg/src/main/jni/ffmpeg_jni.cc
extensions/ffmpeg/src/main/jni/ffmpeg_jni.cc
View file @
6d14c168
...
@@ -26,7 +26,7 @@ extern "C" {
...
@@ -26,7 +26,7 @@ extern "C" {
#include <stdint.h>
#include <stdint.h>
#endif
#endif
#include <libavcodec/avcodec.h>
#include <libavcodec/avcodec.h>
#include <lib
avresample/av
resample.h>
#include <lib
swresample/sw
resample.h>
#include <libavutil/channel_layout.h>
#include <libavutil/channel_layout.h>
#include <libavutil/error.h>
#include <libavutil/error.h>
#include <libavutil/opt.h>
#include <libavutil/opt.h>
...
@@ -289,11 +289,11 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
...
@@ -289,11 +289,11 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
int
sampleCount
=
frame
->
nb_samples
;
int
sampleCount
=
frame
->
nb_samples
;
int
dataSize
=
av_samples_get_buffer_size
(
NULL
,
channelCount
,
sampleCount
,
int
dataSize
=
av_samples_get_buffer_size
(
NULL
,
channelCount
,
sampleCount
,
sampleFormat
,
1
);
sampleFormat
,
1
);
AVAudioResample
Context
*
resampleContext
;
Swr
Context
*
resampleContext
;
if
(
context
->
opaque
)
{
if
(
context
->
opaque
)
{
resampleContext
=
(
AVAudioResample
Context
*
)
context
->
opaque
;
resampleContext
=
(
Swr
Context
*
)
context
->
opaque
;
}
else
{
}
else
{
resampleContext
=
avresample_alloc_context
();
resampleContext
=
swr_alloc
();
av_opt_set_int
(
resampleContext
,
"in_channel_layout"
,
channelLayout
,
0
);
av_opt_set_int
(
resampleContext
,
"in_channel_layout"
,
channelLayout
,
0
);
av_opt_set_int
(
resampleContext
,
"out_channel_layout"
,
channelLayout
,
0
);
av_opt_set_int
(
resampleContext
,
"out_channel_layout"
,
channelLayout
,
0
);
av_opt_set_int
(
resampleContext
,
"in_sample_rate"
,
sampleRate
,
0
);
av_opt_set_int
(
resampleContext
,
"in_sample_rate"
,
sampleRate
,
0
);
...
@@ -302,7 +302,7 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
...
@@ -302,7 +302,7 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
// The output format is always the requested format.
// The output format is always the requested format.
av_opt_set_int
(
resampleContext
,
"out_sample_fmt"
,
av_opt_set_int
(
resampleContext
,
"out_sample_fmt"
,
context
->
request_sample_fmt
,
0
);
context
->
request_sample_fmt
,
0
);
result
=
avresample_open
(
resampleContext
);
result
=
swr_init
(
resampleContext
);
if
(
result
<
0
)
{
if
(
result
<
0
)
{
logError
(
"avresample_open"
,
result
);
logError
(
"avresample_open"
,
result
);
av_frame_free
(
&
frame
);
av_frame_free
(
&
frame
);
...
@@ -312,7 +312,7 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
...
@@ -312,7 +312,7 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
}
}
int
inSampleSize
=
av_get_bytes_per_sample
(
sampleFormat
);
int
inSampleSize
=
av_get_bytes_per_sample
(
sampleFormat
);
int
outSampleSize
=
av_get_bytes_per_sample
(
context
->
request_sample_fmt
);
int
outSampleSize
=
av_get_bytes_per_sample
(
context
->
request_sample_fmt
);
int
outSamples
=
avresample
_get_out_samples
(
resampleContext
,
sampleCount
);
int
outSamples
=
swr
_get_out_samples
(
resampleContext
,
sampleCount
);
int
bufferOutSize
=
outSampleSize
*
channelCount
*
outSamples
;
int
bufferOutSize
=
outSampleSize
*
channelCount
*
outSamples
;
if
(
outSize
+
bufferOutSize
>
outputSize
)
{
if
(
outSize
+
bufferOutSize
>
outputSize
)
{
LOGE
(
"Output buffer size (%d) too small for output data (%d)."
,
LOGE
(
"Output buffer size (%d) too small for output data (%d)."
,
...
@@ -320,15 +320,15 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
...
@@ -320,15 +320,15 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
av_frame_free
(
&
frame
);
av_frame_free
(
&
frame
);
return
-
1
;
return
-
1
;
}
}
result
=
avresample_convert
(
resampleContext
,
&
outputBuffer
,
bufferOutSize
,
result
=
swr_convert
(
resampleContext
,
outSamples
,
frame
->
data
,
frame
->
linesize
[
0
]
,
&
outputBuffer
,
bufferOutSize
,
sampleCount
);
(
const
uint8_t
**
)
frame
->
data
,
frame
->
nb_samples
);
av_frame_free
(
&
frame
);
av_frame_free
(
&
frame
);
if
(
result
<
0
)
{
if
(
result
<
0
)
{
logError
(
"avresample_convert"
,
result
);
logError
(
"avresample_convert"
,
result
);
return
result
;
return
result
;
}
}
int
available
=
avresample_available
(
resampleContext
);
int
available
=
swr_get_out_samples
(
resampleContext
,
0
);
if
(
available
!=
0
)
{
if
(
available
!=
0
)
{
LOGE
(
"Expected no samples remaining after resampling, but found %d."
,
LOGE
(
"Expected no samples remaining after resampling, but found %d."
,
available
);
available
);
...
@@ -351,9 +351,9 @@ void releaseContext(AVCodecContext *context) {
...
@@ -351,9 +351,9 @@ void releaseContext(AVCodecContext *context) {
if
(
!
context
)
{
if
(
!
context
)
{
return
;
return
;
}
}
AVAudioResampleContext
*
resample
Context
;
SwrContext
*
swr
Context
;
if
((
resampleContext
=
(
AVAudioResample
Context
*
)
context
->
opaque
))
{
if
((
swrContext
=
(
Swr
Context
*
)
context
->
opaque
))
{
avresample_free
(
&
resample
Context
);
swr_free
(
&
swr
Context
);
context
->
opaque
=
NULL
;
context
->
opaque
=
NULL
;
}
}
avcodec_free_context
(
&
context
);
avcodec_free_context
(
&
context
);
...
...
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