Skip to content

Commit a8946cb

Browse files
committed
Making format more tolerant of array-like arrays
1 parent 3bab098 commit a8946cb

File tree

1 file changed

+51
-31
lines changed

1 file changed

+51
-31
lines changed

src/format.cc

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,16 +4023,28 @@ napi_value newStream(napi_env env, napi_callback_info info) {
40234023
CHECK_STATUS;
40244024
}
40254025

4026-
status = napi_get_named_property(env, jsContext, "__streams", &jsStreams);
4026+
status = napi_get_named_property(env, jsContext, "__streams", &jsStreams);
4027+
CHECK_STATUS;
4028+
status = napi_typeof(env, jsStreams, &type);
40274029
CHECK_STATUS;
4030+
if (type != napi_object) {
4031+
return result;
4032+
}
4033+
40284034
status = napi_is_array(env, jsStreams, &isArray);
40294035
CHECK_STATUS;
40304036
if (isArray) {
40314037
status = napi_get_array_length(env, jsStreams, &streamCount);
40324038
CHECK_STATUS;
4033-
status = napi_set_element(env, jsStreams, streamCount, result);
4039+
} else {
4040+
napi_value propNames;
4041+
status = napi_get_property_names(env, jsStreams, &propNames);
4042+
CHECK_STATUS;
4043+
status = napi_get_array_length(env, propNames, &streamCount);
40344044
CHECK_STATUS;
4035-
} // else let the first call to get create array
4045+
}
4046+
status = napi_set_element(env, jsStreams, streamCount, result);
4047+
CHECK_STATUS;
40364048
return result;
40374049
}
40384050

@@ -4173,7 +4185,7 @@ napi_value setStreamTimeBase(napi_env env, napi_callback_info info) {
41734185
napi_status status;
41744186
napi_value result, element;
41754187
napi_valuetype type;
4176-
bool isArray;
4188+
// bool isArray;
41774189
AVStream* stream;
41784190

41794191
size_t argc = 1;
@@ -4184,14 +4196,16 @@ napi_value setStreamTimeBase(napi_env env, napi_callback_info info) {
41844196
if (argc < 1) {
41854197
NAPI_THROW_ERROR("A value is required to set the stream time_base property.");
41864198
}
4187-
status = napi_is_array(env, args[0], &isArray);
4188-
CHECK_STATUS;
4189-
if (!isArray) {
4190-
NAPI_THROW_ERROR("The stream's time_base property must be set with an array of two numbers.");
4191-
}
4199+
// status = napi_is_array(env, args[0], &isArray);
4200+
// CHECK_STATUS;
4201+
// if (!isArray) {
4202+
// NAPI_THROW_ERROR("The stream's time_base property must be set with an array of two numbers.");
4203+
// }
41924204
for ( uint32_t x = 0 ; x < 2 ; x++ ) {
41934205
status = napi_get_element(env, args[0], x, &element);
4194-
CHECK_STATUS;
4206+
if (status != napi_ok) {
4207+
NAPI_THROW_ERROR("The stream's time_base property must be set with an array of two numbers.");
4208+
}
41954209
status = napi_typeof(env, element, &type);
41964210
CHECK_STATUS;
41974211
if (type != napi_number) {
@@ -4601,7 +4615,7 @@ napi_value setStreamSmpAspectRt(napi_env env, napi_callback_info info) {
46014615
napi_status status;
46024616
napi_value result, element;
46034617
napi_valuetype type;
4604-
bool isArray;
4618+
// bool isArray;
46054619
AVStream* stream;
46064620

46074621
size_t argc = 1;
@@ -4612,14 +4626,16 @@ napi_value setStreamSmpAspectRt(napi_env env, napi_callback_info info) {
46124626
if (argc < 1) {
46134627
NAPI_THROW_ERROR("A value is required to set the stream sample_aspect_ratio property.");
46144628
}
4615-
status = napi_is_array(env, args[0], &isArray);
4616-
CHECK_STATUS;
4617-
if (!isArray) {
4618-
NAPI_THROW_ERROR("The stream's sample_aspect_ratio property must be set with an array of two numbers.");
4619-
}
4629+
// status = napi_is_array(env, args[0], &isArray);
4630+
// CHECK_STATUS;
4631+
// if (!isArray) {
4632+
// NAPI_THROW_ERROR("The stream's sample_aspect_ratio property must be set with an array of two numbers.");
4633+
// }
46204634
for ( uint32_t x = 0 ; x < 2 ; x++ ) {
46214635
status = napi_get_element(env, args[0], x, &element);
4622-
CHECK_STATUS;
4636+
if (status != napi_ok) {
4637+
NAPI_THROW_ERROR("The stream's sample_aspect_ratio property must be set with an array of two numbers.");
4638+
}
46234639
status = napi_typeof(env, element, &type);
46244640
CHECK_STATUS;
46254641
if (type != napi_number) {
@@ -4770,7 +4786,7 @@ napi_value setStreamAvgFrameRate(napi_env env, napi_callback_info info) {
47704786
napi_status status;
47714787
napi_value result, element;
47724788
napi_valuetype type;
4773-
bool isArray;
4789+
// bool isArray;
47744790
AVStream* stream;
47754791

47764792
size_t argc = 1;
@@ -4781,14 +4797,16 @@ napi_value setStreamAvgFrameRate(napi_env env, napi_callback_info info) {
47814797
if (argc < 1) {
47824798
NAPI_THROW_ERROR("A value is required to set the stream avg_frame_rate property.");
47834799
}
4784-
status = napi_is_array(env, args[0], &isArray);
4785-
CHECK_STATUS;
4786-
if (!isArray) {
4787-
NAPI_THROW_ERROR("The stream's avg_frame_rate property must be set with an array of two numbers.");
4788-
}
4800+
// status = napi_is_array(env, args[0], &isArray);
4801+
// CHECK_STATUS;
4802+
// if (!isArray) {
4803+
// NAPI_THROW_ERROR("The stream's avg_frame_rate property must be set with an array of two numbers.");
4804+
// }
47894805
for ( uint32_t x = 0 ; x < 2 ; x++ ) {
47904806
status = napi_get_element(env, args[0], x, &element);
4791-
CHECK_STATUS;
4807+
if (status != napi_ok) {
4808+
NAPI_THROW_ERROR("The stream's avg_frame_rate property must be set with an array of two numbers.");
4809+
}
47924810
status = napi_typeof(env, element, &type);
47934811
CHECK_STATUS;
47944812
if (type != napi_number) {
@@ -4835,7 +4853,7 @@ napi_value setStreamRFrameRate(napi_env env, napi_callback_info info) {
48354853
napi_status status;
48364854
napi_value result, element;
48374855
napi_valuetype type;
4838-
bool isArray;
4856+
// bool isArray;
48394857
AVStream* stream;
48404858

48414859
size_t argc = 1;
@@ -4846,14 +4864,16 @@ napi_value setStreamRFrameRate(napi_env env, napi_callback_info info) {
48464864
if (argc < 1) {
48474865
NAPI_THROW_ERROR("A value is required to set the stream r_frame_rate property.");
48484866
}
4849-
status = napi_is_array(env, args[0], &isArray);
4850-
CHECK_STATUS;
4851-
if (!isArray) {
4852-
NAPI_THROW_ERROR("The stream's r_frame_rate property must be set with an array of two numbers.");
4853-
}
4867+
// status = napi_is_array(env, args[0], &isArray);
4868+
// CHECK_STATUS;
4869+
// if (!isArray) {
4870+
// NAPI_THROW_ERROR("The stream's r_frame_rate property must be set with an array of two numbers.");
4871+
// }
48544872
for ( uint32_t x = 0 ; x < 2 ; x++ ) {
48554873
status = napi_get_element(env, args[0], x, &element);
4856-
CHECK_STATUS;
4874+
if (status != napi_ok) {
4875+
NAPI_THROW_ERROR("The stream's r_frame_rate property must be set with an array of two numbers.");
4876+
}
48574877
status = napi_typeof(env, element, &type);
48584878
CHECK_STATUS;
48594879
if (type != napi_number) {

0 commit comments

Comments
 (0)