1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

add debugging messages to camerasource, code reformatting to make it more readable and ogranized better

This commit is contained in:
agilob 2015-10-11 07:38:44 +01:00
parent 83bcf2b8ae
commit 7c6ac40d21
No known key found for this signature in database
GPG Key ID: 296F0B764741106C
5 changed files with 90 additions and 50 deletions

View File

@ -78,6 +78,7 @@ void Core::prepareCall(uint32_t friendId, int32_t callId, ToxAv* toxav, bool vid
calls[callId].sendAudioTimer->setSingleShot(true);
connect(calls[callId].sendAudioTimer, &QTimer::timeout, [=](){sendCallAudio(callId,toxav);});
calls[callId].sendAudioTimer->start();
if (calls[callId].videoEnabled)
{
calls[callId].videoSource = new CoreVideoSource;
@ -237,6 +238,7 @@ void Core::cleanupCall(int32_t callId)
calls[callId].active = false;
disconnect(calls[callId].sendAudioTimer,0,0,0);
calls[callId].sendAudioTimer->stop();
if (calls[callId].videoEnabled)
{
CameraSource::getInstance().unsubscribe();

View File

@ -40,6 +40,9 @@ CameraSource::CameraSource()
biglock{false}, freelistLock{false},
isOpen{false}, subscriptions{0}
{
//qDebug() << "CameraSource()";
subscriptions = 0;
av_register_all();
avdevice_register_all();
}
@ -72,6 +75,8 @@ void CameraSource::open(const QString deviceName)
void CameraSource::open(const QString DeviceName, VideoMode Mode)
{
//qDebug() << "open(const QString DeviceName, VideoMode Mode)";
{
bool expected = false;
while (!biglock.compare_exchange_weak(expected, true))
@ -119,7 +124,7 @@ CameraSource::~CameraSource()
// Free all remaining VideoFrame
// Locking must be done precisely this way to avoid races
for (int i=0; i<freelist.size(); i++)
for (int i = 0; i < freelist.size(); i++)
{
std::shared_ptr<VideoFrame> vframe = freelist[i].lock();
if (!vframe)
@ -132,8 +137,9 @@ CameraSource::~CameraSource()
if (cctxOrig)
avcodec_close(cctxOrig);
for (int i=subscriptions; i; --i)
for (int i = subscriptions; i; --i)
device->close();
device = nullptr;
// Memfence so the stream thread sees a nullptr device
std::atomic_thread_fence(std::memory_order_release);
@ -146,6 +152,8 @@ CameraSource::~CameraSource()
bool CameraSource::subscribe()
{
//qDebug() << "subscribe";
// Fast lock
{
bool expected = false;
@ -156,6 +164,8 @@ bool CameraSource::subscribe()
if (!isOpen)
{
++subscriptions;
//qDebug() << "is not open, subscriptions: " << subscriptions;
biglock = false;
return true;
}
@ -163,6 +173,8 @@ bool CameraSource::subscribe()
if (openDevice())
{
++subscriptions;
//qDebug() << "open device, subscriptions: " << subscriptions;
biglock = false;
return true;
}
@ -177,10 +189,13 @@ bool CameraSource::subscribe()
biglock = false;
return false;
}
//qDebug() << "END subscribe";
}
void CameraSource::unsubscribe()
{
//qDebug() << "unsubscribe";
// Fast lock
{
bool expected = false;
@ -190,20 +205,24 @@ void CameraSource::unsubscribe()
if (!isOpen)
{
--subscriptions;
//qDebug() << "is not open";
subscriptions--;
biglock = false;
return;
}
if (!device)
{
qWarning() << "Unsubscribing with zero subscriber";
//qWarning() << "Unsubscribing with zero subscriber";
biglock = false;
return;
}
//qDebug() << "1. device: " << device;
//qDebug() << "2. subscriptions:" << subscriptions;
if (--subscriptions == 0)
if (subscriptions - 1 == 0)
{
//qDebug() << "first block";
closeDevice();
biglock = false;
@ -214,14 +233,18 @@ void CameraSource::unsubscribe()
}
else
{
//qDebug() << "second block";
device->close();
biglock = false;
}
subscriptions--;
//qDebug() << "3. subscriptions: " << subscriptions;
}
bool CameraSource::openDevice()
{
qDebug() << "Opening device "<<deviceName;
//qDebug() << "Opening device: " << deviceName;
if (device)
{
@ -243,15 +266,15 @@ bool CameraSource::openDevice()
// We need to open the device as many time as we already have subscribers,
// otherwise the device could get closed while we still have subscribers
for (int i=subscriptions; i>0; i--)
for (int i = 0; i < subscriptions; i++)
device->open();
// Find the first video stream
for (unsigned i=0; i<device->context->nb_streams; i++)
for (unsigned i = 0; i < device->context->nb_streams; i++)
{
if(device->context->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
if(device->context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStreamIndex=i;
videoStreamIndex = i;
break;
}
}
@ -259,8 +282,8 @@ bool CameraSource::openDevice()
return false;
// Get a pointer to the codec context for the video stream
cctxOrig=device->context->streams[videoStreamIndex]->codec;
codec=avcodec_find_decoder(cctxOrig->codec_id);
cctxOrig = device->context->streams[videoStreamIndex]->codec;
codec = avcodec_find_decoder(cctxOrig->codec_id);
if(!codec)
return false;
@ -268,6 +291,7 @@ bool CameraSource::openDevice()
cctx = avcodec_alloc_context3(codec);
if(avcodec_copy_context(cctx, cctxOrig) != 0)
return false;
cctx->refcounted_frames = 1;
// Open codec
@ -293,11 +317,11 @@ bool CameraSource::openDevice()
void CameraSource::closeDevice()
{
qDebug() << "Closing device "<<deviceName;
//qDebug() << "Closing device " << deviceName;
// Free all remaining VideoFrame
// Locking must be done precisely this way to avoid races
for (int i=0; i<freelist.size(); i++)
for (int i = 0; i < freelist.size(); i++)
{
std::shared_ptr<VideoFrame> vframe = freelist[i].lock();
if (!vframe)
@ -398,9 +422,10 @@ void CameraSource::freelistCallback(int freelistIndex)
int CameraSource::getFreelistSlotLockless()
{
int size = freelist.size();
for (int i=0; i<size; ++i)
for (int i = 0; i < size; ++i)
if (freelist[i].expired())
return i;
freelist.resize(size+(size>>1)+4); // Arbitrary growth strategy, should work well
freelist.resize(size + (size>>1) + 4); // Arbitrary growth strategy, should work well
return size;
}

View File

@ -45,6 +45,7 @@ struct AVCodecContext;
class CameraSource : public VideoSource
{
Q_OBJECT
public:
static CameraSource& getInstance();
static void destroyInstance();

View File

@ -57,6 +57,8 @@
#include "src/widget/tool/screenshotgrabber.h"
#include "src/widget/tool/flyoutoverlaywidget.h"
#include "src/widget/translator.h"
#include "src/video/videosource.h"
#include "src/video/camerasource.h"
ChatForm::ChatForm(Friend* chatFriend)
: f(chatFriend)
@ -138,7 +140,6 @@ void ChatForm::setStatusMessage(QString newMessage)
void ChatForm::onSendTriggered()
{
SendMessageStr(msgEdit->toPlainText());
msgEdit->clear();
}
@ -256,7 +257,7 @@ void ChatForm::onAvInvite(uint32_t FriendId, int CallId, bool video)
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvInvite";
qDebug() << "onAvInvite, callId: " << CallId;
callId = CallId;
callButton->disconnect();
@ -307,7 +308,7 @@ void ChatForm::onAvStart(uint32_t FriendId, int CallId, bool video)
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvStart";
qDebug() << "onAvStart, callId: " << CallId;
audioInputFlag = true;
audioOutputFlag = true;
@ -334,6 +335,7 @@ void ChatForm::onAvStart(uint32_t FriendId, int CallId, bool video)
videoButton->setToolTip("");
connect(callButton, SIGNAL(clicked()),
this, SLOT(onHangupCallTriggered()));
hideNetcam();
}
callButton->style()->polish(callButton);
videoButton->style()->polish(videoButton);
@ -353,12 +355,12 @@ void ChatForm::onAvStart(uint32_t FriendId, int CallId, bool video)
startCounter();
}
void ChatForm::onAvCancel(uint32_t FriendId, int)
void ChatForm::onAvCancel(uint32_t FriendId, int CallId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvCancel";
qDebug() << "onAvCancel, callId: " << CallId;
delete callConfirm;
callConfirm = nullptr;
@ -373,27 +375,12 @@ void ChatForm::onAvCancel(uint32_t FriendId, int)
QDateTime::currentDateTime());
}
void ChatForm::onAvEnd(uint32_t FriendId, int)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvEnd";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
}
void ChatForm::onAvRinging(uint32_t FriendId, int CallId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRinging";
qDebug() << "onAvRinging, callId: " << CallId;
callId = CallId;
callButton->disconnect();
@ -433,7 +420,7 @@ void ChatForm::onAvStarting(uint32_t FriendId, int CallId, bool video)
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvStarting";
qDebug() << "onAvStarting, callId:" << CallId;
callId = CallId;
@ -465,28 +452,44 @@ void ChatForm::onAvStarting(uint32_t FriendId, int CallId, bool video)
startCounter();
}
void ChatForm::onAvEnding(uint32_t FriendId, int)
void ChatForm::onAvEnding(uint32_t FriendId, int CallId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvEnding";
qDebug() << "onAvEnding, callId: " << CallId;
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
CameraSource::getInstance().unsubscribe();
}
void ChatForm::onAvRequestTimeout(uint32_t FriendId, int)
void ChatForm::onAvEnd(uint32_t FriendId, int CallId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRequestTimeout";
qDebug() << "onAvEnd, callId: " << CallId;
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
Core::getInstance()->getVideoSourceFromCall(callId)->unsubscribe();
}
void ChatForm::onAvRequestTimeout(uint32_t FriendId, int CallId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRequestTimeout, callId: " << CallId;
delete callConfirm;
callConfirm = nullptr;
@ -537,7 +540,7 @@ void ChatForm::onAvMediaChange(uint32_t FriendId, int CallId, bool video)
if (FriendId != f->getFriendID() || CallId != callId)
return;
qDebug() << "onAvMediaChange";
qDebug() << "onAvMediaChange, callId: " << CallId;
if (video)
showNetcam();
@ -754,6 +757,7 @@ void ChatForm::onAvatarChange(uint32_t FriendId, const QPixmap &pic)
GenericNetCamView *ChatForm::createNetcam()
{
qDebug() << "creating netcam";
NetCamView* view = new NetCamView(f->getFriendID(), this);
view->show(Core::getInstance()->getVideoSourceFromCall(callId), f->getDisplayedName());
return view;

View File

@ -75,7 +75,8 @@ GenericChatForm::GenericChatForm(QWidget *parent)
chatWidget = new ChatLog(this);
chatWidget->setBusyNotification(ChatMessage::createBusyNotification());
connect(&Settings::getInstance(), &Settings::emojiFontChanged, this, [this]() { chatWidget->forceRelayout(); });
connect(&Settings::getInstance(), &Settings::emojiFontChanged,
this, [this]() { chatWidget->forceRelayout(); });
msgEdit = new ChatTextEdit();
@ -186,12 +187,16 @@ GenericChatForm::GenericChatForm(QWidget *parent)
menu.addActions(chatWidget->actions());
menu.addSeparator();
saveChatAction = menu.addAction(QIcon::fromTheme("document-save"), QString(), this, SLOT(onSaveLogClicked()));
clearAction = menu.addAction(QIcon::fromTheme("edit-clear"), QString(), this, SLOT(clearChatArea(bool)));
saveChatAction = menu.addAction(QIcon::fromTheme("document-save"),
QString(), this, SLOT(onSaveLogClicked()));
clearAction = menu.addAction(QIcon::fromTheme("edit-clear"),
QString(), this, SLOT(clearChatArea(bool)));
menu.addSeparator();
connect(emoteButton, &QPushButton::clicked, this, &GenericChatForm::onEmoteButtonClicked);
connect(chatWidget, &ChatLog::customContextMenuRequested, this, &GenericChatForm::onChatContextMenuRequested);
connect(emoteButton, &QPushButton::clicked,
this, &GenericChatForm::onEmoteButtonClicked);
connect(chatWidget, &ChatLog::customContextMenuRequested,
this, &GenericChatForm::onChatContextMenuRequested);
new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_L, this, SLOT(clearChatArea()));
@ -576,7 +581,8 @@ void GenericChatForm::showNetcam()
if (!netcam)
netcam = createNetcam();
connect(netcam, &GenericNetCamView::showMessageClicked, this, &GenericChatForm::onShowMessagesClicked);
connect(netcam, &GenericNetCamView::showMessageClicked,
this, &GenericChatForm::onShowMessagesClicked);
bodySplitter->insertWidget(0, netcam);
bodySplitter->setCollapsible(0, false);
@ -586,6 +592,8 @@ void GenericChatForm::hideNetcam()
{
if (!netcam)
return;
netcam->close();
netcam->hide();
delete netcam;
netcam = nullptr;