Rtspvideoplugin

extern "C" __declspec(dllexport) void* CreateRTSPPlayer() return new FFmpegRTSPDecoder(); __declspec(dllexport) bool OpenStream(void* player, const char* url) return ((FFmpegRTSPDecoder*)player)->open(url);

bool readFrame(uint8_t** outRGB, int* width, int* height) AVPacket pkt; if (av_read_frame(m_fmtCtx, &pkt) < 0) return false; if (avcodec_send_packet(m_codecCtx, &pkt) == 0) while (avcodec_receive_frame(m_codecCtx, m_frame) == 0) // Convert YUV to RGB if (!m_swsCtx) m_swsCtx = sws_getContext(m_frame->width, m_frame->height, m_frame->format, m_frame->width, m_frame->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, nullptr, nullptr, nullptr); *width = m_frame->width; *height = m_frame->height; sws_scale(m_swsCtx, m_frame->data, m_frame->linesize, 0, m_frame->height, outRGB, &m_frame->linesize[0]); av_packet_unref(&pkt); return true; av_packet_unref(&pkt); return false; rtspvideoplugin

public class RTSPVideoSource : MonoBehaviour [DllImport("RTSPPlugin")] private static extern System.IntPtr CreateRTSPPlayer(); [DllImport("RTSPPlugin")] private static extern bool OpenStream(System.IntPtr player, string url); private System.IntPtr player; private Texture2D videoTexture; __declspec(dllexport) bool OpenStream(void* player

RTSPVideoPlugin() = default; ~RTSPVideoPlugin() stop(); const char* url) return ((FFmpegRTSPDecoder*)player)-&gt

int m_rtpSocket; std::thread m_thread; bool m_running = false; std::string m_url; FrameCallback m_callback; ; extern "C" #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h>

Client (Plugin) Server (Camera) |--- OPTIONS ---------------->| |<--- 200 OK -----------------| |--- DESCRIBE --------------->| |<--- SDP (Session Description)| |--- SETUP (client_port)----->| |<--- 200 OK (server_port)----| |--- PLAY ------------------->| |<--- 200 OK -----------------| |<--- RTP/UDP Stream ---------| 3.1 Minimal RTSP Client Core // RTSPClient.h #include <string> #include <functional> #include <thread> #include <cstring> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> class RTSPVideoPlugin public: using FrameCallback = std::function<void(uint8_t* data, int width, int height, int stride)>;