@lumen5/beamcoder 0.0.1

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 (88) hide show
  1. package/.circleci/config.yml +41 -0
  2. package/.circleci/images/testbeam10-4.1/Dockerfile +12 -0
  3. package/.circleci/test_image/Dockerfile +14 -0
  4. package/.circleci/test_image/build.md +13 -0
  5. package/.eslintrc.js +27 -0
  6. package/.github/workflows/publish-npm.yml +33 -0
  7. package/LICENSE +674 -0
  8. package/README.md +1221 -0
  9. package/beamstreams.js +692 -0
  10. package/binding.gyp +103 -0
  11. package/examples/encode_h264.js +92 -0
  12. package/examples/jpeg_app.js +55 -0
  13. package/examples/jpeg_filter_app.js +101 -0
  14. package/examples/make_mp4.js +123 -0
  15. package/images/beamcoder_small.jpg +0 -0
  16. package/index.d.ts +83 -0
  17. package/index.js +44 -0
  18. package/install_ffmpeg.js +240 -0
  19. package/package.json +45 -0
  20. package/scratch/decode_aac.js +38 -0
  21. package/scratch/decode_avci.js +50 -0
  22. package/scratch/decode_hevc.js +38 -0
  23. package/scratch/decode_pcm.js +39 -0
  24. package/scratch/make_a_mux.js +68 -0
  25. package/scratch/muxer.js +74 -0
  26. package/scratch/read_wav.js +35 -0
  27. package/scratch/simple_mux.js +39 -0
  28. package/scratch/stream_avci.js +127 -0
  29. package/scratch/stream_mp4.js +78 -0
  30. package/scratch/stream_mux.js +47 -0
  31. package/scratch/stream_pcm.js +82 -0
  32. package/scratch/stream_wav.js +62 -0
  33. package/scripts/install_beamcoder_dependencies.sh +25 -0
  34. package/src/adaptor.h +202 -0
  35. package/src/beamcoder.cc +937 -0
  36. package/src/beamcoder_util.cc +1129 -0
  37. package/src/beamcoder_util.h +206 -0
  38. package/src/codec.cc +7386 -0
  39. package/src/codec.h +44 -0
  40. package/src/codec_par.cc +1818 -0
  41. package/src/codec_par.h +40 -0
  42. package/src/decode.cc +569 -0
  43. package/src/decode.h +75 -0
  44. package/src/demux.cc +584 -0
  45. package/src/demux.h +88 -0
  46. package/src/encode.cc +496 -0
  47. package/src/encode.h +72 -0
  48. package/src/filter.cc +1888 -0
  49. package/src/filter.h +30 -0
  50. package/src/format.cc +5287 -0
  51. package/src/format.h +77 -0
  52. package/src/frame.cc +2681 -0
  53. package/src/frame.h +52 -0
  54. package/src/governor.cc +286 -0
  55. package/src/governor.h +30 -0
  56. package/src/hwcontext.cc +378 -0
  57. package/src/hwcontext.h +35 -0
  58. package/src/log.cc +186 -0
  59. package/src/log.h +20 -0
  60. package/src/mux.cc +834 -0
  61. package/src/mux.h +106 -0
  62. package/src/packet.cc +762 -0
  63. package/src/packet.h +49 -0
  64. package/test/codecParamsSpec.js +148 -0
  65. package/test/decoderSpec.js +56 -0
  66. package/test/demuxerSpec.js +41 -0
  67. package/test/encoderSpec.js +69 -0
  68. package/test/filtererSpec.js +47 -0
  69. package/test/formatSpec.js +343 -0
  70. package/test/frameSpec.js +145 -0
  71. package/test/introspectionSpec.js +73 -0
  72. package/test/muxerSpec.js +34 -0
  73. package/test/packetSpec.js +122 -0
  74. package/types/Beamstreams.d.ts +98 -0
  75. package/types/Codec.d.ts +123 -0
  76. package/types/CodecContext.d.ts +555 -0
  77. package/types/CodecPar.d.ts +108 -0
  78. package/types/Decoder.d.ts +137 -0
  79. package/types/Demuxer.d.ts +113 -0
  80. package/types/Encoder.d.ts +94 -0
  81. package/types/Filter.d.ts +324 -0
  82. package/types/FormatContext.d.ts +380 -0
  83. package/types/Frame.d.ts +295 -0
  84. package/types/HWContext.d.ts +62 -0
  85. package/types/Muxer.d.ts +121 -0
  86. package/types/Packet.d.ts +82 -0
  87. package/types/PrivClass.d.ts +25 -0
  88. package/types/Stream.d.ts +165 -0
@@ -0,0 +1,206 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ #ifndef BEAMCODER_UTIL_H
23
+ #define BEAMCODER_UTIL_H
24
+
25
+ #include <chrono>
26
+ #include <stdio.h>
27
+ #include <string>
28
+ #include <unordered_map>
29
+ #include <algorithm>
30
+ #include "node_api.h"
31
+
32
+ extern "C" {
33
+ #include <libavutil/error.h>
34
+ #include <libavutil/pixdesc.h>
35
+ #include <libavutil/channel_layout.h>
36
+ #include <libavutil/opt.h>
37
+ #include <libavcodec/avcodec.h>
38
+ #include <libavformat/avformat.h>
39
+ }
40
+
41
+ #define DECLARE_NAPI_METHOD(name, func) { name, 0, func, 0, 0, 0, napi_default, 0 }
42
+ #define DECLARE_GETTER(name, getter, this) { name, 0, 0, getter, nop, nullptr, napi_enumerable, this }
43
+ #define DECLARE_GETTER2(name, test, getter, this) { name, 0, 0, test ? getter : nullptr, nop, nullptr, test ? napi_enumerable : napi_default, this }
44
+ #define DECLARE_GETTER3(name, test, getter, this) if ( test ) { desc[count++] = { name, 0, 0, getter, nullptr, nullptr, napi_enumerable, this }; }
45
+ // Handling NAPI errors - use "napi_status status;" where used
46
+ #define CHECK_STATUS if (checkStatus(env, status, __FILE__, __LINE__ - 1) != napi_ok) return nullptr
47
+ #define CHECK_BAIL if (checkStatus(env, status, __FILE__, __LINE__ - 1) != napi_ok) goto bail
48
+ #define PASS_STATUS if (status != napi_ok) return status
49
+ #define ACCEPT_STATUS(s) if ((status != s) && (status != napi_ok)) return status
50
+
51
+ napi_status checkStatus(napi_env env, napi_status status,
52
+ const char * file, uint32_t line);
53
+
54
+ // High resolution timing
55
+ #define HR_TIME_POINT std::chrono::high_resolution_clock::time_point
56
+ #define NOW std::chrono::high_resolution_clock::now()
57
+ long long microTime(std::chrono::high_resolution_clock::time_point start);
58
+
59
+ // Argument processing
60
+ napi_status checkArgs(napi_env env, napi_callback_info info, char* methodName,
61
+ napi_value* args, size_t argc, napi_valuetype* types);
62
+
63
+ // Async error handling
64
+ #define BEAMCODER_ERROR_START 5000
65
+ #define BEAMCODER_INVALID_ARGS 5001
66
+ #define BEAMCODER_ERROR_READ_FRAME 5002
67
+ #define BEAMCODER_ERROR_SEEK_FRAME 5003
68
+ #define BEAMCODER_ERROR_ALLOC_DECODER 5004
69
+ #define BEAMCODER_ERROR_EOF 5005
70
+ #define BEAMCODER_ERROR_EINVAL 5006
71
+ #define BEAMCODER_ERROR_ENOMEM 5007
72
+ #define BEAMCODER_ERROR_DECODE 5008
73
+ #define BEAMCODER_ERROR_OUT_OF_BOUNDS 5009
74
+ #define BEAMCODER_ERROR_ALLOC_ENCODER 5010
75
+ #define BEAMCODER_ERROR_ENCODE 5011
76
+ #define BEAMCODER_ERROR_OPENIO 5012
77
+ #define BEAMCODER_DICT_ERROR 5013
78
+ #define BEAMCODER_ERROR_WRITE_HEADER 5014
79
+ #define BEAMCODER_ERROR_INIT_OUTPUT 5015
80
+ #define BEAMCODER_ERROR_WRITE_FRAME 5016
81
+ #define BEAMCODER_ERROR_WRITE_TRAILER 5017
82
+ #define BEAMCODER_ERROR_FILTER_ADD_FRAME 5018
83
+ #define BEAMCODER_ERROR_FILTER_GET_FRAME 5019
84
+ #define BEAMCODER_SUCCESS 0
85
+
86
+ struct carrier {
87
+ virtual ~carrier() {}
88
+ napi_ref passthru = nullptr;
89
+ int32_t status = BEAMCODER_SUCCESS;
90
+ std::string errorMsg;
91
+ long long totalTime;
92
+ napi_deferred _deferred;
93
+ napi_async_work _request = nullptr;
94
+ };
95
+
96
+ void tidyCarrier(napi_env env, carrier* c);
97
+ int32_t rejectStatus(napi_env env, carrier* c, char* file, int32_t line);
98
+
99
+ #define REJECT_STATUS if (rejectStatus(env, c, (char*) __FILE__, __LINE__) != BEAMCODER_SUCCESS) return;
100
+ #define REJECT_BAIL if (rejectStatus(env, c, (char*) __FILE__, __LINE__) != BEAMCODER_SUCCESS) goto bail;
101
+ #define REJECT_RETURN if (rejectStatus(env, c, (char*) __FILE__, __LINE__) != BEAMCODER_SUCCESS) return promise;
102
+ #define FLOATING_STATUS if (status != napi_ok) { \
103
+ printf("Unexpected N-API status not OK in file %s at line %d value %i.\n", \
104
+ __FILE__, __LINE__ - 1, status); \
105
+ }
106
+
107
+ #define NAPI_THROW_ERROR(msg) { \
108
+ char errorMsg[256]; \
109
+ sprintf(errorMsg, "%s", msg); \
110
+ napi_throw_error(env, nullptr, errorMsg); \
111
+ return nullptr; \
112
+ }
113
+
114
+ #define REJECT_ERROR(msg, status) { \
115
+ c->errorMsg = msg; \
116
+ c->status = status; \
117
+ REJECT_STATUS; \
118
+ }
119
+
120
+ #define REJECT_ERROR_RETURN(msg, stat) { \
121
+ c->errorMsg = msg; \
122
+ c->status = stat; \
123
+ REJECT_RETURN; \
124
+ }
125
+
126
+ napi_value nop(napi_env env, napi_callback_info info);
127
+ char* avErrorMsg(const char* base, int avErrorCode);
128
+
129
+ napi_status beam_set_uint32(napi_env env, napi_value target, const char* name, uint32_t value);
130
+ napi_status beam_get_uint32(napi_env env, napi_value target, const char* name, uint32_t* value);
131
+ napi_status beam_set_int32(napi_env env, napi_value target, const char* name, int32_t value);
132
+ napi_status beam_get_int32(napi_env env, napi_value target, const char* name, int32_t* value);
133
+ napi_status beam_set_int64(napi_env env, napi_value target, const char* name, int64_t value);
134
+ napi_status beam_get_int64(napi_env env, napi_value target, const char* name, int64_t* value);
135
+ napi_status beam_set_double(napi_env env, napi_value target, const char* name, double value);
136
+ napi_status beam_get_double(napi_env env, napi_value target, const char* name, double* value);
137
+ napi_status beam_set_string_utf8(napi_env env, napi_value target, const char* name, const char* value);
138
+ napi_status beam_get_string_utf8(napi_env env, napi_value target, const char* name, char** value);
139
+ napi_status beam_set_bool(napi_env env, napi_value target, const char* name, bool value);
140
+ napi_status beam_get_bool(napi_env env, napi_value target, const char* name, bool* present, bool* value);
141
+ napi_status beam_set_rational(napi_env env, napi_value target, const char* name, AVRational value);
142
+ napi_status beam_get_rational(napi_env env, napi_value target, const char* name, AVRational* value);
143
+ napi_status beam_set_null(napi_env env, napi_value target, const char* name);
144
+ napi_status beam_is_null(napi_env env, napi_value props, const char* name, bool* isNull);
145
+ napi_status beam_delete_named_property(napi_env env, napi_value props, const char* name, bool* deleted);
146
+
147
+ #define BEAM_ENUM_UNKNOWN -42
148
+
149
+ template<typename K, typename V>
150
+ std::unordered_map<V,K> inverse_map(std::unordered_map<K,V> &map)
151
+ {
152
+ std::unordered_map<V,K> inv;
153
+ std::for_each(map.begin(), map.end(),
154
+ [&inv] (const std::pair<K,V> &p)
155
+ {
156
+ inv.insert(std::make_pair(p.second, p.first));
157
+ });
158
+ return inv;
159
+ }
160
+
161
+ const char* beam_lookup_name(std::unordered_map<int, std::string> m, int value);
162
+ int beam_lookup_enum(std::unordered_map<std::string, int> m, char* value);
163
+
164
+ struct beamEnum {
165
+ std::unordered_map<int, std::string> forward;
166
+ std::unordered_map<std::string, int> inverse;
167
+ beamEnum(std::unordered_map<int, std::string> fwd) : forward(fwd), inverse(inverse_map(fwd)) {};
168
+ };
169
+
170
+ napi_status beam_set_enum(napi_env env, napi_value target, char* name,
171
+ const beamEnum* enumDesc, int value);
172
+ napi_status beam_get_enum(napi_env env, napi_value target, char* name,
173
+ const beamEnum* enumDesc, int* value);
174
+
175
+ extern const beamEnum* beam_field_order;
176
+ extern const beamEnum* beam_ff_cmp;
177
+ extern const beamEnum* beam_ff_mb_decision;
178
+ extern const beamEnum* beam_av_audio_service_type;
179
+ extern const beamEnum* beam_ff_compliance;
180
+ extern const beamEnum* beam_ff_dct;
181
+ extern const beamEnum* beam_ff_idct;
182
+ extern const beamEnum* beam_avdiscard;
183
+ extern const beamEnum* beam_ff_sub_charenc_mode;
184
+ extern const beamEnum* beam_avmedia_type;
185
+ extern const beamEnum* beam_option_type;
186
+ extern const beamEnum* beam_avoid_neg_ts;
187
+ extern const beamEnum* beam_avfmt_duration2;
188
+ extern const beamEnum* beam_packet_side_data_type;
189
+ extern const beamEnum* beam_frame_side_data_type;
190
+ extern const beamEnum* beam_logging_level;
191
+
192
+ napi_value makeFrame(napi_env env, napi_callback_info info);
193
+
194
+ struct avBufRef {
195
+ napi_env env;
196
+ napi_ref ref;
197
+ int64_t pts = -1;
198
+ };
199
+
200
+ napi_status fromAVClass(napi_env env, const AVClass* cls, napi_value* result);
201
+ napi_status makeAVDictionary(napi_env env, napi_value options, AVDictionary** dict);
202
+
203
+ napi_status fromContextPrivData(napi_env env, void *privData, napi_value* result);
204
+ napi_status toContextPrivData(napi_env env, napi_value params, void* priv_data);
205
+
206
+ #endif // BEAMCODER_UTIL_H