77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#ifndef VIDEODECODER_H
|
|
#define VIDEODECODER_H
|
|
|
|
#include <QThread>
|
|
#include <QMutex>
|
|
#include <QWaitCondition>
|
|
#include <QElapsedTimer>
|
|
|
|
extern "C" {
|
|
#include <libavcodec/avcodec.h>
|
|
#include <libavformat/avformat.h>
|
|
#include <libavutil/imgutils.h>
|
|
#include <libavutil/hwcontext.h>
|
|
}
|
|
|
|
class VideoDecoder : public QThread {
|
|
Q_OBJECT
|
|
public:
|
|
explicit VideoDecoder(QObject *parent = nullptr);
|
|
~VideoDecoder() override;
|
|
|
|
bool openFile(const QString &fileName);
|
|
void closeFile();
|
|
|
|
void play();
|
|
void pause();
|
|
void seek(double seconds);
|
|
void stopThread();
|
|
|
|
double getDuration() const { return m_duration; }
|
|
int getVideoWidth() const { return m_videoWidth; }
|
|
int getVideoHeight() const { return m_videoHeight; }
|
|
bool isPaused() const { return m_isPaused; }
|
|
qint64 getPlaybackTimeMs() const;
|
|
|
|
// Obtener una referencia al fotograma CUDA actual de forma segura
|
|
bool getCurrentFrameRef(AVFrame *destFrame);
|
|
|
|
signals:
|
|
void frameReady();
|
|
void positionChanged(qint64 positionMs);
|
|
void playbackFinished();
|
|
|
|
protected:
|
|
void run() override;
|
|
|
|
private:
|
|
QString m_fileName;
|
|
bool m_running;
|
|
bool m_isPaused;
|
|
bool m_seekRequested;
|
|
double m_seekTimeSecs;
|
|
QMutex m_mutex;
|
|
QWaitCondition m_waitCond;
|
|
|
|
double m_duration;
|
|
int m_videoWidth;
|
|
int m_videoHeight;
|
|
int m_videoStreamIndex;
|
|
|
|
// Relojes de sincronización
|
|
QElapsedTimer m_playbackTimer;
|
|
qint64 m_pausedElapsedMs;
|
|
|
|
AVFormatContext *m_formatContext;
|
|
AVCodecContext *m_codecContext;
|
|
AVBufferRef *m_hwDeviceCtx;
|
|
|
|
// Fotograma CUDA actual y su mutex de protección
|
|
AVFrame *m_currentFrame;
|
|
QMutex m_frameMutex;
|
|
|
|
static enum AVPixelFormat m_hwPixFmt;
|
|
static enum AVPixelFormat get_hw_format(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts);
|
|
};
|
|
|
|
#endif // VIDEODECODER_H
|