Changeset 6109 for pjproject


Ignore:
Timestamp:
Nov 18, 2019 6:24:11 AM (4 years ago)
Author:
ming
Message:

Fixed #2252: Fix Darwin video issue if supplied image height is different from the resolution

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-videodev/darwin_dev.m

    r5874 r6109  
    295295    first_idx = qf->dev_count; 
    296296    if (NSClassFromString(@"AVCaptureSession")) { 
    297         NSArray *dev_list; 
    298  
    299 #if TARGET_OS_IPHONE && defined(__IPHONE_10_0) 
    300         if (NSClassFromString(@"AVCaptureDeviceTypeBuiltInWideAngleCamera")) { 
    301             /* Starting in iOS 10, [AVCaptureDevice devices] is deprecated 
    302              * and replaced by AVCaptureDeviceDiscoverySession. 
     297        NSArray *dev_list = NULL; 
     298 
     299#if (TARGET_OS_IPHONE && defined(__IPHONE_10_0)) || \ 
     300    (TARGET_OS_OSX && defined(__MAC_10_15)) 
     301        if (__builtin_available(macOS 10.15, iOS 10.0, *)) { 
     302            /* Starting in iOS 10 and macOS 10.15, [AVCaptureDevice devices] 
     303             * is deprecated and replaced by AVCaptureDeviceDiscoverySession. 
    303304             */ 
    304305            AVCaptureDeviceDiscoverySession *dds; 
    305306            NSArray<AVCaptureDeviceType> *dev_types = 
    306                 @[AVCaptureDeviceTypeBuiltInWideAngleCamera, 
    307                   AVCaptureDeviceTypeBuiltInDuoCamera, 
    308                   AVCaptureDeviceTypeBuiltInTelephotoCamera]; 
     307                @[AVCaptureDeviceTypeBuiltInWideAngleCamera 
     308#if TARGET_OS_IPHONE && defined(__IPHONE_10_0) 
     309                  , AVCaptureDeviceTypeBuiltInDuoCamera 
     310                  , AVCaptureDeviceTypeBuiltInTelephotoCamera 
     311#endif 
     312                  ]; 
    309313 
    310314            dds = [AVCaptureDeviceDiscoverySession 
     
    315319            dev_list = [dds devices]; 
    316320        } else { 
     321#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_15 
    317322            dev_list = [AVCaptureDevice devices]; 
     323#endif 
    318324        } 
    319325#else 
     
    563569            pj_uint8_t *p, *p_end, *Y, *U, *V; 
    564570            pj_size_t p_len; 
    565             /* Image stride is not always equal to the image width. I.e on Ipad 
    566              * air, at 352*288 the image stride is 384. 
     571            pj_size_t wxh = stream->vid_size.w * stream->vid_size.h; 
     572            /* Image stride is not always equal to the image width. 
     573             * For example, resolution 352*288 can have a stride of 384. 
    567574             */ 
    568575            pj_size_t stride = CVPixelBufferGetBytesPerRowOfPlane(img, 0); 
     576            /* Image height is not always equal to the video resolution. 
     577             * For example, resolution 352*288 can have a height of 264. 
     578             */ 
    569579            pj_size_t height = CVPixelBufferGetHeight(img); 
    570580            pj_bool_t need_clip; 
    571581             
    572582            /* Auto detect rotation */ 
    573             if (height != stream->vid_size.h) { 
     583            if ((stream->vid_size.w > stream->vid_size.h && stride < height) || 
     584                (stream->vid_size.h > stream->vid_size.w && stride > height)) 
     585            { 
     586                pj_size_t w = stream->vid_size.w; 
    574587                stream->vid_size.w = stream->vid_size.h; 
    575                 stream->vid_size.h = height; 
     588                stream->vid_size.h = w; 
    576589            } 
    577590             
     
    580593            p = (pj_uint8_t*)CVPixelBufferGetBaseAddressOfPlane(img, 0); 
    581594 
    582             p_len = stream->vid_size.w * stream->vid_size.h; 
     595            p_len = stream->vid_size.w * height; 
    583596            Y = (pj_uint8_t*)stream->capture_buf; 
    584             U = Y + p_len; 
    585             V = U + p_len/4; 
     597            U = Y + wxh; 
     598            V = U + wxh/4; 
    586599 
    587600            if (!need_clip) { 
    588601                pj_memcpy(Y, p, p_len); 
     602                Y += p_len; 
    589603            } else { 
    590604                int i = 0; 
    591                 for (; i < stream->vid_size.h; ++i) { 
     605                for (; i < height; ++i) { 
    592606                    pj_memcpy(Y, p, stream->vid_size.w); 
    593607                    Y += stream->vid_size.w; 
    594608                    p += stride; 
    595609                } 
     610            } 
     611             
     612            if (stream->vid_size.h > height) { 
     613                pj_memset(Y, 16, (stream->vid_size.h - height) * 
     614                          stream->vid_size.w); 
    596615            } 
    597616 
     
    607626            } else { 
    608627                int i = 0; 
    609                 for (;i<(stream->vid_size.h)/2;++i) { 
     628                for (;i<height/2;++i) { 
    610629                    int y=0; 
    611630                    for (;y<(stream->vid_size.w)/2;++y) { 
     
    615634                    p += (stride - stream->vid_size.w); 
    616635                } 
     636            } 
     637 
     638            if (stream->vid_size.h > height) { 
     639                pj_size_t UV_size = (stream->vid_size.h - height) * 
     640                                    stream->vid_size.w / 4; 
     641                pj_memset(U, 0x80, UV_size); 
     642                pj_memset(V, 0x80, UV_size); 
    617643            } 
    618644        } 
Note: See TracChangeset for help on using the changeset viewer.