From 33c4d2de6382d81f1ab114355120e6effdb133ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Damstedt=20Rasmussen?= Date: Thu, 4 Jul 2024 22:30:04 +0200 Subject: [PATCH] Introduce media file tab for controlling playback --- Client/qtTeamTalk/CMakeLists.txt | 5 +- Client/qtTeamTalk/mainwindow.cpp | 84 +++- Client/qtTeamTalk/mainwindow.h | 6 +- Client/qtTeamTalk/mainwindow.ui | 464 ++++++++++++++--------- Client/qtTeamTalk/streammediafiledlg.cpp | 53 +-- Client/qtTeamTalk/utilmedia.cpp | 60 +++ Client/qtTeamTalk/utilmedia.h | 34 ++ 7 files changed, 461 insertions(+), 245 deletions(-) create mode 100644 Client/qtTeamTalk/utilmedia.cpp create mode 100644 Client/qtTeamTalk/utilmedia.h diff --git a/Client/qtTeamTalk/CMakeLists.txt b/Client/qtTeamTalk/CMakeLists.txt index 2b0b1029bf..aabecc1b71 100644 --- a/Client/qtTeamTalk/CMakeLists.txt +++ b/Client/qtTeamTalk/CMakeLists.txt @@ -90,7 +90,8 @@ if (Qt5_FOUND OR Qt6_FOUND) serverlogeventsmodel.h textmessagecontainer.h useraccountsmodel.h encryptionsetupdlg.h utiltt.h utilxml.h utilos.h serverdlg.h moveusersdlg.h useraccountdlg.h soundeventsmodel.h - mytableview.h mytabwidget.h shortcutsmodel.h + mytableview.h mytabwidget.h shortcutsmodel.h utilmedia.h + main.cpp mainwindow.cpp preferencesdlg.cpp uservideowidget.cpp channelstree.cpp channeldlg.cpp userinfodlg.cpp bannedusersdlg.cpp useraccountsdlg.cpp videogridwidget.cpp @@ -110,7 +111,7 @@ if (Qt5_FOUND OR Qt6_FOUND) serverlogeventsmodel.cpp textmessagecontainer.cpp useraccountsmodel.cpp encryptionsetupdlg.cpp utiltt.cpp utilxml.cpp utilos.cpp serverdlg.cpp moveusersdlg.cpp useraccountdlg.cpp soundeventsmodel.cpp - mytableview.cpp mytabwidget.cpp shortcutsmodel.cpp + mytableview.cpp mytabwidget.cpp shortcutsmodel.cpp utilmedia.cpp mainwindow.ui channel.ui preferences.ui serverlist.ui userinfo.ui bannedusers.ui useraccounts.ui serverproperties.ui uservideo.ui keycomp.ui textmessage.ui diff --git a/Client/qtTeamTalk/mainwindow.cpp b/Client/qtTeamTalk/mainwindow.cpp index 98740686b4..67e8af1856 100644 --- a/Client/qtTeamTalk/mainwindow.cpp +++ b/Client/qtTeamTalk/mainwindow.cpp @@ -45,6 +45,7 @@ #include "utilvideo.h" #include "utiltts.h" #include "utilxml.h" +#include "utilmedia.h" #include "moveusersdlg.h" #include "useraccountdlg.h" @@ -223,21 +224,7 @@ MainWindow::MainWindow(const QString& cfgfile) ui.actionExit->setShortcut(QKeySequence::Quit); #endif - connect(ui.msgEdit, &QLineEdit::textChanged, this, &MainWindow::slotTextChanged); - connect(ui.sendButton, &QAbstractButton::clicked, - this, &MainWindow::slotSendChannelMessage); - connect(ui.msgEdit, &ChatLineEdit::sendTextMessage, - this, &MainWindow::slotSendChannelMessage); - connect(ui.videosendButton, &QAbstractButton::clicked, - this, &MainWindow::slotSendChannelMessage); - connect(ui.desktopsendButton, &QAbstractButton::clicked, - this, &MainWindow::slotSendChannelMessage); - connect(ui.videomsgEdit, &ChatLineEdit::sendTextMessage, - this, &MainWindow::slotSendChannelMessage); - connect(ui.videomsgEdit, &QLineEdit::textChanged, this, &MainWindow::slotTextChanged); - connect(ui.desktopmsgEdit, &QLineEdit::textChanged, this, &MainWindow::slotTextChanged); - connect(ui.desktopmsgEdit, &ChatLineEdit::sendTextMessage, - this, &MainWindow::slotSendChannelMessage); + /* Volume controls */ connect(ui.micSlider, &QAbstractSlider::valueChanged, this, &MainWindow::slotMicrophoneGainChanged); connect(ui.volumeSlider, &QAbstractSlider::valueChanged, @@ -245,7 +232,7 @@ MainWindow::MainWindow(const QString& cfgfile) connect(ui.voiceactSlider, &QAbstractSlider::valueChanged, this, &MainWindow::slotVoiceActivationLevelChanged); - /* ui.channelsWidget */ + /* Channels tree */ connect(ui.channelsWidget, &QTreeWidget::itemSelectionChanged, this, &MainWindow::slotTreeSelectionChanged); connect(ui.channelsWidget, &QWidget::customContextMenuRequested, @@ -259,6 +246,7 @@ MainWindow::MainWindow(const QString& cfgfile) connect(ui.channelsWidget, &ChannelsTree::transmitusersChanged, this, &MainWindow::slotTransmitUsersChanged); + /* Video-tab (video-grid) */ connect(this, &MainWindow::newVideoCaptureFrame, ui.videogridWidget, &VideoGridWidget::slotNewVideoFrame); @@ -272,6 +260,7 @@ MainWindow::MainWindow(const QString& cfgfile) this, &MainWindow::slotUpdateVideoTabUI); connect(ui.videogridWidget, &VideoGridWidget::userVideoSelected, this, &MainWindow::slotUpdateVideoTabUI); + /* Desktop-tab (desktop-grid) */ connect(this, &MainWindow::newDesktopWindow, ui.desktopgridWidget, &DesktopGridWidget::userDesktopWindowUpdate); @@ -289,6 +278,18 @@ MainWindow::MainWindow(const QString& cfgfile) this, &MainWindow::slotUpdateDesktopTabUI); connect(ui.desktopgridWidget, &DesktopGridWidget::userDesktopSelected, this, &MainWindow::slotUpdateDesktopTabUI); + + /* Chat-tab */ + connect(ui.msgEdit, &QLineEdit::textChanged, this, &MainWindow::slotTextChanged); + connect(ui.sendButton, &QAbstractButton::clicked, + this, &MainWindow::slotSendChannelMessage); + connect(ui.msgEdit, &ChatLineEdit::sendTextMessage, + this, &MainWindow::slotSendChannelMessage); + + /* Media-tab */ + connect(ui.playbackOffsetSlider, &QSlider::sliderMoved, + this, &MainWindow::changeMediaFileOffset); + /* Files-tab */ connect(ui.uploadButton, &QAbstractButton::clicked, this, &MainWindow::slotChannelsUploadFile); connect(ui.downloadButton, &QAbstractButton::clicked, this, &MainWindow::slotChannelsDownloadFile); @@ -303,7 +304,13 @@ MainWindow::MainWindow(const QString& cfgfile) this, &MainWindow::slotUploadFiles); connect(ui.filesView, &QWidget::customContextMenuRequested, this, &MainWindow::slotFilesContextMenu); + /* Video-tab buttons */ + connect(ui.videosendButton, &QAbstractButton::clicked, + this, &MainWindow::slotSendChannelMessage); + connect(ui.videomsgEdit, &QLineEdit::textChanged, this, &MainWindow::slotTextChanged); + connect(ui.videomsgEdit, &ChatLineEdit::sendTextMessage, + this, &MainWindow::slotSendChannelMessage); connect(ui.initVideoButton, &QAbstractButton::clicked, ui.actionEnableVideoTransmission, &QAction::triggered); connect(ui.addVideoButton, &QAbstractButton::clicked, this, &MainWindow::slotAddUserVideo); @@ -314,6 +321,11 @@ MainWindow::MainWindow(const QString& cfgfile) connect(this, &MainWindow::preferencesModified, ui.videogridWidget, &VideoGridWidget::preferencesModified); /* Desktop-tab buttons */ + connect(ui.desktopsendButton, &QAbstractButton::clicked, + this, &MainWindow::slotSendChannelMessage); + connect(ui.desktopmsgEdit, &QLineEdit::textChanged, this, &MainWindow::slotTextChanged); + connect(ui.desktopmsgEdit, &ChatLineEdit::sendTextMessage, + this, &MainWindow::slotSendChannelMessage); connect(ui.detachDesktopButton, &QAbstractButton::clicked, this, &MainWindow::slotDetachUserDesktopGrid); connect(ui.addDesktopButton, &QAbstractButton::clicked, @@ -1448,6 +1460,9 @@ void MainWindow::clienteventStreamMediaFile(const MediaFileInfo& mediafileinfo) //update if still talking emit(updateMyself()); + + //update media tab + updateMediaFileProgress(mediafileinfo); } void MainWindow::clienteventUserVideoCapture(int source, int streamid) @@ -5419,6 +5434,43 @@ void MainWindow::slotPauseResumeStream() TT_DoChangeStatus(ttInst, m_statusmode, _W(statusmsg)); } +void MainWindow::updateMediaFileProgress(const MediaFileInfo& mfi) +{ + m_mfi = mfi; + switch (mfi.nStatus) + { + case MFS_CLOSED : + case MFS_ABORTED : + case MFS_ERROR : + case MFS_FINISHED : + ui.durationLabel->setText(durationToString(0)); + ui.playbackTimeLabel->setText(durationToString(0)); + ui.audioLabel->setText(""); + ui.videoLabel->setText(""); + break; + case MFS_PAUSED : + case MFS_STARTED : + case MFS_PLAYING : + ui.durationLabel->setText(durationToString(mfi.uDurationMSec)); + ui.playbackTimeLabel->setText(durationToString(mfi.uElapsedMSec)); + ui.audioLabel->setText(getMediaAudioDescription(mfi.audioFmt)); + ui.videoLabel->setText(getMediaVideoDescription(mfi.videoFmt)); + break; + } +} + +void MainWindow::changeMediaFileOffset(int pos) +{ + double percent = pos / double(ui.playbackOffsetSlider->maximum()); + + m_mfp.uOffsetMSec = UINT32(m_mfi.uDurationMSec * percent); + m_mfp.bPaused = false; + if (!TT_UpdateStreamingMediaFileToChannel(ttInst, &m_mfp, &m_mfp_videocodec)) + { + QMessageBox::critical(this, MENUTEXT(ui.actionPauseResumeStream->text()), tr("Failed to change playback position")); + } +} + void MainWindow::slotChannelsUploadFile(bool /*checked =false */) { int channelid = m_filesmodel->getChannelID(); diff --git a/Client/qtTeamTalk/mainwindow.h b/Client/qtTeamTalk/mainwindow.h index 92c16c81d0..bc162b2ca5 100644 --- a/Client/qtTeamTalk/mainwindow.h +++ b/Client/qtTeamTalk/mainwindow.h @@ -73,9 +73,10 @@ enum TimerEvent enum { TAB_CHAT, + TAB_FILES, + TAB_MEDIA, TAB_VIDEO, TAB_DESKTOP, - TAB_FILES, TAB_COUNT }; @@ -250,6 +251,8 @@ class MainWindow : public QMainWindow void processDesktopInput(int userid, const DesktopInput& input); void startStreamMediaFile(); void stopStreamMediaFile(); + void updateMediaFileProgress(const MediaFileInfo& mfi); + void changeMediaFileOffset(int pos); void loadHotKeys(); void enableHotKey(HotKeyID id, const hotkey_t& hk); void disableHotKey(HotKeyID id); @@ -472,6 +475,7 @@ class MainWindow : public QMainWindow void clienteventSoundDeviceAdded(const SoundDevice& snddev); void clienteventSoundDeviceRemoved(const SoundDevice& snddev); MediaFilePlayback m_mfp = {}; + MediaFileInfo m_mfi = {}; VideoCodec m_mfp_videocodec = {}; signals: diff --git a/Client/qtTeamTalk/mainwindow.ui b/Client/qtTeamTalk/mainwindow.ui index 6a510e547b..700c5fde05 100644 --- a/Client/qtTeamTalk/mainwindow.ui +++ b/Client/qtTeamTalk/mainwindow.ui @@ -11,7 +11,7 @@ - Qt::NoFocus + Qt::FocusPolicy::NoFocus @@ -36,20 +36,20 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - Qt::CustomContextMenu + Qt::ContextMenuPolicy::CustomContextMenu Channel list - QAbstractItemView::NoEditTriggers + QAbstractItemView::EditTrigger::NoEditTriggers false @@ -58,10 +58,10 @@ false - QAbstractItemView::ExtendedSelection + QAbstractItemView::SelectionMode::ExtendedSelection - QAbstractItemView::SelectItems + QAbstractItemView::SelectionBehavior::SelectItems false @@ -164,7 +164,7 @@ 100 - Qt::Horizontal + Qt::Orientation::Horizontal @@ -180,7 +180,7 @@ :/images/images/vumeter.png - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -192,27 +192,27 @@ 0 + + Qt::FocusPolicy::StrongFocus + Voice level + + Voice level + 20 0 - - Voice level - - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - - Qt::StrongFocus - @@ -227,7 +227,7 @@ :/images/images/mike.png - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter micSlider @@ -252,7 +252,7 @@ 100 - Qt::Horizontal + Qt::Orientation::Horizontal @@ -268,7 +268,7 @@ :/images/images/voiceact.png - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter voiceactSlider @@ -296,7 +296,7 @@ 5 - Qt::Horizontal + Qt::Orientation::Horizontal @@ -355,7 +355,7 @@ true - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse @@ -394,6 +394,241 @@ + + + &Files + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + + + + + + + Qt::ContextMenuPolicy::CustomContextMenu + + + Files list + + + false + + + true + + + true + + + false + + + + + + + + + false + + + Download + + + Download + + + + :/images/images/download.png:/images/images/download.png + + + + 20 + 20 + + + + + + + + false + + + Delete + + + Delete + + + + :/images/images/delete.png:/images/images/delete.png + + + + 20 + 20 + + + + + + + + false + + + Upload + + + Upload + + + + :/images/images/upload.png:/images/images/upload.png + + + + 20 + 20 + + + + + + + + + + + Media + + + + + + + + Elapsed + + + + + + + Start position + + + Qt::Orientation::Horizontal + + + + + + + 0:00:00.000 + + + playbackOffsetSlider + + + + + + + + + + + Duration: + + + + + + + + + + Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse + + + + + + + + + + + Audio format: + + + + + + + + + + Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse + + + + + + + + + + + Video format: + + + + + + + + + + Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + @@ -423,7 +658,7 @@ - Qt::Vertical + Qt::Orientation::Vertical 5 @@ -441,7 +676,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -477,7 +712,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -510,7 +745,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -546,7 +781,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -583,7 +818,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -639,7 +874,7 @@ true - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse @@ -698,7 +933,7 @@ - Qt::Vertical + Qt::Orientation::Vertical 5 @@ -716,7 +951,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -755,7 +990,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -791,7 +1026,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -827,7 +1062,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -869,7 +1104,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -925,7 +1160,7 @@ true - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + Qt::TextInteractionFlag::LinksAccessibleByKeyboard|Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextBrowserInteraction|Qt::TextInteractionFlag::TextSelectableByKeyboard|Qt::TextInteractionFlag::TextSelectableByMouse @@ -961,142 +1196,6 @@ - - - &Files - - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - - - - - - - Qt::CustomContextMenu - - - Files list - - - QAbstractItemView::NoEditTriggers - - - false - - - QAbstractItemView::DropOnly - - - true - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::SelectRows - - - true - - - false - - - true - - - - - - - - - false - - - Download - - - Download - - - - :/images/images/download.png:/images/images/download.png - - - - 20 - 20 - - - - - - - - false - - - Delete - - - Delete - - - - :/images/images/delete.png:/images/images/delete.png - - - - 20 - 20 - - - - - - - - false - - - Upload - - - Upload - - - - :/images/images/upload.png:/images/images/upload.png - - - - 20 - 20 - - - - - - - - @@ -1108,7 +1207,7 @@ 0 0 637 - 21 + 24 @@ -2112,6 +2211,9 @@ + + false + :/images/images/streammedia.png:/images/images/streammedia.png @@ -2122,9 +2224,6 @@ Ctrl+P - - false - @@ -2378,6 +2477,12 @@ + + MyTabWidget + QTabWidget +
mytabwidget.h
+ 1 +
ChatTextEdit QPlainTextEdit @@ -2399,11 +2504,6 @@ QLineEdit
chatlineedit.h
- - FilesView - MyTableView -
filesview.h
-
DesktopGridWidget QWidget @@ -2411,9 +2511,9 @@ 1 - MyTabWidget - QTabWidget -
mytabwidget.h
+ FilesView + QWidget +
filesview.h
diff --git a/Client/qtTeamTalk/streammediafiledlg.cpp b/Client/qtTeamTalk/streammediafiledlg.cpp index e19f1da3a0..c144640fd1 100644 --- a/Client/qtTeamTalk/streammediafiledlg.cpp +++ b/Client/qtTeamTalk/streammediafiledlg.cpp @@ -20,6 +20,7 @@ #include "settings.h" #include "audiopreprocessordlg.h" #include "utilui.h" +#include "utilmedia.h" #include #include @@ -56,7 +57,6 @@ StreamMediaFileDlg::StreamMediaFileDlg(QWidget* parent/* = 0*/) connect(ui.preprocessorComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &StreamMediaFileDlg::slotChangePreprocessor); connect(ui.preprocessButton, &QAbstractButton::clicked, this, &StreamMediaFileDlg::slotSetupPreprocessor); connect(ui.playbackOffsetSlider, &QSlider::sliderMoved, this, &StreamMediaFileDlg::slotChangePlayOffset); - //connect(ui.playbackOffsetSlider, &QSlider::valueChanged, this, &StreamMediaFileDlg::slotChangePlayOffset); // audio preprocessor ui.preprocessorComboBox->addItem(tr("No Audio Preprocessor"), NO_AUDIOPREPROCESSOR); @@ -66,7 +66,7 @@ StreamMediaFileDlg::StreamMediaFileDlg(QWidget* parent/* = 0*/) SETTINGS_STREAMMEDIA_AUDIOPREPROCESSOR_DEFAULT).toInt()); setCurrentItemData(ui.preprocessorComboBox, apt); - ui.playbackOffsetSlider->setMaximum(10000); + ui.playbackOffsetSlider->setMaximum(MEDIAFILE_SLIDER_MAXIMUM); m_videocodec.nCodec = Codec(ttSettings->value(SETTINGS_STREAMMEDIA_CODEC, DEFAULT_VIDEO_CODEC).toInt()); switch(m_videocodec.nCodec) @@ -205,34 +205,9 @@ void StreamMediaFileDlg::showMediaFormatInfo() if (TT_GetMediaFileInfo(_W(filename), &m_mediaFile)) { - // display audio format - if(m_mediaFile.audioFmt.nAudioFmt != AFF_NONE) - { - QString channels; - if(m_mediaFile.audioFmt.nChannels == 2) - channels = tr("Stereo"); - else if(m_mediaFile.audioFmt.nChannels == 1) - channels = tr("Mono"); - else - channels = tr("%1 audio channels").arg(m_mediaFile.audioFmt.nChannels); - - audio = tr("%1 Hz, %2").arg(m_mediaFile.audioFmt.nSampleRate).arg(channels); - } - else - audio = tr("Unknown format"); - - // display video format - double fps = double(m_mediaFile.videoFmt.nFPS_Numerator) / double(m_mediaFile.videoFmt.nFPS_Denominator); - if(m_mediaFile.videoFmt.picFourCC != FOURCC_NONE) - video = tr("%1x%2 %3 FPS").arg(m_mediaFile.videoFmt.nWidth).arg(m_mediaFile.videoFmt.nHeight).arg(fps, 0, 'f', 1); - else - video = tr("Unknown format"); - - int duration_sec = m_mediaFile.uDurationMSec / 1000; - duration = QString("%1:%2:%3") - .arg(duration_sec / 3600, 2 , 10, QChar('0')) - .arg((duration_sec % 3600) / 60, 2 , 10, QChar('0')) - .arg(duration_sec % 60, 2 , 10, QChar('0')); + audio = getMediaAudioDescription(m_mediaFile.audioFmt); + video = getMediaVideoDescription(m_mediaFile.videoFmt); + duration = durationToString(m_mediaFile.uDurationMSec, false); } else { @@ -267,23 +242,13 @@ void StreamMediaFileDlg::updateControls() void StreamMediaFileDlg::updateProgress(quint32 elapsed, bool setvalue) { - quint32 hours = elapsed / (60 * 60 * 1000); - quint32 remain = elapsed - (60 * 60 * 1000 * hours); - quint32 minutes = remain / (60 * 1000); - remain -= 60 * 1000 * minutes; - quint32 seconds = remain / 1000; - quint32 msec = remain % 1000; - - ui.playbackTimeLabel->setText(QString("%1:%2:%3.%4").arg(hours) - .arg(minutes, 2, 10, QChar('0')) - .arg(seconds, 2, 10, QChar('0')) - .arg(msec, 3, 10, QChar('0'))); + ui.playbackTimeLabel->setText(durationToString(elapsed)); if (m_mediaFile.uDurationMSec && setvalue) { - double percent = elapsed / (double)m_mediaFile.uDurationMSec; - int value = int(percent * double(ui.playbackOffsetSlider->maximum())); - ui.playbackOffsetSlider->setValue(value); + MediaFileInfo mfi = m_mediaFile; + mfi.uElapsedMSec = elapsed; + setMediaFileProgress(ui.playbackOffsetSlider, mfi); } } diff --git a/Client/qtTeamTalk/utilmedia.cpp b/Client/qtTeamTalk/utilmedia.cpp new file mode 100644 index 0000000000..5b01265605 --- /dev/null +++ b/Client/qtTeamTalk/utilmedia.cpp @@ -0,0 +1,60 @@ +#include "utilmedia.h" + +#include + +QString durationToString(quint32 duration_msec, bool include_msec/* = true*/) +{ + quint32 hours = duration_msec / (60 * 60 * 1000); + quint32 remain = duration_msec - (60 * 60 * 1000 * hours); + quint32 minutes = remain / (60 * 1000); + remain -= 60 * 1000 * minutes; + quint32 seconds = remain / 1000; + quint32 msec = remain % 1000; + + return include_msec ? QString("%1:%2:%3.%4").arg(hours) + .arg(minutes, 2, 10, QChar('0')) + .arg(seconds, 2, 10, QChar('0')) + .arg(msec, 3, 10, QChar('0')) : + QString("%1:%2:%3").arg(hours) + .arg(minutes, 2, 10, QChar('0')) + .arg(seconds, 2, 10, QChar('0')); +} + +QString getMediaAudioDescription(const AudioFormat& audioFmt) +{ + // display audio format + if (audioFmt.nAudioFmt != AFF_NONE) + { + QString channels; + if (audioFmt.nChannels == 2) + channels = QObject::tr("Stereo"); + else if (audioFmt.nChannels == 1) + channels = QObject::tr("Mono"); + else + channels = QObject::tr("%1 audio channels").arg(audioFmt.nChannels); + + return QObject::tr("%1 Hz, %2").arg(audioFmt.nSampleRate).arg(channels); + } + else + return QObject::tr("Unknown format"); +} + +QString getMediaVideoDescription(const VideoFormat& videoFmt) +{ + // display video format + double fps = double(videoFmt.nFPS_Numerator) / double(videoFmt.nFPS_Denominator); + if (videoFmt.picFourCC != FOURCC_NONE) + return QObject::tr("%1x%2 %3 FPS").arg(videoFmt.nWidth).arg(videoFmt.nHeight).arg(fps, 0, 'f', 1); + else + return QObject::tr("Unknown format"); +} + +void setMediaFileProgress(QSlider* slider, const MediaFileInfo& mfi) +{ + if (mfi.uDurationMSec) + { + double percent = mfi.uElapsedMSec / (double)mfi.uDurationMSec; + int value = int(percent * double(slider->maximum())); + slider->setValue(value); + } +} diff --git a/Client/qtTeamTalk/utilmedia.h b/Client/qtTeamTalk/utilmedia.h new file mode 100644 index 0000000000..1ee2bbf29a --- /dev/null +++ b/Client/qtTeamTalk/utilmedia.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023, Bjørn D. Rasmussen, BearWare.dk + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(UTILMEDIA_H) +#define UTILMEDIA_H + +#include "utiltt.h" + +#include +#include + +#define MEDIAFILE_SLIDER_MAXIMUM 10000 + +QString durationToString(quint32 duration_msec, bool include_msec = true); +QString getMediaAudioDescription(const AudioFormat& audioFmt); +QString getMediaVideoDescription(const VideoFormat& videoFmt); + +void setMediaFileProgress(QSlider* slider, const MediaFileInfo& mfi); + +#endif // UTILMEDIA_H