Ignore:
Timestamp:
Apr 3, 2012 7:33:31 AM (12 years ago)
Author:
ming
Message:

Misc (re #1446):

  • Apply format change event to vid_dev only if the format changes.
  • Get the new format info from the event itself (instead of from the client port)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/vid_port.c

    r3993 r4009  
    126126static pj_status_t create_converter(pjmedia_vid_port *vp) 
    127127{ 
     128    if (vp->conv) { 
     129        pjmedia_converter_destroy(vp->conv); 
     130        vp->conv = NULL; 
     131    } 
     132 
    128133    /* Instantiate converter if necessary */ 
    129134    if (vp->conv_param.src.id != vp->conv_param.dst.id || 
     
    136141        const pjmedia_video_format_info *vfi; 
    137142        pjmedia_video_apply_fmt_param vafp; 
    138  
    139         if (vp->conv) { 
    140             pjmedia_converter_destroy(vp->conv); 
    141             vp->conv = NULL; 
    142         } 
    143143 
    144144        status = pjmedia_converter_create(NULL, vp->pool, &vp->conv_param, 
     
    564564    if (event->type == PJMEDIA_EVENT_FMT_CHANGED) { 
    565565        const pjmedia_video_format_detail *vfd; 
     566        pjmedia_vid_dev_param vid_param; 
    566567        pj_status_t status; 
    567568         
     
    569570         
    570571        /* Retrieve the video format detail */ 
    571         vfd = pjmedia_format_get_video_format_detail(&vp->client_port->info.fmt, 
    572                                                     PJ_TRUE); 
    573         if (!vfd) 
     572        vfd = pjmedia_format_get_video_format_detail( 
     573                  &event->data.fmt_changed.new_fmt, PJ_TRUE); 
     574        if (!vfd || !vfd->fps.num || !vfd->fps.denum) 
    574575            return PJMEDIA_EVID_BADFORMAT; 
    575         pj_assert(vfd->fps.num); 
    576576         
    577577        /* Change the destination format to the new format */ 
    578578        pjmedia_format_copy(&vp->conv_param.src, 
    579                             &vp->client_port->info.fmt); 
     579                            &event->data.fmt_changed.new_fmt); 
    580580        /* Only copy the size here */ 
    581581        vp->conv_param.dst.det.vid.size = 
    582         vp->client_port->info.fmt.det.vid.size, 
     582            event->data.fmt_changed.new_fmt.det.vid.size; 
    583583 
    584584        status = create_converter(vp); 
     
    587587            return status; 
    588588        } 
    589          
    590         status = pjmedia_vid_dev_stream_set_cap(vp->strm, 
    591                                                 PJMEDIA_VID_DEV_CAP_FORMAT, 
    592                                                 &vp->conv_param.dst); 
    593         if (status != PJ_SUCCESS) { 
    594             PJ_LOG(3, (THIS_FILE, "failure in changing the format of the " 
    595                        "video device")); 
    596             PJ_LOG(3, (THIS_FILE, "reverting to its original format: %s", 
    597                        status != PJMEDIA_EVID_ERR ? "success" : 
    598                        "failure")); 
    599             return status; 
     589 
     590        pjmedia_vid_dev_stream_get_param(vp->strm, &vid_param); 
     591        if (vid_param.fmt.id != vp->conv_param.dst.id || 
     592            (vid_param.fmt.det.vid.size.h != 
     593             vp->conv_param.dst.det.vid.size.h) || 
     594            (vid_param.fmt.det.vid.size.w != 
     595             vp->conv_param.dst.det.vid.size.w)) 
     596        { 
     597            status = pjmedia_vid_dev_stream_set_cap(vp->strm, 
     598                                                    PJMEDIA_VID_DEV_CAP_FORMAT, 
     599                                                    &vp->conv_param.dst); 
     600            if (status != PJ_SUCCESS) { 
     601                PJ_LOG(3, (THIS_FILE, "failure in changing the format of the " 
     602                                      "video device")); 
     603                PJ_LOG(3, (THIS_FILE, "reverting to its original format: %s", 
     604                                      status != PJMEDIA_EVID_ERR ? "success" : 
     605                                      "failure")); 
     606                return status; 
     607            } 
    600608        } 
    601609         
    602610        if (vp->stream_role == ROLE_PASSIVE) { 
    603             pjmedia_vid_dev_param vid_param; 
    604611            pjmedia_clock_param clock_param; 
    605612             
     
    610617             */ 
    611618            /* Adjust the clock */ 
    612             pjmedia_vid_dev_stream_get_param(vp->strm, &vid_param); 
    613619            clock_param.usec_interval = PJMEDIA_PTIME(&vfd->fps); 
    614620            clock_param.clock_rate = vid_param.clock_rate; 
Note: See TracChangeset for help on using the changeset viewer.