diff --git a/src/media/audio/audio_rtp_session.cpp b/src/media/audio/audio_rtp_session.cpp index ae2b4d17ce5c34e277003fd8f62038f1f6037849..7d44261ddedd4dec891059231f7ee01d81ccf514 100644 --- a/src/media/audio/audio_rtp_session.cpp +++ b/src/media/audio/audio_rtp_session.cpp @@ -116,9 +116,9 @@ AudioSender::setup(SocketPair& socketPair) return false; } - std::string sdp; - audioEncoder_->print_sdp(sdp); - RING_DBG("\n%s", sdp.c_str()); +#ifdef DEBUG_SDP + audioEncoder_->print_sdp(); +#endif return true; } diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp index 6ad69c3d65db5aa9cab0feb46f1f60f7b374d87d..6705bdeac1221f96b2a659404c0fec3f6550e875 100644 --- a/src/media/media_encoder.cpp +++ b/src/media/media_encoder.cpp @@ -33,9 +33,10 @@ #include <algorithm> #include <thread> // hardware_concurrency -namespace ring { +// Define following line if you need to debug libav SDP +//#define DEBUG_SDP 1 -using std::string; +namespace ring { MediaEncoder::MediaEncoder() : outputCtx_(avformat_alloc_context()) @@ -496,21 +497,25 @@ int MediaEncoder::flush() return ret; } -void MediaEncoder::print_sdp(std::string &sdp_) +std::string +MediaEncoder::print_sdp() { /* theora sdp can be huge */ const auto sdp_size = outputCtx_->streams[0]->codec->extradata_size + 2048; + std::string result; std::string sdp(sdp_size, '\0'); av_sdp_create(&outputCtx_, 1, &(*sdp.begin()), sdp_size); std::istringstream iss(sdp); - string line; - sdp_ = ""; + std::string line; while (std::getline(iss, line)) { /* strip windows line ending */ line = line.substr(0, line.length() - 1); - sdp_ += line + "\n"; + result += line + "\n"; } - RING_DBG("Sending SDP: \n%s", sdp_.c_str()); +#ifdef DEBUG_SDP + RING_DBG("Sending SDP:\n%s", result.c_str()); +#endif + return result; } void MediaEncoder::prepareEncoderContext(bool is_video) diff --git a/src/media/media_encoder.h b/src/media/media_encoder.h index 01f34890669167ee3362ed6b7d8177e0b9d31994..d6458fefeec94b782674a76f28303df856858199 100644 --- a/src/media/media_encoder.h +++ b/src/media/media_encoder.h @@ -72,7 +72,7 @@ public: int encode_audio(const AudioBuffer &input); int flush(); - void print_sdp(std::string &sdp_); + std::string print_sdp(); /* getWidth and getHeight return size of the encoded frame. * Values have meaning only after openOutput call. diff --git a/src/media/video/video_sender.cpp b/src/media/video/video_sender.cpp index 979953826f1dea872361195a6e76bba549ca5898..0d30f4648242fba37af481242c322ba8c5c2da9f 100644 --- a/src/media/video/video_sender.cpp +++ b/src/media/video/video_sender.cpp @@ -47,13 +47,12 @@ VideoSender::VideoSender(const std::string& dest, const DeviceParams& dev, videoEncoder_->setIOContext(muxContext_); videoEncoder_->startIO(); - videoEncoder_->print_sdp(sdp_); + videoEncoder_->print_sdp(); } VideoSender::~VideoSender() { videoEncoder_->flush(); - } diff --git a/src/media/video/video_sender.h b/src/media/video/video_sender.h index e5a4511fbfa70644299c7cdb15bfd0609f0bf439..6ea7214aa3ab7ccea8e9a10b72f021abdd8fa02c 100644 --- a/src/media/video/video_sender.h +++ b/src/media/video/video_sender.h @@ -50,7 +50,6 @@ public: ~VideoSender(); - std::string getSDP() const { return sdp_; } void forceKeyFrame(); // as VideoFramePassiveReader @@ -77,7 +76,6 @@ private: std::atomic<int> forceKeyFrame_ {KEYFRAMES_AT_START}; int keyFrameFreq_ {0}; // Set keyframe rate, 0 to disable auto-keyframe. Computed in constructor int64_t frameNumber_ = 0; - std::string sdp_ = ""; }; }} // namespace ring::video