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

📄 utils.c

📁 播放H264文件的播放器
💻 C
📖 第 1 页 / 共 3 页
字号:
    s->release_buffer(s, &temp_pic); // Release old frame    return 0;}int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){    int i;    for(i=0; i<count; i++){        int r= func(c, (char*)arg + i*size);        if(ret) ret[i]= r;    }    return 0;}enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){    while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))        ++fmt;    return fmt[0];}void avcodec_get_frame_defaults(AVFrame *pic){    memset(pic, 0, sizeof(AVFrame));    pic->pts= AV_NOPTS_VALUE;    pic->key_frame= 1;}AVFrame *avcodec_alloc_frame(void){    AVFrame *pic= av_malloc(sizeof(AVFrame));    if(pic==NULL) return NULL;    avcodec_get_frame_defaults(pic);    return pic;}int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec){    int ret= -1;    entangled_thread_counter++;    if(entangled_thread_counter != 1){        av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");        goto end;    }    if(avctx->codec || !codec)        goto end;    if (codec->priv_data_size > 0) {        avctx->priv_data = av_mallocz(codec->priv_data_size);        if (!avctx->priv_data) {            ret = AVERROR(ENOMEM);            goto end;        }    } else {        avctx->priv_data = NULL;    }    if(avctx->coded_width && avctx->coded_height)        avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);    else if(avctx->width && avctx->height)        avcodec_set_dimensions(avctx, avctx->width, avctx->height);    if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){        av_freep(&avctx->priv_data);        ret = AVERROR(EINVAL);        goto end;    }    avctx->codec = codec;    avctx->codec_id = codec->id;    avctx->frame_number = 0;    if(avctx->codec->init){        ret = avctx->codec->init(avctx);        if (ret < 0) {            av_freep(&avctx->priv_data);            avctx->codec= NULL;            goto end;        }    }    ret=0;end:    entangled_thread_counter--;    return ret;}int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,                         const short *samples){    if(buf_size < FF_MIN_BUFFER_SIZE && 0){        av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");        return -1;    }    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){        int ret = avctx->codec->encode(avctx, buf, buf_size, samples);        avctx->frame_number++;        return ret;    }else        return 0;}int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,                         const AVFrame *pict){    if(buf_size < FF_MIN_BUFFER_SIZE){        av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");        return -1;    }    if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))        return -1;    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){        int ret = avctx->codec->encode(avctx, buf, buf_size, pict);        avctx->frame_number++;        emms_c(); //needed to avoid an emms_c() call before every return;        return ret;    }else        return 0;}int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,                            const AVSubtitle *sub){    int ret;    if(sub->start_display_time) {        av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");        return -1;    }    if(sub->num_rects == 0 || !sub->rects)        return -1;    ret = avctx->codec->encode(avctx, buf, buf_size, sub);    avctx->frame_number++;    return ret;}int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,                         int *got_picture_ptr,                         const uint8_t *buf, int buf_size){    int ret;    *got_picture_ptr= 0;    if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))        return -1;    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){        ret = avctx->codec->decode(avctx, picture, got_picture_ptr,                                buf, buf_size);        emms_c(); //needed to avoid an emms_c() call before every return;        if (*got_picture_ptr)            avctx->frame_number++;    }else        ret= 0;    return ret;}int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,                         int *frame_size_ptr,                         const uint8_t *buf, int buf_size){    int ret;    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){        //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough        if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){            av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");            return -1;        }        if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||        *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){            av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);            return -1;        }        ret = avctx->codec->decode(avctx, samples, frame_size_ptr,                                buf, buf_size);        avctx->frame_number++;    }else{        ret= 0;        *frame_size_ptr=0;    }    return ret;}int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,                            int *got_sub_ptr,                            const uint8_t *buf, int buf_size){    int ret;    *got_sub_ptr = 0;    ret = avctx->codec->decode(avctx, sub, got_sub_ptr,                               buf, buf_size);    if (*got_sub_ptr)        avctx->frame_number++;    return ret;}int avcodec_close(AVCodecContext *avctx){    entangled_thread_counter++;    if(entangled_thread_counter != 1){        av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");        entangled_thread_counter--;        return -1;    }    if (avctx->codec->close)        avctx->codec->close(avctx);    avcodec_default_free_buffers(avctx);    av_freep(&avctx->priv_data);    avctx->codec = NULL;    entangled_thread_counter--;    return 0;}AVCodec *avcodec_find_encoder(enum CodecID id){    AVCodec *p;    p = first_avcodec;    while (p) {        if (p->encode != NULL && p->id == id)            return p;        p = p->next;    }    return NULL;}AVCodec *avcodec_find_encoder_by_name(const char *name){    AVCodec *p;    if (!name)        return NULL;    p = first_avcodec;    while (p) {        if (p->encode != NULL && strcmp(name,p->name) == 0)            return p;        p = p->next;    }    return NULL;}AVCodec *avcodec_find_decoder(enum CodecID id){    AVCodec *p;    p = first_avcodec;    while (p) {        if (p->decode != NULL && p->id == id)            return p;        p = p->next;    }    return NULL;}AVCodec *avcodec_find_decoder_by_name(const char *name){    AVCodec *p;    if (!name)        return NULL;    p = first_avcodec;    while (p) {        if (p->decode != NULL && strcmp(name,p->name) == 0)            return p;        p = p->next;    }    return NULL;}void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode){    const char *codec_name;    AVCodec *p;    char buf1[32];    int bitrate;    AVRational display_aspect_ratio;    if (encode)        p = avcodec_find_encoder(enc->codec_id);    else        p = avcodec_find_decoder(enc->codec_id);    if (p) {        codec_name = p->name;    } else if (enc->codec_id == CODEC_ID_MPEG2TS) {        /* fake mpeg2 transport stream codec (currently not           registered) */        codec_name = "mpeg2ts";    } else if (enc->codec_name[0] != '\0') {        codec_name = enc->codec_name;    } else {        /* output avi tags */        if(   isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)           && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){            snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",                     enc->codec_tag & 0xff,                     (enc->codec_tag >> 8) & 0xff,                     (enc->codec_tag >> 16) & 0xff,                     (enc->codec_tag >> 24) & 0xff,                      enc->codec_tag);        } else {            snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);        }        codec_name = buf1;    }    switch(enc->codec_type) {    case CODEC_TYPE_VIDEO:        snprintf(buf, buf_size,                 "Video: %s%s",                 codec_name, enc->mb_decision ? " (hq)" : "");        if (enc->pix_fmt != PIX_FMT_NONE) {            snprintf(buf + strlen(buf), buf_size - strlen(buf),                     ", %s",                     avcodec_get_pix_fmt_name(enc->pix_fmt));        }        if (enc->width) {            snprintf(buf + strlen(buf), buf_size - strlen(buf),                     ", %dx%d",                     enc->width, enc->height);            if (enc->sample_aspect_ratio.num) {                av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,                          enc->width*enc->sample_aspect_ratio.num,                          enc->height*enc->sample_aspect_ratio.den,                          1024*1024);                snprintf(buf + strlen(buf), buf_size - strlen(buf),                         " [PAR %d:%d DAR %d:%d]",                         enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,                         display_aspect_ratio.num, display_aspect_ratio.den);            }            if(av_log_get_level() >= AV_LOG_DEBUG){                int g= av_gcd(enc->time_base.num, enc->time_base.den);                snprintf(buf + strlen(buf), buf_size - strlen(buf),                     ", %d/%d",                     enc->time_base.num/g, enc->time_base.den/g);            }        }        if (encode) {            snprintf(buf + strlen(buf), buf_size - strlen(buf),                     ", q=%d-%d", enc->qmin, enc->qmax);        }        bitrate = enc->bit_rate;        break;    case CODEC_TYPE_AUDIO:        snprintf(buf, buf_size,                 "Audio: %s",                 codec_name);        if (enc->sample_rate) {            snprintf(buf + strlen(buf), buf_size - strlen(buf),                     ", %d Hz", enc->sample_rate);        }                        if (enc->sample_fmt != SAMPLE_FMT_NONE) {                    }        /* for PCM codecs, compute bitrate directly */        switch(enc->codec_id) {        case CODEC_ID_PCM_F64BE:        case CODEC_ID_PCM_F64LE:            bitrate = enc->sample_rate * enc->channels * 64;            break;        case CODEC_ID_PCM_S32LE:        case CODEC_ID_PCM_S32BE:        case CODEC_ID_PCM_U32LE:        case CODEC_ID_PCM_U32BE:        case CODEC_ID_PCM_F32BE:        case CODEC_ID_PCM_F32LE:            bitrate = enc->sample_rate * enc->channels * 32;            break;        case CODEC_ID_PCM_S24LE:        case CODEC_ID_PCM_S24BE:        case CODEC_ID_PCM_U24LE:        case CODEC_ID_PCM_U24BE:        case CODEC_ID_PCM_S24DAUD:            bitrate = enc->sample_rate * enc->channels * 24;            break;        case CODEC_ID_PCM_S16LE:        case CODEC_ID_PCM_S16BE:        case CODEC_ID_PCM_S16LE_PLANAR:        case CODEC_ID_PCM_U16LE:        case CODEC_ID_PCM_U16BE:            bitrate = enc->sample_rate * enc->channels * 16;            break;

⌨️ 快捷键说明

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