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// EndPointInfoView.cpp
33a0795c6fSMarcus Overhagen
34a0795c6fSMarcus Overhagen#include "EndPointInfoView.h"
35a0795c6fSMarcus Overhagen// InfoView
36a0795c6fSMarcus Overhagen#include "InfoWindowManager.h"
37a0795c6fSMarcus Overhagen// Support
38a0795c6fSMarcus Overhagen#include "MediaIcon.h"
39a0795c6fSMarcus Overhagen#include "MediaString.h"
40a0795c6fSMarcus Overhagen
41a0795c6fSMarcus Overhagen__USE_CORTEX_NAMESPACE
42a0795c6fSMarcus Overhagen
43a0795c6fSMarcus Overhagen#include <Debug.h>
44a0795c6fSMarcus Overhagen#define D_METHOD(x) //PRINT (x)
45a0795c6fSMarcus Overhagen
46a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
47a0795c6fSMarcus Overhagen// *** ctor/dtor (public)
48a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
49a0795c6fSMarcus Overhagen
50a0795c6fSMarcus OverhagenEndPointInfoView::EndPointInfoView(
51a0795c6fSMarcus Overhagen	const media_input &input)
527974d3dcSStephan Aßmus	: InfoView(input.name, "Media input", 0),
53a0795c6fSMarcus Overhagen	  m_output(false),
54a0795c6fSMarcus Overhagen	  m_port(input.destination.port),
55a0795c6fSMarcus Overhagen	  m_id(input.destination.id) {
56a0795c6fSMarcus Overhagen	D_METHOD(("EndPointInfoView::EndPointInfoView(input)\n"));
57a0795c6fSMarcus Overhagen
58a0795c6fSMarcus Overhagen	setSideBarWidth(be_plain_font->StringWidth(" Destination ")
59a0795c6fSMarcus Overhagen					+ 2 * InfoView::M_H_MARGIN);
60a0795c6fSMarcus Overhagen
61a0795c6fSMarcus Overhagen	// add "Source" field
62a0795c6fSMarcus Overhagen	addField("Source", MediaString::getStringFor(input.source));
63a0795c6fSMarcus Overhagen
64a0795c6fSMarcus Overhagen	// add "Destination" field
65a0795c6fSMarcus Overhagen	addField("Destination", MediaString::getStringFor(input.destination));
66a0795c6fSMarcus Overhagen
67a0795c6fSMarcus Overhagen	// add a separator field
68a0795c6fSMarcus Overhagen	addField("", "");
69a0795c6fSMarcus Overhagen
70a0795c6fSMarcus Overhagen	// add "Media Type" field
717974d3dcSStephan Aßmus	addField("Media type", MediaString::getStringFor(input.format.type));
72a0795c6fSMarcus Overhagen
73a0795c6fSMarcus Overhagen	_addFormatFields(input.format);
74a0795c6fSMarcus Overhagen}
75a0795c6fSMarcus Overhagen
76a0795c6fSMarcus OverhagenEndPointInfoView::EndPointInfoView(
77a0795c6fSMarcus Overhagen	const media_output &output)
787974d3dcSStephan Aßmus	: InfoView(output.name, "Media output", 0),
79a0795c6fSMarcus Overhagen	  m_output(true),
80a0795c6fSMarcus Overhagen	  m_port(output.source.port),
81a0795c6fSMarcus Overhagen	  m_id(output.source.id) {
82a0795c6fSMarcus Overhagen	D_METHOD(("EndPointInfoView::EndPointInfoView(output)\n"));
83a0795c6fSMarcus Overhagen
84a0795c6fSMarcus Overhagen	setSideBarWidth(be_plain_font->StringWidth(" Destination ")
85a0795c6fSMarcus Overhagen					+ 2 * InfoView::M_H_MARGIN);
86a0795c6fSMarcus Overhagen
87a0795c6fSMarcus Overhagen	// add "Source" field
88a0795c6fSMarcus Overhagen	addField("Source", MediaString::getStringFor(output.source));
89a0795c6fSMarcus Overhagen
90a0795c6fSMarcus Overhagen	// add "Destination" field
91a0795c6fSMarcus Overhagen	addField("Destination", MediaString::getStringFor(output.destination));
92a0795c6fSMarcus Overhagen
93a0795c6fSMarcus Overhagen	// add a separator field
94a0795c6fSMarcus Overhagen	addField("", "");
95a0795c6fSMarcus Overhagen
96a0795c6fSMarcus Overhagen	// add "Media Type" field
977974d3dcSStephan Aßmus	addField("Media type", MediaString::getStringFor(output.format.type));
98a0795c6fSMarcus Overhagen
99a0795c6fSMarcus Overhagen	_addFormatFields(output.format);
100a0795c6fSMarcus Overhagen}
101a0795c6fSMarcus Overhagen
102a0795c6fSMarcus OverhagenEndPointInfoView::~EndPointInfoView()
103a0795c6fSMarcus Overhagen{
104a0795c6fSMarcus Overhagen	D_METHOD(("EndPointInfoView::~EndPointInfoView()\n"));
105a0795c6fSMarcus Overhagen}
106a0795c6fSMarcus Overhagen
107a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
108a0795c6fSMarcus Overhagen// *** BView implementation (public)
109a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
110a0795c6fSMarcus Overhagen
111a0795c6fSMarcus Overhagenvoid EndPointInfoView::DetachedFromWindow() {
112a0795c6fSMarcus Overhagen	D_METHOD(("EndPointInfoView::DetachedFromWindow()\n"));
113a0795c6fSMarcus Overhagen
114a0795c6fSMarcus Overhagen	InfoWindowManager *manager = InfoWindowManager::Instance();
115a0795c6fSMarcus Overhagen	if (manager) {
116a0795c6fSMarcus Overhagen		if (m_output) {
117a0795c6fSMarcus Overhagen			BMessage message(InfoWindowManager::M_OUTPUT_WINDOW_CLOSED);
118a0795c6fSMarcus Overhagen			message.AddInt32("source_port", m_port);
119a0795c6fSMarcus Overhagen			message.AddInt32("source_id", m_id);
120a0795c6fSMarcus Overhagen			manager->PostMessage(&message);
121a0795c6fSMarcus Overhagen		}
122a0795c6fSMarcus Overhagen		else {
123a0795c6fSMarcus Overhagen			BMessage message(InfoWindowManager::M_INPUT_WINDOW_CLOSED);
124a0795c6fSMarcus Overhagen			message.AddInt32("destination_port", m_port);
125a0795c6fSMarcus Overhagen			message.AddInt32("destination_id", m_id);
126a0795c6fSMarcus Overhagen			manager->PostMessage(&message);
127a0795c6fSMarcus Overhagen		}
128a0795c6fSMarcus Overhagen	}
129a0795c6fSMarcus Overhagen}
130a0795c6fSMarcus Overhagen
131a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
132a0795c6fSMarcus Overhagen// *** internal operations (private)
133a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
134a0795c6fSMarcus Overhagen
135a0795c6fSMarcus Overhagenvoid EndPointInfoView::_addFormatFields(
136a0795c6fSMarcus Overhagen	const media_format &format)
137a0795c6fSMarcus Overhagen{
138a0795c6fSMarcus Overhagen	D_METHOD(("EndPointInfoView::_addFormatFields()\n"));
139a0795c6fSMarcus Overhagen
140a0795c6fSMarcus Overhagen	switch (format.type) {
141a0795c6fSMarcus Overhagen		case B_MEDIA_RAW_AUDIO: {
142a0795c6fSMarcus Overhagen			// adjust view properties
143a0795c6fSMarcus Overhagen			setSideBarWidth(be_plain_font->StringWidth(" Sample Rate ") + 2 * InfoView::M_H_MARGIN);
144a0795c6fSMarcus Overhagen			BString s;
145a0795c6fSMarcus Overhagen			// add "Format" field
146a0795c6fSMarcus Overhagen			s = MediaString::forAudioFormat(format.u.raw_audio.format,
147a0795c6fSMarcus Overhagen											format.u.raw_audio.valid_bits);
148a0795c6fSMarcus Overhagen			addField("Format", s);
149a0795c6fSMarcus Overhagen			// add "Sample Rate" field
150a0795c6fSMarcus Overhagen			s = MediaString::forAudioFrameRate(format.u.raw_audio.frame_rate);
1517974d3dcSStephan Aßmus			addField("Sample rate", s);
152a0795c6fSMarcus Overhagen			// add "Channels" field
153a0795c6fSMarcus Overhagen			s = MediaString::forAudioChannelCount(format.u.raw_audio.channel_count);
154a0795c6fSMarcus Overhagen			addField("Channels", s);
155a0795c6fSMarcus Overhagen			// add "Channel Mask" field
156a0795c6fSMarcus Overhagen			s = MediaString::forAudioChannelMask(format.u.raw_audio.channel_mask);
1577974d3dcSStephan Aßmus			addField("Channel mask", s);
158a0795c6fSMarcus Overhagen			// add "Matrix Mask" field
159a0795c6fSMarcus Overhagen			s = MediaString::forAudioMatrixMask(format.u.raw_audio.matrix_mask);
1607974d3dcSStephan Aßmus			addField("Matrix mask", s);
161a0795c6fSMarcus Overhagen			// add the "Byte Order" field
162a0795c6fSMarcus Overhagen			s = MediaString::forAudioByteOrder(format.u.raw_audio.byte_order);
1637974d3dcSStephan Aßmus			addField("Byte order", s);
164a0795c6fSMarcus Overhagen			// add the "Buffer Size" field
165a0795c6fSMarcus Overhagen			s = MediaString::forAudioBufferSize(format.u.raw_audio.buffer_size);
1667974d3dcSStephan Aßmus			addField("Buffer size", s);
167a0795c6fSMarcus Overhagen			break;
168a0795c6fSMarcus Overhagen		}
169a0795c6fSMarcus Overhagen		case B_MEDIA_RAW_VIDEO: {
170a0795c6fSMarcus Overhagen			// adjust view properties
171a0795c6fSMarcus Overhagen			setSideBarWidth(be_plain_font->StringWidth(" Video Data Between ") + 2 * InfoView::M_H_MARGIN);
172a0795c6fSMarcus Overhagen			BString s;
173a0795c6fSMarcus Overhagen			// add the "Format" field
174a0795c6fSMarcus Overhagen			s = MediaString::forVideoFormat(format.u.raw_video.display.format);
175a0795c6fSMarcus Overhagen			addField("Format", s);
176a0795c6fSMarcus Overhagen			// add the "Resolution" field
177a0795c6fSMarcus Overhagen			s = MediaString::forVideoResolution(format.u.raw_video.display.line_width,
178a0795c6fSMarcus Overhagen												format.u.raw_video.display.line_count);
179a0795c6fSMarcus Overhagen			addField("Resolution", s);
180a0795c6fSMarcus Overhagen			// add the "Field Rate" field
181a0795c6fSMarcus Overhagen			s = MediaString::forVideoFieldRate(format.u.raw_video.field_rate,
182a0795c6fSMarcus Overhagen											   format.u.raw_video.interlace);
1837974d3dcSStephan Aßmus			addField("Field rate", s);
184a0795c6fSMarcus Overhagen			// add the "Orientation" field
185a0795c6fSMarcus Overhagen			s = MediaString::forVideoOrientation(format.u.raw_video.orientation);
186a0795c6fSMarcus Overhagen			addField("Orientation", s);
187a0795c6fSMarcus Overhagen			// add the "Aspect Ratio" field
188a0795c6fSMarcus Overhagen			s = MediaString::forVideoAspectRatio(format.u.raw_video.pixel_width_aspect,
189a0795c6fSMarcus Overhagen												 format.u.raw_video.pixel_height_aspect);
1907974d3dcSStephan Aßmus			addField("Aspect ratio", s);
191a0795c6fSMarcus Overhagen			// add the "Active Lines" field
192a0795c6fSMarcus Overhagen			s = MediaString::forVideoActiveLines(format.u.raw_video.first_active,
193a0795c6fSMarcus Overhagen												 format.u.raw_video.last_active);
1947974d3dcSStephan Aßmus			addField("Active lines", s);
195a0795c6fSMarcus Overhagen			// add the "Offset" field
196a0795c6fSMarcus Overhagen			s = MediaString::forVideoOffset(format.u.raw_video.display.pixel_offset,
197a0795c6fSMarcus Overhagen											format.u.raw_video.display.line_offset);
198a0795c6fSMarcus Overhagen			addField("Offset", s);
199a0795c6fSMarcus Overhagen			break;
200a0795c6fSMarcus Overhagen		}
201a0795c6fSMarcus Overhagen		case B_MEDIA_ENCODED_AUDIO: {
202a0795c6fSMarcus Overhagen			// adjust view properties
203a0795c6fSMarcus Overhagen			setSideBarWidth(be_plain_font->StringWidth(" Frame Size ") + 2 * InfoView::M_H_MARGIN);
204a0795c6fSMarcus Overhagen			BString s;
205a0795c6fSMarcus Overhagen			// add the "Bit Rate" field
206a0795c6fSMarcus Overhagen			s = MediaString::forAudioBitRate(format.u.encoded_audio.bit_rate);
2077974d3dcSStephan Aßmus			addField("Bit rate", s);
208a0795c6fSMarcus Overhagen			// add the "Frame Size" field
209a0795c6fSMarcus Overhagen			s = MediaString::forAudioFrameSize(format.u.encoded_audio.frame_size);
2107974d3dcSStephan Aßmus			addField("Frame size", s);
211a0795c6fSMarcus Overhagen			break;
212a0795c6fSMarcus Overhagen		}
213a0795c6fSMarcus Overhagen		case B_MEDIA_ENCODED_VIDEO: {
214a0795c6fSMarcus Overhagen			// adjust view properties
215a0795c6fSMarcus Overhagen			setSideBarWidth(be_plain_font->StringWidth(" Frame Size ") + 2 * InfoView::M_H_MARGIN);
216a0795c6fSMarcus Overhagen			BString s;
217a0795c6fSMarcus Overhagen			// add the "Bit Rate" field
218a0795c6fSMarcus Overhagen			s = MediaString::forVideoBitRate(format.u.encoded_video.avg_bit_rate,
219a0795c6fSMarcus Overhagen											 format.u.encoded_video.max_bit_rate);
2207974d3dcSStephan Aßmus			addField("Bit rate", s);
221a0795c6fSMarcus Overhagen			// add the "Frame Size" field
222a0795c6fSMarcus Overhagen			s = MediaString::forVideoFrameSize(format.u.encoded_video.frame_size);
2237974d3dcSStephan Aßmus			addField("Frame size", s);
224a0795c6fSMarcus Overhagen			// add the "History" field
225a0795c6fSMarcus Overhagen			s = MediaString::forVideoHistory(format.u.encoded_video.forward_history,
226a0795c6fSMarcus Overhagen											 format.u.encoded_video.backward_history);
227a0795c6fSMarcus Overhagen			addField("History", s);
228a0795c6fSMarcus Overhagen			break;
229a0795c6fSMarcus Overhagen		}
230a0795c6fSMarcus Overhagen		case B_MEDIA_MULTISTREAM: {
231a0795c6fSMarcus Overhagen			// adjust view properties
232a0795c6fSMarcus Overhagen			setSideBarWidth(be_plain_font->StringWidth(" Chunk Size ") + 2 * InfoView::M_H_MARGIN);
233a0795c6fSMarcus Overhagen			BString s;
234a0795c6fSMarcus Overhagen			// add the "Format" field
235a0795c6fSMarcus Overhagen			s = MediaString::forMultistreamFormat(format.u.multistream.format);
236a0795c6fSMarcus Overhagen			addField("Format", s);
237a0795c6fSMarcus Overhagen			// add the "Bit Rate" field
238a0795c6fSMarcus Overhagen			s = MediaString::forMultistreamBitRate(format.u.multistream.avg_bit_rate,
239a0795c6fSMarcus Overhagen												   format.u.multistream.max_bit_rate);
2407974d3dcSStephan Aßmus			addField("Bit rate", s);
241a0795c6fSMarcus Overhagen			// add the "Chunk Size" field
242a0795c6fSMarcus Overhagen			s = MediaString::forMultistreamChunkSize(format.u.multistream.avg_chunk_size,
243a0795c6fSMarcus Overhagen													 format.u.multistream.max_chunk_size);
2447974d3dcSStephan Aßmus			addField("Chunk size", s);
245a0795c6fSMarcus Overhagen			// add the "Flags" field
246a0795c6fSMarcus Overhagen			s = MediaString::forMultistreamFlags(format.u.multistream.flags);
247a0795c6fSMarcus Overhagen			addField("Flags", s);
248a0795c6fSMarcus Overhagen			break;
249a0795c6fSMarcus Overhagen		}
250a0795c6fSMarcus Overhagen		default: {
251a0795c6fSMarcus Overhagen			// add no fields
252a0795c6fSMarcus Overhagen		}
253a0795c6fSMarcus Overhagen	}
254a0795c6fSMarcus Overhagen}
255a0795c6fSMarcus Overhagen
256a0795c6fSMarcus Overhagen// END -- EndPointInfoView.cpp --
257