You've already forked libopenshot-audio
mirror of
https://github.com/OpenShot/libopenshot-audio.git
synced 2026-03-02 08:54:01 -08:00
Updated JUCE modules to version 3, which also updated the license headers to reflect AGPLv3 compatibility.
This commit is contained in:
@@ -1,36 +1,48 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE 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.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
struct InterprocessConnection::ConnectionThread : public Thread
|
||||
{
|
||||
ConnectionThread (InterprocessConnection& c) : Thread ("JUCE IPC"), owner (c) {}
|
||||
|
||||
void run() override { owner.runThread(); }
|
||||
|
||||
private:
|
||||
InterprocessConnection& owner;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConnectionThread);
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
|
||||
const uint32 magicMessageHeaderNumber)
|
||||
: Thread ("Juce IPC connection"),
|
||||
callbackConnectionState (false),
|
||||
: callbackConnectionState (false),
|
||||
useMessageThread (callbacksOnMessageThread),
|
||||
magicMessageHeader (magicMessageHeaderNumber),
|
||||
pipeReceiveMessageTimeout (-1)
|
||||
{
|
||||
thread = new ConnectionThread (*this);
|
||||
}
|
||||
|
||||
InterprocessConnection::~InterprocessConnection()
|
||||
@@ -38,9 +50,9 @@ InterprocessConnection::~InterprocessConnection()
|
||||
callbackConnectionState = false;
|
||||
disconnect();
|
||||
masterReference.clear();
|
||||
thread = nullptr;
|
||||
}
|
||||
|
||||
|
||||
//==============================================================================
|
||||
bool InterprocessConnection::connectToSocket (const String& hostName,
|
||||
const int portNumber,
|
||||
@@ -54,7 +66,7 @@ bool InterprocessConnection::connectToSocket (const String& hostName,
|
||||
if (socket->connect (hostName, portNumber, timeOutMillisecs))
|
||||
{
|
||||
connectionMadeInt();
|
||||
startThread();
|
||||
thread->startThread();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -64,17 +76,16 @@ bool InterprocessConnection::connectToSocket (const String& hostName,
|
||||
}
|
||||
}
|
||||
|
||||
bool InterprocessConnection::connectToPipe (const String& pipeName,
|
||||
const int pipeReceiveMessageTimeoutMs)
|
||||
bool InterprocessConnection::connectToPipe (const String& pipeName, const int timeoutMs)
|
||||
{
|
||||
disconnect();
|
||||
|
||||
ScopedPointer <NamedPipe> newPipe (new NamedPipe());
|
||||
ScopedPointer<NamedPipe> newPipe (new NamedPipe());
|
||||
|
||||
if (newPipe->openExisting (pipeName))
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
|
||||
pipeReceiveMessageTimeout = timeoutMs;
|
||||
initialiseWithPipe (newPipe.release());
|
||||
return true;
|
||||
}
|
||||
@@ -82,17 +93,16 @@ bool InterprocessConnection::connectToPipe (const String& pipeName,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InterprocessConnection::createPipe (const String& pipeName,
|
||||
const int pipeReceiveMessageTimeoutMs)
|
||||
bool InterprocessConnection::createPipe (const String& pipeName, const int timeoutMs)
|
||||
{
|
||||
disconnect();
|
||||
|
||||
ScopedPointer <NamedPipe> newPipe (new NamedPipe());
|
||||
ScopedPointer<NamedPipe> newPipe (new NamedPipe());
|
||||
|
||||
if (newPipe->createNewPipe (pipeName))
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
|
||||
pipeReceiveMessageTimeout = timeoutMs;
|
||||
initialiseWithPipe (newPipe.release());
|
||||
return true;
|
||||
}
|
||||
@@ -102,39 +112,41 @@ bool InterprocessConnection::createPipe (const String& pipeName,
|
||||
|
||||
void InterprocessConnection::disconnect()
|
||||
{
|
||||
if (socket != nullptr)
|
||||
socket->close();
|
||||
|
||||
if (pipe != nullptr)
|
||||
pipe->close();
|
||||
|
||||
stopThread (4000);
|
||||
thread->signalThreadShouldExit();
|
||||
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
pipe = nullptr;
|
||||
if (socket != nullptr) socket->close();
|
||||
if (pipe != nullptr) pipe->close();
|
||||
}
|
||||
|
||||
thread->stopThread (4000);
|
||||
deletePipeAndSocket();
|
||||
connectionLostInt();
|
||||
}
|
||||
|
||||
void InterprocessConnection::deletePipeAndSocket()
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
pipe = nullptr;
|
||||
}
|
||||
|
||||
bool InterprocessConnection::isConnected() const
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
|
||||
return ((socket != nullptr && socket->isConnected())
|
||||
|| (pipe != nullptr && pipe->isOpen()))
|
||||
&& isThreadRunning();
|
||||
&& thread->isThreadRunning();
|
||||
}
|
||||
|
||||
String InterprocessConnection::getConnectedHostName() const
|
||||
{
|
||||
if (pipe != nullptr)
|
||||
{
|
||||
return "localhost";
|
||||
}
|
||||
else if (socket != nullptr)
|
||||
|
||||
if (socket != nullptr)
|
||||
{
|
||||
if (! socket->isLocal())
|
||||
return socket->getHostName();
|
||||
@@ -142,7 +154,7 @@ String InterprocessConnection::getConnectedHostName() const
|
||||
return "localhost";
|
||||
}
|
||||
|
||||
return String::empty;
|
||||
return String();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
@@ -163,39 +175,38 @@ bool InterprocessConnection::sendMessage (const MemoryBlock& message)
|
||||
if (socket != nullptr)
|
||||
bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
|
||||
else if (pipe != nullptr)
|
||||
bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
|
||||
bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize(), pipeReceiveMessageTimeout);
|
||||
|
||||
return bytesWritten == (int) messageData.getSize();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
|
||||
void InterprocessConnection::initialiseWithSocket (StreamingSocket* newSocket)
|
||||
{
|
||||
jassert (socket == 0);
|
||||
socket = socket_;
|
||||
jassert (socket == nullptr && pipe == nullptr);
|
||||
socket = newSocket;
|
||||
connectionMadeInt();
|
||||
startThread();
|
||||
thread->startThread();
|
||||
}
|
||||
|
||||
void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
|
||||
void InterprocessConnection::initialiseWithPipe (NamedPipe* newPipe)
|
||||
{
|
||||
jassert (pipe == 0);
|
||||
pipe = pipe_;
|
||||
jassert (socket == nullptr && pipe == nullptr);
|
||||
pipe = newPipe;
|
||||
connectionMadeInt();
|
||||
startThread();
|
||||
thread->startThread();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
struct ConnectionStateMessage : public MessageManager::MessageBase
|
||||
{
|
||||
ConnectionStateMessage (InterprocessConnection* owner_, bool connectionMade_) noexcept
|
||||
: owner (owner_), connectionMade (connectionMade_)
|
||||
ConnectionStateMessage (InterprocessConnection* ipc, bool connected) noexcept
|
||||
: owner (ipc), connectionMade (connected)
|
||||
{}
|
||||
|
||||
void messageCallback()
|
||||
void messageCallback() override
|
||||
{
|
||||
InterprocessConnection* const ipc = owner;
|
||||
if (ipc != nullptr)
|
||||
if (InterprocessConnection* const ipc = owner)
|
||||
{
|
||||
if (connectionMade)
|
||||
ipc->connectionMade();
|
||||
@@ -206,6 +217,8 @@ struct ConnectionStateMessage : public MessageManager::MessageBase
|
||||
|
||||
WeakReference<InterprocessConnection> owner;
|
||||
bool connectionMade;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConnectionStateMessage)
|
||||
};
|
||||
|
||||
void InterprocessConnection::connectionMadeInt()
|
||||
@@ -236,14 +249,13 @@ void InterprocessConnection::connectionLostInt()
|
||||
|
||||
struct DataDeliveryMessage : public Message
|
||||
{
|
||||
DataDeliveryMessage (InterprocessConnection* owner_, const MemoryBlock& data_)
|
||||
: owner (owner_), data (data_)
|
||||
DataDeliveryMessage (InterprocessConnection* ipc, const MemoryBlock& d)
|
||||
: owner (ipc), data (d)
|
||||
{}
|
||||
|
||||
void messageCallback()
|
||||
void messageCallback() override
|
||||
{
|
||||
InterprocessConnection* const ipc = owner;
|
||||
if (ipc != nullptr)
|
||||
if (InterprocessConnection* const ipc = owner)
|
||||
ipc->messageReceived (data);
|
||||
}
|
||||
|
||||
@@ -264,30 +276,30 @@ void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
|
||||
//==============================================================================
|
||||
bool InterprocessConnection::readNextMessageInt()
|
||||
{
|
||||
const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
|
||||
|
||||
uint32 messageHeader[2];
|
||||
const int bytes = socket != nullptr ? socket->read (messageHeader, sizeof (messageHeader), true)
|
||||
: pipe ->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
|
||||
: pipe ->read (messageHeader, sizeof (messageHeader), -1);
|
||||
|
||||
if (bytes == sizeof (messageHeader)
|
||||
&& ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
|
||||
{
|
||||
int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
|
||||
|
||||
if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
|
||||
if (bytesInMessage > 0)
|
||||
{
|
||||
MemoryBlock messageData ((size_t) bytesInMessage, true);
|
||||
int bytesRead = 0;
|
||||
|
||||
while (bytesInMessage > 0)
|
||||
{
|
||||
if (threadShouldExit())
|
||||
if (thread->threadShouldExit())
|
||||
return false;
|
||||
|
||||
const int numThisTime = jmin (bytesInMessage, 65536);
|
||||
const int bytesIn = socket != nullptr ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
|
||||
: pipe ->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
|
||||
void* const data = addBytesToPointer (messageData.getData(), bytesRead);
|
||||
|
||||
const int bytesIn = socket != nullptr ? socket->read (data, numThisTime, true)
|
||||
: pipe ->read (data, numThisTime, -1);
|
||||
|
||||
if (bytesIn <= 0)
|
||||
break;
|
||||
@@ -302,10 +314,8 @@ bool InterprocessConnection::readNextMessageInt()
|
||||
}
|
||||
else if (bytes < 0)
|
||||
{
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
}
|
||||
if (socket != nullptr)
|
||||
deletePipeAndSocket();
|
||||
|
||||
connectionLostInt();
|
||||
return false;
|
||||
@@ -314,9 +324,9 @@ bool InterprocessConnection::readNextMessageInt()
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterprocessConnection::run()
|
||||
void InterprocessConnection::runThread()
|
||||
{
|
||||
while (! threadShouldExit())
|
||||
while (! thread->threadShouldExit())
|
||||
{
|
||||
if (socket != nullptr)
|
||||
{
|
||||
@@ -324,45 +334,32 @@ void InterprocessConnection::run()
|
||||
|
||||
if (ready < 0)
|
||||
{
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
}
|
||||
|
||||
deletePipeAndSocket();
|
||||
connectionLostInt();
|
||||
break;
|
||||
}
|
||||
else if (ready > 0)
|
||||
|
||||
if (ready == 0)
|
||||
{
|
||||
if (! readNextMessageInt())
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread::sleep (2);
|
||||
thread->wait (1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (pipe != nullptr)
|
||||
{
|
||||
if (! pipe->isOpen())
|
||||
{
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
pipe = nullptr;
|
||||
}
|
||||
|
||||
deletePipeAndSocket();
|
||||
connectionLostInt();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! readNextMessageInt())
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (thread->threadShouldExit() || ! readNextMessageInt())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user