FFmpegKit Android API 6.0
Loading...
Searching...
No Matches
fftools_ffmpeg_mux.h
Go to the documentation of this file.
1/*
2 * Muxer internal APIs - should not be included outside of ffmpeg_mux*
3 * Copyright (c) 2023 ARTHENICA LTD
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/*
23 * This file is the modified version of ffmpeg_mux.h file living in ffmpeg source code under the fftools folder. We
24 * manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
25 * by us to develop ffmpeg-kit library.
26 *
27 * ffmpeg-kit changes by ARTHENICA LTD
28 *
29 * 07.2023
30 * --------------------------------------------------------
31 * - FFmpeg 6.0 changes migrated
32 * - fftools header names updated
33 * - want_sdp made thread-local
34 * - EncStatsFile declaration migrated from ffmpeg_mux_init.c
35 * - WARN_MULTIPLE_OPT_USAGE, MATCH_PER_STREAM_OPT, MATCH_PER_TYPE_OPT, SPECIFIER_OPT_FMT declarations migrated from
36 * ffmpeg.h
37 * - ms_from_ost migrated to ffmpeg_mux.c
38 */
39
40#ifndef FFTOOLS_FFMPEG_MUX_H
41#define FFTOOLS_FFMPEG_MUX_H
42
43#include <stdatomic.h>
44#include <stdint.h>
45
47
48#include "libavformat/avformat.h"
49
50#include "libavcodec/packet.h"
51
52#include "libavutil/dict.h"
53#include "libavutil/fifo.h"
54#include "libavutil/thread.h"
55
56#define SPECIFIER_OPT_FMT_str "%s"
57#define SPECIFIER_OPT_FMT_i "%i"
58#define SPECIFIER_OPT_FMT_i64 "%"PRId64
59#define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
60#define SPECIFIER_OPT_FMT_f "%f"
61#define SPECIFIER_OPT_FMT_dbl "%lf"
62
63#define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
64{\
65 char namestr[128] = "";\
66 const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
67 for (int _i = 0; opt_name_##name[_i]; _i++)\
68 av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[_i], opt_name_##name[_i+1] ? (opt_name_##name[_i+2] ? ", " : " or ") : "");\
69 av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
70 namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
71}
72
73#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
74{\
75 int _ret, _matches = 0;\
76 SpecifierOpt *so;\
77 for (int _i = 0; _i < o->nb_ ## name; _i++) {\
78 char *spec = o->name[_i].specifier;\
79 if ((_ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
80 outvar = o->name[_i].u.type;\
81 so = &o->name[_i];\
82 _matches++;\
83 } else if (_ret < 0)\
84 exit_program(1);\
85 }\
86 if (_matches > 1)\
87 WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
88}
89
90#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
91{\
92 int i;\
93 for (i = 0; i < o->nb_ ## name; i++) {\
94 char *spec = o->name[i].specifier;\
95 if (!strcmp(spec, mediatype))\
96 outvar = o->name[i].u.type;\
97 }\
98}
99
100typedef struct MuxStream {
102
103 // name used for logging
104 char log_name[32];
105
106 /* the packets are buffered here until the muxer is ready to be initialized */
108
109 AVBSFContext *bsf_ctx;
110
112
113 int64_t max_frames;
114
115 /*
116 * The size of the AVPackets' buffers in queue.
117 * Updated when a packet is either pushed or pulled from the queue.
118 */
120
122
123 /* Threshold after which max_muxing_queue_size will be in effect */
125
126 /* dts of the last packet sent to the muxer, in the stream timebase
127 * used for making up missing dts values */
130
131typedef struct Muxer {
133
134 // name used for logging
135 char log_name[32];
136
137 AVFormatContext *fc;
138
139 pthread_t thread;
141
142 AVDictionary *opts;
143
145
146 /* filesize limit expressed in bytes */
148 atomic_int_least64_t last_filesize;
150
152 AVPacket *sq_pkt;
154
155typedef struct EncStatsFile {
156 char *path;
157 AVIOContext *io;
159
160/* whether we want to print an SDP, set in of_open() */
161extern __thread int want_sdp;
162
163int mux_check_init(Muxer *mux);
164
165#endif /* FFTOOLS_FFMPEG_MUX_H */
int mux_check_init(Muxer *mux)
__thread int want_sdp
AVIOContext * io
OutputStream ost
AVBSFContext * bsf_ctx
AVFifo * muxing_queue
size_t muxing_queue_data_size
size_t muxing_queue_data_threshold
AVDictionary * opts
OutputFile of
int thread_queue_size
atomic_int_least64_t last_filesize
AVPacket * sq_pkt
ThreadQueue * tq
char log_name[32]
SyncQueue * sq_mux
AVFormatContext * fc
pthread_t thread
int64_t limit_filesize