MediaPacket::~MediaPacket() { if (shouldFreeAvCodecParameters) { if (pAvCodecPar_) avcodec_parameters_free(&pAvCodecPar_); } av_packet_free(&pAvPacket_); }
void ff_mov_close_hinting(MOVTrack *track) { AVFormatContext *rtp_ctx = track->rtp_ctx; avcodec_parameters_free(&track->par); sample_queue_free(&track->sample_queue); if (!rtp_ctx) return; if (rtp_ctx->pb) { av_write_trailer(rtp_ctx); ffio_free_dyn_buf(&rtp_ctx->pb); } avformat_free_context(rtp_ctx); }
void av_bsf_free(AVBSFContext **pctx) { AVBSFContext *ctx; if (!pctx || !*pctx) return; ctx = *pctx; if (ctx->filter->close) ctx->filter->close(ctx); if (ctx->filter->priv_class && ctx->priv_data) av_opt_free(ctx->priv_data); av_opt_free(ctx); av_packet_free(&ctx->internal->buffer_pkt); av_freep(&ctx->internal); av_freep(&ctx->priv_data); avcodec_parameters_free(&ctx->par_in); avcodec_parameters_free(&ctx->par_out); av_freep(pctx); }
// Set avctx codec headers for decoding. Returns <0 on failure. int mp_set_avctx_codec_headers(AVCodecContext *avctx, struct mp_codec_params *c) { enum AVMediaType codec_type = avctx->codec_type; enum AVCodecID codec_id = avctx->codec_id; AVCodecParameters *avp = mp_codec_params_to_av(c); if (!avp) return -1; int r = avcodec_parameters_to_context(avctx, avp) < 0 ? -1 : 0; avcodec_parameters_free(&avp); if (avctx->codec_type != AVMEDIA_TYPE_UNKNOWN) avctx->codec_type = codec_type; if (avctx->codec_id != AV_CODEC_ID_NONE) avctx->codec_id = codec_id; return r; }
AVCodecParameters *mp_codec_params_to_av(struct mp_codec_params *c) { AVCodecParameters *avp = avcodec_parameters_alloc(); if (!avp) return NULL; // If we have lavf demuxer params, they overwrite by definition any others. if (c->lav_codecpar) { if (avcodec_parameters_copy(avp, c->lav_codecpar) < 0) goto error; return avp; } avp->codec_type = mp_to_av_stream_type(c->type); avp->codec_id = mp_codec_to_av_codec_id(c->codec); avp->codec_tag = c->codec_tag; if (c->extradata_size) { avp->extradata = av_mallocz(c->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!avp->extradata) goto error; avp->extradata_size = c->extradata_size; memcpy(avp->extradata, c->extradata, avp->extradata_size); } avp->bits_per_coded_sample = c->bits_per_coded_sample; // Video only avp->width = c->disp_w; avp->height = c->disp_h; // Audio only avp->sample_rate = c->samplerate; avp->bit_rate = c->bitrate; avp->block_align = c->block_align; avp->channels = c->channels.num; if (!mp_chmap_is_unknown(&c->channels)) avp->channel_layout = mp_chmap_to_lavc(&c->channels); return avp; error: avcodec_parameters_free(&avp); return NULL; }
int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) { MOVMuxContext *mov = s->priv_data; MOVTrack *track = &mov->tracks[index]; MOVTrack *src_track = &mov->tracks[src_index]; AVStream *src_st = s->streams[src_index]; int ret = AVERROR(ENOMEM); track->tag = MKTAG('r','t','p',' '); track->src_track = src_index; track->par = avcodec_parameters_alloc(); if (!track->par) goto fail; track->par->codec_type = AVMEDIA_TYPE_DATA; track->par->codec_tag = track->tag; ret = ff_rtp_chain_mux_open(&track->rtp_ctx, s, src_st, NULL, RTP_MAX_PACKET_SIZE, src_index); if (ret < 0) goto fail; /* Copy the RTP AVStream timebase back to the hint AVStream */ track->timescale = track->rtp_ctx->streams[0]->time_base.den; /* Mark the hinted track that packets written to it should be * sent to this track for hinting. */ src_track->hint_track = index; return 0; fail: av_log(s, AV_LOG_WARNING, "Unable to initialize hinting of stream %d\n", src_index); avcodec_parameters_free(&track->par); /* Set a default timescale, to avoid crashes in av_dump_format */ track->timescale = 90000; return ret; }