info_panels.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*****************************************************************************
  2. * info_panels.cpp : Panels for the information dialogs
  3. ****************************************************************************
  4. * Copyright (C) 2006-2007 the VideoLAN team
  5. * $Id$
  6. *
  7. * Authors: Clément Stenac <zorglub@videolan.org>
  8. * Jean-Baptiste Kempf <jb@videolan.org>
  9. * Ilkka Ollakka <ileoo@videolan.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  24. *****************************************************************************/
  25. #ifdef HAVE_CONFIG_H
  26. # include "config.h"
  27. #endif
  28. #include "qt.hpp"
  29. #include "components/info_panels.hpp"
  30. #include "components/interface_widgets.hpp"
  31. #include "info_widgets.hpp"
  32. #include "dialogs/fingerprintdialog.hpp"
  33. #include "adapters/chromaprint.hpp"
  34. #include <assert.h>
  35. #include <vlc_url.h>
  36. #include <vlc_meta.h>
  37. #include <QTreeWidget>
  38. #include <QHeaderView>
  39. #include <QList>
  40. #include <QStringList>
  41. #include <QGridLayout>
  42. #include <QLineEdit>
  43. #include <QLabel>
  44. #include <QSpinBox>
  45. #include <QTextEdit>
  46. static inline void setSpinBounds( QSpinBox *spinbox ) {
  47. spinbox->setRange( 0, INT_MAX );
  48. spinbox->setAccelerated( true );
  49. spinbox->setAlignment( Qt::AlignRight );
  50. spinbox->setSpecialValueText("");
  51. }
  52. /************************************************************************
  53. * Single panels
  54. ************************************************************************/
  55. /**
  56. * First Panel - Meta Info
  57. * All the usual MetaData are displayed and can be changed.
  58. **/
  59. MetaPanel::MetaPanel( QWidget *parent,
  60. intf_thread_t *_p_intf )
  61. : QWidget( parent ), p_intf( _p_intf )
  62. {
  63. QGridLayout *metaLayout = new QGridLayout( this );
  64. metaLayout->setVerticalSpacing( 0 );
  65. QFont smallFont = QApplication::font();
  66. smallFont.setPointSize( smallFont.pointSize() - 1 );
  67. smallFont.setBold( true );
  68. int line = 0; /* Counter for GridLayout */
  69. p_input = NULL;
  70. QLabel *label;
  71. #define ADD_META( string, widget, col, colspan ) { \
  72. label = new QLabel( qtr( string ) ); label->setFont( smallFont ); \
  73. label->setContentsMargins( 3, 2, 0, 0 ); \
  74. metaLayout->addWidget( label, line++, col, 1, colspan ); \
  75. widget = new QLineEdit; \
  76. metaLayout->addWidget( widget, line, col, 1, colspan ); \
  77. CONNECT( widget, textEdited( QString ), this, enterEditMode() ); \
  78. }
  79. /* Title, artist and album*/
  80. ADD_META( VLC_META_TITLE, title_text, 0, 10 ); line++;
  81. ADD_META( VLC_META_ARTIST, artist_text, 0, 10 ); line++;
  82. ADD_META( VLC_META_ALBUM, collection_text, 0, 7 );
  83. /* Date */
  84. label = new QLabel( qtr( VLC_META_DATE ) );
  85. label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
  86. metaLayout->addWidget( label, line - 1, 7, 1, 2 );
  87. /* Date (Should be in years) */
  88. date_text = new QLineEdit;
  89. date_text->setAlignment( Qt::AlignRight );
  90. date_text->setInputMask("0000");
  91. date_text->setMaximumWidth( 140 );
  92. metaLayout->addWidget( date_text, line, 7, 1, -1 );
  93. line++;
  94. /* Genre Name */
  95. /* TODO List id3genres.h is not includable yet ? */
  96. ADD_META( VLC_META_GENRE, genre_text, 0, 7 );
  97. /* Number - on the same line */
  98. label = new QLabel( qtr( VLC_META_TRACK_NUMBER ) );
  99. label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
  100. metaLayout->addWidget( label, line - 1, 7, 1, 3 );
  101. seqnum_text = new QLineEdit;
  102. seqnum_text->setMaximumWidth( 64 );
  103. seqnum_text->setAlignment( Qt::AlignRight );
  104. metaLayout->addWidget( seqnum_text, line, 7, 1, 1 );
  105. label = new QLabel( "/" ); label->setFont( smallFont );
  106. metaLayout->addWidget( label, line, 8, 1, 1 );
  107. seqtot_text = new QLineEdit;
  108. seqtot_text->setMaximumWidth( 64 );
  109. seqtot_text->setAlignment( Qt::AlignRight );
  110. metaLayout->addWidget( seqtot_text, line, 9, 1, 1 );
  111. line++;
  112. /* Rating - on the same line */
  113. /*
  114. metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) ), line, 4, 1, 2 );
  115. rating_text = new QSpinBox; setSpinBounds( rating_text );
  116. metaLayout->addWidget( rating_text, line, 6, 1, 1 );
  117. */
  118. /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
  119. ADD_META( VLC_META_NOW_PLAYING, nowplaying_text, 0, 7 );
  120. nowplaying_text->setReadOnly( true ); line--;
  121. /* Language on the same line */
  122. ADD_META( VLC_META_LANGUAGE, language_text, 7, -1 ); line++;
  123. ADD_META( VLC_META_PUBLISHER, publisher_text, 0, 7 );
  124. fingerprintButton = new QPushButton( qtr("&Fingerprint") );
  125. fingerprintButton->setToolTip( qtr( "Find meta data using audio fingerprinting" ) );
  126. fingerprintButton->setVisible( false );
  127. metaLayout->addWidget( fingerprintButton, line, 7 , 3, -1 );
  128. CONNECT( fingerprintButton, clicked(), this, fingerprint() );
  129. line++;
  130. lblURL = new QLabel;
  131. lblURL->setOpenExternalLinks( true );
  132. lblURL->setTextFormat( Qt::RichText );
  133. lblURL->setMaximumWidth( 128 );
  134. metaLayout->addWidget( lblURL, line -1, 7, 1, -1 );
  135. ADD_META( VLC_META_COPYRIGHT, copyright_text, 0, 7 ); line++;
  136. /* ART_URL */
  137. art_cover = new CoverArtLabel( this, p_intf );
  138. metaLayout->addWidget( art_cover, line, 7, 6, 3, Qt::AlignLeft );
  139. ADD_META( VLC_META_ENCODED_BY, encodedby_text, 0, 7 ); line++;
  140. label = new QLabel( qtr( N_("Comments") ) ); label->setFont( smallFont );
  141. label->setContentsMargins( 3, 2, 0, 0 );
  142. metaLayout->addWidget( label, line++, 0, 1, 7 );
  143. description_text = new QTextEdit;
  144. description_text->setAcceptRichText( false );
  145. metaLayout->addWidget( description_text, line, 0, 1, 7 );
  146. CONNECT( description_text, textChanged(), this, enterEditMode() );
  147. line++;
  148. /* VLC_META_SETTING: Useless */
  149. /* ADD_META( TRACKID ) Useless ? */
  150. /* ADD_URI - Do not show it, done outside */
  151. metaLayout->setColumnStretch( 1, 20 );
  152. metaLayout->setColumnMinimumWidth ( 1, 80 );
  153. metaLayout->setRowStretch( line, 10 );
  154. #undef ADD_META
  155. CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
  156. CONNECT( seqtot_text, textEdited( QString ), this, enterEditMode() );
  157. CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
  158. // CONNECT( THEMIM->getIM(), artChanged( QString ), this, enterEditMode() );
  159. /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
  160. /* We are not yet in Edit Mode */
  161. b_inEditMode = false;
  162. }
  163. /**
  164. * Update all the MetaData and art on an "item-changed" event
  165. **/
  166. void MetaPanel::update( input_item_t *p_item )
  167. {
  168. if( !p_item )
  169. {
  170. clear();
  171. return;
  172. }
  173. /* Don't update if you are in edit mode */
  174. if( b_inEditMode ) return;
  175. p_input = p_item;
  176. char *psz_meta;
  177. #define UPDATE_META( meta, widget ) { \
  178. psz_meta = input_item_Get##meta( p_item ); \
  179. widget->setText( !EMPTY_STR( psz_meta ) ? qfu( psz_meta ) : "" ); \
  180. free( psz_meta ); }
  181. #define UPDATE_META_INT( meta, widget ) { \
  182. psz_meta = input_item_Get##meta( p_item ); \
  183. if( !EMPTY_STR( psz_meta ) ) \
  184. widget->setValue( atoi( psz_meta ) ); } \
  185. free( psz_meta );
  186. /* Name / Title */
  187. psz_meta = input_item_GetTitleFbName( p_item );
  188. if( psz_meta )
  189. {
  190. title_text->setText( qfu( psz_meta ) );
  191. free( psz_meta );
  192. }
  193. else
  194. title_text->setText( "" );
  195. /* URL / URI */
  196. psz_meta = input_item_GetURI( p_item );
  197. if( !EMPTY_STR( psz_meta ) )
  198. emit uriSet( qfu( psz_meta ) );
  199. fingerprintButton->setVisible( Chromaprint::isSupported( QString( psz_meta ) ) );
  200. free( psz_meta );
  201. /* Other classic though */
  202. UPDATE_META( Artist, artist_text );
  203. UPDATE_META( Genre, genre_text );
  204. UPDATE_META( Copyright, copyright_text );
  205. UPDATE_META( Album, collection_text );
  206. disconnect( description_text, SIGNAL(textChanged()), this,
  207. SLOT(enterEditMode()) );
  208. UPDATE_META( Description, description_text );
  209. CONNECT( description_text, textChanged(), this, enterEditMode() );
  210. UPDATE_META( Language, language_text );
  211. UPDATE_META( NowPlaying, nowplaying_text );
  212. UPDATE_META( Publisher, publisher_text );
  213. UPDATE_META( EncodedBy, encodedby_text );
  214. UPDATE_META( Date, date_text );
  215. UPDATE_META( TrackNum, seqnum_text );
  216. UPDATE_META( TrackTotal, seqtot_text );
  217. // UPDATE_META( Setting, setting_text );
  218. // UPDATE_META_INT( Rating, rating_text );
  219. /* URL */
  220. psz_meta = input_item_GetURL( p_item );
  221. if( !EMPTY_STR( psz_meta ) )
  222. {
  223. QString newURL = qfu(psz_meta);
  224. if( currentURL != newURL )
  225. {
  226. currentURL = newURL;
  227. lblURL->setText( "<a href='" + currentURL + "'>" +
  228. currentURL.remove( QRegExp( ".*://") ) + "</a>" );
  229. }
  230. }
  231. free( psz_meta );
  232. #undef UPDATE_META_INT
  233. #undef UPDATE_META
  234. // If a artURL is available as a local file, directly display it !
  235. QString file;
  236. char *psz_art = input_item_GetArtURL( p_item );
  237. if( psz_art )
  238. {
  239. char *psz = vlc_uri2path( psz_art );
  240. free( psz_art );
  241. file = qfu( psz );
  242. free( psz );
  243. }
  244. art_cover->showArtUpdate( file );
  245. art_cover->setItem( p_item );
  246. }
  247. /**
  248. * Save the MetaData, triggered by parent->save Button
  249. **/
  250. void MetaPanel::saveMeta()
  251. {
  252. if( p_input == NULL )
  253. return;
  254. /* now we read the modified meta data */
  255. input_item_SetTitle( p_input, qtu( title_text->text() ) );
  256. input_item_SetArtist( p_input, qtu( artist_text->text() ) );
  257. input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
  258. input_item_SetGenre( p_input, qtu( genre_text->text() ) );
  259. input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
  260. input_item_SetTrackTotal( p_input, qtu( seqtot_text->text() ) );
  261. input_item_SetDate( p_input, qtu( date_text->text() ) );
  262. input_item_SetLanguage( p_input, qtu( language_text->text() ) );
  263. input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
  264. input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
  265. input_item_SetDescription( p_input, qtu( description_text->toPlainText() ) );
  266. input_item_WriteMeta( VLC_OBJECT(THEPL), p_input );
  267. /* Reset the status of the mode. No need to emit any signal because parent
  268. is the only caller */
  269. b_inEditMode = false;
  270. }
  271. bool MetaPanel::isInEditMode()
  272. {
  273. return b_inEditMode;
  274. }
  275. void MetaPanel::enterEditMode()
  276. {
  277. setEditMode( true );
  278. }
  279. void MetaPanel::setEditMode( bool b_editing )
  280. {
  281. b_inEditMode = b_editing;
  282. if( b_editing )emit editing();
  283. }
  284. /*
  285. * Clear all the metadata widgets
  286. */
  287. void MetaPanel::clear()
  288. {
  289. title_text->clear();
  290. artist_text->clear();
  291. genre_text->clear();
  292. copyright_text->clear();
  293. collection_text->clear();
  294. seqnum_text->clear();
  295. seqtot_text->clear();
  296. disconnect( description_text, SIGNAL(textChanged()), this,
  297. SLOT(enterEditMode()) );
  298. description_text->clear();
  299. CONNECT( description_text, textChanged(), this, enterEditMode() );
  300. date_text->clear();
  301. language_text->clear();
  302. nowplaying_text->clear();
  303. publisher_text->clear();
  304. encodedby_text->clear();
  305. art_cover->clear();
  306. fingerprintButton->setVisible( false );
  307. setEditMode( false );
  308. emit uriSet( "" );
  309. }
  310. void MetaPanel::fingerprint()
  311. {
  312. FingerprintDialog *dialog = new FingerprintDialog( this, p_intf, p_input );
  313. CONNECT( dialog, metaApplied( input_item_t * ), this, fingerprintUpdate( input_item_t * ) );
  314. dialog->setAttribute( Qt::WA_DeleteOnClose, true );
  315. dialog->show();
  316. }
  317. void MetaPanel::fingerprintUpdate( input_item_t *p_item )
  318. {
  319. update( p_item );
  320. setEditMode( true );
  321. }
  322. /**
  323. * Second Panel - Shows the extra metadata in a tree, non editable.
  324. **/
  325. ExtraMetaPanel::ExtraMetaPanel( QWidget *parent ) : QWidget( parent )
  326. {
  327. QGridLayout *layout = new QGridLayout(this);
  328. QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
  329. " are shown in this panel.\n" ) );
  330. topLabel->setWordWrap( true );
  331. layout->addWidget( topLabel, 0, 0 );
  332. extraMetaTree = new QTreeWidget( this );
  333. extraMetaTree->setAlternatingRowColors( true );
  334. extraMetaTree->setColumnCount( 2 );
  335. extraMetaTree->resizeColumnToContents( 0 );
  336. extraMetaTree->setHeaderHidden( true );
  337. layout->addWidget( extraMetaTree, 1, 0 );
  338. }
  339. /**
  340. * Update the Extra Metadata from p_meta->i_extras
  341. **/
  342. void ExtraMetaPanel::update( input_item_t *p_item )
  343. {
  344. if( !p_item )
  345. {
  346. clear();
  347. return;
  348. }
  349. QList<QTreeWidgetItem *> items;
  350. extraMetaTree->clear();
  351. vlc_mutex_lock( &p_item->lock );
  352. vlc_meta_t *p_meta = p_item->p_meta;
  353. if( !p_meta )
  354. {
  355. vlc_mutex_unlock( &p_item->lock );
  356. return;
  357. }
  358. const char *psz_disc_number = vlc_meta_Get( p_meta, vlc_meta_DiscNumber);
  359. if( psz_disc_number )
  360. {
  361. QStringList tempItem;
  362. tempItem.append( VLC_META_DISCNUMBER );
  363. tempItem.append( qfu( psz_disc_number ) );
  364. items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
  365. }
  366. char ** ppsz_allkey = vlc_meta_CopyExtraNames( p_meta);
  367. for( int i = 0; ppsz_allkey[i] ; i++ )
  368. {
  369. const char * psz_value = vlc_meta_GetExtra( p_meta, ppsz_allkey[i] );
  370. QStringList tempItem;
  371. tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
  372. tempItem.append( qfu( psz_value ) );
  373. items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
  374. free( ppsz_allkey[i] );
  375. }
  376. vlc_mutex_unlock( &p_item->lock );
  377. free( ppsz_allkey );
  378. extraMetaTree->addTopLevelItems( items );
  379. extraMetaTree->resizeColumnToContents( 0 );
  380. }
  381. /**
  382. * Clear the ExtraMetaData Tree
  383. **/
  384. void ExtraMetaPanel::clear()
  385. {
  386. extraMetaTree->clear();
  387. }
  388. /**
  389. * Third panel - Stream info
  390. * Display all codecs and muxers info that we could gather.
  391. **/
  392. InfoPanel::InfoPanel( QWidget *parent ) : QWidget( parent )
  393. {
  394. QGridLayout *layout = new QGridLayout(this);
  395. QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
  396. " stream is made of.\nMuxer, Audio and Video Codecs, Subtitles "
  397. "are shown." ) );
  398. topLabel->setWordWrap( true );
  399. layout->addWidget( topLabel, 0, 0 );
  400. InfoTree = new QTreeWidget(this);
  401. InfoTree->setColumnCount( 1 );
  402. InfoTree->header()->hide();
  403. #if HAS_QT5
  404. InfoTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
  405. #else
  406. InfoTree->header()->setResizeMode(QHeaderView::ResizeToContents);
  407. #endif
  408. layout->addWidget(InfoTree, 1, 0 );
  409. }
  410. /**
  411. * Update the Codecs information on parent->update()
  412. **/
  413. void InfoPanel::update( input_item_t *p_item)
  414. {
  415. if( !p_item )
  416. {
  417. clear();
  418. return;
  419. }
  420. InfoTree->clear();
  421. QTreeWidgetItem *current_item = NULL;
  422. QTreeWidgetItem *child_item = NULL;
  423. vlc_mutex_locker locker( &p_item->lock );
  424. for( int i = 0; i< p_item->i_categories ; i++)
  425. {
  426. current_item = new QTreeWidgetItem();
  427. current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
  428. InfoTree->addTopLevelItem( current_item );
  429. for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
  430. {
  431. child_item = new QTreeWidgetItem ();
  432. child_item->setText( 0,
  433. qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
  434. + ": "
  435. + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
  436. current_item->addChild(child_item);
  437. }
  438. InfoTree->setItemExpanded( current_item, true);
  439. }
  440. }
  441. /**
  442. * Clear the tree
  443. **/
  444. void InfoPanel::clear()
  445. {
  446. InfoTree->clear();
  447. }
  448. /**
  449. * Save all the information to a file
  450. * Not yet implemented.
  451. **/
  452. /*
  453. void InfoPanel::saveCodecsInfo()
  454. {}
  455. */
  456. /**
  457. * Fourth Panel - Stats
  458. * Displays the Statistics for reading/streaming/encoding/displaying in a tree
  459. */
  460. InputStatsPanel::InputStatsPanel( QWidget *parent ): QWidget( parent )
  461. {
  462. QVBoxLayout *layout = new QVBoxLayout(this);
  463. QLabel *topLabel = new QLabel( qtr( "Current"
  464. " media / stream " "statistics") );
  465. topLabel->setWordWrap( true );
  466. layout->addWidget( topLabel, 0, 0 );
  467. StatsTree = new QTreeWidget(this);
  468. StatsTree->setColumnCount( 3 );
  469. StatsTree->setHeaderHidden( true );
  470. #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
  471. itemName = \
  472. new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
  473. itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
  474. #define CREATE_CATEGORY( catName, itemText ) { \
  475. CREATE_TREE_ITEM( catName, itemText , "", "" ); \
  476. catName->setExpanded( true ); \
  477. StatsTree->addTopLevelItem( catName ); }
  478. #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
  479. CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
  480. catName->addChild( itemName ); }
  481. /* Create the main categories */
  482. CREATE_CATEGORY( audio, qtr("Audio") );
  483. CREATE_CATEGORY( video, qtr("Video") );
  484. CREATE_CATEGORY( input, qtr("Input/Read") );
  485. CREATE_CATEGORY( streaming, qtr("Output/Written/Sent") );
  486. CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Media data size"),
  487. "0", input , "KiB" );
  488. CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
  489. "0", input, "kb/s" );
  490. input_bitrate_graph = new QTreeWidgetItem();
  491. input_bitrate_stat->addChild( input_bitrate_graph );
  492. CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed data size"), "0", input, "KiB") ;
  493. CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Content bitrate"),
  494. "0", input, "kb/s" );
  495. CREATE_AND_ADD_TO_CAT( corrupted_stat, qtr("Discarded (corrupted)"),
  496. "0", input, "" );
  497. CREATE_AND_ADD_TO_CAT( discontinuity_stat, qtr("Dropped (discontinued)"),
  498. "0", input, "" );
  499. CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded"),
  500. "0", video, qtr("blocks") );
  501. CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed"),
  502. "0", video, qtr("frames") );
  503. CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost"),
  504. "0", video, qtr("frames") );
  505. CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent"), "0", streaming, qtr("packets") );
  506. CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent"),
  507. "0", streaming, "KiB" );
  508. CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Upstream rate"),
  509. "0", streaming, "kb/s" );
  510. CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded"),
  511. "0", audio, qtr("blocks") );
  512. CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played"),
  513. "0", audio, qtr("buffers") );
  514. CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost"), "0", audio, qtr("buffers") );
  515. #undef CREATE_AND_ADD_TO_CAT
  516. #undef CREATE_CATEGORY
  517. #undef CREATE_TREE_ITEM
  518. input->setExpanded( true );
  519. video->setExpanded( true );
  520. streaming->setExpanded( true );
  521. audio->setExpanded( true );
  522. StatsTree->resizeColumnToContents( 0 );
  523. StatsTree->setColumnWidth( 1 , 200 );
  524. layout->addWidget(StatsTree, 4, 0 );
  525. statsView = new VLCStatsView( this );
  526. statsView->setFrameStyle( QFrame::NoFrame );
  527. statsView->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
  528. input_bitrate_graph->setSizeHint( 1, QSize(0, 100) );
  529. QString graphlabel =
  530. QString( "<font style=\"color:#ff8c00\">%1</font><br/>%2" )
  531. .arg( qtr("Last 60 seconds") )
  532. .arg( qtr("Overall") );
  533. StatsTree->setItemWidget( input_bitrate_graph, 0, new QLabel( graphlabel ) );
  534. StatsTree->setItemWidget( input_bitrate_graph, 1, statsView );
  535. }
  536. void InputStatsPanel::hideEvent( QHideEvent * event )
  537. {
  538. statsView->reset();
  539. QWidget::hideEvent( event );
  540. }
  541. /**
  542. * Update the Statistics
  543. **/
  544. void InputStatsPanel::update( input_item_t *p_item )
  545. {
  546. if ( !isVisible() ) return;
  547. assert( p_item );
  548. vlc_mutex_lock( &p_item->p_stats->lock );
  549. #define UPDATE_INT( widget, calc... ) \
  550. { widget->setText( 1, QString::number( (qulonglong)calc ) ); }
  551. #define UPDATE_FLOAT( widget, format, calc... ) \
  552. { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
  553. UPDATE_INT( read_media_stat, (p_item->p_stats->i_read_bytes / 1024 ) );
  554. UPDATE_FLOAT( input_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_input_bitrate * 8000 ));
  555. UPDATE_INT( demuxed_stat, (p_item->p_stats->i_demux_read_bytes / 1024 ) );
  556. UPDATE_FLOAT( stream_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
  557. UPDATE_INT( corrupted_stat, p_item->p_stats->i_demux_corrupted );
  558. UPDATE_INT( discontinuity_stat, p_item->p_stats->i_demux_discontinuity );
  559. statsView->addValue( p_item->p_stats->f_input_bitrate * 8000 );
  560. /* Video */
  561. UPDATE_INT( vdecoded_stat, p_item->p_stats->i_decoded_video );
  562. UPDATE_INT( vdisplayed_stat, p_item->p_stats->i_displayed_pictures );
  563. UPDATE_INT( vlost_frames_stat, p_item->p_stats->i_lost_pictures );
  564. /* Sout */
  565. UPDATE_INT( send_stat, p_item->p_stats->i_sent_packets );
  566. UPDATE_INT( send_bytes_stat, (p_item->p_stats->i_sent_bytes)/ 1024 );
  567. UPDATE_FLOAT( send_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_send_bitrate * 8000 ) );
  568. /* Audio*/
  569. UPDATE_INT( adecoded_stat, p_item->p_stats->i_decoded_audio );
  570. UPDATE_INT( aplayed_stat, p_item->p_stats->i_played_abuffers );
  571. UPDATE_INT( alost_stat, p_item->p_stats->i_lost_abuffers );
  572. #undef UPDATE_INT
  573. #undef UPDATE_FLOAT
  574. vlc_mutex_unlock(& p_item->p_stats->lock );
  575. }
  576. void InputStatsPanel::clear()
  577. {
  578. }