📄 utils.c
字号:
static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){ int flags=0; memset(s, 0, sizeof(AVCodecContext)); s->av_class= &av_codec_context_class; s->codec_type = codec_type; if(codec_type == CODEC_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; else if(codec_type == CODEC_TYPE_VIDEO) flags= AV_OPT_FLAG_VIDEO_PARAM; else if(codec_type == CODEC_TYPE_SUBTITLE) flags= AV_OPT_FLAG_SUBTITLE_PARAM; av_opt_set_defaults2(s, flags, flags); s->rc_eq= "tex^qComp"; s->time_base= (AVRational){0,1}; s->get_buffer= avcodec_default_get_buffer; s->release_buffer= avcodec_default_release_buffer; s->get_format= avcodec_default_get_format; s->execute= avcodec_default_execute; s->sample_aspect_ratio= (AVRational){0,1}; s->pix_fmt= PIX_FMT_NONE; s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE s->palctrl = NULL; s->reget_buffer= avcodec_default_reget_buffer;}AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){ AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); if(avctx==NULL) return NULL; avcodec_get_context_defaults2(avctx, codec_type); return avctx;}void avcodec_get_context_defaults(AVCodecContext *s){ avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);}AVCodecContext *avcodec_alloc_context(void){ return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);}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) 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, (void *)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, (void *)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; ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub); avctx->frame_number++; return ret;}int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, 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, 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;}#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, uint8_t *buf, int buf_size){ *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE; return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);}#endifint 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, (uint8_t *)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 (ENABLE_THREADS && avctx->thread_opaque) avcodec_thread_free(avctx); if (avctx->codec->avclose) avctx->codec->avclose(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -