From d0f47da1f78854b2059773642b2cd797e3eea3c1 Mon Sep 17 00:00:00 2001 From: Michel Promonet Date: Sat, 22 Sep 2018 19:27:15 +0200 Subject: [PATCH] add thread name for debugging --- inc/rtspaudiocapturer.h | 11 ++++------- inc/rtspvideocapturer.h | 16 +++++++--------- live555helper | 2 +- src/PeerConnectionManager.cpp | 2 +- src/rtspaudiocapturer.cpp | 15 ++++++++++++++- src/rtspvideocapturer.cpp | 35 +++++++---------------------------- 6 files changed, 34 insertions(+), 47 deletions(-) mode change 100644 => 100755 inc/rtspaudiocapturer.h mode change 100644 => 100755 inc/rtspvideocapturer.h mode change 100644 => 100755 src/rtspaudiocapturer.cpp diff --git a/inc/rtspaudiocapturer.h b/inc/rtspaudiocapturer.h old mode 100644 new mode 100755 index 007a156a..ee5d2fe3 --- a/inc/rtspaudiocapturer.h +++ b/inc/rtspaudiocapturer.h @@ -19,8 +19,8 @@ class RTSPAudioSource : public webrtc::Notifier, public rtc::Thread, public RTSPConnection::Callback { public: - static rtc::scoped_refptr Create(rtc::scoped_refptr audioDecoderFactory, const std::string & uri) { - rtc::scoped_refptr source(new rtc::RefCountedObject(audioDecoderFactory, uri)); + static rtc::scoped_refptr Create(rtc::scoped_refptr audioDecoderFactory, const std::string & uri, const std::map & opts) { + rtc::scoped_refptr source(new rtc::RefCountedObject(audioDecoderFactory, uri, opts)); return source; } @@ -44,11 +44,8 @@ class RTSPAudioSource : public webrtc::Notifier, p virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime); protected: - RTSPAudioSource(rtc::scoped_refptr audioDecoderFactory, const std::string & uri) - : m_connection(m_env, this, uri.c_str(), 5, RTSPConnection::RTPUDPUNICAST, rtc::LogMessage::GetLogToDebug()<=3) - , m_factory(audioDecoderFactory), m_sink(NULL), m_freq(8000), m_channel(1) { rtc::Thread::Start(); } - virtual ~RTSPAudioSource() override { m_env.stop(); rtc::Thread::Stop(); } - + RTSPAudioSource(rtc::scoped_refptr audioDecoderFactory, const std::string & uri, const std::map & opts); + virtual ~RTSPAudioSource(); private: Environment m_env; diff --git a/inc/rtspvideocapturer.h b/inc/rtspvideocapturer.h old mode 100644 new mode 100755 index 3ea695b0..e180db48 --- a/inc/rtspvideocapturer.h +++ b/inc/rtspvideocapturer.h @@ -45,15 +45,13 @@ class RTSPVideoCapturer : public cricket::VideoCapturer, public RTSPConnection:: // overide RTSPConnection::Callback virtual bool onNewSession(const char* id, const char* media, const char* codec, const char* sdp); virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime); - virtual void onConnectionTimeout(RTSPConnection& connection) { - connection.start(); - } - virtual void onDataTimeout(RTSPConnection& connection) { - connection.start(); - } - virtual void onError(RTSPConnection& connection,const char* erro) { - connection.start(1); - } + virtual void onConnectionTimeout(RTSPConnection& connection) { + connection.start(); + } + virtual void onDataTimeout(RTSPConnection& connection) { + connection.start(); + } + virtual void onError(RTSPConnection& connection,const char* erro); // overide webrtc::DecodedImageCallback virtual int32_t Decoded(webrtc::VideoFrame& decodedImage); diff --git a/live555helper b/live555helper index 15dddf1b..de09337b 160000 --- a/live555helper +++ b/live555helper @@ -1 +1 @@ -Subproject commit 15dddf1bbc32d51d04ab1447b31d3d98b7a069f7 +Subproject commit de09337bcf8a23ca15f57ce21f88ddeb5ab3378b diff --git a/src/PeerConnectionManager.cpp b/src/PeerConnectionManager.cpp index 9f6f6d25..cee7efe5 100755 --- a/src/PeerConnectionManager.cpp +++ b/src/PeerConnectionManager.cpp @@ -793,7 +793,7 @@ rtc::scoped_refptr PeerConnectionManager::CreateAud { #ifdef HAVE_LIVE555 audioDeviceModule_->Terminate(); - audioSource = RTSPAudioSource::Create(audioDecoderfactory_, audiourl); + audioSource = RTSPAudioSource::Create(audioDecoderfactory_, audiourl, opts); #endif } else if (std::regex_match("audiocap://",m_publishFilter)) diff --git a/src/rtspaudiocapturer.cpp b/src/rtspaudiocapturer.cpp old mode 100644 new mode 100755 index 2058ea01..d1031bc7 --- a/src/rtspaudiocapturer.cpp +++ b/src/rtspaudiocapturer.cpp @@ -17,6 +17,19 @@ #include "rtspaudiocapturer.h" +RTSPAudioSource::RTSPAudioSource(rtc::scoped_refptr audioDecoderFactory, const std::string & uri, const std::map & opts) + : m_connection(m_env, this, uri.c_str(), RTSPConnection::decodeTimeoutOption(opts), RTSPConnection::decodeRTPTransport(opts), rtc::LogMessage::GetLogToDebug()<=3) + , m_factory(audioDecoderFactory), m_sink(NULL), m_freq(8000), m_channel(1) { + SetName("RTSPAudioSource", NULL); + rtc::Thread::Start(); +} + +RTSPAudioSource::~RTSPAudioSource() { + m_env.stop(); + rtc::Thread::Stop(); +} + + // overide RTSPConnection::Callback bool RTSPAudioSource::onNewSession(const char* id, const char* media, const char* codec, const char* sdp) { @@ -97,7 +110,7 @@ bool RTSPAudioSource::onData(const char* id, unsigned char* buffer, ssize_t size RTC_LOG(LS_ERROR) << "RTSPAudioSource::onData error:No Audio decoder"; } } else { - RTC_LOG(LS_ERROR) << "RTSPAudioSource::onData error:No Audio Sink"; + RTC_LOG(LS_VERBOSE) << "RTSPAudioSource::onData error:No Audio Sink"; } return success; } diff --git a/src/rtspvideocapturer.cpp b/src/rtspvideocapturer.cpp index bbe7f595..4c82d8e5 100755 --- a/src/rtspvideocapturer.cpp +++ b/src/rtspvideocapturer.cpp @@ -32,35 +32,8 @@ uint8_t marker[] = { 0, 0, 0, 1}; -int decodeTimeoutOption(const std::map & opts) { - int timeout = 10; - if (opts.find("timeout") != opts.end()) - { - std::string timeoutString = opts.at("timeout"); - timeout = std::stoi(timeoutString); - } - return timeout; -} - -int decodeRTPTransport(const std::map & opts) -{ - int rtptransport = RTSPConnection::RTPUDPUNICAST; - if (opts.find("rtptransport") != opts.end()) - { - std::string rtpTransportString = opts.at("rtptransport"); - if (rtpTransportString == "tcp") { - rtptransport = RTSPConnection::RTPOVERTCP; - } else if (rtpTransportString == "http") { - rtptransport = RTSPConnection::RTPOVERHTTP; - } else if (rtpTransportString == "multicast") { - rtptransport = RTSPConnection::RTPUDPMULTICAST; - } - } - return rtptransport; -} - RTSPVideoCapturer::RTSPVideoCapturer(const std::string & uri, const std::map & opts) - : m_connection(m_env, this, uri.c_str(), decodeTimeoutOption(opts), decodeRTPTransport(opts), rtc::LogMessage::GetLogToDebug()<=3), + : m_connection(m_env, this, uri.c_str(), RTSPConnection::decodeTimeoutOption(opts), RTSPConnection::decodeRTPTransport(opts), rtc::LogMessage::GetLogToDebug()<=3), m_width(0), m_height(0), m_fps(0) { RTC_LOG(INFO) << "RTSPVideoCapturer " << uri ; @@ -230,6 +203,11 @@ bool RTSPVideoCapturer::onData(const char* id, unsigned char* buffer, ssize_t si return (res == 0); } +void RTSPVideoCapturer::onError(RTSPConnection& connection, const char* error) { + RTC_LOG(LS_ERROR) << "RTSPVideoCapturer:onError url:" << m_connection.getUrl() << " error:" << error; + connection.start(1); +} + void RTSPVideoCapturer::DecoderThread() { while (IsRunning()) { @@ -313,6 +291,7 @@ cricket::CaptureState RTSPVideoCapturer::Start(const cricket::VideoFormat& forma RTC_LOG(INFO) << "RTSPVideoCapturer::start format" << format.ToString(); SetCaptureFormat(&format); SetCaptureState(cricket::CS_RUNNING); + SetName("RTSPVideoCapturer", NULL); rtc::Thread::Start(); m_decoderthread = std::thread(&RTSPVideoCapturer::DecoderThread, this); return cricket::CS_RUNNING;