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
9be4c084
authored
Mar 27, 2020
by
olly
Committed by
Oliver Woodman
Mar 27, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
FFmpeg extension cleanup
PiperOrigin-RevId: 303298804
parent
af05ceac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
31 deletions
extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java
extensions/ffmpeg/src/main/jni/ffmpeg_jni.cc
extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java
View file @
9be4c084
...
...
@@ -36,9 +36,10 @@ import java.util.List;
private
static
final
int
OUTPUT_BUFFER_SIZE_16BIT
=
65536
;
private
static
final
int
OUTPUT_BUFFER_SIZE_32BIT
=
OUTPUT_BUFFER_SIZE_16BIT
*
2
;
// Error codes matching ffmpeg_jni.cc.
private
static
final
int
DECODER_ERROR_INVALID_DATA
=
-
1
;
private
static
final
int
DECODER_ERROR_OTHER
=
-
2
;
// LINT.IfChange
private
static
final
int
AUDIO_DECODER_ERROR_INVALID_DATA
=
-
1
;
private
static
final
int
AUDIO_DECODER_ERROR_OTHER
=
-
2
;
// LINT.ThenChange(../../../../../../../jni/ffmpeg_jni.cc)
private
final
String
codecName
;
@Nullable
private
final
byte
[]
extraData
;
...
...
@@ -107,13 +108,13 @@ import java.util.List;
int
inputSize
=
inputData
.
limit
();
ByteBuffer
outputData
=
outputBuffer
.
init
(
inputBuffer
.
timeUs
,
outputBufferSize
);
int
result
=
ffmpegDecode
(
nativeContext
,
inputData
,
inputSize
,
outputData
,
outputBufferSize
);
if
(
result
==
DECODER_ERROR_INVALID_DATA
)
{
if
(
result
==
AUDIO_
DECODER_ERROR_INVALID_DATA
)
{
// Treat invalid data errors as non-fatal to match the behavior of MediaCodec. No output will
// be produced for this buffer, so mark it as decode-only to ensure that the audio sink's
// position is reset when more audio is produced.
outputBuffer
.
setFlags
(
C
.
BUFFER_FLAG_DECODE_ONLY
);
return
null
;
}
else
if
(
result
==
DECODER_ERROR_OTHER
)
{
}
else
if
(
result
==
AUDIO_
DECODER_ERROR_OTHER
)
{
return
new
FfmpegDecoderException
(
"Error decoding (see logcat)."
);
}
if
(!
hasOutputFormat
)
{
...
...
@@ -121,8 +122,8 @@ import java.util.List;
sampleRate
=
ffmpegGetSampleRate
(
nativeContext
);
if
(
sampleRate
==
0
&&
"alac"
.
equals
(
codecName
))
{
Assertions
.
checkNotNull
(
extraData
);
// ALAC decoder did not set the sample rate in earlier versions of FF
MPEG.
//
See https://trac.ffmpeg.org/ticket/6096
// ALAC decoder did not set the sample rate in earlier versions of FF
mpeg. See
//
https://trac.ffmpeg.org/ticket/6096.
ParsableByteArray
parsableExtraData
=
new
ParsableByteArray
(
extraData
);
parsableExtraData
.
setPosition
(
extraData
.
length
-
4
);
sampleRate
=
parsableExtraData
.
readUnsignedIntToInt
();
...
...
@@ -151,9 +152,7 @@ import java.util.List;
return
sampleRate
;
}
/**
* Returns the encoding of output audio.
*/
/** Returns the encoding of output audio. */
public
@C
.
Encoding
int
getEncoding
()
{
return
encoding
;
}
...
...
@@ -215,13 +214,14 @@ import java.util.List;
int
rawSampleRate
,
int
rawChannelCount
);
private
native
int
ffmpegDecode
(
long
context
,
ByteBuffer
inputData
,
int
inputSize
,
ByteBuffer
outputData
,
int
outputSize
);
private
native
int
ffmpegDecode
(
long
context
,
ByteBuffer
inputData
,
int
inputSize
,
ByteBuffer
outputData
,
int
outputSize
);
private
native
int
ffmpegGetChannelCount
(
long
context
);
private
native
int
ffmpegGetSampleRate
(
long
context
);
private
native
long
ffmpegReset
(
long
context
,
@Nullable
byte
[]
extraData
);
private
native
void
ffmpegRelease
(
long
context
);
}
extensions/ffmpeg/src/main/jni/ffmpeg_jni.cc
View file @
9be4c084
...
...
@@ -36,16 +36,6 @@ extern "C" {
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, \
__VA_ARGS__))
#define AUDIO_DECODER_FUNC(RETURN_TYPE, NAME, ...) \
extern "C" { \
JNIEXPORT RETURN_TYPE \
Java_com_google_android_exoplayer2_ext_ffmpeg_FfmpegAudioDecoder_##NAME( \
JNIEnv *env, jobject thiz, ##__VA_ARGS__); \
} \
JNIEXPORT RETURN_TYPE \
Java_com_google_android_exoplayer2_ext_ffmpeg_FfmpegAudioDecoder_##NAME( \
JNIEnv *env, jobject thiz, ##__VA_ARGS__)
#define LIBRARY_FUNC(RETURN_TYPE, NAME, ...) \
extern "C" { \
JNIEXPORT RETURN_TYPE \
...
...
@@ -56,6 +46,16 @@ extern "C" {
Java_com_google_android_exoplayer2_ext_ffmpeg_FfmpegLibrary_##NAME( \
JNIEnv *env, jobject thiz, ##__VA_ARGS__)
#define AUDIO_DECODER_FUNC(RETURN_TYPE, NAME, ...) \
extern "C" { \
JNIEXPORT RETURN_TYPE \
Java_com_google_android_exoplayer2_ext_ffmpeg_FfmpegAudioDecoder_##NAME( \
JNIEnv *env, jobject thiz, ##__VA_ARGS__); \
} \
JNIEXPORT RETURN_TYPE \
Java_com_google_android_exoplayer2_ext_ffmpeg_FfmpegAudioDecoder_##NAME( \
JNIEnv *env, jobject thiz, ##__VA_ARGS__)
#define ERROR_STRING_BUFFER_LENGTH 256
// Output format corresponding to AudioFormat.ENCODING_PCM_16BIT.
...
...
@@ -63,9 +63,10 @@ static const AVSampleFormat OUTPUT_FORMAT_PCM_16BIT = AV_SAMPLE_FMT_S16;
// Output format corresponding to AudioFormat.ENCODING_PCM_FLOAT.
static
const
AVSampleFormat
OUTPUT_FORMAT_PCM_FLOAT
=
AV_SAMPLE_FMT_FLT
;
// Error codes matching FfmpegAudioDecoder.java.
static
const
int
DECODER_ERROR_INVALID_DATA
=
-
1
;
static
const
int
DECODER_ERROR_OTHER
=
-
2
;
// LINT.IfChange
static
const
int
AUDIO_DECODER_ERROR_INVALID_DATA
=
-
1
;
static
const
int
AUDIO_DECODER_ERROR_OTHER
=
-
2
;
// LINT.ThenChange(../java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java)
/**
* Returns the AVCodec with the specified name, or NULL if it is not available.
...
...
@@ -83,7 +84,8 @@ AVCodecContext *createContext(JNIEnv *env, AVCodec *codec, jbyteArray extraData,
/**
* Decodes the packet into the output buffer, returning the number of bytes
* written, or a negative DECODER_ERROR constant value in the case of an error.
* written, or a negative AUDIO_DECODER_ERROR constant value in the case of an
* error.
*/
int
decodePacket
(
AVCodecContext
*
context
,
AVPacket
*
packet
,
uint8_t
*
outputBuffer
,
int
outputSize
);
...
...
@@ -127,8 +129,8 @@ AUDIO_DECODER_FUNC(jlong, ffmpegInitialize, jstring codecName,
rawChannelCount
);
}
DECODER_FUNC
(
jint
,
ffmpegDecode
,
jlong
context
,
jobject
inputData
,
jint
inputSize
,
jobject
outputData
,
jint
outputSize
)
{
AUDIO_
DECODER_FUNC
(
jint
,
ffmpegDecode
,
jlong
context
,
jobject
inputData
,
jint
inputSize
,
jobject
outputData
,
jint
outputSize
)
{
if
(
!
context
)
{
LOGE
(
"Context must be non-NULL."
);
return
-
1
;
...
...
@@ -260,8 +262,8 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
result
=
avcodec_send_packet
(
context
,
packet
);
if
(
result
)
{
logError
(
"avcodec_send_packet"
,
result
);
return
result
==
AVERROR_INVALIDDATA
?
DECODER_ERROR_INVALID_DATA
:
DECODER_ERROR_OTHER
;
return
result
==
AVERROR_INVALIDDATA
?
AUDIO_
DECODER_ERROR_INVALID_DATA
:
AUDIO_
DECODER_ERROR_OTHER
;
}
// Dequeue output data until it runs out.
...
...
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