2018-06-04 02:16:25 +08:00
|
|
|
|
#ifndef FFMPEGPLAYER_H
|
2017-10-27 13:39:14 +08:00
|
|
|
|
#define FFMPEGPLAYER_H
|
|
|
|
|
|
|
|
|
|
#define MAX_AUDIO_FRAME_SIZE 192000
|
|
|
|
|
#define SDL_AUDIO_BUFFER_SIZE 1024
|
|
|
|
|
#define MAX_AUDIO_SIZE (25 * 16 * 1024)
|
|
|
|
|
#define MAX_VIDEO_SIZE (25 * 256 * 1024)
|
|
|
|
|
#define FLUSH_DATA "FLUSH"
|
|
|
|
|
|
2018-06-04 02:16:25 +08:00
|
|
|
|
extern "C" {
|
2017-10-27 13:39:14 +08:00
|
|
|
|
# include <libavcodec/avcodec.h>
|
|
|
|
|
# include <libavformat/avformat.h>
|
|
|
|
|
# include <libswscale/swscale.h>
|
|
|
|
|
# include <libswresample/swresample.h>
|
|
|
|
|
# include <SDL2/SDL.h>
|
|
|
|
|
# include <SDL2/SDL_thread.h>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include<QThread>
|
|
|
|
|
|
2018-06-04 02:16:25 +08:00
|
|
|
|
typedef struct PacketQueue
|
|
|
|
|
{
|
|
|
|
|
AVPacketList* first_pkt, *last_pkt;
|
2017-10-27 13:39:14 +08:00
|
|
|
|
int nb_packets;
|
|
|
|
|
int size;
|
2018-06-04 02:16:25 +08:00
|
|
|
|
SDL_mutex* mutex;
|
|
|
|
|
SDL_cond* cond;
|
2017-10-27 13:39:14 +08:00
|
|
|
|
} PacketQueue;
|
|
|
|
|
|
2018-06-04 02:16:25 +08:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2017-10-27 13:39:14 +08:00
|
|
|
|
SwrContext* swr_ctx ;//
|
2018-06-04 02:16:25 +08:00
|
|
|
|
AVFrame* wanted_frame;//
|
2017-10-27 13:39:14 +08:00
|
|
|
|
uint8_t* audio_pkt_data;
|
|
|
|
|
int audio_pkt_size; //
|
2018-06-04 02:16:25 +08:00
|
|
|
|
AVFrame* frame; //
|
2017-10-27 13:39:14 +08:00
|
|
|
|
AVFormatContext* afct; //
|
2018-06-04 02:16:25 +08:00
|
|
|
|
AVCodecContext* acct;//
|
2017-10-27 13:39:14 +08:00
|
|
|
|
|
|
|
|
|
unsigned int audio_buf_size; //
|
|
|
|
|
unsigned int audio_buf_index; //
|
|
|
|
|
|
|
|
|
|
PacketQueue audioq; //
|
|
|
|
|
AVPacket pkt; //
|
2018-06-04 02:16:25 +08:00
|
|
|
|
} mediaState;
|
2017-10-27 13:39:14 +08:00
|
|
|
|
|
2018-06-04 02:16:25 +08:00
|
|
|
|
enum playerStatus
|
|
|
|
|
{
|
|
|
|
|
playing,
|
|
|
|
|
pausing,
|
|
|
|
|
buffering,
|
|
|
|
|
stopping
|
2017-10-27 13:39:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FFmpegPlayer : public QThread
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2018-06-04 02:16:25 +08:00
|
|
|
|
explicit FFmpegPlayer ( QObject* parent = 0 );
|
|
|
|
|
void setMedia ( const QString );
|
2017-10-27 13:39:14 +08:00
|
|
|
|
void stop();
|
|
|
|
|
void pause();
|
|
|
|
|
void play();
|
|
|
|
|
playerStatus getPlayerStatus();
|
|
|
|
|
|
|
|
|
|
void FreeAllocSpace();
|
|
|
|
|
protected:
|
|
|
|
|
virtual void run();
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
private:
|
|
|
|
|
QString m_url;
|
|
|
|
|
mediaState m_MS;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // FFMPEGPLAYER_H
|