misc: Fix cppcheck 1.82 + 1.90 warnings

This commit is contained in:
matt335672 2020-01-17 17:21:48 +00:00
parent 627da8da3e
commit 16c20dc6e3
4 changed files with 1 additions and 364 deletions

View File

@ -37,8 +37,6 @@ int g_rem_io_count = 0; // bytes read from remote port
static int g_terminated = 0;
static char g_buf[1024 * 32];
#define
#define
typedef unsigned short tui16;

View File

@ -1,266 +0,0 @@
// not used
#include "decoderthread.h"
/*
* TODO:
* o need to maintain aspect ratio while resizing
* o clicking in the middle of the slider bar should move the slider to the middle
* o need to be able to rewind the move when it is done playing
* o need to be able to load another move and play it w/o restarting player
* o pause button needs to work
* o need images for btns
*/
DecoderThread::DecoderThread()
{
channel = NULL;
geometry.setX(0);
geometry.setY(0);
geometry.setWidth(0);
geometry.setHeight(0);
stream_id = 101;
elapsedTime = 0;
la_seekPos = -1;
videoTimer = NULL;
audioTimer = NULL;
}
void DecoderThread::run()
{
/* need a media file */
if (filename.length() == 0)
{
emit on_decoderErrorMsg("No media file",
"Please select a media file to play");
return;
}
}
void DecoderThread::startMediaPlay()
{
MediaPacket *mediaPkt;
int is_video_frame;
int rv;
/* setup video timer; each time this timer fires, it sends */
/* one video pkt to the client then resets the callback duration */
videoTimer = new QTimer;
connect(videoTimer, SIGNAL(timeout()), this, SLOT(videoTimerCallback()));
//videoTimer->start(1500);
/* setup audio timer; does the same as above, but with audio pkts */
audioTimer = new QTimer;
connect(audioTimer, SIGNAL(timeout()), this, SLOT(audioTimerCallback()));
//audioTimer->start(500);
/* setup pktTimer; each time this timer fires, it reads AVPackets */
/* and puts them into audio/video Queues */
pktTimer = new QTimer;
connect(pktTimer, SIGNAL(timeout()), this, SLOT(pktTimerCallback()));
while (1)
{
/* fill the audio/video queues with initial data; thereafter */
/* data will be filled by pktTimerCallback() */
if ((audioQueue.count() >= 3000) || (videoQueue.count() >= 3000))
{
//pktTimer->start(50);
//videoTimer->start(1500);
//audioTimer->start(500);
playVideo = new PlayVideo(NULL, &videoQueue, channel, 101);
playVideoThread = new QThread(this);
connect(playVideoThread, SIGNAL(started()), playVideo, SLOT(play()));
playVideo->moveToThread(playVideoThread);
playVideoThread->start();
playAudio = new PlayAudio(NULL, &audioQueue, channel, 101);
playAudioThread = new QThread(this);
connect(playAudioThread, SIGNAL(started()), playAudio, SLOT(play()));
playAudio->moveToThread(playAudioThread);
playAudioThread->start();
return;
}
mediaPkt = new MediaPacket;
rv = xrdpvr_get_frame(&mediaPkt->av_pkt,
&is_video_frame,
&mediaPkt->delay_in_us);
if (rv < 0)
{
/* looks like we reached end of file */
break;
}
if (is_video_frame)
videoQueue.enqueue(mediaPkt);
else
audioQueue.enqueue(mediaPkt);
} /* end while (1) */
}
void DecoderThread::on_mediaSeek(int value)
{
mutex.lock();
la_seekPos = value;
mutex.unlock();
qDebug() << "media seek value=" << value;
/* pktTimer stops at end of media; need to restart it */
if (!pktTimer->isActive())
{
updateSlider();
pktTimer->start(100);
}
}
void DecoderThread::setFilename(QString filename)
{
this->filename = filename;
}
void DecoderThread::stopPlayer()
{
pktTimer->stop();
audioQueue.clear();
videoQueue.clear();
}
void DecoderThread::pausePlayer()
{
pktTimer->stop();
}
void DecoderThread::resumePlayer()
{
pktTimer->start(100);
}
void DecoderThread::close()
{
}
void DecoderThread::audioTimerCallback()
{
MediaPacket *pkt;
int delayInMs;
if (audioQueue.isEmpty())
{
qDebug() << "audioTimerCallback: got empty";
audioTimer->setInterval(100);
return;
}
pkt = audioQueue.dequeue();
delayInMs = (int) ((float) pkt->delay_in_us / 1000.0);
send_audio_pkt(channel, 101, pkt->av_pkt);
delete pkt;
//qDebug() << "audioTimerCallback: delay :" << delayInMs;
audioTimer->setInterval(delayInMs);
}
void DecoderThread::videoTimerCallback()
{
MediaPacket *pkt;
int delayInMs;
if (videoQueue.isEmpty())
{
qDebug() << "videoTimerCallback: GOT EMPTY";
videoTimer->setInterval(100);
return;
}
pkt = videoQueue.dequeue();
delayInMs = (int) 10; // ((float) pkt->delay_in_us / 1000.0);
send_video_pkt(channel, 101, pkt->av_pkt);
delete pkt;
updateSlider();
//qDebug() << "videoTimerCallback: delay :" << delayInMs;
videoTimer->setInterval(delayInMs);
}
void DecoderThread::pktTimerCallback()
{
MediaPacket *mediaPkt;
int is_video_frame;
int rv;
while (1)
{
qDebug() << "pktTimerCallback: audioCount=" << audioQueue.count() << "videoCount=" << videoQueue.count();
#if 1
if ((audioQueue.count() >= 20) || (videoQueue.count() >= 20))
return;
#else
if (videoQueue.count() >= 60)
return;
#endif
mediaPkt = new MediaPacket;
rv = xrdpvr_get_frame(&mediaPkt->av_pkt,
&is_video_frame,
&mediaPkt->delay_in_us);
if (rv < 0)
{
/* looks like we reached end of file */
qDebug() << "###### looks like we reached EOF";
pktTimer->stop();
// LK_TODO set some flag so audio/video timer also stop when q is empty
return;
}
if (is_video_frame)
videoQueue.enqueue(mediaPkt);
else
audioQueue.enqueue(mediaPkt);
}
}
void DecoderThread::updateSlider()
{
if (elapsedTime == 0)
elapsedTime = av_gettime();
/* time elapsed in 1/100th sec units since play started */
emit on_elapsedtime((av_gettime() - elapsedTime) / 10000);
mutex.lock();
if (la_seekPos >= 0)
{
qDebug() << "seeking to" << la_seekPos;
//audioTimer->stop();
//videoTimer->stop();
xrdpvr_seek_media(la_seekPos, 0);
elapsedTime = av_gettime() - la_seekPos * 1000000;
//audioTimer->start(10);
//videoTimer->start(10);
la_seekPos = -1;
}
mutex.unlock();
}

View File

@ -1,95 +0,0 @@
#ifndef DECODERTHREAD_H
#define DECODERTHREAD_H
#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
#include <stdint.h>
#endif
#include <QThread>
#include <QDebug>
#include <QString>
#include <QRect>
#include <QMutex>
#include <QTimer>
#include <QQueue>
#include <xrdpapi.h>
#include <xrdpvr.h>
#include <mediapacket.h>
#include <playvideo.h>
#include <playaudio.h>
/* ffmpeg related stuff */
extern "C"
{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
class DecoderThread : public QObject
{
Q_OBJECT
public:
/* public methods */
DecoderThread();
void setFilename(QString filename);
void stopPlayer();
void pausePlayer();
void resumePlayer();
void oneTimeDeinit();
void close();
void run();
void startMediaPlay();
public slots:
void on_mediaSeek(int value);
private:
/* private variables */
QQueue<MediaPacket *> audioQueue;
QQueue<MediaPacket *> videoQueue;
QTimer *videoTimer;
QTimer *audioTimer;
QTimer *pktTimer;
QString filename;
void *channel;
int stream_id;
QRect geometry;
int64_t elapsedTime; /* elapsed time in usecs since play started */
QMutex mutex;
int64_t la_seekPos; /* locked access; must hold mutex */
PlayVideo *playVideo;
QThread *playVideoThread;
PlayAudio *playAudio;
QThread *playAudioThread;
/* private functions */
int sendMetadataFile();
int sendAudioFormat();
int sendVideoFormat();
int sendGeometry();
void updateSlider();
private slots:
/* private slots */
void audioTimerCallback();
void videoTimerCallback();
void pktTimerCallback();
signals:
/* private signals */
void on_progressUpdate(int percent);
void on_decoderErrorMsg(QString title, QString msg);
void on_mediaDurationInSeconds(int duration);
void on_elapsedtime(int val); /* in hundredth of a sec */
};
#endif // DECODERTHREAD_H

View File

@ -267,7 +267,7 @@ handle_connection(int client_fd)
}
if (retlen != sizeof(rdp_fd))
{
fprintf(stderr, "WTSVirtualChannelQuery() returned wrong length %d\n",
fprintf(stderr, "WTSVirtualChannelQuery() returned wrong length %u\n",
retlen);
}
rdp_fd = *retdata;