struct MuxChain {
AVFormatContext *mpegts_ctx;
AVFormatContext *rtp_ctx;
+ AVPacket *pkt;
};
static int rtp_mpegts_write_close(AVFormatContext *s)
av_write_trailer(chain->rtp_ctx);
avformat_free_context(chain->rtp_ctx);
}
+
+ av_packet_free(&chain->pkt);
+
return 0;
}
{
struct MuxChain *chain = s->priv_data;
AVFormatContext *mpegts_ctx = NULL, *rtp_ctx = NULL;
- AVOutputFormat *mpegts_format = av_guess_format("mpegts", NULL, NULL);
- AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
+ ff_const59 AVOutputFormat *mpegts_format = av_guess_format("mpegts", NULL, NULL);
+ ff_const59 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
int i, ret = AVERROR(ENOMEM);
AVStream *st;
mpegts_ctx = avformat_alloc_context();
if (!mpegts_ctx)
return AVERROR(ENOMEM);
+ chain->pkt = av_packet_alloc();
+ if (!chain->pkt)
+ goto fail;
mpegts_ctx->oformat = mpegts_format;
mpegts_ctx->max_delay = s->max_delay;
+ av_dict_copy(&mpegts_ctx->metadata, s->metadata, 0);
for (i = 0; i < s->nb_streams; i++) {
AVStream* st = avformat_new_stream(mpegts_ctx, NULL);
if (!st)
fail:
if (mpegts_ctx) {
ffio_free_dyn_buf(&mpegts_ctx->pb);
+ av_dict_free(&mpegts_ctx->metadata);
avformat_free_context(mpegts_ctx);
}
- if (rtp_ctx)
- avformat_free_context(rtp_ctx);
+ avformat_free_context(rtp_ctx);
rtp_mpegts_write_close(s);
return ret;
}
struct MuxChain *chain = s->priv_data;
int ret = 0, size;
uint8_t *buf;
- AVPacket local_pkt;
+ AVPacket *local_pkt = chain->pkt;
if (!chain->mpegts_ctx->pb) {
if ((ret = avio_open_dyn_buf(&chain->mpegts_ctx->pb)) < 0)
av_free(buf);
return 0;
}
- av_init_packet(&local_pkt);
- local_pkt.data = buf;
- local_pkt.size = size;
- local_pkt.stream_index = 0;
+ av_packet_unref(local_pkt);
+ local_pkt->data = buf;
+ local_pkt->size = size;
+ local_pkt->stream_index = 0;
if (pkt->pts != AV_NOPTS_VALUE)
- local_pkt.pts = av_rescale_q(pkt->pts,
+ local_pkt->pts = av_rescale_q(pkt->pts,
s->streams[pkt->stream_index]->time_base,
chain->rtp_ctx->streams[0]->time_base);
if (pkt->dts != AV_NOPTS_VALUE)
- local_pkt.dts = av_rescale_q(pkt->dts,
+ local_pkt->dts = av_rescale_q(pkt->dts,
s->streams[pkt->stream_index]->time_base,
chain->rtp_ctx->streams[0]->time_base);
- ret = av_write_frame(chain->rtp_ctx, &local_pkt);
+ ret = av_write_frame(chain->rtp_ctx, local_pkt);
av_free(buf);
return ret;