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