Convert an audio to uncompress wav by libvlc - c++

OS : win10 64 bits
compiler : vc2017 64bits
vlc version : 3.0.9.2 from here
Source codes
#include <vlc/vlc.h>
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
void libvlc_callback(libvlc_event_t const *event, void*)
{
switch (event->type) {
case libvlc_MediaMetaChanged:
std::cout<<__func__<<": libvlc_MediaMetaChanged = "<<event->u.media_meta_changed.meta_type<<std::endl;
break;
case libvlc_MediaSubItemAdded:
std::cout<<__func__<<": libvlc_MediaSubItemAdded = "<<event->u.media_subitem_added.new_child<<std::endl;
break;
case libvlc_MediaDurationChanged:
std::cout<<__func__<<": libvlc_MediaDurationChanged = "
<<event->u.media_duration_changed.new_duration<<std::endl;
break;
case libvlc_MediaParsedChanged:
std::cout<<__func__<<": libvlc_MediaParsedChanged = "<<event->u.media_parsed_changed.new_status<<std::endl;
break;
case libvlc_MediaFreed:
std::cout<<__func__<<": libvlc_MediaFreed = "<<event->u.media_freed.md<<std::endl;
break;
case libvlc_MediaStateChanged:
std::cout<<__func__<<":libvlc_MediaStateChanged = "<<event->u.media_state_changed.new_state<<std::endl;
break;
default:
break;
}
}
std::vector<libvlc_event_e> create_events()
{
return {libvlc_MediaMetaChanged,
libvlc_MediaSubItemAdded,
libvlc_MediaDurationChanged,
libvlc_MediaParsedChanged,
libvlc_MediaFreed,
libvlc_MediaStateChanged};
}
int main()
{
libvlc_instance_t *inst = libvlc_new(0, nullptr);
char const *location = "C:/Users/ssss/audio/audio.mp3";
libvlc_media_t *vlc_media = libvlc_media_new_location(inst, location);
libvlc_event_manager_t *vlc_events = libvlc_media_event_manager(vlc_media);
for(libvlc_event_e const &event : create_events()){
libvlc_event_attach(vlc_events, event, libvlc_callback, nullptr);
}
libvlc_media_add_option(vlc_media, "--sout='#transcode{acodec=s16l, ab=16, channels=1, samplerate=16000}:"
"std{access=file, mux=wav, "
"dst=\"audio.wav\"}'");
std::this_thread::sleep_for(std::chrono::seconds(10));
libvlc_media_release(vlc_media);
libvlc_release(inst);
}
The output I got are
main libvlc debug: VLC media player - 3.0.9.2 Vetinari
main libvlc debug: Copyright © 1996-2020 the VideoLAN team
main libvlc debug: revision 3.0.9.2-0-gd4c1aefe4d
main libvlc debug: configured with ../extras/package/win32/../../../configure '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=x86_64-w64-mingw32' '--with-breakpad=https://win.crashes.videolan.org' 'host_alias=x86_64-w64-mingw32' 'PKG_CONFIG_LIBDIR=/home/jenkins/workspace/vlc-release/windows/vlc-release-win32-x64/contrib/x86_64-w64-mingw32/lib/pkgconfig'
main libvlc debug: using multimedia timers as clock source
main libvlc debug: min period: 1 ms, max period: 1000000 ms
main libvlc debug: searching plug-in modules
main libvlc debug: loading plugins cache file C:\vlc-3.0.9.2-win64\plugins\plugins.dat
main libvlc warning: cannot read C:\vlc\vlc-3.0.9.2-win64\plugins\plugins.dat: No such file or directory
main libvlc debug: recursively browsing `C:\vlc\vlc-3.0.9.2-win64\plugins'
main libvlc debug: plug-ins loaded: 494 modules
main logger debug: looking for logger module matching "any": 2 candidates
main logger debug: using logger module "console"
main libvlc debug: translation test: code is "C"
main keystore debug: looking for keystore module matching "memory": 3 candidates
main keystore debug: using keystore module "memory"
main libvlc debug: CPU has capabilities MMX MMXEXT SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 FPU
libvlc_callback: libvlc_MediaFreed = 000001DBD602CC50
main libvlc debug: exiting
main libvlc debug: no exit handler
main libvlc debug: removing all interfaces
main keystore debug: removing module "memory"
I cannot see any audio.wav generated in the folder, which step I missed or done it wrong? Thanks
Edit: pass parameters into libvlc_new
const char * const vlc_args[] = {
"--sout",
"#transcode{acodec=s16l,channels=2,samplerate=44100}:std{access=file,mux=wav,dst=\"C:/my_path/clip_0002.wav\"}",
"C:/my_path/audio.wav"};
libvlc_instance_t *inst = libvlc_new(3, vlc_args);
std::this_thread::sleep_for(std::chrono::seconds(60));
libvlc_release(inst);
It give me output message
main libvlc debug: exiting
main libvlc debug: no exit handler
main libvlc debug: removing all interfaces
main keystore debug: removing module "memory"
Don't know why the output file 'audio.wav' never generated in the folder

Found a solution, you need to play the media and open the file correctly, for simplicity I use "libvlc_media_new_path" in this example, if you are using "libvlc_media_new_location", remember to append "file:///" before the location and change to native separator.
#include "core/vlc_error.hpp"
#include <vlc/vlc.h>
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include <QString>
void libvlc_callback(libvlc_event_t const *event, void*)
{
switch (event->type) {
case libvlc_MediaMetaChanged:
std::cout<<__func__<<": libvlc_MediaMetaChanged = "<<event->u.media_meta_changed.meta_type<<std::endl;
break;
case libvlc_MediaSubItemAdded:
std::cout<<__func__<<": libvlc_MediaSubItemAdded = "<<event->u.media_subitem_added.new_child<<std::endl;
break;
case libvlc_MediaDurationChanged:
std::cout<<__func__<<": libvlc_MediaDurationChanged = "
<<event->u.media_duration_changed.new_duration<<std::endl;
break;
case libvlc_MediaParsedChanged:
std::cout<<__func__<<": libvlc_MediaParsedChanged = "<<event->u.media_parsed_changed.new_status<<std::endl;
break;
case libvlc_MediaFreed:
std::cout<<__func__<<": libvlc_MediaFreed = "<<event->u.media_freed.md<<std::endl;
break;
case libvlc_MediaStateChanged:
std::cout<<__func__<<":libvlc_MediaStateChanged = "<<event->u.media_state_changed.new_state<<std::endl;
break;
default:
break;
}
}
std::vector<libvlc_event_e> create_events()
{
return {libvlc_MediaMetaChanged,
libvlc_MediaSubItemAdded,
libvlc_MediaDurationChanged,
libvlc_MediaParsedChanged,
libvlc_MediaListEndReached,
libvlc_MediaFreed,
libvlc_MediaStateChanged};
}
int main()
{
libvlc_instance_t *inst = libvlc_new(0, nullptr);
char const *location = "clip_0002.wav";
libvlc_media_t *vlc_media = libvlc_media_new_path(inst, location);
libvlc_event_manager_t *vlc_events = libvlc_media_event_manager(vlc_media);
for(libvlc_event_e const &event : create_events()){
libvlc_event_attach(vlc_events, event, libvlc_callback, nullptr);
}
QString const cmd("transcode{acodec=s16l, ab=16, channels=1, samplerate=16000}:"
"std{access=file, mux=wav, "
"dst='audio.wav'}");
QString config = ":sout=#duplicate{dst=display,dst=\"%1\"}";
config = config.arg(cmd);
std::cout<<"-------------------------"<<std::endl;
std::cout<<config.toStdString()<<std::endl;
libvlc_media_add_option(vlc_media, ":sout-all");
qt_vlc::vlc_error::show_err_msg();
libvlc_media_add_option(vlc_media, config.toUtf8().data());
qt_vlc::vlc_error::show_err_msg();
libvlc_media_player_t *vlc_player = libvlc_media_player_new_from_media(vlc_media);
libvlc_audio_set_mute(vlc_player, true);
libvlc_media_player_play(vlc_player);
while(1){
qt_vlc::vlc_error::show_err_msg();
if(libvlc_media_get_state(vlc_media) == libvlc_Ended){
break;
}
std::cout<<"media state = "<<libvlc_media_get_state(vlc_media)<<std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
libvlc_media_player_release(vlc_player);
libvlc_media_release(vlc_media);
libvlc_release(inst);
}
You can convert video to audio by this solution too, problem is it will show the video when converting, finding a way to hide the video.

Related

Live555 RTSP server: no data received

I'm trying to write a C++ program, that sends a bunch of images and converts them into a RTSP stream. After some grinding, I've came up with the code for that. VLC seems to connect to the server, but it gets no data, then it quits... Can anyone tell me what I'm doing wrong? Thank you!
VLC just tells me this:
main debug: processing request item: rtsp://192.168.56.1/ScreenShots, node: Playlist, skip: 0
main debug: rebuilding array of current - root Playlist
main debug: rebuild done - 1 items, index 0
main debug: starting playback of new item
main debug: resyncing on rtsp://192.168.56.1/ScreenShots
main debug: rtsp://192.168.56.1/ScreenShots is at 0
main debug: creating new input thread
main debug: Creating an input for 'rtsp://192.168.56.1/ScreenShots'
main debug: requesting art for new input thread
main debug: using timeshift granularity of 50 MiB
main debug: using timeshift path: C:\Users\Benny\AppData\Local\Temp
main debug: looking for meta fetcher module matching "any": 1 candidates
main debug: `rtsp://192.168.56.1/ScreenShots' gives access `rtsp' demux `any' path `192.168.56.1/ScreenShots'
main debug: creating demux: access='rtsp' demux='any' location='192.168.56.1/ScreenShots' file='\\192.168.56.1\ScreenShots'
main debug: looking for access_demux module matching "rtsp": 15 candidates
lua debug: Trying Lua scripts in C:\Users\Benny\AppData\Roaming\vlc\lua\meta\fetcher
lua debug: Trying Lua scripts in C:\Program Files\VideoLAN\VLC\lua\meta\fetcher
main debug: no meta fetcher modules matched
main debug: looking for art finder module matching "any": 2 candidates
live555 debug: version 2016.11.28
lua debug: Trying Lua scripts in C:\Users\Benny\AppData\Roaming\vlc\lua\meta\art
lua debug: Trying Lua scripts in C:\Program Files\VideoLAN\VLC\lua\meta\art
lua debug: Trying Lua playlist script C:\Program Files\VideoLAN\VLC\lua\meta\art\00_musicbrainz.luac
lua debug: skipping script (unmatched scope) C:\Program Files\VideoLAN\VLC\lua\meta\art\00_musicbrainz.luac
lua debug: Trying Lua playlist script C:\Program Files\VideoLAN\VLC\lua\meta\art\01_googleimage.luac
lua debug: skipping script (unmatched scope) C:\Program Files\VideoLAN\VLC\lua\meta\art\01_googleimage.luac
lua debug: Trying Lua playlist script C:\Program Files\VideoLAN\VLC\lua\meta\art\02_frenchtv.luac
lua debug: skipping script (unmatched scope) C:\Program Files\VideoLAN\VLC\lua\meta\art\02_frenchtv.luac
lua debug: Trying Lua playlist script C:\Program Files\VideoLAN\VLC\lua\meta\art\03_lastfm.luac
lua debug: skipping script (unmatched scope) C:\Program Files\VideoLAN\VLC\lua\meta\art\03_lastfm.luac
main debug: no art finder modules matched
live555 debug: RTP subsession 'video/H264'
qt debug: IM: Setting an input
main debug: selecting program id=0
live555 debug: setup start: 0.000000 stop:0.000000
live555 debug: We have a timeout of 65 seconds
live555 debug: play start: 0.000000 stop:0.000000
main debug: using access_demux module "live555"
main debug: looking for packetizer module matching "any": 25 candidates
h264 debug: found NAL_SPS (sps_id=7)
h264 debug: found NAL_PPS (pps_id=7 sps_id=7)
main debug: using packetizer module "h264"
main debug: looking for video decoder module matching "any": 19 candidates
avcodec debug: using ffmpeg Lavc58.6.103
avcodec debug: CPU flags: 0x000fd3db
avcodec debug: allowing 6 thread(s) for decoding
avcodec debug: codec (h264) started
avcodec debug: using frame thread mode with 6 threads
main debug: using video decoder module "avcodec"
main debug: looking for meta reader module matching "any": 2 candidates
lua debug: Trying Lua scripts in C:\Users\Benny\AppData\Roaming\vlc\lua\meta\reader
lua debug: Trying Lua scripts in C:\Program Files\VideoLAN\VLC\lua\meta\reader
lua debug: Trying Lua playlist script C:\Program Files\VideoLAN\VLC\lua\meta\reader\filename.luac
main debug: no meta reader modules matched
main debug: `rtsp://192.168.56.1/ScreenShots' successfully opened
live555 error: no data received in 10s, aborting
main debug: EOF reached
main debug: killing decoder fourcc `h264'
main debug: removing module "avcodec"
main debug: removing module "h264"
main debug: removing module "live555"
main debug: Program doesn't contain anymore ES
main debug: dead input
main debug: changing item without a request (current 0/1)
main debug: nothing to play
qt debug: IM: Deleting the input
Here is how I do this in code:
Starting the server:
void startServer(void * aArg) {
rtspServer = new OTPRTSPServer(554);
if (!rtspServer->init(DEFAULT_MONITOR.maxResolution.width, DEFAULT_MONITOR.maxResolution.height, 20)) {
cerr << "Could not start the RTSP Server" << endl;
exit(1);
}
rtspServer->addSession("ScreenShots");
rtspServer->play();
readyToSetFrame = true;
rtspServer->doEvent();
}
Here are the RTSPServer functions that I've wrote:
bool init(int srcWidth, int srcHeight, int fps) {
m_srcWidth = srcWidth;
m_srcHeight = srcHeight;
m_fps = fps;
OutPacketBuffer::maxSize = 100000;
int cNameLen = 100;
m_cName.resize(cNameLen + 1, 0);
gethostname((char*)&(m_cName[0]), cNameLen);
m_rtspServer = RTSPServer::createNew(*m_env, m_rtspPort, nullptr);
if (m_rtspServer == nullptr) {
std::cerr << "Failed to create RTSP server: " << m_env->getResultMsg() << std::endl;
return false;
}
m_screenSource = ScreenSource::createNew(*m_env, m_srcWidth * m_srcHeight, 10);
if (!m_screenSource->openEncoder(m_srcWidth, m_srcHeight, m_fps)) {
std::cerr << "Failed to open X264 encoder: " << std::endl;
return false;
}
return true;
}
void addSession(const std::string& streamName) {
sockaddr_storage destinationAddress;
((struct sockaddr_in&)destinationAddress).sin_addr.s_addr = chooseRandomIPv4SSMAddress(*m_env);
const Port rtpPort(m_rtpPortNum);
const Port rtcpPort(m_rtcpPortNum);
auto rtpGroupSock = new Groupsock(*m_env, destinationAddress, rtpPort, m_ttl);
m_rtpGroupSock->multicastSendOnly();
auto rtcpGroupSock = new Groupsock(*m_env, destinationAddress, rtcpPort, m_ttl);
m_rtcpGroupSock->multicastSendOnly();
m_videoSink = H264VideoRTPSink::createNew(*m_env, rtpGroupSock, m_rtpPayloadFormat);
m_rtcp = RTCPInstance::createNew(*m_env, rtcpGroupSock, m_estimatedSessionBandwidth, &(m_cName[0]), m_videoSink, nullptr, True);
auto sms = ServerMediaSession::createNew(*m_env, streamName.c_str(), "Screen image", "Image from the screen", True);
sms->addSubsession(PassiveServerMediaSubsession::createNew(*m_videoSink, m_rtcp));
m_rtspServer->addServerMediaSession(sms);
std::cout << "Play this stream using the Local URL: " << m_rtspServer->rtspURL(sms) << std::endl;
}
inline void play() {
m_videoES = m_screenSource;
m_videoSource = H264VideoStreamFramer::createNew(*m_env, m_videoES);
m_videoSink->startPlaying(*m_videoSource, nullptr, nullptr);
}
inline void doEvent() {
std::cout << "Doing event loop..." << std::endl;
m_env->taskScheduler().doEventLoop();
std::cout << "Done doing event loop" << std::endl;
}
inline void streamImage(const uint8_t* src, const int index) {
m_screenSource->encode(src);
}

SET Request impossible with snmpSET and netsnmp lib

i have an agent thanks to netsnmp library , its working fine for the Getrequest , I use MibIreasonning to do my test of get and set however I have a big problem for the set , when I do the snmp set i got no Response and the value dosent change , with command line i use :
snmpset -v2c -cprivate 127.0.0.1:10181 1.3.6.1.4.1.4045.61005681.20.2.3.0.0 i 1
and i got : Timeout: No Response from 127.0.0.1:10181
and If i do snmpset in public I got : Error in packet , Reason noAccess
Here is my code if you can please help me :
//-------------------------------------------------------------------------------------------------
// ValueOID
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <iostream>
#include <string>
int handle_AgentSNMP15 (
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
int value=0 ;
switch (reqinfo->mode) {
case MODE_GET:
std::cout<<"GETSNMP15"<<std::endl;
std::cout<<"get value "<<*(requests->requestvb->val.integer)<<std::endl;
snmp_set_var_typed_value(
requests->requestvb,
ASN_INTEGER,
(u_char*)&value,
sizeof(value));
break;
case MODE_SET_RESERVE1:
std::cout<<*(requests->requestvb->val.integer)<<std::endl;
case MODE_SET_RESERVE2:
value = *(requests->requestvb->val.integer);
std::cout<<"RESERVE2"<<std::endl;
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
std::cout<<"SETACTION"<<std::endl;
value = *(requests->requestvb->val.integer);
break;
case MODE_SET_COMMIT:
std::cout<<"SETCOMMIT"<<std::endl;
value = *(requests->requestvb->val.integer);
break;
case MODE_SET_UNDO:
break;
default:
{
snmp_log(
LOG_ERR,
"Unknown mode (%d) in handle_dot1dBaseType\n",
reqinfo->mode);
std::cout<<"ERROR OTHER THAN GET";
return SNMP_ERR_GENERR;
}
}
return SNMP_ERR_NOERROR;
}
void init_Value() {
static oid AgentSNMP15[]={1,3,6,1,4,1,4045,61005681,20,2,3,0};
netsnmp_register_scalar(netsnmp_create_handler_registration(
"agentSNMP15",
handle_AgentSNMP15,
AgentSNMP15,
OID_LENGTH(AgentSNMP15),
HANDLER_CAN_RWRITE));
}
Thanks for your help

how to view stream sent by me libvlc C/C++

im on Ubuntu 14.04 and I'm trying to write a program that will stream my desktop, using the answer to this: libvlc stream part of screen as an example. However, I don't have another computer readily aviable to see that the stream is going along well, so how can I view that stream on my computer?
libvlc_vlm_add_broadcast(inst, "mybroad", "screen://",
"#transcode{vcodec=h264,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ts,dst=:8080/stream}",
5, params, 1, 0)
My program throws no errors, and writes this
[0x7f0118000e18] x264 encoder: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[0x7f0118000e18] x264 encoder: profile High, level 3.0
[0x7f0118000e18] x264 encoder: final ratefactor: 25.54
[0x7f0118000e18] x264 encoder: using SAR=1/1
[0x7f0118000e18] x264 encoder: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[0x7f0118000e18] x264 encoder: profile High, level 2.2
So to me, everything seems ok. However, I don't know how to view that stream from my computer- if I open vlc and try to open a network stream, using http:// #:7777 (space on purpose, website does not allow to post such links) I get the invalid host error in its log. This probably is a silly mistake or error on my part, but any help would be greatly appreciated!
if anyone needs it, this is my entire code (I'm using QT 4.8.6):
#include <QCoreApplication>
#include <iostream>
#include <vlc/vlc.h>
#include <X11/Xlib.h>
// #include <QDebug>
using namespace std;
bool ended;
void playerEnded(const libvlc_event_t* event, void *ptr);
libvlc_media_list_t * subitems;
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *media;
libvlc_media_t * stream;
int main(int argc, char *argv[])
{
XInitThreads();
QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
ended = false;
QCoreApplication a(argc, argv);
// the array with parameters
const char* params[] = {"screen-top=0",
"screen-left=0",
"screen-width=640",
"screen-height=480",
"screen-fps=10"};
// Load the VLC engine */
inst = libvlc_new (0, NULL);
if(!inst)
std::cout << "Can't load video player plugins" << std::endl;
cout<< "add broacast: " <<
libvlc_vlm_add_broadcast(inst, "mybroad",
"screen://",
"#transcode{vcodec=h264,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ts,dst=:8080/stream}",
5, params, // <= 5 == sizeof(params) == count of parameters
1, 0)<< '\n';
cout<< "poczatek broacastu: " <<libvlc_vlm_play_media(inst, "mybroad")<< '\n';
media = libvlc_media_new_location(inst,http://#:8080/stream");
// Create a media player playing environment
mp = libvlc_media_player_new (inst);
libvlc_media_player_play (mp);
cout<<"szatan!!!"<<endl;
int e;
cin>>e;
/* Stop playing */
libvlc_media_player_stop (mp);
/* Free the media_player */
libvlc_media_player_release (mp);
libvlc_release (inst);
return a.exec();
}
so, i have found the answer- stack overflow wont let me post an answer because I'm new here, so its in the comments! I should have used my IP address when creating media: media = libvlc_media_new_location(inst, "http: //192.168.1.56:8080");(space on purpose so that forum does not hide link) works great! –

Unresolved Externals in Irrlicht

I am currently coding in Visual Studio 2010, using C++ and the Irrlicht game engine. I have tried asking this question on their forum, however I haven't had any response.
I am using the tutorials on the Irrlicht website:
http://irrlicht.sourceforge.net/docu/example002.html
The error I am getting is: "unresolved external symbol _imp_createDevice referenced in function _main"
I have added linked the Irrlicht library and include files already, but I am still getting this error.
// Tutorial2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) OpenGL 1.5\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n"\
" (d) Burning's Software Renderer\n (e) Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a':driverType = video::EDT_OPENGL; break;
case 'b':driverType = video::EDT_DIRECT3D9; break;
case 'c':driverType = video::EDT_DIRECT3D8; break;
case 'd':driverType = video::EDT_BURNINGSVIDEO; break;
case 'e':driverType = video::EDT_SOFTWARE; break;
case 'f':driverType = video::EDT_NULL; break;
default: return 1;
}
// create device and exit if creation failed
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(640, 480));
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
// node = smgr->addmeshSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
while(device->run())
{
if(device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example[";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
device->drop();
return 0;
}
I've managed to build the sample, no problem.
The only way to get your error is to mix the 32 and 64bit lib files.
Rename the 64bit library Irrlicht_x64.lib and try building again.

trouble with Open Cv and GPIO on mini6410

I am doing a simple project on arm based mini6410. I have debian package installed on mini. My project is to interface one IR motion sensor and I USB webcam with the mini6410. the working will be simple, whenever there will be any motion detected by IR sensor, the webcam will be on for 30 seconds save the images (over write the previous) and then off.
I have already cross comiled the Open CV code using arm-linux-gcc
For IR I am using GPE register.
Here I am stuck with a issue which I am unable to resolve. and even dont know how to resolve. OpenCv code is a cpp file camera.cpp and the file which deals with I/O ports is a C file named sensor.c. Now in that c file I am polling or whatever mechanism to check if the GPE register is 1 or not. If it is one, I should start the Open CV code which will start to capture images. further more this sensor.c file is not to be compiled rather made a module and then insmod on my mini6410.
However I dont know how to write c++ code in a c file. you can say i dont know how to call the OpenCV thing from the C file. as it is a module and within this i cant write the cpp code as then using namespace std and using namespace cv doesnot work.
i am new to embedded stuff and linux it self. so I wanted to know are there some possible solutions.
i am attaching my codes of both files.
This is sensor.c
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/serio.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <mach/map.h>
#include <mach/regs-clock.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#include <mach/gpio-bank-q.h>
#include <mach/gpio-bank-e.h>
#include <mach/map.h>
#include <plat/regs-timer.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/moduleparam.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>
#include <mach/gpio-bank-k.h>
#define RLV 0x0FFF
unsigned Gpe;
unsigned sensor_value;
typedef struct
{
int delay;
} TIM_DEV;
static TIM_DEV TimDev;
static irqreturn_t INTHandler(int irq,void *TimDev)
{
Gpe = readl(S3C64XX_GPEDAT);
Gpe &= ~(0xF<<1);
readl(sensor_value, S3C64XX_GPEDAT);
while (sensor_value == 1)
{//1 means that IR sensor has detected a motion and given a value of +5 V
for (i = 0; i < 30; i++){
//CV_function();
// delay here such that delay(1 s) * 30 = 30 seconds
}
}
return IRQ_HANDLED;
}
static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.write = MyWrite,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
unsigned TimerControl;
unsigned TimerINTControl;
unsigned TimerCNTB;
unsigned TimerCMPB;
unsigned TimerCFG1;
unsigned Ge;
TimerControl = readl(S3C_TCON);
TimerINTControl = readl(S3C_TINT_CSTAT);
TimerCNTB = readl(S3C_TCNTB(0));
TimerCMPB = readl(S3C_TCMPB(0));
TimerCFG1 = readl(S3C_TCFG1);
TimerCFG1 &= ~(S3C_TCFG1_MUX0_MASK);
TimerCNTB = RLV;
TimerCMPB = 0;
writel(TimerCNTB, S3C_TCNTB(0));
writel(TimerCMPB, S3C_TCMPB(0));
writel(TimerCFG1, S3C_TCFG1);
TimerControl |= S3C_TCON_T0MANUALUPD;
TimerINTControl |= S3C_TINT_CSTAT_T0INTEN;
writel(TimerControl, S3C_TCON);
writel(TimerINTControl, S3C_TINT_CSTAT);
TimerControl = readl(S3C_TCON);
TimerControl |= S3C_TCON_T0RELOAD;
TimerControl &= ~S3C_TCON_T0MANUALUPD;
TimerControl |= S3C_TCON_T0START;
writel(TimerControl, S3C_TCON);
//////////////Here I am configuring my GPE as input/////////////
Ge = readl(S3C64XX_GPECON);
Ge &= ~(0xFFFF<<4);
Ge |= (0x0000<<4);
writel(Ge, S3C64XX_GPECON);
/////////////
misc_register(&misc);
ret = request_irq(IRQ_TIMER0, INTHandler, IRQF_SHARED, DEVICE_NAME, &TimDev);
if (ret)
{
return ret;
}
return ret;
}
static void __exit dev_exit(void)
{
free_irq(IRQ_TIMER0, &TimDev);
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("XYZ");
this is camera.cpp
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{CvCapture* capture = 0;
Mat frame, frameCopy, image;
capture = cvCaptureFromCAM( 2 );
if( !capture )
{
cout << "No camera detected" << endl;
}
if( capture )
{
cout << "In capture ..." << endl;
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
break;
if( iplImg->origin == IPL_ORIGIN_TL )
frame.copyTo( frameCopy );
else
flip( frame, frameCopy, 0 );
cvSaveImage("image.jpg" ,iplImg);
}
cvReleaseCapture( &capture );
return 0;
}
the for loop in the sensor.c file should have my this above code by some means
I hope you get the idea,
Thanks
The missing link in the code shown is a mechanism by which the user-space code shown above can get notification of a change in the GPIO pin detected by the device driver.
There are two obvious ways to achieve this:
Integrate the GPIO pin into the platform's GPIO resources and then use the generic sysfs mechanism from user-space. The Linux kernel GPIO documentation describes both kernel and user-space side of this.
Have your driver expose a sysfs node for the GPIO line. sysfs is fundamental to the Linux Driver Model. I suggest a thorough read of Linux Device Drivers 3rd Edition.
The user-space side of either method is similar: You open the sysfs resource exported by your module and then use either poll() or select() to block until an event occurs.