add_library(rtsp_plugin SHARED src/plugin.cpp) target_include_directories(rtsp_plugin PRIVATE $FFMPEG_INCLUDE_DIRS) target_link_libraries(rtsp_plugin $FFMPEG_LIBRARIES) target_compile_definitions(rtsp_plugin PRIVATE -DPLUGIN_EXPORTS)
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> rtspvideoplugin
if (avformat_open_input(&m_fmtCtx, rtspUrl, nullptr, &opts) < 0) return false; if (avformat_find_stream_info(m_fmtCtx, nullptr) < 0) return false; // Find video stream int videoStream = -1; for (int i = 0; i < m_fmtCtx->nb_streams; i++) if (m_fmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) videoStream = i; break; AVCodec* codec = avcodec_find_decoder(m_fmtCtx->streams[videoStream]->codecpar->codec_id); m_codecCtx = avcodec_alloc_context3(codec); avcodec_parameters_to_context(m_codecCtx, m_fmtCtx->streams[videoStream]->codecpar); avcodec_open2(m_codecCtx, codec, nullptr); m_frame = av_frame_alloc(); return true; add_library(rtsp_plugin SHARED src/plugin
; 4.1 Unity Plugin (C++ -> C#) Expose C functions: bool m_running = false