Changeset 4057


Ignore:
Timestamp:
Apr 17, 2012 6:54:50 AM (12 years ago)
Author:
bennylp
Message:

Related to re #1478: add timestamp value to audio and video frames in the AVI player, and fix the avg/max bps calculation for the port info of audio stream

File:
1 edited

Legend:

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

    r4048 r4057  
    4949#define SIGNATURE           PJMEDIA_SIG_PORT_VID_AVI_PLAYER 
    5050 
     51#define VIDEO_CLOCK_RATE        90000 
     52 
    5153#if 0 
    5254#   define TRACE_(x)    PJ_LOG(4,x) 
     
    124126    unsigned         options; 
    125127    pjmedia_format_id fmt_id; 
     128    unsigned         usec_per_frame; 
    126129    pj_uint16_t      bits_per_sample; 
    127130    pj_bool_t        eof; 
     
    131134    pj_oshandle_t    fd; 
    132135    pj_ssize_t       size_left; 
     136    pj_timestamp     next_ts; 
    133137 
    134138    pj_status_t    (*cb)(pjmedia_port*, void*); 
     
    456460 
    457461            fport[i]->bits_per_sample = (vfi ? vfi->bpp : 0); 
     462            fport[i]->usec_per_frame = avi_hdr.avih_hdr.usec_per_frame; 
    458463            pjmedia_format_init_video(&fport[i]->base.info.fmt, 
    459464                                      fport[i]->fmt_id, 
     
    462467                                      strl_hdr->rate, 
    463468                                      strl_hdr->scale); 
    464              
     469#if 0 
     470            /* The calculation below is wrong. strf_hdr->biSizeImage shows 
     471             * uncompressed size. Looks like we need to go the ugly way to 
     472             * get the bitrage: 
     473             *    http://www.virtualdub.org/blog/pivot/entry.php?id=159 
     474             */ 
     475            bps = strf_hdr->biSizeImage * 8 * strl_hdr->rate / strl_hdr->scale; 
     476            if (bps==0) { 
     477                /* strf_hdr->biSizeImage may be zero for uncompressed RGB */ 
     478                bps = strf_hdr->biWidth * strf_hdr->biHeight * 
     479                        strf_hdr->biBitCount * 
     480                        strl_hdr->rate / strl_hdr->scale; 
     481            } 
     482            fport[i]->base.info.fmt.det.vid.avg_bps = bps; 
     483            fport[i]->base.info.fmt.det.vid.max_bps = bps; 
     484#endif 
    465485        } else { 
    466486            strf_audio_hdr_t *strf_hdr = 
     
    468488 
    469489            fport[i]->bits_per_sample = strf_hdr->bits_per_sample; 
     490            fport[i]->usec_per_frame = avi_hdr.avih_hdr.usec_per_frame; 
    470491            pjmedia_format_init_audio(&fport[i]->base.info.fmt, 
    471492                                      fport[i]->fmt_id, 
     
    473494                                      strf_hdr->nchannels, 
    474495                                      strf_hdr->bits_per_sample, 
    475                                       20000, 
    476                                       strf_hdr->bytes_per_sec, 
    477                                       strf_hdr->bytes_per_sec); 
     496                                      20000 /* fport[i]->usec_per_frame */, 
     497                                      strf_hdr->bytes_per_sec * 8, 
     498                                      strf_hdr->bytes_per_sec * 8); 
    478499        } 
    479500 
     
    696717        frame->type = (fport->base.info.fmt.type == PJMEDIA_TYPE_VIDEO ? 
    697718                       PJMEDIA_FRAME_TYPE_VIDEO : PJMEDIA_FRAME_TYPE_AUDIO); 
    698         frame->timestamp.u64 = 0; 
     719 
    699720        if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) { 
    700721            if (size_to_read > fport->size_left) 
     
    720741    } while(1); 
    721742 
     743    frame->timestamp.u64 = fport->next_ts.u64; 
     744    if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) { 
     745        if (fport->usec_per_frame) { 
     746            fport->next_ts.u64 += (fport->usec_per_frame * 
     747                                   fport->base.info.fmt.det.aud.clock_rate / 
     748                                   1000000); 
     749        } else { 
     750            fport->next_ts.u64 += (frame->size * 
     751                                   fport->base.info.fmt.det.aud.clock_rate / 
     752                                   (fport->base.info.fmt.det.aud.avg_bps / 8)); 
     753        } 
     754    } else { 
     755        if (fport->usec_per_frame) { 
     756            fport->next_ts.u64 += (fport->usec_per_frame * VIDEO_CLOCK_RATE / 
     757                                   1000000); 
     758        } else { 
     759            fport->next_ts.u64 += (frame->size * VIDEO_CLOCK_RATE / 
     760                                   (fport->base.info.fmt.det.vid.avg_bps / 8)); 
     761        } 
     762    } 
     763 
    722764    return PJ_SUCCESS; 
    723765 
Note: See TracChangeset for help on using the changeset viewer.