1/* 2 * Copyright 2015, Dario Casalinuovo. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#include <MediaConnection.h> 7 8#include <string.h> 9 10#include "MediaClientNode.h" 11 12#include "MediaDebug.h" 13 14 15BMediaConnection::BMediaConnection(media_connection_kinds kinds, 16 const char* name) 17 : 18 fOwner(NULL), 19 fBind(NULL) 20{ 21 CALLED(); 22 23 fConnection.kinds = kinds; 24 fConnection.id = -1; 25 //fConnection.client = media_client::null; 26 if (name != NULL) 27 strcpy(fConnection.name, name); 28} 29 30 31BMediaConnection::~BMediaConnection() 32{ 33 CALLED(); 34 35} 36 37 38const media_connection& 39BMediaConnection::Connection() const 40{ 41 return fConnection; 42} 43 44 45BMediaClient* 46BMediaConnection::Client() const 47{ 48 return fOwner; 49} 50 51 52const char* 53BMediaConnection::Name() const 54{ 55 return fConnection.name; 56} 57 58 59bool 60BMediaConnection::HasBinding() const 61{ 62 CALLED(); 63 64 return fBind != NULL; 65} 66 67 68BMediaConnection* 69BMediaConnection::Binding() const 70{ 71 CALLED(); 72 73 return fBind; 74} 75 76 77bool 78BMediaConnection::IsConnected() const 79{ 80 CALLED(); 81 82 return fConnected; 83} 84 85 86status_t 87BMediaConnection::Disconnect() 88{ 89 CALLED(); 90 91 return fOwner->_DisconnectConnection(this); 92} 93 94 95status_t 96BMediaConnection::Release() 97{ 98 CALLED(); 99 100 status_t ret = fOwner->_ReleaseConnection(this); 101 if (ret != B_OK) 102 return ret; 103 104 delete this; 105 return ret; 106} 107 108 109void 110BMediaConnection::Connected(const media_format& format) 111{ 112 // Update the status of our connection format. 113 fConnection.format = format; 114 115 fConnected = true; 116} 117 118 119void 120BMediaConnection::Disconnected() 121{ 122 CALLED(); 123 124 fConnected = false; 125} 126 127 128void 129BMediaConnection::_ConnectionRegistered(BMediaClient* owner, 130 media_connection_id id) 131{ 132 fOwner = owner; 133 fConnection.id = id; 134 fConnection.client = fOwner->Client(); 135 136 if (fConnection.IsOutput()) { 137 fConnection.source.port = fOwner->fNode->ControlPort(); 138 fConnection.source.id = fConnection.id; 139 140 fConnection.destination = media_destination::null; 141 } else { 142 fConnection.destination.port = fOwner->fNode->ControlPort(); 143 fConnection.destination.id = fConnection.id; 144 145 fConnection.source = media_source::null; 146 } 147} 148 149 150const media_source& 151BMediaConnection::_Source() const 152{ 153 return fConnection.source; 154} 155 156 157const media_destination& 158BMediaConnection::_Destination() const 159{ 160 return fConnection.destination; 161} 162 163 164void BMediaConnection::_ReservedMediaConnection0() {} 165void BMediaConnection::_ReservedMediaConnection1() {} 166void BMediaConnection::_ReservedMediaConnection2() {} 167void BMediaConnection::_ReservedMediaConnection3() {} 168void BMediaConnection::_ReservedMediaConnection4() {} 169void BMediaConnection::_ReservedMediaConnection5() {} 170void BMediaConnection::_ReservedMediaConnection6() {} 171void BMediaConnection::_ReservedMediaConnection7() {} 172void BMediaConnection::_ReservedMediaConnection8() {} 173void BMediaConnection::_ReservedMediaConnection9() {} 174void BMediaConnection::_ReservedMediaConnection10() {} 175 176 177BMediaInput::BMediaInput(const char* name) 178 : 179 BMediaConnection(B_MEDIA_INPUT, name) 180{ 181} 182 183 184BMediaInput::~BMediaInput() 185{ 186 CALLED(); 187} 188 189 190void 191BMediaInput::HandleBuffer(BBuffer* buffer) 192{ 193 CALLED(); 194} 195 196 197void 198BMediaInput::Connected(const media_format& format) 199{ 200 BMediaConnection::Connected(format); 201} 202 203 204void 205BMediaInput::Disconnected() 206{ 207 BMediaConnection::Disconnected(); 208} 209 210 211void BMediaInput::_ReservedMediaInput0() {} 212void BMediaInput::_ReservedMediaInput1() {} 213void BMediaInput::_ReservedMediaInput2() {} 214void BMediaInput::_ReservedMediaInput3() {} 215void BMediaInput::_ReservedMediaInput4() {} 216void BMediaInput::_ReservedMediaInput5() {} 217void BMediaInput::_ReservedMediaInput6() {} 218void BMediaInput::_ReservedMediaInput7() {} 219void BMediaInput::_ReservedMediaInput8() {} 220void BMediaInput::_ReservedMediaInput9() {} 221void BMediaInput::_ReservedMediaInput10() {} 222 223 224BMediaOutput::BMediaOutput(const char* name) 225 : 226 BMediaConnection(B_MEDIA_OUTPUT, name), 227 fBufferGroup(NULL) 228{ 229} 230 231 232BMediaOutput::~BMediaOutput() 233{ 234 CALLED(); 235} 236 237 238status_t 239BMediaOutput::SendBuffer(BBuffer* buffer) 240{ 241 CALLED(); 242 243 if (!IsConnected()) 244 return B_ERROR; 245 246 return fOwner->fNode->SendBuffer(buffer, this); 247} 248 249 250void 251BMediaOutput::Connected(const media_format& format) 252{ 253 BMediaConnection::Connected(format); 254} 255 256 257void 258BMediaOutput::Disconnected() 259{ 260 BMediaConnection::Disconnected(); 261} 262 263 264bool 265BMediaOutput::_IsEnabled() const 266{ 267 CALLED(); 268 269 return fEnabled; 270} 271 272 273void 274BMediaOutput::_SetEnabled(bool enabled) 275{ 276 fEnabled = enabled; 277} 278 279 280void BMediaOutput::_ReservedMediaOutput0() {} 281void BMediaOutput::_ReservedMediaOutput1() {} 282void BMediaOutput::_ReservedMediaOutput2() {} 283void BMediaOutput::_ReservedMediaOutput3() {} 284void BMediaOutput::_ReservedMediaOutput4() {} 285void BMediaOutput::_ReservedMediaOutput5() {} 286void BMediaOutput::_ReservedMediaOutput6() {} 287void BMediaOutput::_ReservedMediaOutput7() {} 288void BMediaOutput::_ReservedMediaOutput8() {} 289void BMediaOutput::_ReservedMediaOutput9() {} 290void BMediaOutput::_ReservedMediaOutput10() {} 291