pjsua2示例(适用于android)视频调用旋转-90度,并在调用setCaptureOrient时抛出异常



我正在使用pjsua2示例项目进行视频通话,一切都很好,两个android应用程序客户端都可以看到和听到对方的声音,但视频是旋转的-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_setting(dev_id,PJMEDIA_vid_dev_CAP_ORIENTATION,&orient,keep)错误:不支持选项/操作(PJ_ENOTSUP)(状态=70012)[../src/pjsua2/media.cpp:1483]说明:不支持选项/操作(PJ_ENOTSUP)

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

我已经知道错误的原因,是pjsip源代码不支持我使用的ffmpeg-libs的捕获方向设置。我在中找到了它

...
#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
}
...

最新更新