OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "chromecast/renderer/media/media_channel_proxy.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "chromecast/common/media/cma_messages.h" |
| 9 |
| 10 namespace chromecast { |
| 11 namespace media { |
| 12 |
| 13 MediaChannelProxy::MediaChannelProxy() |
| 14 : is_open_(false), |
| 15 id_(0) { |
| 16 filter_ = CmaMessageFilterProxy::Get(); |
| 17 DCHECK(filter_.get()); |
| 18 } |
| 19 |
| 20 MediaChannelProxy::~MediaChannelProxy() { |
| 21 } |
| 22 |
| 23 void MediaChannelProxy::Open(LoadType load_type) { |
| 24 CHECK(!is_open_); |
| 25 // Renderer side. |
| 26 id_ = filter_->CreateChannel(); |
| 27 is_open_ = true; |
| 28 |
| 29 // Browser side. |
| 30 bool success = Send( |
| 31 scoped_ptr<IPC::Message>(new CmaHostMsg_CreateMedia(id_, load_type))); |
| 32 if (!success) { |
| 33 is_open_ = false; |
| 34 id_ = 0; |
| 35 } |
| 36 } |
| 37 |
| 38 void MediaChannelProxy::Close() { |
| 39 if (!is_open_) |
| 40 return; |
| 41 |
| 42 // Browser side. |
| 43 Send(scoped_ptr<IPC::Message>(new CmaHostMsg_DestroyMedia(id_))); |
| 44 |
| 45 // Renderer side. |
| 46 is_open_ = false; |
| 47 filter_->DestroyChannel(id_); |
| 48 id_ = 0; |
| 49 } |
| 50 |
| 51 bool MediaChannelProxy::SetMediaDelegate( |
| 52 const CmaMessageFilterProxy::MediaDelegate& media_delegate) { |
| 53 if (!is_open_) |
| 54 return false; |
| 55 return filter_->SetMediaDelegate(id_, media_delegate); |
| 56 } |
| 57 |
| 58 bool MediaChannelProxy::SetAudioDelegate( |
| 59 const CmaMessageFilterProxy::AudioDelegate& audio_delegate) { |
| 60 if (!is_open_) |
| 61 return false; |
| 62 return filter_->SetAudioDelegate(id_, audio_delegate); |
| 63 } |
| 64 |
| 65 bool MediaChannelProxy::SetVideoDelegate( |
| 66 const CmaMessageFilterProxy::VideoDelegate& video_delegate) { |
| 67 if (!is_open_) |
| 68 return false; |
| 69 return filter_->SetVideoDelegate(id_, video_delegate); |
| 70 } |
| 71 |
| 72 bool MediaChannelProxy::Send(scoped_ptr<IPC::Message> message) { |
| 73 if (!is_open_) |
| 74 return false; |
| 75 return filter_->Send(message.Pass()); |
| 76 } |
| 77 |
| 78 } // namespace media |
| 79 } // namespace chromecast |
OLD | NEW |