Skip to content

Commit

Permalink
feat: refactor hw contexts, use kotlin-flow-graph library, extend Sof…
Browse files Browse the repository at this point in the history
…twareGLRenderInterop, remove obsolete VAGLXRenderInterop (replaced by SoftwareGLRenderInterop)
  • Loading branch information
silenium-dev committed Aug 10, 2024
1 parent b74bc4c commit 8e754b6
Show file tree
Hide file tree
Showing 68 changed files with 1,879 additions and 1,088 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
// (in a separate module for demo project and in testMain).
// With compose.desktop.common you will also lose @Preview functionality
implementation(compose.desktop.currentOs)
implementation(libs.flow.graph)
implementation(libs.compose.gl)
implementation(libs.compose.gl.natives)
implementation(libs.jni.utils)
Expand Down
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
kotlin.code.style=official
kotlin.version=2.0.0
compose.version=1.6.11
skiko.egl=true
skiko.egl=false
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[versions]
kotlin = "2.0.0"
kotlin = "2.0.10"

kotlinx-coroutines = "1.8.1"
kotlinx-serialization = "1.7.1"
kotlinx-datetime = "0.6.0"

flow-graph = "e9463af-dev"
compose = "1.6.11"
compose-gl = "0.3.0"
jni-utils = "0.1.5"
Expand All @@ -31,6 +32,7 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-

kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }

flow-graph = { group = "dev.silenium.libs.flow-graph", name = "kotlin-flow-graph", version.ref = "flow-graph" }
compose-gl = { group = "dev.silenium.compose.gl", name = "compose-gl", version.ref = "compose-gl" }
compose-gl-natives = { group = "dev.silenium.compose.gl", name = "compose-gl-natives-linux-x86_64", version.ref = "compose-gl" }
ffmpeg-natives = { group = "dev.silenium.libs", name = "ffmpeg-natives", version = "7.0+0.2.0" }
Expand Down
14 changes: 12 additions & 2 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ if (NOT USE_SYSTEM_FFMPEG)
endif ()

set(SOURCES
src/cpp/data/AVBufferRef.cpp
src/cpp/data/AVCodecID.cpp
src/cpp/data/AVPixelFormat.cpp
src/cpp/data/Frame.cpp
src/cpp/data/Packet.cpp
src/cpp/decode/Decoder.cpp
src/cpp/decode/SoftwareDecoder.cpp
src/cpp/demux/Demuxer.cpp
src/cpp/demux/FileDemuxer.cpp
src/cpp/demux/Stream.cpp
src/cpp/helper/errors.cpp
Expand All @@ -51,7 +52,16 @@ set(SOURCES
src/cpp/render/Swizzles.hpp
src/cpp/render/Swizzles.cpp
src/cpp/util/Errors.cpp
src/cpp/util/AVBuffer.cpp
src/cpp/data/AVCodecParameters.cpp
src/cpp/decode/DecoderContext.h
src/cpp/decode/DecoderContext.cpp
src/cpp/data/FramePadMetadata.cpp
src/cpp/data/FramePadMetadata.hpp
src/cpp/demux/Demuxer.hpp
src/cpp/hw/DeviceContext.cpp
src/cpp/hw/FramesContext.cpp
src/cpp/helper/buffers.hpp
src/cpp/helper/buffers.cpp
)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand Down
2 changes: 1 addition & 1 deletion native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ val generateMakefile = tasks.register<Exec>("generateMakefile") {

val compileNative = tasks.register<Exec>("compileNative") {
workingDir = layout.buildDirectory.dir("cmake").get().asFile
commandLine(cmakeExe, "--build", ".")
commandLine(cmakeExe, "--build", ".", "-j", Runtime.getRuntime().availableProcessors().toString())
dependsOn(generateMakefile)

standardOutput = System.out
Expand Down
57 changes: 57 additions & 0 deletions native/src/cpp/data/AVBufferRef.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by silenium-dev on 8/1/24.
//

#include <jni.h>

extern "C" {
#include <libavutil/buffer.h>

JNIEXPORT void JNICALL Java_dev_silenium_multimedia_core_data_AVBufferRefKt_destroyAVBufferN(
JNIEnv *env,
jobject thiz,
const jlong buffer) {
auto avBuffer = reinterpret_cast<AVBufferRef *>(buffer);
av_buffer_unref(&avBuffer);
}

JNIEXPORT jlong JNICALL Java_dev_silenium_multimedia_core_data_AVBufferRefKt_cloneAVBufferN(
JNIEnv *env,
jobject thiz,
const jlong buffer) {
const auto avBuffer = reinterpret_cast<AVBufferRef *>(buffer);
return reinterpret_cast<jlong>(av_buffer_ref(avBuffer));
}

JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_data_AVBufferRefKt_byteBufferN(
JNIEnv *env,
jobject thiz,
const jlong buffer) {
const auto avBuffer = reinterpret_cast<AVBufferRef *>(buffer);
return env->NewDirectByteBuffer(avBuffer->data, static_cast<jlong>(avBuffer->size));
}

JNIEXPORT jlong JNICALL Java_dev_silenium_multimedia_core_data_AVBufferRefKt_bufferSizeN(
JNIEnv *env,
jobject thiz,
const jlong buffer) {
const auto avBuffer = reinterpret_cast<AVBufferRef *>(buffer);
return static_cast<jlong>(avBuffer->size);
}

JNIEXPORT jlong JNICALL Java_dev_silenium_multimedia_core_data_AVBufferRefKt_bufferDataPtrN(
JNIEnv *env,
jobject thiz,
const jlong buffer) {
const auto avBuffer = reinterpret_cast<AVBufferRef *>(buffer);
return reinterpret_cast<jlong>(avBuffer->data);
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVBufferRefKt_refCountN(
JNIEnv *env,
jobject thiz,
const jlong buffer) {
const auto avBuffer = reinterpret_cast<AVBufferRef *>(buffer);
return av_buffer_get_ref_count(avBuffer);
}
}
90 changes: 90 additions & 0 deletions native/src/cpp/data/AVCodecParameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Created by silenium-dev on 8/4/24.
//

#include "helper/rationals.hpp"
#include <jni.h>

extern "C" {
#include <libavcodec/codec_par.h>

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_codecIdN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->codec_id;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_widthN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->width;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_heightN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->height;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_formatN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->format;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_colorSpaceN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->color_space;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_colorPrimariesN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->color_primaries;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_colorRangeN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->color_range;
}

JNIEXPORT jint JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_colorTrcN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->color_trc;
}

JNIEXPORT jobject JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_frameRateN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return toJava(env, codecParameters->framerate);
}

JNIEXPORT jlong JNICALL Java_dev_silenium_multimedia_core_data_AVCodecParametersKt_bitRateN(
JNIEnv *env,
jobject thiz,
const jlong context) {
const auto codecParameters = reinterpret_cast<AVCodecParameters *>(context);
return codecParameters->bit_rate;
}
}
Loading

0 comments on commit 8e754b6

Please sign in to comment.