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