First successful screenshot achieved.
This commit is contained in:
parent
1198bbabbf
commit
ef44794376
@ -32,24 +32,30 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
|
|||||||
unsigned int stride = data->coreController->stride;
|
unsigned int stride = data->coreController->stride;
|
||||||
color_t *outputBuffer = data->coreController->outputBuffer;
|
color_t *outputBuffer = data->coreController->outputBuffer;
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
unsigned char *raw_data;
|
unsigned char *raw_data = NULL;
|
||||||
size_t raw_data_len = 0;
|
size_t raw_data_len = 0;
|
||||||
struct msPacketSendFrame *send_frame;
|
struct msPacketSendFrame *send_frame = NULL;
|
||||||
struct msPacket *packet;
|
struct msPacket *packet = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
|
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
|
||||||
|
|
||||||
send_frame = msPacketSendFrameNew(stride, width * height, outputBuffer);
|
send_frame = msPacketSendFrameNew(stride, width * height, outputBuffer);
|
||||||
raw_data = msPacketSendFrameSerialize(send_frame, &raw_data_len);
|
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);
|
packet = msPacketNew(PACKET_SEND_FRAME, raw_data_len, raw_data);
|
||||||
msPacketSend(packet, data);
|
msPacketSend(packet, data);
|
||||||
|
|
||||||
|
return_ms_thread_callback_set_frame:
|
||||||
|
if (send_frame) {
|
||||||
msPacketSendFrameDestroy(&send_frame);
|
msPacketSendFrameDestroy(&send_frame);
|
||||||
|
}
|
||||||
|
if (packet) {
|
||||||
msPacketDestroy(&packet);
|
msPacketDestroy(&packet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
msPacketHelloHandle(const struct msPacket *packet, struct msPacketHello *hello,
|
msPacketHelloHandle(const struct msPacket *packet, struct msPacketHello *hello,
|
||||||
|
@ -27,14 +27,14 @@ unsigned char *
|
|||||||
msPacketSendFrameSerialize(struct msPacketSendFrame *const self, size_t *len) {
|
msPacketSendFrameSerialize(struct msPacketSendFrame *const self, size_t *len) {
|
||||||
unsigned char *bytes;
|
unsigned char *bytes;
|
||||||
unsigned int stride = self->stride;
|
unsigned int stride = self->stride;
|
||||||
size_t outputBufferSizeBytes = self->outputBufferSize * sizeof *self->outputBuffer;
|
size_t outputBufferSizeBytes = self->outputBufferSize * sizeof (uint32_t);
|
||||||
stride = htobe32(stride);
|
stride = htobe32(stride);
|
||||||
*len = (sizeof self->stride) + (sizeof self->outputBufferSize) + (outputBufferSizeBytes);
|
*len = (sizeof self->stride) + (sizeof self->outputBufferSize) + (outputBufferSizeBytes);
|
||||||
outputBufferSizeBytes = htobe64(outputBufferSizeBytes);
|
outputBufferSizeBytes = htobe64(outputBufferSizeBytes);
|
||||||
bytes = malloc(*len);
|
bytes = malloc(*len);
|
||||||
#define GOTO_END_SERIALIZE_FAIL() \
|
#define GOTO_END_SERIALIZE_FAIL() \
|
||||||
free(bytes); \
|
free(bytes); \
|
||||||
bytes = NULL;
|
bytes = NULL; \
|
||||||
goto return_ms_packet_send_frame_serialize;
|
goto return_ms_packet_send_frame_serialize;
|
||||||
FILE *fp = fmemopen(bytes, sizeof *bytes * *len, "w");
|
FILE *fp = fmemopen(bytes, sizeof *bytes * *len, "w");
|
||||||
if (fwrite(&self->stride, sizeof self->stride, 1, fp) == -1) {
|
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) {
|
if (fwrite(&outputBufferSizeBytes, sizeof outputBufferSizeBytes, 1, fp) == -1) {
|
||||||
GOTO_END_SERIALIZE_FAIL();
|
GOTO_END_SERIALIZE_FAIL();
|
||||||
}
|
}
|
||||||
if (fwrite(self->outputBuffer, sizeof *self->outputBuffer, self->outputBufferSize, fp) == -1) {
|
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();
|
GOTO_END_SERIALIZE_FAIL();
|
||||||
}
|
}
|
||||||
fclose(fp);
|
}
|
||||||
return_ms_packet_send_frame_serialize:
|
return_ms_packet_send_frame_serialize:
|
||||||
|
fclose(fp);
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
24
tester.pl
24
tester.pl
@ -40,11 +40,31 @@ sub retrieve_packet {
|
|||||||
(read $fh, my $size, 8) or return 0;
|
(read $fh, my $size, 8) or return 0;
|
||||||
$size = unpack('Q>', $size);
|
$size = unpack('Q>', $size);
|
||||||
(read $fh, my $raw_data, $size) or return 0;
|
(read $fh, my $raw_data, $size) or return 0;
|
||||||
say $id;
|
state $i = 0;
|
||||||
say $size;
|
if ($i == 500) {
|
||||||
|
read_send_frame($raw_data);
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
return 1;
|
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 {
|
sub write_packet {
|
||||||
my $fh = shift;
|
my $fh = shift;
|
||||||
my $id = shift;
|
my $id = shift;
|
||||||
|
Loading…
Reference in New Issue
Block a user