bare-ffmpeg 1.0.0-2 → 1.0.0-21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +10 -3
- package/README.md +1097 -0
- package/binding.cc +3330 -0
- package/cmake/ports/ffmpeg/port.cmake +513 -0
- package/cmake/ports/opus/patches/01-windows-clang.patch +52 -0
- package/cmake/ports/opus/port.cmake +42 -0
- package/cmake/ports/svt-av1/port.cmake +42 -0
- package/cmake/ports/x264/patches/01-windows-clang.patch +33 -0
- package/cmake/ports/x264/port.cmake +157 -0
- package/index.js +14 -4
- package/lib/audio-fifo.js +47 -0
- package/lib/channel-layout.js +35 -0
- package/lib/codec-context.js +92 -15
- package/lib/codec-parameters.js +230 -8
- package/lib/codec.js +19 -0
- package/lib/constants.js +163 -8
- package/lib/dictionary.js +18 -15
- package/lib/errors.js +38 -0
- package/lib/format-context.js +62 -31
- package/lib/frame.js +87 -16
- package/lib/image.js +22 -0
- package/lib/input-format.js +8 -3
- package/lib/io-context.js +29 -6
- package/lib/log.js +16 -0
- package/lib/output-format.js +4 -0
- package/lib/packet.js +88 -13
- package/lib/rational.js +35 -1
- package/lib/resampler.js +63 -0
- package/lib/samples.js +49 -0
- package/lib/scaler.js +8 -7
- package/lib/stream.js +37 -12
- package/package.json +7 -4
- package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
- package/binding.c +0 -2128
- package/lib/reference-counted.js +0 -39
package/binding.cc
ADDED
|
@@ -0,0 +1,3330 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
#include <cstdint>
|
|
3
|
+
#include <stddef.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
#include <tuple>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
#include <bare.h>
|
|
10
|
+
#include <js.h>
|
|
11
|
+
#include <jstl.h>
|
|
12
|
+
|
|
13
|
+
extern "C" {
|
|
14
|
+
#include <libavcodec/avcodec.h>
|
|
15
|
+
#include <libavcodec/codec.h>
|
|
16
|
+
#include <libavcodec/codec_id.h>
|
|
17
|
+
#include <libavcodec/codec_par.h>
|
|
18
|
+
#include <libavcodec/packet.h>
|
|
19
|
+
#include <libavdevice/avdevice.h>
|
|
20
|
+
#include <libavformat/avformat.h>
|
|
21
|
+
#include <libavformat/avio.h>
|
|
22
|
+
#include <libavutil/audio_fifo.h>
|
|
23
|
+
#include <libavutil/channel_layout.h>
|
|
24
|
+
#include <libavutil/dict.h>
|
|
25
|
+
#include <libavutil/error.h>
|
|
26
|
+
#include <libavutil/frame.h>
|
|
27
|
+
#include <libavutil/imgutils.h>
|
|
28
|
+
#include <libavutil/log.h>
|
|
29
|
+
#include <libavutil/mem.h>
|
|
30
|
+
#include <libavutil/pixfmt.h>
|
|
31
|
+
#include <libavutil/rational.h>
|
|
32
|
+
#include <libavutil/samplefmt.h>
|
|
33
|
+
#include <libswresample/swresample.h>
|
|
34
|
+
#include <libswscale/swscale.h>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
using bare_ffmpeg_io_context_on_write_cb_t = js_function_t<void, js_arraybuffer_t>;
|
|
38
|
+
|
|
39
|
+
typedef struct {
|
|
40
|
+
AVIOContext *handle;
|
|
41
|
+
|
|
42
|
+
js_env_t *env;
|
|
43
|
+
js_persistent_t<bare_ffmpeg_io_context_on_write_cb_t> on_write;
|
|
44
|
+
} bare_ffmpeg_io_context_t;
|
|
45
|
+
|
|
46
|
+
typedef struct {
|
|
47
|
+
const AVOutputFormat *handle;
|
|
48
|
+
} bare_ffmpeg_output_format_t;
|
|
49
|
+
|
|
50
|
+
typedef struct {
|
|
51
|
+
const AVInputFormat *handle;
|
|
52
|
+
} bare_ffmpeg_input_format_t;
|
|
53
|
+
|
|
54
|
+
typedef struct {
|
|
55
|
+
AVFormatContext *handle;
|
|
56
|
+
} bare_ffmpeg_format_context_t;
|
|
57
|
+
|
|
58
|
+
typedef struct {
|
|
59
|
+
AVStream *handle;
|
|
60
|
+
} bare_ffmpeg_stream_t;
|
|
61
|
+
|
|
62
|
+
typedef struct {
|
|
63
|
+
const AVCodec *handle;
|
|
64
|
+
} bare_ffmpeg_codec_t;
|
|
65
|
+
|
|
66
|
+
typedef struct {
|
|
67
|
+
AVCodecParameters *handle;
|
|
68
|
+
} bare_ffmpeg_codec_parameters_t;
|
|
69
|
+
|
|
70
|
+
typedef struct {
|
|
71
|
+
AVCodecContext *handle;
|
|
72
|
+
} bare_ffmpeg_codec_context_t;
|
|
73
|
+
|
|
74
|
+
typedef struct {
|
|
75
|
+
AVChannelLayout handle;
|
|
76
|
+
} bare_ffmpeg_channel_layout_t;
|
|
77
|
+
|
|
78
|
+
typedef struct {
|
|
79
|
+
AVFrame *handle;
|
|
80
|
+
} bare_ffmpeg_frame_t;
|
|
81
|
+
|
|
82
|
+
typedef struct {
|
|
83
|
+
AVPacket *handle;
|
|
84
|
+
} bare_ffmpeg_packet_t;
|
|
85
|
+
|
|
86
|
+
typedef struct {
|
|
87
|
+
struct SwsContext *handle;
|
|
88
|
+
} bare_ffmpeg_scaler_t;
|
|
89
|
+
|
|
90
|
+
typedef struct {
|
|
91
|
+
struct AVDictionary *handle;
|
|
92
|
+
} bare_ffmpeg_dictionary_t;
|
|
93
|
+
|
|
94
|
+
typedef struct {
|
|
95
|
+
struct SwrContext *handle;
|
|
96
|
+
} bare_ffmpeg_resampler_t;
|
|
97
|
+
|
|
98
|
+
typedef struct {
|
|
99
|
+
AVAudioFifo *handle;
|
|
100
|
+
} bare_ffmpeg_audio_fifo_t;
|
|
101
|
+
|
|
102
|
+
static uv_once_t bare_ffmpeg__init_guard = UV_ONCE_INIT;
|
|
103
|
+
|
|
104
|
+
static inline bool
|
|
105
|
+
bad_timebase(const AVRational r) {
|
|
106
|
+
return r.den < 1 || // invalid denominator
|
|
107
|
+
av_q2d(r) == 0; // detect initial state: (0 / 1)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static void
|
|
111
|
+
bare_ffmpeg__on_init(void) {
|
|
112
|
+
av_log_set_level(AV_LOG_ERROR);
|
|
113
|
+
|
|
114
|
+
avdevice_register_all();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static int32_t
|
|
118
|
+
bare_ffmpeg_log_get_level(js_env_t *) {
|
|
119
|
+
return av_log_get_level();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static void
|
|
123
|
+
bare_ffmpeg_log_set_level(js_env_t *, int32_t level) {
|
|
124
|
+
av_log_set_level(level);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static int
|
|
128
|
+
io_context_write_packet(void *opaque, const uint8_t *chunk, int len) {
|
|
129
|
+
auto context = reinterpret_cast<bare_ffmpeg_io_context_t *>(opaque);
|
|
130
|
+
auto env = context->env;
|
|
131
|
+
|
|
132
|
+
bare_ffmpeg_io_context_on_write_cb_t callback;
|
|
133
|
+
|
|
134
|
+
int err = js_get_reference_value(env, context->on_write, callback);
|
|
135
|
+
assert(err == 0);
|
|
136
|
+
|
|
137
|
+
js_arraybuffer_t data;
|
|
138
|
+
err = js_create_arraybuffer(env, chunk, static_cast<size_t>(len), data);
|
|
139
|
+
|
|
140
|
+
assert(err == 0);
|
|
141
|
+
|
|
142
|
+
// TODO: running on js-stack during avformat_write_header()
|
|
143
|
+
// trace other invocations, pray singlethread.
|
|
144
|
+
err = js_call_function(env, callback, data);
|
|
145
|
+
return err;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static js_arraybuffer_t
|
|
149
|
+
bare_ffmpeg_io_context_init(
|
|
150
|
+
js_env_t *env,
|
|
151
|
+
js_receiver_t,
|
|
152
|
+
std::optional<js_arraybuffer_span_t> data,
|
|
153
|
+
uint64_t offset,
|
|
154
|
+
uint64_t len,
|
|
155
|
+
std::optional<bare_ffmpeg_io_context_on_write_cb_t> on_write
|
|
156
|
+
) {
|
|
157
|
+
int err;
|
|
158
|
+
|
|
159
|
+
js_arraybuffer_t handle;
|
|
160
|
+
|
|
161
|
+
bare_ffmpeg_io_context_t *context;
|
|
162
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
163
|
+
assert(err == 0);
|
|
164
|
+
|
|
165
|
+
context->env = env;
|
|
166
|
+
|
|
167
|
+
int write_flag = 0;
|
|
168
|
+
if (on_write) {
|
|
169
|
+
write_flag = 1;
|
|
170
|
+
err = js_create_reference(env, *on_write, context->on_write);
|
|
171
|
+
assert(err == 0);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
size_t size = static_cast<size_t>(len);
|
|
175
|
+
|
|
176
|
+
uint8_t *io = NULL;
|
|
177
|
+
|
|
178
|
+
if (size) {
|
|
179
|
+
io = reinterpret_cast<uint8_t *>(av_malloc(size));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (data) {
|
|
183
|
+
memcpy(io, &data.value()[static_cast<size_t>(offset)], size);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// TODO: for stream read support provide read/seek callbacks
|
|
187
|
+
|
|
188
|
+
context->handle = avio_alloc_context(
|
|
189
|
+
io,
|
|
190
|
+
static_cast<int>(len),
|
|
191
|
+
write_flag,
|
|
192
|
+
context,
|
|
193
|
+
NULL, // io_context_read_packet
|
|
194
|
+
io_context_write_packet,
|
|
195
|
+
NULL // io_context_seek
|
|
196
|
+
);
|
|
197
|
+
assert(context->handle->opaque == context);
|
|
198
|
+
|
|
199
|
+
return handle;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
static void
|
|
203
|
+
bare_ffmpeg_io_context_destroy(
|
|
204
|
+
js_env_t *env,
|
|
205
|
+
js_receiver_t,
|
|
206
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_io_context_t, 1> context
|
|
207
|
+
) {
|
|
208
|
+
av_free(context->handle->buffer);
|
|
209
|
+
|
|
210
|
+
avio_context_free(&context->handle);
|
|
211
|
+
context->on_write.reset();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static js_arraybuffer_t
|
|
215
|
+
bare_ffmpeg_output_format_init(js_env_t *env, js_receiver_t, std::string name) {
|
|
216
|
+
int err;
|
|
217
|
+
|
|
218
|
+
const AVOutputFormat *format = av_guess_format(name.c_str(), NULL, NULL);
|
|
219
|
+
|
|
220
|
+
if (format == NULL) {
|
|
221
|
+
err = js_throw_errorf(env, NULL, "No output format found for name '%s'", name.c_str());
|
|
222
|
+
assert(err == 0);
|
|
223
|
+
|
|
224
|
+
throw js_pending_exception;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
js_arraybuffer_t handle;
|
|
228
|
+
|
|
229
|
+
bare_ffmpeg_output_format_t *context;
|
|
230
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
231
|
+
assert(err == 0);
|
|
232
|
+
|
|
233
|
+
context->handle = format;
|
|
234
|
+
|
|
235
|
+
return handle;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static int32_t
|
|
239
|
+
bare_ffmpeg_output_format_get_flags(
|
|
240
|
+
js_env_t *,
|
|
241
|
+
js_receiver_t,
|
|
242
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_output_format_t, 1> format
|
|
243
|
+
) {
|
|
244
|
+
return format->handle->flags;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static js_arraybuffer_t
|
|
248
|
+
bare_ffmpeg_input_format_init(js_env_t *env, js_receiver_t, std::string name) {
|
|
249
|
+
int err;
|
|
250
|
+
|
|
251
|
+
const AVInputFormat *format = av_find_input_format(name.c_str());
|
|
252
|
+
|
|
253
|
+
if (format == NULL) {
|
|
254
|
+
err = js_throw_errorf(env, NULL, "No input format found for name '%s'", name.c_str());
|
|
255
|
+
assert(err == 0);
|
|
256
|
+
|
|
257
|
+
throw js_pending_exception;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
js_arraybuffer_t handle;
|
|
261
|
+
|
|
262
|
+
bare_ffmpeg_input_format_t *context;
|
|
263
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
264
|
+
assert(err == 0);
|
|
265
|
+
|
|
266
|
+
context->handle = format;
|
|
267
|
+
|
|
268
|
+
return handle;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
static int32_t
|
|
272
|
+
bare_ffmpeg_input_format_get_flags(
|
|
273
|
+
js_env_t *,
|
|
274
|
+
js_receiver_t,
|
|
275
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_input_format_t, 1> format
|
|
276
|
+
) {
|
|
277
|
+
return format->handle->flags;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static js_arraybuffer_t
|
|
281
|
+
bare_ffmpeg_format_context_open_input_with_io(
|
|
282
|
+
js_env_t *env,
|
|
283
|
+
js_receiver_t,
|
|
284
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_io_context_t, 1> io
|
|
285
|
+
) {
|
|
286
|
+
int err;
|
|
287
|
+
|
|
288
|
+
js_arraybuffer_t handle;
|
|
289
|
+
|
|
290
|
+
bare_ffmpeg_format_context_t *context;
|
|
291
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
292
|
+
assert(err == 0);
|
|
293
|
+
|
|
294
|
+
context->handle = avformat_alloc_context();
|
|
295
|
+
context->handle->pb = io->handle;
|
|
296
|
+
context->handle->opaque = (void *) context;
|
|
297
|
+
|
|
298
|
+
err = avformat_open_input(&context->handle, NULL, NULL, NULL);
|
|
299
|
+
if (err < 0) {
|
|
300
|
+
avformat_free_context(context->handle);
|
|
301
|
+
|
|
302
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
303
|
+
assert(err == 0);
|
|
304
|
+
|
|
305
|
+
throw js_pending_exception;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
err = avformat_find_stream_info(context->handle, NULL);
|
|
309
|
+
if (err < 0) {
|
|
310
|
+
avformat_close_input(&context->handle);
|
|
311
|
+
|
|
312
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
313
|
+
assert(err == 0);
|
|
314
|
+
|
|
315
|
+
throw js_pending_exception;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return handle;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
static js_arraybuffer_t
|
|
322
|
+
bare_ffmpeg_format_context_open_input_with_format(
|
|
323
|
+
js_env_t *env,
|
|
324
|
+
js_receiver_t,
|
|
325
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_input_format_t, 1> format,
|
|
326
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1> options,
|
|
327
|
+
std::string url
|
|
328
|
+
) {
|
|
329
|
+
int err;
|
|
330
|
+
|
|
331
|
+
js_arraybuffer_t handle;
|
|
332
|
+
|
|
333
|
+
bare_ffmpeg_format_context_t *context;
|
|
334
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
335
|
+
assert(err == 0);
|
|
336
|
+
|
|
337
|
+
context->handle = avformat_alloc_context();
|
|
338
|
+
context->handle->opaque = (void *) context;
|
|
339
|
+
|
|
340
|
+
err = avformat_open_input(&context->handle, url.c_str(), format->handle, &options->handle);
|
|
341
|
+
if (err < 0) {
|
|
342
|
+
avformat_free_context(context->handle);
|
|
343
|
+
|
|
344
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
345
|
+
assert(err == 0);
|
|
346
|
+
|
|
347
|
+
throw js_pending_exception;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
err = avformat_find_stream_info(context->handle, NULL);
|
|
351
|
+
if (err < 0) {
|
|
352
|
+
avformat_close_input(&context->handle);
|
|
353
|
+
|
|
354
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
355
|
+
assert(err == 0);
|
|
356
|
+
|
|
357
|
+
throw js_pending_exception;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return handle;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
static void
|
|
364
|
+
bare_ffmpeg_format_context_close_input(
|
|
365
|
+
js_env_t *env,
|
|
366
|
+
js_receiver_t,
|
|
367
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
368
|
+
) {
|
|
369
|
+
avformat_close_input(&context->handle);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
static js_arraybuffer_t
|
|
373
|
+
bare_ffmpeg_format_context_open_output(
|
|
374
|
+
js_env_t *env,
|
|
375
|
+
js_receiver_t,
|
|
376
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_output_format_t, 1> format,
|
|
377
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_io_context_t, 1> io
|
|
378
|
+
) {
|
|
379
|
+
int err;
|
|
380
|
+
|
|
381
|
+
js_arraybuffer_t handle;
|
|
382
|
+
|
|
383
|
+
bare_ffmpeg_format_context_t *context;
|
|
384
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
385
|
+
assert(err == 0);
|
|
386
|
+
|
|
387
|
+
err = avformat_alloc_output_context2(&context->handle, format->handle, NULL, NULL);
|
|
388
|
+
if (err < 0) {
|
|
389
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
390
|
+
assert(err == 0);
|
|
391
|
+
|
|
392
|
+
throw js_pending_exception;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
context->handle->pb = io->handle;
|
|
396
|
+
context->handle->opaque = (void *) context;
|
|
397
|
+
|
|
398
|
+
return handle;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
static void
|
|
402
|
+
bare_ffmpeg_format_context_close_output(
|
|
403
|
+
js_env_t *env,
|
|
404
|
+
js_receiver_t,
|
|
405
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
406
|
+
) {
|
|
407
|
+
avformat_free_context(context->handle);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
static js_array_t
|
|
411
|
+
bare_ffmpeg_format_context_get_streams(
|
|
412
|
+
js_env_t *env,
|
|
413
|
+
js_receiver_t,
|
|
414
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
415
|
+
) {
|
|
416
|
+
int err;
|
|
417
|
+
|
|
418
|
+
uint32_t len = context->handle->nb_streams;
|
|
419
|
+
|
|
420
|
+
js_array_t result;
|
|
421
|
+
err = js_create_array(env, len, result);
|
|
422
|
+
assert(err == 0);
|
|
423
|
+
|
|
424
|
+
for (uint32_t i = 0; i < len; i++) {
|
|
425
|
+
js_arraybuffer_t handle;
|
|
426
|
+
|
|
427
|
+
bare_ffmpeg_stream_t *stream;
|
|
428
|
+
err = js_create_arraybuffer(env, stream, handle);
|
|
429
|
+
assert(err == 0);
|
|
430
|
+
|
|
431
|
+
stream->handle = context->handle->streams[i];
|
|
432
|
+
|
|
433
|
+
err = js_set_element(env, result, i, handle);
|
|
434
|
+
assert(err == 0);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return result;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
static int
|
|
441
|
+
bare_ffmpeg_format_context_get_best_stream_index(
|
|
442
|
+
js_env_t *env,
|
|
443
|
+
js_receiver_t,
|
|
444
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
445
|
+
int32_t type
|
|
446
|
+
) {
|
|
447
|
+
auto i = av_find_best_stream(context->handle, static_cast<AVMediaType>(type), -1, -1, NULL, 0);
|
|
448
|
+
|
|
449
|
+
if (i < 0) i = -1;
|
|
450
|
+
|
|
451
|
+
return i;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
static js_arraybuffer_t
|
|
455
|
+
bare_ffmpeg_format_context_create_stream(
|
|
456
|
+
js_env_t *env,
|
|
457
|
+
js_receiver_t,
|
|
458
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
459
|
+
) {
|
|
460
|
+
int err;
|
|
461
|
+
|
|
462
|
+
js_arraybuffer_t handle;
|
|
463
|
+
|
|
464
|
+
bare_ffmpeg_stream_t *stream;
|
|
465
|
+
err = js_create_arraybuffer(env, stream, handle);
|
|
466
|
+
assert(err == 0);
|
|
467
|
+
|
|
468
|
+
stream->handle = avformat_new_stream(context->handle, NULL);
|
|
469
|
+
|
|
470
|
+
return handle;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
static bool
|
|
474
|
+
bare_ffmpeg_format_context_read_frame(
|
|
475
|
+
js_env_t *env,
|
|
476
|
+
js_receiver_t,
|
|
477
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
478
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
479
|
+
) {
|
|
480
|
+
int err;
|
|
481
|
+
|
|
482
|
+
av_packet_unref(packet->handle);
|
|
483
|
+
|
|
484
|
+
err = av_read_frame(context->handle, packet->handle);
|
|
485
|
+
if (err < 0 && err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
|
|
486
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
487
|
+
assert(err == 0);
|
|
488
|
+
|
|
489
|
+
throw js_pending_exception;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return err == 0;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
static bool
|
|
496
|
+
bare_ffmpeg_format_context_write_header(
|
|
497
|
+
js_env_t *env,
|
|
498
|
+
js_receiver_t,
|
|
499
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
500
|
+
std::optional<js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1>> muxer_options
|
|
501
|
+
) {
|
|
502
|
+
int err;
|
|
503
|
+
|
|
504
|
+
if (!muxer_options) {
|
|
505
|
+
err = avformat_write_header(context->handle, NULL);
|
|
506
|
+
} else {
|
|
507
|
+
auto dict = *muxer_options;
|
|
508
|
+
err = avformat_write_header(context->handle, &dict->handle);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (err < 0) {
|
|
512
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
513
|
+
assert(err == 0);
|
|
514
|
+
|
|
515
|
+
throw js_pending_exception;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return err;
|
|
519
|
+
}
|
|
520
|
+
static void
|
|
521
|
+
bare_ffmpeg_format_context_write_frame(
|
|
522
|
+
js_env_t *env,
|
|
523
|
+
js_receiver_t,
|
|
524
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
525
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
526
|
+
) {
|
|
527
|
+
int err = av_interleaved_write_frame(context->handle, packet->handle);
|
|
528
|
+
|
|
529
|
+
if (err < 0) {
|
|
530
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
531
|
+
assert(err == 0);
|
|
532
|
+
|
|
533
|
+
throw js_pending_exception;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
static void
|
|
538
|
+
bare_ffmpeg_format_context_write_trailer(
|
|
539
|
+
js_env_t *env,
|
|
540
|
+
js_receiver_t,
|
|
541
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
542
|
+
) {
|
|
543
|
+
int err = av_write_trailer(context->handle);
|
|
544
|
+
if (err < 0) {
|
|
545
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
546
|
+
assert(err == 0);
|
|
547
|
+
|
|
548
|
+
throw js_pending_exception;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
static void
|
|
553
|
+
bare_ffmpeg_format_context_dump(
|
|
554
|
+
js_env_t *env,
|
|
555
|
+
js_receiver_t,
|
|
556
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
557
|
+
bool is_output,
|
|
558
|
+
int32_t index,
|
|
559
|
+
std::string url
|
|
560
|
+
) {
|
|
561
|
+
av_dump_format(context->handle, index, url.c_str(), is_output);
|
|
562
|
+
|
|
563
|
+
for (int i = 0; i < context->handle->nb_streams; i++) {
|
|
564
|
+
auto stream = context->handle->streams[i];
|
|
565
|
+
av_log(NULL, AV_LOG_INFO, " - stream=%i timebase=(%i / %i)\n", i, stream->time_base.num, stream->time_base.den);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
static int32_t
|
|
570
|
+
bare_ffmpeg_stream_get_index(
|
|
571
|
+
js_env_t *env,
|
|
572
|
+
js_receiver_t,
|
|
573
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
574
|
+
) {
|
|
575
|
+
return stream->handle->index;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
static int32_t
|
|
579
|
+
bare_ffmpeg_stream_get_id(
|
|
580
|
+
js_env_t *env,
|
|
581
|
+
js_receiver_t,
|
|
582
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
583
|
+
) {
|
|
584
|
+
return stream->handle->id;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
static void
|
|
588
|
+
bare_ffmpeg_stream_set_id(
|
|
589
|
+
js_env_t *env,
|
|
590
|
+
js_receiver_t,
|
|
591
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream,
|
|
592
|
+
int32_t id
|
|
593
|
+
) {
|
|
594
|
+
stream->handle->id = id;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
static js_arraybuffer_t
|
|
598
|
+
bare_ffmpeg_stream_get_time_base(
|
|
599
|
+
js_env_t *env,
|
|
600
|
+
js_receiver_t,
|
|
601
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
602
|
+
) {
|
|
603
|
+
int err;
|
|
604
|
+
|
|
605
|
+
js_arraybuffer_t result;
|
|
606
|
+
|
|
607
|
+
int32_t *data;
|
|
608
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
609
|
+
assert(err == 0);
|
|
610
|
+
|
|
611
|
+
data[0] = stream->handle->time_base.num;
|
|
612
|
+
data[1] = stream->handle->time_base.den;
|
|
613
|
+
|
|
614
|
+
return result;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
static void
|
|
618
|
+
bare_ffmpeg_stream_set_time_base(
|
|
619
|
+
js_env_t *env,
|
|
620
|
+
js_receiver_t,
|
|
621
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream,
|
|
622
|
+
int num,
|
|
623
|
+
int den
|
|
624
|
+
) {
|
|
625
|
+
stream->handle->time_base.num = num;
|
|
626
|
+
stream->handle->time_base.den = den;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
static js_arraybuffer_t
|
|
630
|
+
bare_ffmpeg_stream_get_avg_framerate(
|
|
631
|
+
js_env_t *env,
|
|
632
|
+
js_receiver_t,
|
|
633
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
634
|
+
) {
|
|
635
|
+
int err;
|
|
636
|
+
|
|
637
|
+
js_arraybuffer_t result;
|
|
638
|
+
|
|
639
|
+
int32_t *data;
|
|
640
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
641
|
+
assert(err == 0);
|
|
642
|
+
|
|
643
|
+
data[0] = stream->handle->avg_frame_rate.num;
|
|
644
|
+
data[1] = stream->handle->avg_frame_rate.den;
|
|
645
|
+
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
static void
|
|
650
|
+
bare_ffmpeg_stream_set_avg_framerate(
|
|
651
|
+
js_env_t *env,
|
|
652
|
+
js_receiver_t,
|
|
653
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream,
|
|
654
|
+
int num,
|
|
655
|
+
int den
|
|
656
|
+
) {
|
|
657
|
+
stream->handle->avg_frame_rate.num = num;
|
|
658
|
+
stream->handle->avg_frame_rate.den = den;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
static js_arraybuffer_t
|
|
662
|
+
bare_ffmpeg_stream_get_codec_parameters(
|
|
663
|
+
js_env_t *env,
|
|
664
|
+
js_receiver_t,
|
|
665
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
666
|
+
) {
|
|
667
|
+
int err;
|
|
668
|
+
|
|
669
|
+
js_arraybuffer_t handle;
|
|
670
|
+
|
|
671
|
+
bare_ffmpeg_codec_parameters_t *parameters;
|
|
672
|
+
err = js_create_arraybuffer(env, parameters, handle);
|
|
673
|
+
assert(err == 0);
|
|
674
|
+
|
|
675
|
+
parameters->handle = stream->handle->codecpar;
|
|
676
|
+
|
|
677
|
+
return handle;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
static js_arraybuffer_t
|
|
681
|
+
bare_ffmpeg_find_decoder_by_id(js_env_t *env, js_receiver_t, uint32_t id) {
|
|
682
|
+
int err;
|
|
683
|
+
|
|
684
|
+
const AVCodec *decoder = avcodec_find_decoder((enum AVCodecID) id);
|
|
685
|
+
|
|
686
|
+
if (decoder == NULL) {
|
|
687
|
+
err = js_throw_errorf(env, NULL, "No decoder found for codec '%d'", id);
|
|
688
|
+
assert(err == 0);
|
|
689
|
+
|
|
690
|
+
throw js_pending_exception;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
js_arraybuffer_t handle;
|
|
694
|
+
|
|
695
|
+
bare_ffmpeg_codec_t *context;
|
|
696
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
697
|
+
assert(err == 0);
|
|
698
|
+
|
|
699
|
+
context->handle = decoder;
|
|
700
|
+
|
|
701
|
+
return handle;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
static js_arraybuffer_t
|
|
705
|
+
bare_ffmpeg_find_encoder_by_id(js_env_t *env, js_receiver_t, uint32_t id) {
|
|
706
|
+
int err;
|
|
707
|
+
|
|
708
|
+
const AVCodec *encoder = avcodec_find_encoder((enum AVCodecID) id);
|
|
709
|
+
|
|
710
|
+
if (encoder == NULL) {
|
|
711
|
+
err = js_throw_errorf(env, NULL, "No encoder found for codec '%d'", id);
|
|
712
|
+
assert(err == 0);
|
|
713
|
+
|
|
714
|
+
throw js_pending_exception;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
js_arraybuffer_t handle;
|
|
718
|
+
|
|
719
|
+
bare_ffmpeg_codec_t *context;
|
|
720
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
721
|
+
assert(err == 0);
|
|
722
|
+
|
|
723
|
+
context->handle = encoder;
|
|
724
|
+
|
|
725
|
+
return handle;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
static std::string
|
|
729
|
+
bare_ffmpeg_get_codec_name_by_id(js_env_t *env, js_receiver_t, uint32_t id) {
|
|
730
|
+
auto name = avcodec_get_name((enum AVCodecID) id);
|
|
731
|
+
|
|
732
|
+
return std::string(name);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
static js_arraybuffer_t
|
|
736
|
+
bare_ffmpeg_codec_context_init(
|
|
737
|
+
js_env_t *env,
|
|
738
|
+
js_receiver_t,
|
|
739
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_t, 1> codec
|
|
740
|
+
) {
|
|
741
|
+
int err;
|
|
742
|
+
|
|
743
|
+
js_arraybuffer_t handle;
|
|
744
|
+
|
|
745
|
+
bare_ffmpeg_codec_context_t *context;
|
|
746
|
+
err = js_create_arraybuffer(env, context, handle);
|
|
747
|
+
assert(err == 0);
|
|
748
|
+
|
|
749
|
+
context->handle = avcodec_alloc_context3(codec->handle);
|
|
750
|
+
context->handle->opaque = (void *) context;
|
|
751
|
+
|
|
752
|
+
return handle;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
static void
|
|
756
|
+
bare_ffmpeg_codec_context_destroy(
|
|
757
|
+
js_env_t *env,
|
|
758
|
+
js_receiver_t,
|
|
759
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
760
|
+
) {
|
|
761
|
+
avcodec_free_context(&context->handle);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
static bool
|
|
765
|
+
bare_ffmpeg_codec_context_open(
|
|
766
|
+
js_env_t *env,
|
|
767
|
+
js_receiver_t,
|
|
768
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
769
|
+
) {
|
|
770
|
+
int err;
|
|
771
|
+
|
|
772
|
+
err = avcodec_open2(context->handle, context->handle->codec, NULL);
|
|
773
|
+
|
|
774
|
+
if (err < 0) {
|
|
775
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
776
|
+
assert(err == 0);
|
|
777
|
+
|
|
778
|
+
throw js_pending_exception;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return err == 0;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
static int32_t
|
|
785
|
+
bare_ffmpeg_codec_context_get_flags(
|
|
786
|
+
js_env_t *env,
|
|
787
|
+
js_receiver_t,
|
|
788
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
789
|
+
) {
|
|
790
|
+
return context->handle->flags;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
static void
|
|
794
|
+
bare_ffmpeg_codec_context_set_flags(
|
|
795
|
+
js_env_t *env,
|
|
796
|
+
js_receiver_t,
|
|
797
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
798
|
+
int32_t value
|
|
799
|
+
) {
|
|
800
|
+
context->handle->flags = value;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
static int64_t
|
|
804
|
+
bare_ffmpeg_frame_get_format(
|
|
805
|
+
js_env_t *env,
|
|
806
|
+
js_receiver_t,
|
|
807
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
808
|
+
) {
|
|
809
|
+
return frame->handle->format;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
static void
|
|
813
|
+
bare_ffmpeg_frame_set_format(
|
|
814
|
+
js_env_t *env,
|
|
815
|
+
js_receiver_t,
|
|
816
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
817
|
+
int format
|
|
818
|
+
) {
|
|
819
|
+
frame->handle->format = format;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
static js_arraybuffer_t
|
|
823
|
+
bare_ffmpeg_frame_get_channel_layout(
|
|
824
|
+
js_env_t *env,
|
|
825
|
+
js_receiver_t,
|
|
826
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
827
|
+
) {
|
|
828
|
+
int err;
|
|
829
|
+
|
|
830
|
+
js_arraybuffer_t result;
|
|
831
|
+
|
|
832
|
+
bare_ffmpeg_channel_layout_t *layout;
|
|
833
|
+
err = js_create_arraybuffer(env, layout, result);
|
|
834
|
+
assert(err == 0);
|
|
835
|
+
|
|
836
|
+
err = av_channel_layout_copy(&layout->handle, &frame->handle->ch_layout);
|
|
837
|
+
assert(err == 0);
|
|
838
|
+
|
|
839
|
+
return result;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
static void
|
|
843
|
+
bare_ffmpeg_frame_set_channel_layout(
|
|
844
|
+
js_env_t *env,
|
|
845
|
+
js_receiver_t,
|
|
846
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
847
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
848
|
+
) {
|
|
849
|
+
int err;
|
|
850
|
+
|
|
851
|
+
err = av_channel_layout_copy(&frame->handle->ch_layout, &layout->handle);
|
|
852
|
+
assert(err == 0);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
static bool
|
|
856
|
+
bare_ffmpeg_codec_context_open_with_options(
|
|
857
|
+
js_env_t *env,
|
|
858
|
+
js_receiver_t,
|
|
859
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
860
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1> options
|
|
861
|
+
) {
|
|
862
|
+
int err;
|
|
863
|
+
|
|
864
|
+
err = avcodec_open2(context->handle, context->handle->codec, &options->handle);
|
|
865
|
+
if (err < 0) {
|
|
866
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
867
|
+
assert(err == 0);
|
|
868
|
+
|
|
869
|
+
throw js_pending_exception;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
return err == 0;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
static int64_t
|
|
876
|
+
bare_ffmpeg_codec_context_get_pixel_format(
|
|
877
|
+
js_env_t *env,
|
|
878
|
+
js_receiver_t,
|
|
879
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
880
|
+
) {
|
|
881
|
+
return context->handle->pix_fmt;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
static void
|
|
885
|
+
bare_ffmpeg_codec_context_set_pixel_format(
|
|
886
|
+
js_env_t *env,
|
|
887
|
+
js_receiver_t,
|
|
888
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
889
|
+
int32_t value
|
|
890
|
+
) {
|
|
891
|
+
context->handle->pix_fmt = static_cast<AVPixelFormat>(value);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
static int64_t
|
|
895
|
+
bare_ffmpeg_codec_context_get_width(
|
|
896
|
+
js_env_t *env,
|
|
897
|
+
js_receiver_t,
|
|
898
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
899
|
+
) {
|
|
900
|
+
return context->handle->width;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
static void
|
|
904
|
+
bare_ffmpeg_codec_context_set_width(
|
|
905
|
+
js_env_t *env,
|
|
906
|
+
js_receiver_t,
|
|
907
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
908
|
+
int value
|
|
909
|
+
) {
|
|
910
|
+
context->handle->width = value;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
static int64_t
|
|
914
|
+
bare_ffmpeg_codec_context_get_height(
|
|
915
|
+
js_env_t *env,
|
|
916
|
+
js_receiver_t,
|
|
917
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
918
|
+
) {
|
|
919
|
+
return context->handle->height;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
static void
|
|
923
|
+
bare_ffmpeg_codec_context_set_height(
|
|
924
|
+
js_env_t *env,
|
|
925
|
+
js_receiver_t,
|
|
926
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
927
|
+
int value
|
|
928
|
+
) {
|
|
929
|
+
context->handle->height = value;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
static int64_t
|
|
933
|
+
bare_ffmpeg_codec_context_get_sample_format(
|
|
934
|
+
js_env_t *env,
|
|
935
|
+
js_receiver_t,
|
|
936
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
937
|
+
) {
|
|
938
|
+
return context->handle->sample_fmt;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
static void
|
|
942
|
+
bare_ffmpeg_codec_context_set_sample_format(
|
|
943
|
+
js_env_t *env,
|
|
944
|
+
js_receiver_t,
|
|
945
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
946
|
+
int32_t value
|
|
947
|
+
) {
|
|
948
|
+
context->handle->sample_fmt = static_cast<AVSampleFormat>(value);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
static js_arraybuffer_t
|
|
952
|
+
bare_ffmpeg_codec_context_get_time_base(
|
|
953
|
+
js_env_t *env,
|
|
954
|
+
js_receiver_t,
|
|
955
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
956
|
+
) {
|
|
957
|
+
int err;
|
|
958
|
+
|
|
959
|
+
js_arraybuffer_t result;
|
|
960
|
+
|
|
961
|
+
int32_t *data;
|
|
962
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
963
|
+
assert(err == 0);
|
|
964
|
+
|
|
965
|
+
data[0] = context->handle->time_base.num;
|
|
966
|
+
data[1] = context->handle->time_base.den;
|
|
967
|
+
|
|
968
|
+
return result;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
static void
|
|
972
|
+
bare_ffmpeg_codec_context_set_time_base(
|
|
973
|
+
js_env_t *env,
|
|
974
|
+
js_receiver_t,
|
|
975
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
976
|
+
int num,
|
|
977
|
+
int den
|
|
978
|
+
) {
|
|
979
|
+
context->handle->time_base.num = num;
|
|
980
|
+
context->handle->time_base.den = den;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
static js_arraybuffer_t
|
|
984
|
+
bare_ffmpeg_codec_context_get_channel_layout(
|
|
985
|
+
js_env_t *env,
|
|
986
|
+
js_receiver_t,
|
|
987
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
988
|
+
) {
|
|
989
|
+
int err;
|
|
990
|
+
|
|
991
|
+
js_arraybuffer_t result;
|
|
992
|
+
|
|
993
|
+
bare_ffmpeg_channel_layout_t *layout;
|
|
994
|
+
err = js_create_arraybuffer(env, layout, result);
|
|
995
|
+
assert(err == 0);
|
|
996
|
+
|
|
997
|
+
err = av_channel_layout_copy(&layout->handle, &context->handle->ch_layout);
|
|
998
|
+
assert(err == 0);
|
|
999
|
+
|
|
1000
|
+
return result;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
static void
|
|
1004
|
+
bare_ffmpeg_codec_context_set_channel_layout(
|
|
1005
|
+
js_env_t *env,
|
|
1006
|
+
js_receiver_t,
|
|
1007
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1008
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
1009
|
+
) {
|
|
1010
|
+
int err;
|
|
1011
|
+
|
|
1012
|
+
err = av_channel_layout_copy(&context->handle->ch_layout, &layout->handle);
|
|
1013
|
+
assert(err == 0);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
static int
|
|
1017
|
+
bare_ffmpeg_codec_context_get_sample_rate(
|
|
1018
|
+
js_env_t *env,
|
|
1019
|
+
js_receiver_t,
|
|
1020
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
1021
|
+
) {
|
|
1022
|
+
return context->handle->sample_rate;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
static void
|
|
1026
|
+
bare_ffmpeg_codec_context_set_sample_rate(
|
|
1027
|
+
js_env_t *env,
|
|
1028
|
+
js_receiver_t,
|
|
1029
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1030
|
+
int32_t sample_rate
|
|
1031
|
+
) {
|
|
1032
|
+
context->handle->sample_rate = sample_rate;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
static int
|
|
1036
|
+
bare_ffmpeg_codec_context_get_gop_size(
|
|
1037
|
+
js_env_t *env,
|
|
1038
|
+
js_receiver_t,
|
|
1039
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
1040
|
+
) {
|
|
1041
|
+
return context->handle->gop_size;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
static void
|
|
1045
|
+
bare_ffmpeg_codec_context_set_gop_size(
|
|
1046
|
+
js_env_t *env,
|
|
1047
|
+
js_receiver_t,
|
|
1048
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1049
|
+
int32_t gop_size
|
|
1050
|
+
) {
|
|
1051
|
+
context->handle->gop_size = gop_size;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
static js_arraybuffer_t
|
|
1055
|
+
bare_ffmpeg_codec_context_get_framerate(
|
|
1056
|
+
js_env_t *env,
|
|
1057
|
+
js_receiver_t,
|
|
1058
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
1059
|
+
) {
|
|
1060
|
+
int err;
|
|
1061
|
+
|
|
1062
|
+
js_arraybuffer_t result;
|
|
1063
|
+
|
|
1064
|
+
int32_t *data;
|
|
1065
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1066
|
+
assert(err == 0);
|
|
1067
|
+
|
|
1068
|
+
data[0] = context->handle->framerate.num;
|
|
1069
|
+
data[1] = context->handle->framerate.den;
|
|
1070
|
+
|
|
1071
|
+
return result;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
static void
|
|
1075
|
+
bare_ffmpeg_codec_context_set_framerate(
|
|
1076
|
+
js_env_t *env,
|
|
1077
|
+
js_receiver_t,
|
|
1078
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1079
|
+
int num,
|
|
1080
|
+
int den
|
|
1081
|
+
) {
|
|
1082
|
+
context->handle->framerate.num = num;
|
|
1083
|
+
context->handle->framerate.den = den;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
static bool
|
|
1087
|
+
bare_ffmpeg_codec_context_send_packet(
|
|
1088
|
+
js_env_t *env,
|
|
1089
|
+
js_receiver_t,
|
|
1090
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1091
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1092
|
+
) {
|
|
1093
|
+
int err;
|
|
1094
|
+
|
|
1095
|
+
err = avcodec_send_packet(context->handle, packet->handle);
|
|
1096
|
+
if (err < 0 && err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
|
|
1097
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1098
|
+
assert(err == 0);
|
|
1099
|
+
|
|
1100
|
+
throw js_pending_exception;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
return err == 0;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
static bool
|
|
1107
|
+
bare_ffmpeg_codec_context_receive_packet(
|
|
1108
|
+
js_env_t *env,
|
|
1109
|
+
js_receiver_t,
|
|
1110
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1111
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1112
|
+
) {
|
|
1113
|
+
int err;
|
|
1114
|
+
|
|
1115
|
+
err = avcodec_receive_packet(context->handle, packet->handle);
|
|
1116
|
+
if (err < 0 && err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
|
|
1117
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1118
|
+
assert(err == 0);
|
|
1119
|
+
|
|
1120
|
+
throw js_pending_exception;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
return err == 0;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
static bool
|
|
1127
|
+
bare_ffmpeg_codec_context_send_frame(
|
|
1128
|
+
js_env_t *env,
|
|
1129
|
+
js_receiver_t,
|
|
1130
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1131
|
+
std::optional<js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1>> frame
|
|
1132
|
+
) {
|
|
1133
|
+
int err;
|
|
1134
|
+
|
|
1135
|
+
if (frame) {
|
|
1136
|
+
err = avcodec_send_frame(context->handle, (*frame)->handle);
|
|
1137
|
+
} else {
|
|
1138
|
+
err = avcodec_send_frame(context->handle, NULL); // End of stream
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
if (err < 0 && err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
|
|
1142
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1143
|
+
assert(err == 0);
|
|
1144
|
+
|
|
1145
|
+
throw js_pending_exception;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
return err == 0;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
static bool
|
|
1152
|
+
bare_ffmpeg_codec_context_receive_frame(
|
|
1153
|
+
js_env_t *env,
|
|
1154
|
+
js_receiver_t,
|
|
1155
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1156
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1157
|
+
) {
|
|
1158
|
+
int err;
|
|
1159
|
+
|
|
1160
|
+
err = avcodec_receive_frame(context->handle, frame->handle);
|
|
1161
|
+
if (err < 0 && err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
|
|
1162
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1163
|
+
assert(err == 0);
|
|
1164
|
+
|
|
1165
|
+
throw js_pending_exception;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
return err == 0;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
static void
|
|
1172
|
+
bare_ffmpeg_codec_parameters_from_context(
|
|
1173
|
+
js_env_t *env,
|
|
1174
|
+
js_receiver_t,
|
|
1175
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1176
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
1177
|
+
) {
|
|
1178
|
+
int err;
|
|
1179
|
+
|
|
1180
|
+
err = avcodec_parameters_from_context(parameters->handle, context->handle);
|
|
1181
|
+
|
|
1182
|
+
if (err < 0) {
|
|
1183
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1184
|
+
assert(err == 0);
|
|
1185
|
+
|
|
1186
|
+
throw js_pending_exception;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
static void
|
|
1191
|
+
bare_ffmpeg_codec_parameters_to_context(
|
|
1192
|
+
js_env_t *env,
|
|
1193
|
+
js_receiver_t,
|
|
1194
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1195
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1196
|
+
) {
|
|
1197
|
+
int err;
|
|
1198
|
+
|
|
1199
|
+
err = avcodec_parameters_to_context(context->handle, parameters->handle);
|
|
1200
|
+
if (err < 0) {
|
|
1201
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1202
|
+
assert(err == 0);
|
|
1203
|
+
|
|
1204
|
+
throw js_pending_exception;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
static js_arraybuffer_t
|
|
1209
|
+
bare_ffmpeg_codec_parameters_alloc(
|
|
1210
|
+
js_env_t *env,
|
|
1211
|
+
js_receiver_t
|
|
1212
|
+
) {
|
|
1213
|
+
int err;
|
|
1214
|
+
|
|
1215
|
+
js_arraybuffer_t handle;
|
|
1216
|
+
bare_ffmpeg_codec_parameters_t *parameters;
|
|
1217
|
+
err = js_create_arraybuffer(env, parameters, handle);
|
|
1218
|
+
assert(err == 0);
|
|
1219
|
+
|
|
1220
|
+
parameters->handle = avcodec_parameters_alloc();
|
|
1221
|
+
|
|
1222
|
+
return handle;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
static void
|
|
1226
|
+
bare_ffmpeg_codec_parameters_destroy(
|
|
1227
|
+
js_env_t *env,
|
|
1228
|
+
js_receiver_t,
|
|
1229
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1230
|
+
) {
|
|
1231
|
+
avcodec_parameters_free(¶meters->handle);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
static int64_t
|
|
1235
|
+
bare_ffmpeg_codec_parameters_get_bit_rate(
|
|
1236
|
+
js_env_t *env,
|
|
1237
|
+
js_receiver_t,
|
|
1238
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1239
|
+
) {
|
|
1240
|
+
return parameters->handle->bit_rate;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
static void
|
|
1244
|
+
bare_ffmpeg_codec_parameters_set_bit_rate(
|
|
1245
|
+
js_env_t *env,
|
|
1246
|
+
js_receiver_t,
|
|
1247
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1248
|
+
int64_t bit_rate
|
|
1249
|
+
) {
|
|
1250
|
+
parameters->handle->bit_rate = bit_rate;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
static int
|
|
1254
|
+
bare_ffmpeg_codec_parameters_get_bits_per_coded_sample(
|
|
1255
|
+
js_env_t *env,
|
|
1256
|
+
js_receiver_t,
|
|
1257
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1258
|
+
) {
|
|
1259
|
+
return parameters->handle->bits_per_coded_sample;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
static void
|
|
1263
|
+
bare_ffmpeg_codec_parameters_set_bits_per_coded_sample(
|
|
1264
|
+
js_env_t *env,
|
|
1265
|
+
js_receiver_t,
|
|
1266
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1267
|
+
int bits
|
|
1268
|
+
) {
|
|
1269
|
+
parameters->handle->bits_per_coded_sample = bits;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
static int
|
|
1273
|
+
bare_ffmpeg_codec_parameters_get_bits_per_raw_sample(
|
|
1274
|
+
js_env_t *env,
|
|
1275
|
+
js_receiver_t,
|
|
1276
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1277
|
+
) {
|
|
1278
|
+
return parameters->handle->bits_per_raw_sample;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
static void
|
|
1282
|
+
bare_ffmpeg_codec_parameters_set_bits_per_raw_sample(
|
|
1283
|
+
js_env_t *env,
|
|
1284
|
+
js_receiver_t,
|
|
1285
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1286
|
+
int bits
|
|
1287
|
+
) {
|
|
1288
|
+
parameters->handle->bits_per_raw_sample = bits;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
static int
|
|
1292
|
+
bare_ffmpeg_codec_parameters_get_sample_rate(
|
|
1293
|
+
js_env_t *env,
|
|
1294
|
+
js_receiver_t,
|
|
1295
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1296
|
+
) {
|
|
1297
|
+
return parameters->handle->sample_rate;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
static void
|
|
1301
|
+
bare_ffmpeg_codec_parameters_set_sample_rate(
|
|
1302
|
+
js_env_t *env,
|
|
1303
|
+
js_receiver_t,
|
|
1304
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1305
|
+
int rate
|
|
1306
|
+
) {
|
|
1307
|
+
parameters->handle->sample_rate = rate;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
static int
|
|
1311
|
+
bare_ffmpeg_codec_parameters_get_nb_channels(
|
|
1312
|
+
js_env_t *env,
|
|
1313
|
+
js_receiver_t,
|
|
1314
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1315
|
+
) {
|
|
1316
|
+
return parameters->handle->ch_layout.nb_channels;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
static void
|
|
1320
|
+
bare_ffmpeg_codec_parameters_set_nb_channels(
|
|
1321
|
+
js_env_t *env,
|
|
1322
|
+
js_receiver_t,
|
|
1323
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1324
|
+
int nb_channels
|
|
1325
|
+
) {
|
|
1326
|
+
parameters->handle->ch_layout.nb_channels = nb_channels;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
static int64_t
|
|
1330
|
+
bare_ffmpeg_codec_parameters_get_type(
|
|
1331
|
+
js_env_t *env,
|
|
1332
|
+
js_receiver_t,
|
|
1333
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1334
|
+
) {
|
|
1335
|
+
return parameters->handle->codec_type;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
static void
|
|
1339
|
+
bare_ffmpeg_codec_parameters_set_type(
|
|
1340
|
+
js_env_t *env,
|
|
1341
|
+
js_receiver_t,
|
|
1342
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1343
|
+
int type
|
|
1344
|
+
) {
|
|
1345
|
+
parameters->handle->codec_type = static_cast<AVMediaType>(type);
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
static uint32_t
|
|
1349
|
+
bare_ffmpeg_codec_parameters_get_tag(
|
|
1350
|
+
js_env_t *env,
|
|
1351
|
+
js_receiver_t,
|
|
1352
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1353
|
+
) {
|
|
1354
|
+
return parameters->handle->codec_tag;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
static void
|
|
1358
|
+
bare_ffmpeg_codec_parameters_set_tag(
|
|
1359
|
+
js_env_t *env,
|
|
1360
|
+
js_receiver_t,
|
|
1361
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1362
|
+
uint32_t codec_tag
|
|
1363
|
+
) {
|
|
1364
|
+
parameters->handle->codec_tag = codec_tag;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
static int32_t
|
|
1368
|
+
bare_ffmpeg_codec_parameters_get_id(
|
|
1369
|
+
js_env_t *env,
|
|
1370
|
+
js_receiver_t,
|
|
1371
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1372
|
+
) {
|
|
1373
|
+
return parameters->handle->codec_id;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
static void
|
|
1377
|
+
bare_ffmpeg_codec_parameters_set_id(
|
|
1378
|
+
js_env_t *env,
|
|
1379
|
+
js_receiver_t,
|
|
1380
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1381
|
+
uint32_t codec_id
|
|
1382
|
+
) {
|
|
1383
|
+
parameters->handle->codec_id = static_cast<AVCodecID>(codec_id);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
static int
|
|
1387
|
+
bare_ffmpeg_codec_parameters_get_level(
|
|
1388
|
+
js_env_t *env,
|
|
1389
|
+
js_receiver_t,
|
|
1390
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1391
|
+
) {
|
|
1392
|
+
return parameters->handle->level;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
static void
|
|
1396
|
+
bare_ffmpeg_codec_parameters_set_level(
|
|
1397
|
+
js_env_t *env,
|
|
1398
|
+
js_receiver_t,
|
|
1399
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1400
|
+
int level
|
|
1401
|
+
) {
|
|
1402
|
+
parameters->handle->level = level;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
static int
|
|
1406
|
+
bare_ffmpeg_codec_parameters_get_profile(
|
|
1407
|
+
js_env_t *env,
|
|
1408
|
+
js_receiver_t,
|
|
1409
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1410
|
+
) {
|
|
1411
|
+
return parameters->handle->profile;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
static void
|
|
1415
|
+
bare_ffmpeg_codec_parameters_set_profile(
|
|
1416
|
+
js_env_t *env,
|
|
1417
|
+
js_receiver_t,
|
|
1418
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1419
|
+
int profile
|
|
1420
|
+
) {
|
|
1421
|
+
parameters->handle->profile = profile;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
static int
|
|
1425
|
+
bare_ffmpeg_codec_parameters_get_format(
|
|
1426
|
+
js_env_t *env,
|
|
1427
|
+
js_receiver_t,
|
|
1428
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1429
|
+
) {
|
|
1430
|
+
return parameters->handle->format;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
static void
|
|
1434
|
+
bare_ffmpeg_codec_parameters_set_format(
|
|
1435
|
+
js_env_t *env,
|
|
1436
|
+
js_receiver_t,
|
|
1437
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1438
|
+
int format
|
|
1439
|
+
) {
|
|
1440
|
+
parameters->handle->format = format;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
static js_arraybuffer_t
|
|
1444
|
+
bare_ffmpeg_codec_parameters_get_channel_layout(
|
|
1445
|
+
js_env_t *env,
|
|
1446
|
+
js_receiver_t,
|
|
1447
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1448
|
+
) {
|
|
1449
|
+
int err;
|
|
1450
|
+
|
|
1451
|
+
js_arraybuffer_t result;
|
|
1452
|
+
|
|
1453
|
+
bare_ffmpeg_channel_layout_t *layout;
|
|
1454
|
+
err = js_create_arraybuffer(env, layout, result);
|
|
1455
|
+
assert(err == 0);
|
|
1456
|
+
|
|
1457
|
+
err = av_channel_layout_copy(&layout->handle, ¶meters->handle->ch_layout);
|
|
1458
|
+
assert(err == 0);
|
|
1459
|
+
|
|
1460
|
+
return result;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
static void
|
|
1464
|
+
bare_ffmpeg_codec_parameters_set_channel_layout(
|
|
1465
|
+
js_env_t *env,
|
|
1466
|
+
js_receiver_t,
|
|
1467
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1468
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
1469
|
+
) {
|
|
1470
|
+
int err;
|
|
1471
|
+
|
|
1472
|
+
err = av_channel_layout_copy(¶meters->handle->ch_layout, &layout->handle);
|
|
1473
|
+
assert(err == 0);
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
static int
|
|
1477
|
+
bare_ffmpeg_codec_parameters_get_width(
|
|
1478
|
+
js_env_t *env,
|
|
1479
|
+
js_receiver_t,
|
|
1480
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1481
|
+
) {
|
|
1482
|
+
return parameters->handle->width;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
static void
|
|
1486
|
+
bare_ffmpeg_codec_parameters_set_width(
|
|
1487
|
+
js_env_t *env,
|
|
1488
|
+
js_receiver_t,
|
|
1489
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1490
|
+
int width
|
|
1491
|
+
) {
|
|
1492
|
+
parameters->handle->width = width;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
static int32_t
|
|
1496
|
+
bare_ffmpeg_codec_parameters_get_height(
|
|
1497
|
+
js_env_t *env,
|
|
1498
|
+
js_receiver_t,
|
|
1499
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1500
|
+
) {
|
|
1501
|
+
return parameters->handle->height;
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
static void
|
|
1505
|
+
bare_ffmpeg_codec_parameters_set_height(
|
|
1506
|
+
js_env_t *env,
|
|
1507
|
+
js_receiver_t,
|
|
1508
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1509
|
+
int height
|
|
1510
|
+
) {
|
|
1511
|
+
parameters->handle->height = height;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
static js_arraybuffer_t
|
|
1515
|
+
bare_ffmpeg_codec_parameters_get_framerate(
|
|
1516
|
+
js_env_t *env,
|
|
1517
|
+
js_receiver_t,
|
|
1518
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1519
|
+
) {
|
|
1520
|
+
int err;
|
|
1521
|
+
|
|
1522
|
+
js_arraybuffer_t result;
|
|
1523
|
+
|
|
1524
|
+
int32_t *data;
|
|
1525
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1526
|
+
assert(err == 0);
|
|
1527
|
+
|
|
1528
|
+
data[0] = parameters->handle->framerate.num;
|
|
1529
|
+
data[1] = parameters->handle->framerate.den;
|
|
1530
|
+
|
|
1531
|
+
return result;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
static void
|
|
1535
|
+
bare_ffmpeg_codec_parameters_set_framerate(
|
|
1536
|
+
js_env_t *env,
|
|
1537
|
+
js_receiver_t,
|
|
1538
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1539
|
+
int numerator,
|
|
1540
|
+
int denominator
|
|
1541
|
+
) {
|
|
1542
|
+
parameters->handle->framerate.num = numerator;
|
|
1543
|
+
parameters->handle->framerate.den = denominator;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
static js_arraybuffer_t
|
|
1547
|
+
bare_ffmpeg_codec_parameters_get_extra_data(
|
|
1548
|
+
js_env_t *env,
|
|
1549
|
+
js_receiver_t,
|
|
1550
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1551
|
+
) {
|
|
1552
|
+
int err;
|
|
1553
|
+
|
|
1554
|
+
js_arraybuffer_t buffer;
|
|
1555
|
+
|
|
1556
|
+
assert(parameters->handle->extradata_size >= 0);
|
|
1557
|
+
|
|
1558
|
+
err = js_create_arraybuffer(
|
|
1559
|
+
env,
|
|
1560
|
+
parameters->handle->extradata,
|
|
1561
|
+
static_cast<size_t>(parameters->handle->extradata_size),
|
|
1562
|
+
buffer
|
|
1563
|
+
);
|
|
1564
|
+
assert(err == 0);
|
|
1565
|
+
|
|
1566
|
+
return buffer;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
void
|
|
1570
|
+
bare_ffmpeg_codec_parameters_set_extra_data(
|
|
1571
|
+
js_env_t *env,
|
|
1572
|
+
js_receiver_t,
|
|
1573
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1574
|
+
js_arraybuffer_t buffer,
|
|
1575
|
+
uint32_t offset,
|
|
1576
|
+
uint32_t len
|
|
1577
|
+
) {
|
|
1578
|
+
int err;
|
|
1579
|
+
|
|
1580
|
+
std::span<uint8_t> view;
|
|
1581
|
+
|
|
1582
|
+
err = js_get_arraybuffer_info(env, buffer, view);
|
|
1583
|
+
assert(err == 0);
|
|
1584
|
+
|
|
1585
|
+
if (parameters->handle->extradata_size) {
|
|
1586
|
+
assert(parameters->handle->extradata_size > 0);
|
|
1587
|
+
assert(parameters->handle->extradata);
|
|
1588
|
+
|
|
1589
|
+
av_free(parameters->handle->extradata);
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
size_t min_size = len + AV_INPUT_BUFFER_PADDING_SIZE;
|
|
1593
|
+
|
|
1594
|
+
parameters->handle->extradata = reinterpret_cast<uint8_t *>(av_malloc(min_size));
|
|
1595
|
+
memset(¶meters->handle->extradata[len], 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
|
1596
|
+
|
|
1597
|
+
memcpy(parameters->handle->extradata, &view[offset], len);
|
|
1598
|
+
|
|
1599
|
+
parameters->handle->extradata_size = static_cast<int>(len);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
static int
|
|
1603
|
+
bare_ffmpeg_codec_parameters_get_block_align(
|
|
1604
|
+
js_env_t *env,
|
|
1605
|
+
js_receiver_t,
|
|
1606
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1607
|
+
) {
|
|
1608
|
+
return parameters->handle->block_align;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
static void
|
|
1612
|
+
bare_ffmpeg_codec_parameters_set_block_align(
|
|
1613
|
+
js_env_t *env,
|
|
1614
|
+
js_receiver_t,
|
|
1615
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1616
|
+
int block_align
|
|
1617
|
+
) {
|
|
1618
|
+
parameters->handle->block_align = block_align;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
static int
|
|
1622
|
+
bare_ffmpeg_codec_parameters_get_initial_padding(
|
|
1623
|
+
js_env_t *env,
|
|
1624
|
+
js_receiver_t,
|
|
1625
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1626
|
+
) {
|
|
1627
|
+
return parameters->handle->initial_padding;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
static void
|
|
1631
|
+
bare_ffmpeg_codec_parameters_set_initial_padding(
|
|
1632
|
+
js_env_t *env,
|
|
1633
|
+
js_receiver_t,
|
|
1634
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1635
|
+
int initial_padding
|
|
1636
|
+
) {
|
|
1637
|
+
parameters->handle->initial_padding = initial_padding;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
static int
|
|
1641
|
+
bare_ffmpeg_codec_parameters_get_trailing_padding(
|
|
1642
|
+
js_env_t *env,
|
|
1643
|
+
js_receiver_t,
|
|
1644
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1645
|
+
) {
|
|
1646
|
+
return parameters->handle->trailing_padding;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
static void
|
|
1650
|
+
bare_ffmpeg_codec_parameters_set_trailing_padding(
|
|
1651
|
+
js_env_t *env,
|
|
1652
|
+
js_receiver_t,
|
|
1653
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1654
|
+
int trailing_padding
|
|
1655
|
+
) {
|
|
1656
|
+
parameters->handle->trailing_padding = trailing_padding;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
static int
|
|
1660
|
+
bare_ffmpeg_codec_parameters_get_seek_preroll(
|
|
1661
|
+
js_env_t *env,
|
|
1662
|
+
js_receiver_t,
|
|
1663
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1664
|
+
) {
|
|
1665
|
+
return parameters->handle->seek_preroll;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
static void
|
|
1669
|
+
bare_ffmpeg_codec_parameters_set_seek_preroll(
|
|
1670
|
+
js_env_t *env,
|
|
1671
|
+
js_receiver_t,
|
|
1672
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1673
|
+
int seek_preroll
|
|
1674
|
+
) {
|
|
1675
|
+
parameters->handle->seek_preroll = seek_preroll;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
static js_arraybuffer_t
|
|
1679
|
+
bare_ffmpeg_codec_parameters_get_sample_aspect_ratio(
|
|
1680
|
+
js_env_t *env,
|
|
1681
|
+
js_receiver_t,
|
|
1682
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1683
|
+
) {
|
|
1684
|
+
int err;
|
|
1685
|
+
js_arraybuffer_t result;
|
|
1686
|
+
|
|
1687
|
+
int32_t *data;
|
|
1688
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1689
|
+
assert(err == 0);
|
|
1690
|
+
|
|
1691
|
+
data[0] = parameters->handle->sample_aspect_ratio.num;
|
|
1692
|
+
data[1] = parameters->handle->sample_aspect_ratio.den;
|
|
1693
|
+
|
|
1694
|
+
return result;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
static void
|
|
1698
|
+
bare_ffmpeg_codec_parameters_set_sample_aspect_ratio(
|
|
1699
|
+
js_env_t *env,
|
|
1700
|
+
js_receiver_t,
|
|
1701
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1702
|
+
int num,
|
|
1703
|
+
int den
|
|
1704
|
+
) {
|
|
1705
|
+
parameters->handle->sample_aspect_ratio.num = num;
|
|
1706
|
+
parameters->handle->sample_aspect_ratio.den = den;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
static int
|
|
1710
|
+
bare_ffmpeg_codec_parameters_get_video_delay(
|
|
1711
|
+
js_env_t *env,
|
|
1712
|
+
js_receiver_t,
|
|
1713
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1714
|
+
) {
|
|
1715
|
+
return parameters->handle->video_delay;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
static void
|
|
1719
|
+
bare_ffmpeg_codec_parameters_set_video_delay(
|
|
1720
|
+
js_env_t *env,
|
|
1721
|
+
js_receiver_t,
|
|
1722
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
|
|
1723
|
+
int delay
|
|
1724
|
+
) {
|
|
1725
|
+
parameters->handle->video_delay = delay;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
static js_arraybuffer_t
|
|
1729
|
+
bare_ffmpeg_frame_init(js_env_t *env, js_receiver_t) {
|
|
1730
|
+
int err;
|
|
1731
|
+
|
|
1732
|
+
js_arraybuffer_t handle;
|
|
1733
|
+
|
|
1734
|
+
bare_ffmpeg_frame_t *frame;
|
|
1735
|
+
err = js_create_arraybuffer(env, frame, handle);
|
|
1736
|
+
assert(err == 0);
|
|
1737
|
+
|
|
1738
|
+
frame->handle = av_frame_alloc();
|
|
1739
|
+
frame->handle->opaque = (void *) frame;
|
|
1740
|
+
|
|
1741
|
+
return handle;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
static void
|
|
1745
|
+
bare_ffmpeg_frame_unref(
|
|
1746
|
+
js_env_t *env,
|
|
1747
|
+
js_receiver_t,
|
|
1748
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1749
|
+
) {
|
|
1750
|
+
av_frame_unref(frame->handle);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
static void
|
|
1754
|
+
bare_ffmpeg_frame_destroy(
|
|
1755
|
+
js_env_t *env,
|
|
1756
|
+
js_receiver_t,
|
|
1757
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1758
|
+
) {
|
|
1759
|
+
av_frame_free(&frame->handle);
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
static int32_t
|
|
1763
|
+
bare_ffmpeg_frame_get_width(
|
|
1764
|
+
js_env_t *env,
|
|
1765
|
+
js_receiver_t,
|
|
1766
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1767
|
+
) {
|
|
1768
|
+
return frame->handle->width;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
static void
|
|
1772
|
+
bare_ffmpeg_frame_set_width(
|
|
1773
|
+
js_env_t *env,
|
|
1774
|
+
js_receiver_t,
|
|
1775
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1776
|
+
int32_t width
|
|
1777
|
+
) {
|
|
1778
|
+
frame->handle->width = width;
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
static int32_t
|
|
1782
|
+
bare_ffmpeg_frame_get_height(
|
|
1783
|
+
js_env_t *env,
|
|
1784
|
+
js_receiver_t,
|
|
1785
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1786
|
+
) {
|
|
1787
|
+
return frame->handle->height;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
static void
|
|
1791
|
+
bare_ffmpeg_frame_set_height(
|
|
1792
|
+
js_env_t *env,
|
|
1793
|
+
js_receiver_t,
|
|
1794
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1795
|
+
int32_t height
|
|
1796
|
+
) {
|
|
1797
|
+
frame->handle->height = height;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
static int64_t
|
|
1801
|
+
bare_ffmpeg_frame_get_pixel_format(
|
|
1802
|
+
js_env_t *env,
|
|
1803
|
+
js_receiver_t,
|
|
1804
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1805
|
+
) {
|
|
1806
|
+
return frame->handle->format;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
static void
|
|
1810
|
+
bare_ffmpeg_frame_set_pixel_format(
|
|
1811
|
+
js_env_t *env,
|
|
1812
|
+
js_receiver_t,
|
|
1813
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1814
|
+
int32_t format
|
|
1815
|
+
) {
|
|
1816
|
+
frame->handle->format = static_cast<AVPixelFormat>(format);
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
static int32_t
|
|
1820
|
+
bare_ffmpeg_frame_get_nb_samples(
|
|
1821
|
+
js_env_t *env,
|
|
1822
|
+
js_receiver_t,
|
|
1823
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1824
|
+
) {
|
|
1825
|
+
return frame->handle->nb_samples;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
static void
|
|
1829
|
+
bare_ffmpeg_frame_set_nb_samples(
|
|
1830
|
+
js_env_t *env,
|
|
1831
|
+
js_receiver_t,
|
|
1832
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1833
|
+
int32_t nb_samples
|
|
1834
|
+
) {
|
|
1835
|
+
frame->handle->nb_samples = nb_samples;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
static int32_t
|
|
1839
|
+
bare_ffmpeg_frame_get_pict_type(
|
|
1840
|
+
js_env_t *env,
|
|
1841
|
+
js_receiver_t,
|
|
1842
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1843
|
+
) {
|
|
1844
|
+
return frame->handle->pict_type;
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
static int64_t
|
|
1848
|
+
bare_ffmpeg_frame_get_pts(
|
|
1849
|
+
js_env_t *env,
|
|
1850
|
+
js_receiver_t,
|
|
1851
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1852
|
+
) {
|
|
1853
|
+
int64_t ts = frame->handle->pts;
|
|
1854
|
+
|
|
1855
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
1856
|
+
|
|
1857
|
+
return ts;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
static void
|
|
1861
|
+
bare_ffmpeg_frame_set_pts(
|
|
1862
|
+
js_env_t *,
|
|
1863
|
+
js_receiver_t,
|
|
1864
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1865
|
+
int64_t value
|
|
1866
|
+
) {
|
|
1867
|
+
frame->handle->pts = value;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
static int64_t
|
|
1871
|
+
bare_ffmpeg_frame_get_pkt_dts(
|
|
1872
|
+
js_env_t *env,
|
|
1873
|
+
js_receiver_t,
|
|
1874
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1875
|
+
) {
|
|
1876
|
+
int64_t ts = frame->handle->pkt_dts;
|
|
1877
|
+
|
|
1878
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
1879
|
+
|
|
1880
|
+
return ts;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
static void
|
|
1884
|
+
bare_ffmpeg_frame_set_pkt_dts(
|
|
1885
|
+
js_env_t *,
|
|
1886
|
+
js_receiver_t,
|
|
1887
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1888
|
+
int64_t value
|
|
1889
|
+
) {
|
|
1890
|
+
frame->handle->pkt_dts = value;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
static js_arraybuffer_t
|
|
1894
|
+
bare_ffmpeg_frame_get_time_base(
|
|
1895
|
+
js_env_t *env,
|
|
1896
|
+
js_receiver_t,
|
|
1897
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1898
|
+
) {
|
|
1899
|
+
int err;
|
|
1900
|
+
|
|
1901
|
+
js_arraybuffer_t result;
|
|
1902
|
+
|
|
1903
|
+
int32_t *data;
|
|
1904
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1905
|
+
assert(err == 0);
|
|
1906
|
+
|
|
1907
|
+
data[0] = frame->handle->time_base.num;
|
|
1908
|
+
data[1] = frame->handle->time_base.den;
|
|
1909
|
+
|
|
1910
|
+
return result;
|
|
1911
|
+
}
|
|
1912
|
+
static void
|
|
1913
|
+
bare_ffmpeg_frame_set_time_base(
|
|
1914
|
+
js_env_t *env,
|
|
1915
|
+
js_receiver_t,
|
|
1916
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1917
|
+
int num,
|
|
1918
|
+
int den
|
|
1919
|
+
) {
|
|
1920
|
+
frame->handle->time_base.num = num;
|
|
1921
|
+
frame->handle->time_base.den = den;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
static void
|
|
1925
|
+
bare_ffmpeg_frame_alloc(
|
|
1926
|
+
js_env_t *env,
|
|
1927
|
+
js_receiver_t,
|
|
1928
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1929
|
+
int align
|
|
1930
|
+
) {
|
|
1931
|
+
int err;
|
|
1932
|
+
|
|
1933
|
+
err = av_frame_get_buffer(frame->handle, align);
|
|
1934
|
+
if (err < 0) {
|
|
1935
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
1936
|
+
assert(err == 0);
|
|
1937
|
+
|
|
1938
|
+
throw js_pending_exception;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
static js_arraybuffer_t
|
|
1943
|
+
bare_ffmpeg_image_init(
|
|
1944
|
+
js_env_t *env,
|
|
1945
|
+
js_receiver_t,
|
|
1946
|
+
int32_t pixel_format,
|
|
1947
|
+
int32_t width,
|
|
1948
|
+
int32_t height,
|
|
1949
|
+
int32_t align
|
|
1950
|
+
) {
|
|
1951
|
+
int err;
|
|
1952
|
+
|
|
1953
|
+
auto len = av_image_get_buffer_size(
|
|
1954
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
1955
|
+
width,
|
|
1956
|
+
height,
|
|
1957
|
+
align
|
|
1958
|
+
);
|
|
1959
|
+
|
|
1960
|
+
if (len < 0) {
|
|
1961
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
1962
|
+
assert(err == 0);
|
|
1963
|
+
|
|
1964
|
+
throw js_pending_exception;
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
js_arraybuffer_t handle;
|
|
1968
|
+
err = js_create_arraybuffer(env, static_cast<size_t>(len), handle);
|
|
1969
|
+
assert(err == 0);
|
|
1970
|
+
|
|
1971
|
+
return handle;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
static void
|
|
1975
|
+
bare_ffmpeg_image_fill(
|
|
1976
|
+
js_env_t *env,
|
|
1977
|
+
js_receiver_t,
|
|
1978
|
+
int32_t pixel_format,
|
|
1979
|
+
int32_t width,
|
|
1980
|
+
int32_t height,
|
|
1981
|
+
int32_t align,
|
|
1982
|
+
js_arraybuffer_span_t data,
|
|
1983
|
+
uint64_t offset,
|
|
1984
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1985
|
+
) {
|
|
1986
|
+
int err;
|
|
1987
|
+
|
|
1988
|
+
auto len = av_image_fill_arrays(
|
|
1989
|
+
frame->handle->data,
|
|
1990
|
+
frame->handle->linesize,
|
|
1991
|
+
&data[static_cast<size_t>(offset)],
|
|
1992
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
1993
|
+
width,
|
|
1994
|
+
height,
|
|
1995
|
+
align
|
|
1996
|
+
);
|
|
1997
|
+
|
|
1998
|
+
if (len < 0) {
|
|
1999
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2000
|
+
assert(err == 0);
|
|
2001
|
+
|
|
2002
|
+
throw js_pending_exception;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
static void
|
|
2007
|
+
bare_ffmpeg_image_read(
|
|
2008
|
+
js_env_t *env,
|
|
2009
|
+
js_receiver_t,
|
|
2010
|
+
int32_t pixel_format,
|
|
2011
|
+
int32_t width,
|
|
2012
|
+
int32_t height,
|
|
2013
|
+
int32_t align,
|
|
2014
|
+
js_arraybuffer_span_t data,
|
|
2015
|
+
uint64_t offset,
|
|
2016
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
2017
|
+
) {
|
|
2018
|
+
uint8_t *dst_data[4];
|
|
2019
|
+
int dst_linesize[4];
|
|
2020
|
+
|
|
2021
|
+
int err = av_image_fill_arrays(
|
|
2022
|
+
dst_data,
|
|
2023
|
+
dst_linesize,
|
|
2024
|
+
&data[offset],
|
|
2025
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
2026
|
+
width,
|
|
2027
|
+
height,
|
|
2028
|
+
align
|
|
2029
|
+
);
|
|
2030
|
+
assert(err >= 0);
|
|
2031
|
+
|
|
2032
|
+
av_image_copy(
|
|
2033
|
+
dst_data,
|
|
2034
|
+
dst_linesize,
|
|
2035
|
+
frame->handle->data,
|
|
2036
|
+
frame->handle->linesize,
|
|
2037
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
2038
|
+
width,
|
|
2039
|
+
height
|
|
2040
|
+
);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
static int
|
|
2044
|
+
bare_ffmpeg_image_get_line_size(
|
|
2045
|
+
js_env_t *env,
|
|
2046
|
+
js_receiver_t,
|
|
2047
|
+
int32_t pixel_format,
|
|
2048
|
+
int32_t width,
|
|
2049
|
+
int32_t plane
|
|
2050
|
+
) {
|
|
2051
|
+
return av_image_get_linesize(
|
|
2052
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
2053
|
+
width,
|
|
2054
|
+
plane
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
static js_arraybuffer_t
|
|
2059
|
+
bare_ffmpeg_samples_init(
|
|
2060
|
+
js_env_t *env,
|
|
2061
|
+
js_receiver_t,
|
|
2062
|
+
int32_t sample_format,
|
|
2063
|
+
int32_t nb_channels,
|
|
2064
|
+
int32_t nb_samples,
|
|
2065
|
+
int32_t align
|
|
2066
|
+
) {
|
|
2067
|
+
int err;
|
|
2068
|
+
|
|
2069
|
+
auto len = av_samples_get_buffer_size(
|
|
2070
|
+
NULL,
|
|
2071
|
+
nb_channels,
|
|
2072
|
+
nb_samples,
|
|
2073
|
+
static_cast<AVSampleFormat>(sample_format),
|
|
2074
|
+
align
|
|
2075
|
+
);
|
|
2076
|
+
|
|
2077
|
+
if (len < 0) {
|
|
2078
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2079
|
+
assert(err == 0);
|
|
2080
|
+
|
|
2081
|
+
throw js_pending_exception;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
js_arraybuffer_t handle;
|
|
2085
|
+
err = js_create_arraybuffer(env, static_cast<size_t>(len), handle);
|
|
2086
|
+
assert(err == 0);
|
|
2087
|
+
|
|
2088
|
+
return handle;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
static int
|
|
2092
|
+
bare_ffmpeg_samples_fill(
|
|
2093
|
+
js_env_t *env,
|
|
2094
|
+
js_receiver_t,
|
|
2095
|
+
int32_t sample_format,
|
|
2096
|
+
int32_t nb_channels,
|
|
2097
|
+
int32_t nb_samples,
|
|
2098
|
+
int32_t align,
|
|
2099
|
+
js_arraybuffer_span_t data,
|
|
2100
|
+
uint64_t offset,
|
|
2101
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
2102
|
+
) {
|
|
2103
|
+
int err;
|
|
2104
|
+
|
|
2105
|
+
auto len = av_samples_fill_arrays(
|
|
2106
|
+
frame->handle->data,
|
|
2107
|
+
frame->handle->linesize,
|
|
2108
|
+
&data[static_cast<size_t>(offset)],
|
|
2109
|
+
nb_channels,
|
|
2110
|
+
nb_samples,
|
|
2111
|
+
static_cast<AVSampleFormat>(sample_format),
|
|
2112
|
+
align
|
|
2113
|
+
);
|
|
2114
|
+
|
|
2115
|
+
if (len < 0) {
|
|
2116
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2117
|
+
assert(err == 0);
|
|
2118
|
+
|
|
2119
|
+
throw js_pending_exception;
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
return len;
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
static js_arraybuffer_t
|
|
2126
|
+
bare_ffmpeg_packet_init(js_env_t *env, js_receiver_t) {
|
|
2127
|
+
int err;
|
|
2128
|
+
|
|
2129
|
+
js_arraybuffer_t handle;
|
|
2130
|
+
|
|
2131
|
+
bare_ffmpeg_packet_t *packet;
|
|
2132
|
+
err = js_create_arraybuffer(env, packet, handle);
|
|
2133
|
+
assert(err == 0);
|
|
2134
|
+
|
|
2135
|
+
packet->handle = av_packet_alloc();
|
|
2136
|
+
|
|
2137
|
+
return handle;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
static js_arraybuffer_t
|
|
2141
|
+
bare_ffmpeg_packet_init_from_buffer(
|
|
2142
|
+
js_env_t *env,
|
|
2143
|
+
js_receiver_t,
|
|
2144
|
+
js_arraybuffer_span_t data,
|
|
2145
|
+
uint64_t offset,
|
|
2146
|
+
uint64_t len
|
|
2147
|
+
) {
|
|
2148
|
+
int err;
|
|
2149
|
+
|
|
2150
|
+
AVPacket *pkt = av_packet_alloc();
|
|
2151
|
+
|
|
2152
|
+
err = av_new_packet(pkt, static_cast<int>(len));
|
|
2153
|
+
assert(err == 0);
|
|
2154
|
+
|
|
2155
|
+
memcpy(pkt->data, &data[static_cast<size_t>(offset)], static_cast<size_t>(len));
|
|
2156
|
+
|
|
2157
|
+
js_arraybuffer_t handle;
|
|
2158
|
+
|
|
2159
|
+
bare_ffmpeg_packet_t *packet;
|
|
2160
|
+
err = js_create_arraybuffer(env, packet, handle);
|
|
2161
|
+
assert(err == 0);
|
|
2162
|
+
|
|
2163
|
+
packet->handle = pkt;
|
|
2164
|
+
|
|
2165
|
+
return handle;
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
static void
|
|
2169
|
+
bare_ffmpeg_packet_unref(
|
|
2170
|
+
js_env_t *env,
|
|
2171
|
+
js_receiver_t,
|
|
2172
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2173
|
+
) {
|
|
2174
|
+
av_packet_unref(packet->handle);
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
static int32_t
|
|
2178
|
+
bare_ffmpeg_packet_get_stream_index(
|
|
2179
|
+
js_env_t *env,
|
|
2180
|
+
js_receiver_t,
|
|
2181
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2182
|
+
) {
|
|
2183
|
+
return packet->handle->stream_index;
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
static void
|
|
2187
|
+
bare_ffmpeg_packet_set_stream_index(
|
|
2188
|
+
js_env_t *env,
|
|
2189
|
+
js_receiver_t,
|
|
2190
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2191
|
+
int32_t value
|
|
2192
|
+
) {
|
|
2193
|
+
packet->handle->stream_index = value;
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
static js_arraybuffer_t
|
|
2197
|
+
bare_ffmpeg_packet_get_data(
|
|
2198
|
+
js_env_t *env,
|
|
2199
|
+
js_receiver_t,
|
|
2200
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2201
|
+
) {
|
|
2202
|
+
int err;
|
|
2203
|
+
|
|
2204
|
+
auto size = static_cast<size_t>(packet->handle->size);
|
|
2205
|
+
|
|
2206
|
+
js_arraybuffer_t handle;
|
|
2207
|
+
|
|
2208
|
+
uint8_t *data;
|
|
2209
|
+
err = js_create_arraybuffer(env, size, data, handle);
|
|
2210
|
+
assert(err == 0);
|
|
2211
|
+
|
|
2212
|
+
memcpy(data, packet->handle->data, size);
|
|
2213
|
+
|
|
2214
|
+
return handle;
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
static void
|
|
2218
|
+
bare_ffmpeg_packet_set_data(
|
|
2219
|
+
js_env_t *env,
|
|
2220
|
+
js_receiver_t,
|
|
2221
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2222
|
+
js_arraybuffer_span_t data,
|
|
2223
|
+
uint32_t offset,
|
|
2224
|
+
uint32_t len
|
|
2225
|
+
) {
|
|
2226
|
+
int err;
|
|
2227
|
+
assert(offset + len <= data.size());
|
|
2228
|
+
|
|
2229
|
+
av_packet_unref(packet->handle);
|
|
2230
|
+
|
|
2231
|
+
err = av_new_packet(packet->handle, static_cast<int>(len));
|
|
2232
|
+
assert(err == 0);
|
|
2233
|
+
|
|
2234
|
+
memcpy(packet->handle->data, &data[offset], len);
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
static bool
|
|
2238
|
+
bare_ffmpeg_packet_is_keyframe(
|
|
2239
|
+
js_env_t *,
|
|
2240
|
+
js_receiver_t,
|
|
2241
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2242
|
+
) {
|
|
2243
|
+
return packet->handle->flags & AV_PKT_FLAG_KEY;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
static int64_t
|
|
2247
|
+
bare_ffmpeg_packet_get_dts(
|
|
2248
|
+
js_env_t *env,
|
|
2249
|
+
js_receiver_t,
|
|
2250
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2251
|
+
) {
|
|
2252
|
+
int64_t ts = packet->handle->dts;
|
|
2253
|
+
|
|
2254
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
2255
|
+
|
|
2256
|
+
return ts;
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
static void
|
|
2260
|
+
bare_ffmpeg_packet_set_dts(
|
|
2261
|
+
js_env_t *env,
|
|
2262
|
+
js_receiver_t,
|
|
2263
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2264
|
+
int64_t value
|
|
2265
|
+
) {
|
|
2266
|
+
packet->handle->dts = value;
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
static int64_t
|
|
2270
|
+
bare_ffmpeg_packet_get_pts(
|
|
2271
|
+
js_env_t *env,
|
|
2272
|
+
js_receiver_t,
|
|
2273
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2274
|
+
) {
|
|
2275
|
+
int64_t ts = packet->handle->pts;
|
|
2276
|
+
|
|
2277
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
2278
|
+
|
|
2279
|
+
return ts;
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
static void
|
|
2283
|
+
bare_ffmpeg_packet_set_pts(
|
|
2284
|
+
js_env_t *env,
|
|
2285
|
+
js_receiver_t,
|
|
2286
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2287
|
+
int64_t value
|
|
2288
|
+
) {
|
|
2289
|
+
packet->handle->pts = value;
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
static js_arraybuffer_t
|
|
2293
|
+
bare_ffmpeg_packet_get_time_base(
|
|
2294
|
+
js_env_t *env,
|
|
2295
|
+
js_receiver_t,
|
|
2296
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2297
|
+
) {
|
|
2298
|
+
int err;
|
|
2299
|
+
|
|
2300
|
+
js_arraybuffer_t result;
|
|
2301
|
+
|
|
2302
|
+
int32_t *data;
|
|
2303
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
2304
|
+
assert(err == 0);
|
|
2305
|
+
|
|
2306
|
+
data[0] = packet->handle->time_base.num;
|
|
2307
|
+
data[1] = packet->handle->time_base.den;
|
|
2308
|
+
|
|
2309
|
+
return result;
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
static void
|
|
2313
|
+
bare_ffmpeg_packet_set_time_base(
|
|
2314
|
+
js_env_t *env,
|
|
2315
|
+
js_receiver_t,
|
|
2316
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2317
|
+
int num,
|
|
2318
|
+
int den
|
|
2319
|
+
) {
|
|
2320
|
+
packet->handle->time_base.num = num;
|
|
2321
|
+
packet->handle->time_base.den = den;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
static int64_t
|
|
2325
|
+
bare_ffmpeg_packet_rescale_ts(
|
|
2326
|
+
js_env_t *env,
|
|
2327
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2328
|
+
int32_t num,
|
|
2329
|
+
int32_t den
|
|
2330
|
+
) {
|
|
2331
|
+
AVRational src = packet->handle->time_base;
|
|
2332
|
+
AVRational dst = {.num = num, .den = den};
|
|
2333
|
+
|
|
2334
|
+
if (
|
|
2335
|
+
bad_timebase(src) ||
|
|
2336
|
+
bad_timebase(dst) ||
|
|
2337
|
+
packet->handle->dts == AV_NOPTS_VALUE ||
|
|
2338
|
+
packet->handle->pts == AV_NOPTS_VALUE
|
|
2339
|
+
) {
|
|
2340
|
+
return false;
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
av_packet_rescale_ts(packet->handle, src, dst);
|
|
2344
|
+
|
|
2345
|
+
packet->handle->time_base = dst;
|
|
2346
|
+
|
|
2347
|
+
return true;
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
static int64_t
|
|
2351
|
+
bare_ffmpeg_packet_get_duration(
|
|
2352
|
+
js_env_t *env,
|
|
2353
|
+
js_receiver_t,
|
|
2354
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2355
|
+
) {
|
|
2356
|
+
return packet->handle->duration;
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
static void
|
|
2360
|
+
bare_ffmpeg_packet_set_duration(
|
|
2361
|
+
js_env_t *env,
|
|
2362
|
+
js_receiver_t,
|
|
2363
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2364
|
+
int64_t value
|
|
2365
|
+
) {
|
|
2366
|
+
packet->handle->duration = value;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
static int32_t
|
|
2370
|
+
bare_ffmpeg_packet_get_flags(
|
|
2371
|
+
js_env_t *env,
|
|
2372
|
+
js_receiver_t,
|
|
2373
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
2374
|
+
) {
|
|
2375
|
+
return packet->handle->flags;
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
static void
|
|
2379
|
+
bare_ffmpeg_packet_set_flags(
|
|
2380
|
+
js_env_t *env,
|
|
2381
|
+
js_receiver_t,
|
|
2382
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2383
|
+
int32_t value
|
|
2384
|
+
) {
|
|
2385
|
+
packet->handle->flags = value;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
static js_arraybuffer_t
|
|
2389
|
+
bare_ffmpeg_scaler_init(
|
|
2390
|
+
js_env_t *env,
|
|
2391
|
+
js_receiver_t,
|
|
2392
|
+
int64_t source_format,
|
|
2393
|
+
int32_t source_width,
|
|
2394
|
+
int32_t source_height,
|
|
2395
|
+
int64_t target_format,
|
|
2396
|
+
int32_t target_width,
|
|
2397
|
+
int32_t target_height
|
|
2398
|
+
) {
|
|
2399
|
+
int err;
|
|
2400
|
+
|
|
2401
|
+
js_arraybuffer_t handle;
|
|
2402
|
+
|
|
2403
|
+
bare_ffmpeg_scaler_t *scaler;
|
|
2404
|
+
err = js_create_arraybuffer(env, scaler, handle);
|
|
2405
|
+
assert(err == 0);
|
|
2406
|
+
|
|
2407
|
+
scaler->handle = sws_getContext(
|
|
2408
|
+
source_width,
|
|
2409
|
+
source_height,
|
|
2410
|
+
static_cast<AVPixelFormat>(source_format),
|
|
2411
|
+
target_width,
|
|
2412
|
+
target_height,
|
|
2413
|
+
static_cast<AVPixelFormat>(target_format),
|
|
2414
|
+
SWS_BICUBIC,
|
|
2415
|
+
NULL,
|
|
2416
|
+
NULL,
|
|
2417
|
+
NULL
|
|
2418
|
+
);
|
|
2419
|
+
|
|
2420
|
+
return handle;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
static void
|
|
2424
|
+
bare_ffmpeg_scaler_destroy(
|
|
2425
|
+
js_env_t *env,
|
|
2426
|
+
js_receiver_t,
|
|
2427
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_scaler_t, 1> scaler
|
|
2428
|
+
) {
|
|
2429
|
+
sws_freeContext(scaler->handle);
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
static int
|
|
2433
|
+
bare_ffmpeg_scaler_scale(
|
|
2434
|
+
js_env_t *env,
|
|
2435
|
+
js_receiver_t,
|
|
2436
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_scaler_t, 1> scaler,
|
|
2437
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> source,
|
|
2438
|
+
int y,
|
|
2439
|
+
int height,
|
|
2440
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> target
|
|
2441
|
+
) {
|
|
2442
|
+
int err = av_frame_copy_props(target->handle, source->handle);
|
|
2443
|
+
assert(err == 0);
|
|
2444
|
+
|
|
2445
|
+
return sws_scale(
|
|
2446
|
+
scaler->handle,
|
|
2447
|
+
reinterpret_cast<const uint8_t *const *>(source->handle->data),
|
|
2448
|
+
source->handle->linesize,
|
|
2449
|
+
y,
|
|
2450
|
+
height,
|
|
2451
|
+
target->handle->data,
|
|
2452
|
+
target->handle->linesize
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
static js_arraybuffer_t
|
|
2457
|
+
bare_ffmpeg_dictionary_init(
|
|
2458
|
+
js_env_t *env,
|
|
2459
|
+
js_receiver_t
|
|
2460
|
+
) {
|
|
2461
|
+
int err;
|
|
2462
|
+
|
|
2463
|
+
js_arraybuffer_t handle;
|
|
2464
|
+
|
|
2465
|
+
bare_ffmpeg_dictionary_t *dict;
|
|
2466
|
+
err = js_create_arraybuffer(env, dict, handle);
|
|
2467
|
+
assert(err == 0);
|
|
2468
|
+
|
|
2469
|
+
dict->handle = NULL;
|
|
2470
|
+
|
|
2471
|
+
return handle;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
static void
|
|
2475
|
+
bare_ffmpeg_dictionary_destroy(
|
|
2476
|
+
js_env_t *env,
|
|
2477
|
+
js_receiver_t,
|
|
2478
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1> dict
|
|
2479
|
+
) {
|
|
2480
|
+
av_dict_free(&dict->handle);
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
static void
|
|
2484
|
+
bare_ffmpeg_dictionary_set_entry(
|
|
2485
|
+
js_env_t *env,
|
|
2486
|
+
js_receiver_t,
|
|
2487
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1> dict,
|
|
2488
|
+
std::string key,
|
|
2489
|
+
std::string value
|
|
2490
|
+
) {
|
|
2491
|
+
int err;
|
|
2492
|
+
|
|
2493
|
+
err = av_dict_set(&dict->handle, key.c_str(), value.c_str(), 0);
|
|
2494
|
+
assert(err == 0);
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
static std::vector<std::tuple<const char *, const char *>>
|
|
2498
|
+
bare_ffmpeg_dictionary_get_entries(
|
|
2499
|
+
js_env_t *env,
|
|
2500
|
+
js_receiver_t,
|
|
2501
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1> dict
|
|
2502
|
+
) {
|
|
2503
|
+
std::vector<std::tuple<const char *, const char *>> entries{};
|
|
2504
|
+
|
|
2505
|
+
const AVDictionaryEntry *entry = nullptr;
|
|
2506
|
+
while ((entry = av_dict_iterate(dict->handle, entry))) {
|
|
2507
|
+
entries.emplace_back(entry->key, entry->value);
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
return entries;
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
static std::optional<std::string>
|
|
2514
|
+
bare_ffmpeg_dictionary_get_entry(
|
|
2515
|
+
js_env_t *env,
|
|
2516
|
+
js_receiver_t,
|
|
2517
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1> dict,
|
|
2518
|
+
std::string key
|
|
2519
|
+
) {
|
|
2520
|
+
AVDictionaryEntry *entry = av_dict_get(dict->handle, key.c_str(), NULL, 0);
|
|
2521
|
+
|
|
2522
|
+
if (entry == NULL) {
|
|
2523
|
+
return std::nullopt;
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2526
|
+
return std::string{entry->value};
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
static js_arraybuffer_t
|
|
2530
|
+
bare_ffmpeg_resampler_init(
|
|
2531
|
+
js_env_t *env,
|
|
2532
|
+
js_receiver_t,
|
|
2533
|
+
int32_t in_rate,
|
|
2534
|
+
int32_t in_fmt,
|
|
2535
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> in_layout,
|
|
2536
|
+
int32_t out_rate,
|
|
2537
|
+
int32_t out_fmt,
|
|
2538
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> out_layout
|
|
2539
|
+
) {
|
|
2540
|
+
int err;
|
|
2541
|
+
|
|
2542
|
+
js_arraybuffer_t handle;
|
|
2543
|
+
|
|
2544
|
+
bare_ffmpeg_resampler_t *resampler;
|
|
2545
|
+
err = js_create_arraybuffer(env, resampler, handle);
|
|
2546
|
+
assert(err == 0);
|
|
2547
|
+
|
|
2548
|
+
resampler->handle = swr_alloc();
|
|
2549
|
+
|
|
2550
|
+
err = swr_alloc_set_opts2(
|
|
2551
|
+
&resampler->handle,
|
|
2552
|
+
&out_layout->handle,
|
|
2553
|
+
static_cast<AVSampleFormat>(out_fmt),
|
|
2554
|
+
out_rate,
|
|
2555
|
+
&in_layout->handle,
|
|
2556
|
+
static_cast<AVSampleFormat>(in_fmt),
|
|
2557
|
+
in_rate,
|
|
2558
|
+
0,
|
|
2559
|
+
NULL
|
|
2560
|
+
);
|
|
2561
|
+
|
|
2562
|
+
if (err < 0) {
|
|
2563
|
+
swr_free(&resampler->handle);
|
|
2564
|
+
|
|
2565
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
2566
|
+
assert(err == 0);
|
|
2567
|
+
|
|
2568
|
+
throw js_pending_exception;
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
err = swr_init(resampler->handle);
|
|
2572
|
+
if (err < 0) {
|
|
2573
|
+
swr_free(&resampler->handle);
|
|
2574
|
+
|
|
2575
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
2576
|
+
assert(err == 0);
|
|
2577
|
+
|
|
2578
|
+
throw js_pending_exception;
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
return handle;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
static int64_t
|
|
2585
|
+
bare_ffmpeg_resampler_convert_frames(
|
|
2586
|
+
js_env_t *env,
|
|
2587
|
+
js_receiver_t,
|
|
2588
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_resampler_t, 1> resampler,
|
|
2589
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> in_frame,
|
|
2590
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> out_frame
|
|
2591
|
+
) {
|
|
2592
|
+
int err;
|
|
2593
|
+
|
|
2594
|
+
auto result = swr_convert(
|
|
2595
|
+
resampler->handle,
|
|
2596
|
+
(uint8_t **) out_frame->handle->data,
|
|
2597
|
+
out_frame->handle->nb_samples,
|
|
2598
|
+
(const uint8_t **) in_frame->handle->data,
|
|
2599
|
+
in_frame->handle->nb_samples
|
|
2600
|
+
);
|
|
2601
|
+
|
|
2602
|
+
if (result < 0) {
|
|
2603
|
+
err = js_throw_error(env, NULL, av_err2str(result));
|
|
2604
|
+
assert(err == 0);
|
|
2605
|
+
|
|
2606
|
+
throw js_pending_exception;
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
out_frame->handle->nb_samples = result;
|
|
2610
|
+
|
|
2611
|
+
return result;
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
static int64_t
|
|
2615
|
+
bare_ffmpeg_resampler_get_delay(
|
|
2616
|
+
js_env_t *env,
|
|
2617
|
+
js_receiver_t,
|
|
2618
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_resampler_t, 1> resampler,
|
|
2619
|
+
int64_t base
|
|
2620
|
+
) {
|
|
2621
|
+
return swr_get_delay(resampler->handle, base);
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
static int64_t
|
|
2625
|
+
bare_ffmpeg_resampler_flush(
|
|
2626
|
+
js_env_t *env,
|
|
2627
|
+
js_receiver_t,
|
|
2628
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_resampler_t, 1> resampler,
|
|
2629
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> out_frame
|
|
2630
|
+
) {
|
|
2631
|
+
int err;
|
|
2632
|
+
|
|
2633
|
+
auto result = swr_convert(
|
|
2634
|
+
resampler->handle,
|
|
2635
|
+
out_frame->handle->data,
|
|
2636
|
+
out_frame->handle->nb_samples,
|
|
2637
|
+
NULL,
|
|
2638
|
+
0
|
|
2639
|
+
);
|
|
2640
|
+
|
|
2641
|
+
if (result < 0) {
|
|
2642
|
+
err = js_throw_error(env, NULL, av_err2str(result));
|
|
2643
|
+
assert(err == 0);
|
|
2644
|
+
|
|
2645
|
+
throw js_pending_exception;
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
out_frame->handle->nb_samples = result;
|
|
2649
|
+
|
|
2650
|
+
return result;
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
static void
|
|
2654
|
+
bare_ffmpeg_resampler_destroy(
|
|
2655
|
+
js_env_t *env,
|
|
2656
|
+
js_receiver_t,
|
|
2657
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_resampler_t, 1> resampler
|
|
2658
|
+
) {
|
|
2659
|
+
swr_free(&resampler->handle);
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
static js_arraybuffer_t
|
|
2663
|
+
bare_ffmpeg_channel_layout_copy(
|
|
2664
|
+
js_env_t *env,
|
|
2665
|
+
js_receiver_t,
|
|
2666
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
2667
|
+
) {
|
|
2668
|
+
int err;
|
|
2669
|
+
|
|
2670
|
+
js_arraybuffer_t result;
|
|
2671
|
+
|
|
2672
|
+
bare_ffmpeg_channel_layout_t *copy;
|
|
2673
|
+
err = js_create_arraybuffer(env, copy, result);
|
|
2674
|
+
assert(err == 0);
|
|
2675
|
+
|
|
2676
|
+
err = av_channel_layout_copy(©->handle, &layout->handle);
|
|
2677
|
+
assert(err == 0);
|
|
2678
|
+
|
|
2679
|
+
return result;
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
static int
|
|
2683
|
+
bare_ffmpeg_channel_layout_get_nb_channels(
|
|
2684
|
+
js_env_t *env,
|
|
2685
|
+
js_receiver_t,
|
|
2686
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
2687
|
+
) {
|
|
2688
|
+
return layout->handle.nb_channels;
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
static uint64_t
|
|
2692
|
+
bare_ffmpeg_channel_layout_get_mask(
|
|
2693
|
+
js_env_t *env,
|
|
2694
|
+
js_receiver_t,
|
|
2695
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
2696
|
+
) {
|
|
2697
|
+
return layout->handle.u.mask;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
static js_arraybuffer_t
|
|
2701
|
+
bare_ffmpeg_channel_layout_from_mask(
|
|
2702
|
+
js_env_t *env,
|
|
2703
|
+
js_receiver_t,
|
|
2704
|
+
uint64_t mask
|
|
2705
|
+
) {
|
|
2706
|
+
int err;
|
|
2707
|
+
|
|
2708
|
+
js_arraybuffer_t result;
|
|
2709
|
+
|
|
2710
|
+
bare_ffmpeg_channel_layout_t *layout;
|
|
2711
|
+
err = js_create_arraybuffer(env, layout, result);
|
|
2712
|
+
assert(err == 0);
|
|
2713
|
+
|
|
2714
|
+
err = av_channel_layout_from_mask(&layout->handle, mask);
|
|
2715
|
+
assert(err == 0);
|
|
2716
|
+
|
|
2717
|
+
return result;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
static js_arraybuffer_t
|
|
2721
|
+
bare_ffmpeg_audio_fifo_init(
|
|
2722
|
+
js_env_t *env,
|
|
2723
|
+
js_receiver_t,
|
|
2724
|
+
int32_t sample_fmt,
|
|
2725
|
+
int32_t channels,
|
|
2726
|
+
int32_t nb_samples
|
|
2727
|
+
) {
|
|
2728
|
+
int err;
|
|
2729
|
+
|
|
2730
|
+
js_arraybuffer_t handle;
|
|
2731
|
+
|
|
2732
|
+
bare_ffmpeg_audio_fifo_t *fifo;
|
|
2733
|
+
err = js_create_arraybuffer(env, fifo, handle);
|
|
2734
|
+
assert(err == 0);
|
|
2735
|
+
|
|
2736
|
+
fifo->handle = av_audio_fifo_alloc(
|
|
2737
|
+
static_cast<AVSampleFormat>(sample_fmt),
|
|
2738
|
+
channels,
|
|
2739
|
+
nb_samples
|
|
2740
|
+
);
|
|
2741
|
+
|
|
2742
|
+
return handle;
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
static void
|
|
2746
|
+
bare_ffmpeg_audio_fifo_destroy(
|
|
2747
|
+
js_env_t *env,
|
|
2748
|
+
js_receiver_t,
|
|
2749
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo
|
|
2750
|
+
) {
|
|
2751
|
+
av_audio_fifo_free(fifo->handle);
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
static int
|
|
2755
|
+
bare_ffmpeg_audio_fifo_write(
|
|
2756
|
+
js_env_t *env,
|
|
2757
|
+
js_receiver_t,
|
|
2758
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo,
|
|
2759
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
2760
|
+
) {
|
|
2761
|
+
int err;
|
|
2762
|
+
|
|
2763
|
+
int len = av_audio_fifo_write(fifo->handle, (void **) frame->handle->data, frame->handle->nb_samples);
|
|
2764
|
+
|
|
2765
|
+
if (len < 0) {
|
|
2766
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2767
|
+
assert(err == 0);
|
|
2768
|
+
throw js_pending_exception;
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
return len;
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
static int
|
|
2775
|
+
bare_ffmpeg_audio_fifo_read(
|
|
2776
|
+
js_env_t *env,
|
|
2777
|
+
js_receiver_t,
|
|
2778
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo,
|
|
2779
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
2780
|
+
int32_t nb_samples
|
|
2781
|
+
) {
|
|
2782
|
+
int err;
|
|
2783
|
+
|
|
2784
|
+
int len = av_audio_fifo_read(fifo->handle, (void **) frame->handle->data, nb_samples);
|
|
2785
|
+
|
|
2786
|
+
if (len < 0) {
|
|
2787
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2788
|
+
assert(err == 0);
|
|
2789
|
+
throw js_pending_exception;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
return len;
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
static int
|
|
2796
|
+
bare_ffmpeg_audio_fifo_peek(
|
|
2797
|
+
js_env_t *env,
|
|
2798
|
+
js_receiver_t,
|
|
2799
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo,
|
|
2800
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
2801
|
+
int32_t nb_samples
|
|
2802
|
+
) {
|
|
2803
|
+
int err;
|
|
2804
|
+
|
|
2805
|
+
int len = av_audio_fifo_peek(fifo->handle, (void **) frame->handle->data, nb_samples);
|
|
2806
|
+
|
|
2807
|
+
if (len < 0) {
|
|
2808
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2809
|
+
assert(err == 0);
|
|
2810
|
+
throw js_pending_exception;
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
return len;
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
static int
|
|
2817
|
+
bare_ffmpeg_audio_fifo_drain(
|
|
2818
|
+
js_env_t *env,
|
|
2819
|
+
js_receiver_t,
|
|
2820
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo,
|
|
2821
|
+
int32_t nb_samples
|
|
2822
|
+
) {
|
|
2823
|
+
int err;
|
|
2824
|
+
|
|
2825
|
+
int len = av_audio_fifo_drain(fifo->handle, nb_samples);
|
|
2826
|
+
|
|
2827
|
+
if (len < 0) {
|
|
2828
|
+
err = js_throw_error(env, NULL, av_err2str(len));
|
|
2829
|
+
assert(err == 0);
|
|
2830
|
+
throw js_pending_exception;
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
return len;
|
|
2834
|
+
}
|
|
2835
|
+
|
|
2836
|
+
static void
|
|
2837
|
+
bare_ffmpeg_audio_fifo_reset(
|
|
2838
|
+
js_env_t *env,
|
|
2839
|
+
js_receiver_t,
|
|
2840
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo
|
|
2841
|
+
) {
|
|
2842
|
+
av_audio_fifo_reset(fifo->handle);
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
static int
|
|
2846
|
+
bare_ffmpeg_audio_fifo_size(
|
|
2847
|
+
js_env_t *env,
|
|
2848
|
+
js_receiver_t,
|
|
2849
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo
|
|
2850
|
+
) {
|
|
2851
|
+
return av_audio_fifo_size(fifo->handle);
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
static int
|
|
2855
|
+
bare_ffmpeg_audio_fifo_space(
|
|
2856
|
+
js_env_t *env,
|
|
2857
|
+
js_receiver_t,
|
|
2858
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_audio_fifo_t, 1> fifo
|
|
2859
|
+
) {
|
|
2860
|
+
return av_audio_fifo_space(fifo->handle);
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
static js_arraybuffer_t
|
|
2864
|
+
bare_ffmpeg_rational_d2q(
|
|
2865
|
+
js_env_t *env,
|
|
2866
|
+
js_receiver_t,
|
|
2867
|
+
double num
|
|
2868
|
+
) {
|
|
2869
|
+
constexpr int safe_max = 1 << 26;
|
|
2870
|
+
|
|
2871
|
+
auto rational = av_d2q(num, safe_max);
|
|
2872
|
+
|
|
2873
|
+
int err;
|
|
2874
|
+
|
|
2875
|
+
js_arraybuffer_t result;
|
|
2876
|
+
|
|
2877
|
+
int32_t *data;
|
|
2878
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
2879
|
+
assert(err == 0);
|
|
2880
|
+
|
|
2881
|
+
data[0] = rational.num;
|
|
2882
|
+
data[1] = rational.den;
|
|
2883
|
+
|
|
2884
|
+
return result;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
static js_value_t *
|
|
2888
|
+
bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
2889
|
+
uv_once(&bare_ffmpeg__init_guard, bare_ffmpeg__on_init);
|
|
2890
|
+
|
|
2891
|
+
int err;
|
|
2892
|
+
|
|
2893
|
+
#define V(name, fn) \
|
|
2894
|
+
err = js_set_property<fn>(env, exports, name); \
|
|
2895
|
+
assert(err == 0);
|
|
2896
|
+
|
|
2897
|
+
V("getLogLevel", bare_ffmpeg_log_get_level);
|
|
2898
|
+
V("setLogLevel", bare_ffmpeg_log_set_level);
|
|
2899
|
+
|
|
2900
|
+
V("initIOContext", bare_ffmpeg_io_context_init)
|
|
2901
|
+
V("destroyIOContext", bare_ffmpeg_io_context_destroy)
|
|
2902
|
+
|
|
2903
|
+
V("initOutputFormat", bare_ffmpeg_output_format_init)
|
|
2904
|
+
V("initInputFormat", bare_ffmpeg_input_format_init)
|
|
2905
|
+
V("getOutputFormatFlags", bare_ffmpeg_output_format_get_flags)
|
|
2906
|
+
V("getInputFormatFlags", bare_ffmpeg_input_format_get_flags)
|
|
2907
|
+
|
|
2908
|
+
V("openInputFormatContextWithIO", bare_ffmpeg_format_context_open_input_with_io)
|
|
2909
|
+
V("openInputFormatContextWithFormat", bare_ffmpeg_format_context_open_input_with_format)
|
|
2910
|
+
V("closeInputFormatContext", bare_ffmpeg_format_context_close_input)
|
|
2911
|
+
V("openOutputFormatContext", bare_ffmpeg_format_context_open_output)
|
|
2912
|
+
V("closeOutputFormatContext", bare_ffmpeg_format_context_close_output)
|
|
2913
|
+
V("getFormatContextStreams", bare_ffmpeg_format_context_get_streams)
|
|
2914
|
+
V("getFormatContextBestStreamIndex", bare_ffmpeg_format_context_get_best_stream_index)
|
|
2915
|
+
V("createFormatContextStream", bare_ffmpeg_format_context_create_stream)
|
|
2916
|
+
V("readFormatContextFrame", bare_ffmpeg_format_context_read_frame)
|
|
2917
|
+
V("writeFormatContextHeader", bare_ffmpeg_format_context_write_header)
|
|
2918
|
+
V("writeFormatContextFrame", bare_ffmpeg_format_context_write_frame)
|
|
2919
|
+
V("writeFormatContextTrailer", bare_ffmpeg_format_context_write_trailer)
|
|
2920
|
+
V("dumpFormatContext", bare_ffmpeg_format_context_dump)
|
|
2921
|
+
|
|
2922
|
+
V("getStreamIndex", bare_ffmpeg_stream_get_index)
|
|
2923
|
+
V("getStreamId", bare_ffmpeg_stream_get_id)
|
|
2924
|
+
V("setStreamId", bare_ffmpeg_stream_set_id)
|
|
2925
|
+
V("getStreamTimeBase", bare_ffmpeg_stream_get_time_base)
|
|
2926
|
+
V("setStreamTimeBase", bare_ffmpeg_stream_set_time_base)
|
|
2927
|
+
V("getStreamAverageFramerate", bare_ffmpeg_stream_get_avg_framerate)
|
|
2928
|
+
V("setStreamAverageFramerate", bare_ffmpeg_stream_set_avg_framerate)
|
|
2929
|
+
V("getStreamCodecParameters", bare_ffmpeg_stream_get_codec_parameters)
|
|
2930
|
+
|
|
2931
|
+
V("findDecoderByID", bare_ffmpeg_find_decoder_by_id)
|
|
2932
|
+
V("findEncoderByID", bare_ffmpeg_find_encoder_by_id)
|
|
2933
|
+
V("getCodecNameByID", bare_ffmpeg_get_codec_name_by_id)
|
|
2934
|
+
|
|
2935
|
+
V("initCodecContext", bare_ffmpeg_codec_context_init)
|
|
2936
|
+
V("destroyCodecContext", bare_ffmpeg_codec_context_destroy)
|
|
2937
|
+
V("openCodecContext", bare_ffmpeg_codec_context_open)
|
|
2938
|
+
V("openCodecContextWithOptions", bare_ffmpeg_codec_context_open_with_options)
|
|
2939
|
+
V("getCodecContextFlags", bare_ffmpeg_codec_context_get_flags)
|
|
2940
|
+
V("setCodecContextFlags", bare_ffmpeg_codec_context_set_flags)
|
|
2941
|
+
V("getCodecContextPixelFormat", bare_ffmpeg_codec_context_get_pixel_format)
|
|
2942
|
+
V("setCodecContextPixelFormat", bare_ffmpeg_codec_context_set_pixel_format)
|
|
2943
|
+
V("getCodecContextWidth", bare_ffmpeg_codec_context_get_width)
|
|
2944
|
+
V("setCodecContextWidth", bare_ffmpeg_codec_context_set_width)
|
|
2945
|
+
V("getCodecContextHeight", bare_ffmpeg_codec_context_get_height)
|
|
2946
|
+
V("setCodecContextHeight", bare_ffmpeg_codec_context_set_height)
|
|
2947
|
+
V("getCodecContextSampleFormat", bare_ffmpeg_codec_context_get_sample_format)
|
|
2948
|
+
V("setCodecContextSampleFormat", bare_ffmpeg_codec_context_set_sample_format)
|
|
2949
|
+
V("getCodecContextTimeBase", bare_ffmpeg_codec_context_get_time_base)
|
|
2950
|
+
V("setCodecContextTimeBase", bare_ffmpeg_codec_context_set_time_base)
|
|
2951
|
+
V("getCodecContextChannelLayout", bare_ffmpeg_codec_context_get_channel_layout);
|
|
2952
|
+
V("setCodecContextChannelLayout", bare_ffmpeg_codec_context_set_channel_layout);
|
|
2953
|
+
V("getCodecContextSampleRate", bare_ffmpeg_codec_context_get_sample_rate);
|
|
2954
|
+
V("setCodecContextSampleRate", bare_ffmpeg_codec_context_set_sample_rate);
|
|
2955
|
+
V("getCodecContextGOPSize", bare_ffmpeg_codec_context_get_gop_size)
|
|
2956
|
+
V("setCodecContextGOPSize", bare_ffmpeg_codec_context_set_gop_size)
|
|
2957
|
+
V("getCodecContextFramerate", bare_ffmpeg_codec_context_get_framerate)
|
|
2958
|
+
V("setCodecContextFramerate", bare_ffmpeg_codec_context_set_framerate)
|
|
2959
|
+
|
|
2960
|
+
V("sendCodecContextPacket", bare_ffmpeg_codec_context_send_packet)
|
|
2961
|
+
V("receiveCodecContextPacket", bare_ffmpeg_codec_context_receive_packet)
|
|
2962
|
+
V("sendCodecContextFrame", bare_ffmpeg_codec_context_send_frame)
|
|
2963
|
+
V("receiveCodecContextFrame", bare_ffmpeg_codec_context_receive_frame)
|
|
2964
|
+
|
|
2965
|
+
V("codecParametersFromContext", bare_ffmpeg_codec_parameters_from_context)
|
|
2966
|
+
V("codecParametersToContext", bare_ffmpeg_codec_parameters_to_context)
|
|
2967
|
+
V("allocCodecParameters", bare_ffmpeg_codec_parameters_alloc)
|
|
2968
|
+
V("destroyCodecParameters", bare_ffmpeg_codec_parameters_destroy)
|
|
2969
|
+
V("getCodecParametersBitRate", bare_ffmpeg_codec_parameters_get_bit_rate)
|
|
2970
|
+
V("setCodecParametersBitRate", bare_ffmpeg_codec_parameters_set_bit_rate)
|
|
2971
|
+
V("getCodecParametersBitsPerCodedSample", bare_ffmpeg_codec_parameters_get_bits_per_coded_sample)
|
|
2972
|
+
V("setCodecParametersBitsPerCodedSample", bare_ffmpeg_codec_parameters_set_bits_per_coded_sample)
|
|
2973
|
+
V("getCodecParametersBitsPerRawSample", bare_ffmpeg_codec_parameters_get_bits_per_raw_sample)
|
|
2974
|
+
V("setCodecParametersBitsPerRawSample", bare_ffmpeg_codec_parameters_set_bits_per_raw_sample)
|
|
2975
|
+
V("getCodecParametersSampleRate", bare_ffmpeg_codec_parameters_get_sample_rate)
|
|
2976
|
+
V("setCodecParametersSampleRate", bare_ffmpeg_codec_parameters_set_sample_rate)
|
|
2977
|
+
V("getCodecParametersFramerate", bare_ffmpeg_codec_parameters_get_framerate)
|
|
2978
|
+
V("setCodecParametersFramerate", bare_ffmpeg_codec_parameters_set_framerate)
|
|
2979
|
+
V("getCodecParametersNbChannels", bare_ffmpeg_codec_parameters_get_nb_channels)
|
|
2980
|
+
V("setCodecParametersNbChannels", bare_ffmpeg_codec_parameters_set_nb_channels)
|
|
2981
|
+
V("getCodecParametersType", bare_ffmpeg_codec_parameters_get_type)
|
|
2982
|
+
V("setCodecParametersType", bare_ffmpeg_codec_parameters_set_type)
|
|
2983
|
+
V("getCodecParametersTag", bare_ffmpeg_codec_parameters_get_tag)
|
|
2984
|
+
V("setCodecParametersTag", bare_ffmpeg_codec_parameters_set_tag)
|
|
2985
|
+
V("getCodecParametersId", bare_ffmpeg_codec_parameters_get_id)
|
|
2986
|
+
V("setCodecParametersId", bare_ffmpeg_codec_parameters_set_id)
|
|
2987
|
+
V("getCodecParametersLevel", bare_ffmpeg_codec_parameters_get_level)
|
|
2988
|
+
V("setCodecParametersLevel", bare_ffmpeg_codec_parameters_set_level)
|
|
2989
|
+
V("getCodecParametersProfile", bare_ffmpeg_codec_parameters_get_profile)
|
|
2990
|
+
V("setCodecParametersProfile", bare_ffmpeg_codec_parameters_set_profile)
|
|
2991
|
+
V("getCodecParametersFormat", bare_ffmpeg_codec_parameters_get_format)
|
|
2992
|
+
V("setCodecParametersFormat", bare_ffmpeg_codec_parameters_set_format)
|
|
2993
|
+
V("getCodecParametersChannelLayout", bare_ffmpeg_codec_parameters_get_channel_layout)
|
|
2994
|
+
V("setCodecParametersChannelLayout", bare_ffmpeg_codec_parameters_set_channel_layout)
|
|
2995
|
+
V("getCodecParametersWidth", bare_ffmpeg_codec_parameters_get_width)
|
|
2996
|
+
V("setCodecParametersWidth", bare_ffmpeg_codec_parameters_set_width)
|
|
2997
|
+
V("getCodecParametersHeight", bare_ffmpeg_codec_parameters_get_height)
|
|
2998
|
+
V("setCodecParametersHeight", bare_ffmpeg_codec_parameters_set_height)
|
|
2999
|
+
V("getCodecParametersExtraData", bare_ffmpeg_codec_parameters_get_extra_data)
|
|
3000
|
+
V("setCodecParametersExtraData", bare_ffmpeg_codec_parameters_set_extra_data)
|
|
3001
|
+
V("getCodecParametersBlockAlign", bare_ffmpeg_codec_parameters_get_block_align)
|
|
3002
|
+
V("setCodecParametersBlockAlign", bare_ffmpeg_codec_parameters_set_block_align)
|
|
3003
|
+
V("getCodecParametersInitialPadding", bare_ffmpeg_codec_parameters_get_initial_padding)
|
|
3004
|
+
V("setCodecParametersInitialPadding", bare_ffmpeg_codec_parameters_set_initial_padding)
|
|
3005
|
+
V("getCodecParametersTrailingPadding", bare_ffmpeg_codec_parameters_get_trailing_padding)
|
|
3006
|
+
V("setCodecParametersTrailingPadding", bare_ffmpeg_codec_parameters_set_trailing_padding)
|
|
3007
|
+
V("getCodecParametersSeekPreroll", bare_ffmpeg_codec_parameters_get_seek_preroll)
|
|
3008
|
+
V("setCodecParametersSeekPreroll", bare_ffmpeg_codec_parameters_set_seek_preroll)
|
|
3009
|
+
V("getCodecParametersSampleAspectRatio", bare_ffmpeg_codec_parameters_get_sample_aspect_ratio)
|
|
3010
|
+
V("setCodecParametersSampleAspectRatio", bare_ffmpeg_codec_parameters_set_sample_aspect_ratio)
|
|
3011
|
+
V("getCodecParametersVideoDelay", bare_ffmpeg_codec_parameters_get_video_delay)
|
|
3012
|
+
V("setCodecParametersVideoDelay", bare_ffmpeg_codec_parameters_set_video_delay)
|
|
3013
|
+
|
|
3014
|
+
V("initFrame", bare_ffmpeg_frame_init)
|
|
3015
|
+
V("destroyFrame", bare_ffmpeg_frame_destroy)
|
|
3016
|
+
V("unrefFrame", bare_ffmpeg_frame_unref)
|
|
3017
|
+
V("getFrameWidth", bare_ffmpeg_frame_get_width)
|
|
3018
|
+
V("setFrameWidth", bare_ffmpeg_frame_set_width)
|
|
3019
|
+
V("getFrameHeight", bare_ffmpeg_frame_get_height)
|
|
3020
|
+
V("setFrameHeight", bare_ffmpeg_frame_set_height)
|
|
3021
|
+
V("getFramePixelFormat", bare_ffmpeg_frame_get_pixel_format)
|
|
3022
|
+
V("setFramePixelFormat", bare_ffmpeg_frame_set_pixel_format)
|
|
3023
|
+
V("getFrameFormat", bare_ffmpeg_frame_get_format)
|
|
3024
|
+
V("setFrameFormat", bare_ffmpeg_frame_set_format)
|
|
3025
|
+
V("getFrameChannelLayout", bare_ffmpeg_frame_get_channel_layout)
|
|
3026
|
+
V("setFrameChannelLayout", bare_ffmpeg_frame_set_channel_layout)
|
|
3027
|
+
V("getFrameNbSamples", bare_ffmpeg_frame_get_nb_samples)
|
|
3028
|
+
V("setFrameNbSamples", bare_ffmpeg_frame_set_nb_samples)
|
|
3029
|
+
V("getFramePictType", bare_ffmpeg_frame_get_pict_type)
|
|
3030
|
+
V("getFramePTS", bare_ffmpeg_frame_get_pts)
|
|
3031
|
+
V("setFramePTS", bare_ffmpeg_frame_set_pts)
|
|
3032
|
+
V("getFramePacketDTS", bare_ffmpeg_frame_get_pkt_dts)
|
|
3033
|
+
V("setFramePacketDTS", bare_ffmpeg_frame_set_pkt_dts)
|
|
3034
|
+
V("getFrameTimeBase", bare_ffmpeg_frame_get_time_base)
|
|
3035
|
+
V("setFrameTimeBase", bare_ffmpeg_frame_set_time_base)
|
|
3036
|
+
V("allocFrame", bare_ffmpeg_frame_alloc)
|
|
3037
|
+
|
|
3038
|
+
V("initImage", bare_ffmpeg_image_init)
|
|
3039
|
+
V("fillImage", bare_ffmpeg_image_fill)
|
|
3040
|
+
V("readImage", bare_ffmpeg_image_read)
|
|
3041
|
+
V("getImageLineSize", bare_ffmpeg_image_get_line_size)
|
|
3042
|
+
|
|
3043
|
+
V("initSamples", bare_ffmpeg_samples_init)
|
|
3044
|
+
V("fillSamples", bare_ffmpeg_samples_fill)
|
|
3045
|
+
|
|
3046
|
+
V("initPacket", bare_ffmpeg_packet_init)
|
|
3047
|
+
V("initPacketFromBuffer", bare_ffmpeg_packet_init_from_buffer)
|
|
3048
|
+
V("unrefPacket", bare_ffmpeg_packet_unref)
|
|
3049
|
+
V("getPacketStreamIndex", bare_ffmpeg_packet_get_stream_index)
|
|
3050
|
+
V("setPacketStreamIndex", bare_ffmpeg_packet_set_stream_index)
|
|
3051
|
+
V("getPacketData", bare_ffmpeg_packet_get_data)
|
|
3052
|
+
V("setPacketData", bare_ffmpeg_packet_set_data)
|
|
3053
|
+
V("isPacketKeyframe", bare_ffmpeg_packet_is_keyframe)
|
|
3054
|
+
V("getPacketDTS", bare_ffmpeg_packet_get_dts)
|
|
3055
|
+
V("setPacketDTS", bare_ffmpeg_packet_set_dts)
|
|
3056
|
+
V("getPacketPTS", bare_ffmpeg_packet_get_pts)
|
|
3057
|
+
V("setPacketPTS", bare_ffmpeg_packet_set_pts)
|
|
3058
|
+
V("getPacketTimeBase", bare_ffmpeg_packet_get_time_base)
|
|
3059
|
+
V("setPacketTimeBase", bare_ffmpeg_packet_set_time_base)
|
|
3060
|
+
V("rescalePacketTimestamps", bare_ffmpeg_packet_rescale_ts)
|
|
3061
|
+
V("getPacketDuration", bare_ffmpeg_packet_get_duration)
|
|
3062
|
+
V("setPacketDuration", bare_ffmpeg_packet_set_duration)
|
|
3063
|
+
V("getPacketFlags", bare_ffmpeg_packet_get_flags)
|
|
3064
|
+
V("setPacketFlags", bare_ffmpeg_packet_set_flags)
|
|
3065
|
+
|
|
3066
|
+
V("initScaler", bare_ffmpeg_scaler_init)
|
|
3067
|
+
V("destroyScaler", bare_ffmpeg_scaler_destroy)
|
|
3068
|
+
V("scaleScaler", bare_ffmpeg_scaler_scale)
|
|
3069
|
+
|
|
3070
|
+
V("initDictionary", bare_ffmpeg_dictionary_init)
|
|
3071
|
+
V("destroyDictionary", bare_ffmpeg_dictionary_destroy)
|
|
3072
|
+
V("getDictionaryEntry", bare_ffmpeg_dictionary_get_entry)
|
|
3073
|
+
V("setDictionaryEntry", bare_ffmpeg_dictionary_set_entry)
|
|
3074
|
+
V("getDictionaryEntries", bare_ffmpeg_dictionary_get_entries)
|
|
3075
|
+
|
|
3076
|
+
V("initResampler", bare_ffmpeg_resampler_init)
|
|
3077
|
+
V("destroyResampler", bare_ffmpeg_resampler_destroy)
|
|
3078
|
+
V("convertResampler", bare_ffmpeg_resampler_convert_frames)
|
|
3079
|
+
V("getResamplerDelay", bare_ffmpeg_resampler_get_delay)
|
|
3080
|
+
V("flushResampler", bare_ffmpeg_resampler_flush)
|
|
3081
|
+
|
|
3082
|
+
V("copyChannelLayout", bare_ffmpeg_channel_layout_copy)
|
|
3083
|
+
V("getChannelLayoutNbChannels", bare_ffmpeg_channel_layout_get_nb_channels)
|
|
3084
|
+
V("getChannelLayoutMask", bare_ffmpeg_channel_layout_get_mask)
|
|
3085
|
+
V("channelLayoutFromMask", bare_ffmpeg_channel_layout_from_mask)
|
|
3086
|
+
|
|
3087
|
+
V("initAudioFifo", bare_ffmpeg_audio_fifo_init)
|
|
3088
|
+
V("destroyAudioFifo", bare_ffmpeg_audio_fifo_destroy)
|
|
3089
|
+
V("writeAudioFifo", bare_ffmpeg_audio_fifo_write)
|
|
3090
|
+
V("readAudioFifo", bare_ffmpeg_audio_fifo_read)
|
|
3091
|
+
V("peekAudioFifo", bare_ffmpeg_audio_fifo_peek)
|
|
3092
|
+
V("drainAudioFifo", bare_ffmpeg_audio_fifo_drain)
|
|
3093
|
+
V("resetAudioFifo", bare_ffmpeg_audio_fifo_reset)
|
|
3094
|
+
V("getAudioFifoSize", bare_ffmpeg_audio_fifo_size)
|
|
3095
|
+
V("getAudioFifoSpace", bare_ffmpeg_audio_fifo_space)
|
|
3096
|
+
|
|
3097
|
+
V("rationalD2Q", bare_ffmpeg_rational_d2q)
|
|
3098
|
+
#undef V
|
|
3099
|
+
|
|
3100
|
+
#define V(name) \
|
|
3101
|
+
{ \
|
|
3102
|
+
js_value_t *val; \
|
|
3103
|
+
err = js_create_int64(env, name, &val); \
|
|
3104
|
+
assert(err == 0); \
|
|
3105
|
+
err = js_set_named_property(env, exports, #name, val); \
|
|
3106
|
+
assert(err == 0); \
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
V(AV_LOG_QUIET)
|
|
3110
|
+
V(AV_LOG_PANIC)
|
|
3111
|
+
V(AV_LOG_FATAL)
|
|
3112
|
+
V(AV_LOG_ERROR)
|
|
3113
|
+
V(AV_LOG_WARNING)
|
|
3114
|
+
V(AV_LOG_INFO)
|
|
3115
|
+
V(AV_LOG_VERBOSE)
|
|
3116
|
+
V(AV_LOG_DEBUG)
|
|
3117
|
+
V(AV_LOG_TRACE)
|
|
3118
|
+
|
|
3119
|
+
V(AV_CODEC_ID_MJPEG)
|
|
3120
|
+
V(AV_CODEC_ID_H264)
|
|
3121
|
+
V(AV_CODEC_ID_AAC)
|
|
3122
|
+
V(AV_CODEC_ID_OPUS)
|
|
3123
|
+
V(AV_CODEC_ID_AV1)
|
|
3124
|
+
V(AV_CODEC_ID_FLAC)
|
|
3125
|
+
V(AV_CODEC_ID_MP3)
|
|
3126
|
+
|
|
3127
|
+
V(AV_CODEC_FLAG_COPY_OPAQUE)
|
|
3128
|
+
V(AV_CODEC_FLAG_FRAME_DURATION)
|
|
3129
|
+
V(AV_CODEC_FLAG_PASS1)
|
|
3130
|
+
V(AV_CODEC_FLAG_PASS2)
|
|
3131
|
+
V(AV_CODEC_FLAG_LOOP_FILTER)
|
|
3132
|
+
V(AV_CODEC_FLAG_GRAY)
|
|
3133
|
+
V(AV_CODEC_FLAG_PSNR)
|
|
3134
|
+
V(AV_CODEC_FLAG_INTERLACED_DCT)
|
|
3135
|
+
V(AV_CODEC_FLAG_LOW_DELAY)
|
|
3136
|
+
V(AV_CODEC_FLAG_GLOBAL_HEADER)
|
|
3137
|
+
V(AV_CODEC_FLAG_BITEXACT)
|
|
3138
|
+
V(AV_CODEC_FLAG_AC_PRED)
|
|
3139
|
+
V(AV_CODEC_FLAG_INTERLACED_ME)
|
|
3140
|
+
V(AV_CODEC_FLAG_CLOSED_GOP)
|
|
3141
|
+
|
|
3142
|
+
V(AV_PIX_FMT_RGBA)
|
|
3143
|
+
V(AV_PIX_FMT_RGB24)
|
|
3144
|
+
V(AV_PIX_FMT_YUVJ420P)
|
|
3145
|
+
V(AV_PIX_FMT_YUV420P)
|
|
3146
|
+
V(AV_PIX_FMT_UYVY422)
|
|
3147
|
+
|
|
3148
|
+
V(AVMEDIA_TYPE_UNKNOWN)
|
|
3149
|
+
V(AVMEDIA_TYPE_VIDEO)
|
|
3150
|
+
V(AVMEDIA_TYPE_AUDIO)
|
|
3151
|
+
V(AVMEDIA_TYPE_DATA)
|
|
3152
|
+
V(AVMEDIA_TYPE_SUBTITLE)
|
|
3153
|
+
V(AVMEDIA_TYPE_ATTACHMENT)
|
|
3154
|
+
V(AVMEDIA_TYPE_NB)
|
|
3155
|
+
|
|
3156
|
+
V(AV_SAMPLE_FMT_NONE)
|
|
3157
|
+
V(AV_SAMPLE_FMT_U8)
|
|
3158
|
+
V(AV_SAMPLE_FMT_S16)
|
|
3159
|
+
V(AV_SAMPLE_FMT_S32)
|
|
3160
|
+
V(AV_SAMPLE_FMT_FLT)
|
|
3161
|
+
V(AV_SAMPLE_FMT_DBL)
|
|
3162
|
+
V(AV_SAMPLE_FMT_U8P)
|
|
3163
|
+
V(AV_SAMPLE_FMT_S16P)
|
|
3164
|
+
V(AV_SAMPLE_FMT_S32P)
|
|
3165
|
+
V(AV_SAMPLE_FMT_FLTP)
|
|
3166
|
+
V(AV_SAMPLE_FMT_DBLP)
|
|
3167
|
+
V(AV_SAMPLE_FMT_S64)
|
|
3168
|
+
V(AV_SAMPLE_FMT_S64P)
|
|
3169
|
+
V(AV_SAMPLE_FMT_NB)
|
|
3170
|
+
|
|
3171
|
+
V(AV_CH_LAYOUT_MONO)
|
|
3172
|
+
V(AV_CH_LAYOUT_STEREO)
|
|
3173
|
+
V(AV_CH_LAYOUT_QUAD)
|
|
3174
|
+
V(AV_CH_LAYOUT_SURROUND)
|
|
3175
|
+
V(AV_CH_LAYOUT_2POINT1)
|
|
3176
|
+
V(AV_CH_LAYOUT_5POINT0)
|
|
3177
|
+
V(AV_CH_LAYOUT_5POINT1)
|
|
3178
|
+
V(AV_CH_LAYOUT_7POINT1)
|
|
3179
|
+
|
|
3180
|
+
V(AV_PICTURE_TYPE_NONE)
|
|
3181
|
+
V(AV_PICTURE_TYPE_I)
|
|
3182
|
+
V(AV_PICTURE_TYPE_P)
|
|
3183
|
+
V(AV_PICTURE_TYPE_B)
|
|
3184
|
+
V(AV_PICTURE_TYPE_S)
|
|
3185
|
+
V(AV_PICTURE_TYPE_SI)
|
|
3186
|
+
V(AV_PICTURE_TYPE_SP)
|
|
3187
|
+
V(AV_PICTURE_TYPE_BI)
|
|
3188
|
+
|
|
3189
|
+
// InputFormat flags
|
|
3190
|
+
V(AVFMT_SHOW_IDS)
|
|
3191
|
+
V(AVFMT_GENERIC_INDEX)
|
|
3192
|
+
V(AVFMT_TS_DISCONT)
|
|
3193
|
+
V(AVFMT_NOBINSEARCH)
|
|
3194
|
+
V(AVFMT_NOGENSEARCH)
|
|
3195
|
+
V(AVFMT_NO_BYTE_SEEK)
|
|
3196
|
+
V(AVFMT_SEEK_TO_PTS)
|
|
3197
|
+
|
|
3198
|
+
// OutputFormat flags
|
|
3199
|
+
V(AVFMT_GLOBALHEADER)
|
|
3200
|
+
V(AVFMT_VARIABLE_FPS)
|
|
3201
|
+
V(AVFMT_NODIMENSIONS)
|
|
3202
|
+
V(AVFMT_NOSTREAMS)
|
|
3203
|
+
V(AVFMT_TS_NONSTRICT)
|
|
3204
|
+
V(AVFMT_TS_NEGATIVE)
|
|
3205
|
+
|
|
3206
|
+
// Common format flags
|
|
3207
|
+
V(AVFMT_NOFILE)
|
|
3208
|
+
V(AVFMT_NEEDNUMBER)
|
|
3209
|
+
V(AVFMT_NOTIMESTAMPS)
|
|
3210
|
+
|
|
3211
|
+
// Profile
|
|
3212
|
+
V(AV_PROFILE_UNKNOWN)
|
|
3213
|
+
V(AV_PROFILE_RESERVED)
|
|
3214
|
+
V(AV_PROFILE_AAC_MAIN)
|
|
3215
|
+
V(AV_PROFILE_AAC_LOW)
|
|
3216
|
+
V(AV_PROFILE_AAC_SSR)
|
|
3217
|
+
V(AV_PROFILE_AAC_LTP)
|
|
3218
|
+
V(AV_PROFILE_AAC_HE)
|
|
3219
|
+
V(AV_PROFILE_AAC_HE_V2)
|
|
3220
|
+
V(AV_PROFILE_AAC_LD)
|
|
3221
|
+
V(AV_PROFILE_AAC_ELD)
|
|
3222
|
+
V(AV_PROFILE_AAC_USAC)
|
|
3223
|
+
V(AV_PROFILE_MPEG2_AAC_LOW)
|
|
3224
|
+
V(AV_PROFILE_MPEG2_AAC_HE)
|
|
3225
|
+
V(AV_PROFILE_DNXHD)
|
|
3226
|
+
V(AV_PROFILE_DNXHR_LB)
|
|
3227
|
+
V(AV_PROFILE_DNXHR_SQ)
|
|
3228
|
+
V(AV_PROFILE_DNXHR_HQ)
|
|
3229
|
+
V(AV_PROFILE_DNXHR_HQX)
|
|
3230
|
+
V(AV_PROFILE_DNXHR_444)
|
|
3231
|
+
V(AV_PROFILE_DTS)
|
|
3232
|
+
V(AV_PROFILE_DTS_ES)
|
|
3233
|
+
V(AV_PROFILE_DTS_96_24)
|
|
3234
|
+
V(AV_PROFILE_DTS_HD_HRA)
|
|
3235
|
+
V(AV_PROFILE_DTS_HD_MA)
|
|
3236
|
+
V(AV_PROFILE_DTS_EXPRESS)
|
|
3237
|
+
V(AV_PROFILE_DTS_HD_MA_X)
|
|
3238
|
+
V(AV_PROFILE_DTS_HD_MA_X_IMAX)
|
|
3239
|
+
V(AV_PROFILE_EAC3_DDP_ATMOS)
|
|
3240
|
+
V(AV_PROFILE_TRUEHD_ATMOS)
|
|
3241
|
+
V(AV_PROFILE_MPEG2_422)
|
|
3242
|
+
V(AV_PROFILE_MPEG2_HIGH)
|
|
3243
|
+
V(AV_PROFILE_MPEG2_SS)
|
|
3244
|
+
V(AV_PROFILE_MPEG2_SNR_SCALABLE)
|
|
3245
|
+
V(AV_PROFILE_MPEG2_MAIN)
|
|
3246
|
+
V(AV_PROFILE_MPEG2_SIMPLE)
|
|
3247
|
+
V(AV_PROFILE_H264_CONSTRAINED)
|
|
3248
|
+
V(AV_PROFILE_H264_INTRA)
|
|
3249
|
+
V(AV_PROFILE_H264_BASELINE)
|
|
3250
|
+
V(AV_PROFILE_H264_CONSTRAINED_BASELINE)
|
|
3251
|
+
V(AV_PROFILE_H264_MAIN)
|
|
3252
|
+
V(AV_PROFILE_H264_EXTENDED)
|
|
3253
|
+
V(AV_PROFILE_H264_HIGH)
|
|
3254
|
+
V(AV_PROFILE_H264_HIGH_10)
|
|
3255
|
+
V(AV_PROFILE_H264_HIGH_10_INTRA)
|
|
3256
|
+
V(AV_PROFILE_H264_MULTIVIEW_HIGH)
|
|
3257
|
+
V(AV_PROFILE_H264_HIGH_422)
|
|
3258
|
+
V(AV_PROFILE_H264_HIGH_422_INTRA)
|
|
3259
|
+
V(AV_PROFILE_H264_STEREO_HIGH)
|
|
3260
|
+
V(AV_PROFILE_H264_HIGH_444)
|
|
3261
|
+
V(AV_PROFILE_H264_HIGH_444_PREDICTIVE)
|
|
3262
|
+
V(AV_PROFILE_H264_HIGH_444_INTRA)
|
|
3263
|
+
V(AV_PROFILE_H264_CAVLC_444)
|
|
3264
|
+
V(AV_PROFILE_VC1_SIMPLE)
|
|
3265
|
+
V(AV_PROFILE_VC1_MAIN)
|
|
3266
|
+
V(AV_PROFILE_VC1_COMPLEX)
|
|
3267
|
+
V(AV_PROFILE_VC1_ADVANCED)
|
|
3268
|
+
V(AV_PROFILE_MPEG4_SIMPLE)
|
|
3269
|
+
V(AV_PROFILE_MPEG4_SIMPLE_SCALABLE)
|
|
3270
|
+
V(AV_PROFILE_MPEG4_CORE)
|
|
3271
|
+
V(AV_PROFILE_MPEG4_MAIN)
|
|
3272
|
+
V(AV_PROFILE_MPEG4_N_BIT)
|
|
3273
|
+
V(AV_PROFILE_MPEG4_SCALABLE_TEXTURE)
|
|
3274
|
+
V(AV_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION)
|
|
3275
|
+
V(AV_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE)
|
|
3276
|
+
V(AV_PROFILE_MPEG4_HYBRID)
|
|
3277
|
+
V(AV_PROFILE_MPEG4_ADVANCED_REAL_TIME)
|
|
3278
|
+
V(AV_PROFILE_MPEG4_CORE_SCALABLE)
|
|
3279
|
+
V(AV_PROFILE_MPEG4_ADVANCED_CODING)
|
|
3280
|
+
V(AV_PROFILE_MPEG4_ADVANCED_CORE)
|
|
3281
|
+
V(AV_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE)
|
|
3282
|
+
V(AV_PROFILE_MPEG4_SIMPLE_STUDIO)
|
|
3283
|
+
V(AV_PROFILE_MPEG4_ADVANCED_SIMPLE)
|
|
3284
|
+
V(AV_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0)
|
|
3285
|
+
V(AV_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1)
|
|
3286
|
+
V(AV_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION)
|
|
3287
|
+
V(AV_PROFILE_JPEG2000_DCINEMA_2K)
|
|
3288
|
+
V(AV_PROFILE_JPEG2000_DCINEMA_4K)
|
|
3289
|
+
V(AV_PROFILE_VP9_0)
|
|
3290
|
+
V(AV_PROFILE_VP9_1)
|
|
3291
|
+
V(AV_PROFILE_VP9_2)
|
|
3292
|
+
V(AV_PROFILE_VP9_3)
|
|
3293
|
+
V(AV_PROFILE_HEVC_MAIN)
|
|
3294
|
+
V(AV_PROFILE_HEVC_MAIN_10)
|
|
3295
|
+
V(AV_PROFILE_HEVC_MAIN_STILL_PICTURE)
|
|
3296
|
+
V(AV_PROFILE_HEVC_REXT)
|
|
3297
|
+
V(AV_PROFILE_HEVC_MULTIVIEW_MAIN)
|
|
3298
|
+
V(AV_PROFILE_HEVC_SCC)
|
|
3299
|
+
V(AV_PROFILE_VVC_MAIN_10)
|
|
3300
|
+
V(AV_PROFILE_VVC_MAIN_10_444)
|
|
3301
|
+
V(AV_PROFILE_AV1_MAIN)
|
|
3302
|
+
V(AV_PROFILE_AV1_HIGH)
|
|
3303
|
+
V(AV_PROFILE_AV1_PROFESSIONAL)
|
|
3304
|
+
V(AV_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT)
|
|
3305
|
+
V(AV_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT)
|
|
3306
|
+
V(AV_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT)
|
|
3307
|
+
V(AV_PROFILE_MJPEG_HUFFMAN_LOSSLESS)
|
|
3308
|
+
V(AV_PROFILE_MJPEG_JPEG_LS)
|
|
3309
|
+
V(AV_PROFILE_SBC_MSBC)
|
|
3310
|
+
V(AV_PROFILE_PRORES_PROXY)
|
|
3311
|
+
V(AV_PROFILE_PRORES_LT)
|
|
3312
|
+
V(AV_PROFILE_PRORES_STANDARD)
|
|
3313
|
+
V(AV_PROFILE_PRORES_HQ)
|
|
3314
|
+
V(AV_PROFILE_PRORES_4444)
|
|
3315
|
+
V(AV_PROFILE_PRORES_XQ)
|
|
3316
|
+
V(AV_PROFILE_ARIB_PROFILE_A)
|
|
3317
|
+
V(AV_PROFILE_ARIB_PROFILE_C)
|
|
3318
|
+
V(AV_PROFILE_KLVA_SYNC)
|
|
3319
|
+
V(AV_PROFILE_KLVA_ASYNC)
|
|
3320
|
+
V(AV_PROFILE_EVC_BASELINE)
|
|
3321
|
+
V(AV_PROFILE_EVC_MAIN)
|
|
3322
|
+
|
|
3323
|
+
// Levels
|
|
3324
|
+
V(AV_LEVEL_UNKNOWN)
|
|
3325
|
+
#undef V
|
|
3326
|
+
|
|
3327
|
+
return exports;
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
BARE_MODULE(bare_ffmpeg, bare_ffmpeg_exports)
|