21
21
22
22
#include " decode.h"
23
23
24
- char * req_hw_type = nullptr ;
25
- AVPixelFormat req_hw_pix_fmt = AV_PIX_FMT_NONE;
26
-
27
24
AVPixelFormat get_format (AVCodecContext *s, const AVPixelFormat *pix_fmts)
28
25
{
29
- AVPixelFormat result = AV_PIX_FMT_NONE;
30
26
const AVPixelFormat *p;
31
27
int i, err;
32
28
33
- if (0 == strcmp (" auto" , req_hw_type)) {
34
- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
35
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get (*p);
36
- const AVCodecHWConfig *config = NULL ;
37
-
38
- if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
39
- break ;
29
+ for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
30
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get (*p);
31
+ const AVCodecHWConfig *config = NULL ;
40
32
41
- for (i = 0 ;; i++) {
42
- config = avcodec_get_hw_config (s->codec , i);
43
- if (!config)
44
- break ;
45
- if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
46
- continue ;
47
- if (config->pix_fmt == *p)
48
- break ;
49
- }
33
+ if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
34
+ break ;
50
35
51
- if (config ) {
52
- err = av_hwdevice_ctx_create (& s->hw_device_ctx , config-> device_type , NULL , NULL , 0 );
53
- if (err < 0 ) {
54
- char errstr[ 128 ] ;
55
- av_make_error_string (errstr, 128 , err);
56
- printf ( " Error in get_format \' auto \' av_hwdevice_ctx_create: %s \n " , errstr) ;
57
- }
36
+ for (i = 0 ;; i++ ) {
37
+ config = avcodec_get_hw_config ( s->codec , i );
38
+ if (!config)
39
+ break ;
40
+ if (!(config-> methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
41
+ continue ;
42
+ if (config-> pix_fmt == *p)
58
43
break ;
59
- }
60
44
}
61
- result = *p;
62
- } else {
63
- err = av_hwdevice_ctx_create (&s->hw_device_ctx , av_hwdevice_find_type_by_name (req_hw_type), NULL , NULL , 0 );
64
- if (err < 0 ) {
65
- char errstr[128 ];
66
- av_make_error_string (errstr, 128 , err);
67
- printf (" Error in get_format \' %s\' av_hwdevice_ctx_create: %s\n " , req_hw_type, errstr);
45
+
46
+ if (config) {
47
+ err = av_hwdevice_ctx_create (&s->hw_device_ctx , config->device_type , NULL , NULL , 0 );
48
+ if (err < 0 ) {
49
+ char errstr[128 ];
50
+ av_make_error_string (errstr, 128 , err);
51
+ printf (" Error in get_format av_hwdevice_ctx_create: %s\n " , errstr);
52
+ }
53
+ break ;
68
54
}
69
- result = req_hw_pix_fmt;
70
55
}
71
56
72
- return result ;
57
+ return *p ;
73
58
}
74
59
75
60
napi_value decoder (napi_env env, napi_callback_info info) {
@@ -85,8 +70,8 @@ napi_value decoder(napi_env env, napi_callback_info info) {
85
70
AVCodecParameters* params = nullptr ;
86
71
char * codecName = nullptr ;
87
72
size_t codecNameLen = 0 ;
88
- size_t hwTypeLen = 0 ;
89
73
int32_t codecID = -1 ;
74
+ bool hwaccel = false ;
90
75
91
76
size_t argc = 1 ;
92
77
napi_value args[1 ];
@@ -205,16 +190,9 @@ napi_value decoder(napi_env env, napi_callback_info info) {
205
190
if (hasHWaccel) {
206
191
status = napi_get_named_property (env, args[0 ], " hwaccel" , &value);
207
192
CHECK_STATUS;
208
- hwTypeLen = 64 ;
209
- req_hw_type = (char *) malloc (sizeof (char ) * (hwTypeLen + 1 ));
210
- status = napi_get_value_string_utf8 (env, value, req_hw_type,
211
- 64 , &hwTypeLen);
193
+ status = napi_get_value_bool (env, value, &hwaccel);
212
194
CHECK_STATUS;
213
- req_hw_pix_fmt = av_get_pix_fmt (req_hw_type);
214
-
215
- if (0 != strcmp (" auto" , req_hw_type) && req_hw_pix_fmt == AV_PIX_FMT_NONE)
216
- printf (" Decoder hwaccel name \' %s\' not recognised\n " , req_hw_type);
217
- else
195
+ if (hwaccel)
218
196
decoder->get_format = get_format;
219
197
}
220
198
0 commit comments