Skip to content

Commit 8dc6c1f

Browse files
committed
progress
1 parent ebe3fa2 commit 8dc6c1f

File tree

5 files changed

+78
-68
lines changed

5 files changed

+78
-68
lines changed

binding.gyp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"targets": [{
33
"target_name" : "beamcoder",
4-
"sources" : [ "src/beamcoder.cc", "src/beamcoder_util.cc",
4+
"sources" : [ "src/beamcoder.cc", "src/beamcoder_util.cc",
5+
"src/log.cc" ,
56
"src/governor.cc", "src/demux.cc",
67
"src/decode.cc", "src/filter.cc",
78
"src/encode.cc", "src/mux.cc",
89
"src/packet.cc", "src/frame.cc",
910
"src/codec_par.cc", "src/format.cc",
10-
"src/codec.cc", "src/hwcontext.cc" ],
11+
"src/codec.cc", "src/hwcontext.cc"],
1112
"conditions": [
1213
['OS!="win"', {
1314
"defines": [

src/beamcoder.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ napi_value Init(napi_env env, napi_value exports) {
891891
DECLARE_NAPI_METHOD("configurations", configurations),
892892
DECLARE_NAPI_METHOD("licenses", licenses),
893893
DECLARE_NAPI_METHOD("logging", logging),
894+
// DECLARE_NAPI_METHOD("setLoggingCallback", setLoggingCallback),
894895
DECLARE_NAPI_METHOD("governor", governor),
895896
DECLARE_NAPI_METHOD("format", makeFormat),
896897
DECLARE_NAPI_METHOD("decoder", decoder),

src/log.cc

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
std::unordered_map<int, std::string> beam_logging_level_fmap = {
2-
{ AV_LOG_QUIET, "quiet" },
3-
{ AV_LOG_PANIC, "panic" },
4-
{ AV_LOG_FATAL, "fatal" },
5-
{ AV_LOG_ERROR, "error" },
6-
{ AV_LOG_WARNING, "warning" },
7-
{ AV_LOG_INFO, "info" },
8-
{ AV_LOG_VERBOSE, "verbose" },
9-
{ AV_LOG_DEBUG, "debug" },
10-
{ AV_LOG_TRACE, "trace" }
11-
};
1+
#include "node_api.h"
2+
#include <stdio.h>
3+
#include "log.h"
4+
5+
extern "C" {
6+
#include <libavutil/log.h>
7+
}
128

139
const beamEnum* beam_logging_level = new beamEnum(beam_logging_level_fmap);
1410

@@ -65,56 +61,51 @@ napi_value logging(napi_env env, napi_callback_info info) {
6561
return result;
6662
}
6763

68-
n_api_value set_logging_callback(napi_env env, napi_callback_info info){
69-
70-
napi_threadsafe_function status;
71-
napi_value result;
72-
73-
napi_value args[1];
74-
size_t argc = 1;
75-
status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
76-
CHECK_STATUS;
77-
78-
if (argc != 1) {
79-
status = napi_throw_error(env, nullptr, "One argumentis required to set logging callback.");
80-
return nullptr;
81-
}
82-
83-
napi_value callback = args[0];
84-
napi_valuetype t;
85-
status = napi_typeof(env, callback, &t);
86-
CHECK_STATUS;
87-
88-
if (t != napi_function) {
89-
status = napi_throw_type_error(env, nullptr, "Callback argument should be a function.");
90-
return nullptr;
91-
}
92-
93-
// Inspired from https://www.ffmpeg.org/doxygen/0.6/log_8c-source.html
94-
void av_log_custom_callback(void* ptr, int level, const char* fmt, va_list vl){
95-
static int print_prefix=1;
96-
static int count;
97-
static char prev[1024];
98-
char line[1024];
99-
static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9};
100-
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
101-
if(level>av_log_level)
102-
return;
103-
104-
napi_value arg;
105-
status = napi_create_string_utf8(env, line, &arg);
106-
CHECK_STATUS;
107-
108-
napi_value* argv = &arg;
109-
size_t argc = 1;
110-
napi_value return_val;
111-
112-
status = napi_call_function(env, global, callback, argc, argv, &return_val);
113-
CHECK_STATUS;
114-
}
115-
116-
117-
CHECK_STATUS;
118-
119-
120-
}
64+
// napi_value setLoggingCallback(napi_env env, napi_callback_info info){
65+
//
66+
// napi_threadsafe_function status;
67+
//
68+
// napi_value args[1];
69+
// size_t argc = 1;
70+
// status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
71+
// CHECK_STATUS;
72+
//
73+
// if (argc != 1) {
74+
// status = napi_throw_error(env, nullptr, "One argumentis required to set logging callback.");
75+
// return nullptr;
76+
// }
77+
//
78+
// napi_value callback = args[0];
79+
// napi_valuetype t;
80+
// status = napi_typeof(env, callback, &t);
81+
// CHECK_STATUS;
82+
//
83+
// if (t != napi_function) {
84+
// status = napi_throw_type_error(env, nullptr, "Callback argument should be a function.");
85+
// return nullptr;
86+
// }
87+
//
88+
// // Inspired from https://www.ffmpeg.org/doxygen/0.6/log_8c-source.html
89+
// void av_log_custom_callback(void* ptr, int level, const char* fmt, va_list vl){
90+
// static int print_prefix=1;
91+
// static int count;
92+
// static char prev[1024];
93+
// char line[1024];
94+
// static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9};
95+
// AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
96+
// if(level>av_log_level)
97+
// return;
98+
//
99+
// napi_value arg;
100+
// status = napi_create_string_utf8(env, line, &arg);
101+
// CHECK_STATUS;
102+
//
103+
// napi_value* argv = &arg;
104+
// size_t argc = 1;
105+
// napi_value return_val;
106+
//
107+
// status = napi_call_function(env, global, callback, argc, argv, &return_val);
108+
// CHECK_STATUS;
109+
// }
110+
// av_log_set_callback(av_log_custom_callback);
111+
// }

src/log.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33

44
#include "node_api.h"
55
#include "beamcoder_util.h"
6+
#include <stdio.h>
7+
#include <unordered_map>
68

79
extern const beamEnum* beam_logging_level;
810
napi_value logging(napi_env env, napi_callback_info info);
9-
11+
std::unordered_map<int, std::string> beam_logging_level_fmap = {
12+
{ AV_LOG_QUIET, "quiet" },
13+
{ AV_LOG_PANIC, "panic" },
14+
{ AV_LOG_FATAL, "fatal" },
15+
{ AV_LOG_ERROR, "error" },
16+
{ AV_LOG_WARNING, "warning" },
17+
{ AV_LOG_INFO, "info" },
18+
{ AV_LOG_VERBOSE, "verbose" },
19+
{ AV_LOG_DEBUG, "debug" },
20+
{ AV_LOG_TRACE, "trace" }
21+
};
22+
// napi_value setLoggingCallback(napi_env env, napi_callback_info info);
1023
#endif // BEAMCODER_LOG_H

test/introspectionSpec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ test('Muxer information', t => {
5353
t.end();
5454
});
5555

56-
test('Custom Logging', t => {
56+
test('Custom Logging', async t => {
57+
let n = 0;
5758
const cb = () => {
59+
n++;
5860
console.log('in callback')
5961
};
6062
beamcoder.setLoggingCallback(cb);
6163

64+
let dm = await beamcoder.demuxer('https://www.elecard.com/storage/video/bbb_1080p_c.ts');
65+
t.ok(n > 2);
6266
});

0 commit comments

Comments
 (0)