Changeset 5052


Ignore:
Timestamp:
Apr 8, 2015 9:07:00 AM (6 years ago)
Author:
ming
Message:

Re #1835: More robust handling of format change, to prevent data race if clock is still running.

File:
1 edited

Legend:

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

    r5047 r5052  
    221221    pjmedia_vid_dev_opengl_draw(stream->gl_buf, stream->vid_size.w, stream->vid_size.h, 
    222222                                stream->frame->buf); 
     223 
     224    [stream->ogl_context presentRenderbuffer:GL_RENDERBUFFER]; 
    223225} 
    224226 
     
    228230     * it is called, we can be sure that render() has completed. 
    229231     */ 
     232} 
     233 
     234- (void)change_format 
     235{ 
     236    pjmedia_video_format_detail *vfd; 
     237     
     238    vfd = pjmedia_format_get_video_format_detail(&stream->param.fmt, PJ_TRUE); 
     239    pj_memcpy(&stream->vid_size, &vfd->size, sizeof(vfd->size)); 
     240    if (stream->param.disp_size.w == 0 || stream->param.disp_size.h == 0) 
     241        pj_memcpy(&stream->param.disp_size, &vfd->size, sizeof(vfd->size)); 
    230242} 
    231243 
     
    254266    strm->ts_inc = PJMEDIA_SPF2(param->clock_rate, &vfd->fps, 1); 
    255267     
     268    rect = CGRectMake(0, 0, strm->param.disp_size.w, strm->param.disp_size.h); 
     269    strm->gl_view = [[GLView alloc] initWithFrame:rect]; 
     270    if (!strm->gl_view) 
     271        return PJ_ENOMEM; 
     272    strm->gl_view->stream = strm; 
     273 
    256274    /* If OUTPUT_RESIZE flag is not used, set display size to default */ 
    257275    if (!(param->flags & PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE)) { 
     
    264282    if (status != PJ_SUCCESS) 
    265283        goto on_error; 
    266      
    267     rect = CGRectMake(0, 0, strm->param.disp_size.w, strm->param.disp_size.h); 
    268     strm->gl_view = [[GLView alloc] initWithFrame:rect]; 
    269     if (!strm->gl_view) 
    270         return PJ_ENOMEM; 
    271     strm->gl_view->stream = strm; 
    272284     
    273285    /* Perform OpenGL buffer initializations in the main thread. */ 
     
    373385    if (cap==PJMEDIA_VID_DEV_CAP_FORMAT) { 
    374386        const pjmedia_video_format_info *vfi; 
    375         pjmedia_video_format_detail *vfd; 
    376387        pjmedia_format *fmt = (pjmedia_format *)pval; 
    377388        iosgl_fmt_info *ifi; 
     
    387398        pjmedia_format_copy(&strm->param.fmt, fmt); 
    388399         
    389         vfd = pjmedia_format_get_video_format_detail(fmt, PJ_TRUE); 
    390         pj_memcpy(&strm->vid_size, &vfd->size, sizeof(vfd->size)); 
    391         if (strm->param.disp_size.w == 0 || strm->param.disp_size.h == 0) 
    392             pj_memcpy(&strm->param.disp_size, &vfd->size, sizeof(vfd->size)); 
     400        [strm->gl_view performSelectorOnMainThread:@selector(change_format) 
     401                       withObject:nil waitUntilDone:YES]; 
    393402 
    394403        return PJ_SUCCESS; 
     
    460469                           withObject:nil waitUntilDone:YES]; 
    461470     
    462     [stream->ogl_context presentRenderbuffer:GL_RENDERBUFFER]; 
    463      
    464471    return PJ_SUCCESS; 
    465472} 
Note: See TracChangeset for help on using the changeset viewer.