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/browser/media/android/browser_demuxer_android.h"
7 #include "content/common/media/media_player_messages_android.h"
11 class BrowserDemuxerAndroid::Internal
: public media::DemuxerAndroid
{
13 Internal(const scoped_refptr
<BrowserDemuxerAndroid
>& demuxer
,
14 int demuxer_client_id
)
16 demuxer_client_id_(demuxer_client_id
) {}
19 DCHECK(ClientIDExists()) << demuxer_client_id_
;
20 demuxer_
->RemoveDemuxerClient(demuxer_client_id_
);
23 // media::DemuxerAndroid implementation.
24 virtual void Initialize(media::DemuxerAndroidClient
* client
) OVERRIDE
{
25 DCHECK(!ClientIDExists()) << demuxer_client_id_
;
26 demuxer_
->AddDemuxerClient(demuxer_client_id_
, client
);
29 virtual void RequestDemuxerConfigs() OVERRIDE
{
30 DCHECK(ClientIDExists()) << demuxer_client_id_
;
31 demuxer_
->Send(new MediaPlayerMsg_MediaConfigRequest(demuxer_client_id_
));
34 virtual void RequestDemuxerData(media::DemuxerStream::Type type
) OVERRIDE
{
35 DCHECK(ClientIDExists()) << demuxer_client_id_
;
36 demuxer_
->Send(new MediaPlayerMsg_ReadFromDemuxer(
37 demuxer_client_id_
, type
));
40 virtual void RequestDemuxerSeek(
41 const base::TimeDelta
& time_to_seek
,
42 bool is_browser_seek
) OVERRIDE
{
43 DCHECK(ClientIDExists()) << demuxer_client_id_
;
44 demuxer_
->Send(new MediaPlayerMsg_DemuxerSeekRequest(
45 demuxer_client_id_
, time_to_seek
, is_browser_seek
));
49 // Helper for DCHECKing that the ID is still registered.
50 bool ClientIDExists() {
51 return demuxer_
->demuxer_clients_
.Lookup(demuxer_client_id_
);
54 scoped_refptr
<BrowserDemuxerAndroid
> demuxer_
;
55 int demuxer_client_id_
;
57 DISALLOW_COPY_AND_ASSIGN(Internal
);
60 BrowserDemuxerAndroid::BrowserDemuxerAndroid() {}
62 BrowserDemuxerAndroid::~BrowserDemuxerAndroid() {}
64 void BrowserDemuxerAndroid::OverrideThreadForMessage(
65 const IPC::Message
& message
,
66 BrowserThread::ID
* thread
) {
67 switch (message
.type()) {
68 case MediaPlayerHostMsg_DemuxerReady::ID
:
69 case MediaPlayerHostMsg_ReadFromDemuxerAck::ID
:
70 case MediaPlayerHostMsg_DurationChanged::ID
:
71 case MediaPlayerHostMsg_DemuxerSeekDone::ID
:
72 *thread
= BrowserThread::UI
;
77 bool BrowserDemuxerAndroid::OnMessageReceived(const IPC::Message
& message
,
78 bool* message_was_ok
) {
80 IPC_BEGIN_MESSAGE_MAP_EX(BrowserDemuxerAndroid
, message
, *message_was_ok
)
81 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DemuxerReady
, OnDemuxerReady
)
82 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_ReadFromDemuxerAck
,
84 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DurationChanged
,
86 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DemuxerSeekDone
,
88 IPC_MESSAGE_UNHANDLED(handled
= false)
93 scoped_ptr
<media::DemuxerAndroid
> BrowserDemuxerAndroid::CreateDemuxer(
94 int demuxer_client_id
) {
95 return scoped_ptr
<media::DemuxerAndroid
>(
96 new Internal(this, demuxer_client_id
));
99 void BrowserDemuxerAndroid::AddDemuxerClient(
100 int demuxer_client_id
,
101 media::DemuxerAndroidClient
* client
) {
102 DVLOG(1) << __FUNCTION__
<< " peer_pid=" << peer_pid()
103 << " demuxer_client_id=" << demuxer_client_id
;
104 demuxer_clients_
.AddWithID(client
, demuxer_client_id
);
107 void BrowserDemuxerAndroid::RemoveDemuxerClient(int demuxer_client_id
) {
108 DVLOG(1) << __FUNCTION__
<< " peer_pid=" << peer_pid()
109 << " demuxer_client_id=" << demuxer_client_id
;
110 demuxer_clients_
.Remove(demuxer_client_id
);
113 void BrowserDemuxerAndroid::OnDemuxerReady(
114 int demuxer_client_id
,
115 const media::DemuxerConfigs
& configs
) {
116 media::DemuxerAndroidClient
* client
=
117 demuxer_clients_
.Lookup(demuxer_client_id
);
119 client
->OnDemuxerConfigsAvailable(configs
);
122 void BrowserDemuxerAndroid::OnReadFromDemuxerAck(
123 int demuxer_client_id
,
124 const media::DemuxerData
& data
) {
125 media::DemuxerAndroidClient
* client
=
126 demuxer_clients_
.Lookup(demuxer_client_id
);
128 client
->OnDemuxerDataAvailable(data
);
131 void BrowserDemuxerAndroid::OnDemuxerSeekDone(
132 int demuxer_client_id
,
133 const base::TimeDelta
& actual_browser_seek_time
) {
134 media::DemuxerAndroidClient
* client
=
135 demuxer_clients_
.Lookup(demuxer_client_id
);
137 client
->OnDemuxerSeekDone(actual_browser_seek_time
);
140 void BrowserDemuxerAndroid::OnDurationChanged(int demuxer_client_id
,
141 const base::TimeDelta
& duration
) {
142 media::DemuxerAndroidClient
* client
=
143 demuxer_clients_
.Lookup(demuxer_client_id
);
145 client
->OnDemuxerDurationChanged(duration
);
148 } // namespace content