⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpegvideo.c

📁 tcpmp播放器的flv插件
💻 C
📖 第 1 页 / 共 5 页
字号:
        if(s->dct_count[intra] > (1<<16)){            for(i=0; i<64; i++){                s->dct_error_sum[intra][i] >>=1;            }            s->dct_count[intra] >>= 1;        }                for(i=0; i<64; i++){            s->dct_offset[intra][i]= (s->avctx->noise_reduction * s->dct_count[intra] + s->dct_error_sum[intra][i]/2) / (s->dct_error_sum[intra][i]+1);        }    }}/** * generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded */int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx){    int i;    AVFrame *pic;    s->mb_skipped = 0;    assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3);    /* mark&release old frames */    if (s->pict_type != B_TYPE && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) {        avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr);        /* release forgotten pictures */        /* if(mpeg124/h263) */        if(!s->encoding){            for(i=0; i<MAX_PICTURE_COUNT; i++){                if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){                    av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");                    avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);                                }            }        }    }alloc:    if(!s->encoding){        /* release non reference frames */        for(i=0; i<MAX_PICTURE_COUNT; i++){            if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){                s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);            }        }        if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)            pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header)        else{            i= ff_find_unused_picture(s, 0);            pic= (AVFrame*)&s->picture[i];        }        pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264)                        && !s->dropable ? 3 : 0;        pic->coded_picture_number= s->coded_picture_number++;                if( alloc_picture(s, (Picture*)pic, 0) < 0)            return -1;        s->current_picture_ptr= (Picture*)pic;        s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic        s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence;    }    s->current_picture_ptr->pict_type= s->pict_type;//    if(s->flags && CODEC_FLAG_QSCALE)   //      s->current_picture_ptr->quality= s->new_picture_ptr->quality;    s->current_picture_ptr->key_frame= s->pict_type == I_TYPE;    copy_picture(&s->current_picture, s->current_picture_ptr);    if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){    if (s->pict_type != B_TYPE) {        s->last_picture_ptr= s->next_picture_ptr;        if(!s->dropable)            s->next_picture_ptr= s->current_picture_ptr;    }/*    av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,        s->last_picture_ptr    ? s->last_picture_ptr->data[0] : NULL,         s->next_picture_ptr    ? s->next_picture_ptr->data[0] : NULL,         s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL,        s->pict_type, s->dropable);*/        if(s->last_picture_ptr) copy_picture(&s->last_picture, s->last_picture_ptr);    if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr);        if(s->pict_type != I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL)){        av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n");        assert(s->pict_type != B_TYPE); //these should have been dropped if we don't have a reference        goto alloc;    }    assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0]));    if(s->picture_structure!=PICT_FRAME){        int i;        for(i=0; i<4; i++){            if(s->picture_structure == PICT_BOTTOM_FIELD){                 s->current_picture.data[i] += s->current_picture.linesize[i];            }             s->current_picture.linesize[i] *= 2;            s->last_picture.linesize[i] *=2;            s->next_picture.linesize[i] *=2;        }    }  }       s->hurry_up= s->avctx->hurry_up;    s->error_resilience= avctx->error_resilience;    /* set dequantizer, we can't do it during init as it might change for mpeg4       and we can't do it in the header decode as init isnt called for mpeg4 there yet */    if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){        s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;        s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;    }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){        s->dct_unquantize_intra = s->dct_unquantize_h263_intra;        s->dct_unquantize_inter = s->dct_unquantize_h263_inter;    }else{        s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;        s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;    }    if(s->dct_error_sum){        assert(s->avctx->noise_reduction && s->encoding);        update_noise_reduction(s);    }        #ifdef HAVE_XVMC    if(s->avctx->xvmc_acceleration)        return XVMC_field_start(s, avctx);#endif    return 0;}/* generic function for encode/decode called after a frame has been coded/decoded */void MPV_frame_end(MpegEncContext *s){    int i;    /* draw edge for correct motion prediction if outside */#ifdef HAVE_XVMC//just to make sure that all data is rendered.    if(s->avctx->xvmc_acceleration){        XVMC_field_end(s);    }else#endif    if(s->unrestricted_mv && s->current_picture.reference && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {            draw_edges(s->current_picture.data[0], s->linesize  , s->h_edge_pos   , s->v_edge_pos   , EDGE_WIDTH  );            draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);            draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);    }    emms_c();        s->last_pict_type    = s->pict_type;    if(s->pict_type!=B_TYPE){        s->last_non_b_pict_type= s->pict_type;    }#if 0        /* copy back current_picture variables */    for(i=0; i<MAX_PICTURE_COUNT; i++){        if(s->picture[i].data[0] == s->current_picture.data[0]){            s->picture[i]= s->current_picture;            break;        }        }    assert(i<MAX_PICTURE_COUNT);#endif        if(s->encoding){        /* release non-reference frames */        for(i=0; i<MAX_PICTURE_COUNT; i++){            if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){                s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);            }        }    }    // clear copies, to avoid confusion#if 0    memset(&s->last_picture, 0, sizeof(Picture));    memset(&s->next_picture, 0, sizeof(Picture));    memset(&s->current_picture, 0, sizeof(Picture));#endif    s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr;}/** * draws an line from (ex, ey) -> (sx, sy). * @param w width of the image * @param h height of the image * @param stride stride/linesize of the image * @param color color of the arrow */static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){    int t, x, y, fr, f;        sx= clip(sx, 0, w-1);    sy= clip(sy, 0, h-1);    ex= clip(ex, 0, w-1);    ey= clip(ey, 0, h-1);        buf[sy*stride + sx]+= color;        if(ABS(ex - sx) > ABS(ey - sy)){        if(sx > ex){            t=sx; sx=ex; ex=t;            t=sy; sy=ey; ey=t;        }        buf+= sx + sy*stride;        ex-= sx;        f= ((ey-sy)<<16)/ex;        for(x= 0; x <= ex; x++){            y = (x*f)>>16;            fr= (x*f)&0xFFFF;            buf[ y   *stride + x]+= (color*(0x10000-fr))>>16;            buf[(y+1)*stride + x]+= (color*         fr )>>16;        }    }else{        if(sy > ey){            t=sx; sx=ex; ex=t;            t=sy; sy=ey; ey=t;        }        buf+= sx + sy*stride;        ey-= sy;        if(ey) f= ((ex-sx)<<16)/ey;        else   f= 0;        for(y= 0; y <= ey; y++){            x = (y*f)>>16;            fr= (y*f)&0xFFFF;            buf[y*stride + x  ]+= (color*(0x10000-fr))>>16;;            buf[y*stride + x+1]+= (color*         fr )>>16;;        }    }}/** * draws an arrow from (ex, ey) -> (sx, sy). * @param w width of the image * @param h height of the image * @param stride stride/linesize of the image * @param color color of the arrow */static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){     int dx,dy;    sx= clip(sx, -100, w+100);    sy= clip(sy, -100, h+100);    ex= clip(ex, -100, w+100);    ey= clip(ey, -100, h+100);        dx= ex - sx;    dy= ey - sy;        if(dx*dx + dy*dy > 3*3){        int rx=  dx + dy;        int ry= -dx + dy;        int length= ff_sqrt((rx*rx + ry*ry)<<8);                //FIXME subpixel accuracy        rx= ROUNDED_DIV(rx*3<<4, length);        ry= ROUNDED_DIV(ry*3<<4, length);                draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);        draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);    }    draw_line(buf, sx, sy, ex, ey, w, h, stride, color);}#if 0 //Picard
/** * prints debuging info for the given picture. */void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){    if(!pict || !pict->mb_type) return;    if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){        int x,y;                av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: ");        switch (pict->pict_type) {            case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break;            case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break;            case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break;            case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break;            case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break;            case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break;                    }        for(y=0; y<s->mb_height; y++){            for(x=0; x<s->mb_width; x++){                if(s->avctx->debug&FF_DEBUG_SKIP){                    int count= s->mbskip_table[x + y*s->mb_stride];                    if(count>9) count=9;                    av_log(s->avctx, AV_LOG_DEBUG, "%1d", count);                }                if(s->avctx->debug&FF_DEBUG_QP){                    av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]);                }                if(s->avctx->debug&FF_DEBUG_MB_TYPE){                    int mb_type= pict->mb_type[x + y*s->mb_stride];                    //Type & MV direction                    if(IS_PCM(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "P");                    else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "A");                    else if(IS_INTRA4x4(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "i");                    else if(IS_INTRA16x16(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "I");                    else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "d");                    else if(IS_DIRECT(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "D");                    else if(IS_GMC(mb_type) && IS_SKIP(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "g");                    else if(IS_GMC(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "G");                    else if(IS_SKIP(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "S");                    else if(!USES_LIST(mb_type, 1))                        av_log(s->avctx, AV_LOG_DEBUG, ">");                    else if(!USES_LIST(mb_type, 0))                        av_log(s->avctx, AV_LOG_DEBUG, "<");                    else{                        assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));                        av_log(s->avctx, AV_LOG_DEBUG, "X");                    }                                        //segmentation                    if(IS_8X8(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "+");                    else if(IS_16X8(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "-");                    else if(IS_8X16(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, "|");                    else if(IS_INTRA(mb_type) || IS_16X16(mb_type))                        av_log(s->avctx, AV_LOG_DEBUG, " ");                    else                        av_log(s->avctx, AV_LOG_DEBUG, "?");                                                                if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)                        av_log(s->avctx, AV_LOG_DEBUG, "=");                    else                        av_log(s->avctx, AV_LOG_DEBUG, " ");                }//                av_log(s->avctx, AV_LOG_DEBUG, " ");            }            av_log(s->avctx, AV_LOG_DEBUG, "\n");        }    }    if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){        const int shift= 1 +

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -