qt_rtmp_demo/media/screen_capture.h

101 lines
2.4 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>
#include <string>
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:
typedef struct{
int width;
int height;
int x;
int y;
}Rect;
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);
int SetStrip(Rect* rect);
int InitEncoder(std::string path);
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;
SwsContext *vsc = NULL;
int mHeight = 0;
int mWidth = 0;
int mWidthCut = 0;
int mHeightCut = 0;
AVFrame* mEncodeYUV = NULL;
int frameIndex = 0;
AVCodecContext* mVideoEncoder = 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;
Rect *mStrip = nullptr;
AVPixelFormat mVideoType = AV_PIX_FMT_NONE;
AVFilterContext *m_buffersrc_ctx;
AVFilterContext *m_buffersink_ctx;
};
#endif // SCREEN_CAPTURE_H