-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterClass.h
84 lines (72 loc) · 1.81 KB
/
MasterClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <Windows.h>
#include <cstdint>
#include <chrono>
extern "C"
{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/frame.h>
#include <libavutil/file.h>
#include <libavformat/avio.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
#undef main
struct buffer_data {
uint8_t* ptr;
size_t size; ///< size left in the buffer
};
struct s_dimension {
int width;
int height;
};
struct s_decoded_frame {
uint8_t* data; //data as rgb or yuv format; set the dependencies
int linesize;
int width;
int height;
int time_avcodec_send_packet;
int time_avcodec_receive_frame;
int time_avcodec_sws_scale;
int buffer_size;
};
struct sYUVplanes {
uint8_t* Y; //data as rgb or yuv format; set the dependencies
uint8_t* U;
uint8_t* V;
};
typedef std::chrono::high_resolution_clock Time;
typedef std::chrono::microseconds us;
typedef std::chrono::duration<float> fsec;
class MasterClass
{
public:
s_dimension* init_ffmpeg(uint8_t*, int);
sYUVplanes* decode_ffmpeg(uint8_t*, int);
void unref_YUVPlanes_structure(uint8_t* avframe);
int check_hardware_device_support(int);
void clear_ffmpeg();
private:
AVBufferRef* hw_device_ctx = NULL;
enum AVHWDeviceType type;
AVCodec* Codec = NULL;
AVCodecContext* codec_ctx = NULL;
AVPacket* pkt = NULL;
AVFormatContext* fmt_ctx = NULL;
AVIOContext* avio_ctx = NULL;
AVFrame* frame;
uint8_t* buffer = NULL, * avio_ctx_buffer = NULL;
size_t buffer_size, avio_ctx_buffer_size = 1024 * 180;
int ret = 0;
struct buffer_data bd = { 0 };
s_decoded_frame* struct_export;
s_dimension* dimension_export;
sYUVplanes* yuvPlanes;
bool hardware_acceleration = false;
const char* device_name = "d3d11va";
sYUVplanes* decode(AVCodecContext*, AVFrame*, AVPacket*);
};