summaryrefslogtreecommitdiffstats
path: root/content/renderer/media
diff options
context:
space:
mode:
authorqinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-22 22:45:32 +0000
committerqinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-22 22:45:32 +0000
commit5366f98ef8cd66b92a422e48a90593bdf7de966a (patch)
tree81579877fba479e7f6e02ca92ec1a01266c84524 /content/renderer/media
parenteec89c62a43504930ca79f7d65389a4ccb5a7972 (diff)
downloadchromium_src-5366f98ef8cd66b92a422e48a90593bdf7de966a.zip
chromium_src-5366f98ef8cd66b92a422e48a90593bdf7de966a.tar.gz
chromium_src-5366f98ef8cd66b92a422e48a90593bdf7de966a.tar.bz2
Revert 217531 "Run |demuxer_| related tasks in the media thread."
> Run |demuxer_| related tasks in the media thread. > > - We found that the reading from |demuxer_| and its read-callback loops > run very slowly, in the heavy load situation in the render thread. > to improve the response time of the readings, we run tasks related to > |demuxer_| in the media thread. > > > BUG=268208 > > Review URL: https://chromiumcodereview.appspot.com/22630006 TBR=ycheo@chromium.org Review URL: https://codereview.chromium.org/23361021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219134 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media')
-rw-r--r--content/renderer/media/android/media_source_delegate.cc285
-rw-r--r--content/renderer/media/android/media_source_delegate.h49
-rw-r--r--content/renderer/media/android/webmediaplayer_android.cc4
-rw-r--r--content/renderer/media/android/webmediaplayer_android.h4
4 files changed, 104 insertions, 238 deletions
diff --git a/content/renderer/media/android/media_source_delegate.cc b/content/renderer/media/android/media_source_delegate.cc
index 953882a..9df122d 100644
--- a/content/renderer/media/android/media_source_delegate.cc
+++ b/content/renderer/media/android/media_source_delegate.cc
@@ -37,29 +37,35 @@ const uint8 kVorbisPadding[] = { 0xff, 0xff, 0xff, 0xff };
namespace content {
+// TODO(xhwang): BIND_TO_RENDER_LOOP* force posts callback! Since everything
+// works on the same thread in this class, not all force posts are necessary.
+
+#define BIND_TO_RENDER_LOOP(function) \
+ media::BindToLoop(base::MessageLoopProxy::current(), \
+ base::Bind(function, weak_this_.GetWeakPtr()))
+
+#define BIND_TO_RENDER_LOOP_1(function, arg1) \
+ media::BindToLoop(base::MessageLoopProxy::current(), \
+ base::Bind(function, weak_this_.GetWeakPtr(), arg1))
+
+#define BIND_TO_RENDER_LOOP_2(function, arg1, arg2) \
+ media::BindToLoop(base::MessageLoopProxy::current(), \
+ base::Bind(function, weak_this_.GetWeakPtr(), arg1, arg2))
+
+#define BIND_TO_RENDER_LOOP_3(function, arg1, arg2, arg3) \
+ media::BindToLoop(base::MessageLoopProxy::current(), \
+ base::Bind(function, \
+ weak_this_.GetWeakPtr(), arg1, arg2, arg3))
+
static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log,
const std::string& error) {
media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error));
}
-MediaSourceDelegate::MediaSourceDelegate(
- WebMediaPlayerProxyAndroid* proxy,
- int player_id,
- const scoped_refptr<base::MessageLoopProxy>& media_loop,
- media::MediaLog* media_log)
- : main_weak_this_(this),
- media_weak_this_(this),
- main_loop_(base::MessageLoopProxy::current()),
- media_loop_(media_loop),
- send_read_from_demuxer_ack_cb_(media::BindToLoop(main_loop_,
- base::Bind(&MediaSourceDelegate::SendReadFromDemuxerAck,
- main_weak_this_.GetWeakPtr()))),
- send_seek_request_ack_cb_(media::BindToLoop(main_loop_,
- base::Bind(&MediaSourceDelegate::SendSeekRequestAck,
- main_weak_this_.GetWeakPtr()))),
- send_demuxer_ready_cb_(media::BindToLoop(main_loop_,
- base::Bind(&MediaSourceDelegate::SendDemuxerReady,
- main_weak_this_.GetWeakPtr()))),
+MediaSourceDelegate::MediaSourceDelegate(WebMediaPlayerProxyAndroid* proxy,
+ int player_id,
+ media::MediaLog* media_log)
+ : weak_this_(this),
proxy_(proxy),
player_id_(player_id),
media_log_(media_log),
@@ -74,7 +80,6 @@ MediaSourceDelegate::MediaSourceDelegate(
}
MediaSourceDelegate::~MediaSourceDelegate() {
- DCHECK(main_loop_->BelongsToCurrentThread());
DVLOG(1) << "~MediaSourceDelegate() : " << player_id_;
DCHECK(!chunk_demuxer_);
DCHECK(!demuxer_);
@@ -85,7 +90,6 @@ MediaSourceDelegate::~MediaSourceDelegate() {
}
void MediaSourceDelegate::Destroy() {
- DCHECK(main_loop_->BelongsToCurrentThread());
DVLOG(1) << "Destroy() : " << player_id_;
if (!demuxer_) {
delete this;
@@ -97,23 +101,7 @@ void MediaSourceDelegate::Destroy() {
media_source_opened_cb_.Reset();
proxy_ = NULL;
- main_weak_this_.InvalidateWeakPtrs();
- DCHECK(!main_weak_this_.HasWeakPtrs());
-
- if (chunk_demuxer_)
- chunk_demuxer_->Shutdown();
- // |this| will be transfered to the callback StopDemuxer() and
- // OnDemuxerStopDone(). they own |this| and OnDemuxerStopDone() will delete
- // it when called. Hence using base::Unretained(this) is safe here.
- media_loop_->PostTask(FROM_HERE,
- base::Bind(&MediaSourceDelegate::StopDemuxer,
- base::Unretained(this)));
-}
-
-void MediaSourceDelegate::StopDemuxer() {
- DCHECK(media_loop_->BelongsToCurrentThread());
- DCHECK(demuxer_);
-
+ demuxer_ = NULL;
audio_stream_ = NULL;
video_stream_ = NULL;
// TODO(xhwang): Figure out if we need to Reset the DDSs after Seeking or
@@ -121,14 +109,15 @@ void MediaSourceDelegate::StopDemuxer() {
audio_decrypting_demuxer_stream_.reset();
video_decrypting_demuxer_stream_.reset();
- media_weak_this_.InvalidateWeakPtrs();
- DCHECK(!media_weak_this_.HasWeakPtrs());
+ weak_this_.InvalidateWeakPtrs();
+ DCHECK(!weak_this_.HasWeakPtrs());
- // The callback OnDemuxerStopDone() owns |this| and will delete it when
- // called. Hence using base::Unretained(this) is safe here.
- demuxer_->Stop(media::BindToLoop(main_loop_,
- base::Bind(&MediaSourceDelegate::OnDemuxerStopDone,
- base::Unretained(this))));
+ if (chunk_demuxer_) {
+ // The callback OnDemuxerStopDone() owns |this| and will delete it when
+ // called. Hence using base::Unretained(this) is safe here.
+ chunk_demuxer_->Stop(base::Bind(&MediaSourceDelegate::OnDemuxerStopDone,
+ base::Unretained(this)));
+ }
}
void MediaSourceDelegate::InitializeMediaSource(
@@ -137,57 +126,39 @@ void MediaSourceDelegate::InitializeMediaSource(
const media::SetDecryptorReadyCB& set_decryptor_ready_cb,
const UpdateNetworkStateCB& update_network_state_cb,
const DurationChangeCB& duration_change_cb) {
- DCHECK(main_loop_->BelongsToCurrentThread());
DCHECK(!media_source_opened_cb.is_null());
media_source_opened_cb_ = media_source_opened_cb;
need_key_cb_ = need_key_cb;
set_decryptor_ready_cb_ = set_decryptor_ready_cb;
- update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb);
- duration_change_cb_ = media::BindToCurrentLoop(duration_change_cb);
+ update_network_state_cb_ = update_network_state_cb;
+ duration_change_cb_ = duration_change_cb;
access_unit_size_ = kAccessUnitSizeForMediaSource;
chunk_demuxer_.reset(new media::ChunkDemuxer(
- media::BindToLoop(main_loop_,
- base::Bind(&MediaSourceDelegate::OnDemuxerOpened,
- main_weak_this_.GetWeakPtr())),
- media::BindToLoop(main_loop_,
- base::Bind(&MediaSourceDelegate::OnNeedKey,
- main_weak_this_.GetWeakPtr(), "")),
+ BIND_TO_RENDER_LOOP(&MediaSourceDelegate::OnDemuxerOpened),
+ BIND_TO_RENDER_LOOP_1(&MediaSourceDelegate::OnNeedKey, ""),
// WeakPtrs can only bind to methods without return values.
base::Bind(&MediaSourceDelegate::OnAddTextTrack, base::Unretained(this)),
base::Bind(&LogMediaSourceError, media_log_)));
demuxer_ = chunk_demuxer_.get();
- // |this| will be retained until StopDemuxer() is posted, so Unretained() is
- // safe here.
- media_loop_->PostTask(FROM_HERE,
- base::Bind(&MediaSourceDelegate::InitializeDemuxer,
- base::Unretained(this)));
-}
-
-void MediaSourceDelegate::InitializeDemuxer() {
- DCHECK(media_loop_->BelongsToCurrentThread());
- demuxer_->Initialize(this, base::Bind(&MediaSourceDelegate::OnDemuxerInitDone,
- media_weak_this_.GetWeakPtr()));
+ chunk_demuxer_->Initialize(this,
+ BIND_TO_RENDER_LOOP(&MediaSourceDelegate::OnDemuxerInitDone));
}
#if defined(GOOGLE_TV)
void MediaSourceDelegate::InitializeMediaStream(
media::Demuxer* demuxer,
const UpdateNetworkStateCB& update_network_state_cb) {
- DCHECK(main_loop_->BelongsToCurrentThread());
DCHECK(demuxer);
demuxer_ = demuxer;
- update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb);
+ update_network_state_cb_ = update_network_state_cb;
// When playing Media Stream, don't wait to accumulate multiple packets per
// IPC communication.
access_unit_size_ = 1;
- // |this| will be retained until StopDemuxer() is posted, so Unretained() is
- // safe here.
- media_loop_->PostTask(FROM_HERE,
- base::Bind(&MediaSourceDelegate::InitializeDemuxer,
- base::Unretained(this)));
+ demuxer_->Initialize(this,
+ BIND_TO_RENDER_LOOP(&MediaSourceDelegate::OnDemuxerInitDone));
}
#endif
@@ -214,14 +185,13 @@ size_t MediaSourceDelegate::VideoDecodedByteCount() const {
}
void MediaSourceDelegate::Seek(base::TimeDelta time, unsigned seek_request_id) {
- DCHECK(main_loop_->BelongsToCurrentThread());
DVLOG(1) << "Seek(" << time.InSecondsF() << ") : " << player_id_;
last_seek_time_ = time;
last_seek_request_id_ = seek_request_id;
if (chunk_demuxer_) {
- if (IsSeeking()) {
+ if (seeking_) {
chunk_demuxer_->CancelPendingSeek(time);
return;
}
@@ -229,18 +199,10 @@ void MediaSourceDelegate::Seek(base::TimeDelta time, unsigned seek_request_id) {
chunk_demuxer_->StartWaitingForSeek(time);
}
- SetSeeking(true);
- media_loop_->PostTask(FROM_HERE,
- base::Bind(&MediaSourceDelegate::SeekInternal,
- base::Unretained(this),
- time, seek_request_id));
-}
-
-void MediaSourceDelegate::SeekInternal(base::TimeDelta time,
- unsigned request_id) {
- DCHECK(media_loop_->BelongsToCurrentThread());
- demuxer_->Seek(time, base::Bind(&MediaSourceDelegate::OnDemuxerSeekDone,
- media_weak_this_.GetWeakPtr(), request_id));
+ seeking_ = true;
+ demuxer_->Seek(time,
+ BIND_TO_RENDER_LOOP_1(&MediaSourceDelegate::OnDemuxerSeekDone,
+ seek_request_id));
}
void MediaSourceDelegate::SetTotalBytes(int64 total_bytes) {
@@ -258,58 +220,45 @@ void MediaSourceDelegate::AddBufferedTimeRange(base::TimeDelta start,
void MediaSourceDelegate::SetDuration(base::TimeDelta duration) {
DVLOG(1) << "SetDuration(" << duration.InSecondsF() << ") : " << player_id_;
- // Notify our owner (e.g. WebMediaPlayerAndroid) that duration has changed.
- // |duration_change_cb_| is bound to the main thread.
+ // Notify our owner (e.g. WebMediaPlayerAndroid) that
+ // duration has changed.
if (!duration_change_cb_.is_null())
duration_change_cb_.Run(duration);
}
void MediaSourceDelegate::OnReadFromDemuxer(media::DemuxerStream::Type type) {
- DCHECK(main_loop_->BelongsToCurrentThread());
- media_loop_->PostTask(
- FROM_HERE,
- base::Bind(&MediaSourceDelegate::OnReadFromDemuxerInternal,
- base::Unretained(this), type));
-}
-
-void MediaSourceDelegate::OnReadFromDemuxerInternal(
- media::DemuxerStream::Type type) {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnReadFromDemuxer(" << type << ") : " << player_id_;
- if (IsSeeking())
+ if (seeking_)
return; // Drop the request during seeking.
DCHECK(type == DemuxerStream::AUDIO || type == DemuxerStream::VIDEO);
// The access unit size should have been initialized properly at this stage.
DCHECK_GT(access_unit_size_, 0u);
- scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params(
- new MediaPlayerHostMsg_ReadFromDemuxerAck_Params());
+ MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params =
+ type == DemuxerStream::AUDIO ? &audio_params_ : &video_params_;
params->type = type;
params->access_units.resize(access_unit_size_);
- ReadFromDemuxerStream(type, params.Pass(), 0);
+ ReadFromDemuxerStream(type, params, 0);
}
void MediaSourceDelegate::ReadFromDemuxerStream(
media::DemuxerStream::Type type,
- scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params,
+ MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params,
size_t index) {
- DCHECK(media_loop_->BelongsToCurrentThread());
- DCHECK(!IsSeeking());
+ DCHECK(!seeking_);
// DemuxerStream::Read() always returns the read callback asynchronously.
DemuxerStream* stream =
(type == DemuxerStream::AUDIO) ? audio_stream_ : video_stream_;
- stream->Read(base::Bind(
- &MediaSourceDelegate::OnBufferReady,
- media_weak_this_.GetWeakPtr(), type, base::Passed(&params), index));
+ stream->Read(base::Bind(&MediaSourceDelegate::OnBufferReady,
+ weak_this_.GetWeakPtr(), type, params, index));
}
void MediaSourceDelegate::OnBufferReady(
media::DemuxerStream::Type type,
- scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params,
+ MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params,
size_t index,
DemuxerStream::Status status,
const scoped_refptr<media::DecoderBuffer>& buffer) {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnBufferReady(" << index << ", " << status << ", "
<< ((!buffer || buffer->end_of_stream()) ?
-1 : buffer->timestamp().InMilliseconds())
@@ -318,8 +267,9 @@ void MediaSourceDelegate::OnBufferReady(
// No new OnReadFromDemuxer() will be called during seeking. So this callback
// must be from previous OnReadFromDemuxer() call and should be ignored.
- if (IsSeeking()) {
+ if (seeking_) {
DVLOG(1) << "OnBufferReady(): Ignore previous read during seeking.";
+ params->access_units.clear();
return;
}
@@ -338,6 +288,7 @@ void MediaSourceDelegate::OnBufferReady(
case DemuxerStream::kAborted:
// Because the abort was caused by the seek, don't respond ack.
DVLOG(1) << "OnBufferReady() : Aborted";
+ params->access_units.clear();
return;
case DemuxerStream::kConfigChanged:
@@ -397,7 +348,7 @@ void MediaSourceDelegate::OnBufferReady(
buffer->decrypt_config()->subsamples();
}
if (++index < params->access_units.size()) {
- ReadFromDemuxerStream(type, params.Pass(), index);
+ ReadFromDemuxerStream(type, params, index);
return;
}
break;
@@ -406,25 +357,19 @@ void MediaSourceDelegate::OnBufferReady(
NOTREACHED();
}
- send_read_from_demuxer_ack_cb_.Run(params.Pass());
-}
-
-void MediaSourceDelegate::SendReadFromDemuxerAck(
- scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params) {
- DCHECK(main_loop_->BelongsToCurrentThread());
- if (!IsSeeking() && proxy_)
+ if (proxy_)
proxy_->ReadFromDemuxerAck(player_id_, *params);
+
+ params->access_units.clear();
}
void MediaSourceDelegate::OnDemuxerError(media::PipelineStatus status) {
DVLOG(1) << "OnDemuxerError(" << status << ") : " << player_id_;
- // |update_network_state_cb_| is bound to the main thread.
if (status != media::PIPELINE_OK && !update_network_state_cb_.is_null())
update_network_state_cb_.Run(PipelineErrorToNetworkState(status));
}
void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnDemuxerInitDone(" << status << ") : " << player_id_;
DCHECK(demuxer_);
@@ -457,7 +402,6 @@ void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) {
}
void MediaSourceDelegate::InitAudioDecryptingDemuxerStream() {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "InitAudioDecryptingDemuxerStream() : " << player_id_;
DCHECK(!set_decryptor_ready_cb_.is_null());
@@ -465,12 +409,11 @@ void MediaSourceDelegate::InitAudioDecryptingDemuxerStream() {
base::MessageLoopProxy::current(), set_decryptor_ready_cb_));
audio_decrypting_demuxer_stream_->Initialize(
audio_stream_,
- base::Bind(&MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone,
- media_weak_this_.GetWeakPtr()));
+ BIND_TO_RENDER_LOOP(
+ &MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone));
}
void MediaSourceDelegate::InitVideoDecryptingDemuxerStream() {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "InitVideoDecryptingDemuxerStream() : " << player_id_;
DCHECK(!set_decryptor_ready_cb_.is_null());
@@ -478,13 +421,12 @@ void MediaSourceDelegate::InitVideoDecryptingDemuxerStream() {
base::MessageLoopProxy::current(), set_decryptor_ready_cb_));
video_decrypting_demuxer_stream_->Initialize(
video_stream_,
- base::Bind(&MediaSourceDelegate::OnVideoDecryptingDemuxerStreamInitDone,
- media_weak_this_.GetWeakPtr()));
+ BIND_TO_RENDER_LOOP(
+ &MediaSourceDelegate::OnVideoDecryptingDemuxerStreamInitDone));
}
void MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone(
media::PipelineStatus status) {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnAudioDecryptingDemuxerStreamInitDone(" << status
<< ") : " << player_id_;
DCHECK(demuxer_);
@@ -508,7 +450,6 @@ void MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone(
void MediaSourceDelegate::OnVideoDecryptingDemuxerStreamInitDone(
media::PipelineStatus status) {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnVideoDecryptingDemuxerStreamInitDone(" << status
<< ") : " << player_id_;
DCHECK(demuxer_);
@@ -526,9 +467,8 @@ void MediaSourceDelegate::OnVideoDecryptingDemuxerStreamInitDone(
void MediaSourceDelegate::OnDemuxerSeekDone(unsigned seek_request_id,
media::PipelineStatus status) {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnDemuxerSeekDone(" << status << ") : " << player_id_;
- DCHECK(IsSeeking());
+ DCHECK(seeking_);
if (status != media::PIPELINE_OK) {
OnDemuxerError(status);
@@ -539,7 +479,10 @@ void MediaSourceDelegate::OnDemuxerSeekDone(unsigned seek_request_id,
if (seek_request_id != last_seek_request_id_) {
if (chunk_demuxer_)
chunk_demuxer_->StartWaitingForSeek(last_seek_time_);
- SeekInternal(last_seek_time_, last_seek_request_id_);
+ demuxer_->Seek(
+ last_seek_time_,
+ BIND_TO_RENDER_LOOP_1(&MediaSourceDelegate::OnDemuxerSeekDone,
+ last_seek_request_id_));
return;
}
@@ -547,59 +490,46 @@ void MediaSourceDelegate::OnDemuxerSeekDone(unsigned seek_request_id,
}
void MediaSourceDelegate::ResetAudioDecryptingDemuxerStream() {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "ResetAudioDecryptingDemuxerStream() : " << player_id_;
if (audio_decrypting_demuxer_stream_) {
audio_decrypting_demuxer_stream_->Reset(
base::Bind(&MediaSourceDelegate::ResetVideoDecryptingDemuxerStream,
- media_weak_this_.GetWeakPtr()));
+ weak_this_.GetWeakPtr()));
} else {
ResetVideoDecryptingDemuxerStream();
}
}
void MediaSourceDelegate::ResetVideoDecryptingDemuxerStream() {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "ResetVideoDecryptingDemuxerStream()";
- if (video_decrypting_demuxer_stream_)
- video_decrypting_demuxer_stream_->Reset(send_seek_request_ack_cb_);
- else
- send_seek_request_ack_cb_.Run();
+ if (video_decrypting_demuxer_stream_) {
+ video_decrypting_demuxer_stream_->Reset(
+ base::Bind(&MediaSourceDelegate::SendSeekRequestAck,
+ weak_this_.GetWeakPtr()));
+ } else {
+ SendSeekRequestAck();
+ }
}
void MediaSourceDelegate::SendSeekRequestAck() {
DVLOG(1) << "SendSeekRequestAck() : " << player_id_;
- SetSeeking(false);
+ seeking_ = false;
proxy_->SeekRequestAck(player_id_, last_seek_request_id_);
last_seek_request_id_ = 0;
}
void MediaSourceDelegate::OnDemuxerStopDone() {
- DCHECK(main_loop_->BelongsToCurrentThread());
DVLOG(1) << "OnDemuxerStopDone() : " << player_id_;
chunk_demuxer_.reset();
- demuxer_ = NULL;
delete this;
}
void MediaSourceDelegate::OnMediaConfigRequest() {
- if (!media_loop_->BelongsToCurrentThread()) {
- media_loop_->PostTask(FROM_HERE,
- base::Bind(&MediaSourceDelegate::OnMediaConfigRequest,
- base::Unretained(this)));
- return;
- }
if (CanNotifyDemuxerReady())
NotifyDemuxerReady();
}
void MediaSourceDelegate::NotifyKeyAdded(const std::string& key_system) {
- if (!media_loop_->BelongsToCurrentThread()) {
- media_loop_->PostTask(FROM_HERE,
- base::Bind(&MediaSourceDelegate::NotifyKeyAdded,
- base::Unretained(this), key_system));
- return;
- }
DVLOG(1) << "NotifyKeyAdded() : " << player_id_;
// TODO(kjyoun): Enhance logic to detect when to call NotifyDemuxerReady()
// For now, we calls it when the first key is added. See
@@ -615,7 +545,6 @@ void MediaSourceDelegate::NotifyKeyAdded(const std::string& key_system) {
}
bool MediaSourceDelegate::CanNotifyDemuxerReady() {
- DCHECK(media_loop_->BelongsToCurrentThread());
// This can happen when a key is added before the demuxer is initialized.
// See NotifyKeyAdded().
// TODO(kjyoun): Remove NotifyDemxuerReady() call from NotifyKeyAdded() so
@@ -629,45 +558,36 @@ bool MediaSourceDelegate::CanNotifyDemuxerReady() {
}
void MediaSourceDelegate::NotifyDemuxerReady() {
- DCHECK(media_loop_->BelongsToCurrentThread());
DVLOG(1) << "NotifyDemuxerReady() : " << player_id_;
DCHECK(CanNotifyDemuxerReady());
- scoped_ptr<MediaPlayerHostMsg_DemuxerReady_Params> params(
- new MediaPlayerHostMsg_DemuxerReady_Params());
+ MediaPlayerHostMsg_DemuxerReady_Params params;
if (audio_stream_) {
media::AudioDecoderConfig config = audio_stream_->audio_decoder_config();
- params->audio_codec = config.codec();
- params->audio_channels =
+ params.audio_codec = config.codec();
+ params.audio_channels =
media::ChannelLayoutToChannelCount(config.channel_layout());
- params->audio_sampling_rate = config.samples_per_second();
- params->is_audio_encrypted = config.is_encrypted();
- params->audio_extra_data = std::vector<uint8>(
+ params.audio_sampling_rate = config.samples_per_second();
+ params.is_audio_encrypted = config.is_encrypted();
+ params.audio_extra_data = std::vector<uint8>(
config.extra_data(), config.extra_data() + config.extra_data_size());
}
if (video_stream_) {
media::VideoDecoderConfig config = video_stream_->video_decoder_config();
- params->video_codec = config.codec();
- params->video_size = config.natural_size();
- params->is_video_encrypted = config.is_encrypted();
- params->video_extra_data = std::vector<uint8>(
+ params.video_codec = config.codec();
+ params.video_size = config.natural_size();
+ params.is_video_encrypted = config.is_encrypted();
+ params.video_extra_data = std::vector<uint8>(
config.extra_data(), config.extra_data() + config.extra_data_size());
}
- params->duration_ms = GetDurationMs();
- params->key_system = HasEncryptedStream() ? key_system_ : "";
-
- send_demuxer_ready_cb_.Run(params.Pass());
-}
+ params.duration_ms = GetDurationMs();
+ params.key_system = HasEncryptedStream() ? key_system_ : "";
-void MediaSourceDelegate::SendDemuxerReady(
- scoped_ptr<MediaPlayerHostMsg_DemuxerReady_Params> params) {
- DCHECK(main_loop_->BelongsToCurrentThread());
if (proxy_)
- proxy_->DemuxerReady(player_id_, *params);
+ proxy_->DemuxerReady(player_id_, params);
}
int MediaSourceDelegate::GetDurationMs() {
- DCHECK(media_loop_->BelongsToCurrentThread());
if (!chunk_demuxer_)
return -1;
@@ -681,7 +601,6 @@ int MediaSourceDelegate::GetDurationMs() {
}
void MediaSourceDelegate::OnDemuxerOpened() {
- DCHECK(main_loop_->BelongsToCurrentThread());
if (media_source_opened_cb_.is_null())
return;
@@ -693,7 +612,6 @@ void MediaSourceDelegate::OnNeedKey(const std::string& session_id,
const std::string& type,
scoped_ptr<uint8[]> init_data,
int init_data_size) {
- DCHECK(main_loop_->BelongsToCurrentThread());
if (need_key_cb_.is_null())
return;
@@ -708,21 +626,10 @@ scoped_ptr<media::TextTrack> MediaSourceDelegate::OnAddTextTrack(
}
bool MediaSourceDelegate::HasEncryptedStream() {
- DCHECK(media_loop_->BelongsToCurrentThread());
return (audio_stream_ &&
audio_stream_->audio_decoder_config().is_encrypted()) ||
(video_stream_ &&
video_stream_->video_decoder_config().is_encrypted());
}
-void MediaSourceDelegate::SetSeeking(bool seeking) {
- base::AutoLock auto_lock(seeking_lock_);
- seeking_ = seeking;
-}
-
-bool MediaSourceDelegate::IsSeeking() const {
- base::AutoLock auto_lock(seeking_lock_);
- return seeking_;
-}
-
} // namespace content
diff --git a/content/renderer/media/android/media_source_delegate.h b/content/renderer/media/android/media_source_delegate.h
index e5463c6..f217a63 100644
--- a/content/renderer/media/android/media_source_delegate.h
+++ b/content/renderer/media/android/media_source_delegate.h
@@ -9,8 +9,8 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
+#include "media/base/android/demuxer_stream_player_params.h"
#include "media/base/decryptor.h"
#include "media/base/demuxer.h"
#include "media/base/media_keys.h"
@@ -25,7 +25,6 @@ class DecoderBuffer;
class DecryptingDemuxerStream;
class DemuxerStream;
class MediaLog;
-struct MediaPlayerHostMsg_DemuxerReady_Params;
struct MediaPlayerHostMsg_ReadFromDemuxerAck_Params;
}
@@ -52,7 +51,6 @@ class MediaSourceDelegate : public media::DemuxerHost {
MediaSourceDelegate(WebMediaPlayerProxyAndroid* proxy,
int player_id,
- const scoped_refptr<base::MessageLoopProxy>& media_loop,
media::MediaLog* media_log);
// Initialize the MediaSourceDelegate. |media_source| will be owned by
@@ -93,13 +91,6 @@ class MediaSourceDelegate : public media::DemuxerHost {
void Destroy();
private:
- typedef base::Callback<void(
- scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params)>
- ReadFromDemuxerAckCB;
- typedef base::Callback<void(
- scoped_ptr<media::MediaPlayerHostMsg_DemuxerReady_Params> params)>
- DemuxerReadyCB;
-
// This is private to enforce use of the Destroyer.
virtual ~MediaSourceDelegate();
@@ -149,52 +140,26 @@ class MediaSourceDelegate : public media::DemuxerHost {
const std::string& language);
void NotifyDemuxerReady();
bool CanNotifyDemuxerReady();
- void SendDemuxerReady(
- scoped_ptr<media::MediaPlayerHostMsg_DemuxerReady_Params> params);
- void StopDemuxer();
- void InitializeDemuxer();
- void SeekInternal(base::TimeDelta time, unsigned seek_request_id);
- void OnReadFromDemuxerInternal(media::DemuxerStream::Type type);
// Reads an access unit from the demuxer stream |stream| and stores it in
// the |index|th access unit in |params|.
void ReadFromDemuxerStream(
media::DemuxerStream::Type type,
- scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params,
+ media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params,
size_t index);
void OnBufferReady(
media::DemuxerStream::Type type,
- scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params,
+ media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params,
size_t index,
media::DemuxerStream::Status status,
const scoped_refptr<media::DecoderBuffer>& buffer);
- void SendReadFromDemuxerAck(
- scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params);
-
// Helper function for calculating duration.
int GetDurationMs();
bool HasEncryptedStream();
- void SetSeeking(bool seeking);
- bool IsSeeking() const;
-
- // Weak pointer must be dereferenced and invalidated on the same thread.
- base::WeakPtrFactory<MediaSourceDelegate> main_weak_this_;
- base::WeakPtrFactory<MediaSourceDelegate> media_weak_this_;
-
- // Message loop for main renderer thread.
- const scoped_refptr<base::MessageLoopProxy> main_loop_;
- // Message loop for the media thread.
- // When there is high load in the render thread, the reading from |demuxer_|
- // and its read-callback loops run very slowly. To improve the response time
- // of the readings, we run tasks related to |demuxer_| in the media thread.
- const scoped_refptr<base::MessageLoopProxy> media_loop_;
-
- ReadFromDemuxerAckCB send_read_from_demuxer_ack_cb_;
- base::Closure send_seek_request_ack_cb_;
- DemuxerReadyCB send_demuxer_ready_cb_;
+ base::WeakPtrFactory<MediaSourceDelegate> weak_this_;
WebMediaPlayerProxyAndroid* proxy_;
int player_id_;
@@ -231,10 +196,10 @@ class MediaSourceDelegate : public media::DemuxerHost {
// through GenerateKeyRequest() directly from WebKit.
std::string init_data_type_;
- // Lock used to serialize access for |seeking_|.
- mutable base::Lock seeking_lock_;
- bool seeking_;
+ media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params audio_params_;
+ media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params video_params_;
+ bool seeking_;
base::TimeDelta last_seek_time_;
unsigned last_seek_request_id_;
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc
index f8eea96..ec0565e 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -65,14 +65,12 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
RendererMediaPlayerManager* manager,
WebMediaPlayerProxyAndroid* proxy,
StreamTextureFactory* factory,
- const scoped_refptr<base::MessageLoopProxy>& media_loop,
media::MediaLog* media_log)
: frame_(frame),
client_(client),
delegate_(delegate),
buffered_(1u),
main_loop_(base::MessageLoopProxy::current()),
- media_loop_(media_loop),
ignore_metadata_duration_change_(false),
pending_seek_(0),
seeking_(false),
@@ -232,7 +230,7 @@ void WebMediaPlayerAndroid::load(LoadType load_type,
if (source_type_ != MediaPlayerAndroid::SOURCE_TYPE_URL) {
has_media_info_ = true;
media_source_delegate_.reset(
- new MediaSourceDelegate(proxy_, player_id_, media_loop_, media_log_));
+ new MediaSourceDelegate(proxy_, player_id_, media_log_));
// |media_source_delegate_| is owned, so Unretained() is safe here.
if (source_type_ == MediaPlayerAndroid::SOURCE_TYPE_MSE) {
media_source_delegate_->InitializeMediaSource(
diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h
index 03f511cb..e149d44 100644
--- a/content/renderer/media/android/webmediaplayer_android.h
+++ b/content/renderer/media/android/webmediaplayer_android.h
@@ -77,7 +77,6 @@ class WebMediaPlayerAndroid
RendererMediaPlayerManager* manager,
WebMediaPlayerProxyAndroid* proxy,
StreamTextureFactory* factory,
- const scoped_refptr<base::MessageLoopProxy>& media_loop,
media::MediaLog* media_log);
virtual ~WebMediaPlayerAndroid();
@@ -304,9 +303,6 @@ class WebMediaPlayerAndroid
// Message loop for main renderer thread.
const scoped_refptr<base::MessageLoopProxy> main_loop_;
- // Message loop for media thread.
- const scoped_refptr<base::MessageLoopProxy> media_loop_;
-
// URL of the media file to be fetched.
GURL url_;