1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/media/android/renderer_demuxer_android.h"
8 #include "base/single_thread_task_runner.h"
9 #include "content/child/thread_safe_sender.h"
10 #include "content/common/media/media_player_messages_android.h"
11 #include "content/renderer/media/android/media_source_delegate.h"
12 #include "content/renderer/media/android/renderer_media_player_manager.h"
13 #include "content/renderer/media/android/webmediaplayer_android.h"
14 #include "content/renderer/render_thread_impl.h"
18 RendererDemuxerAndroid::RendererDemuxerAndroid()
19 : thread_safe_sender_(RenderThreadImpl::current()->thread_safe_sender()),
21 RenderThreadImpl::current()->GetMediaThreadTaskRunner()) {}
23 RendererDemuxerAndroid::~RendererDemuxerAndroid() {}
25 int RendererDemuxerAndroid::GetNextDemuxerClientID() {
26 // Don't use zero for IDs since it can be interpreted as having no ID.
27 return next_demuxer_client_id_
.GetNext() + 1;
30 void RendererDemuxerAndroid::AddDelegate(int demuxer_client_id
,
31 MediaSourceDelegate
* delegate
) {
32 DCHECK(media_task_runner_
->BelongsToCurrentThread());
33 delegates_
.AddWithID(delegate
, demuxer_client_id
);
36 void RendererDemuxerAndroid::RemoveDelegate(int demuxer_client_id
) {
37 DCHECK(media_task_runner_
->BelongsToCurrentThread());
38 delegates_
.Remove(demuxer_client_id
);
41 bool RendererDemuxerAndroid::OnMessageReceived(const IPC::Message
& message
) {
42 switch (message
.type()) {
43 case MediaPlayerMsg_DemuxerSeekRequest::ID
:
44 case MediaPlayerMsg_ReadFromDemuxer::ID
:
45 media_task_runner_
->PostTask(FROM_HERE
, base::Bind(
46 &RendererDemuxerAndroid::DispatchMessage
, this, message
));
52 void RendererDemuxerAndroid::DemuxerReady(
53 int demuxer_client_id
,
54 const media::DemuxerConfigs
& configs
) {
55 thread_safe_sender_
->Send(new MediaPlayerHostMsg_DemuxerReady(
56 demuxer_client_id
, configs
));
59 void RendererDemuxerAndroid::ReadFromDemuxerAck(
60 int demuxer_client_id
,
61 const media::DemuxerData
& data
) {
62 thread_safe_sender_
->Send(new MediaPlayerHostMsg_ReadFromDemuxerAck(
63 demuxer_client_id
, data
));
66 void RendererDemuxerAndroid::DemuxerSeekDone(
67 int demuxer_client_id
,
68 const base::TimeDelta
& actual_browser_seek_time
) {
69 thread_safe_sender_
->Send(new MediaPlayerHostMsg_DemuxerSeekDone(
70 demuxer_client_id
, actual_browser_seek_time
));
73 void RendererDemuxerAndroid::DurationChanged(int demuxer_client_id
,
74 const base::TimeDelta
& duration
) {
75 thread_safe_sender_
->Send(new MediaPlayerHostMsg_DurationChanged(
76 demuxer_client_id
, duration
));
79 void RendererDemuxerAndroid::DispatchMessage(const IPC::Message
& message
) {
80 IPC_BEGIN_MESSAGE_MAP(RendererDemuxerAndroid
, message
)
81 IPC_MESSAGE_HANDLER(MediaPlayerMsg_DemuxerSeekRequest
, OnDemuxerSeekRequest
)
82 IPC_MESSAGE_HANDLER(MediaPlayerMsg_ReadFromDemuxer
, OnReadFromDemuxer
)
86 void RendererDemuxerAndroid::OnReadFromDemuxer(
87 int demuxer_client_id
,
88 media::DemuxerStream::Type type
) {
89 MediaSourceDelegate
* delegate
= delegates_
.Lookup(demuxer_client_id
);
91 delegate
->OnReadFromDemuxer(type
);
94 void RendererDemuxerAndroid::OnDemuxerSeekRequest(
95 int demuxer_client_id
,
96 const base::TimeDelta
& time_to_seek
,
97 bool is_browser_seek
) {
98 MediaSourceDelegate
* delegate
= delegates_
.Lookup(demuxer_client_id
);
100 delegate
->Seek(time_to_seek
, is_browser_seek
);
103 } // namespace content