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