17561d9acSDario Casalinuovo /*
27561d9acSDario Casalinuovo * Copyright 2015, Dario Casalinuovo. All rights reserved.
37561d9acSDario Casalinuovo * Distributed under the terms of the MIT License.
47561d9acSDario Casalinuovo */
57561d9acSDario Casalinuovo
67561d9acSDario Casalinuovo #include <MediaConnection.h>
77561d9acSDario Casalinuovo
8852b6295SBarrett17 #include <string.h>
9852b6295SBarrett17
107561d9acSDario Casalinuovo #include "MediaClientNode.h"
117561d9acSDario Casalinuovo
12*b84955d4SBarrett17 #include "MediaDebug.h"
137561d9acSDario Casalinuovo
147561d9acSDario Casalinuovo
BMediaConnection(media_connection_kinds kinds,const char * name)151c15261fSBarrett17 BMediaConnection::BMediaConnection(media_connection_kinds kinds,
161c15261fSBarrett17 const char* name)
177561d9acSDario Casalinuovo :
187561d9acSDario Casalinuovo fOwner(NULL),
19ff56eda5SBarrett17 fBind(NULL)
207561d9acSDario Casalinuovo {
217561d9acSDario Casalinuovo CALLED();
227561d9acSDario Casalinuovo
237561d9acSDario Casalinuovo fConnection.kinds = kinds;
240cc5ecb8SDario Casalinuovo fConnection.id = -1;
257561d9acSDario Casalinuovo //fConnection.client = media_client::null;
261c15261fSBarrett17 if (name != NULL)
271c15261fSBarrett17 strcpy(fConnection.name, name);
287561d9acSDario Casalinuovo }
297561d9acSDario Casalinuovo
307561d9acSDario Casalinuovo
~BMediaConnection()317561d9acSDario Casalinuovo BMediaConnection::~BMediaConnection()
327561d9acSDario Casalinuovo {
337561d9acSDario Casalinuovo CALLED();
347561d9acSDario Casalinuovo
357561d9acSDario Casalinuovo }
367561d9acSDario Casalinuovo
377561d9acSDario Casalinuovo
387561d9acSDario Casalinuovo const media_connection&
Connection() const397561d9acSDario Casalinuovo BMediaConnection::Connection() const
407561d9acSDario Casalinuovo {
417561d9acSDario Casalinuovo return fConnection;
427561d9acSDario Casalinuovo }
437561d9acSDario Casalinuovo
447561d9acSDario Casalinuovo
45991d9dbfSDario Casalinuovo BMediaClient*
Client() const46991d9dbfSDario Casalinuovo BMediaConnection::Client() const
47991d9dbfSDario Casalinuovo {
48991d9dbfSDario Casalinuovo return fOwner;
49991d9dbfSDario Casalinuovo }
50991d9dbfSDario Casalinuovo
51991d9dbfSDario Casalinuovo
521c15261fSBarrett17 const char*
Name() const531c15261fSBarrett17 BMediaConnection::Name() const
541c15261fSBarrett17 {
551c15261fSBarrett17 return fConnection.name;
561c15261fSBarrett17 }
571c15261fSBarrett17
581c15261fSBarrett17
597561d9acSDario Casalinuovo bool
HasBinding() const607561d9acSDario Casalinuovo BMediaConnection::HasBinding() const
617561d9acSDario Casalinuovo {
627561d9acSDario Casalinuovo CALLED();
637561d9acSDario Casalinuovo
647561d9acSDario Casalinuovo return fBind != NULL;
657561d9acSDario Casalinuovo }
667561d9acSDario Casalinuovo
677561d9acSDario Casalinuovo
687561d9acSDario Casalinuovo BMediaConnection*
Binding() const697561d9acSDario Casalinuovo BMediaConnection::Binding() const
707561d9acSDario Casalinuovo {
717561d9acSDario Casalinuovo CALLED();
727561d9acSDario Casalinuovo
737561d9acSDario Casalinuovo return fBind;
747561d9acSDario Casalinuovo }
757561d9acSDario Casalinuovo
767561d9acSDario Casalinuovo
777561d9acSDario Casalinuovo bool
IsConnected() const787561d9acSDario Casalinuovo BMediaConnection::IsConnected() const
797561d9acSDario Casalinuovo {
807561d9acSDario Casalinuovo CALLED();
817561d9acSDario Casalinuovo
827561d9acSDario Casalinuovo return fConnected;
837561d9acSDario Casalinuovo }
847561d9acSDario Casalinuovo
857561d9acSDario Casalinuovo
867561d9acSDario Casalinuovo status_t
Disconnect()877561d9acSDario Casalinuovo BMediaConnection::Disconnect()
887561d9acSDario Casalinuovo {
897561d9acSDario Casalinuovo CALLED();
907561d9acSDario Casalinuovo
91ff56eda5SBarrett17 return fOwner->_DisconnectConnection(this);
927561d9acSDario Casalinuovo }
937561d9acSDario Casalinuovo
947561d9acSDario Casalinuovo
957561d9acSDario Casalinuovo status_t
Release()967561d9acSDario Casalinuovo BMediaConnection::Release()
977561d9acSDario Casalinuovo {
987561d9acSDario Casalinuovo CALLED();
997561d9acSDario Casalinuovo
100991d9dbfSDario Casalinuovo status_t ret = fOwner->_ReleaseConnection(this);
101991d9dbfSDario Casalinuovo if (ret != B_OK)
102991d9dbfSDario Casalinuovo return ret;
103991d9dbfSDario Casalinuovo
104991d9dbfSDario Casalinuovo delete this;
105991d9dbfSDario Casalinuovo return ret;
1067561d9acSDario Casalinuovo }
1077561d9acSDario Casalinuovo
1087561d9acSDario Casalinuovo
1097561d9acSDario Casalinuovo void
Connected(const media_format & format)1107561d9acSDario Casalinuovo BMediaConnection::Connected(const media_format& format)
1117561d9acSDario Casalinuovo {
1126dc7d854SBarrett17 // Update the status of our connection format.
1136dc7d854SBarrett17 fConnection.format = format;
1146dc7d854SBarrett17
1157561d9acSDario Casalinuovo fConnected = true;
1167561d9acSDario Casalinuovo }
1177561d9acSDario Casalinuovo
1187561d9acSDario Casalinuovo
1197561d9acSDario Casalinuovo void
Disconnected()1207561d9acSDario Casalinuovo BMediaConnection::Disconnected()
1217561d9acSDario Casalinuovo {
1226072c6f1SBarrett17 CALLED();
1236072c6f1SBarrett17
1247561d9acSDario Casalinuovo fConnected = false;
1257561d9acSDario Casalinuovo }
1267561d9acSDario Casalinuovo
1277561d9acSDario Casalinuovo
1287561d9acSDario Casalinuovo void
_ConnectionRegistered(BMediaClient * owner,media_connection_id id)129d64dd7beSDario Casalinuovo BMediaConnection::_ConnectionRegistered(BMediaClient* owner,
1307561d9acSDario Casalinuovo media_connection_id id)
1317561d9acSDario Casalinuovo {
1327561d9acSDario Casalinuovo fOwner = owner;
1337561d9acSDario Casalinuovo fConnection.id = id;
1347561d9acSDario Casalinuovo fConnection.client = fOwner->Client();
1357561d9acSDario Casalinuovo
1367561d9acSDario Casalinuovo if (fConnection.IsOutput()) {
1377561d9acSDario Casalinuovo fConnection.source.port = fOwner->fNode->ControlPort();
1387561d9acSDario Casalinuovo fConnection.source.id = fConnection.id;
1397561d9acSDario Casalinuovo
1407561d9acSDario Casalinuovo fConnection.destination = media_destination::null;
1417561d9acSDario Casalinuovo } else {
1427561d9acSDario Casalinuovo fConnection.destination.port = fOwner->fNode->ControlPort();
1437561d9acSDario Casalinuovo fConnection.destination.id = fConnection.id;
1447561d9acSDario Casalinuovo
1457561d9acSDario Casalinuovo fConnection.source = media_source::null;
1467561d9acSDario Casalinuovo }
1477561d9acSDario Casalinuovo }
1487561d9acSDario Casalinuovo
1497561d9acSDario Casalinuovo
1507561d9acSDario Casalinuovo const media_source&
_Source() const151d64dd7beSDario Casalinuovo BMediaConnection::_Source() const
1527561d9acSDario Casalinuovo {
15383bcc405SBarrett17 return fConnection.source;
1547561d9acSDario Casalinuovo }
1557561d9acSDario Casalinuovo
1567561d9acSDario Casalinuovo
1577561d9acSDario Casalinuovo const media_destination&
_Destination() const158d64dd7beSDario Casalinuovo BMediaConnection::_Destination() const
1597561d9acSDario Casalinuovo {
16083bcc405SBarrett17 return fConnection.destination;
1617561d9acSDario Casalinuovo }
1627561d9acSDario Casalinuovo
1637561d9acSDario Casalinuovo
_ReservedMediaConnection0()1647561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection0() {}
_ReservedMediaConnection1()1657561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection1() {}
_ReservedMediaConnection2()1667561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection2() {}
_ReservedMediaConnection3()1677561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection3() {}
_ReservedMediaConnection4()1687561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection4() {}
_ReservedMediaConnection5()1697561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection5() {}
_ReservedMediaConnection6()1707561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection6() {}
_ReservedMediaConnection7()1717561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection7() {}
_ReservedMediaConnection8()1727561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection8() {}
_ReservedMediaConnection9()1737561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection9() {}
_ReservedMediaConnection10()1747561d9acSDario Casalinuovo void BMediaConnection::_ReservedMediaConnection10() {}
1757561d9acSDario Casalinuovo
1767561d9acSDario Casalinuovo
BMediaInput(const char * name)1771c15261fSBarrett17 BMediaInput::BMediaInput(const char* name)
1787561d9acSDario Casalinuovo :
1791c15261fSBarrett17 BMediaConnection(B_MEDIA_INPUT, name)
1807561d9acSDario Casalinuovo {
1817561d9acSDario Casalinuovo }
1827561d9acSDario Casalinuovo
1837561d9acSDario Casalinuovo
~BMediaInput()1840844ddf4SDario Casalinuovo BMediaInput::~BMediaInput()
1850844ddf4SDario Casalinuovo {
1860844ddf4SDario Casalinuovo CALLED();
1870844ddf4SDario Casalinuovo }
1880844ddf4SDario Casalinuovo
1890844ddf4SDario Casalinuovo
1907561d9acSDario Casalinuovo void
HandleBuffer(BBuffer * buffer)1915854fc4aSDario Casalinuovo BMediaInput::HandleBuffer(BBuffer* buffer)
1927561d9acSDario Casalinuovo {
1937561d9acSDario Casalinuovo CALLED();
194444d8ec0SBarrett17 }
1957561d9acSDario Casalinuovo
196444d8ec0SBarrett17
197444d8ec0SBarrett17 void
Connected(const media_format & format)198444d8ec0SBarrett17 BMediaInput::Connected(const media_format& format)
199444d8ec0SBarrett17 {
200444d8ec0SBarrett17 BMediaConnection::Connected(format);
201444d8ec0SBarrett17 }
202444d8ec0SBarrett17
203444d8ec0SBarrett17
204444d8ec0SBarrett17 void
Disconnected()205444d8ec0SBarrett17 BMediaInput::Disconnected()
206444d8ec0SBarrett17 {
207444d8ec0SBarrett17 BMediaConnection::Disconnected();
2087561d9acSDario Casalinuovo }
2097561d9acSDario Casalinuovo
2107561d9acSDario Casalinuovo
_ReservedMediaInput0()2117561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput0() {}
_ReservedMediaInput1()2127561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput1() {}
_ReservedMediaInput2()2137561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput2() {}
_ReservedMediaInput3()2147561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput3() {}
_ReservedMediaInput4()2157561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput4() {}
_ReservedMediaInput5()2167561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput5() {}
_ReservedMediaInput6()2177561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput6() {}
_ReservedMediaInput7()2187561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput7() {}
_ReservedMediaInput8()2197561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput8() {}
_ReservedMediaInput9()2207561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput9() {}
_ReservedMediaInput10()2217561d9acSDario Casalinuovo void BMediaInput::_ReservedMediaInput10() {}
2227561d9acSDario Casalinuovo
2237561d9acSDario Casalinuovo
BMediaOutput(const char * name)2241c15261fSBarrett17 BMediaOutput::BMediaOutput(const char* name)
2257561d9acSDario Casalinuovo :
2261c15261fSBarrett17 BMediaConnection(B_MEDIA_OUTPUT, name),
227ff56eda5SBarrett17 fBufferGroup(NULL)
2287561d9acSDario Casalinuovo {
2297561d9acSDario Casalinuovo }
2307561d9acSDario Casalinuovo
2317561d9acSDario Casalinuovo
~BMediaOutput()2320844ddf4SDario Casalinuovo BMediaOutput::~BMediaOutput()
2330844ddf4SDario Casalinuovo {
2340844ddf4SDario Casalinuovo CALLED();
2350844ddf4SDario Casalinuovo }
2360844ddf4SDario Casalinuovo
2370844ddf4SDario Casalinuovo
2387561d9acSDario Casalinuovo status_t
SendBuffer(BBuffer * buffer)2397561d9acSDario Casalinuovo BMediaOutput::SendBuffer(BBuffer* buffer)
2407561d9acSDario Casalinuovo {
2417561d9acSDario Casalinuovo CALLED();
2427561d9acSDario Casalinuovo
2435854fc4aSDario Casalinuovo if (!IsConnected())
2445854fc4aSDario Casalinuovo return B_ERROR;
2455854fc4aSDario Casalinuovo
2467561d9acSDario Casalinuovo return fOwner->fNode->SendBuffer(buffer, this);
2477561d9acSDario Casalinuovo }
2487561d9acSDario Casalinuovo
2497561d9acSDario Casalinuovo
250ff56eda5SBarrett17 void
Connected(const media_format & format)251444d8ec0SBarrett17 BMediaOutput::Connected(const media_format& format)
252444d8ec0SBarrett17 {
253444d8ec0SBarrett17 BMediaConnection::Connected(format);
254444d8ec0SBarrett17 }
255444d8ec0SBarrett17
256444d8ec0SBarrett17
257444d8ec0SBarrett17 void
Disconnected()258ff56eda5SBarrett17 BMediaOutput::Disconnected()
259ff56eda5SBarrett17 {
260ff56eda5SBarrett17 BMediaConnection::Disconnected();
261ff56eda5SBarrett17 }
262ff56eda5SBarrett17
263ff56eda5SBarrett17
2646dc7d854SBarrett17 bool
_IsEnabled() const2656dc7d854SBarrett17 BMediaOutput::_IsEnabled() const
2667561d9acSDario Casalinuovo {
2676dc7d854SBarrett17 CALLED();
2686dc7d854SBarrett17
2696dc7d854SBarrett17 return fEnabled;
2706dc7d854SBarrett17 }
2716dc7d854SBarrett17
2726dc7d854SBarrett17
2736dc7d854SBarrett17 void
_SetEnabled(bool enabled)2746dc7d854SBarrett17 BMediaOutput::_SetEnabled(bool enabled)
2756dc7d854SBarrett17 {
2766dc7d854SBarrett17 fEnabled = enabled;
2777561d9acSDario Casalinuovo }
2787561d9acSDario Casalinuovo
2797561d9acSDario Casalinuovo
_ReservedMediaOutput0()2807561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput0() {}
_ReservedMediaOutput1()2817561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput1() {}
_ReservedMediaOutput2()2827561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput2() {}
_ReservedMediaOutput3()2837561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput3() {}
_ReservedMediaOutput4()2847561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput4() {}
_ReservedMediaOutput5()2857561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput5() {}
_ReservedMediaOutput6()2867561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput6() {}
_ReservedMediaOutput7()2877561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput7() {}
_ReservedMediaOutput8()2887561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput8() {}
_ReservedMediaOutput9()2897561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput9() {}
_ReservedMediaOutput10()2907561d9acSDario Casalinuovo void BMediaOutput::_ReservedMediaOutput10() {}
291