bare-ffmpeg 1.0.0-32 → 1.0.0-33

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.
Files changed (34) hide show
  1. package/CMakeLists.txt +31 -9
  2. package/README.md +65 -1761
  3. package/binding.cc +734 -1
  4. package/cmake/ports/ffmpeg/port.cmake +8 -9
  5. package/cmake/ports/libdrm/port.cmake +32 -0
  6. package/cmake/ports/libva/port.cmake +53 -0
  7. package/cmake/ports/x264/port.cmake +7 -2
  8. package/index.js +6 -0
  9. package/lib/codec-context.js +9 -0
  10. package/lib/codec-parameters.js +32 -0
  11. package/lib/codec.js +1 -0
  12. package/lib/constants.js +118 -1
  13. package/lib/frame.js +19 -0
  14. package/lib/hw-device-context.js +31 -0
  15. package/lib/hw-frames-constraints.js +54 -0
  16. package/lib/hw-frames-context.js +92 -0
  17. package/package.json +1 -1
  18. package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
  19. package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
  20. package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
  21. package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
  22. package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
  23. package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
  24. package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
  25. package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
  26. package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
  27. package/prebuilds/linux-arm64/bare-ffmpeg/libva-drm.so.2 +0 -0
  28. package/prebuilds/linux-arm64/bare-ffmpeg/libva.so.2 +0 -0
  29. package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
  30. package/prebuilds/linux-x64/bare-ffmpeg/libva-drm.so.2 +0 -0
  31. package/prebuilds/linux-x64/bare-ffmpeg/libva.so.2 +0 -0
  32. package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
  33. package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
  34. package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
package/binding.cc CHANGED
@@ -29,11 +29,13 @@ extern "C" {
29
29
  #include <libavutil/dict.h>
30
30
  #include <libavutil/error.h>
31
31
  #include <libavutil/frame.h>
32
+ #include <libavutil/hwcontext.h>
32
33
  #include <libavutil/imgutils.h>
33
34
  #include <libavutil/log.h>
34
35
  #include <libavutil/mathematics.h>
35
36
  #include <libavutil/mem.h>
36
37
  #include <libavutil/opt.h>
38
+ #include <libavutil/pixdesc.h>
37
39
  #include <libavutil/pixfmt.h>
38
40
  #include <libavutil/rational.h>
39
41
  #include <libavutil/samplefmt.h>
@@ -134,6 +136,18 @@ typedef struct {
134
136
  AVFilterInOut *handle;
135
137
  } bare_ffmpeg_filter_inout_t;
136
138
 
139
+ typedef struct {
140
+ AVBufferRef *handle;
141
+ } bare_ffmpeg_hw_device_context_t;
142
+
143
+ typedef struct {
144
+ AVBufferRef *handle;
145
+ } bare_ffmpeg_hw_frames_context_t;
146
+
147
+ typedef struct {
148
+ AVHWFramesConstraints *handle;
149
+ } bare_ffmpeg_hw_frames_constraints_t;
150
+
137
151
  static uv_once_t bare_ffmpeg__init_guard = UV_ONCE_INIT;
138
152
 
139
153
  static void
@@ -628,7 +642,6 @@ bare_ffmpeg_format_context_create_stream(
628
642
  assert(err == 0);
629
643
 
630
644
  stream->handle = avformat_new_stream(context->handle, NULL);
631
-
632
645
  return handle;
633
646
  }
634
647
 
@@ -1302,6 +1315,77 @@ bare_ffmpeg_frame_copy_properties(
1302
1315
  }
1303
1316
  }
1304
1317
 
1318
+ static void
1319
+ bare_ffmpeg_frame_transfer_data(
1320
+ js_env_t *env,
1321
+ js_receiver_t,
1322
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> dst,
1323
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> src
1324
+ ) {
1325
+ int err = av_hwframe_transfer_data(dst->handle, src->handle, 0);
1326
+
1327
+ if (err < 0) {
1328
+ err = js_throw_error(env, NULL, av_err2str(err));
1329
+ assert(err == 0);
1330
+
1331
+ throw js_pending_exception;
1332
+ }
1333
+ }
1334
+
1335
+ static void
1336
+ bare_ffmpeg_frame_map(
1337
+ js_env_t *env,
1338
+ js_receiver_t,
1339
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> dst,
1340
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> src,
1341
+ int32_t flags
1342
+ ) {
1343
+ int err = av_hwframe_map(dst->handle, src->handle, flags);
1344
+
1345
+ if (err < 0) {
1346
+ err = js_throw_error(env, NULL, av_err2str(err));
1347
+ assert(err == 0);
1348
+
1349
+ throw js_pending_exception;
1350
+ }
1351
+ }
1352
+
1353
+ static std::optional<js_arraybuffer_t>
1354
+ bare_ffmpeg_frame_get_hw_frames_ctx(
1355
+ js_env_t *env,
1356
+ js_receiver_t,
1357
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
1358
+ ) {
1359
+ int err;
1360
+
1361
+ if (frame->handle->hw_frames_ctx == nullptr) {
1362
+ return std::nullopt;
1363
+ }
1364
+
1365
+ js_arraybuffer_t handle;
1366
+ bare_ffmpeg_hw_frames_context_t *hw_frames_ctx;
1367
+ err = js_create_arraybuffer(env, hw_frames_ctx, handle);
1368
+ assert(err == 0);
1369
+
1370
+ hw_frames_ctx->handle = av_buffer_ref(frame->handle->hw_frames_ctx);
1371
+
1372
+ return handle;
1373
+ }
1374
+
1375
+ static void
1376
+ bare_ffmpeg_frame_set_hw_frames_ctx(
1377
+ js_env_t *env,
1378
+ js_receiver_t,
1379
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
1380
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
1381
+ ) {
1382
+ if (frame->handle->hw_frames_ctx != nullptr) {
1383
+ av_buffer_unref(&frame->handle->hw_frames_ctx);
1384
+ }
1385
+
1386
+ frame->handle->hw_frames_ctx = av_buffer_ref(hw_frames_ctx->handle);
1387
+ }
1388
+
1305
1389
  static bool
1306
1390
  bare_ffmpeg_codec_context_open_with_options(
1307
1391
  js_env_t *env,
@@ -1590,6 +1674,42 @@ bare_ffmpeg_codec_context_set_request_sample_format(
1590
1674
  context->handle->request_sample_fmt = static_cast<AVSampleFormat>(sample_format);
1591
1675
  }
1592
1676
 
1677
+ static std::optional<js_arraybuffer_t>
1678
+ bare_ffmpeg_codec_context_get_hw_device_ctx(
1679
+ js_env_t *env,
1680
+ js_receiver_t,
1681
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
1682
+ ) {
1683
+ int err;
1684
+
1685
+ if (context->handle->hw_device_ctx == nullptr) {
1686
+ return std::nullopt;
1687
+ }
1688
+
1689
+ js_arraybuffer_t handle;
1690
+ bare_ffmpeg_hw_device_context_t *hw_device_ctx;
1691
+ err = js_create_arraybuffer(env, hw_device_ctx, handle);
1692
+ assert(err == 0);
1693
+
1694
+ hw_device_ctx->handle = av_buffer_ref(context->handle->hw_device_ctx);
1695
+
1696
+ return handle;
1697
+ }
1698
+
1699
+ static void
1700
+ bare_ffmpeg_codec_context_set_hw_device_ctx(
1701
+ js_env_t *env,
1702
+ js_receiver_t,
1703
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
1704
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_device_context_t, 1> hw_device_ctx
1705
+ ) {
1706
+ if (context->handle->hw_device_ctx != nullptr) {
1707
+ av_buffer_unref(&context->handle->hw_device_ctx);
1708
+ }
1709
+
1710
+ context->handle->hw_device_ctx = av_buffer_ref(hw_device_ctx->handle);
1711
+ }
1712
+
1593
1713
  static enum AVPixelFormat
1594
1714
  bare_ffmpeg__on_codec_context_get_format(struct AVCodecContext *input_context, const enum AVPixelFormat *fmt) {
1595
1715
  int err;
@@ -2275,6 +2395,163 @@ bare_ffmpeg_codec_parameters_set_frame_size(
2275
2395
  parameters->handle->frame_size = frame_size;
2276
2396
  }
2277
2397
 
2398
+ static int
2399
+ bare_ffmpeg_codec_parameters_get_color_space(
2400
+ js_env_t *env,
2401
+ js_receiver_t,
2402
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
2403
+ ) {
2404
+ return parameters->handle->color_space;
2405
+ }
2406
+
2407
+ static void
2408
+ bare_ffmpeg_codec_parameters_set_color_space(
2409
+ js_env_t *env,
2410
+ js_receiver_t,
2411
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
2412
+ int color_space
2413
+ ) {
2414
+ parameters->handle->color_space = static_cast<AVColorSpace>(color_space);
2415
+ }
2416
+
2417
+ static int
2418
+ bare_ffmpeg_codec_parameters_get_color_primaries(
2419
+ js_env_t *env,
2420
+ js_receiver_t,
2421
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
2422
+ ) {
2423
+ return parameters->handle->color_primaries;
2424
+ }
2425
+
2426
+ static void
2427
+ bare_ffmpeg_codec_parameters_set_color_primaries(
2428
+ js_env_t *env,
2429
+ js_receiver_t,
2430
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
2431
+ int color_primaries
2432
+ ) {
2433
+ parameters->handle->color_primaries = static_cast<AVColorPrimaries>(color_primaries);
2434
+ }
2435
+
2436
+ static int
2437
+ bare_ffmpeg_codec_parameters_get_color_trc(
2438
+ js_env_t *env,
2439
+ js_receiver_t,
2440
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
2441
+ ) {
2442
+ return parameters->handle->color_trc;
2443
+ }
2444
+
2445
+ static void
2446
+ bare_ffmpeg_codec_parameters_set_color_trc(
2447
+ js_env_t *env,
2448
+ js_receiver_t,
2449
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
2450
+ int color_trc
2451
+ ) {
2452
+ parameters->handle->color_trc = static_cast<AVColorTransferCharacteristic>(color_trc);
2453
+ }
2454
+
2455
+ static std::string
2456
+ bare_ffmpeg_color_space_name(
2457
+ js_env_t *env,
2458
+ js_receiver_t,
2459
+ int color_space
2460
+ ) {
2461
+ return av_color_space_name(static_cast<AVColorSpace>(color_space));
2462
+ }
2463
+
2464
+ static int
2465
+ bare_ffmpeg_color_space_from_name(
2466
+ js_env_t *env,
2467
+ js_receiver_t,
2468
+ std::string color_space_name
2469
+ ) {
2470
+ int id = av_color_space_from_name(color_space_name.c_str());
2471
+
2472
+ if (id < 0) {
2473
+ int err = js_throw_error(env, NULL, av_err2str(id));
2474
+ assert(err == 0);
2475
+
2476
+ throw js_pending_exception;
2477
+ }
2478
+
2479
+ return id;
2480
+ }
2481
+
2482
+ static std::string
2483
+ bare_ffmpeg_color_primaries_name(
2484
+ js_env_t *env,
2485
+ js_receiver_t,
2486
+ int color_primaries
2487
+ ) {
2488
+ return av_color_primaries_name(static_cast<AVColorPrimaries>(color_primaries));
2489
+ }
2490
+
2491
+ static int
2492
+ bare_ffmpeg_color_primaries_from_name(
2493
+ js_env_t *env,
2494
+ js_receiver_t,
2495
+ std::string color_primaries_name
2496
+ ) {
2497
+ int id = av_color_primaries_from_name(color_primaries_name.c_str());
2498
+
2499
+ if (id < 0) {
2500
+ int err = js_throw_error(env, NULL, av_err2str(id));
2501
+ assert(err == 0);
2502
+
2503
+ throw js_pending_exception;
2504
+ }
2505
+
2506
+ return id;
2507
+ }
2508
+
2509
+ static std::string
2510
+ bare_ffmpeg_color_transfer_name(
2511
+ js_env_t *env,
2512
+ js_receiver_t,
2513
+ int color_trc
2514
+ ) {
2515
+ return av_color_transfer_name(static_cast<AVColorTransferCharacteristic>(color_trc));
2516
+ }
2517
+
2518
+ static int
2519
+ bare_ffmpeg_color_transfer_from_name(
2520
+ js_env_t *env,
2521
+ js_receiver_t,
2522
+ std::string color_trc_name
2523
+ ) {
2524
+ int id = av_color_transfer_from_name(color_trc_name.c_str());
2525
+
2526
+ if (id < 0) {
2527
+ int err = js_throw_error(env, NULL, av_err2str(id));
2528
+ assert(err == 0);
2529
+
2530
+ throw js_pending_exception;
2531
+ }
2532
+
2533
+ return id;
2534
+ }
2535
+
2536
+ static int
2537
+ bare_ffmpeg_codec_parameters_get_color_range(
2538
+ js_env_t *env,
2539
+ js_receiver_t,
2540
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
2541
+ ) {
2542
+ return parameters->handle->color_range;
2543
+ }
2544
+
2545
+ static void
2546
+ bare_ffmpeg_codec_parameters_set_color_range(
2547
+ js_env_t *env,
2548
+ js_receiver_t,
2549
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters,
2550
+ int color_range
2551
+ ) {
2552
+ parameters->handle->color_range = static_cast<AVColorRange>(color_range);
2553
+ }
2554
+
2278
2555
  static js_arraybuffer_t
2279
2556
  bare_ffmpeg_frame_init(js_env_t *env, js_receiver_t) {
2280
2557
  int err;
@@ -2490,6 +2767,330 @@ bare_ffmpeg_frame_alloc(
2490
2767
  }
2491
2768
  }
2492
2769
 
2770
+ static js_arraybuffer_t
2771
+ bare_ffmpeg_hw_device_context_init(
2772
+ js_env_t *env,
2773
+ js_receiver_t,
2774
+ int type,
2775
+ std::optional<std::string> device
2776
+ ) {
2777
+ int err;
2778
+
2779
+ js_arraybuffer_t handle;
2780
+ bare_ffmpeg_hw_device_context_t *hw_device_ctx;
2781
+ err = js_create_arraybuffer(env, hw_device_ctx, handle);
2782
+ assert(err == 0);
2783
+
2784
+ const char *device_str = device.has_value() ? device.value().c_str() : nullptr;
2785
+ err = av_hwdevice_ctx_create(
2786
+ &hw_device_ctx->handle,
2787
+ static_cast<AVHWDeviceType>(type),
2788
+ device_str,
2789
+ nullptr,
2790
+ 0
2791
+ );
2792
+
2793
+ if (err < 0) {
2794
+ err = js_throw_error(env, NULL, av_err2str(err));
2795
+ assert(err == 0);
2796
+
2797
+ throw js_pending_exception;
2798
+ }
2799
+
2800
+ return handle;
2801
+ }
2802
+
2803
+ static void
2804
+ bare_ffmpeg_hw_device_context_destroy(
2805
+ js_env_t *env,
2806
+ js_receiver_t,
2807
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_device_context_t, 1> hw_device_ctx
2808
+ ) {
2809
+ av_buffer_unref(&hw_device_ctx->handle);
2810
+ }
2811
+
2812
+ static void
2813
+ bare_ffmpeg_hw_frames_context_destroy(
2814
+ js_env_t *env,
2815
+ js_receiver_t,
2816
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
2817
+ ) {
2818
+ av_buffer_unref(&hw_frames_ctx->handle);
2819
+ }
2820
+
2821
+ static js_arraybuffer_t
2822
+ bare_ffmpeg_hw_frames_context_init(
2823
+ js_env_t *env,
2824
+ js_receiver_t,
2825
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_device_context_t, 1> hw_device_ctx,
2826
+ int32_t format,
2827
+ int32_t sw_format,
2828
+ int32_t width,
2829
+ int32_t height
2830
+ ) {
2831
+ int err;
2832
+
2833
+ js_arraybuffer_t handle;
2834
+ bare_ffmpeg_hw_frames_context_t *hw_frames_ctx;
2835
+ err = js_create_arraybuffer(env, hw_frames_ctx, handle);
2836
+ assert(err == 0);
2837
+
2838
+ hw_frames_ctx->handle = av_hwframe_ctx_alloc(hw_device_ctx->handle);
2839
+
2840
+ if (hw_frames_ctx->handle == nullptr) {
2841
+ err = js_throw_error(env, NULL, "Failed to allocate hardware frames context");
2842
+ assert(err == 0);
2843
+
2844
+ throw js_pending_exception;
2845
+ }
2846
+
2847
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
2848
+ ctx->format = static_cast<enum AVPixelFormat>(format);
2849
+ ctx->sw_format = static_cast<enum AVPixelFormat>(sw_format);
2850
+ ctx->width = width;
2851
+ ctx->height = height;
2852
+
2853
+ err = av_hwframe_ctx_init(hw_frames_ctx->handle);
2854
+
2855
+ if (err < 0) {
2856
+ av_buffer_unref(&hw_frames_ctx->handle);
2857
+ err = js_throw_error(env, NULL, av_err2str(err));
2858
+ assert(err == 0);
2859
+
2860
+ throw js_pending_exception;
2861
+ }
2862
+
2863
+ return handle;
2864
+ }
2865
+
2866
+ static void
2867
+ bare_ffmpeg_hw_frames_context_get_buffer(
2868
+ js_env_t *env,
2869
+ js_receiver_t,
2870
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx,
2871
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
2872
+ ) {
2873
+ int err = av_hwframe_get_buffer(hw_frames_ctx->handle, frame->handle, 0);
2874
+ if (err < 0) {
2875
+ err = js_throw_error(env, NULL, av_err2str(err));
2876
+ assert(err == 0);
2877
+
2878
+ throw js_pending_exception;
2879
+ }
2880
+ }
2881
+
2882
+ static js_arraybuffer_t
2883
+ bare_ffmpeg_hw_frames_context_get_constraints(
2884
+ js_env_t *env,
2885
+ js_receiver_t,
2886
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
2887
+ ) {
2888
+ int err;
2889
+
2890
+ AVHWFramesContext *frames_ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
2891
+
2892
+ AVHWFramesConstraints *constraints = av_hwdevice_get_hwframe_constraints(frames_ctx->device_ref, NULL);
2893
+ if (!constraints) {
2894
+ err = js_throw_error(env, NULL, "Failed to get hardware frame constraints");
2895
+ assert(err == 0);
2896
+ throw js_pending_exception;
2897
+ }
2898
+
2899
+ js_arraybuffer_t handle;
2900
+ bare_ffmpeg_hw_frames_constraints_t *hw_frames_constraints;
2901
+
2902
+ err = js_create_arraybuffer(env, hw_frames_constraints, handle);
2903
+ assert(err == 0);
2904
+
2905
+ hw_frames_constraints->handle = constraints;
2906
+
2907
+ return handle;
2908
+ }
2909
+
2910
+ static void
2911
+ bare_ffmpeg_hw_frames_constraints_destroy(
2912
+ js_env_t *env,
2913
+ js_receiver_t,
2914
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2915
+ ) {
2916
+ av_hwframe_constraints_free(&hw_frames_constraints->handle);
2917
+ }
2918
+
2919
+ static std::vector<int32_t>
2920
+ bare_ffmpeg_hw_frames_constraints_get_valid_sw_formats(
2921
+ js_env_t *env,
2922
+ js_receiver_t,
2923
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2924
+ ) {
2925
+ std::vector<int32_t> formats;
2926
+
2927
+ if (hw_frames_constraints->handle->valid_sw_formats) {
2928
+ for (int i = 0; hw_frames_constraints->handle->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
2929
+ formats.push_back(hw_frames_constraints->handle->valid_sw_formats[i]);
2930
+ }
2931
+ }
2932
+
2933
+ return formats;
2934
+ }
2935
+
2936
+ static std::vector<int32_t>
2937
+ bare_ffmpeg_hw_frames_constraints_get_valid_hw_formats(
2938
+ js_env_t *env,
2939
+ js_receiver_t,
2940
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2941
+ ) {
2942
+ std::vector<int32_t> formats;
2943
+
2944
+ if (hw_frames_constraints->handle->valid_hw_formats) {
2945
+ for (int i = 0; hw_frames_constraints->handle->valid_hw_formats[i] != AV_PIX_FMT_NONE; i++) {
2946
+ formats.push_back(hw_frames_constraints->handle->valid_hw_formats[i]);
2947
+ }
2948
+ }
2949
+
2950
+ return formats;
2951
+ }
2952
+
2953
+ static int32_t
2954
+ bare_ffmpeg_hw_frames_constraints_get_min_width(
2955
+ js_env_t *env,
2956
+ js_receiver_t,
2957
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2958
+ ) {
2959
+ return hw_frames_constraints->handle->min_width;
2960
+ }
2961
+
2962
+ static int32_t
2963
+ bare_ffmpeg_hw_frames_constraints_get_max_width(
2964
+ js_env_t *env,
2965
+ js_receiver_t,
2966
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2967
+ ) {
2968
+ return hw_frames_constraints->handle->max_width;
2969
+ }
2970
+
2971
+ static int32_t
2972
+ bare_ffmpeg_hw_frames_constraints_get_min_height(
2973
+ js_env_t *env,
2974
+ js_receiver_t,
2975
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2976
+ ) {
2977
+ return hw_frames_constraints->handle->min_height;
2978
+ }
2979
+
2980
+ static int32_t
2981
+ bare_ffmpeg_hw_frames_constraints_get_max_height(
2982
+ js_env_t *env,
2983
+ js_receiver_t,
2984
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_constraints_t, 1> hw_frames_constraints
2985
+ ) {
2986
+ return hw_frames_constraints->handle->max_height;
2987
+ }
2988
+
2989
+ static int32_t
2990
+ bare_ffmpeg_hw_frames_context_get_format(
2991
+ js_env_t *env,
2992
+ js_receiver_t,
2993
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
2994
+ ) {
2995
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
2996
+ return ctx->format;
2997
+ }
2998
+
2999
+ static void
3000
+ bare_ffmpeg_hw_frames_context_set_format(
3001
+ js_env_t *env,
3002
+ js_receiver_t,
3003
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx,
3004
+ int32_t format
3005
+ ) {
3006
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3007
+ ctx->format = static_cast<enum AVPixelFormat>(format);
3008
+ }
3009
+
3010
+ static int32_t
3011
+ bare_ffmpeg_hw_frames_context_get_sw_format(
3012
+ js_env_t *env,
3013
+ js_receiver_t,
3014
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
3015
+ ) {
3016
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3017
+ return ctx->sw_format;
3018
+ }
3019
+
3020
+ static void
3021
+ bare_ffmpeg_hw_frames_context_set_sw_format(
3022
+ js_env_t *env,
3023
+ js_receiver_t,
3024
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx,
3025
+ int32_t sw_format
3026
+ ) {
3027
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3028
+ ctx->sw_format = static_cast<enum AVPixelFormat>(sw_format);
3029
+ }
3030
+
3031
+ static int32_t
3032
+ bare_ffmpeg_hw_frames_context_get_width(
3033
+ js_env_t *env,
3034
+ js_receiver_t,
3035
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
3036
+ ) {
3037
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3038
+ return ctx->width;
3039
+ }
3040
+
3041
+ static void
3042
+ bare_ffmpeg_hw_frames_context_set_width(
3043
+ js_env_t *env,
3044
+ js_receiver_t,
3045
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx,
3046
+ int32_t width
3047
+ ) {
3048
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3049
+ ctx->width = width;
3050
+ }
3051
+
3052
+ static int32_t
3053
+ bare_ffmpeg_hw_frames_context_get_height(
3054
+ js_env_t *env,
3055
+ js_receiver_t,
3056
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
3057
+ ) {
3058
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3059
+ return ctx->height;
3060
+ }
3061
+
3062
+ static void
3063
+ bare_ffmpeg_hw_frames_context_set_height(
3064
+ js_env_t *env,
3065
+ js_receiver_t,
3066
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx,
3067
+ int32_t height
3068
+ ) {
3069
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3070
+ ctx->height = height;
3071
+ }
3072
+
3073
+ static int32_t
3074
+ bare_ffmpeg_hw_frames_context_get_initial_pool_size(
3075
+ js_env_t *env,
3076
+ js_receiver_t,
3077
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx
3078
+ ) {
3079
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3080
+ return ctx->initial_pool_size;
3081
+ }
3082
+
3083
+ static void
3084
+ bare_ffmpeg_hw_frames_context_set_initial_pool_size(
3085
+ js_env_t *env,
3086
+ js_receiver_t,
3087
+ js_arraybuffer_span_of_t<bare_ffmpeg_hw_frames_context_t, 1> hw_frames_ctx,
3088
+ int32_t initial_pool_size
3089
+ ) {
3090
+ AVHWFramesContext *ctx = reinterpret_cast<AVHWFramesContext *>(hw_frames_ctx->handle->data);
3091
+ ctx->initial_pool_size = initial_pool_size;
3092
+ }
3093
+
2493
3094
  static js_arraybuffer_t
2494
3095
  bare_ffmpeg_image_init(
2495
3096
  js_env_t *env,
@@ -4147,6 +4748,8 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
4147
4748
  V("getCodecContextRequestSampleFormat", bare_ffmpeg_codec_context_get_request_sample_format)
4148
4749
  V("setCodecContextRequestSampleFormat", bare_ffmpeg_codec_context_set_request_sample_format)
4149
4750
  V("setCodecContextGetFormat", bare_ffmpeg_codec_context_set_get_format)
4751
+ V("getCodecContextHWDeviceCtx", bare_ffmpeg_codec_context_get_hw_device_ctx)
4752
+ V("setCodecContextHWDeviceCtx", bare_ffmpeg_codec_context_set_hw_device_ctx)
4150
4753
 
4151
4754
  V("sendCodecContextPacket", bare_ffmpeg_codec_context_send_packet)
4152
4755
  V("receiveCodecContextPacket", bare_ffmpeg_codec_context_receive_packet)
@@ -4203,6 +4806,21 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
4203
4806
  V("setCodecParametersVideoDelay", bare_ffmpeg_codec_parameters_set_video_delay)
4204
4807
  V("getCodecParametersFrameSize", bare_ffmpeg_codec_parameters_get_frame_size)
4205
4808
  V("setCodecParametersFrameSize", bare_ffmpeg_codec_parameters_set_frame_size)
4809
+ V("getCodecParametersColorSpace", bare_ffmpeg_codec_parameters_get_color_space)
4810
+ V("setCodecParametersColorSpace", bare_ffmpeg_codec_parameters_set_color_space)
4811
+ V("getCodecParametersColorPrimaries", bare_ffmpeg_codec_parameters_get_color_primaries)
4812
+ V("setCodecParametersColorPrimaries", bare_ffmpeg_codec_parameters_set_color_primaries)
4813
+ V("getCodecParametersColorTRC", bare_ffmpeg_codec_parameters_get_color_trc)
4814
+ V("setCodecParametersColorTRC", bare_ffmpeg_codec_parameters_set_color_trc)
4815
+ V("getCodecParametersColorRange", bare_ffmpeg_codec_parameters_get_color_range)
4816
+ V("setCodecParametersColorRange", bare_ffmpeg_codec_parameters_set_color_range)
4817
+
4818
+ V("getColorSpaceNameByID", bare_ffmpeg_color_space_name)
4819
+ V("getColorSpaceFromName", bare_ffmpeg_color_space_from_name)
4820
+ V("getColorPrimariesNameByID", bare_ffmpeg_color_primaries_name)
4821
+ V("getColorPrimariesFromName", bare_ffmpeg_color_primaries_from_name)
4822
+ V("getColorTransferNameByID", bare_ffmpeg_color_transfer_name)
4823
+ V("getColorTransferFromName", bare_ffmpeg_color_transfer_from_name)
4206
4824
 
4207
4825
  V("initFrame", bare_ffmpeg_frame_init)
4208
4826
  V("destroyFrame", bare_ffmpeg_frame_destroy)
@@ -4227,8 +4845,37 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
4227
4845
  V("getFrameSampleRate", bare_ffmpeg_frame_get_sample_rate)
4228
4846
  V("setFrameSampleRate", bare_ffmpeg_frame_set_sample_rate)
4229
4847
  V("copyFrameProperties", bare_ffmpeg_frame_copy_properties)
4848
+ V("transferFrameData", bare_ffmpeg_frame_transfer_data)
4849
+ V("mapFrame", bare_ffmpeg_frame_map)
4850
+ V("getFrameHWFramesCtx", bare_ffmpeg_frame_get_hw_frames_ctx)
4851
+ V("setFrameHWFramesCtx", bare_ffmpeg_frame_set_hw_frames_ctx)
4230
4852
  V("allocFrame", bare_ffmpeg_frame_alloc)
4231
4853
 
4854
+ V("initHWDeviceContext", bare_ffmpeg_hw_device_context_init)
4855
+ V("destroyHWDeviceContext", bare_ffmpeg_hw_device_context_destroy)
4856
+ V("initHWFramesContext", bare_ffmpeg_hw_frames_context_init)
4857
+ V("destroyHWFramesContext", bare_ffmpeg_hw_frames_context_destroy)
4858
+ V("getHWFramesContextFormat", bare_ffmpeg_hw_frames_context_get_format)
4859
+ V("setHWFramesContextFormat", bare_ffmpeg_hw_frames_context_set_format)
4860
+ V("getHWFramesContextSWFormat", bare_ffmpeg_hw_frames_context_get_sw_format)
4861
+ V("setHWFramesContextSWFormat", bare_ffmpeg_hw_frames_context_set_sw_format)
4862
+ V("getHWFramesContextWidth", bare_ffmpeg_hw_frames_context_get_width)
4863
+ V("setHWFramesContextWidth", bare_ffmpeg_hw_frames_context_set_width)
4864
+ V("getHWFramesContextHeight", bare_ffmpeg_hw_frames_context_get_height)
4865
+ V("setHWFramesContextHeight", bare_ffmpeg_hw_frames_context_set_height)
4866
+ V("getHWFramesContextInitialPoolSize", bare_ffmpeg_hw_frames_context_get_initial_pool_size)
4867
+ V("setHWFramesContextInitialPoolSize", bare_ffmpeg_hw_frames_context_set_initial_pool_size)
4868
+ V("getHWFramesContextBuffer", bare_ffmpeg_hw_frames_context_get_buffer)
4869
+ V("getHWFramesContextConstraints", bare_ffmpeg_hw_frames_context_get_constraints)
4870
+
4871
+ V("destroyHWFramesConstraints", bare_ffmpeg_hw_frames_constraints_destroy)
4872
+ V("getHWFramesConstraintsValidSwFormats", bare_ffmpeg_hw_frames_constraints_get_valid_sw_formats)
4873
+ V("getHWFramesConstraintsValidHwFormats", bare_ffmpeg_hw_frames_constraints_get_valid_hw_formats)
4874
+ V("getHWFramesConstraintsMinWidth", bare_ffmpeg_hw_frames_constraints_get_min_width)
4875
+ V("getHWFramesConstraintsMaxWidth", bare_ffmpeg_hw_frames_constraints_get_max_width)
4876
+ V("getHWFramesConstraintsMinHeight", bare_ffmpeg_hw_frames_constraints_get_min_height)
4877
+ V("getHWFramesConstraintsMaxHeight", bare_ffmpeg_hw_frames_constraints_get_max_height)
4878
+
4232
4879
  V("initImage", bare_ffmpeg_image_init)
4233
4880
  V("fillImage", bare_ffmpeg_image_fill)
4234
4881
  V("readImage", bare_ffmpeg_image_read)
@@ -4357,6 +5004,15 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
4357
5004
  V(AV_CODEC_ID_AV1)
4358
5005
  V(AV_CODEC_ID_FLAC)
4359
5006
  V(AV_CODEC_ID_MP3)
5007
+ V(AV_CODEC_ID_HEVC)
5008
+ V(AV_CODEC_ID_VP8)
5009
+ V(AV_CODEC_ID_VP9)
5010
+ V(AV_CODEC_ID_VORBIS)
5011
+ V(AV_CODEC_ID_PCM_S16LE)
5012
+ V(AV_CODEC_ID_PCM_S16BE)
5013
+ V(AV_CODEC_ID_PCM_U8)
5014
+ V(AV_CODEC_ID_PCM_ALAW)
5015
+ V(AV_CODEC_ID_PCM_MULAW)
4360
5016
 
4361
5017
  V(AV_CODEC_FLAG_COPY_OPAQUE)
4362
5018
  V(AV_CODEC_FLAG_FRAME_DURATION)
@@ -4384,6 +5040,18 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
4384
5040
  V(AV_PIX_FMT_NV24)
4385
5041
  V(AV_PIX_FMT_VIDEOTOOLBOX)
4386
5042
 
5043
+ V(AV_HWDEVICE_TYPE_VIDEOTOOLBOX)
5044
+ V(AV_HWDEVICE_TYPE_CUDA)
5045
+ V(AV_HWDEVICE_TYPE_VAAPI)
5046
+ V(AV_HWDEVICE_TYPE_DXVA2)
5047
+ V(AV_HWDEVICE_TYPE_QSV)
5048
+ V(AV_HWDEVICE_TYPE_D3D11VA)
5049
+
5050
+ V(AV_HWFRAME_MAP_READ)
5051
+ V(AV_HWFRAME_MAP_WRITE)
5052
+ V(AV_HWFRAME_MAP_OVERWRITE)
5053
+ V(AV_HWFRAME_MAP_DIRECT)
5054
+
4387
5055
  V(AVMEDIA_TYPE_UNKNOWN)
4388
5056
  V(AVMEDIA_TYPE_VIDEO)
4389
5057
  V(AVMEDIA_TYPE_AUDIO)
@@ -4562,6 +5230,71 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
4562
5230
  // Levels
4563
5231
  V(AV_LEVEL_UNKNOWN)
4564
5232
 
5233
+ // Color Space
5234
+ V(AVCOL_SPC_RGB)
5235
+ V(AVCOL_SPC_BT709)
5236
+ V(AVCOL_SPC_UNSPECIFIED)
5237
+ V(AVCOL_SPC_RESERVED)
5238
+ V(AVCOL_SPC_FCC)
5239
+ V(AVCOL_SPC_BT470BG)
5240
+ V(AVCOL_SPC_SMPTE170M)
5241
+ V(AVCOL_SPC_SMPTE240M)
5242
+ V(AVCOL_SPC_YCGCO)
5243
+ V(AVCOL_SPC_YCOCG)
5244
+ V(AVCOL_SPC_BT2020_NCL)
5245
+ V(AVCOL_SPC_BT2020_CL)
5246
+ V(AVCOL_SPC_SMPTE2085)
5247
+ V(AVCOL_SPC_CHROMA_DERIVED_NCL)
5248
+ V(AVCOL_SPC_CHROMA_DERIVED_CL)
5249
+ V(AVCOL_SPC_ICTCP)
5250
+ V(AVCOL_SPC_IPT_C2)
5251
+ V(AVCOL_SPC_YCGCO_RE)
5252
+ V(AVCOL_SPC_YCGCO_RO)
5253
+
5254
+ // Color Range
5255
+ V(AVCOL_RANGE_UNSPECIFIED)
5256
+ V(AVCOL_RANGE_MPEG)
5257
+ V(AVCOL_RANGE_JPEG)
5258
+
5259
+ // Color Primaries
5260
+ V(AVCOL_PRI_BT709)
5261
+ V(AVCOL_PRI_UNSPECIFIED)
5262
+ V(AVCOL_PRI_RESERVED)
5263
+ V(AVCOL_PRI_BT470M)
5264
+ V(AVCOL_PRI_BT470BG)
5265
+ V(AVCOL_PRI_SMPTE170M)
5266
+ V(AVCOL_PRI_SMPTE240M)
5267
+ V(AVCOL_PRI_FILM)
5268
+ V(AVCOL_PRI_BT2020)
5269
+ V(AVCOL_PRI_SMPTE428)
5270
+ V(AVCOL_PRI_SMPTEST428_1)
5271
+ V(AVCOL_PRI_SMPTE431)
5272
+ V(AVCOL_PRI_SMPTE432)
5273
+ V(AVCOL_PRI_EBU3213)
5274
+ V(AVCOL_PRI_JEDEC_P22)
5275
+
5276
+ // Color Transfer Characteristics
5277
+ V(AVCOL_TRC_BT709)
5278
+ V(AVCOL_TRC_UNSPECIFIED)
5279
+ V(AVCOL_TRC_RESERVED)
5280
+ V(AVCOL_TRC_GAMMA22)
5281
+ V(AVCOL_TRC_GAMMA28)
5282
+ V(AVCOL_TRC_SMPTE170M)
5283
+ V(AVCOL_TRC_SMPTE240M)
5284
+ V(AVCOL_TRC_LINEAR)
5285
+ V(AVCOL_TRC_LOG)
5286
+ V(AVCOL_TRC_LOG_SQRT)
5287
+ V(AVCOL_TRC_IEC61966_2_4)
5288
+ V(AVCOL_TRC_BT1361_ECG)
5289
+ V(AVCOL_TRC_IEC61966_2_1)
5290
+ V(AVCOL_TRC_BT2020_10)
5291
+ V(AVCOL_TRC_BT2020_12)
5292
+ V(AVCOL_TRC_SMPTE2084)
5293
+ V(AVCOL_TRC_SMPTEST2084)
5294
+ V(AVCOL_TRC_SMPTE428)
5295
+ V(AVCOL_TRC_SMPTEST428_1)
5296
+ V(AVCOL_TRC_ARIB_STD_B67)
5297
+
4565
5298
  // SEEK
4566
5299
  V(AVSEEK_SIZE)
4567
5300
  V(AVSEEK_FORCE)