Skip to content

Instantly share code, notes, and snippets.

@scovit
Last active April 24, 2020 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scovit/5b87d9a17edc64c0c2d5922702528097 to your computer and use it in GitHub Desktop.
Save scovit/5b87d9a17edc64c0c2d5922702528097 to your computer and use it in GitHub Desktop.
my $lib = q:to/END/;
#include <stdio.h>
typedef struct {
int x;
int y;
int w;
int h;
} GstVideoRectangle;
void gst_video_sink_center_rect(GstVideoRectangle src,
GstVideoRectangle dst,
GstVideoRectangle * result,
int scaling) {
printf("src: x: %d y: %d w: %d h: %d\n", src.x, src.y, src.w, src.h);
printf("dst: x: %d y: %d w: %d h: %d\n", dst.x, dst.y, dst.w, dst.h);
printf("result: %lld\n", (long long)result);
printf("scaling: %d\n", scaling);
}
END
my $fh = open :w, './a.c';
$fh.say: $lib;
$fh.close;
run 'gcc', '-shared', '-o', 'liba.so', '-fPIC', './a.c';
use NativeCall;
class GstVideoRectangle is repr("CStruct") {
has int32 $.x;
has int32 $.y;
has int32 $.w;
has int32 $.h;
}
sub gst_video_sink_center_rect(
int64, int64,
int64, int64,
Pointer,
int32 ) is native('./liba.so') { * }
sub malloc(int32 --> Pointer) is native { * }
sub gst_video_sink_center_rect_wrapper($src,
$dst,
$result,
$scaling) {
gst_video_sink_center_rect($src.x + $src.y +< 32, $src.w + $src.h +< 32,
$dst.x + $dst.y +< 32, $dst.w + $dst.h +< 32,
$result,
$scaling);
}
my $src = GstVideoRectangle.new(:50x, :51y, :53w, :54h);
dd $src;
my $dst = GstVideoRectangle.new(:70x, :71y, :73w, :74h);
dd $dst;
my $result = malloc(16);
dd $result;
my $scaling = 1;
dd $scaling;
gst_video_sink_center_rect_wrapper($src,
$dst,
$result,
$scaling)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment