AVFrameContext结构体销毁函数avformat_free_context

 AVFrameContext结构体销毁函数avformat_free_context


void avformat_free_context(AVFormatContext *s)
{
    int i;

    if (!s)
        return;

    if (s->oformat && s->oformat->deinit && s->internal->initialized)
        s->oformat->deinit(s);

//av_opt_free定义
/*
void av_opt_free(void *obj)
{
    const AVOption *o = NULL;
    while ((o = av_opt_next(obj, o))) {
        switch (o->type) {
//针对不同类型,调用不同的“释放”函数
        case AV_OPT_TYPE_STRING:
        case AV_OPT_TYPE_BINARY:
            av_freep((uint8_t *)obj + o->offset);
            break;

        case AV_OPT_TYPE_DICT:
            av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
            break;

        default:
            break;
        }
    }
}
*/

    av_opt_free(s);
//
    if (s->iformat && s->iformat->priv_class && s->priv_data)
        av_opt_free(s->priv_data);
    if (s->oformat && s->oformat->priv_class && s->priv_data)
        av_opt_free(s->priv_data);

//针对流进行“释放”,同时把number置零
    for (i = 0; i < s->nb_streams; i++)
        free_stream(&s->streams[i]);
    s->nb_streams = 0;

//针对programs进行“释放”,同时把number置零
    for (i = 0; i < s->nb_programs; i++) {
        av_dict_free(&s->programs[i]->metadata);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    s->nb_programs = 0;

    av_freep(&s->programs);
    av_freep(&s->priv_data);
    while (s->nb_chapters--) {
        av_dict_free(&s->chapters[s->nb_chapters]->metadata);
        av_freep(&s->chapters[s->nb_chapters]);
    }
    av_freep(&s->chapters);
    av_dict_free(&s->metadata);
    av_dict_free(&s->internal->id3v2_meta);
    av_packet_free(&s->internal->pkt);
    av_packet_free(&s->internal->parse_pkt);
    av_freep(&s->streams);
    flush_packet_queue(s);
    av_freep(&s->internal);
    av_freep(&s->url);
    av_free(s);
}

 

 
posted @ 2021-04-13 19:06  Keep_Silent  阅读(45)  评论(0编辑  收藏  举报