Commit 8e1cae02 authored by Tristan Matthews's avatar Tristan Matthews

* #30408: video: fix memory leak

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