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 15 BMediaConnection::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 31 BMediaConnection::~BMediaConnection() 32 { 33 CALLED(); 34 35 } 36 37 38 const media_connection& 39 BMediaConnection::Connection() const 40 { 41 return fConnection; 42 } 43 44 45 BMediaClient* 46 BMediaConnection::Client() const 47 { 48 return fOwner; 49 } 50 51 52 const char* 53 BMediaConnection::Name() const 54 { 55 return fConnection.name; 56 } 57 58 59 bool 60 BMediaConnection::HasBinding() const 61 { 62 CALLED(); 63 64 return fBind != NULL; 65 } 66 67 68 BMediaConnection* 69 BMediaConnection::Binding() const 70 { 71 CALLED(); 72 73 return fBind; 74 } 75 76 77 bool 78 BMediaConnection::IsConnected() const 79 { 80 CALLED(); 81 82 return fConnected; 83 } 84 85 86 status_t 87 BMediaConnection::Disconnect() 88 { 89 CALLED(); 90 91 return fOwner->_DisconnectConnection(this); 92 } 93 94 95 status_t 96 BMediaConnection::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 109 void 110 BMediaConnection::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 119 void 120 BMediaConnection::Disconnected() 121 { 122 CALLED(); 123 124 fConnected = false; 125 } 126 127 128 void 129 BMediaConnection::_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 150 const media_source& 151 BMediaConnection::_Source() const 152 { 153 return fConnection.source; 154 } 155 156 157 const media_destination& 158 BMediaConnection::_Destination() const 159 { 160 return fConnection.destination; 161 } 162 163 164 void BMediaConnection::_ReservedMediaConnection0() {} 165 void BMediaConnection::_ReservedMediaConnection1() {} 166 void BMediaConnection::_ReservedMediaConnection2() {} 167 void BMediaConnection::_ReservedMediaConnection3() {} 168 void BMediaConnection::_ReservedMediaConnection4() {} 169 void BMediaConnection::_ReservedMediaConnection5() {} 170 void BMediaConnection::_ReservedMediaConnection6() {} 171 void BMediaConnection::_ReservedMediaConnection7() {} 172 void BMediaConnection::_ReservedMediaConnection8() {} 173 void BMediaConnection::_ReservedMediaConnection9() {} 174 void BMediaConnection::_ReservedMediaConnection10() {} 175 176 177 BMediaInput::BMediaInput(const char* name) 178 : 179 BMediaConnection(B_MEDIA_INPUT, name) 180 { 181 } 182 183 184 BMediaInput::~BMediaInput() 185 { 186 CALLED(); 187 } 188 189 190 void 191 BMediaInput::HandleBuffer(BBuffer* buffer) 192 { 193 CALLED(); 194 } 195 196 197 void 198 BMediaInput::Connected(const media_format& format) 199 { 200 BMediaConnection::Connected(format); 201 } 202 203 204 void 205 BMediaInput::Disconnected() 206 { 207 BMediaConnection::Disconnected(); 208 } 209 210 211 void BMediaInput::_ReservedMediaInput0() {} 212 void BMediaInput::_ReservedMediaInput1() {} 213 void BMediaInput::_ReservedMediaInput2() {} 214 void BMediaInput::_ReservedMediaInput3() {} 215 void BMediaInput::_ReservedMediaInput4() {} 216 void BMediaInput::_ReservedMediaInput5() {} 217 void BMediaInput::_ReservedMediaInput6() {} 218 void BMediaInput::_ReservedMediaInput7() {} 219 void BMediaInput::_ReservedMediaInput8() {} 220 void BMediaInput::_ReservedMediaInput9() {} 221 void BMediaInput::_ReservedMediaInput10() {} 222 223 224 BMediaOutput::BMediaOutput(const char* name) 225 : 226 BMediaConnection(B_MEDIA_OUTPUT, name), 227 fBufferGroup(NULL) 228 { 229 } 230 231 232 BMediaOutput::~BMediaOutput() 233 { 234 CALLED(); 235 } 236 237 238 status_t 239 BMediaOutput::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 250 void 251 BMediaOutput::Connected(const media_format& format) 252 { 253 BMediaConnection::Connected(format); 254 } 255 256 257 void 258 BMediaOutput::Disconnected() 259 { 260 BMediaConnection::Disconnected(); 261 } 262 263 264 bool 265 BMediaOutput::_IsEnabled() const 266 { 267 CALLED(); 268 269 return fEnabled; 270 } 271 272 273 void 274 BMediaOutput::_SetEnabled(bool enabled) 275 { 276 fEnabled = enabled; 277 } 278 279 280 void BMediaOutput::_ReservedMediaOutput0() {} 281 void BMediaOutput::_ReservedMediaOutput1() {} 282 void BMediaOutput::_ReservedMediaOutput2() {} 283 void BMediaOutput::_ReservedMediaOutput3() {} 284 void BMediaOutput::_ReservedMediaOutput4() {} 285 void BMediaOutput::_ReservedMediaOutput5() {} 286 void BMediaOutput::_ReservedMediaOutput6() {} 287 void BMediaOutput::_ReservedMediaOutput7() {} 288 void BMediaOutput::_ReservedMediaOutput8() {} 289 void BMediaOutput::_ReservedMediaOutput9() {} 290 void BMediaOutput::_ReservedMediaOutput10() {} 291