Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for video capture orientation #1861

Closed
pjsipbot opened this issue Jun 25, 2015 · 1 comment
Closed

Support for video capture orientation #1861

pjsipbot opened this issue Jun 25, 2015 · 1 comment

Comments

@pjsipbot
Copy link
Collaborator

2015-06-25 07:28:31: @mingteluu created the issue on trac ticket 1861

Currently there is no mechanism to notify other party about new video orientation, so in this ticket, we implement a feature which allows the video sender to transmit video with the "proper" orientation at all time, i.e: head upside whatever the device orientation is. When a device orientation changes, the application can tell the library and the library will rotate the video, resize it accordingly, and insert blank/black in left+right sides. The receiver/decoder side will then receive the video in the correct orientation, nothing to do on the decoder side.

The feature is available on iOS and Android only.


2015-06-25 09:17:53: @mingteluu commented

In r5118:
Re #1861: Initial implementation of video orientation support

  • Utility to resize and rotate video frame
  • Support for iOS + sample
  • pjsua API to set video device's orientation

2015-06-25 09:37:57: @mingteluu changed title from Support for video orientation to Support for video capture orientation


2015-07-03 07:21:32: @mingteluu commented

In r5125:
Re #1861: Changed pjsua API for setting the orientation using a more generic API, pjsua_vid_dev_set_setting() instead


2015-07-07 05:13:15: @nanangizz commented

In r5128:
Re #1861: Fixed compile error of 'undeclared identifier PJMEDIA_VID_DEV_MAX_DEVS' when video is disabled.


2015-07-30 07:23:37: @mingteluu changed status from new to closed


2015-07-30 07:23:37: @mingteluu set resolution to fixed


2015-07-30 07:23:37: @mingteluu commented

In r5138:
Fixed #1861: Add support for video capture orientation on Android

@houhm
Copy link

houhm commented May 18, 2021

in ipad ,I orient the pad, but the video device's orientation is invalid.the code with below:

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(orientationChanged:)
    name:UIDeviceOrientationDidChangeNotification
    object:[UIDevice currentDevice]];
    }

  • (void)orientationChanged:(NSNotification *)note
    {

#if PJSUA_HAS_VIDEO
const pjmedia_orient pj_ori[4] =
{
PJMEDIA_ORIENT_ROTATE_90DEG, /* UIDeviceOrientationPortrait /
PJMEDIA_ORIENT_ROTATE_270DEG, /
UIDeviceOrientationPortraitUpsideDown /
PJMEDIA_ORIENT_ROTATE_180DEG, /
UIDeviceOrientationLandscapeLeft,
home button on the right side /
PJMEDIA_ORIENT_NATURAL /
UIDeviceOrientationLandscapeRight,
home button on the left side */
};
static pj_thread_desc a_thread_desc;
static pj_thread_t *a_thread;
static UIDeviceOrientation prev_ori = 0;
UIDeviceOrientation dev_ori = [[UIDevice currentDevice] orientation];
int i;

if (dev_ori == prev_ori) return;

NSLog(@"Device orientation changed: %d", (int)(prev_ori = dev_ori));

if (dev_ori >= UIDeviceOrientationPortrait &&
    dev_ori <= UIDeviceOrientationLandscapeRight)
{
    if (!pj_thread_is_registered()) {
        pj_thread_register("ipjsua", a_thread_desc, &a_thread);
    }

    /* Here we set the orientation for all video devices.
     * This may return failure for renderer devices or for
     * capture devices which do not support orientation setting,
     * we can simply ignore them.
     */
    for (i = pjsua_vid_dev_count()-1; i >= 0; i--) {
       pj_status_t status =  pjsua_vid_dev_set_setting(i, PJMEDIA_VID_DEV_CAP_ORIENTATION,
                                  &pj_ori[dev_ori-1], PJ_TRUE);
        NSLog(@"orientation set status = %d",status);
    }
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    [self localPreviewWithRect:self.view.bounds];
});

#endif
}

  • (IBAction)onLocalPreview:(id)sender{
    UIView *localView = [self startLocalPreview];
    [self.view addSubview:localView];
    }

  • (UIView *)startLocalPreview{

    pj_thread_desc desc;
    pj_thread_t *thread = 0;
    if(!pj_thread_is_registered()){
    pj_thread_register(NULL,desc,&thread);
    }

    pjsua_vid_preview_param preview_param;
    pjsua_vid_preview_param_default(&preview_param);
    preview_param.wnd_flags = PJMEDIA_VID_DEV_WND_BORDER |
    PJMEDIA_VID_DEV_WND_RESIZABLE;
    preview_param.show = PJ_TRUE;

    pj_status_t result = pjsua_vid_preview_start(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, &preview_param);
    if (result != PJ_SUCCESS)
    {
    // DFFCSLog(@"开启预览失败");
    return nil;
    }

// DFFCSLog(@"开启预览成功");
UIView *preview = [self localPreviewWithRect:self.view.bounds];
return preview;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants