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