deploy: current vibn theia state
Some checks failed
Playwright Tests / Playwright Tests (ubuntu-22.04, Node.js 22.x) (push) Has been cancelled
3PP License Check / 3PP License Check (11, 22.x, ubuntu-22.04) (push) Has been cancelled
Publish packages to NPM / Perform Publishing (push) Has been cancelled

Made-with: Cursor
This commit is contained in:
2026-02-27 12:01:08 -08:00
commit 8bb5110148
3782 changed files with 640947 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
// *****************************************************************************
// Copyright (C) 2019 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
/**
* https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_n_api
*/
#include <node_api.h>
#include <string.h>
#include "ffmpeg.h"
/**
* Return the list of codecs registered in the FFMPEG library.
*/
napi_value codecs(napi_env env, napi_callback_info info)
{
// We will reuse this `status` for all napi calls.
napi_status status;
char *error = NULL;
// Get arguments.
size_t argc = 1;
napi_value argv[1];
status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
if (status != napi_ok || argc < 1)
{
error = "invalid arguments";
goto error;
}
// Get first argument as string.
char path[2048];
status = napi_get_value_string_utf8(env, argv[0], path, 2048, NULL);
if (status != napi_ok)
{
error = "invalid string argument";
goto error;
}
// Load ffmpeg based on the provided path.
struct FFMPEG_Library ffmpeg = NULL_FFMPEG_LIBRARY;
char *load_error = load_ffmpeg_library(&ffmpeg, path);
if (load_error != NULL)
{
error = load_error;
goto error;
}
// Create the JavaScript list that will be returned.
napi_value codecs;
status = napi_create_array(env, &codecs);
if (status != napi_ok)
{
error = "napi_create_array fail";
goto error;
}
// Iterate over the codec descriptions.
// It includes descriptions for codecs that may not be present in the library.
struct AVCodecDescriptor *descriptor = ffmpeg.avcodec_descriptor_next(NULL);
while (descriptor != NULL)
{
// Try to fetch the codec being described, returns null on missing codecs.
struct AVCodec *decoder = ffmpeg.avcodec_find_decoder(descriptor->id);
if (decoder != NULL)
{
// Create the codec object and assign the properties.
napi_value object, value;
napi_create_object(env, &object);
// id: number
napi_create_int32(env, decoder->id, &value);
napi_set_named_property(env, object, "id", value);
// name: string
napi_create_string_utf8(env, decoder->name, strlen(decoder->name), &value);
napi_set_named_property(env, object, "name", value);
// longName: string
napi_create_string_utf8(env, decoder->long_name, strlen(decoder->long_name), &value);
napi_set_named_property(env, object, "longName", value);
// Pushing into a JS array requires calling the JS method for that.
napi_value push_fn;
napi_get_named_property(env, codecs, "push", &push_fn);
napi_call_function(env, codecs, push_fn, 1, (napi_value[]){object}, NULL);
}
descriptor = ffmpeg.avcodec_descriptor_next(descriptor);
}
// Free the ffmpeg library.
char *unload_error = unload_ffmpeg_library(&ffmpeg);
if (unload_error != NULL)
{
error = unload_error;
goto error;
}
return codecs;
error:
if (error != NULL)
{
napi_throw_error(env, NULL, error);
}
return NULL;
}
/**
* https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_module_registration
*/
napi_value initialize(napi_env env, napi_value exports)
{
napi_status status;
napi_value function_codecs;
status = napi_create_function(env, NULL, 0, codecs, NULL, &function_codecs);
if (status != napi_ok)
{
return NULL;
}
status = napi_set_named_property(env, exports, "codecs", function_codecs);
if (status != napi_ok)
{
return NULL;
}
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, initialize);

View File

@@ -0,0 +1,80 @@
#ifndef FFMPEG_H
#define FFMPEG_H
/**
* THIS FILE REDEFINES DATA AS RETURNED BY THE FFMPEG LIBRARY.
* HEADER FILES ARE NOT DISTRIBUTED IN OUR SETUP, HENCE THIS.
*/
/**
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavutil/avutil.h#L193-L201
*/
enum AVMediaType
{
_UNKNOWN_DATA_AVMediaType = -1,
};
/**
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L191-L653
*/
enum AVCodecID
{
__UNKNOWN_DATA_AVCodecID = 0,
};
/**
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L3611-L3721
*/
struct AVCodec
{
const char *name, *long_name;
enum AVMediaType type;
enum AVCodecID id;
};
/**
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L660-L688
*/
struct AVCodecDescriptor
{
enum AVCodecID id;
enum AVMediaType type;
const char *name, *long_name;
};
/**
* Wrapper around the ffmpeg library that must be loaded at runtime.
*/
struct FFMPEG_Library
{
void *handle;
/**
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L6228
*
* We use AVCodecDescriptor because it is the only structure that we can
* query on all platforms. Windows' ffmpeg.dll does not export a
* `av_codec_next` function, only `avcodec_descriptor_next`.
* Also it seems that this "descriptor" concept is the recommended API.
*/
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *);
/**
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L4646
*/
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID);
};
#define NULL_FFMPEG_LIBRARY \
(struct FFMPEG_Library) { NULL, NULL, NULL }
/**
* Loader that will inject the loaded functions into a FFMPEG_Library structure.
*/
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path);
/**
* Free library.
*/
char *unload_ffmpeg_library(struct FFMPEG_Library *library);
#endif // FFMPEG_H guard

View File

@@ -0,0 +1,68 @@
// *****************************************************************************
// Copyright (C) 2019 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
#ifndef LINUX_FFMPEG
#define LINUX_FFMPEG
#include <stdlib.h>
#include <dlfcn.h>
#include "ffmpeg.h"
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
{
void *handle = dlopen(library_path, RTLD_NOW);
char *error = dlerror();
if (error != NULL)
{
goto error;
}
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *) = dlsym(handle, "avcodec_descriptor_next");
error = dlerror();
if (error != NULL)
{
goto error;
}
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = dlsym(handle, "avcodec_find_decoder");
error = dlerror();
if (error != NULL)
{
goto error;
}
library->handle = handle;
library->avcodec_descriptor_next = avcodec_descriptor_next;
library->avcodec_find_decoder = avcodec_find_decoder;
return NULL;
error:
if (handle != NULL)
{
dlclose(handle);
}
return error;
}
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
{
dlclose(library->handle);
*library = NULL_FFMPEG_LIBRARY;
return dlerror();
}
#endif // LINUX_FFMPEG guard

View File

@@ -0,0 +1,26 @@
// *****************************************************************************
// Copyright (C) 2019 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
#ifndef MAC_FFMPEG
#define MAC_FFMPEG
/**
* Mac seems to use the same libraries as Linux.
* Difference is that the compiler doesn't need to be told to use `-ldl`.
*/
#include "./linux-ffmpeg.c"
#endif // MAC_FFMPEG guard

View File

@@ -0,0 +1,77 @@
// *****************************************************************************
// Copyright (C) 2019 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
#ifndef WIN_FFMPEG
#define WIN_FFMPEG
#include <windows.h>
#include "ffmpeg.h"
static char *error_library_not_found = "shared library not found";
static char *error_function_not_found = "function not found in shared library";
static char *error_cannot_free_library = "cannot free shared library";
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
{
char *error = NULL;
HMODULE handle = LoadLibrary(library_path);
if (!handle)
{
error = error_library_not_found;
goto error;
}
struct AVCodecDescriptor *(*av_codec_next)(const struct AVCodecDescriptor *) = (struct AVCodecDescriptor * (*)(const struct AVCodecDescriptor *))
GetProcAddress(handle, "avcodec_descriptor_next");
if (!av_codec_next)
{
error = error_function_not_found;
goto error;
}
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = (struct AVCodec * (*)(enum AVCodecID))
GetProcAddress(handle, "avcodec_find_decoder");
if (!avcodec_find_decoder)
{
error = error_function_not_found;
goto error;
}
library->handle = handle;
library->avcodec_descriptor_next = av_codec_next;
library->avcodec_find_decoder = avcodec_find_decoder;
return NULL;
error:
if (handle)
{
FreeLibrary(handle);
}
return error;
}
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
{
if (library->handle && FreeLibrary(library->handle))
{
*library = NULL_FFMPEG_LIBRARY;
return NULL;
}
return error_cannot_free_library;
}
#endif // WIN_FFMPEG guard