@theia/ffmpeg 1.53.0-next.5 → 1.53.0-next.55
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.
- package/README.md +3 -3
- package/binding.gyp +29 -29
- package/native/ffmpeg.c +146 -146
- package/native/ffmpeg.h +80 -80
- package/native/linux-ffmpeg.c +68 -68
- package/native/mac-ffmpeg.c +26 -26
- package/native/win-ffmpeg.c +77 -77
- package/package.json +2 -2
- package/src/check-ffmpeg.ts +56 -56
- package/src/ffmpeg.ts +114 -114
- package/src/hash.ts +28 -28
- package/src/index.ts +20 -20
- package/src/replace-ffmpeg.ts +80 -80
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# `ffmeg.node`
|
|
2
|
-
|
|
3
|
-
This is a [Node Native Addon](https://nodejs.org/docs/latest-v14.x/api/n-api.html) to dynamically link to Electron's `ffmpeg.dll` and fetch a list of included codecs.
|
|
1
|
+
# `ffmeg.node`
|
|
2
|
+
|
|
3
|
+
This is a [Node Native Addon](https://nodejs.org/docs/latest-v14.x/api/n-api.html) to dynamically link to Electron's `ffmpeg.dll` and fetch a list of included codecs.
|
package/binding.gyp
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
'targets': [{
|
|
3
|
-
'defines': ['NAPI_VERSION=2'],
|
|
4
|
-
'target_name': 'ffmpeg',
|
|
5
|
-
'sources': [
|
|
6
|
-
'native/ffmpeg.c',
|
|
7
|
-
],
|
|
8
|
-
'conditions': [
|
|
9
|
-
['OS=="linux"', {
|
|
10
|
-
'sources': [
|
|
11
|
-
'native/linux-ffmpeg.c',
|
|
12
|
-
],
|
|
13
|
-
'libraries': [
|
|
14
|
-
'-ldl',
|
|
15
|
-
]
|
|
16
|
-
}],
|
|
17
|
-
['OS=="mac"', {
|
|
18
|
-
'sources': [
|
|
19
|
-
'native/mac-ffmpeg.c',
|
|
20
|
-
]
|
|
21
|
-
}],
|
|
22
|
-
['OS=="win"', {
|
|
23
|
-
'sources': [
|
|
24
|
-
'native/win-ffmpeg.c',
|
|
25
|
-
]
|
|
26
|
-
}],
|
|
27
|
-
],
|
|
28
|
-
}],
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
'targets': [{
|
|
3
|
+
'defines': ['NAPI_VERSION=2'],
|
|
4
|
+
'target_name': 'ffmpeg',
|
|
5
|
+
'sources': [
|
|
6
|
+
'native/ffmpeg.c',
|
|
7
|
+
],
|
|
8
|
+
'conditions': [
|
|
9
|
+
['OS=="linux"', {
|
|
10
|
+
'sources': [
|
|
11
|
+
'native/linux-ffmpeg.c',
|
|
12
|
+
],
|
|
13
|
+
'libraries': [
|
|
14
|
+
'-ldl',
|
|
15
|
+
]
|
|
16
|
+
}],
|
|
17
|
+
['OS=="mac"', {
|
|
18
|
+
'sources': [
|
|
19
|
+
'native/mac-ffmpeg.c',
|
|
20
|
+
]
|
|
21
|
+
}],
|
|
22
|
+
['OS=="win"', {
|
|
23
|
+
'sources': [
|
|
24
|
+
'native/win-ffmpeg.c',
|
|
25
|
+
]
|
|
26
|
+
}],
|
|
27
|
+
],
|
|
28
|
+
}],
|
|
29
|
+
}
|
package/native/ffmpeg.c
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_n_api
|
|
19
|
-
*/
|
|
20
|
-
#include <node_api.h>
|
|
21
|
-
|
|
22
|
-
#include <string.h>
|
|
23
|
-
|
|
24
|
-
#include "ffmpeg.h"
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Return the list of codecs registered in the FFMPEG library.
|
|
28
|
-
*/
|
|
29
|
-
napi_value codecs(napi_env env, napi_callback_info info)
|
|
30
|
-
{
|
|
31
|
-
// We will reuse this `status` for all napi calls.
|
|
32
|
-
napi_status status;
|
|
33
|
-
char *error = NULL;
|
|
34
|
-
|
|
35
|
-
// Get arguments.
|
|
36
|
-
size_t argc = 1;
|
|
37
|
-
napi_value argv[1];
|
|
38
|
-
status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
|
|
39
|
-
if (status != napi_ok || argc < 1)
|
|
40
|
-
{
|
|
41
|
-
error = "invalid arguments";
|
|
42
|
-
goto error;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Get first argument as string.
|
|
46
|
-
char path[2048];
|
|
47
|
-
status = napi_get_value_string_utf8(env, argv[0], path, 2048, NULL);
|
|
48
|
-
if (status != napi_ok)
|
|
49
|
-
{
|
|
50
|
-
error = "invalid string argument";
|
|
51
|
-
goto error;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Load ffmpeg based on the provided path.
|
|
55
|
-
struct FFMPEG_Library ffmpeg = NULL_FFMPEG_LIBRARY;
|
|
56
|
-
char *load_error = load_ffmpeg_library(&ffmpeg, path);
|
|
57
|
-
if (load_error != NULL)
|
|
58
|
-
{
|
|
59
|
-
error = load_error;
|
|
60
|
-
goto error;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Create the JavaScript list that will be returned.
|
|
64
|
-
napi_value codecs;
|
|
65
|
-
status = napi_create_array(env, &codecs);
|
|
66
|
-
if (status != napi_ok)
|
|
67
|
-
{
|
|
68
|
-
error = "napi_create_array fail";
|
|
69
|
-
goto error;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Iterate over the codec descriptions.
|
|
73
|
-
// It includes descriptions for codecs that may not be present in the library.
|
|
74
|
-
struct AVCodecDescriptor *descriptor = ffmpeg.avcodec_descriptor_next(NULL);
|
|
75
|
-
while (descriptor != NULL)
|
|
76
|
-
{
|
|
77
|
-
// Try to fetch the codec being described, returns null on missing codecs.
|
|
78
|
-
struct AVCodec *decoder = ffmpeg.avcodec_find_decoder(descriptor->id);
|
|
79
|
-
if (decoder != NULL)
|
|
80
|
-
{
|
|
81
|
-
// Create the codec object and assign the properties.
|
|
82
|
-
napi_value object, value;
|
|
83
|
-
napi_create_object(env, &object);
|
|
84
|
-
|
|
85
|
-
// id: number
|
|
86
|
-
napi_create_int32(env, decoder->id, &value);
|
|
87
|
-
napi_set_named_property(env, object, "id", value);
|
|
88
|
-
|
|
89
|
-
// name: string
|
|
90
|
-
napi_create_string_utf8(env, decoder->name, strlen(decoder->name), &value);
|
|
91
|
-
napi_set_named_property(env, object, "name", value);
|
|
92
|
-
|
|
93
|
-
// longName: string
|
|
94
|
-
napi_create_string_utf8(env, decoder->long_name, strlen(decoder->long_name), &value);
|
|
95
|
-
napi_set_named_property(env, object, "longName", value);
|
|
96
|
-
|
|
97
|
-
// Pushing into a JS array requires calling the JS method for that.
|
|
98
|
-
napi_value push_fn;
|
|
99
|
-
napi_get_named_property(env, codecs, "push", &push_fn);
|
|
100
|
-
napi_call_function(env, codecs, push_fn, 1, (napi_value[]){object}, NULL);
|
|
101
|
-
}
|
|
102
|
-
descriptor = ffmpeg.avcodec_descriptor_next(descriptor);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Free the ffmpeg library.
|
|
106
|
-
char *unload_error = unload_ffmpeg_library(&ffmpeg);
|
|
107
|
-
if (unload_error != NULL)
|
|
108
|
-
{
|
|
109
|
-
error = unload_error;
|
|
110
|
-
goto error;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return codecs;
|
|
114
|
-
|
|
115
|
-
error:
|
|
116
|
-
if (error != NULL)
|
|
117
|
-
{
|
|
118
|
-
napi_throw_error(env, NULL, error);
|
|
119
|
-
}
|
|
120
|
-
return NULL;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_module_registration
|
|
125
|
-
*/
|
|
126
|
-
napi_value initialize(napi_env env, napi_value exports)
|
|
127
|
-
{
|
|
128
|
-
napi_status status;
|
|
129
|
-
napi_value function_codecs;
|
|
130
|
-
|
|
131
|
-
status = napi_create_function(env, NULL, 0, codecs, NULL, &function_codecs);
|
|
132
|
-
if (status != napi_ok)
|
|
133
|
-
{
|
|
134
|
-
return NULL;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
status = napi_set_named_property(env, exports, "codecs", function_codecs);
|
|
138
|
-
if (status != napi_ok)
|
|
139
|
-
{
|
|
140
|
-
return NULL;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return exports;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
NAPI_MODULE(NODE_GYP_MODULE_NAME, initialize);
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2019 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_n_api
|
|
19
|
+
*/
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
|
|
22
|
+
#include <string.h>
|
|
23
|
+
|
|
24
|
+
#include "ffmpeg.h"
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Return the list of codecs registered in the FFMPEG library.
|
|
28
|
+
*/
|
|
29
|
+
napi_value codecs(napi_env env, napi_callback_info info)
|
|
30
|
+
{
|
|
31
|
+
// We will reuse this `status` for all napi calls.
|
|
32
|
+
napi_status status;
|
|
33
|
+
char *error = NULL;
|
|
34
|
+
|
|
35
|
+
// Get arguments.
|
|
36
|
+
size_t argc = 1;
|
|
37
|
+
napi_value argv[1];
|
|
38
|
+
status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
|
|
39
|
+
if (status != napi_ok || argc < 1)
|
|
40
|
+
{
|
|
41
|
+
error = "invalid arguments";
|
|
42
|
+
goto error;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get first argument as string.
|
|
46
|
+
char path[2048];
|
|
47
|
+
status = napi_get_value_string_utf8(env, argv[0], path, 2048, NULL);
|
|
48
|
+
if (status != napi_ok)
|
|
49
|
+
{
|
|
50
|
+
error = "invalid string argument";
|
|
51
|
+
goto error;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Load ffmpeg based on the provided path.
|
|
55
|
+
struct FFMPEG_Library ffmpeg = NULL_FFMPEG_LIBRARY;
|
|
56
|
+
char *load_error = load_ffmpeg_library(&ffmpeg, path);
|
|
57
|
+
if (load_error != NULL)
|
|
58
|
+
{
|
|
59
|
+
error = load_error;
|
|
60
|
+
goto error;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Create the JavaScript list that will be returned.
|
|
64
|
+
napi_value codecs;
|
|
65
|
+
status = napi_create_array(env, &codecs);
|
|
66
|
+
if (status != napi_ok)
|
|
67
|
+
{
|
|
68
|
+
error = "napi_create_array fail";
|
|
69
|
+
goto error;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Iterate over the codec descriptions.
|
|
73
|
+
// It includes descriptions for codecs that may not be present in the library.
|
|
74
|
+
struct AVCodecDescriptor *descriptor = ffmpeg.avcodec_descriptor_next(NULL);
|
|
75
|
+
while (descriptor != NULL)
|
|
76
|
+
{
|
|
77
|
+
// Try to fetch the codec being described, returns null on missing codecs.
|
|
78
|
+
struct AVCodec *decoder = ffmpeg.avcodec_find_decoder(descriptor->id);
|
|
79
|
+
if (decoder != NULL)
|
|
80
|
+
{
|
|
81
|
+
// Create the codec object and assign the properties.
|
|
82
|
+
napi_value object, value;
|
|
83
|
+
napi_create_object(env, &object);
|
|
84
|
+
|
|
85
|
+
// id: number
|
|
86
|
+
napi_create_int32(env, decoder->id, &value);
|
|
87
|
+
napi_set_named_property(env, object, "id", value);
|
|
88
|
+
|
|
89
|
+
// name: string
|
|
90
|
+
napi_create_string_utf8(env, decoder->name, strlen(decoder->name), &value);
|
|
91
|
+
napi_set_named_property(env, object, "name", value);
|
|
92
|
+
|
|
93
|
+
// longName: string
|
|
94
|
+
napi_create_string_utf8(env, decoder->long_name, strlen(decoder->long_name), &value);
|
|
95
|
+
napi_set_named_property(env, object, "longName", value);
|
|
96
|
+
|
|
97
|
+
// Pushing into a JS array requires calling the JS method for that.
|
|
98
|
+
napi_value push_fn;
|
|
99
|
+
napi_get_named_property(env, codecs, "push", &push_fn);
|
|
100
|
+
napi_call_function(env, codecs, push_fn, 1, (napi_value[]){object}, NULL);
|
|
101
|
+
}
|
|
102
|
+
descriptor = ffmpeg.avcodec_descriptor_next(descriptor);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Free the ffmpeg library.
|
|
106
|
+
char *unload_error = unload_ffmpeg_library(&ffmpeg);
|
|
107
|
+
if (unload_error != NULL)
|
|
108
|
+
{
|
|
109
|
+
error = unload_error;
|
|
110
|
+
goto error;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return codecs;
|
|
114
|
+
|
|
115
|
+
error:
|
|
116
|
+
if (error != NULL)
|
|
117
|
+
{
|
|
118
|
+
napi_throw_error(env, NULL, error);
|
|
119
|
+
}
|
|
120
|
+
return NULL;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_module_registration
|
|
125
|
+
*/
|
|
126
|
+
napi_value initialize(napi_env env, napi_value exports)
|
|
127
|
+
{
|
|
128
|
+
napi_status status;
|
|
129
|
+
napi_value function_codecs;
|
|
130
|
+
|
|
131
|
+
status = napi_create_function(env, NULL, 0, codecs, NULL, &function_codecs);
|
|
132
|
+
if (status != napi_ok)
|
|
133
|
+
{
|
|
134
|
+
return NULL;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
status = napi_set_named_property(env, exports, "codecs", function_codecs);
|
|
138
|
+
if (status != napi_ok)
|
|
139
|
+
{
|
|
140
|
+
return NULL;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return exports;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
NAPI_MODULE(NODE_GYP_MODULE_NAME, initialize);
|
package/native/ffmpeg.h
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
#ifndef FFMPEG_H
|
|
2
|
-
#define FFMPEG_H
|
|
3
|
-
/**
|
|
4
|
-
* THIS FILE REDEFINES DATA AS RETURNED BY THE FFMPEG LIBRARY.
|
|
5
|
-
* HEADER FILES ARE NOT DISTRIBUTED IN OUR SETUP, HENCE THIS.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavutil/avutil.h#L193-L201
|
|
10
|
-
*/
|
|
11
|
-
enum AVMediaType
|
|
12
|
-
{
|
|
13
|
-
_UNKNOWN_DATA_AVMediaType = -1,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L191-L653
|
|
18
|
-
*/
|
|
19
|
-
enum AVCodecID
|
|
20
|
-
{
|
|
21
|
-
__UNKNOWN_DATA_AVCodecID = 0,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L3611-L3721
|
|
26
|
-
*/
|
|
27
|
-
struct AVCodec
|
|
28
|
-
{
|
|
29
|
-
const char *name, *long_name;
|
|
30
|
-
enum AVMediaType type;
|
|
31
|
-
enum AVCodecID id;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L660-L688
|
|
36
|
-
*/
|
|
37
|
-
struct AVCodecDescriptor
|
|
38
|
-
{
|
|
39
|
-
enum AVCodecID id;
|
|
40
|
-
enum AVMediaType type;
|
|
41
|
-
const char *name, *long_name;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Wrapper around the ffmpeg library that must be loaded at runtime.
|
|
46
|
-
*/
|
|
47
|
-
struct FFMPEG_Library
|
|
48
|
-
{
|
|
49
|
-
void *handle;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L6228
|
|
53
|
-
*
|
|
54
|
-
* We use AVCodecDescriptor because it is the only structure that we can
|
|
55
|
-
* query on all platforms. Windows' ffmpeg.dll does not export a
|
|
56
|
-
* `av_codec_next` function, only `avcodec_descriptor_next`.
|
|
57
|
-
* Also it seems that this "descriptor" concept is the recommended API.
|
|
58
|
-
*/
|
|
59
|
-
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L4646
|
|
63
|
-
*/
|
|
64
|
-
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
#define NULL_FFMPEG_LIBRARY \
|
|
68
|
-
(struct FFMPEG_Library) { NULL, NULL, NULL }
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Loader that will inject the loaded functions into a FFMPEG_Library structure.
|
|
72
|
-
*/
|
|
73
|
-
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Free library.
|
|
77
|
-
*/
|
|
78
|
-
char *unload_ffmpeg_library(struct FFMPEG_Library *library);
|
|
79
|
-
|
|
80
|
-
#endif // FFMPEG_H guard
|
|
1
|
+
#ifndef FFMPEG_H
|
|
2
|
+
#define FFMPEG_H
|
|
3
|
+
/**
|
|
4
|
+
* THIS FILE REDEFINES DATA AS RETURNED BY THE FFMPEG LIBRARY.
|
|
5
|
+
* HEADER FILES ARE NOT DISTRIBUTED IN OUR SETUP, HENCE THIS.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavutil/avutil.h#L193-L201
|
|
10
|
+
*/
|
|
11
|
+
enum AVMediaType
|
|
12
|
+
{
|
|
13
|
+
_UNKNOWN_DATA_AVMediaType = -1,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L191-L653
|
|
18
|
+
*/
|
|
19
|
+
enum AVCodecID
|
|
20
|
+
{
|
|
21
|
+
__UNKNOWN_DATA_AVCodecID = 0,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L3611-L3721
|
|
26
|
+
*/
|
|
27
|
+
struct AVCodec
|
|
28
|
+
{
|
|
29
|
+
const char *name, *long_name;
|
|
30
|
+
enum AVMediaType type;
|
|
31
|
+
enum AVCodecID id;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L660-L688
|
|
36
|
+
*/
|
|
37
|
+
struct AVCodecDescriptor
|
|
38
|
+
{
|
|
39
|
+
enum AVCodecID id;
|
|
40
|
+
enum AVMediaType type;
|
|
41
|
+
const char *name, *long_name;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Wrapper around the ffmpeg library that must be loaded at runtime.
|
|
46
|
+
*/
|
|
47
|
+
struct FFMPEG_Library
|
|
48
|
+
{
|
|
49
|
+
void *handle;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L6228
|
|
53
|
+
*
|
|
54
|
+
* We use AVCodecDescriptor because it is the only structure that we can
|
|
55
|
+
* query on all platforms. Windows' ffmpeg.dll does not export a
|
|
56
|
+
* `av_codec_next` function, only `avcodec_descriptor_next`.
|
|
57
|
+
* Also it seems that this "descriptor" concept is the recommended API.
|
|
58
|
+
*/
|
|
59
|
+
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L4646
|
|
63
|
+
*/
|
|
64
|
+
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
#define NULL_FFMPEG_LIBRARY \
|
|
68
|
+
(struct FFMPEG_Library) { NULL, NULL, NULL }
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Loader that will inject the loaded functions into a FFMPEG_Library structure.
|
|
72
|
+
*/
|
|
73
|
+
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Free library.
|
|
77
|
+
*/
|
|
78
|
+
char *unload_ffmpeg_library(struct FFMPEG_Library *library);
|
|
79
|
+
|
|
80
|
+
#endif // FFMPEG_H guard
|
package/native/linux-ffmpeg.c
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
#ifndef LINUX_FFMPEG
|
|
18
|
-
#define LINUX_FFMPEG
|
|
19
|
-
|
|
20
|
-
#include <stdlib.h>
|
|
21
|
-
#include <dlfcn.h>
|
|
22
|
-
|
|
23
|
-
#include "ffmpeg.h"
|
|
24
|
-
|
|
25
|
-
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
|
|
26
|
-
{
|
|
27
|
-
void *handle = dlopen(library_path, RTLD_NOW);
|
|
28
|
-
char *error = dlerror();
|
|
29
|
-
if (error != NULL)
|
|
30
|
-
{
|
|
31
|
-
goto error;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *) = dlsym(handle, "avcodec_descriptor_next");
|
|
35
|
-
error = dlerror();
|
|
36
|
-
if (error != NULL)
|
|
37
|
-
{
|
|
38
|
-
goto error;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = dlsym(handle, "avcodec_find_decoder");
|
|
42
|
-
error = dlerror();
|
|
43
|
-
if (error != NULL)
|
|
44
|
-
{
|
|
45
|
-
goto error;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
library->handle = handle;
|
|
49
|
-
library->avcodec_descriptor_next = avcodec_descriptor_next;
|
|
50
|
-
library->avcodec_find_decoder = avcodec_find_decoder;
|
|
51
|
-
return NULL;
|
|
52
|
-
|
|
53
|
-
error:
|
|
54
|
-
if (handle != NULL)
|
|
55
|
-
{
|
|
56
|
-
dlclose(handle);
|
|
57
|
-
}
|
|
58
|
-
return error;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
|
|
62
|
-
{
|
|
63
|
-
dlclose(library->handle);
|
|
64
|
-
*library = NULL_FFMPEG_LIBRARY;
|
|
65
|
-
return dlerror();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
#endif // LINUX_FFMPEG guard
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2019 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
#ifndef LINUX_FFMPEG
|
|
18
|
+
#define LINUX_FFMPEG
|
|
19
|
+
|
|
20
|
+
#include <stdlib.h>
|
|
21
|
+
#include <dlfcn.h>
|
|
22
|
+
|
|
23
|
+
#include "ffmpeg.h"
|
|
24
|
+
|
|
25
|
+
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
|
|
26
|
+
{
|
|
27
|
+
void *handle = dlopen(library_path, RTLD_NOW);
|
|
28
|
+
char *error = dlerror();
|
|
29
|
+
if (error != NULL)
|
|
30
|
+
{
|
|
31
|
+
goto error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *) = dlsym(handle, "avcodec_descriptor_next");
|
|
35
|
+
error = dlerror();
|
|
36
|
+
if (error != NULL)
|
|
37
|
+
{
|
|
38
|
+
goto error;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = dlsym(handle, "avcodec_find_decoder");
|
|
42
|
+
error = dlerror();
|
|
43
|
+
if (error != NULL)
|
|
44
|
+
{
|
|
45
|
+
goto error;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
library->handle = handle;
|
|
49
|
+
library->avcodec_descriptor_next = avcodec_descriptor_next;
|
|
50
|
+
library->avcodec_find_decoder = avcodec_find_decoder;
|
|
51
|
+
return NULL;
|
|
52
|
+
|
|
53
|
+
error:
|
|
54
|
+
if (handle != NULL)
|
|
55
|
+
{
|
|
56
|
+
dlclose(handle);
|
|
57
|
+
}
|
|
58
|
+
return error;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
|
|
62
|
+
{
|
|
63
|
+
dlclose(library->handle);
|
|
64
|
+
*library = NULL_FFMPEG_LIBRARY;
|
|
65
|
+
return dlerror();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#endif // LINUX_FFMPEG guard
|