-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCameraCapture.h
66 lines (56 loc) · 1.61 KB
/
CameraCapture.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
#pragma once
#include "ReadParams.h"
#include "DataPacket.h"
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mathematics.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
#include <libavutil/pixdesc.h>
#include <libavdevice/avdevice.h>
#include <libavutil/dict.h>
}
class CameraCapture
{
public:
// constructor, params from class ReadParams
CameraCapture(const CameraParams* params = nullptr);
// destructor for libav pointers
~CameraCapture() {
av_dict_free(&CamInDict);
avcodec_free_context(&CodecCtx);
avformat_close_input(&Input_fmt_Ctx);
if (FrameOut) {
av_frame_free(&FrameOut);
}
sws_freeContext(SwsCtx);
SwsCtx = nullptr;
};
void set_cam_params(const CameraParams* params) {
CamParams = params;
}
void set_callback_func(std::function<void(DataPacket*)> func) {
OnFrameFunc = func;
}
bool ready() const {
return (State == 1) && (OnFrameFunc != nullptr);
}
int initialize();
void capture();
private:
std::function<void(DataPacket*)> OnFrameFunc;
AVFormatContext* Input_fmt_Ctx;
std::clock_t DelayClock;
AVCodecContext* CodecCtx;
AVDictionary* CamInDict;
SwsContext* SwsCtx;
AVFrame* FrameOut;
DataPacket DataOut;
uint64_t FrameCnt;
uint64_t Bitrate;
int DataOutSz;
int OutStreamNum;
int State; // capture ready state
const CameraParams* CamParams;
};