Changeset 4685

Show
Ignore:
Timestamp:
03/12/10 02:10:27 (4 years ago)
Author:
soohyunc
Message:

-- added mechanisms to keep track of

sent packets
didn't sent packets

per frame

so that we could do some necessary actions when:

capture frames faster than transmitting
(e.g., building transmitter queue forever)

currently, action fields are left empty.

Location:
vic/branches/cc
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • vic/branches/cc/cc/o.sh

    r4648 r4685  
    1313 
    1414# encoding time difference 
    15 grep enc_time trace.s | grep -v pid | awk '{if($1=="num:" && $3=="enc_time:") print}' | awk '{print $2"\t"$4}' > enct.xg 
     15grep enc_time trace.s | grep -v pid | awk '{if($1=="now:" && $3=="enc_time:") print}' | awk '{print $2"\t"$4}' > enct.xg 
    1616 
    1717# start grab 
  • vic/branches/cc/codec/encoder-h261.cpp

    r4621 r4685  
    114114} 
    115115 
     116// frame history size to keep track the number of packets per frame 
     117#define FHSIZE  10 
    116118 
    117119class H261Encoder : public TransmitterModule { 
    118120    public: 
    119121        void setq(int q); 
     122 
     123        // Tx pktbuf size 
     124        int txq_beg_; 
     125        int txq_end_; 
     126        int txq_dif_; 
     127        // number of transmitted packets for this round of encoding 
     128        int num_sent_; 
     129        // number of sent packets in between two encoding instances 
     130        // (these packets were sent from the Tx queue upon XR reception) 
     131        int sent_more_; 
     132        // packets per frame 
     133        int ppframe_[FHSIZE]; 
     134        inline void init_ppframe() { 
     135                for (int i = 0; i < FHSIZE; i++) 
     136                ppframe_[i] = 0; 
     137        } 
     138        // video frame number 
     139        int vfno_; 
     140 
    120141    protected: 
    121142        H261Encoder(int ft); 
     
    137158                return ((double) tv.tv_sec + 1e-6 * (double) tv.tv_usec); 
    138159        } 
    139         double ts_off_; // timestamp offset 
    140160        double enc_start_;      // encoding start timestamp 
    141161        double enc_end_;        // encoding end timestamp 
    142         int encno_;     // number of encoding routine  
    143162 
    144163        /* bit buffer */ 
     
    177196        u_int loff_[12];        /* where to find Y given gob# */ 
    178197        u_int blkno_[12];       /* for CR */ 
     198 
     199private: 
    179200}; 
    180201 
     
    221242        enc_start_ = 0.0; 
    222243        enc_end_ = 0.0; 
    223         encno_ = 1; 
     244 
     245        // Tx pktbuf size 
     246        txq_beg_ = 0; 
     247        txq_end_ = 0; 
     248        txq_dif_ = 0; 
     249        // number of transmitted packets for this round of encoding 
     250        num_sent_ = 0; 
     251        // number of sent packets in between two encoding instances 
     252        // (these packets were sent from the Tx queue upon XR reception) 
     253        sent_more_ = 0; 
     254 
     255        // packets per frame 
     256        init_ppframe(); 
     257        // video frame number 
     258        vfno_ = 0; 
    224259 
    225260        for (int q = 0; q < 32; ++q) { 
     
    769804                        bb_ = 0; 
    770805        } 
     806        // increment the number of packets for this frame 
     807        ppframe_[vfno_%FHSIZE]++; 
     808        fprintf(stderr, "\tnow: %f\tppframe[%d]: %d\n", 
     809        h261_now()-offset(), vfno_%FHSIZE, ppframe_[vfno_%FHSIZE]); 
    771810        tx_->send(pb); 
    772811 
     
    786825int H261PixelEncoder::consume(const VideoFrame *vf) 
    787826{ 
     827        // adjust timestamp offset 
     828        tx_->tx_now_offset_ = offset(); 
     829 
     830        // (get the necessary stats before encoding) ---------------------* 
     831        // Tx queue size before entering this encoding 
     832        txq_beg_ = tx_->tx_buf_size(); 
     833        // sent packets after the previous encoding round,  
     834        // but before starting this encoding instance. 
     835        // -- these packets were sent from the Tx queue  
     836        //    upon XR reception in between two encoding instances. 
     837        sent_more_ = txq_end_ - txq_beg_; 
     838 
     839        fprintf(stderr, "\tnow: %f\tsent: %d more: %d vf[%d]: %d\n", 
     840        h261_now()-offset(), num_sent_, sent_more_, vfno_%FHSIZE, ppframe_[vfno_%FHSIZE]); 
     841 
     842        // all encoded packets associated with  
     843        // the previously captured frame have been sent  
     844        if (num_sent_ + sent_more_ == ppframe_[vfno_%FHSIZE]) { 
     845        } 
     846        // some packets associated with  
     847        // the previously captured frame have not been sent 
     848        if (num_sent_ + sent_more_ < ppframe_[vfno_%FHSIZE]) { 
     849        } 
     850        // more packets have been sent than the encoded packets 
     851        // perhaps, there were some packets in the tx queue, and 
     852        // cwnd has been increrased allowing sending them all. 
     853        if (num_sent_ + sent_more_ > ppframe_[vfno_%FHSIZE]) { 
     854        } 
     855        // ---------------------------------------------------------------* 
     856 
     857        // increment frame number 
     858        if (vfno_++%FHSIZE == 0)  
     859        init_ppframe(); 
     860 
     861        // check size 
    788862        if (!samesize(vf)) 
    789863                size(vf->width_, vf->height_); 
    790864 
     865        // main encoding loop 
     866        // (send packets while encoding) 
    791867        YuvFrame* p = (YuvFrame*)vf; 
    792         return(encode(p, p->crvec_)); 
     868        int cc = encode(p, p->crvec_); 
     869 
     870        // Tx queue size after finishing encoding 
     871        txq_end_ = tx_->tx_buf_size(); 
     872        txq_dif_ = txq_end_ - txq_beg_; 
     873        // number of Tx'd packets during this encoding instance 
     874        // (these Tx'd packets may include the previous frame(s).) 
     875        num_sent_ = ppframe_[vfno_%FHSIZE] - txq_dif_; 
     876 
     877        fprintf(stderr, "   now: %f\ttxq_end: %d\tdif: %d\n",  
     878                h261_now()-offset(), txq_end_, txq_dif_); 
     879 
     880        fprintf(stderr, "   now: %f\tenc_time: %f\n\n",  
     881                h261_now()-offset(), (enc_end_ - enc_start_)); 
     882 
     883        return(cc); 
    793884} 
    794885                 
     
    797888H261Encoder::encode(const VideoFrame* vf, const u_int8_t *crvec) 
    798889{ 
    799         //fprintf(stderr,"\nH261Encoder encode()\n"); 
    800         ts_off_ = offset(); 
    801         tx_->tx_now_offset_ = ts_off_; 
    802         enc_start_ = h261_now() - ts_off_; 
     890        enc_start_ = h261_now()-offset(); 
    803891        fprintf(stderr,">>>h261_encode_start\tnow: %f\n", enc_start_); 
    804892 
     
    898986 
    899987        // time measurement 
    900         enc_end_ = h261_now() - ts_off_; 
     988        enc_end_ = h261_now()-offset(); 
    901989        fprintf(stderr,"\n>>>h261_encode_end\tnow: %f\n", enc_end_); 
    902         fprintf(stderr,"   num: %d\tenc_time: %f\n\n",  
    903                 encno_++, (enc_end_ - enc_start_)); 
    904990 
    905991        return (cc);