• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/renderer/media/android/renderer_demuxer_android.h"
6 
7 #include "base/bind.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"
15 
16 namespace content {
17 
RendererDemuxerAndroid()18 RendererDemuxerAndroid::RendererDemuxerAndroid()
19     : thread_safe_sender_(RenderThreadImpl::current()->thread_safe_sender()),
20       media_task_runner_(
21           RenderThreadImpl::current()->GetMediaThreadTaskRunner()) {}
22 
~RendererDemuxerAndroid()23 RendererDemuxerAndroid::~RendererDemuxerAndroid() {}
24 
GetNextDemuxerClientID()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;
28 }
29 
AddDelegate(int demuxer_client_id,MediaSourceDelegate * delegate)30 void RendererDemuxerAndroid::AddDelegate(int demuxer_client_id,
31                                          MediaSourceDelegate* delegate) {
32   DCHECK(media_task_runner_->BelongsToCurrentThread());
33   delegates_.AddWithID(delegate, demuxer_client_id);
34 }
35 
RemoveDelegate(int demuxer_client_id)36 void RendererDemuxerAndroid::RemoveDelegate(int demuxer_client_id) {
37   DCHECK(media_task_runner_->BelongsToCurrentThread());
38   delegates_.Remove(demuxer_client_id);
39 }
40 
OnMessageReceived(const IPC::Message & message)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));
47       return true;
48    }
49   return false;
50 }
51 
DemuxerReady(int demuxer_client_id,const media::DemuxerConfigs & configs)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));
57 }
58 
ReadFromDemuxerAck(int demuxer_client_id,const media::DemuxerData & data)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));
64 }
65 
DemuxerSeekDone(int demuxer_client_id,const base::TimeDelta & actual_browser_seek_time)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));
71 }
72 
DurationChanged(int demuxer_client_id,const base::TimeDelta & duration)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));
77 }
78 
DispatchMessage(const IPC::Message & message)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)
83   IPC_END_MESSAGE_MAP()
84 }
85 
OnReadFromDemuxer(int demuxer_client_id,media::DemuxerStream::Type type)86 void RendererDemuxerAndroid::OnReadFromDemuxer(
87     int demuxer_client_id,
88     media::DemuxerStream::Type type) {
89   MediaSourceDelegate* delegate = delegates_.Lookup(demuxer_client_id);
90   if (delegate)
91     delegate->OnReadFromDemuxer(type);
92 }
93 
OnDemuxerSeekRequest(int demuxer_client_id,const base::TimeDelta & time_to_seek,bool is_browser_seek)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);
99   if (delegate)
100     delegate->Seek(time_to_seek, is_browser_seek);
101 }
102 
103 }  // namespace content
104