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

* #14176: sip/video: register video threads with pjsip before calling its functions

parent f1024984
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,9 @@ libsiplink_la_SOURCES = \ ...@@ -14,7 +14,9 @@ libsiplink_la_SOURCES = \
sipvoiplink.h \ sipvoiplink.h \
siptransport.h \ siptransport.h \
sip_utils.cpp \ sip_utils.cpp \
sip_utils.h sip_utils.h \
sip_thread_client.h \
sip_thread_client.cpp
if BUILD_SDES if BUILD_SDES
libsiplink_la_SOURCES+= sdes_negotiator.cpp \ libsiplink_la_SOURCES+= sdes_negotiator.cpp \
......
/*
* Copyright (C) 2012 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "sip_thread_client.h"
#include "logger.h"
SIPThreadClient::SIPThreadClient() : thread_(0)
{
// We have to register the external thread so it can access the pjsip frameworks
if (pj_thread_register(NULL, desc_, &thread_) != PJ_SUCCESS)
ERROR("Could not register thread");
}
SIPThreadClient::~SIPThreadClient()
{
if (thread_) {
WARN("Destroying thread handle");
pj_thread_join(thread_);
pj_thread_destroy(thread_);
}
}
/*
* Copyright (C) 2011 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef SIP_THREAD_CLIENT_H_
#define SIP_THREAD_CLIENT_H_
#include "pj/os.h"
#include "noncopyable.h"
class pj_thread_t;
class SIPThreadClient {
private:
NON_COPYABLE(SIPThreadClient);
pj_thread_t *thread_;
pj_thread_desc desc_;
public:
SIPThreadClient();
~SIPThreadClient();
};
#endif // SIP_THREAD_CLIENT_H_
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "video_receive_thread.h" #include "video_receive_thread.h"
#include "dbus/video_controls.h" #include "dbus/video_controls.h"
#include "packet_handle.h" #include "packet_handle.h"
#include "sip/sip_thread_client.h"
#include "check.h" #include "check.h"
// libav includes // libav includes
...@@ -153,8 +154,10 @@ void VideoReceiveThread::setup() ...@@ -153,8 +154,10 @@ void VideoReceiveThread::setup()
EXIT_IF_FAIL(ret == 0, "Could not open input \"%s\"", input.c_str()); EXIT_IF_FAIL(ret == 0, "Could not open input \"%s\"", input.c_str());
DEBUG("Finding stream info"); DEBUG("Finding stream info");
if (requestKeyFrameCallback_) if (requestKeyFrameCallback_) {
sipThreadClient_.reset(new SIPThreadClient);
requestKeyFrameCallback_(id_); requestKeyFrameCallback_(id_);
}
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0) #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0)
ret = av_find_stream_info(inputCtx_); ret = av_find_stream_info(inputCtx_);
#else #else
...@@ -217,7 +220,8 @@ VideoReceiveThread::VideoReceiveThread(const std::string &id, const std::map<str ...@@ -217,7 +220,8 @@ VideoReceiveThread::VideoReceiveThread(const std::string &id, const std::map<str
args_(args), frameNumber_(0), inputDecoder_(0), decoderCtx_(0), rawFrame_(0), args_(args), frameNumber_(0), inputDecoder_(0), decoderCtx_(0), rawFrame_(0),
scaledPicture_(0), streamIndex_(-1), inputCtx_(0), imgConvertCtx_(0), scaledPicture_(0), streamIndex_(-1), inputCtx_(0), imgConvertCtx_(0),
dstWidth_(0), dstHeight_(0), sink_(), receiving_(false), sdpFilename_(), dstWidth_(0), dstHeight_(0), sink_(), receiving_(false), sdpFilename_(),
bufferSize_(0), id_(id), interruptCb_(), requestKeyFrameCallback_(0) bufferSize_(0), id_(id), interruptCb_(), requestKeyFrameCallback_(0),
sipThreadClient_(0)
{ {
interruptCb_.callback = interruptCb; interruptCb_.callback = interruptCb;
interruptCb_.opaque = this; interruptCb_.opaque = this;
...@@ -281,6 +285,7 @@ void VideoReceiveThread::run() ...@@ -281,6 +285,7 @@ void VideoReceiveThread::run()
} }
yield(); yield();
} }
sipThreadClient_.reset();
} }
VideoReceiveThread::~VideoReceiveThread() VideoReceiveThread::~VideoReceiveThread()
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <climits> #include <climits>
#include <memory>
#include "shm_sink.h" #include "shm_sink.h"
#include "noncopyable.h" #include "noncopyable.h"
...@@ -47,6 +48,7 @@ class AVCodecContext; ...@@ -47,6 +48,7 @@ class AVCodecContext;
class AVStream; class AVStream;
class AVFormatContext; class AVFormatContext;
class AVFrame; class AVFrame;
class SIPThreadClient;
namespace sfl_video { namespace sfl_video {
...@@ -76,14 +78,17 @@ class VideoReceiveThread : public ost::Thread { ...@@ -76,14 +78,17 @@ class VideoReceiveThread : public ost::Thread {
std::string sdpFilename_; std::string sdpFilename_;
size_t bufferSize_; size_t bufferSize_;
const std::string id_; const std::string id_;
AVIOInterruptCB interruptCb_;
void (* requestKeyFrameCallback_)(const std::string &);
// XXX: This must be allocated in the video thread, not the main thread
std::auto_ptr<SIPThreadClient> sipThreadClient_;
void setup(); void setup();
void openDecoder(); void openDecoder();
void createScalingContext(); void createScalingContext();
void loadSDP(); void loadSDP();
void fill_buffer(void *data); void fill_buffer(void *data);
static int interruptCb(void *ctx); static int interruptCb(void *ctx);
AVIOInterruptCB interruptCb_;
void (* requestKeyFrameCallback_)(const std::string &);
public: public:
VideoReceiveThread(const std::string &id, const std::map<std::string, std::string> &args); VideoReceiveThread(const std::string &id, const std::map<std::string, std::string> &args);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment