2020*/
2121
2222#include " codec.h"
23+ #include " hwcontext.h"
2324
2425napi_value getCodecCtxCodecID (napi_env env, napi_callback_info info) {
2526 napi_status status;
@@ -6495,6 +6496,56 @@ napi_value getCodecCtxCodedSideData(napi_env env, napi_callback_info info) {
64956496 return result;
64966497}
64976498
6499+ napi_value getCodecHWFramesCtx (napi_env env, napi_callback_info info) {
6500+ napi_status status;
6501+ napi_value result;
6502+ AVCodecContext* codec;
6503+
6504+ size_t argc = 0 ;
6505+ status = napi_get_cb_info (env, info, &argc, nullptr , nullptr , (void **) &codec);
6506+ CHECK_STATUS;
6507+
6508+ if (codec->hw_frames_ctx == nullptr ) {
6509+ status = napi_get_null (env, &result);
6510+ CHECK_STATUS;
6511+ } else {
6512+ status = fromHWFramesContext (env, codec->hw_frames_ctx , &result);
6513+ CHECK_STATUS;
6514+ }
6515+
6516+ return result;
6517+ }
6518+
6519+ napi_value setCodecHWFramesCtx (napi_env env, napi_callback_info info) {
6520+ napi_status status;
6521+ napi_value result, contextExt;
6522+ napi_valuetype type;
6523+ AVCodecContext* codec;
6524+ AVBufferRef* contextRef;
6525+
6526+ size_t argc = 1 ;
6527+ napi_value args[1 ];
6528+ status = napi_get_cb_info (env, info, &argc, args, nullptr , (void **) &codec);
6529+ CHECK_STATUS;
6530+ if (argc < 1 ) {
6531+ NAPI_THROW_ERROR (" A value is required to set the hw_frames_context property." );
6532+ }
6533+ status = napi_typeof (env, args[0 ], &type);
6534+ CHECK_STATUS;
6535+ if (type != napi_object) {
6536+ NAPI_THROW_ERROR (" An object is required to set the hw_frames_context property." );
6537+ }
6538+ status = napi_get_named_property (env, args[0 ], " _framesContext" , &contextExt);
6539+ CHECK_STATUS;
6540+ status = napi_get_value_external (env, contextExt, (void **) &contextRef);
6541+ CHECK_STATUS;
6542+ codec->hw_frames_ctx = av_buffer_ref (contextRef);
6543+
6544+ status = napi_get_undefined (env, &result);
6545+ CHECK_STATUS;
6546+ return result;
6547+ }
6548+
64986549napi_value getCodecCtxSubTextFmt (napi_env env, napi_callback_info info) {
64996550 napi_status status;
65006551 napi_value result;
@@ -6618,6 +6669,26 @@ napi_value setCodecCtxMaxPixels(napi_env env, napi_callback_info info) {
66186669 return result;
66196670}
66206671
6672+ napi_value getCodecHWDeviceCtx (napi_env env, napi_callback_info info) {
6673+ napi_status status;
6674+ napi_value result;
6675+ AVCodecContext* codec;
6676+
6677+ size_t argc = 0 ;
6678+ status = napi_get_cb_info (env, info, &argc, nullptr , nullptr , (void **) &codec);
6679+ CHECK_STATUS;
6680+
6681+ if (codec->hw_device_ctx == nullptr ) {
6682+ status = napi_get_null (env, &result);
6683+ CHECK_STATUS;
6684+ } else {
6685+ status = fromHWDeviceContext (env, codec->hw_device_ctx , &result);
6686+ CHECK_STATUS;
6687+ }
6688+
6689+ return result;
6690+ }
6691+
66216692napi_value getCodecCtxHwAccelFlags (napi_env env, napi_callback_info info) {
66226693 napi_status status;
66236694 napi_value result;
@@ -7227,17 +7298,20 @@ napi_status fromAVCodecContext(napi_env env, AVCodecContext* codec,
72277298 { " coded_side_data" , nullptr , nullptr ,
72287299 encoding ? getCodecCtxCodedSideData : nullptr , failBoth, nullptr ,
72297300 encoding ? napi_enumerable : napi_default, codec},
7230- // TODO hw_frames_ctx
7301+ { " hw_frames_ctx" , nullptr , nullptr ,
7302+ getCodecHWFramesCtx,
7303+ encoding ? setCodecHWFramesCtx : failDecoding, nullptr ,
7304+ encoding ? (napi_property_attributes) (napi_writable | napi_enumerable) : napi_enumerable, codec},
7305+ // 130
72317306 { " sub_text_format" , nullptr , nullptr ,
72327307 encoding ? nullptr : getCodecCtxSubTextFmt,
72337308 encoding ? failEncoding : setCodecCtxSubTextFmt, nullptr ,
72347309 encoding ? napi_default : (napi_property_attributes) (napi_writable | napi_enumerable), codec},
7235- // 130
72367310 { " trailing_padding" , nullptr , nullptr , getCodecCtxTrailPad, setCodecCtxTrailPad, nullptr ,
72377311 (napi_property_attributes) (napi_writable | napi_enumerable), codec},
72387312 { " max_pixels" , nullptr , nullptr , getCodecCtxMaxPixels, setCodecCtxMaxPixels, nullptr ,
72397313 (napi_property_attributes) (napi_writable | napi_enumerable), codec},
7240- // TODO hw_device_ctx
7314+ { " hw_device_ctx" , nullptr , nullptr , getCodecHWDeviceCtx, nullptr , nullptr , napi_enumerable, codec},
72417315 { " hwaccel_flags" , nullptr , nullptr ,
72427316 encoding ? nullptr : getCodecCtxHwAccelFlags,
72437317 encoding ? failEncoding : setCodecCtxHwAccelFlags, nullptr ,
@@ -7256,15 +7330,15 @@ napi_status fromAVCodecContext(napi_env env, AVCodecContext* codec,
72567330 encoding ? flushEnc : flushDec, nullptr , nullptr , nullptr , napi_enumerable, codec},
72577331 { " extractParams" , nullptr , extractParams, nullptr , nullptr , nullptr , napi_enumerable, nullptr },
72587332 { " useParams" , nullptr , useParams, nullptr , nullptr , nullptr , napi_enumerable, nullptr },
7333+ // 140
72597334 // Hidden values - to allow Object.assign to work
72607335 { " params" , nullptr , nullptr , nullptr , nop, undef, // Set for muxing
72617336 napi_writable, nullptr },
72627337 { " stream_index" , nullptr , nullptr , nullptr , nop, undef, napi_writable, nullptr },
7263- // 140
72647338 { " demuxer" , nullptr , nullptr , nullptr , nop, undef, napi_writable, nullptr },
72657339 { " _CodecContext" , nullptr , nullptr , nullptr , nullptr , extCodec, napi_default, nullptr }
72667340 };
7267- status = napi_define_properties (env, jsCodec, 142 , desc);
7341+ status = napi_define_properties (env, jsCodec, 144 , desc);
72687342 PASS_STATUS;
72697343
72707344 *result = jsCodec;
0 commit comments