Skip to content
47 changes: 41 additions & 6 deletions Build/Boot.scons
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
import platform
import re

EnsureSConsVersion(0,98,1)

Expand All @@ -16,7 +17,8 @@ PLATFORM_TO_TARGET_MAP = {
'linux2' : 'x86-unknown-linux',
'win32' : 'x86-microsoft-win32',
'cygwin' : 'x86-unknown-cygwin',
'darwin' : 'universal-apple-macosx'
'darwin' : 'universal-apple-macosx',
'raspberry-pi-arm' : 'arm-raspberry-pi-linux'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could you align the : please?

}

# list all target dirs
Expand All @@ -25,20 +27,53 @@ targets_dir = scons_root+'/Build/Targets'
targets_dirs = os.listdir(targets_dir)
TARGET_PLATFORMS = [x for x in targets_dirs if os.path.exists(targets_dir +'/'+x+'/Config.scons')]

def pi_version():
"""Detect the version of the Raspberry Pi. Returns either 1, 2 or
None depending on if it's a Raspberry Pi 1 (model A, B, A+, B+),
Raspberry Pi 2 (model B+), or not a Raspberry Pi.
"""
# Check /proc/cpuinfo for the Hardware field value.
# 2708 is pi 1
# 2709 is pi 2
# 2835 is pi 3 on 4.9.x kernel
# Anything else is not a pi.
with open('/proc/cpuinfo', 'r') as infile:
cpuinfo = infile.read()
# Match a line like 'Hardware : BCM2709'
match = re.search('^Hardware\s+:\s+(\w+)$', cpuinfo,
flags=re.MULTILINE | re.IGNORECASE)
if not match:
# Couldn't find the hardware, assume it isn't a pi.
return None
if match.group(1) == 'BCM2708':
# Pi 1
return 1
elif match.group(1) == 'BCM2709':
# Pi 2
return 2
elif match.group(1) == 'BCM2835':
# Pi 3 / Pi on 4.9.x kernel
return 3
else:
# Something else, not a pi.
return None

def DefaultTarget():
platform_id = sys.platform
if platform.system() == 'Linux':
if (platform.machine() == 'i386' or
if pi_version() is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to hook into platform.machine().startswith('arm') last and differentiate between linux-arm and raspberry-pi-arm instead?
Alternatively, is there anyway to use linux-arm for raspberry?

platform_id = 'raspberry-pi-arm'
elif (platform.machine() == 'i386' or
platform.machine() == 'i486' or
platform.machine() == 'i586'or
platform.machine() == 'i686'):
platform_id = 'linux-i386'
if (platform.machine() == 'x86_64'):
elif (platform.machine() == 'x86_64'):
platform_id = 'linux-x86_64'
if (platform.machine().startswith('arm')):
elif (platform.machine().startswith('arm')):
platform_id = 'linux-arm'

if PLATFORM_TO_TARGET_MAP.has_key(platform_id):
if platform_id in PLATFORM_TO_TARGET_MAP:
return PLATFORM_TO_TARGET_MAP[platform_id]
else:
return None
Expand Down Expand Up @@ -67,5 +102,5 @@ base_env = env
for build_config in env['build_config']:
env = base_env.Clone()
env['build_config'] = build_config
print '********** Configuring Build Target =', env['target'], '/', build_config, '********'
print ('********** Configuring Build Target =', env['target'], '/', build_config, '********')
SConscript('Build.scons', variant_dir='Targets/'+env['target']+'/'+build_config, exports='env', duplicate=0)
48 changes: 45 additions & 3 deletions Build/Build.scons
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def DeclareBuildDir(dir):
def GetIncludeDirs(modules, exclude=None):
dirs = []
for module in Split(modules):
if Modules.has_key(module) and not module == exclude:
if module in Modules and not module == exclude:
dirs += Modules[module].GetIncludeDirs()
else:
dirs += [GetDirPath(module)]
Expand All @@ -44,7 +44,7 @@ def GetIncludeDirs(modules, exclude=None):
def GetLibraries(modules):
libs = []
for module in Split(modules):
if Modules.has_key(module):
if module in Modules:
libs += Modules[module].GetLibraries()
else:
libs += [module]
Expand Down Expand Up @@ -114,6 +114,7 @@ class LibraryModule(Module):

# the product is a library
self.env.AppendUnique(CPPPATH=cpp_path)
self.env.AppendUnique(CCFLAGS='-fPIC')
if shared is False:
self.product = self.env.Library(target=name, source=sources)
else:
Expand Down Expand Up @@ -145,6 +146,42 @@ def Application(name, dir, deps, install = False):
if env['build_config'] == 'Release' and env.has_key('STRIP'):
env.AddPostAction(inst, env['STRIP']+' $TARGETS');

def Swig(name, dir, deps):
DeclareBuildDir(dir)
cpp_path = GetIncludeDirs(deps)

inc = '-I' + ' -I'.join([env.GetBuildPath(x) for x in cpp_path])

def generator(source, target, env, for_signature):
return 'swig -python -py3 -threads -c++ {} -o {} {}'.format(inc, target[0], source[0])

bld = Builder(generator = generator)
env.Append(BUILDERS={'Swig' : bld})

return env.Swig([name + '_wrap.cxx', name + '_wrap.h', name + '.py'], GlobSources(dir, ['*.i']))

def PythonBinding(name, dir, deps):
swig_out = Swig(name, dir, deps)

DeclareBuildDir(dir)
cpp_path = GetIncludeDirs(deps) + [GetDirPath(dir)]
libs = GetLibraries(deps)

# the product is a library
env_ = env.Clone()
env_.AppendUnique(CPPPATH=cpp_path, LIBS=libs)
env_.ParseConfig('pkg-config python3 --cflags --libs')
product = env_.SharedLibrary(target=name,
source=GlobSources(dir, ['*.cxx']) + [swig_out[0]],
SHLIBSUFFIX='.so', SHLIBPREFIX='_')
env_.Alias(name, product)

# copy to Targets folder
inst = env.Install(dir=env.GetBuildPath('#/Targets/'+env['target']+'/'+env['build_config']), source=product)
if env['build_config'] == 'Release' and env.has_key('STRIP'):
env.AddPostAction(inst, env['STRIP']+' $TARGETS');

env.Install(dir=env.GetBuildPath('#/Targets/'+env['target']+'/'+env['build_config']), source=swig_out[2])
#######################################################
# Main Build
#######################################################
Expand All @@ -163,7 +200,8 @@ else:
target_config_file = env.GetBuildPath('#/Build/Targets/'+env['target']+'/Config.scons')
if os.path.exists(target_config_file):
# Load the target-specific config file
execfile(target_config_file)
with open(target_config_file) as f:
exec(f.read())

#######################################################
# modules
Expand Down Expand Up @@ -273,3 +311,7 @@ for tool in ['TextToHeader']:
dir = 'Source/Tools/' + tool,
deps = ['Platinum'],
install = True)

PythonBinding(name = 'media_renderer',
dir = 'binding/python',
deps = ['Platinum', 'PltMediaRenderer'])
7 changes: 7 additions & 0 deletions Build/Targets/arm-raspberry-pi-linux/Config.scons
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LoadTool('gcc-generic', env, gcc_cross_prefix='')

### Neptune System Files
env['NPT_SYSTEM_SOURCES']={'System/StdC':'*.cpp', 'System/Bsd':'*.cpp', 'System/Posix':'*.cpp', 'System/Null':'NptNullAutoreleasePool.cpp'}
env['NPT_EXTRA_LIBS']=['pthread']

env['STRIP'] = ''
5 changes: 5 additions & 0 deletions Build/Targets/universal-apple-macosx/Config.scons
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LoadTool('gcc-generic', env)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally not supported because building iOS/macOS with Scons is unstable and unsupported at the moment.


### Neptune System Files
env['NPT_SYSTEM_SOURCES']={'System/StdC':'*.cpp', 'System/Bsd':'*.cpp', 'System/Posix':'*.cpp', 'System/Null':'NptNullAutoreleasePool.cpp NptNullSerialPort.cpp'}
env['NPT_EXTRA_LIBS']=['pthread']
5 changes: 5 additions & 0 deletions Build/Targets/x86_64-unknown-linux/Config.scons
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LoadTool('gcc-generic', env)

### Neptune System Files
env['NPT_SYSTEM_SOURCES']={'System/StdC':'*.cpp', 'System/Bsd':'*.cpp', 'System/Posix':'*.cpp', 'System/Null':'NptNullAutoreleasePool.cpp NptNullSerialPort.cpp'}
env['NPT_EXTRA_LIBS']=['pthread']
46 changes: 23 additions & 23 deletions Source/Apps/FrameStreamer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
| as published by the Free Software Foundation; either version 2
| of the License, or (at your option) any later version.
|
| OEMs, ISVs, VARs and other distributors that combine and
| OEMs, ISVs, VARs and other distributors that combine and
| distribute commercially licensed software with Platinum software
| and do not wish to distribute the source code for the commercially
| licensed software under version 2, or (at your option) any later
| version, of the GNU General Public License (the "GPL") must enter
| into a commercial license agreement with Plutinosoft, LLC.
| [email protected]
|
|
| 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; see the file LICENSE.txt. If not, write to
| the Free Software Foundation, Inc.,
| the Free Software Foundation, Inc.,
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
| http://www.gnu.org/licenses/gpl-2.0.html
|
Expand Down Expand Up @@ -59,11 +59,11 @@ class StreamValidator : public PLT_StreamValidator
public:
StreamValidator(NPT_Reference<PLT_FrameBuffer>& buffer) : m_Buffer(buffer) {}
virtual ~StreamValidator() {}

// PLT_StreamValidator methods
bool OnNewRequestAccept(const NPT_HttpRequest& request,
bool OnNewRequestAccept(const NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response,
NPT_HttpResponse& response,
NPT_Reference<PLT_FrameBuffer>& buffer) {
NPT_COMPILER_UNUSED(request);
NPT_COMPILER_UNUSED(response);
Expand All @@ -72,7 +72,7 @@ class StreamValidator : public PLT_StreamValidator
buffer = m_Buffer;
return true;
}

NPT_Reference<PLT_FrameBuffer> m_Buffer;
};

Expand All @@ -83,7 +83,7 @@ class FrameWriter : public NPT_Thread
{
public:
FrameWriter(NPT_Reference<PLT_FrameBuffer>& frame_buffer,
const char* frame_folder) :
const char* frame_folder) :
m_FrameBuffer(frame_buffer),
m_Aborted(false),
m_Folder(frame_folder)
Expand All @@ -104,12 +104,12 @@ class FrameWriter : public NPT_Thread
const char* frame_path = NULL;
NPT_DataBuffer frame;
NPT_List<NPT_String>::Iterator entry;

while (!m_Aborted) {
// has number of images changed since last time?
NPT_LargeSize count;
NPT_File::GetSize(m_Folder, count);

if (entries.GetItemCount() == 0 || entries.GetItemCount() != count) {
NPT_File::ListDir(m_Folder, entries);
entry = entries.GetFirstItem();
Expand All @@ -118,26 +118,26 @@ class FrameWriter : public NPT_Thread
NPT_System::Sleep(NPT_TimeInterval(0.2f));
continue;
}

// set delay based on number of files if necessary
m_Delay = NPT_TimeInterval((float)1.f/entries.GetItemCount());
}

// look for path to next image
if (!(frame_path = GetPath(entry))) {
// loop back if necessary
entry = entries.GetFirstItem();
continue;
}

if (NPT_FAILED(NPT_File::Load(NPT_FilePath::Create(m_Folder, frame_path), frame))) {
NPT_LOG_SEVERE_1("Image \"%s\" not found!", frame_path?frame_path:"none");
// clear previously loaded names so we reload entire set
entries.Clear();
continue;
}

if (NPT_FAILED(m_FrameBuffer->SetNextFrame(frame.GetData(),
if (NPT_FAILED(m_FrameBuffer->SetNextFrame(frame.GetData(),
frame.GetDataSize()))) {
NPT_LOG_SEVERE_1("Failed to set next frame %s", frame_path);
goto failure;
Expand Down Expand Up @@ -183,7 +183,7 @@ ParseCommandLine(char** args)

/* default values */
Options.path = NULL;

while ((arg = *args++)) {
if (Options.path == NULL) {
Options.path = arg;
Expand All @@ -207,24 +207,24 @@ int
main(int argc, char** argv)
{
NPT_COMPILER_UNUSED(argc);

/* parse command line */
ParseCommandLine(argv);
// frame buffer

// frame buffer
NPT_Reference<PLT_FrameBuffer> frame_buffer(new PLT_FrameBuffer("image/jpeg"));

// A Framewriter reading images from a folder and writing them
// into frame buffer in a loop
FrameWriter writer(frame_buffer, Options.path);
writer.Start();

// stream request validation
StreamValidator validator(frame_buffer);
// frame server receiving requests and serving frames

// frame server receiving requests and serving frames
// read from frame buffer
NPT_Reference<PLT_FrameServer> device(
NPT_Reference<PLT_FrameServer> device(
new PLT_FrameServer(
"frame",
validator,
Expand All @@ -235,7 +235,7 @@ main(int argc, char** argv)
return 1;

char buf[256];
while (true) {
while (true) {
fgets(buf, 256, stdin);
if (*buf == 'q')
break;
Expand Down
Loading