50 lines
1016 B
C++
50 lines
1016 B
C++
#ifndef SCAR_VIDEO_DECODER_H
|
|
#define SCAR_VIDEO_DECODER_H
|
|
|
|
#include <vector>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <QImage>
|
|
|
|
extern "C" {
|
|
#include <libavcodec/avcodec.h>
|
|
#include <libavutil/imgutils.h>
|
|
#include <libswscale/swscale.h>
|
|
}
|
|
|
|
namespace scar {
|
|
|
|
class VideoDecoder {
|
|
public:
|
|
VideoDecoder();
|
|
~VideoDecoder();
|
|
|
|
// Initialize decoder
|
|
bool initialize();
|
|
|
|
// Decode H.264 packet and return RGB24 data
|
|
// Returns empty vector if no frame ready yet
|
|
// out_linesize is the actual stride/linesize of each row in bytes
|
|
std::vector<uint8_t> decode(const std::vector<uint8_t>& encoded_data,
|
|
int& out_width, int& out_height, int& out_linesize);
|
|
|
|
// Cleanup
|
|
void cleanup();
|
|
|
|
private:
|
|
AVCodecContext* codec_ctx_;
|
|
AVFrame* frame_;
|
|
SwsContext* sws_ctx_;
|
|
|
|
int width_;
|
|
int height_;
|
|
|
|
bool initialized_;
|
|
std::mutex decode_mutex_;
|
|
};
|
|
|
|
} // namespace scar
|
|
|
|
#endif // SCAR_VIDEO_DECODER_H
|