Changeset 3803


Ignore:
Timestamp:
Oct 7, 2011 5:41:37 AM (12 years ago)
Author:
ming
Message:

Closed #1382: Handle flipped image in dshow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-videodev/dshow_dev.c

    r3797 r3803  
    111111    pj_thread_desc           cap_thread_desc; 
    112112    pj_thread_t             *cap_thread; 
     113    void                    *frm_buf; 
     114    unsigned                 frm_buf_size; 
    113115 
    114116    struct dshow_graph 
     
    557559{ 
    558560    struct dshow_stream *strm = (struct dshow_stream*)user_data; 
    559     unsigned char *buffer; 
    560561    pjmedia_frame frame = {0}; 
    561562 
     
    577578    } 
    578579 
    579     IMediaSample_GetPointer(pMediaSample, &buffer); 
    580  
    581580    frame.type = PJMEDIA_TYPE_VIDEO; 
    582581    IMediaSample_GetPointer(pMediaSample, (BYTE **)&frame.buf); 
     
    585584    frame.timestamp = strm->cap_ts; 
    586585    strm->cap_ts.u64 += strm->cap_ts_inc; 
     586 
     587    if (strm->frm_buf_size) { 
     588        unsigned i, stride; 
     589        BYTE *src_buf, *dst_buf; 
     590        pjmedia_video_format_detail *vfd; 
     591         
     592        /* Image is bottom-up, convert it to top-down. */ 
     593        src_buf = dst_buf = (BYTE *)frame.buf; 
     594        stride = strm->frm_buf_size; 
     595        vfd = pjmedia_format_get_video_format_detail(&strm->param.fmt, 
     596                                                     PJ_TRUE); 
     597        src_buf += (vfd->size.h - 1) * stride; 
     598 
     599        for (i = vfd->size.h / 2; i > 0; i--) { 
     600            memcpy(strm->frm_buf, dst_buf, stride); 
     601            memcpy(dst_buf, src_buf, stride); 
     602            memcpy(src_buf, strm->frm_buf, stride); 
     603            dst_buf += stride; 
     604            src_buf -= stride; 
     605        } 
     606    } 
     607 
    587608    if (strm->vid_cb.capture_cb) 
    588609        (*strm->vid_cb.capture_cb)(&strm->base, strm->user_data, &frame); 
     
    761782    hr = IFilterGraph_ConnectDirect(graph->filter_graph, srcpin, sinkpin, 
    762783                                    mediatype); 
    763     if (SUCCEEDED(hr) && (use_def_size || use_def_fps)) { 
    764         pjmedia_format_init_video(&strm->param.fmt, strm->param.fmt.id, 
    765                                   video_info->bmiHeader.biWidth, 
    766                                   video_info->bmiHeader.biHeight, 
    767                                   10000000, 
    768                                   (unsigned)video_info->AvgTimePerFrame); 
     784    if (SUCCEEDED(hr)) { 
     785        if (use_def_size || use_def_fps) { 
     786            pjmedia_format_init_video(&strm->param.fmt, strm->param.fmt.id, 
     787                                      video_info->bmiHeader.biWidth, 
     788                                      video_info->bmiHeader.biHeight, 
     789                                      10000000, 
     790                                      (unsigned)video_info->AvgTimePerFrame); 
     791        } 
     792 
     793        strm->frm_buf_size = 0; 
     794        if (dir == PJMEDIA_DIR_CAPTURE && 
     795            video_info->bmiHeader.biCompression == BI_RGB && 
     796            video_info->bmiHeader.biHeight > 0) 
     797        { 
     798            /* Allocate buffer to flip the captured image. */ 
     799            strm->frm_buf_size = (video_info->bmiHeader.biBitCount >> 3) * 
     800                                 video_info->bmiHeader.biWidth; 
     801            strm->frm_buf = pj_pool_alloc(strm->pool, strm->frm_buf_size); 
     802        } 
    769803    } 
    770804 
Note: See TracChangeset for help on using the changeset viewer.