Skip to content

Commit

Permalink
add thread name for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Sep 22, 2018
1 parent 014c9c8 commit d0f47da
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 47 deletions.
11 changes: 4 additions & 7 deletions inc/rtspaudiocapturer.h 100644 → 100755
Expand Up @@ -19,8 +19,8 @@

class RTSPAudioSource : public webrtc::Notifier<webrtc::AudioSourceInterface>, public rtc::Thread, public RTSPConnection::Callback {
public:
static rtc::scoped_refptr<RTSPAudioSource> Create(rtc::scoped_refptr<webrtc::AudioDecoderFactory> audioDecoderFactory, const std::string & uri) {
rtc::scoped_refptr<RTSPAudioSource> source(new rtc::RefCountedObject<RTSPAudioSource>(audioDecoderFactory, uri));
static rtc::scoped_refptr<RTSPAudioSource> Create(rtc::scoped_refptr<webrtc::AudioDecoderFactory> audioDecoderFactory, const std::string & uri, const std::map<std::string,std::string> & opts) {
rtc::scoped_refptr<RTSPAudioSource> source(new rtc::RefCountedObject<RTSPAudioSource>(audioDecoderFactory, uri, opts));
return source;
}

Expand All @@ -44,11 +44,8 @@ class RTSPAudioSource : public webrtc::Notifier<webrtc::AudioSourceInterface>, p
virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime);

protected:
RTSPAudioSource(rtc::scoped_refptr<webrtc::AudioDecoderFactory> 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<webrtc::AudioDecoderFactory> audioDecoderFactory, const std::string & uri, const std::map<std::string,std::string> & opts);
virtual ~RTSPAudioSource();

private:
Environment m_env;
Expand Down
16 changes: 7 additions & 9 deletions inc/rtspvideocapturer.h 100644 → 100755
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion live555helper
2 changes: 1 addition & 1 deletion src/PeerConnectionManager.cpp
Expand Up @@ -793,7 +793,7 @@ rtc::scoped_refptr<webrtc::AudioTrackInterface> 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))
Expand Down
15 changes: 14 additions & 1 deletion src/rtspaudiocapturer.cpp 100644 → 100755
Expand Up @@ -17,6 +17,19 @@
#include "rtspaudiocapturer.h"


RTSPAudioSource::RTSPAudioSource(rtc::scoped_refptr<webrtc::AudioDecoderFactory> audioDecoderFactory, const std::string & uri, const std::map<std::string,std::string> & 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) {

Expand Down Expand Up @@ -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;
}
Expand Down
35 changes: 7 additions & 28 deletions src/rtspvideocapturer.cpp
Expand Up @@ -32,35 +32,8 @@

uint8_t marker[] = { 0, 0, 0, 1};

int decodeTimeoutOption(const std::map<std::string,std::string> & 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<std::string,std::string> & 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<std::string,std::string> & 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 ;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d0f47da

Please sign in to comment.