summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--media/base/android/audio_decoder_job.cc3
-rw-r--r--media/base/android/audio_decoder_job.h1
-rw-r--r--media/base/android/media_codec_audio_decoder.cc3
-rw-r--r--media/base/android/media_codec_audio_decoder.h1
-rw-r--r--media/base/android/media_codec_bridge.cc38
-rw-r--r--media/base/android/media_codec_bridge.h7
-rw-r--r--media/base/android/media_codec_decoder.cc2
-rw-r--r--media/base/android/media_codec_decoder.h1
-rw-r--r--media/base/android/media_codec_video_decoder.cc1
-rw-r--r--media/base/android/media_codec_video_decoder.h1
-rw-r--r--media/base/android/media_decoder_job.cc5
-rw-r--r--media/base/android/media_decoder_job.h1
-rw-r--r--media/base/android/video_decoder_job.cc1
-rw-r--r--media/base/android/video_decoder_job.h1
14 files changed, 46 insertions, 20 deletions
diff --git a/media/base/android/audio_decoder_job.cc b/media/base/android/audio_decoder_job.cc
index ba26e99..f281a19 100644
--- a/media/base/android/audio_decoder_job.cc
+++ b/media/base/android/audio_decoder_job.cc
@@ -96,6 +96,7 @@ void AudioDecoderJob::ResetTimestampHelper() {
void AudioDecoderJob::ReleaseOutputBuffer(
int output_buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta current_presentation_timestamp,
@@ -104,7 +105,7 @@ void AudioDecoderJob::ReleaseOutputBuffer(
if (render_output) {
int64 head_position = (static_cast<AudioCodecBridge*>(
media_codec_bridge_.get()))->PlayOutputBuffer(
- output_buffer_index, size);
+ output_buffer_index, size, offset);
size_t new_frames_count = size / bytes_per_frame_;
frame_count_ += new_frames_count;
audio_timestamp_helper_->AddFrames(new_frames_count);
diff --git a/media/base/android/audio_decoder_job.h b/media/base/android/audio_decoder_job.h
index 0a7523f..ba37486 100644
--- a/media/base/android/audio_decoder_job.h
+++ b/media/base/android/audio_decoder_job.h
@@ -43,6 +43,7 @@ class AudioDecoderJob : public MediaDecoderJob {
// MediaDecoderJob implementation.
void ReleaseOutputBuffer(
int output_buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta current_presentation_timestamp,
diff --git a/media/base/android/media_codec_audio_decoder.cc b/media/base/android/media_codec_audio_decoder.cc
index 373d062..f2fae72 100644
--- a/media/base/android/media_codec_audio_decoder.cc
+++ b/media/base/android/media_codec_audio_decoder.cc
@@ -158,6 +158,7 @@ void MediaCodecAudioDecoder::OnOutputFormatChanged() {
}
void MediaCodecAudioDecoder::Render(int buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta pts,
@@ -171,7 +172,7 @@ void MediaCodecAudioDecoder::Render(int buffer_index,
if (render_output) {
int64 head_position =
(static_cast<AudioCodecBridge*>(media_codec_bridge_.get()))
- ->PlayOutputBuffer(buffer_index, size);
+ ->PlayOutputBuffer(buffer_index, size, offset);
size_t new_frames_count = size / bytes_per_frame_;
frame_count_ += new_frames_count;
diff --git a/media/base/android/media_codec_audio_decoder.h b/media/base/android/media_codec_audio_decoder.h
index 53bb664..cb14466 100644
--- a/media/base/android/media_codec_audio_decoder.h
+++ b/media/base/android/media_codec_audio_decoder.h
@@ -44,6 +44,7 @@ class MediaCodecAudioDecoder : public MediaCodecDecoder {
ConfigStatus ConfigureInternal() override;
void OnOutputFormatChanged() override;
void Render(int buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta pts,
diff --git a/media/base/android/media_codec_bridge.cc b/media/base/android/media_codec_bridge.cc
index f076b21..a5fa77b 100644
--- a/media/base/android/media_codec_bridge.cc
+++ b/media/base/android/media_codec_bridge.cc
@@ -4,6 +4,7 @@
#include "media/base/android/media_codec_bridge.h"
+#include <algorithm>
#include "base/android/build_info.h"
#include "base/android/jni_android.h"
@@ -492,19 +493,25 @@ bool MediaCodecBridge::CopyFromOutputBuffer(int index,
size_t offset,
void* dst,
int dst_size) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> j_buffer(
- Java_MediaCodecBridge_getOutputBuffer(env, j_media_codec_.obj(), index));
- void* src_data =
- reinterpret_cast<uint8*>(env->GetDirectBufferAddress(j_buffer.obj())) +
- offset;
- int src_capacity = env->GetDirectBufferCapacity(j_buffer.obj()) - offset;
+ void* src_data = nullptr;
+ int src_capacity = GetOutputBufferAddress(index, offset, &src_data);
if (src_capacity < dst_size)
return false;
memcpy(dst, src_data, dst_size);
return true;
}
+int MediaCodecBridge::GetOutputBufferAddress(int index,
+ size_t offset,
+ void** addr) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> j_buffer(
+ Java_MediaCodecBridge_getOutputBuffer(env, j_media_codec_.obj(), index));
+ *addr = reinterpret_cast<uint8*>(
+ env->GetDirectBufferAddress(j_buffer.obj())) + offset;
+ return env->GetDirectBufferCapacity(j_buffer.obj()) - offset;
+}
+
bool MediaCodecBridge::FillInputBuffer(int index,
const uint8* data,
size_t size) {
@@ -697,16 +704,19 @@ bool AudioCodecBridge::ConfigureMediaFormat(jobject j_format,
return true;
}
-int64 AudioCodecBridge::PlayOutputBuffer(int index, size_t size) {
+int64 AudioCodecBridge::PlayOutputBuffer(
+ int index, size_t size, size_t offset) {
DCHECK_LE(0, index);
int numBytes = base::checked_cast<int>(size);
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> buf =
- Java_MediaCodecBridge_getOutputBuffer(env, media_codec(), index);
- uint8* buffer = static_cast<uint8*>(env->GetDirectBufferAddress(buf.obj()));
- ScopedJavaLocalRef<jbyteArray> byte_array =
- base::android::ToJavaByteArray(env, buffer, numBytes);
+ void* buffer = nullptr;
+ int capacity = GetOutputBufferAddress(index, offset, &buffer);
+ numBytes = std::min(capacity, numBytes);
+ CHECK_GE(numBytes, 0);
+
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jbyteArray> byte_array = base::android::ToJavaByteArray(
+ env, static_cast<uint8*>(buffer), numBytes);
return Java_MediaCodecBridge_playOutputBuffer(
env, media_codec(), byte_array.obj());
}
diff --git a/media/base/android/media_codec_bridge.h b/media/base/android/media_codec_bridge.h
index 8de5c4b..045e59c 100644
--- a/media/base/android/media_codec_bridge.h
+++ b/media/base/android/media_codec_bridge.h
@@ -202,6 +202,11 @@ class MEDIA_EXPORT MediaCodecBridge {
// started.
bool StartInternal() WARN_UNUSED_RESULT;
+ // Called to get the buffer address given the output buffer index and offset.
+ // This function returns the size of the output and |addr| is the pointer to
+ // the address to read.
+ int GetOutputBufferAddress(int index, size_t offset, void** addr);
+
jobject media_codec() { return j_media_codec_.obj(); }
MediaCodecDirection direction_;
@@ -236,7 +241,7 @@ class AudioCodecBridge : public MediaCodecBridge {
// Play the output buffer. This call must be called after
// DequeueOutputBuffer() and before ReleaseOutputBuffer. Returns the playback
// head position expressed in frames.
- int64 PlayOutputBuffer(int index, size_t size);
+ int64 PlayOutputBuffer(int index, size_t size, size_t offset);
// Set the volume of the audio output.
void SetVolume(double volume);
diff --git a/media/base/android/media_codec_decoder.cc b/media/base/android/media_codec_decoder.cc
index 796dff1..bf0147f 100644
--- a/media/base/android/media_codec_decoder.cc
+++ b/media/base/android/media_codec_decoder.cc
@@ -633,7 +633,7 @@ bool MediaCodecDecoder::DepleteOutputBufferQueue() {
case MEDIA_CODEC_OK:
// We got the decoded frame
- Render(buffer_index, size, true, pts, eos_encountered);
+ Render(buffer_index, offset, size, true, pts, eos_encountered);
break;
case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER:
diff --git a/media/base/android/media_codec_decoder.h b/media/base/android/media_codec_decoder.h
index 2cc38b6..f3faf20 100644
--- a/media/base/android/media_codec_decoder.h
+++ b/media/base/android/media_codec_decoder.h
@@ -232,6 +232,7 @@ class MediaCodecDecoder {
// Renders the decoded frame and releases output buffer, or posts
// a delayed task to do it at a later time,
virtual void Render(int buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta pts,
diff --git a/media/base/android/media_codec_video_decoder.cc b/media/base/android/media_codec_video_decoder.cc
index e4641d5..d728edd 100644
--- a/media/base/android/media_codec_video_decoder.cc
+++ b/media/base/android/media_codec_video_decoder.cc
@@ -185,6 +185,7 @@ void MediaCodecVideoDecoder::OnOutputFormatChanged() {
}
void MediaCodecVideoDecoder::Render(int buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta pts,
diff --git a/media/base/android/media_codec_video_decoder.h b/media/base/android/media_codec_video_decoder.h
index 8b6de8e..75ab365 100644
--- a/media/base/android/media_codec_video_decoder.h
+++ b/media/base/android/media_codec_video_decoder.h
@@ -56,6 +56,7 @@ class MediaCodecVideoDecoder : public MediaCodecDecoder {
void SynchronizePTSWithTime(base::TimeDelta current_time) override;
void OnOutputFormatChanged() override;
void Render(int buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta pts,
diff --git a/media/base/android/media_decoder_job.cc b/media/base/android/media_decoder_job.cc
index af8ecb4..a1e8606 100644
--- a/media/base/android/media_decoder_job.cc
+++ b/media/base/android/media_decoder_job.cc
@@ -495,6 +495,7 @@ void MediaDecoderJob::DecodeInternal(
base::Bind(&MediaDecoderJob::ReleaseOutputBuffer,
base::Unretained(this),
buffer_index,
+ offset,
size,
render_output,
presentation_timestamp,
@@ -518,8 +519,8 @@ void MediaDecoderJob::DecodeInternal(
}
ReleaseOutputCompletionCallback completion_callback = base::Bind(
callback, status);
- ReleaseOutputBuffer(buffer_index, size, render_output, presentation_timestamp,
- completion_callback);
+ ReleaseOutputBuffer(buffer_index, offset, size, render_output,
+ presentation_timestamp, completion_callback);
}
void MediaDecoderJob::OnDecodeCompleted(
diff --git a/media/base/android/media_decoder_job.h b/media/base/android/media_decoder_job.h
index 329512f..5fee4b0 100644
--- a/media/base/android/media_decoder_job.h
+++ b/media/base/android/media_decoder_job.h
@@ -126,6 +126,7 @@ class MediaDecoderJob {
// |render_output| is true. Upon completion, |callback| will be called.
virtual void ReleaseOutputBuffer(
int output_buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta current_presentation_timestamp,
diff --git a/media/base/android/video_decoder_job.cc b/media/base/android/video_decoder_job.cc
index d49d2d2..2a29d015 100644
--- a/media/base/android/video_decoder_job.cc
+++ b/media/base/android/video_decoder_job.cc
@@ -78,6 +78,7 @@ void VideoDecoderJob::SetDemuxerConfigs(const DemuxerConfigs& configs) {
void VideoDecoderJob::ReleaseOutputBuffer(
int output_buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta current_presentation_timestamp,
diff --git a/media/base/android/video_decoder_job.h b/media/base/android/video_decoder_job.h
index 36f70d8..00a8e6f 100644
--- a/media/base/android/video_decoder_job.h
+++ b/media/base/android/video_decoder_job.h
@@ -43,6 +43,7 @@ class VideoDecoderJob : public MediaDecoderJob {
// MediaDecoderJob implementation.
void ReleaseOutputBuffer(
int output_buffer_index,
+ size_t offset,
size_t size,
bool render_output,
base::TimeDelta current_presentation_timestamp,