49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <windows.h>
|
|
#include <flutter_texture_registrar.h>
|
|
#include <flutter_plugin_registrar.h>
|
|
#include <mftransform.h>
|
|
#include <wrl/client.h>
|
|
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <vector>
|
|
|
|
class VideoDecoder {
|
|
public:
|
|
// spsPps: Annex-B SPS+PPS bytes (the payload from a 0x01 config packet).
|
|
VideoDecoder(FlutterDesktopTextureRegistrarRef tex_reg,
|
|
const uint8_t* sps_pps, size_t sps_pps_len);
|
|
~VideoDecoder();
|
|
|
|
int64_t texture_id() const { return texture_id_; }
|
|
bool is_valid() const { return texture_id_ >= 0; }
|
|
|
|
void FeedNal(const uint8_t* nal, size_t len);
|
|
|
|
private:
|
|
bool Init(const uint8_t* sps_pps, size_t sps_pps_len);
|
|
bool ParseSpsSize(const uint8_t* data, size_t len, int& w, int& h);
|
|
void Nv12ToBgra(const uint8_t* nv12, int stride,
|
|
uint8_t* bgra, int w, int h);
|
|
|
|
static const FlutterDesktopPixelBuffer* PixelBufferCallback(
|
|
size_t width, size_t height, void* user_data);
|
|
|
|
FlutterDesktopTextureRegistrarRef tex_reg_;
|
|
int64_t texture_id_ = -1;
|
|
|
|
Microsoft::WRL::ComPtr<IMFTransform> decoder_;
|
|
|
|
FlutterDesktopPixelBuffer pixel_buf_{};
|
|
std::vector<uint8_t> frame_data_;
|
|
|
|
int width_ = 0;
|
|
int height_ = 0;
|
|
LONGLONG input_ts_ = 0;
|
|
|
|
std::mutex mu_;
|
|
};
|