Commit 3fcd87ba authored by Guillaume Roguez's avatar Guillaume Roguez

#28512: fix VideoPacket (init packet and non-free memory) and minor changes.

parent 7b55baf8
......@@ -40,9 +40,10 @@ namespace sfl_video {
VideoPacket::VideoPacket() : packet_(0)
{
packet_ = static_cast<AVPacket *>(av_malloc(sizeof(AVPacket)));
av_init_packet(packet_);
}
VideoPacket::~VideoPacket() { av_free_packet(packet_); }
VideoPacket::~VideoPacket() { av_free_packet(packet_); av_free(packet_); }
/*=== VideoIOHandle =========================================================*/
......@@ -57,7 +58,7 @@ VideoIOHandle::VideoIOHandle(ssize_t buffer_size,
buf_ = static_cast<unsigned char *>(av_malloc(buffer_size));
ctx_ = avio_alloc_context(buf_, buffer_size, writeable, opaque, read_cb,
write_cb, seek_cb);
//ctx_->max_packet_size = buffer_size;
ctx_->max_packet_size = buffer_size;
}
VideoIOHandle::~VideoIOHandle() { av_free(ctx_); av_free(buf_); }
......
......@@ -181,8 +181,6 @@ void VideoRtpSession::forceKeyFrame()
{
if (sendThread_.get())
sendThread_->forceKeyFrame();
else
ERROR("Video sending thread is NULL");
}
void
......
......@@ -54,8 +54,8 @@ VideoSendThread::VideoSendThread(const std::map<string, string> &args) :
, forceKeyFrame_(0)
, thread_(0)
, frameNumber_(0)
, muxContext_(0)
, fromMixer_(false)
, muxContext_(0)
{}
VideoSendThread::~VideoSendThread()
......@@ -120,7 +120,7 @@ void VideoSendThread::setup()
}
EXIT_IF_FAIL(!videoEncoder_->openOutput(enc_name, "rtp",
args_["destination"].c_str(), NULL),
args_["destination"].c_str(), NULL),
"encoder openOutput() failed");
videoEncoder_->setIOContext(muxContext_);
EXIT_IF_FAIL(!videoEncoder_->startIO(), "encoder start failed");
......@@ -160,28 +160,27 @@ void VideoSendThread::run()
setup();
while (threadRunning_) {
encodeAndSendVideo();
VideoFrame *frame = videoSource_->waitNewFrame().get();
if (frame)
encodeAndSendVideo(frame);
}
delete videoEncoder_;
if (muxContext_)
delete muxContext_;
muxContext_ = nullptr;
}
void VideoSendThread::encodeAndSendVideo()
void VideoSendThread::encodeAndSendVideo(VideoFrame *input_frame)
{
bool is_keyframe = forceKeyFrame_ > 0;
if (is_keyframe)
atomic_decrement(&forceKeyFrame_);
// Select frame source to encode
VideoFrame *inputframe = videoSource_->waitNewFrame().get();
if (inputframe) {
EXIT_IF_FAIL(videoEncoder_->encode(*inputframe, is_keyframe, frameNumber_++) >= 0,
"encoding failed");
}
EXIT_IF_FAIL(videoEncoder_->encode(*input_frame, is_keyframe, frameNumber_++) >= 0,
"encoding failed");
}
void VideoSendThread::forceKeyFrame()
......
......@@ -51,7 +51,7 @@ private:
static int interruptCb(void *ctx);
static void *runCallback(void *);
void run();
void encodeAndSendVideo();
void encodeAndSendVideo(VideoFrame *);
std::map<std::string, std::string> args_;
/*-------------------------------------------------------------*/
......
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