pjsua2示例(用于android)视频调用旋转-90度并在调用setCaptureOrient

时间:2015-10-27 12:52:45

标签: android video pjsip

我正在使用pjsua2示例项目进行视频通话,每件事情都很顺利,Android app客户端都能看到和听到对方,但视频旋转-90度。 在CallActivity.java中,调用setCaptureOrient(cap_dev, orient, true)时会抛出异常。

@Override
    public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    WindowManager wm;
    Display display;
    int rotation;
    pjmedia_orient orient;

    wm = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
    display = wm.getDefaultDisplay();
    rotation = display.getRotation();
    System.out.println("Device orientation changed: " + rotation);

    switch (rotation) {
    case Surface.ROTATION_0:   // Portrait
        orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_270DEG;
        break;
    case Surface.ROTATION_90:  // Landscape, home button on the right
        orient = pjmedia_orient.PJMEDIA_ORIENT_NATURAL;
        break;
    case Surface.ROTATION_180:
        orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_90DEG;
        break;
    case Surface.ROTATION_270: // Landscape, home button on the left
        orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_180DEG;
        break;
    default:
        orient = pjmedia_orient.PJMEDIA_ORIENT_UNKNOWN;
    }

    if (MyApp.ep != null && MainActivity.account != null) {
        try {
        AccountConfig cfg = MainActivity.account.cfg;
        int cap_dev = cfg.getVideoConfig().getDefaultCaptureDevice();




        //----------here throws an exception:option/operation is not support. ------------

        MyApp.ep.vidDevManager().setCaptureOrient(cap_dev, orient,true);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}    

异常信息:

  

media.cpp!pjsua_vid_dev_set_setting(dev_id,PJMEDIA_VID_DEV_CAP_ORIENTATION,& orient,keep)错误:不支持选项/操作(PJ_ENOTSUP)(状态= 70012)[../src/pjsua2/media.cpp:1483]       描述:不支持选项/操作(PJ_ENOTSUP)

我没有改变任何东西,但它只是不起作用,为什么呢?

1 个答案:

答案 0 :(得分:0)

我已经知道错误的原因了,就是pjsip源代码不支持我使用的ffmpeg libs的捕获方向设置。我在: pjproject / pjmedia / src / pjmedia-videodev /中找到它util.c

...
#include "util.h"

#include <pj/assert.h>
#include <pj/errno.h>
#include <pj/log.h>

#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)

#if defined(PJMEDIA_HAS_LIBYUV) && PJMEDIA_HAS_LIBYUV != 0
#include  <libyuv.h>
#define HAS_ROTATION 1
#else
    #define HAS_ROTATION 0     //the reason why ffmpeg not support capture orientation setting
#endif

#define THIS_FILE       "vid_util.c"

pj_status_t
pjmedia_vid_dev_conv_create_converter(pjmedia_vid_dev_conv *conv,
                  pj_pool_t *pool,
                  pjmedia_format *fmt,
                  pjmedia_rect_size src_size,
                  pjmedia_rect_size dst_size,
                  pj_bool_t handle_rotation,
                  pj_bool_t maintain_aspect_ratio)
{
    pj_status_t status;
    pjmedia_conversion_param conv_param;
    const pjmedia_video_format_info *vfi;   

    pj_assert((src_size.w == dst_size.w || src_size.h == dst_size.h) ||
          (src_size.w == dst_size.h || src_size.h == dst_size.w));

if (conv->conv)
    return PJ_SUCCESS;

if (fmt->id != PJMEDIA_FORMAT_I420 && fmt->id != PJMEDIA_FORMAT_BGRA)
    return PJ_EINVAL;

/* Currently, for BGRA format, device must handle the rotation. */
if (fmt->id == PJMEDIA_FORMAT_BGRA && handle_rotation)
    return PJ_ENOTSUP;

if (handle_rotation) {
#if !HAS_ROTATION
return PJ_ENOTSUP; // return ffmpeg not support capture orientation setting error
#endif
}
...