You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
6.4 KiB
228 lines
6.4 KiB
#ifndef __VIDEOLIVE555AVLIBSOURCE_H_INCL__
|
|
#define __VIDEOLIVE555AVLIBSOURCE_H_INCL__
|
|
|
|
#ifndef LRF_PROXY_ONLY
|
|
|
|
#include "../../../alg/generic/md5.h"
|
|
#include "../../../components/base/basicLIBAV.h"
|
|
#include "../../../components/base/basicLogCollection.h"
|
|
#include "../../../components/base/basicMediaSource.h"
|
|
#include "../../../components/base/basicSettings.h"
|
|
#include "../../../components/base/basicThread.h"
|
|
|
|
#include <BasicUsageEnvironment.hh>
|
|
#include <liveMedia/liveMedia.hh>
|
|
|
|
#define RTSP_CLIENT_VERBOSITY_LEVEL 1
|
|
#define INBUF_SIZE 40960
|
|
#define AUDIO_INBUF_SIZE 20480
|
|
#define AUDIO_REFILL_THRESH 4096
|
|
#define DUMMY_SINK_RECEIVE_BUFFER_SIZE 400000
|
|
#define REQUEST_STREAMING_OVER_TCP True
|
|
|
|
class videoLIVE555Source;
|
|
|
|
class StreamClientState
|
|
{
|
|
public:
|
|
|
|
StreamClientState();
|
|
virtual ~StreamClientState();
|
|
|
|
public:
|
|
|
|
MediaSubsessionIterator * iter;
|
|
MediaSession * session;
|
|
MediaSubsession * subsession;
|
|
TaskToken streamTimerTask;
|
|
double duration;
|
|
};
|
|
|
|
class CustomRTSPClient : public RTSPClient
|
|
{
|
|
private:
|
|
|
|
videoLIVE555Source * session;
|
|
StreamClientState streamClientState;
|
|
|
|
public:
|
|
|
|
static CustomRTSPClient * createNew(videoLIVE555Source * session, UsageEnvironment & env, const char * rtspURL, int verbosityLevel = 0, const char * applicationName = NULL, portNumBits tunnelOverHTTPPortNum = 0);
|
|
|
|
StreamClientState & getStreamClientState()
|
|
{
|
|
return this->streamClientState;
|
|
}
|
|
|
|
videoLIVE555Source * getSession()
|
|
{
|
|
return this->session;
|
|
}
|
|
|
|
virtual ~CustomRTSPClient();
|
|
|
|
private:
|
|
|
|
CustomRTSPClient(videoLIVE555Source * session, UsageEnvironment & env, const char * rtspURL, int verbosityLevel, const char * applicationName, portNumBits tunnelOverHTTPPortNum);
|
|
};
|
|
|
|
class DummySink : public MediaSink
|
|
{
|
|
public:
|
|
|
|
static DummySink * createNew(videoLIVE555Source * session, UsageEnvironment & env, MediaSubsession & subsession, // identifies the kind of data that's being received
|
|
const char * streamId = NULL, int w = -1, int h = -1, int ww = -1, int hh = -1); // identifies the stream itself (optional)
|
|
virtual ~DummySink();
|
|
|
|
private:
|
|
|
|
basicLogCollection * m_pLog;
|
|
AVCodecID m_eCodecProbe;
|
|
cv::Mat * m_pRGB;
|
|
|
|
int m_nInWidth;
|
|
int m_nInHeight;
|
|
int m_nOutWidth;
|
|
int m_nOutHeight;
|
|
|
|
DummySink(videoLIVE555Source * session, UsageEnvironment & env, MediaSubsession & subsession, const char * streamId, int w, int h, int ww, int hh);
|
|
// called only by "createNew()"
|
|
|
|
static void afterGettingFrame(void * clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds);
|
|
void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds);
|
|
// void saveFrameToFile()
|
|
private:
|
|
|
|
// redefined virtual functions:
|
|
virtual Boolean continuePlaying();
|
|
|
|
public:
|
|
|
|
void setSprop(const u_int8_t * prop, unsigned size);
|
|
|
|
private:
|
|
|
|
videoLIVE555Source * m_pSession;
|
|
uint8_t * m_pReceiveBuffer;
|
|
uint8_t * m_pReceiveBufferAV;
|
|
MediaSubsession & m_sSubSession;
|
|
char * m_pStreamId;
|
|
H264or5VideoFileSink * qtOut;
|
|
FILE * m_pOutFile[2];
|
|
uint8_t m_nCurrentOutFile;
|
|
// const avlib v6
|
|
const AVCodec * m_pCodec;
|
|
AVCodecContext * m_pCodecContext;
|
|
|
|
AVCodec * m_pOutCodec;
|
|
AVCodecContext * m_pOutCodecContext;
|
|
AVFormatContext * m_pOutFormatCtx;
|
|
AVDictionary * m_pOutFormatOpts;
|
|
AVStream * m_pOutStream;
|
|
uint8_t * m_pH264;
|
|
|
|
uint64_t m_iFrameIndex;
|
|
AVFrame * m_pFrame;
|
|
AVFrame * m_pRGBFrame;
|
|
SwsContext * m_pSwsContext;
|
|
|
|
uint8_t m_aInBuf[INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
|
|
// char buf[1024];
|
|
AVPacket m_sAvPkt;
|
|
};
|
|
|
|
class videoLIVE555Source : public basicMediaSource, public basicThread
|
|
{
|
|
private:
|
|
|
|
basicLogCollection * m_pLog;
|
|
void * m_pOpaque;
|
|
bool m_bIsParamsSet;
|
|
|
|
int m_nInWidth;
|
|
int m_nInHeight;
|
|
int m_nOutWidth;
|
|
int m_nOutHeight;
|
|
MS_WORK_MODE m_eWM;
|
|
|
|
StreamClientState streamClientState;
|
|
|
|
virtual Boolean continuePlaying();
|
|
uint8_t * fReceiveBuffer;
|
|
TaskScheduler * m_pScheduler;
|
|
|
|
UsageEnvironment * m_pUsageEnvironment;
|
|
MediaSession * m_pMediaSession;
|
|
|
|
volatile char _eventLoopWatchVariable;
|
|
|
|
CustomRTSPClient * m_pRtspClient;
|
|
DummySink * m_pSink;
|
|
MediaSubsession * fSubsession;
|
|
char * fStreamId;
|
|
|
|
static void continueAfterDESCRIBE(RTSPClient * rtspClient, int resultCode, char * resultString);
|
|
static void continueAfterSETUP(RTSPClient * rtspClient, int resultCode, char * resultString);
|
|
static void continueAfterPLAY(RTSPClient * rtspClient, int resultCode, char * resultString);
|
|
// Other event handler functions:
|
|
static void subsessionAfterPlaying(void * clientData);
|
|
|
|
// called when a stream's subsession (e.g., audio or video substream) ends
|
|
static void subsessionByeHandler(void * clientData); //, char const* reason );
|
|
// called when a RTCP "BYE" is received for a subsession
|
|
static void streamTimerHandler(void * clientData);
|
|
// The main streaming routine (for each "rtsp://" URL):
|
|
|
|
void openURL(UsageEnvironment & env, const char * progName, const char * rtspURL);
|
|
// Used to iterate through each stream's 'subsessions', setting up each one:
|
|
void setupNextSubsession(RTSPClient * rtspClient);
|
|
|
|
// Used to shut down and close a stream (including its "RTSPClient" object):
|
|
void shutdownStream(RTSPClient * rtspClient, int exitCode = 1);
|
|
|
|
protected:
|
|
|
|
void m_fThreadProc(void);
|
|
|
|
public:
|
|
|
|
static void sessionAfterPlaying(void * clientData);
|
|
|
|
virtual bool _open(CSTR URI, bool ShowDeviceMenu = false, float framerate = -1.0f, int inputPin = -1, int width = -1, int height = -1, int s_width = -1, int s_height = -1);
|
|
virtual bool _close(void);
|
|
virtual bool _stop(void);
|
|
bool isFinished(void);
|
|
|
|
MS_WORK_MODE getWM(void) const
|
|
{
|
|
return m_eWM;
|
|
}
|
|
|
|
void setWM(int M)
|
|
{
|
|
m_eWM = (MS_WORK_MODE) M;
|
|
}
|
|
|
|
MediaStateStatus getStatus(void);
|
|
|
|
explicit videoLIVE555Source(void * opaque = NULL);
|
|
explicit videoLIVE555Source(CSTR URI, void * opaque = NULL, MS_WORK_MODE mode = MS_MODE_DECODE_FRAMES);
|
|
virtual ~videoLIVE555Source();
|
|
|
|
bool setSize(int Width, int Height);
|
|
bool setProportionalByWidth(int Width);
|
|
bool setProportionalByHeight(int Height);
|
|
bool setFPS(int);
|
|
bool setName(CSTR Name);
|
|
bool setFrameAspectRatio(FrameAspectRatio AspectRatio);
|
|
void consumeFrame(cv::Mat * frm);
|
|
|
|
MediaSession * getMS(void)
|
|
{
|
|
return m_pMediaSession;
|
|
}
|
|
};
|
|
|
|
#endif //!LRF_PROXY_ONLY
|
|
|
|
#endif
|