Changeset 5002 for pjproject


Ignore:
Timestamp:
Mar 19, 2015 7:03:39 AM (9 years ago)
Author:
riza
Message:

Re #1826: Add enum video format supported in iOS

File:
1 edited

Legend:

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

    r4909 r5002  
    5050}; 
    5151 
     52typedef struct ios_supported_size 
     53{ 
     54    pj_size_t supported_size_w; 
     55    pj_size_t supported_size_h; 
     56    NSString *preset_str; 
     57} ios_supported_size; 
     58 
     59/* Set the preset_str on set_preset_str method. */ 
     60static ios_supported_size ios_sizes[] = 
     61{ 
     62    { 352, 288, NULL }, 
     63    { 640, 480, NULL }, 
     64    { 1280, 720, NULL }, 
     65    { 1920, 1080, NULL } 
     66}; 
     67 
    5268/* qt device info */ 
    5369struct ios_dev_info 
     
    170186}; 
    171187 
     188static void set_preset_str() 
     189{ 
     190    ios_sizes[0].preset_str = AVCaptureSessionPreset352x288; 
     191    ios_sizes[1].preset_str = AVCaptureSessionPreset640x480; 
     192    ios_sizes[2].preset_str = AVCaptureSessionPreset1280x720; 
     193    ios_sizes[3].preset_str = AVCaptureSessionPreset1920x1080; 
     194} 
    172195 
    173196/**************************************************************************** 
     
    199222    unsigned i, l, first_idx, front_idx = -1; 
    200223    enum { MAX_DEV_COUNT = 8 }; 
     224     
     225    set_preset_str(); 
    201226     
    202227    /* Initialize input and output devices here */ 
     
    269294                continue; 
    270295            } 
     296             
     297            if (qdi->info.dir == PJMEDIA_DIR_RENDER) { 
     298                fmt = &qdi->info.fmt[qdi->info.fmt_cnt++]; 
     299                pjmedia_format_init_video(fmt, 
     300                                          ios_fmts[l].pjmedia_format, 
     301                                          DEFAULT_WIDTH, 
     302                                          DEFAULT_HEIGHT, 
     303                                          DEFAULT_FPS, 1); 
     304            } else { 
     305                int m; 
     306                AVCaptureDevice *dev = qdi->dev; 
    271307                 
    272             fmt = &qdi->info.fmt[qdi->info.fmt_cnt++]; 
    273             pjmedia_format_init_video(fmt, 
    274                                       ios_fmts[l].pjmedia_format, 
    275                                       DEFAULT_WIDTH, 
    276                                       DEFAULT_HEIGHT, 
    277                                       DEFAULT_FPS, 1);   
     308                /* Set supported size for capture device */ 
     309                for(m = 0; m < PJ_ARRAY_SIZE(ios_sizes) && 
     310                           qdi->info.fmt_cnt<PJMEDIA_VID_DEV_INFO_FMT_CNT; 
     311                    m++) 
     312                { 
     313                    if ([dev supportsAVCaptureSessionPreset: 
     314                                                       ios_sizes[m].preset_str]) 
     315                    { 
     316                        fmt = &qdi->info.fmt[qdi->info.fmt_cnt++]; 
     317                        pjmedia_format_init_video(fmt, 
     318                                                  ios_fmts[l].pjmedia_format, 
     319                                                  ios_sizes[m].supported_size_w, 
     320                                                  ios_sizes[m].supported_size_h, 
     321                                                  DEFAULT_FPS, 1); 
     322                    } 
     323                }                 
     324            } 
    278325        } 
    279326    } 
     
    576623 
    577624    if (param->dir & PJMEDIA_DIR_CAPTURE) { 
    578         NSString *size_preset_str[] = { 
    579             AVCaptureSessionPreset352x288, 
    580             AVCaptureSessionPreset640x480, 
    581             AVCaptureSessionPreset1280x720, 
    582             AVCaptureSessionPreset1920x1080 
    583         }; 
    584         pj_size_t supported_size_w[] = { 352, 640, 1280, 1920 }; 
    585         pj_size_t supported_size_h[] = { 288, 480,  720, 1080 }; 
    586         pj_size_t supported_size[] = { 352*288, 640*480, 1280*720, 1920*1080 }; 
    587         pj_size_t requested_size = strm->size.w * strm->size.h; 
    588625        int i; 
    589          
     626                 
    590627        /* Create capture stream here */ 
    591628        strm->cap_session = [[AVCaptureSession alloc] init]; 
     
    594631            goto on_error; 
    595632        } 
    596          
    597633        AVCaptureDevice *dev = qf->dev_info[param->cap_id].dev; 
    598          
    599         /* Find the closest supported size */ 
    600         for(i = PJ_ARRAY_SIZE(supported_size)-1; i > 0; --i) { 
    601             if (![dev supportsAVCaptureSessionPreset: size_preset_str[i]]) 
    602                 continue; 
    603             if (supported_size[i-1] < requested_size) 
     634  
     635        for (i = PJ_ARRAY_SIZE(ios_sizes)-1; i > 0; --i) { 
     636            if ((vfd->size.w == ios_sizes[i].supported_size_w) && 
     637                (vfd->size.h == ios_sizes[i].supported_size_h)) 
     638            { 
    604639                break; 
    605         } 
    606         strm->cap_session.sessionPreset = size_preset_str[i]; 
    607         vfd->size.w = supported_size_w[i]; 
    608         vfd->size.h = supported_size_h[i]; 
     640            } 
     641        } 
     642         
     643        strm->cap_session.sessionPreset = ios_sizes[i].preset_str; 
     644         
     645        vfd->size.w = ios_sizes[i].supported_size_w; 
     646        vfd->size.h = ios_sizes[i].supported_size_h; 
    609647        strm->size = vfd->size; 
    610648        strm->bytes_per_row = strm->size.w * vfi->bpp / 8; 
     
    9801018{ 
    9811019    struct ios_stream *stream = (struct ios_stream*)strm; 
    982      
     1020 
    9831021    if (stream->frame_size >= frame->size) 
    9841022        pj_memcpy(stream->render_buf, frame->buf, frame->size); 
Note: See TracChangeset for help on using the changeset viewer.