/************************************************************ *Copyright (C), 2017-2027,lcb0281@gmail.com *FileName: videoplayer.h *Date: 2019-06-15 *Author: Caibiao Lee *Version: V1.0 *Description: 音视频读取解码显示播放模块 *Others: 该模块代码由网上拷贝,我只是添加了 注释,规范了一些编码规范 *History: ***********************************************************/ #ifndef VIDEOPLAYER_H #define VIDEOPLAYER_H #include #include extern "C" { #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include #include "libavutil/pixfmt.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" #include #include #include #include #include #include } #define VIDEO_PICTURE_QUEUE_SIZE 1 #define MAX_AUDIO_SIZE (25 * 16 * 1024) #define MAX_VIDEO_SIZE (25 * 256 * 1024) #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 /**1 second of 48khz 32bit audio**/ class VideoPlayer; /**前置声明**/ typedef struct PacketQueue { AVPacketList *first_pkt; /**队列头指针**/ AVPacketList *last_pkt; /**队列尾指针**/ int nb_packets; /**队列长度**/ int size; /**该节点数据大小**/ SDL_mutex *mutex; /**互斥量**/ SDL_cond *cond; /**状态变量**/ } PacketQueue; typedef struct VideoState { DECLARE_ALIGNED(16,uint8_t,audio_buf2) [AVCODEC_MAX_AUDIO_FRAME_SIZE * 4];//字节对齐,提升效率 AVFormatContext *pFormatContext; /**文件格式上下文**/ PacketQueue audioq;//音频队列 AVFrame *audio_frame;/**解码音频过程中的使用缓存**/ AVStream *audio_st; /**音频流**/ AVStream *video_st;//视频流 AVPacket audio_pkt; PacketQueue videoq;//视频队列 struct SwrContext *swr_ctx; /**用于解码后的音频格式转换**/ uint8_t *audio_buf; uint8_t *audio_pkt_data; int audio_pkt_size; int s32VStreamCount; /**视频流数量**/ int s32AStreamCount; /**音频流数量**/ int audio_src_channels; int audio_tgt_channels; int audio_src_freq; int audio_tgt_freq; int audio_hw_buf_size; unsigned int audio_buf_size; unsigned int audio_buf_index; int64_t audio_src_channel_layout; int64_t audio_tgt_channel_layout; enum AVSampleFormat audio_src_fmt; enum AVSampleFormat audio_tgt_fmt; double audio_clock; /**音频时钟**/ double video_clock; /**