summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_mux.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-10-13 13:14:34 +0200
committerAnton Khirnov <anton@khirnov.net>2022-10-18 14:19:11 +0200
commit2266e0483470cb73147c36bf5ce044b9eef1e841 (patch)
tree0abd51e0937415e7e9cc75f72d34db7d1ad598c8 /fftools/ffmpeg_mux.c
parent709b47f8a4a92f79ccbc05487ccaebefb7c78049 (diff)
fftools/ffmpeg_mux: embed OutputStream in a MuxStream
This is now possible since OutputStream is a child of OutputFile and the code allocating it can access MuxStream. Avoids the overhead and extra complexity of allocating two objects instead of one. Similar to what was previously done for OutputFile/Muxer.
Diffstat (limited to 'fftools/ffmpeg_mux.c')
-rw-r--r--fftools/ffmpeg_mux.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 032b2ac34c..4ad69a149a 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -45,6 +45,11 @@ static Muxer *mux_from_of(OutputFile *of)
return (Muxer*)of;
}
+static MuxStream *ms_from_ost(OutputStream *ost)
+{
+ return (MuxStream*)ost;
+}
+
static int64_t filesize(AVIOContext *pb)
{
int64_t ret = -1;
@@ -60,7 +65,7 @@ static int64_t filesize(AVIOContext *pb)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
{
- MuxStream *ms = &mux->streams[ost->index];
+ MuxStream *ms = ms_from_ost(ost);
AVFormatContext *s = mux->fc;
AVStream *st = ost->st;
int64_t fs;
@@ -251,7 +256,7 @@ finish:
static int queue_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
{
- MuxStream *ms = &mux->streams[ost->index];
+ MuxStream *ms = ms_from_ost(ost);
AVPacket *tmp_pkt = NULL;
int ret;
@@ -409,8 +414,8 @@ static int thread_start(Muxer *mux)
/* flush the muxing queues */
for (int i = 0; i < fc->nb_streams; i++) {
- MuxStream *ms = &mux->streams[i];
OutputStream *ost = mux->of.streams[i];
+ MuxStream *ms = ms_from_ost(ost);
AVPacket *pkt;
/* try to improve muxing time_base (only possible if nothing has been written yet) */
@@ -626,9 +631,11 @@ int of_write_trailer(OutputFile *of)
static void ost_free(OutputStream **post)
{
OutputStream *ost = *post;
+ MuxStream *ms;
if (!ost)
return;
+ ms = ms_from_ost(ost);
if (ost->logfile) {
if (fclose(ost->logfile))
@@ -638,6 +645,13 @@ static void ost_free(OutputStream **post)
ost->logfile = NULL;
}
+ if (ms->muxing_queue) {
+ AVPacket *pkt;
+ while (av_fifo_read(ms->muxing_queue, &pkt, 1) >= 0)
+ av_packet_free(&pkt);
+ av_fifo_freep2(&ms->muxing_queue);
+ }
+
av_bsf_free(&ost->bsf_ctx);
av_frame_free(&ost->filtered_frame);
@@ -697,19 +711,6 @@ void of_close(OutputFile **pof)
sq_free(&of->sq_encode);
sq_free(&mux->sq_mux);
- for (int i = 0; i < mux->nb_streams; i++) {
- MuxStream *ms = &mux->streams[i];
- AVPacket *pkt;
-
- if (!ms->muxing_queue)
- continue;
-
- while (av_fifo_read(ms->muxing_queue, &pkt, 1) >= 0)
- av_packet_free(&pkt);
- av_fifo_freep2(&ms->muxing_queue);
- }
- av_freep(&mux->streams);
-
for (int i = 0; i < of->nb_streams; i++)
ost_free(&of->streams[i]);
av_freep(&of->streams);