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