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