#pragma once //Windows #include #include #include #include using namespace std; extern "C" { #include "libavformat/avformat.h" #include "libavutil/mathematics.h" #include "libavutil/time.h" }; #pragma comment (lib, "ws2_32.lib") #pragma comment (lib, "Secur32.lib") #pragma comment (lib, "Bcrypt.lib") class RtmpPuller { public: class RtmpPullObserver { public : enum ObserverType { Observer_Video = 0, Observer_Audio = 1, }; virtual void OnRtmpFrame(void * dat, uint32_t size) {}; ObserverType mObserverType; }; enum CAP_STATUS { RUNNING = 1, STOP = 2, PAUSE = 3, FAIL = 4, NOSOURCE = 6, }; RtmpPuller(); int ConnectServer(const char *); int StartPull(); int PullData(); int SetObserver(RtmpPullObserver *); CAP_STATUS Status(); AVStream *AudioStream(); private: CAP_STATUS mStatus; AVOutputFormat *mOutFormat = NULL; //Input AVFormatContext and Output AVFormatContext AVFormatContext *mIfmtCtx = NULL; AVPacket pkt; string mRtmpUrl; int mVideoIndex; int mAudioIndex; int mFrameIndex; AVBitStreamFilterContext* mH264bsfc; std::thread *mThread; vector mObserver; AVStream *mAudioStream; AVStream *mVideoStream; mutex mMux; }; int ThreadPull(RtmpPuller*p);