Re: Video preview on android with Qt app

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello!

Next problem I'm faced with is creating video preview failed with error PJMEDIA_EVID_BADFORMAT, because my cam using NV21/1920x1080 by default:
I/pjsua   (17818): 02:23:22.910     vid_port.c  ..Opening device Front camera [Android] for capture: format=NV21, size=1920x1080 @15:1 fps
I/pjsua   (17818): 02:23:22.910     vid_port.c  ..Closing Front camera..
I/pjsua   (17818): 02:23:22.910    pjsua_vid.c  ..Window 0: destroying..
I/pjsua   (17818): 02:23:22.910      media.cpp  pjsua_vid_preview_start(devId, &prm) error: Bad or invalid video device format

I tried to specify supported format:

    //front cam has index == 1
    int camIdx = 1;

    //checking formats untill getting YV12/640x480
    VideoDevInfo devInfo = ep->vidDevManager().getDevInfo(camIdx);
    MediaFormatVector fmtVec = devInfo.fmt;
    MediaFormatVideo *fmt;
    for (int i = 0; i < fmtVec.size(); i++) {
        fmt = (MediaFormatVideo*)fmtVec.at(i);
        if (fmt->height == 480 && fmt->width == 640 && fmt->id == PJMEDIA_FORMAT_I420)
            break;
    }

    //creating VideoPreview
    vidPrev = new VideoPreview(camIdx);

    //setting format
    VideoPreviewOpParam param;
    param.format = *fmt;

    //starting VideoPreview
    vidPrev->start(param);

But I was surprised when video preview ignored my settings and continued using  NV21/1920x1080. After reading pjsip's sources I found out that pjsua2 Media API is incomplete, VideoPreviewOpParam converts into pjsua_vid_preview_param with error and pjsua_vid_preview_param ignored later.
I rewrited Media API (diff attached to this e-mail)  and was able to create preview:
I/pjsua   ( 7501): 02:43:33.566     vid_port.c  ..Opening device OpenGL renderer [OpenGL] for render: format=I420, size=640x480 @15:1 fps
I/pjsua   ( 7501): 02:43:33.566 android_opengl  ..Re-initializing OpenGL due to format change
I/pjsua   ( 7501): 02:43:33.566 android_opengl  ..Android OpenGL ES renderer successfully created
I/pjsua   ( 7501): 02:43:33.566     vid_port.c  ..Device OpenGL renderer [OpenGL] opened: format=I420, size=640x480 @15:1 fps
I/pjsua   ( 7501): 02:43:33.566    pjsua_vid.c  ..preview window id 0 created for cap_dev=1 rend_dev=-2
I/pjsua   ( 7501): 02:43:33.566    pjsua_vid.c  ..Window 0 created
I/pjsua   ( 7501): 02:43:33.566 android_opengl  .Starting Android opengl stream
I/pjsua   ( 7501): 02:43:33.566  android_dev.c  .Starting Android camera stream

The current problem - I don't see preview video on screen, VideoWindow getInfo().isNative says that it is not native window, but when I'm tring setPos() or Show() I'm getting this error:
I/pjsua   (12855): 03:02:48.615      media.cpp  pjsua_vid_win_set_show(winId, show) error: Invalid or unsupported video capability (PJMEDIA_EVID_INVCAP) (status=520008) [../src/pjsua2/media.cpp:1071]

What I'm doing wrong?

16.08.2016, 22:08, "Анцев Александр" <a.antsev@xxxxxxxxx>:
> Hello!
>
> The problem with finding PjCamera class is solved.
> PjClass is searched in "pjproject-2.5.5\pjmedia\src\pjmedia-videodev\android_dev.c" file in jni_init_ids() function. This function is normally called in thread which loaded this lib, so this function have access to class loader and everything is working fine, But when you starting use Qt for GUI, QApplication is started in its own thread and the system class loader is available from this context, so jni_init_ids() can't find PjCamera with FindClass.
> The simplest solution is find PjCamera in JNI_OnLoad() function, defined in "pjproject-2.5.5\pjlib\src\pj\os_core_unix.c" and cache the results. This function is called when library is loaded and class loader is available.
> To do so the two things should be done:
> 1. Move some code from jni_init_ids() to JNI_OnLoad().
> 2. use __android_log_print instead of PJ_LOG macro (because log facility is not inited at this point).
>
> I've made a patch (git diff), hope it will be usefull.
>
> 15.08.2016, 14:26, "Анцев Александр" <a.antsev@xxxxxxxxx>:
>>  Hello!
>>
>>  I'm trying to build an app for android with GUI written on Qt. Now I'm working on video preview. What i've done already:
>>  1. Build OpenH264 lib.
>>  2. Build pjsip with video support.
>>  3. Copy PjCamera.java and PjCameraInfo.java into my app folder (src\org\pjsip\).
>>
>>  The problem is that pjsip unable to find class name PjCamera from JVM. I have this debug log:
>>  .............
>>  I/pjsua (16412): 22:52:38.159 android_jni_de ..Android JNI sound library initialized
>>  I/pjsua (16412): 22:52:38.162 pjlib ..select() I/O Queue created (0xb861b48c)
>>  I/pjsua (16412): 22:52:38.182 pjsua_vid.c ..Initializing video subsystem..
>>  I/pjsua (16412): 22:52:38.183 openh264.cpp ...OpenH264 codec initialized
>>  I/pjsua (16412): 22:52:38.183 opengl_dev.c ...OpenGL device initialized
>>  I/pjsua (16412): 22:52:38.184 android_dev.c ...[JNI] Unable to find class 'PjCamera'
>>  .............
>>
>>  And when I'm trying to create preview video program crashes. (I'm not sure that I'm creating video preview with correct device and maybe this is another error).
>>  My code:
>>      vidPrev = new VideoPreview(PJMEDIA_VID_DEFAULT_RENDER_DEV);
>>      VideoPreviewOpParam param;
>>      vidPrev->start(param); // <-- crash here
>>      VideoWindow prev = vidPrev->getVideoWindow();
>>
>>  Crash log:
>>  I/pjsua (16412): 22:52:39.511 pjsua_vid.c !Starting preview for cap_dev=-2, show=1
>>  I/pjsua (16412): 22:52:39.511 pjsua_vid.c .Creating video window: type=preview, cap_id=-2, rend_id=-2
>>  I/pjsua (16412): 22:52:39.511 pjsua_vid.c ..Window 0: destroying..
>>  I/pjsua (16412): 22:52:39.511 media.cpp pjsua_vid_preview_start(devId, &prm) error: Invalid video device (PJMEDIA_EVID_INVDEV) (status=520004) [../src/pjsua2/media.cpp:1185]
>>  F/libc (16412): Fatal signal 6 (SIGABRT), code -6 in tid 16638 (QtThread)
>>  I/DEBUG ( 288): pid: 16412, tid: 16638, name: QtThread >>> org.qtproject.example <<<
>>  D/InputDispatcher( 984): Focus left window: 16412
>>  E/lowmemorykiller( 255): Error writing /proc/16412/oom_score_adj; errno=22
>>  I/Zygote ( 317): Process 16412 exited due to signal (6)
>>  I/ActivityManager( 984): Process org.qtproject.example (pid 16412)(adj 1) has died.(63,298)
>>
>>  Does anybody faced with such error before?
>>
>>  --
>>  С уважением,
>>  Александр Анцев
>>
>>  _______________________________________________
>>  Visit our blog: http://blog.pjsip.org
>>
>>  pjsip mailing list
>>  pjsip@xxxxxxxxxxxxxxx
>>  http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
> --
> С уважением,
> Александр Анцев
> ,
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip@xxxxxxxxxxxxxxx
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

--
С уважением,
Александр Анцев
diff --git a/3rd part/pjproject-2.5.5/pjsip/include/pjsua2/media.hpp b/3rd part/pjproject-2.5.5/pjsip/include/pjsua2/media.hpp
index 42b1a21..daf262a 100644
--- a/3rd part/pjproject-2.5.5/pjsip/include/pjsua2/media.hpp
+++ b/3rd part/pjproject-2.5.5/pjsip/include/pjsua2/media.hpp
@@ -1542,7 +1542,7 @@ struct VideoPreviewOpParam {
     /**
      * Media format. If left unitialized, this parameter will not be used.
      */
-    MediaFormat		    format;
+    MediaFormatVideo		    format;
 
     /**
      * Optional output window to be used to display the video preview.
diff --git a/3rd part/pjproject-2.5.5/pjsip/src/pjsua2/media.cpp b/3rd part/pjproject-2.5.5/pjsip/src/pjsua2/media.cpp
index c3d89e5..df2376d 100644
--- a/3rd part/pjproject-2.5.5/pjsip/src/pjsua2/media.cpp
+++ b/3rd part/pjproject-2.5.5/pjsip/src/pjsua2/media.cpp
@@ -1140,6 +1140,12 @@ void VideoPreviewOpParam::fromPj(const pjsua_vid_preview_param &prm)
     this->windowFlags		    = prm.wnd_flags;
     this->format.id		    = prm.format.id;
     this->format.type		    = prm.format.type;
+    this->format.width              = prm.format.det.vid.size.w;
+    this->format.height             = prm.format.det.vid.size.h;
+    this->format.fpsNum             = prm.format.det.vid.fps.num;
+    this->format.fpsDenum           = prm.format.det.vid.fps.denum;
+    this->format.avgBps             = prm.format.det.vid.avg_bps;
+    this->format.maxBps             = prm.format.det.vid.max_bps;
     this->window.type		    = prm.wnd.type;
     this->window.handle.window	    = prm.wnd.info.window;
 #else
@@ -1152,13 +1158,20 @@ pjsua_vid_preview_param VideoPreviewOpParam::toPj() const
     pjsua_vid_preview_param param;
     pj_bzero(&param, sizeof(param));
 #if PJSUA_HAS_VIDEO
-    param.rend_id	    = this->rendId;
-    param.show		    = this->show;
-    param.wnd_flags	    = this->windowFlags;
-    param.format.id	    = this->format.id;
-    param.format.type	    = this->format.type;
-    param.wnd.type	    = this->window.type;
-    param.wnd.info.window   = this->window.handle.window;
+    param.rend_id                  = this->rendId;
+    param.show                     = this->show;
+    param.wnd_flags                = this->windowFlags;
+    param.format.id                = this->format.id;
+    param.format.type              = this->format.type;
+    param.format.detail_type 	   = PJMEDIA_FORMAT_DETAIL_VIDEO;
+    param.format.det.vid.size.w    = this->format.width;
+    param.format.det.vid.size.h    = this->format.height;
+    param.format.det.vid.fps.num   = this->format.fpsNum;
+    param.format.det.vid.fps.denum = this->format.fpsDenum;
+    param.format.det.vid.avg_bps   = this->format.avgBps;
+    param.format.det.vid.max_bps   = this->format.maxBps;
+    param.wnd.type                 = this->window.type;
+    param.wnd.info.window          = this->window.handle.window;
 #endif
     return param;
 }
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux