Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export Event getExtraDataString to python #134

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
28 changes: 28 additions & 0 deletions examples/testVideo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#######################################################################################################################
# Source files
SET( srcs
libstreamport.cpp
video_buf_pool.cpp
video_ctrl.cpp
video_stream_manager.cpp
video_stream_port.cpp
main.cpp
)

#######################################################################################################################
# Headers
SET( headers
libstreamport.h
video_buf_pool.h
video_ctrl.h
video_stream_manager.h
video_stream_port.h
)

#######################################################################################################################
# Setup compile info
add_executable(testVideo ${srcs} ${headers})
set_target_properties(testVideo PROPERTIES FOLDER examples)
target_link_libraries(testVideo omega omegaToolkit)


94 changes: 94 additions & 0 deletions examples/testVideo/libstreamport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <omega.h>

#include <omicron/Thread.h>

#include "libstreamport.h"

class streamport : public omicron::Thread
{
public:
streamport()
{
_color = n;
n += 10000;
_w = 1920;
_h = 1080;
int size = _w * _h * 3 / 2;
_buf = new char[ size ];
memset( _buf, _color, size );
}
~streamport()
{

}
virtual void threadProc()
{
while( !_stop )
{
if( _handler )
{
int size = _w * _h * 3 / 2;
memset( _buf, _color++, size );
_handler->on_video_frame_got( ( unsigned char* )_buf, _w, _h );
}

omega::osleep( 16 ); //for 60fps
}
}

bool start()
{
_stop = false;
omicron::Thread::start();
return true;
}
bool stop()
{
_stop = true;
omicron::Thread::stop();
return true;
}

libstreamport_handler *_handler;
bool _stop;
int _color;
void* _buf;
int _w;
int _h;

static int n;
};

int streamport::n = 0;

libstreamport::libstreamport()
: sp( NULL )
{
sp = new streamport;
}

libstreamport::libstreamport( libstreamport_handler *_handler, int _output_format )
: sp( NULL )
{
sp = new streamport;
sp->_handler = _handler;
}

libstreamport::~libstreamport()
{
}

void libstreamport::set_prama( libstreamport_handler *_handler, int _output_format )
{
sp->_handler = _handler;
}

bool libstreamport::start_video( )
{
return sp->start();
}

bool libstreamport::stop_video()
{
return sp->stop();
}
30 changes: 30 additions & 0 deletions examples/testVideo/libstreamport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <string>

class streamport;

#define OUTPUT_FMT_YUV 0
#define OUTPUT_FMT_RGB 1

class libstreamport_handler
{
public:
virtual void on_video_frame_got( unsigned char *buf, int width, int height ) = 0;
};

class libstreamport
{
public:
libstreamport();
libstreamport( libstreamport_handler *_handler, int _output_format = OUTPUT_FMT_YUV );
virtual ~libstreamport();

void set_prama( libstreamport_handler *_handler, int _output_format = OUTPUT_FMT_YUV );

bool start_video( );
bool stop_video();

protected:
streamport *sp;
};
120 changes: 120 additions & 0 deletions examples/testVideo/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**********************************************************************************************************************
* THE OMEGA LIB PROJECT
*---------------------------------------------------------------------------------------------------------------------
* Copyright 2010 Electronic Visualization Laboratory, University of Illinois at Chicago
* Authors:
* Alessandro Febretti [email protected]
*---------------------------------------------------------------------------------------------------------------------
* Copyright (c) 2010, Electronic Visualization Laboratory, University of Illinois at Chicago
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*---------------------------------------------------------------------------------------------------------------------
* ohello
* Implements the simplest possible omegalib application. Just a synchronized renderer that performs some
* opengl drawing on one or multiple nodes.
*********************************************************************************************************************/
#include <omega.h>
#include <omegaToolkit.h>
#include <omegaGl.h>

using namespace omega;
using namespace omegaToolkit;
using namespace omegaToolkit::ui;

#include <omicron/Timer.h>

#include <vector>

#include "video_ctrl.h"
#include "video_stream_manager.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class VideoApplication: public EngineModule
{
public:
VideoApplication(): EngineModule( "VideoApplication" ) {}
virtual void initialize()
{
EngineModule::initialize();

omega::Console* console = getEngine()->getConsole();
console->setDrawFlags( omega::Console::DrawStats );

myUiModule = UiModule::createAndInitialize();
Ref<Container> myUi = myUiModule->getUi();

int nXOff = 0;
int nScreenW = 3840;
int nScreenH = 800;

std::vector< int > xx;
std::vector< int > yy;

int xNum = 6;
int yNum = 4;
int w = nScreenW / xNum;
int h = nScreenH / yNum;

for( int i = 0; i < xNum; i ++ )
{
xx.push_back( nScreenW * i / xNum );
}
for( int i = 0; i < yNum; i ++ )
{
yy.push_back( nScreenH * i / yNum );
}

int nVideoPort = 4602;
const char* ip = "168.168.68.42";
int n = 0;
for( int i = 0; i < xx.size(); i++ )
{
for( int j = 0; j < yy.size(); j ++ )
{
VideoCtrl* v1 = VideoCtrl::create( myUi );
v1->startVideo( ip, ip, nVideoPort, nVideoPort + 1, 60, 0 );
v1->setPosition( omega::Vector2f( nXOff + xx[ i ], yy[ j ] ) );
v1->setSize( omega::Vector2f( w, h ) );

nVideoPort += 2;
}
}
}

void update( const UpdateContext & context )
{
omicron::Timer timer;
timer.start();
//update all video streams to next frame
VideoStreamManager::instance()->updateAllStreams();

timer.stop();
fprintf( stderr, "--------------- update : %f\n", timer.getElapsedTimeInMilliSec() );
//fprintf( stderr, "------------------------------------------\n" );
}

private:
// The ui manager
Ref<UiModule> myUiModule;
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ApplicationBase entry point
int main( int argc, char** argv )
{
Application<VideoApplication> app( "testVideo" );
return omain( app, argc, argv );
}
106 changes: 106 additions & 0 deletions examples/testVideo/video_buf_pool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "video_buf_pool.h"

VideoData::VideoData()
: data( NULL )
, w( 0 )
, h( 0 )
, size( 0 )
{
}

VideoData::VideoData( int w, int h, int size )
{
this->w = w;
this->h = h;
this->size = size;
this->data = new char[ size ];
}

VideoData::~VideoData()
{
if( data )
{
delete[] data;
data = NULL;
}
}

void VideoData::resize( int w, int h, int size )
{
if( data )
{
delete[] data;
data = NULL;
}

this->w = w;
this->h = h;
this->size = size;
this->data = new char[ size ];
}

VideoBufPool::VideoBufPool()
: _maxSize( 0 )
{
}

VideoBufPool::~VideoBufPool()
{
release();
}

bool VideoBufPool::init( int maxSize )
{
_maxSize = maxSize;
for( int i = 0; i < maxSize; ++i )
{
_bufs.push( new VideoData() );
}
return true;
}

void VideoBufPool::release()
{
fast_mutex_autolock autolock( _mutex );
while( !_bufs.empty() )
{
VideoData* buf = _bufs.top();
_bufs.pop();
delete buf;
}
}

int VideoBufPool::getMaxSize()
{
fast_mutex_autolock autolock( _mutex );
return _maxSize;
}

int VideoBufPool::getFreeCount()
{
fast_mutex_autolock autolock( _mutex );
return _bufs.size();
}

VideoData* VideoBufPool::malloc( int w, int h, int size )
{
fast_mutex_autolock autolock( _mutex );
if( _bufs.empty() )
{
return NULL;
}
VideoData* buf = _bufs.top();
_bufs.pop();

if( buf->size != size )
{
buf->resize( w, h, size );
}
return buf;
}

void VideoBufPool::free( VideoData* buf )
{
fast_mutex_autolock autolock( _mutex );
_bufs.push( buf );
}
Loading