Skip to content
Snippets Groups Projects
Commit 8e1cae02 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #30408: video: fix memory leak

VideoEncoder need not be allocated dynamically.
parent fafcd55e
No related branches found
No related tags found
No related merge requests found
...@@ -56,16 +56,19 @@ VideoSender::VideoSender(const std::string &id, ...@@ -56,16 +56,19 @@ VideoSender::VideoSender(const std::string &id,
, sdp_() , sdp_()
{ setup(); } { setup(); }
VideoSender::~VideoSender()
{
delete muxContext_;
}
bool VideoSender::setup() bool VideoSender::setup()
{ {
const char *enc_name = args_["codec"].c_str(); const char *enc_name = args_["codec"].c_str();
videoEncoder_ = new VideoEncoder();
/* Encoder setup */ /* Encoder setup */
if (!args_["width"].empty()) { if (!args_["width"].empty()) {
const char *s = args_["width"].c_str(); const char *s = args_["width"].c_str();
videoEncoder_->setOption("width", s); videoEncoder_.setOption("width", s);
} else { } else {
ERROR("width option not set"); ERROR("width option not set");
return false; return false;
...@@ -73,39 +76,39 @@ bool VideoSender::setup() ...@@ -73,39 +76,39 @@ bool VideoSender::setup()
if (!args_["height"].empty()) { if (!args_["height"].empty()) {
const char *s = args_["height"].c_str(); const char *s = args_["height"].c_str();
videoEncoder_->setOption("height", s); videoEncoder_.setOption("height", s);
} else { } else {
ERROR("height option not set"); ERROR("height option not set");
return false; return false;
} }
videoEncoder_->setOption("bitrate", args_["bitrate"].c_str()); videoEncoder_.setOption("bitrate", args_["bitrate"].c_str());
if (!args_["framerate"].empty()) if (!args_["framerate"].empty())
videoEncoder_->setOption("framerate", args_["framerate"].c_str()); videoEncoder_.setOption("framerate", args_["framerate"].c_str());
if (!args_["parameters"].empty()) if (!args_["parameters"].empty())
videoEncoder_->setOption("parameters", args_["parameters"].c_str()); videoEncoder_.setOption("parameters", args_["parameters"].c_str());
if (!args_["payload_type"].empty()) { if (!args_["payload_type"].empty()) {
DEBUG("Writing stream header for payload type %s", DEBUG("Writing stream header for payload type %s",
args_["payload_type"].c_str()); args_["payload_type"].c_str());
videoEncoder_->setOption("payload_type", args_["payload_type"].c_str()); videoEncoder_.setOption("payload_type", args_["payload_type"].c_str());
} }
if (videoEncoder_->openOutput(enc_name, "rtp", args_["destination"].c_str(), if (videoEncoder_.openOutput(enc_name, "rtp", args_["destination"].c_str(),
NULL)) { NULL)) {
ERROR("encoder openOutput() failed"); ERROR("encoder openOutput() failed");
return false; return false;
} }
videoEncoder_->setIOContext(muxContext_); videoEncoder_.setIOContext(muxContext_);
if (videoEncoder_->startIO()) { if (videoEncoder_.startIO()) {
ERROR("encoder start failed"); ERROR("encoder start failed");
return false; return false;
} }
videoEncoder_->print_sdp(sdp_); videoEncoder_.print_sdp(sdp_);
return true; return true;
} }
...@@ -116,7 +119,7 @@ void VideoSender::encodeAndSendVideo(VideoFrame& input_frame) ...@@ -116,7 +119,7 @@ void VideoSender::encodeAndSendVideo(VideoFrame& input_frame)
if (is_keyframe) if (is_keyframe)
atomic_decrement(&forceKeyFrame_); atomic_decrement(&forceKeyFrame_);
if (videoEncoder_->encode(input_frame, is_keyframe, frameNumber_++) < 0) if (videoEncoder_.encode(input_frame, is_keyframe, frameNumber_++) < 0)
ERROR("encoding failed"); ERROR("encoding failed");
} }
......
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
VideoSender(const std::string &id, VideoSender(const std::string &id,
const std::map<std::string, std::string> &args, const std::map<std::string, std::string> &args,
SocketPair& socketPair); SocketPair& socketPair);
virtual ~VideoSender();
std::string getSDP() const { return sdp_; } std::string getSDP() const { return sdp_; }
void forceKeyFrame(); void forceKeyFrame();
...@@ -66,7 +67,7 @@ private: ...@@ -66,7 +67,7 @@ private:
std::map<std::string, std::string> args_; std::map<std::string, std::string> args_;
const std::string &id_; const std::string &id_;
VideoEncoder *videoEncoder_; VideoEncoder videoEncoder_;
int forceKeyFrame_; int forceKeyFrame_;
int frameNumber_; int frameNumber_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment