mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
feat: loudnorm (#1358)
* feat: loudnorm * fix * fix: android only * fix: toString
This commit is contained in:
committed by
GitHub
parent
046412b709
commit
22c57bf468
@@ -9,6 +9,7 @@ import 'package:get/get_rx/get_rx.dart';
|
||||
import 'package:media_kit/ffi/src/allocation.dart';
|
||||
import 'package:media_kit/ffi/src/utf8.dart';
|
||||
import 'package:media_kit/generated/libmpv/bindings.dart' as generated;
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:media_kit/src/player/native/core/initializer.dart';
|
||||
import 'package:media_kit/src/player/native/core/native_library.dart';
|
||||
|
||||
@@ -54,7 +55,15 @@ class MpvConvertWebp {
|
||||
'${Pref.hardwareDecoding},auto-copy', // transcode only support copy
|
||||
},
|
||||
);
|
||||
_setHeader();
|
||||
NativePlayer.setHeader(
|
||||
const {
|
||||
'user-agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
|
||||
'referer': HttpString.baseUrl,
|
||||
},
|
||||
_mpv,
|
||||
_ctx,
|
||||
);
|
||||
if (progress != null) {
|
||||
_observeProperty('time-pos');
|
||||
}
|
||||
@@ -79,7 +88,7 @@ class MpvConvertWebp {
|
||||
switch (event.ref.event_id) {
|
||||
case generated.mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
|
||||
final prop = event.ref.data.cast<generated.mpv_event_property>().ref;
|
||||
if (prop.name.cast<Utf8>().toDartString() == 'time-pos' &&
|
||||
if (prop.name.toDartString() == 'time-pos' &&
|
||||
prop.format == generated.mpv_format.MPV_FORMAT_DOUBLE) {
|
||||
progress!.value = (prop.data.cast<Double>().value - start) / duration;
|
||||
}
|
||||
@@ -89,9 +98,9 @@ class MpvConvertWebp {
|
||||
break;
|
||||
case generated.mpv_event_id.MPV_EVENT_LOG_MESSAGE:
|
||||
final log = event.ref.data.cast<generated.mpv_event_log_message>().ref;
|
||||
final prefix = log.prefix.cast<Utf8>().toDartString().trim();
|
||||
final level = log.level.cast<Utf8>().toDartString().trim();
|
||||
final text = log.text.cast<Utf8>().toDartString().trim();
|
||||
final prefix = log.prefix.toDartString().trim();
|
||||
final level = log.level.toDartString().trim();
|
||||
final text = log.text.toDartString().trim();
|
||||
debugPrint('WebpConvert: $level $prefix : $text');
|
||||
if (kDebugMode) {
|
||||
_success = level != 'error' && level != 'fatal';
|
||||
@@ -108,18 +117,8 @@ class MpvConvertWebp {
|
||||
}
|
||||
}
|
||||
|
||||
void _command(List<String> args) {
|
||||
final pointers = args.map((e) => e.toNativeUtf8()).toList();
|
||||
final arr = calloc<Pointer<Utf8>>(128);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
arr[i] = pointers[i];
|
||||
}
|
||||
|
||||
_mpv.mpv_command(_ctx, arr.cast());
|
||||
|
||||
calloc.free(arr);
|
||||
pointers.forEach(calloc.free);
|
||||
}
|
||||
void _command(List<String> args) =>
|
||||
NativePlayer.statiCommand(args, _mpv, _ctx);
|
||||
|
||||
void _observeProperty(String property) {
|
||||
final name = property.toNativeUtf8();
|
||||
@@ -132,47 +131,6 @@ class MpvConvertWebp {
|
||||
|
||||
calloc.free(name);
|
||||
}
|
||||
|
||||
void _setHeader() {
|
||||
final property = 'http-header-fields'.toNativeUtf8();
|
||||
// Allocate & fill the [mpv_node] with the headers.
|
||||
final value = calloc<generated.mpv_node>();
|
||||
final valRef = value.ref
|
||||
..format = generated.mpv_format.MPV_FORMAT_NODE_ARRAY;
|
||||
valRef.u.list = calloc<generated.mpv_node_list>();
|
||||
final valList = valRef.u.list.ref
|
||||
..num = 2
|
||||
..values = calloc<generated.mpv_node>(2);
|
||||
|
||||
const entries = [
|
||||
(
|
||||
'user-agent',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
|
||||
),
|
||||
('referer', HttpString.baseUrl),
|
||||
];
|
||||
for (int i = 0; i < 2; i++) {
|
||||
final (k, v) = entries[i];
|
||||
valList.values[i]
|
||||
..format = generated.mpv_format.MPV_FORMAT_STRING
|
||||
..u.string = '$k: $v'.toNativeUtf8().cast();
|
||||
}
|
||||
_mpv.mpv_set_property(
|
||||
_ctx,
|
||||
property.cast(),
|
||||
generated.mpv_format.MPV_FORMAT_NODE,
|
||||
value.cast(),
|
||||
);
|
||||
// Free the allocated memory.
|
||||
calloc.free(property);
|
||||
for (int i = 0; i < valList.num; i++) {
|
||||
calloc.free(valList.values[i].u.string);
|
||||
}
|
||||
calloc
|
||||
..free(valList.values)
|
||||
..free(valRef.u.list)
|
||||
..free(value);
|
||||
}
|
||||
}
|
||||
|
||||
enum WebpPreset {
|
||||
|
||||
Reference in New Issue
Block a user