86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#ifndef SCREEN_CAPTURE
|
|
#define SCREEN_CAPTURE
|
|
|
|
#include <Windows.h>
|
|
#include <Wincodec.h> // we use WIC for saving images
|
|
#include <d3d9.h> // DirectX 9 header
|
|
#include <d3d9helper.h>
|
|
#include <stdint.h>
|
|
#include "streamcontrol.h"
|
|
#include <thread>
|
|
extern "C"
|
|
{
|
|
#include "libavcodec/avcodec.h"
|
|
#include "libavformat/avformat.h"
|
|
#include "libavutil/avutil.h"
|
|
#include "libswscale/swscale.h"
|
|
#include "libavutil/opt.h"
|
|
#include "libavutil/imgutils.h"
|
|
#include <libavfilter/avfilter.h>
|
|
#include <libavfilter/buffersink.h>
|
|
#include <libavfilter/buffersrc.h>
|
|
#include <libavutil/opt.h>
|
|
#include <libavutil/dict.h>
|
|
#include "libavdevice/avdevice.h"
|
|
|
|
}
|
|
HRESULT Direct3D9TakeScreenshots(UINT adapter, UINT count);
|
|
|
|
|
|
class ScreenCapture :public StreamControl
|
|
{
|
|
public:
|
|
class CaptureVideoObserver {
|
|
public:
|
|
virtual void OnScreenData(const void *frameaddress, uint32_t framelen) {};
|
|
};
|
|
|
|
ScreenCapture();
|
|
void EnumScreen();
|
|
void PrintDisplayModeInfo(IDirect3D9 *pD3D, D3DFORMAT fmt);
|
|
void SetObserver(CaptureVideoObserver * );
|
|
int InitCap();
|
|
int Process(void*) override;
|
|
int Height();
|
|
int Width();
|
|
int InitFilter(const char *filters_descr);
|
|
int InitFilter2(const char *filters_descr);
|
|
|
|
private:
|
|
|
|
IDirect3D9* m_d3d9_dev = nullptr;
|
|
CaptureVideoObserver* mObserver;
|
|
std::thread *mThread;
|
|
AVFormatContext* m_fmt_ctx = NULL;
|
|
AVPacket* packet = NULL;
|
|
AVInputFormat* m_input_fmt = NULL;
|
|
int video_stream = -1;
|
|
AVCodecContext * _codec_ctx= NULL;
|
|
AVFrame* rgb= NULL;
|
|
AVFrame* m_cut_frame = NULL;
|
|
|
|
SwsContext *vsc = NULL;
|
|
int height = 0;
|
|
int width = 0;
|
|
AVFrame* yuv = NULL;
|
|
int frameIndex = 0;
|
|
AVCodecContext* vc = NULL;
|
|
long long duration = 0;
|
|
AVPacket* Encodepacket = NULL;
|
|
int EncodeIndex = 0;
|
|
AVStream* st = NULL;
|
|
long long startpts = 0;
|
|
long long lastpts = 0;
|
|
AVFormatContext * ic = NULL;
|
|
AVCodec* _codec = NULL;
|
|
AVFilterGraph *m_filter_graph;
|
|
|
|
AVFilterContext *m_buffersrc_ctx;
|
|
AVFilterContext *m_buffersink_ctx;
|
|
|
|
|
|
};
|
|
|
|
#endif // SCREEN_CAPTURE_H
|
|
|