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