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