1/*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions, and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32// ConnectionInfoView.cpp
33
34#include "ConnectionInfoView.h"
35// InfoView
36#include "InfoWindowManager.h"
37// Support
38#include "MediaIcon.h"
39#include "MediaString.h"
40// NodeManager
41#include "Connection.h"
42
43// MediaKit
44#include <MediaDefs.h>
45
46__USE_CORTEX_NAMESPACE
47
48#include <Debug.h>
49#define D_METHOD(x) //PRINT (x)
50#define D_MESSAGE(x) //PRINT (x)
51
52// -------------------------------------------------------- //
53// *** ctor/dtor (public)
54// -------------------------------------------------------- //
55
56ConnectionInfoView::ConnectionInfoView(
57	const Connection &connection)
58	: InfoView("Connection", "", 0),
59	  m_source(connection.source()),
60	  m_destination(connection.destination())
61{
62	D_METHOD(("ConnectionInfoView::ConnectionInfoView()\n"));
63
64	setSideBarWidth(be_plain_font->StringWidth(" Destination ")
65					+ 2 * InfoView::M_H_MARGIN);
66	media_input input;
67	media_output output;
68	if (connection.getOutput(&output) == B_OK) {
69		// add "Source" field
70		BString s;
71		s << output.name;
72		if (s.Length() > 0)
73			s << " ";
74		s << "(" << MediaString::getStringFor(output.source) << ")";
75		addField("Source", s);
76	}
77	if (connection.getInput(&input) == B_OK) {
78		// add "Destination" field
79		BString s;
80		s << input.name;
81		if (s.Length() > 0)
82			s << " ";
83		s << "(" << MediaString::getStringFor(input.destination) << ")";
84		addField("Destination", s);
85	}
86
87	// add a separator field
88	addField("", "");
89
90	// add "Media Type" field
91	addField("Media Type", MediaString::getStringFor(connection.format().type));
92
93	// add the format fields
94	_addFormatFields(connection.format());
95}
96
97ConnectionInfoView::~ConnectionInfoView()
98{
99	D_METHOD(("ConnectionInfoView::~ConnectionInfoView()\n"));
100}
101
102// -------------------------------------------------------- //
103// *** internal operations (private)
104// -------------------------------------------------------- //
105
106void ConnectionInfoView::_addFormatFields(
107	const media_format &format) {
108	D_METHOD(("ConnectionInfoView::_addFormatFields()\n"));
109
110	switch (format.type) {
111		case B_MEDIA_RAW_AUDIO: {
112			// adjust view properties
113			setSideBarWidth(be_plain_font->StringWidth(" Sample Rate ") + 2 * InfoView::M_H_MARGIN);
114			BString s;
115			// add "Format" field
116			s = MediaString::forAudioFormat(format.u.raw_audio.format,
117											format.u.raw_audio.valid_bits);
118			addField("Format", s);
119			// add "Sample Rate" field
120			s = MediaString::forAudioFrameRate(format.u.raw_audio.frame_rate);
121			addField("Sample Rate", s);
122			// add "Channels" field
123			s = MediaString::forAudioChannelCount(format.u.raw_audio.channel_count);
124			addField("Channels", s);
125			// add "Channel Mask" field
126			s = MediaString::forAudioChannelMask(format.u.raw_audio.channel_mask);
127			addField("Channel Mask", s);
128			// add "Matrix Mask" field
129			s = MediaString::forAudioMatrixMask(format.u.raw_audio.matrix_mask);
130			addField("Matrix Mask", s);
131			// add the "Byte Order" field
132			s = MediaString::forAudioByteOrder(format.u.raw_audio.byte_order);
133			addField("Byte Order", s);
134			// add the "Buffer Size" field
135			s = MediaString::forAudioBufferSize(format.u.raw_audio.buffer_size);
136			addField("Buffer Size", s);
137			break;
138		}
139		case B_MEDIA_RAW_VIDEO: {
140			// adjust view properties
141			setSideBarWidth(be_plain_font->StringWidth(" Video Data Between ") + 2 * InfoView::M_H_MARGIN);
142			BString s;
143			// add the "Format" field
144			s = MediaString::forVideoFormat(format.u.raw_video.display.format);
145			addField("Format", s);
146			// add the "Resolution" field
147			s = MediaString::forVideoResolution(format.u.raw_video.display.line_width,
148												format.u.raw_video.display.line_count);
149			addField("Resolution", s);
150			// add the "Field Rate" field
151			s = MediaString::forVideoFieldRate(format.u.raw_video.field_rate,
152											   format.u.raw_video.interlace);
153			addField("Field Rate", s);
154			// add the "Orientation" field
155			s = MediaString::forVideoOrientation(format.u.raw_video.orientation);
156			addField("Orientation", s);
157			// add the "Aspect Ratio" field
158			s = MediaString::forVideoAspectRatio(format.u.raw_video.pixel_width_aspect,
159												 format.u.raw_video.pixel_height_aspect);
160			addField("Aspect Ratio", s);
161			// add the "Active Lines" field
162			s = MediaString::forVideoActiveLines(format.u.raw_video.first_active,
163												 format.u.raw_video.last_active);
164			addField("Active Lines", s);
165			// add the "Offset" field
166			s = MediaString::forVideoOffset(format.u.raw_video.display.pixel_offset,
167											format.u.raw_video.display.line_offset);
168			addField("Offset", s);
169			break;
170		}
171		case B_MEDIA_ENCODED_AUDIO: {
172			// adjust view properties
173			setSideBarWidth(be_plain_font->StringWidth(" Frame Size ") + 2 * InfoView::M_H_MARGIN);
174			BString s;
175			// add the "Bit Rate" field
176			s = MediaString::forAudioBitRate(format.u.encoded_audio.bit_rate);
177			addField("Bit Rate", s);
178			// add the "Frame Size" field
179			s = MediaString::forAudioFrameSize(format.u.encoded_audio.frame_size);
180			addField("Frame Size", s);
181			break;
182		}
183		case B_MEDIA_ENCODED_VIDEO: {
184			// adjust view properties
185			setSideBarWidth(be_plain_font->StringWidth(" Frame Size ") + 2 * InfoView::M_H_MARGIN);
186			BString s;
187			// add the "Bit Rate" field
188			s = MediaString::forVideoBitRate(format.u.encoded_video.avg_bit_rate,
189											 format.u.encoded_video.max_bit_rate);
190			addField("Bit Rate", s);
191			// add the "Frame Size" field
192			s = MediaString::forVideoFrameSize(format.u.encoded_video.frame_size);
193			addField("Frame Size", s);
194			// add the "History" field
195			s = MediaString::forVideoHistory(format.u.encoded_video.forward_history,
196											 format.u.encoded_video.backward_history);
197			addField("History", s);
198			break;
199		}
200		case B_MEDIA_MULTISTREAM: {
201			// adjust view properties
202			setSideBarWidth(be_plain_font->StringWidth(" Chunk Size ") + 2 * InfoView::M_H_MARGIN);
203			BString s;
204			// add the "Format" field
205			s = MediaString::forMultistreamFormat(format.u.multistream.format);
206			addField("Format", s);
207			// add the "Bit Rate" field
208			s = MediaString::forMultistreamBitRate(format.u.multistream.avg_bit_rate,
209												   format.u.multistream.max_bit_rate);
210			addField("Bit Rate", s);
211			// add the "Chunk Size" field
212			s = MediaString::forMultistreamChunkSize(format.u.multistream.avg_chunk_size,
213													 format.u.multistream.max_chunk_size);
214			addField("Chunk Size", s);
215			// add the "Flags" field
216			s = MediaString::forMultistreamFlags(format.u.multistream.flags);
217			addField("Flags", s);
218			break;
219		}
220		default: {
221			// add no fields
222		}
223	}
224}
225
226// -------------------------------------------------------- //
227// *** BView implementation (public)
228// -------------------------------------------------------- //
229
230void ConnectionInfoView::DetachedFromWindow() {
231	D_METHOD(("ConnectionInfoView::DetachedFromWindow()\n"));
232
233	InfoWindowManager *manager = InfoWindowManager::Instance();
234	if (manager) {
235		BMessage message(InfoWindowManager::M_CONNECTION_WINDOW_CLOSED);
236		message.AddInt32("source_port", m_source.port);
237		message.AddInt32("source_id", m_source.id);
238		message.AddInt32("destination_port", m_destination.port);
239		message.AddInt32("destination_id", m_destination.id);
240		manager->PostMessage(&message);
241	}
242}
243
244// END -- ConnectionInfoView.cpp --
245