Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 97
Registered: ‎11-13-2012
My Device: BB10 Simulator
My Carrier: Globe Telecom
Accepted Solution

[HELP] H264 Video Camera trying to modify HelloVideoCamera

I am very new to Video Recording and Video Encoding stuffs.

 

In this line I get Error 22

 

camera_error_t error = camera_start_encode(mCameraHandle, NULL, NULL, NULL, NULL, NULL);

fprintf(stderr, "camera_start_encode() error %d", error); // It returns 22

 

 I checked here https://developer.blackberry.com/native/reference/core/com.qnx.doc.camera.lib_ref/topic/camera_error... what's the error 22 but I can't see any error values with 22

 

here's my full code

 

HelloVideoCameraApp::HelloVideoCameraApp(bb::cascades::Application *app) :
        QObject(app),
        mCameraHandle(CAMERA_HANDLE_INVALID),
        mVideoFileDescriptor(-1)
{
    mViewfinderWindow = ForeignWindowControl::create().windowId(QString("cameraViewfinder"));
    mViewfinderWindow->setUpdatedProperties(WindowProperty::Position | WindowProperty::Size | WindowProperty::Visible);
 
    QObject::connect(mViewfinderWindow, SIGNAL(windowAttached(screen_window_t, const QString &, const QString &)), this, SLOT(onWindowAttached(screen_window_t, const QString &,const QString &)));
 
    mStartFrontButton = Button::create("Front Camera").onClicked(this, SLOT(onStartFront()));
    mStartRearButton = Button::create("Rear Camera").onClicked(this, SLOT(onStartRear()));
    mStopButton = Button::create("Stop Camera").onClicked(this, SLOT(onStopCamera()));
    mStopButton->setVisible(false);
    mStartStopButton = Button::create("Record Start").onClicked(this, SLOT(onStartStopRecording()));
    mStartStopButton->setVisible(false);
 
    mStatusLabel = Label::create("filename");
    mStatusLabel->setVisible(false);
 
    Container* container = Container::create()
        .layout(DockLayout::create())
        .add(Container::create()
            .horizontal(HorizontalAlignment::Center)
            .vertical(VerticalAlignment::Center)
            .add(mViewfinderWindow))
        .add(Container::create()
            .horizontal(HorizontalAlignment::Left)
            .vertical(VerticalAlignment::Top)
            .add(mStatusLabel))
        .add(Container::create()
            .horizontal(HorizontalAlignment::Center)
            .vertical(VerticalAlignment::Bottom)
            .layout(StackLayout::create()
                        .orientation(LayoutOrientation::LeftToRight))
                        .add(mStartFrontButton)
                        .add(mStartRearButton)
                        .add(mStartStopButton)
                        .add(mStopButton));
 
 
    app->setScene(Page::create().content(container));
}
 
HelloVideoCameraApp::~HelloVideoCameraApp()
{
}
 
void HelloVideoCameraApp::onWindowAttached(screen_window_t win, const QString &group, const QString &id)
{
    int i = (mCameraUnit == CAMERA_UNIT_FRONT);
    screen_set_window_property_iv(win, SCREEN_PROPERTY_MIRROR, &i);
    i = -1;
    screen_set_window_property_iv(win, SCREEN_PROPERTY_ZORDER, &i);
    screen_context_t screen_ctx;
    screen_get_window_property_pv(win, SCREEN_PROPERTY_CONTEXT, (void **)&screen_ctx);
    screen_flush_context(screen_ctx, 0);
}
 
int HelloVideoCameraApp::createViewfinder(camera_unit_t cameraUnit, const QString &group, const QString &id)
{
    if (mCameraHandle != CAMERA_HANDLE_INVALID)
    {
        qDebug() << "camera already running";
        return EBUSY;
    }
 
    mCameraUnit = cameraUnit;
 
    if (camera_open(mCameraUnit,CAMERA_MODE_RW | CAMERA_MODE_ROLL,&mCameraHandle) != CAMERA_EOK)
    {
        qDebug() << "could not open camera";
        return EIO;
    }
 
    qDebug() << "camera opened";
 
    //camera_set_video_property(mCameraHandle, CAMERA_IMGPROP_VIDEOCODEC, CAMERA_VIDEOCODEC_H264);
 
    camera_error_t error = camera_set_video_property(mCameraHandle,
                                                                CAMERA_IMGPROP_VIDEOCODEC, CAMERA_VIDEOCODEC_H264,
                                                                CAMERA_IMGPROP_WIDTH, 640,
                                                                CAMERA_IMGPROP_HEIGHT, 352,
                                                                CAMERA_IMGPROP_FRAMERATE, (double)30.0);
 
    if(error == CAMERA_EOK)
        {
                qDebug() << "VIDEO PROPERTY SUCCESS";
        }
        else
        {
                qDebug() << "VIDEO PROPERTY ERROR: " << error;
        }
 
    if (camera_set_videovf_property(mCameraHandle,CAMERA_IMGPROP_WIN_GROUPID, group.toStdString().c_str(),CAMERA_IMGPROP_WIN_ID, id.toStdString().c_str()) == CAMERA_EOK)
    {
        qDebug() << "viewfinder configured";
 
        if (camera_start_video_viewfinder(mCameraHandle, NULL, NULL, NULL) == CAMERA_EOK)
        {
            qDebug() << "viewfinder started";
            mStartFrontButton->setVisible(false);
            mStartRearButton->setVisible(false);
            mStopButton->setVisible(true);
            mStartStopButton->setText("Start Recording");
            mStartStopButton->setVisible(true);
            mStartStopButton->setEnabled(true);
            return EOK;
        }
    }
 
    qDebug() << "couldn't start viewfinder";
 
    camera_close(mCameraHandle);
    mCameraHandle = CAMERA_HANDLE_INVALID;
    return EIO;
}
 
void HelloVideoCameraApp::onStartFront()
{
    qDebug() << "onStartFront";
 
    if (mViewfinderWindow)
    {
        // create a window and see if we can catch the join
        if (createViewfinder(CAMERA_UNIT_FRONT,mViewfinderWindow->windowGroup().toStdString().c_str(),mViewfinderWindow->windowId().toStdString().c_str()) == EOK)
        {
            qDebug() << "created viewfinder";
        }
    }
}
 
void HelloVideoCameraApp::onStartRear()
{
    qDebug() << "onStartRear";
 
    if (mViewfinderWindow)
    {
        // create a window and see if we can catch the join
        if (createViewfinder(CAMERA_UNIT_REAR,mViewfinderWindow->windowGroup().toStdString().c_str(),mViewfinderWindow->windowId().toStdString().c_str()) == EOK)
        {
            qDebug() << "created viewfinder";
        }
    }
}
 
void HelloVideoCameraApp::onStopCamera()
{
    qDebug() << "onStopCamera";
 
    if (mCameraHandle != CAMERA_HANDLE_INVALID)
    {
        // closing the camera handle causes the viewfinder to stop which will in turn
        // cause it to detach from the foreign window
        camera_close(mCameraHandle);
        mCameraHandle = CAMERA_HANDLE_INVALID;
        // reset button visibility
        mStartStopButton->setVisible(false);
        mStopButton->setVisible(false);
        mStartFrontButton->setVisible(true);
        mStartRearButton->setVisible(true);
    }
}
 
void HelloVideoCameraApp::onStartStopRecording()
{
    qDebug() << "onStartStopRecording";
 
    if (mCameraHandle != CAMERA_HANDLE_INVALID)
    {
        if (mVideoFileDescriptor == -1)
        {
            soundplayer_play_sound_blocking("event_recording_start");
 
            char filename[CAMERA_ROLL_NAMELEN];
 
            if (camera_roll_open_video(mCameraHandle,&mVideoFileDescriptor,filename,sizeof(filename),CAMERA_ROLL_VIDEO_FMT_DEFAULT) == CAMERA_EOK)
            {
                qDebug() << "opened " << filename;
 
//                if (camera_start_video(mCameraHandle,filename,NULL,NULL,NULL) == CAMERA_EOK)
//                {
//                    qDebug() << "started recording";
//                    mStartStopButton->setText("Stop Recording");
//                    mStopButton->setEnabled(false);
//                    mStatusLabel->setText(basename(filename));
//                    mStatusLabel->setVisible(true);
//                    return;
//                }
 
                camera_error_t error = camera_start_encode(mCameraHandle, NULL, NULL, NULL, NULL, NULL);
 
                                if(error == CAMERA_EOK)
                                {
                                        qDebug() << "Encoding started\n";
                                        mStartStopButton->setText("Stop Recording");
                                        mStopButton->setEnabled(false);
                                        mStatusLabel->setText(basename(filename));
                                        mStatusLabel->setVisible(true);
                                        return;
                                }
                                else
                                {
                                        qDebug() << "Encoding Failed\n";
                                }
 
                                fprintf(stderr, "camera_start_encode() error %d", error);
 
                qDebug() << "failed to start recording: " << error;
                camera_roll_close_video(mVideoFileDescriptor);
                mVideoFileDescriptor = -1;
            }
 
            soundplayer_play_sound("event_recording_stop");
        }
        else
        {
            soundplayer_play_sound("event_recording_stop");
            camera_stop_encode(mCameraHandle);
            qDebug() << "stopped recording";
            camera_roll_close_video(mVideoFileDescriptor);
            mVideoFileDescriptor = -1;
            mStartStopButton->setText("Start Recording");
            mStopButton->setEnabled(true);
            mStatusLabel->setVisible(false);
        }
    }
}

 Any help is very much appreciated. please. Thank you.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: [HELP] H264 Video Camera trying to modify HelloVideoCamera

Check the errors returned against the enum values,

 

http://developer.blackberry.com/native/reference/core/com.qnx.doc.camera.lib_ref/topic/camera_error_...

 

It's likely to be some resource conflict or resource limit.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: [HELP] H264 Video Camera trying to modify HelloVideoCamera

You can't pass NULL in for every argument in camera_start_encode (why would you? It's not going to do anything useful without some callbacks)

 

In particular you at least need something for the enc_video_callback argument. You almost certainly want one for status_callback callback as well, or you aren't really going to know what's going on. And if you expect audio, you need one enc_audio_callback. Honestly you'll probably use the videwo callback too.. But you DEFINITELY need enc_video_callback.

 

https://developer.blackberry.com/native/reference/core/com.qnx.doc.camera.lib_ref/topic/camera_start...

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 97
Registered: ‎11-13-2012
My Device: BB10 Simulator
My Carrier: Globe Telecom

Re: [HELP] H264 Video Camera trying to modify HelloVideoCamera

I've checked.. but I can't compare the error 22 to the enum values. Smiley Sad
Developer
Posts: 97
Registered: ‎11-13-2012
My Device: BB10 Simulator
My Carrier: Globe Telecom

Re: [HELP] H264 Video Camera trying to modify HelloVideoCamera

Thanks.. I eliminated the camera_start_encode function

 

my main problem was I really need to encode video recording as H264... and now I have the solution.. Knobtviker taugtht me... I used the BestCam sample..

 

added this camera_init_video_encoder(); to the constructor

 

and added this line after opening the camera

 

camera_set_videoencoder_parameter(mHandle, CAMERA_H264AVC_BITRATE, 1000000, CAMERA_H264AVC_KEYFRAMEINTERVAL, 3, CAMERA_H264AVC_RATECONTROL, CAMERA_H264AVC_RATECONTROL_VBR, CAMERA_H264AVC_PROFILE, CAMERA_H264AVC_PROFILE_HIGH, CAMERA_H264AVC_LEVEL, CAMERA_H264AVC_LEVEL_4);

 

these properties too

 

QByteArray groupBA = mFwc->windowGroup().toLocal8Bit();
QByteArray winBA = mFwc->windowId().toLocal8Bit();
err = camera_set_videovf_property(mHandle, CAMERA_IMGPROP_HWOVERLAY, 1, CAMERA_IMGPROP_FORMAT, CAMERA_FRAMETYPE_NV12, CAMERA_IMGPROP_WIN_GROUPID, groupBA.data(), CAMERA_IMGPROP_WIN_ID, winBA.data(), CAMERA_IMGPROP_WIDTH, 720, CAMERA_IMGPROP_HEIGHT, 720, CAMERA_IMGPROP_MAXFOV, 0);
err = camera_set_video_property(mHandle, CAMERA_IMGPROP_WIDTH, 720, CAMERA_IMGPROP_HEIGHT, 720, CAMERA_IMGPROP_AUDIOCODEC, CAMERA_AUDIOCODEC_AAC, CAMERA_IMGPROP_STABILIZATION, 1); //CAMERA_IMGPROP_VIDEOCODEC, CAMERA_VIDEOCODEC_AVC1,

 

now I can record a video with H264 format.

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: [HELP] H264 Video Camera trying to modify HelloVideoCamera

A note about camera error codes.  They are all straight out of errno.h, except any of the higher numbered ones (I think starting around 0x1000).  Those error codes were for things we couldnt find a good match for in errno.h.

The camera_error_t enum may not be entirely complete, but you'll notice they are defined as CAMERA_EINVAL = EINVAL, CAMERA_EBADF = EBADF, and so on.