Skip to content

Commit

Permalink
dynamic_cast;
Browse files Browse the repository at this point in the history
  • Loading branch information
RealChuan committed Sep 1, 2023
1 parent 6b5f7ec commit 92a8fec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
26 changes: 13 additions & 13 deletions examples/player/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ void MainWindow::onProcessEvents()
auto eventPtr = d_ptr->playerPtr->takePropertyChangeEvent();
switch (eventPtr->type()) {
case Ffmpeg::PropertyChangeEvent::EventType::Duration: {
auto durationEvent = static_cast<Ffmpeg::DurationEvent *>(eventPtr.data());
auto durationEvent = dynamic_cast<Ffmpeg::DurationEvent *>(eventPtr.data());
d_ptr->controlWidget->setDuration(durationEvent->duration() / AV_TIME_BASE);
} break;
case Ffmpeg::PropertyChangeEvent::EventType::Position: {
auto positionEvent = static_cast<Ffmpeg::PositionEvent *>(eventPtr.data());
auto positionEvent = dynamic_cast<Ffmpeg::PositionEvent *>(eventPtr.data());
d_ptr->controlWidget->setPosition(positionEvent->position() / AV_TIME_BASE);
} break;
case Ffmpeg::PropertyChangeEvent::EventType::MediaState: {
auto stateEvent = static_cast<Ffmpeg::MediaStateEvent *>(eventPtr.data());
auto stateEvent = dynamic_cast<Ffmpeg::MediaStateEvent *>(eventPtr.data());
switch (stateEvent->state()) {
case Ffmpeg::MediaState::Stopped:
d_ptr->controlWidget->setPlayButtonChecked(false);
Expand All @@ -352,15 +352,15 @@ void MainWindow::onProcessEvents()
}
} break;
case Ffmpeg::PropertyChangeEvent::EventType::CacheSpeed: {
auto speedEvent = static_cast<Ffmpeg::CacheSpeedEvent *>(eventPtr.data());
auto speedEvent = dynamic_cast<Ffmpeg::CacheSpeedEvent *>(eventPtr.data());
d_ptr->controlWidget->setCacheSpeed(speedEvent->speed());
} break;
case Ffmpeg::PropertyChangeEvent::MediaTrack: {
qDeleteAll(d_ptr->audioTracksGroup->actions());
qDeleteAll(d_ptr->videoTracksGroup->actions());
qDeleteAll(d_ptr->subTracksGroup->actions());

auto tracksEvent = static_cast<Ffmpeg::MediaTrackEvent *>(eventPtr.data());
auto tracksEvent = dynamic_cast<Ffmpeg::MediaTrackEvent *>(eventPtr.data());
auto tracks = tracksEvent->tracks();
for (const auto &track : qAsConst(tracks)) {
std::unique_ptr<QAction> actionPtr(new QAction(track.info(), this));
Expand Down Expand Up @@ -390,7 +390,7 @@ void MainWindow::onProcessEvents()
}
} break;
case Ffmpeg::PropertyChangeEvent::SeekChanged: {
auto seekEvent = static_cast<Ffmpeg::SeekChangedEvent *>(eventPtr.data());
auto seekEvent = dynamic_cast<Ffmpeg::SeekChangedEvent *>(eventPtr.data());
int value = seekEvent->position() * 100 / d_ptr->playerPtr->duration();
auto text = tr("Seeked To %1 (key frame) / %2 (%3%)")
.arg(QTime::fromMSecsSinceStartOfDay(seekEvent->position() / 1000)
Expand All @@ -401,7 +401,7 @@ void MainWindow::onProcessEvents()
d_ptr->setTitleWidgetText(text);
} break;
case Ffmpeg::PropertyChangeEvent::Error: {
auto errorEvent = static_cast<Ffmpeg::ErrorEvent *>(eventPtr.data());
auto errorEvent = dynamic_cast<Ffmpeg::ErrorEvent *>(eventPtr.data());
const auto text = tr("Error[%1]:%2.")
.arg(QString::number(errorEvent->error().errorCode()),
errorEvent->error().errorString());
Expand All @@ -419,22 +419,22 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
if (!d_ptr->videoRender.isNull() && watched == d_ptr->videoRender->widget()) {
switch (event->type()) {
case QEvent::DragEnter: {
auto e = static_cast<QDragEnterEvent *>(event);
auto e = dynamic_cast<QDragEnterEvent *>(event);
e->acceptProposedAction();
} break;
case QEvent::DragMove: {
auto e = static_cast<QDragMoveEvent *>(event);
auto e = dynamic_cast<QDragMoveEvent *>(event);
e->acceptProposedAction();
} break;
case QEvent::Drop: {
auto e = static_cast<QDropEvent *>(event);
auto e = dynamic_cast<QDropEvent *>(event);
QList<QUrl> urls = e->mimeData()->urls();
if (!urls.isEmpty()) {
addToPlaylist(urls);
}
} break;
case QEvent::ContextMenu: {
auto e = static_cast<QContextMenuEvent *>(event);
auto e = dynamic_cast<QContextMenuEvent *>(event);
d_ptr->menu->exec(e->globalPos());
} break;
case QEvent::MouseButtonDblClick:
Expand All @@ -450,7 +450,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
} else if (watched == d_ptr->playlistView) {
switch (event->type()) {
case QEvent::ContextMenu: {
auto e = static_cast<QContextMenuEvent *>(event);
auto e = dynamic_cast<QContextMenuEvent *>(event);
d_ptr->playListMenu->exec(e->globalPos());
} break;
default: break;
Expand All @@ -461,7 +461,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
d_ptr->controlWidget->show();
d_ptr->controlWidget->hide();
auto controlWidgetGeometry = d_ptr->controlWidget->geometry();
auto e = static_cast<QHoverEvent *>(event);
auto e = dynamic_cast<QHoverEvent *>(event);
bool contain = controlWidgetGeometry.contains(e->position().toPoint());
d_ptr->setControlWidgetVisible(contain);
if (isFullScreen()) {
Expand Down
6 changes: 3 additions & 3 deletions ffmpeg/audiorender/audiooutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ void printAudioOuputDevice()
class AudioOutput::AudioOutputPrivate
{
public:
AudioOutputPrivate(AudioOutput *q)
explicit AudioOutputPrivate(AudioOutput *q)
: q_ptr(q)
{
mediaDevices = new QMediaDevices(q_ptr);
}
~AudioOutputPrivate() {}
~AudioOutputPrivate() = default;

void reset(const Audio::Config &config)
{
Expand Down Expand Up @@ -62,7 +62,7 @@ AudioOutput::AudioOutput(const Audio::Config &config, QObject *parent)
buildConnect();
}

AudioOutput::~AudioOutput() {}
AudioOutput::~AudioOutput() = default;

void AudioOutput::onWrite(const QByteArray &audioBuf)
{
Expand Down
2 changes: 0 additions & 2 deletions ffmpeg/decoderaudioframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ void DecoderAudioFrame::setVolume(qreal volume)
d_ptr->volume = volume;
if (d_ptr->audioOutputThreadPtr) {
emit d_ptr->audioOutputThreadPtr->volumeChanged(d_ptr->volume);
qDebug() << "set volume:" << d_ptr->volume;
}
}

Expand All @@ -90,7 +89,6 @@ void DecoderAudioFrame::runDecoder()
auto format = getAudioFormatFromCodecCtx(m_contextInfo->codecCtx(), sampleSize);
QScopedPointer<AudioOutputThread> audioOutputThreadPtr(new AudioOutputThread);
d_ptr->audioOutputThreadPtr = audioOutputThreadPtr.data();
qDebug() << "AudioOutputThreadPtr:" << d_ptr->audioOutputThreadPtr;
audioOutputThreadPtr->openOutput({format, format.sampleRate() * sampleSize / 8, d_ptr->volume});
AudioFrameConverter audioConverter(m_contextInfo->codecCtx(), format);
bool firstFrame = false;
Expand Down
18 changes: 9 additions & 9 deletions ffmpeg/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Player::PlayerPrivate
case Event::EventType::CloseMedia: processCloseMediaEvent(); break;
case Event::EventType::AudioTarck:
case Event::EventType::VideoTrack:
case Event::EventType::SubtitleTrack: processSelectedMediaTrackEvent(eventPtr);
case Event::EventType::SubtitleTrack: processSelectedMediaTrackEvent(eventPtr); break;
case Event::EventType::Volume: processVolumeEvent(eventPtr); break;
case Event::EventType::Speed: processSpeedEvent(eventPtr); break;
case Event::EventType::Gpu: processGpuEvent(eventPtr); break;
Expand All @@ -304,7 +304,7 @@ class Player::PlayerPrivate

void processPauseEvent(const EventPtr &eventPtr)
{
auto pauseEvent = static_cast<PauseEvent *>(eventPtr.data());
auto pauseEvent = dynamic_cast<PauseEvent *>(eventPtr.data());
if (pauseEvent->paused()) {
setMediaState(MediaState::Pausing);
} else if (q_ptr->isRunning()) {
Expand Down Expand Up @@ -340,7 +340,7 @@ class Player::PlayerPrivate
if (subtitleInfo->isIndexVaild()) {
count++;
}
auto seekEvent = static_cast<SeekEvent *>(eventPtr.data());
auto seekEvent = dynamic_cast<SeekEvent *>(eventPtr.data());
seekEvent->setWaitCountdown(count);
audioDecoder->addEvent(eventPtr);
videoDecoder->addEvent(eventPtr);
Expand Down Expand Up @@ -370,7 +370,7 @@ class Player::PlayerPrivate

void processSeekRelativeEvent(const EventPtr &eventPtr)
{
auto seekRelativeEvent = static_cast<SeekRelativeEvent *>(eventPtr.data());
auto seekRelativeEvent = dynamic_cast<SeekRelativeEvent *>(eventPtr.data());
auto relativePosition = seekRelativeEvent->relativePosition();
auto position = this->position + relativePosition * AV_TIME_BASE;
if (position < 0) {
Expand All @@ -384,7 +384,7 @@ class Player::PlayerPrivate

void processGpuEvent(const EventPtr &eventPtr)
{
auto gpuEvent = static_cast<GpuEvent *>(eventPtr.data());
auto gpuEvent = dynamic_cast<GpuEvent *>(eventPtr.data());
gpuDecode = gpuEvent->use();
if (filepath.isEmpty()) {
return;
Expand Down Expand Up @@ -425,7 +425,7 @@ class Player::PlayerPrivate
position = 0;
}

auto selectedMediaTrackEvent = static_cast<SelectedMediaTrackEvent *>(eventPtr.data());
auto selectedMediaTrackEvent = dynamic_cast<SelectedMediaTrackEvent *>(eventPtr.data());
switch (selectedMediaTrackEvent->type()) {
case Event::EventType::AudioTarck:
meidaIndex.audioindex = selectedMediaTrackEvent->index();
Expand All @@ -451,7 +451,7 @@ class Player::PlayerPrivate

void processOpenMediaEvent(const EventPtr &eventPtr)
{
auto openMediaEvent = static_cast<OpenMediaEvent *>(eventPtr.data());
auto openMediaEvent = dynamic_cast<OpenMediaEvent *>(eventPtr.data());
filepath = openMediaEvent->filepath();
q_ptr->onPlay();
}
Expand Down Expand Up @@ -479,13 +479,13 @@ class Player::PlayerPrivate

void processSpeedEvent(const EventPtr &eventPtr)
{
auto speedEvent = static_cast<SpeedEvent *>(eventPtr.data());
auto speedEvent = dynamic_cast<SpeedEvent *>(eventPtr.data());
Clock::setSpeed(speedEvent->speed());
}

void processVolumeEvent(const EventPtr &eventPtr)
{
auto volumeEvent = static_cast<VolumeEvent *>(eventPtr.data());
auto volumeEvent = dynamic_cast<VolumeEvent *>(eventPtr.data());
audioDecoder->setVolume(volumeEvent->volume());
}

Expand Down

0 comments on commit 92a8fec

Please sign in to comment.