From 52d925e01ee1b1514ae9c17721deefc912a42f42 Mon Sep 17 00:00:00 2001 From: "Sung Wook Moon (iMac)" Date: Thu, 11 Jul 2019 17:51:07 +0900 Subject: [PATCH 1/4] Add RTSP Support --- camera/gstCamera.cpp | 63 ++++++++++++++++++++++++++++---------------- camera/gstCamera.h | 3 ++- 2 files changed, 43 insertions(+), 23 deletions(-) mode change 100644 => 100755 camera/gstCamera.cpp mode change 100644 => 100755 camera/gstCamera.h diff --git a/camera/gstCamera.cpp b/camera/gstCamera.cpp old mode 100644 new mode 100755 index 282c975d..0fff7b68 --- a/camera/gstCamera.cpp +++ b/camera/gstCamera.cpp @@ -43,6 +43,7 @@ const char* gstCameraSrcToString( gstCameraSrc src ) if( src == GST_SOURCE_NVCAMERA ) return "GST_SOURCE_NVCAMERA"; else if( src == GST_SOURCE_NVARGUS ) return "GST_SOURCE_NVARGUS"; else if( src == GST_SOURCE_V4L2 ) return "GST_SOURCE_V4L2"; + else if( src == GST_SOURCE_RTSP ) return "GST_SOURCE_RTSP"; return "UNKNOWN"; } @@ -404,12 +405,13 @@ bool gstCamera::buildLaunchStr( gstCameraSrc src ) // nvvidconv flip-method=2 ! 'video/x-raw(memory:NVMM), format=(string)I420' ! fakesink silent=false -v // #define CAPS_STR "video/x-raw(memory:NVMM), width=(int)2592, height=(int)1944, format=(string)I420, framerate=(fraction)30/1" // #define CAPS_STR "video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1" + + //rtspsrc location=rtsp://10.0.1.103/Streaming/Channels/103 ! queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! appsink name=mysink + std::ostringstream ss; - if( csiCamera() && src != GST_SOURCE_V4L2 ) + if( csiCamera() && (src == GST_SOURCE_NVARGUS || src == GST_SOURCE_NVCAMERA) ) { - mSource = src; // store camera source method - #if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5 // if JetPack 3.1-3.3 (different flip-method) const int flipMethod = 0; // Xavier (w/TRT5) camera is mounted inverted #else @@ -423,7 +425,7 @@ bool gstCamera::buildLaunchStr( gstCameraSrc src ) ss << "video/x-raw ! appsink name=mysink"; } - else + else if ( src == GST_SOURCE_V4L2 ) { ss << "v4l2src device=" << mCameraStr << " ! "; ss << "video/x-raw, width=(int)" << mWidth << ", height=(int)" << mHeight << ", "; @@ -435,8 +437,12 @@ bool gstCamera::buildLaunchStr( gstCameraSrc src ) #endif ss << "appsink name=mysink"; - - mSource = GST_SOURCE_V4L2; + } + else if ( src == GST_SOURCE_RTSP ) + { + ss << "rtspsrc location=" << mCameraStr << " ! "; + ss << "queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! videoconvert ! video/x-raw, format=RGB ! videoconvert ! "; + ss << "appsink name=mysink"; } mLaunchStr = ss.str(); @@ -462,22 +468,30 @@ bool gstCamera::parseCameraStr( const char* camera ) // check if the string is a V4L2 device const char* prefixV4L2 = "/dev/video"; - const size_t prefixLength = strlen(prefixV4L2); + // check if the string is a rtsp streaming + const char* prefixRTSP = "rtsp://"; + const size_t cameraLength = strlen(camera); - if( cameraLength < prefixLength ) - { + if( cameraLength <= 2 ) + { const int result = sscanf(camera, "%i", &mSensorCSI); if( result == 1 && mSensorCSI >= 0 ) return true; } - else if( strncmp(camera, prefixV4L2, prefixLength) == 0 ) + else if( strncmp(camera, prefixV4L2, strlen(prefixV4L2)) == 0 ) { + mSource = GST_SOURCE_V4L2; + return true; + } + else if( strncmp(camera, prefixRTSP, strlen(prefixRTSP)) == 0 ) + { + mSource = GST_SOURCE_RTSP; return true; } - printf(LOG_GSTREAMER "gstCamera::Create('%s') -- invalid camera device requested\n", camera); + printf(LOG_GSTREAMER "gstCamera::Create('%s') -- invalid camera device requested... \n", camera); return false; } @@ -504,20 +518,25 @@ gstCamera* gstCamera::Create( uint32_t width, uint32_t height, const char* camer cam->mDepth = cam->csiCamera() ? 12 : 24; // NV12 or RGB cam->mSize = (width * height * cam->mDepth) / 8; - if( !cam->init(GST_SOURCE_NVARGUS) ) + if(cam->mSource == GST_SOURCE_V4L2 || cam->mSource == GST_SOURCE_RTSP) + { + if( cam->mSensorCSI >= 0 ) + cam->mSensorCSI = -1; + if( !cam->init(cam->mSource) ) + { + printf(LOG_GSTREAMER "failed to init gstCamera (%s, camera %s)\n", gstCameraSrcToString(cam->mSource), cam->mCameraStr.c_str()); + return NULL; + } + } + else { - printf(LOG_GSTREAMER "failed to init gstCamera (GST_SOURCE_NVARGUS, camera %s)\n", cam->mCameraStr.c_str()); - - if( !cam->init(GST_SOURCE_NVCAMERA) ) + cam->mSource = GST_SOURCE_NVARGUS; + if( !cam->init(cam->mSource) ) { - printf(LOG_GSTREAMER "failed to init gstCamera (GST_SOURCE_NVCAMERA, camera %s)\n", cam->mCameraStr.c_str()); - - if( cam->mSensorCSI >= 0 ) - cam->mSensorCSI = -1; - - if( !cam->init(GST_SOURCE_V4L2) ) + cam->mSource = GST_SOURCE_NVCAMERA; + if( !cam->init(cam->mSource) ) { - printf(LOG_GSTREAMER "failed to init gstCamera (GST_SOURCE_V4L2, camera %s)\n", cam->mCameraStr.c_str()); + printf(LOG_GSTREAMER "failed to init gstCamera (%s, camera %s)\n", gstCameraSrcToString(cam->mSource), cam->mCameraStr.c_str()); return NULL; } } diff --git a/camera/gstCamera.h b/camera/gstCamera.h old mode 100644 new mode 100755 index e148c152..b8ccc0d8 --- a/camera/gstCamera.h +++ b/camera/gstCamera.h @@ -42,7 +42,8 @@ enum gstCameraSrc { GST_SOURCE_NVCAMERA, /* use nvcamerasrc element */ GST_SOURCE_NVARGUS, /* use nvargussrc element */ - GST_SOURCE_V4L2 /* use v4l2src element */ + GST_SOURCE_V4L2, /* use v4l2src element */ + GST_SOURCE_RTSP /* use rtspsrc element */ }; /** From 78cbb5b70e84712eda5fcb269bfa3361f41856b5 Mon Sep 17 00:00:00 2001 From: "Sung Wook Moon (iMac)" Date: Mon, 15 Jul 2019 14:05:41 +0900 Subject: [PATCH 2/4] testing rtsp parser --- camera/gstCamera.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/camera/gstCamera.cpp b/camera/gstCamera.cpp index 0fff7b68..0941c4a3 100755 --- a/camera/gstCamera.cpp +++ b/camera/gstCamera.cpp @@ -440,8 +440,12 @@ bool gstCamera::buildLaunchStr( gstCameraSrc src ) } else if ( src == GST_SOURCE_RTSP ) { - ss << "rtspsrc location=" << mCameraStr << " ! "; - ss << "queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! videoconvert ! video/x-raw, format=RGB ! videoconvert ! "; + ss << "rtspsrc location=" << mCameraStr << " latency=0 ! "; + //ss << "queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! videoconvert ! video/x-raw, format=RGB ! videoconvert ! "; + ss << "decodebin ! "; + ss << "nvvidconv ! "; + ss << "video/x-raw, format=I420, width=" << mWidth << ", height=" << mHeight << " ! "; + //videoscale ! video/x-raw,width=1280,height=800 ss << "appsink name=mysink"; } From af6e9c2c79fc8075b745e1add5c86df1e5f2cc97 Mon Sep 17 00:00:00 2001 From: nano Date: Mon, 15 Jul 2019 14:41:50 +0900 Subject: [PATCH 3/4] add resize feature but slow, commented --- camera/gstCamera.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/camera/gstCamera.cpp b/camera/gstCamera.cpp index 0941c4a3..7118e46d 100755 --- a/camera/gstCamera.cpp +++ b/camera/gstCamera.cpp @@ -441,11 +441,10 @@ bool gstCamera::buildLaunchStr( gstCameraSrc src ) else if ( src == GST_SOURCE_RTSP ) { ss << "rtspsrc location=" << mCameraStr << " latency=0 ! "; - //ss << "queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! videoconvert ! video/x-raw, format=RGB ! videoconvert ! "; - ss << "decodebin ! "; - ss << "nvvidconv ! "; - ss << "video/x-raw, format=I420, width=" << mWidth << ", height=" << mHeight << " ! "; - //videoscale ! video/x-raw,width=1280,height=800 + ss << "queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! "; + ss << "videoconvert ! video/x-raw, format=RGB ! "; + //ss << "videoconvert ! videoscale ! video/x-raw, format=RGB, width=" << mWidth << ", height=" << mHeight << " ! "; + ss << "appsink name=mysink"; } From 6d05acdaca4cc7fccc9ae9de198af093912821e2 Mon Sep 17 00:00:00 2001 From: nano Date: Mon, 15 Jul 2019 15:15:55 +0900 Subject: [PATCH 4/4] removed rtsp latency=0 caused delay frame --- camera/gstCamera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera/gstCamera.cpp b/camera/gstCamera.cpp index 7118e46d..60737856 100755 --- a/camera/gstCamera.cpp +++ b/camera/gstCamera.cpp @@ -440,7 +440,7 @@ bool gstCamera::buildLaunchStr( gstCameraSrc src ) } else if ( src == GST_SOURCE_RTSP ) { - ss << "rtspsrc location=" << mCameraStr << " latency=0 ! "; + ss << "rtspsrc location=" << mCameraStr << " ! "; ss << "queue ! rtph264depay ! h264parse ! queue ! omxh264dec ! "; ss << "videoconvert ! video/x-raw, format=RGB ! "; //ss << "videoconvert ! videoscale ! video/x-raw, format=RGB, width=" << mWidth << ", height=" << mHeight << " ! ";