Skip to content

Instantly share code, notes, and snippets.

@RomiTT
RomiTT / Example.cpp
Last active July 18, 2019 04:02
For thread-safe function call in native node module.
Napi::Value FGM::test(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
auto cb = info[0].As<Napi::Function>();
threadSafeCallback = ThreadSafeFunction::Create(cb);
std::thread t([threadSafeCallback]() => {
// do something
libvlc_media_add_option(m, ":avcodec-hw=dxva2");
// Below is the information about option list.
/* Input */
var_Create (mp, "rate", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT);
var_Create (mp, "sout", VLC_VAR_STRING);
var_Create (mp, "demux-filter", VLC_VAR_STRING);
@RomiTT
RomiTT / RGB_DEFAULT.hlsl
Last active January 11, 2024 12:38
YUV to RGB HLSL Shaders - DirectX 11
//-----------------------------------------------------------
// YUV TO RGB BT.601 For SD TV
//-----------------------------------------------------------
cbuffer PS_CONSTANT_BUFFER : register(b0)
{
float Opacity;
float ignoreA;
float ignoreB;
float ignoreC;
@RomiTT
RomiTT / VideoTexture.cpp
Last active August 25, 2019 19:20
Creating a texture for pixel shader and updating the texture in DirectX 11.
//------------------------------------------------
// Creating texture for rendering video
//------------------------------------------------
// ID3D11Device* Device
ID3D11Texture2D* texture = nullptr;
D3D11_TEXTURE2D_DESC td;
RtlZeroMemory(&td, sizeof(D3D11_TEXTURE2D_DESC));
@RomiTT
RomiTT / pseudo_code.cpp
Last active July 29, 2023 10:42
Tip for implementing VLC custom callback with DirectX
// VLC prepares to render a video frame.
static void* lock(void* data, void** p_pixels) {
return NULL; // Picture identifier, not needed here.
}
// VLC just rendered a video frame.
static void unlock(void* data, void* id, void* const* p_pixels) {
}
// VLC wants to display a video frame.
@RomiTT
RomiTT / picture_CopyPixels.c
Created August 12, 2019 15:45
vlc functions.
void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
{
for( int i = 0; i < p_src->i_planes ; i++ )
plane_CopyPixels( p_dst->p+i, p_src->p+i );
assert( p_dst->context == NULL );
if( p_src->context != NULL )
p_dst->context = p_src->context->copy( p_src->context );
}
libvlc_media_track_t** pp_tracks;
unsigned i_count = libvlc_media_tracks_get(m, &pp_tracks);
if (i_count > 0) {
for (unsigned i = 0; i < i_count; ++i)
{
libvlc_media_track_t* p_track = pp_tracks[i];
switch (p_track->i_type)
{
case libvlc_track_audio:
@RomiTT
RomiTT / fragment_shader_NV12_to_RGB.frag
Created November 5, 2019 16:29 — forked from crearo/fragment_shader_NV12_to_RGB.frag
A fragment shader to convert NV12 to RGB.
/** A fragment shader to convert NV12 to RGB.
* Input textures Y - is a block of size w*h.
* texture UV is of size w*h/2.
* Remember, both U and V are individually of size w/2*h/2, but they are interleaved.
* The layout looks like this :
* ----------
* | |
* | Y | size = w*h
* | |
* |________|
void copy_texture(GLuint srcTex, GLuint destTex, int width, int height) {
GLuint fboIds[2];
glGenFramebuffers(2, fboIds);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboIds[0]);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, srcTex, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboIds[1]);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTex, 0);
@RomiTT
RomiTT / glfw_ship.cpp
Created March 3, 2020 17:06 — forked from ad8e/glfw_ship.cpp
instructions to use skia and glfw together. (download, installation, first program). works on Linux and Windows.
/* Note: this Google copyright notice only applies to the original file, which has large sections copy-pasted here. my changes are under CC0 (public domain).
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
The official instructions don't work well. These alternative instructions are intended to be the shortest path to get a minimal setup running.