+#include <QToolButton>
+#include <QGridLayout>
+
+SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
+ QWidget( _parent ) , p_intf( _p_intf )
+{
+ QGroupBox *AVBox, *subsBox;
+
+ QToolButton *moinsAV, *plusAV;
+ QToolButton *moinssubs, *plussubs;
+ QToolButton *moinssubSpeed, *plussubSpeed;
+
+ QToolButton *updateButton;
+
+ QGridLayout *mainLayout = new QGridLayout( this );
+
+ /* AV sync */
+ AVBox = new QGroupBox( qtr( "Audio/Video" ) );
+ QGridLayout *AVLayout = new QGridLayout( AVBox );
+
+ moinsAV = new QToolButton;
+ moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ moinsAV->setAutoRaise( true );
+ moinsAV->setText( "-" );
+ AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
+
+ plusAV = new QToolButton;
+ plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ plusAV->setAutoRaise( true );
+ plusAV->setText( "+" );
+ AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
+
+ QLabel *AVLabel = new QLabel;
+ AVLabel->setText( qtr( "Advance of audio over video:" ) );
+ AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
+
+ AVSpin = new QDoubleSpinBox;
+ AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
+ AVSpin->setDecimals( 3 );
+ AVSpin->setMinimum( -100 );
+ AVSpin->setMaximum( 100 );
+ AVSpin->setSingleStep( 0.1 );
+ AVSpin->setToolTip( qtr( "A positive value means that\n"
+ "the audio is ahead of the video" ) );
+ AVSpin->setSuffix( "s" );
+ AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
+ mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
+
+
+ /* Subs */
+ subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
+ QGridLayout *subsLayout = new QGridLayout( subsBox );
+
+ moinssubs = new QToolButton;
+ moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ moinssubs->setAutoRaise( true );
+ moinssubs->setText( "-" );
+ subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
+
+ plussubs = new QToolButton;
+ plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ plussubs->setAutoRaise( true );
+ plussubs->setText( "+" );
+ subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
+
+ QLabel *subsLabel = new QLabel;
+ subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
+ subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
+
+ subsSpin = new QDoubleSpinBox;
+ subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
+ subsSpin->setDecimals( 3 );
+ subsSpin->setMinimum( -100 );
+ subsSpin->setMaximum( 100 );
+ subsSpin->setSingleStep( 0.1 );
+ subsSpin->setToolTip( qtr( "A positive value means that\n"
+ "the subtitles are ahead of the video" ) );
+ subsSpin->setSuffix( "s" );
+ subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
+
+
+ moinssubSpeed = new QToolButton;
+ moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ moinssubSpeed->setAutoRaise( true );
+ moinssubSpeed->setText( "-" );
+ subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
+
+ plussubSpeed = new QToolButton;
+ plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ plussubSpeed->setAutoRaise( true );
+ plussubSpeed->setText( "+" );
+ subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
+
+ QLabel *subSpeedLabel = new QLabel;
+ subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
+ subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
+
+ subSpeedSpin = new QDoubleSpinBox;
+ subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
+ subSpeedSpin->setDecimals( 3 );
+ subSpeedSpin->setMinimum( 1 );
+ subSpeedSpin->setMaximum( 100 );
+ subSpeedSpin->setSingleStep( 0.2 );
+ subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
+
+ mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
+
+ updateButton = new QToolButton;
+ updateButton->setAutoRaise( true );
+ mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
+
+
+ /* Various Connects */
+ CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
+ CONNECT( plusAV, clicked(), AVSpin, stepUp () );
+ CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
+ CONNECT( plussubs, clicked(), subsSpin, stepUp () );
+ CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
+ CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
+ CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
+ CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
+ CONNECT( subSpeedSpin, valueChanged ( double ),
+ this, adjustSubsSpeed( double ) );
+ BUTTON_SET_ACT_I( updateButton, "", update,
+ qtr( "Force update of this dialog's values" ), update() );
+
+ /* Set it */
+ update();
+}
+
+void SyncControls::update()
+{
+ int64_t i_delay;
+ if( THEMIM->getInput() )
+ {
+ i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
+ AVSpin->setValue( ( (double)i_delay ) / 1000000 );
+ i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
+ subsSpin->setValue( ( (double)i_delay ) / 1000000 );
+ subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
+ }
+}
+
+void SyncControls::advanceAudio( double f_advance )
+{
+ if( THEMIM->getInput() )
+ {
+ int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
+ i_delay += f_advance * 1000000;
+ var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
+ msg_Dbg( p_intf, "I am advancing Audio %d", f_advance );
+ }
+}
+
+void SyncControls::advanceSubs( double f_advance )
+{
+ if( THEMIM->getInput() )
+ {
+ int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
+ i_delay += f_advance * 1000000;
+ var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
+ msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
+ }
+}
+
+void SyncControls::adjustSubsSpeed( double f_fps )
+{
+ if( THEMIM->getInput() )
+ {
+ var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
+ }
+}
+