First successful screenshot achieved.

This commit is contained in:
Sergiotarxz 2023-03-13 01:37:13 +01:00
parent 1198bbabbf
commit ef44794376
3 changed files with 43 additions and 14 deletions

View File

@ -32,23 +32,29 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
unsigned int stride = data->coreController->stride;
color_t *outputBuffer = data->coreController->outputBuffer;
unsigned width, height;
unsigned char *raw_data;
unsigned char *raw_data = NULL;
size_t raw_data_len = 0;
struct msPacketSendFrame *send_frame;
struct msPacket *packet;
struct msPacketSendFrame *send_frame = NULL;
struct msPacket *packet = NULL;
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
send_frame = msPacketSendFrameNew(stride, width * height, outputBuffer);
raw_data = msPacketSendFrameSerialize(send_frame, &raw_data_len);
if (!raw_data) {
goto return_ms_thread_callback_set_frame;
}
packet = msPacketNew(PACKET_SEND_FRAME, raw_data_len, raw_data);
msPacketSend(packet, data);
msPacketSendFrameDestroy(&send_frame);
msPacketDestroy(&packet);
return_ms_thread_callback_set_frame:
if (send_frame) {
msPacketSendFrameDestroy(&send_frame);
}
if (packet) {
msPacketDestroy(&packet);
}
}
bool

View File

@ -27,14 +27,14 @@ unsigned char *
msPacketSendFrameSerialize(struct msPacketSendFrame *const self, size_t *len) {
unsigned char *bytes;
unsigned int stride = self->stride;
size_t outputBufferSizeBytes = self->outputBufferSize * sizeof *self->outputBuffer;
size_t outputBufferSizeBytes = self->outputBufferSize * sizeof (uint32_t);
stride = htobe32(stride);
*len = (sizeof self->stride) + (sizeof self->outputBufferSize) + (outputBufferSizeBytes);
outputBufferSizeBytes = htobe64(outputBufferSizeBytes);
bytes = malloc(*len);
#define GOTO_END_SERIALIZE_FAIL() \
free(bytes); \
bytes = NULL;
bytes = NULL; \
goto return_ms_packet_send_frame_serialize;
FILE *fp = fmemopen(bytes, sizeof *bytes * *len, "w");
if (fwrite(&self->stride, sizeof self->stride, 1, fp) == -1) {
@ -43,10 +43,13 @@ msPacketSendFrameSerialize(struct msPacketSendFrame *const self, size_t *len) {
if (fwrite(&outputBufferSizeBytes, sizeof outputBufferSizeBytes, 1, fp) == -1) {
GOTO_END_SERIALIZE_FAIL();
}
if (fwrite(self->outputBuffer, sizeof *self->outputBuffer, self->outputBufferSize, fp) == -1) {
GOTO_END_SERIALIZE_FAIL();
for (size_t i = 0; i < self->outputBufferSize; i++) {
color_t pixel = self->outputBuffer[i];
if (fwrite(&pixel, sizeof pixel, 1, fp) == -1) {
GOTO_END_SERIALIZE_FAIL();
}
}
fclose(fp);
return_ms_packet_send_frame_serialize:
fclose(fp);
return bytes;
}

View File

@ -40,11 +40,31 @@ sub retrieve_packet {
(read $fh, my $size, 8) or return 0;
$size = unpack('Q>', $size);
(read $fh, my $raw_data, $size) or return 0;
say $id;
say $size;
state $i = 0;
if ($i == 500) {
read_send_frame($raw_data);
}
$i++;
return 1;
}
sub read_send_frame {
my $raw_data = shift;
open my $fh, '<', \$raw_data;
(read $fh, my $stride, 4) or return 0;
$stride = unpack('N', $stride);
(read $fh, my $size, 8) or return 0;
$size = unpack('Q>', $size);
(read $fh, my $rgbx, $size) or return 0;
my @rgbx = split '', $rgbx;
for (my $i = 3; $i < length $rgbx; $i+=4) {
$rgbx[$i] = chr 255;
}
$rgbx = join '', @rgbx;
path('screenshot.rgbx')->spew($rgbx);
close $fh;
}
sub write_packet {
my $fh = shift;
my $id = shift;