multimedia/client/qt_gl_/yuvgl/media/VideoCoder.h

71 lines
1.6 KiB
C
Raw Normal View History

2020-06-04 15:28:45 +00:00
#pragma once
#ifdef _WIN32
#include "Debuger.h"
#include "CameraCapture.h"
//Windows
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"
};
#else
//Linux...
#ifdef __cplusplus
extern "C"
{
#endif
#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#ifdef __cplusplus
};
#endif
#endif
class VideoCodeObserver {
public:
virtual void OnGetCodeFrame(uint8_t *data, int len) {
Debuger::Debug(L"get one code %d \r\n", len);
}
};
class VideoCoder : public Camera::CameraObserver{
private:
int mWidth;
int mHeight;
unsigned int mDestWidth;
unsigned int mDestHeight;
int mBytePerPixel;
enum AVPixelFormat mInformat;
AVFormatContext *mFormatCtx;
AVOutputFormat *mOutputFmt;
AVStream *mVideoStream;
AVCodecContext *mCodecCtx;
AVCodec *mCodec;
AVPacket mAVPack;
uint8_t *mPitureBuffer;
AVFrame *mFrame;
VideoCodeObserver *mObserver;
public:
int OnBuffer(double dblSampleTime, BYTE * pBuffer, long lBufferSize);
int OnCameraData(uint8_t *dat, uint32_t size) ;
int SetDestPix(uint8_t width,uint8_t height);
VideoCoder(int width,int height,AVPixelFormat formt);
~VideoCoder();
void Encode(uint8_t*src,int size, enum AVPixelFormat format);
void SetOberver(VideoCodeObserver *p) {
this->mObserver = p;
}
void SetOutPutPixel(unsigned int width,unsigned int height);
private:
int flushCoder(AVFormatContext *fmt_ctx, unsigned int stream_index);
int forceYUV420P(uint8_t *src, int size, enum AVPixelFormat format, uint8_t ***dst,int *s);
};