Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RTSP Support #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions camera/gstCamera.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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
Expand All @@ -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 << ", ";
Expand All @@ -435,8 +437,15 @@ 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 ! ";
ss << "videoconvert ! video/x-raw, format=RGB ! ";
//ss << "videoconvert ! videoscale ! video/x-raw, format=RGB, width=" << mWidth << ", height=" << mHeight << " ! ";

ss << "appsink name=mysink";
}

mLaunchStr = ss.str();
Expand All @@ -462,22 +471,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;
}

Expand All @@ -504,20 +521,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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion camera/gstCamera.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};

/**
Expand Down