Showing posts with label N900. Show all posts
Showing posts with label N900. Show all posts

Saturday, March 31, 2012

Using camera API and getting raw image frame on N9 (Meego)

Past few weeks I was working on my pet project. I thought to add one feature in this project and it required me to use camera and access its individual raw frame.

Accessing camera on harmattan platform is supported by using QCamera API,  camera API is quite easy to use and I checked camera example application which works on n900.

After going through example application, I decided to use it in my application.

Creating camera and capturing  image or video using QCamera is quite simple and straight forward. I did  not faced any problem with it. But remember you need to request access from aegis framework for using camera, you can use following request for this purpose.
    
    <aegis>
        <request>
            <credential name="GRP::video" />
            <credential name="GRP::pulse-access" />
            <for path="absolute path to application" />
        </request>
    </aegis>


But when I decided to access raw image frame from camera, it did not proved so easy. N900 camera example does not work on N9 and need some changes.

I will try to list those changes and reason here.

To access individual camera frame from camera I decided to use MyVideoSurface class, you can find original source here.

But as I run the program on device, I noticed many camera related error in console and did not capture any valid camera image.

Error goes not like this.
CameraBin error: "Could not negotiate format" 
Reason for this is QCamera on N9, return image in UVVY format, so we need to add this image(QVideoFrame::Format_UYVY) support in MyVideoSurface class. But if you just add this support and dose not implement code to handle this format, you will face follwing error.
Failed to start video surface / CameraBin error: “Internal data flow error.” 
Reason it you can not use QVideoFrame offered in present method call, to create QImage directly. You need to convert image from UYVY to RGB and then use those RGB data to create QImage.

QGraphicsVideoItem class in n900, has a fast implementation of this conversion. You can find its implementation here.

Now you should have a valid QImage that you can use for further processing. Here is my code for MyVideoSurface class after making above changes. This class is tested on N950 device.

MyVideoSurface::MyVideoSurface( QObject* parent)
    : QAbstractVideoSurface(parent)
{
}

bool MyVideoSurface::start(const QVideoSurfaceFormat &format)
{
    mVideoFormat = format;
    //start only if format is UYVY, i dont handle other format now
    if( format.pixelFormat() == QVideoFrame::Format_UYVY ){
        QAbstractVideoSurface::start(format);
        return true;
    } else {
        return false;
    }
}

bool MyVideoSurface::present(const QVideoFrame &frame)
{
    mFrame = frame;

    if (surfaceFormat().pixelFormat() != mFrame.pixelFormat() ||
            surfaceFormat().frameSize() != mFrame.size()) {
        qDebug() << "stop()";
        stop();
        return false;
    } else {
        //this is necessary to get valid data from frame
        mFrame.map(QAbstractVideoBuffer::ReadOnly);

#ifdef  __ARM_NEON__

        QImage lastImage( mFrame.size(), QImage::Format_RGB16);
        const uchar *src = mFrame.bits();
        uchar *dst = lastImage.bits();
        const int srcLineStep = mFrame.bytesPerLine();
        const int dstLineStep = lastImage.bytesPerLine();
        const int h = mFrame.height();
        const int w = mFrame.width();

        for (int y=0; y < h; y++) {
            //this function you can find in qgraphicsvideoitem_maemo5.cpp,
            //link is mentioned above
            uyvy422_to_rgb16_line_neon(dst, src, w);
            src += srcLineStep;
            dst += dstLineStep;
        }

        mLastFrame = QPixmap::fromImage(lastImage);
        //emit signal, other can handle it and do necessary processing
        emit frameUpdated(mLastFrame);

#endif
        mFrame.unmap();

        return true;
    }
}

QList MyVideoSurface::supportedPixelFormats(
            QAbstractVideoBuffer::HandleType handleType) const
{
    if (handleType == QAbstractVideoBuffer::NoHandle) {
        //add support for UYVY format
        return QList<QVideoFrame::PixelFormat>() <<  QVideoFrame::Format_UYVY;
    } else {
        return QList<QVideoFrame::PixelFormat>();
    }
}

And following is MyCamera class, that use above MyVideoSurface class to display individual frame. I derived this class from QDeclarativeItem, so I can use it in QML as well.

MyCamera::MyCamera( QDeclarativeItem * parent ) :
    QDeclarativeItem(parent),mCamera(0)
{
    startCapture();
    mPixmap = new QGraphicsPixmapItem(this);
}

MyCamera::~MyCamera(){
    stopCapture();
}

void MyCamera::stopCapture(){
    if( mCamera )
        mCamera->stop();
}

void MyCamera::startCapture()
{
    mCamera = new QCamera(this);
    //set Still image mode for image capture or Video for capturing video
    //mCamera->setCaptureMode(QCamera::CaptureStillImage);
    mCamera->setCaptureMode(QCamera::CaptureVideo);

    //set my surface, to get individual frame from camera
    mSurface = new MyVideoSurface();
    mCamera->setViewfinder(mSurface );

    connect(mSurface,SIGNAL(frameUpdated(QPixmap)),this,SLOT(frameUpdated(QPixmap)));

    //set up video capture setting
    QVideoEncoderSettings videoSetting;
    //videoSetting.setQuality((QtMultimediaKit::EncodingQuality)0); //low
    videoSetting.setResolution(QSize(848, 480));

    // Media recoder to capture video,use record () to capture video
    QMediaRecorder* videoRecorder = new QMediaRecorder(mCamera);
    videoRecorder->setEncodingSettings(videoRecorder->audioSettings(),videoSetting);

    //  set up image capture setting
    //QImageEncoderSettings imageSetting;
    //imageSetting.setQuality((QtMultimediaKit::EncodingQuality)0); //low
    //imageSetting.setResolution(QSize(320, 240));

    // Image capture to capture Image,use capture() to capture image
    //m_stillImageCapture = new QCameraImageCapture(mCamera,this);
    //m_stillImageCapture->setEncodingSettings(imageSetting);

    // Start camera
    if (mCamera->state() == QCamera::ActiveState) {
        mCamera->stop();
    }
    mCamera->start();
}

void MyCamera::frameUpdated(const QPixmap& pixmap) {
    mPixmap->setPixmap(pixmap);
}

Friday, November 4, 2011

Taking backup of Audiobook Reader on N9/N950

Recently I upgraded my N950 to PR 1.1 and realized that its camera is not working any longer.

After googling a bit I found that issue can be solved by flashing "Linux_OCF_39-5_RM680-RM680-OEM1.bin" image. But that means loosing all data, you can use backup and restore app but unfortunately my Audiobook Reader currently dose not support backup restore.  I need to  implement this feature in next release.

But if you need this support currently like me, then you can try following work around.

Audiobook reader setting file is store at "/home/user/.config/kunal/audiobookreader.conf". You can copy this file to your pc using ssh and then restore it at same place when you need.

I am not sure but same trick can be used for N900 as well.

Hope this helps.

Thursday, October 6, 2011

The Math Game now available for N9/N950 (Harmatta) on Ovi Store

Today The Math Game's Harmattan version passed the Ovi QA process and its now available on Ovi Store.

The Math Game is fun and simple math game for little once. I created  game in hope that it will help to increase kid's interest in Math.

Harmattan version is now available here.

You can find maemo version here.

Please find more information regarding this application here.

Saturday, April 30, 2011

Audiobook Reader for N900 using QML and Phonon

Now days I am trying to learn Qt Quick (QML) and as exercise I decided to upgraded my Audiobook reader application to use QML.

Outcome is pretty good I think, GUI looks much more impressive than earlier though feature set remain same as before.

Currently new version is waiting to be approved by Ovi Store QA. As soon as its cleared you can download it for free from Ovi Store. But its only available for N900 users.

Following is demo video on Qt SDK simulator, Please note that File Dialog will be different on actual hardware.



Following are screen capture from application.



Sunday, December 5, 2010

Audiobook Reader for N900 usign Qt and Phonon

So after long time I found enough time to complete my Audiobook Reader application. This application was in extra-devel repository for long time but there were few problem with it, now finally I worked on those bugs and I am satisfied enough to share information about it.

Now days almost all novels are available in audio format and I am huge fan of those audio book. Previously I was using n900's music player to hear those audio books. But music player dose not preserve last playing position and this create problem when phone restart.

So I created this Audiobook Reader application.Key features are listed below.
  • You can add multiple audiobook.
  • It support both individual audio file which contain whole book, or can add folder which contain books audio file.
  • You can bookmark position in audiobook and can resume from same position.
  • It remember bookmark for all audiobook.This mean you can play multiple audiobook simultaneously.
Following are snaps from  application.


Above snaps is of Book list view. This view list currently added books, 
  • Add Audio button is used to add single audio file which contain whole book content.
  • Add Folder button is used to add folder, which contain multiple audio file for book. Note that you need to select folder which contain audio files, not the individual files.
  • Pokemon icon is used to start playing individual audio book.
  • Cross mark icon is used to remove this book from book list.





In above snaps are from  Reading view.This view list currently played book's title, track name and artist's name.
  • > button is used to play book
  • || button is used to pause book
  • x button is used to stop book, it will put reading position to beginning.
  • <)) button is used to increase/ decrease volume
Currently you can download this application to your n900 from extra-devel repository.

Saturday, October 23, 2010

Creating Qt game for mobile device with differnt screen size

Till now I have created few Qt games for Maemo 5 (N900) device, and now I wanted to run same games on Symbian device which support Qt.

First problem I encounter doing so is different screen size from N900, in my current game implementation I have hard coded screen size and coordination of game object.

After playing with graphics framework from some time, I created a small prototype application that shows two rectangle one on top left other on bottom right corner and can run on different Symbian device and N900 as well. So first thing I did is to remove all hard coded coordinate and implemented resize event, then scaled all graphics item which are added to graphics scene.

Following is my prototype code.

In below code, I have added QGraphicsView as QMainWindow's central widget and also reimplemented resizeEvent of QMainWindow.
GraphicsWidget::GraphicsWidget(QWidget *parent)
    : QMainWindow(parent)
{    
    _scene = new MyScene();
    _scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    _view = new QGraphicsView(_scene,this);
    _view->setDragMode(QGraphicsView::NoDrag);
    _view->setCacheMode(QGraphicsView::CacheBackground);
    _view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);

    setCentralWidget(_view);

    // Disable scrollbars
    _view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    _view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

void GraphicsWidget::resizeEvent(QResizeEvent* event)
{
    _scene->setSceneRect(_view->rect());
    QWidget::resizeEvent(event);
}

And then in MyScene class, derived from QGraphicsScene, on sceneRectChanged signal i am scaling all item to scale factor according to my reference screen size, which is of n900 device's screen size.
MyScene::MyScene()
    :QGraphicsScene()
{
    item1 = new MyGraphicsItem();
    addItem( item1 );

    item2 = new MyGraphicsItem();
    addItem( item2 );
    QObject::connect(this,SIGNAL(sceneRectChanged(QRectF)),
                    this,SLOT(resize(QRectF)));
}

void MyScene::resize(const QRectF& newRect)
{
    qreal w = (qreal)newRect.width()/800 ;
    qreal h =  (qreal)newRect.height()/480;

    item1->resetMatrix();
    item1->scale(w,h);
    item1->setPos(newRect.topLeft());

    item2->resetMatrix();
    item2->scale(w,h);
    item2->setPos(newRect.width()-(item2->boundingRect().width()*w),
            newRect.height() - (item2->boundingRect().height()*h));
}
Finally in main function, I am showing QMainWindow in full screen mode.
int main(int argc, char* argv[] )
{
    QApplication app(argc,argv);
    GraphicsWidget widget;
    widget.showFullScreen();
    return app.exec();
}
Following are snaps from prototype running on emulator for different device.



Sunday, August 29, 2010

Crazy Chickens video on youtube.

I have uploaded video of crazy chickens n900 game on youtube. Here youtube link for video, embedded video is below.

Tuesday, August 24, 2010

Crazy Chickens game for N900 (Maemo) using Qt

Recently I started to learn Qt' graphics view and I decided to put my learning in to some action and as output I created this game called crazy chickens. Its classic egg catcher game.

Goal of game is to catch eggs before they touch the ground. You get four chances if you let egg fall on ground. Speed of game increase as you catch more eggs. To make Motu(the fat boy) catch egg in to basket you need to touch hen which produced the egg. Game dose not take gravity into account so speed of egg remain constant till it fall to ground.

I already uploaded this game to maemo's extra-devel repository, so if you want to try the game enable extra-devel repository. I am also planning to promote this game to extra-testing repository soon so this game should be available in extra-testing repository as well.

Some snaps of this game from my N900.









Saturday, May 8, 2010

Color match game for Maemo using Qt

I have added new game called color match to my reaction game. Idea behind game is to understand problem before you react to it.

In color match game, you will see two box on screen, on upper box there will be text which is color name and lower box will display color. You have to tell if color name displayed in upper box is matching color  displayed in lower box. This is it, if your answer is correct than you will get points. Now in this game I am also considering time which you took to answer, more you take time lower the points.

Here are fews snaps from game. And if you are interested in code, I have uploaded code on my glorious repository. I will also upload game to maemo extra-devel soon.

Friday, April 16, 2010

Live Wallpapers for N900

I found this cool application that makes your wallpaper live and animated.

Here is video fro that application.



Find more information on original blog here.

Wednesday, April 7, 2010

Speed match in Reaction game

Recently I was not able to post anything new. I was busy in updating Reaction game with new game option called Speed Match.

In Speed match you have to remember shape and you have to answer if currnely displayed shape is matching previous shape or not. This game help you to improve your reaction time, working memory and also information processing speed.

Here are few snaps from game.






Scoring is still not in proper shape, i have not considered time taken to answer. I am currenly working on that will update it soon.

If you are instrested in code than i have uploded code on gitorious. To try game on N900, add extra devel repository to application manager and then type "apt-get install reaction" on xterm.

Monday, March 29, 2010

Final Puyo, game for N900

Its took time for me to update my game with final version, because mostly this time I was busy in reading books but as soon as I got time. I fixed performance problem in game, implemented scoring system and done some minor modification.

Performance problem was kind on ignorance from my side than actually a problem. I was drawing a large image in small area every now and than. So most time was going in to scaling image to make it fit to draw in small area. I reduced my image size to draw area and from then onwards game is running smooth on N900.
 
Here is link to debian file,for you to try on you N900.Please make sure that you have qt 4.6 installed before installing this debian package. I am also planning to ad this game on maemo extra devel repository, then onwards you will be able to download game from N900's application manager.

To play game shake phone left or right to move falling smilies accordingly. Goal is to arrange smiley of same color in horizontal,vertical or square of four to make them disappear.Game is vary simple and dose not support rotation of smiles and dose not change speed with time. Game will end smiley touch top of board.

Following are few snaps from new Puyo.

Thursday, March 18, 2010

Reaction game for N900 to measure brain's reaction time

While working on improving performance of Puyo game, to bring some freshness to my mind I thought to divert my attention to some other activity, so I thought to create another simple game that helps to measure and  improve brain's reaction time.

Game will show you a blue rectangle at random place and you have to touch that rectangle within some time limit. If you manage to touch it than it increase your point. More  points mean better reaction time. If you get points more than 55 than it mean you have awesome reaction time.

If you want to download game and try it on your N900 then here is link.

Here are snaps from game.








Sunday, March 7, 2010

Turn N900 to WiFi hotspot using JoikuSpot

Joiku has release beta version of JoikuSpot for linux and maemo platform. By using JoikuSpot you can turn your N900 to WiFi hotspot and can share your 3G connection or Gprs connection with other device like iPod, Laptop or other mobile phone.

I  tried to install this on my N900. Initially I had some problem downloading software to my device but after installation it worked awesome. Configuration is quite easy, you can start using it just after installation with default option. Or if you prefer to configure security , implement NAT option or choose IP range , it allows you to change those parameter as well.

If you want to try it out download it from here.

Here are snaps of JoikuSpot working on my N900. 

N900N900

Friday, March 5, 2010

Puyo game for N900, created using Qt

I have created simple game named Puyo for N900 using Qt, its kind of Tatris game. It use N900's accelerometer to move smiles left or right and smiles will disappear if three or more smilies with same color appear in row or column.

Here are screenshots of my little game. Its still under development and might have some bugs. If you want to try this game, I am attaching debian installer and also instruction for installation.






Download debian package from here. This package depends on Maemo Qt Extra Library , so you need to install Qt extra library as well. Find instruction here to install Maemo Qt Extra library.

You will also need root access to install this debian packge. If you don't have root access to device, Install rootsh script from application manager that will help you to get root access.

Taking screenshot of Screen on N900

I have created one application on my N900 and wanted to take screen shot of that application while it is running on N900. I tried to search such application on application manager but was not able to find such application. So i tried to Google for this and after searching while I found that N900 already have screen capture utility installed and to capture screen there is special key combination. Key combination is CTRL + SHIFT + P.  By pressing this key combination this utility will capture screen and save image in /Images/Screenshots  folder.

Here is my sample screenshot.