dont need to init twice
This commit is contained in:
parent
d185b0e855
commit
f0b8310822
3 changed files with 75 additions and 54 deletions
|
@ -100,7 +100,6 @@ class cStreamClient {
|
|||
// header.datalen = data.get_size() * sizeof(UINT32);
|
||||
header.datalen = sizeof(tDataMessage);
|
||||
|
||||
|
||||
// send tile header
|
||||
bool sendFull = false;
|
||||
tDataMessage dm;
|
||||
|
@ -151,7 +150,6 @@ class cStreamClient {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
WSADATA data;
|
||||
if(WSAStartup(MAKEWORD(2, 2), &data) != NO_ERROR) {
|
||||
|
@ -167,61 +165,64 @@ int main(int argc, char** argv) {
|
|||
|
||||
// Create a capture interface
|
||||
auto capture = hazelnut::CreateFramebufferCapture(hazelnut::GuessBestCaptureInterface());
|
||||
if (!capture) {
|
||||
if(!capture) {
|
||||
printf("Failed to create a capture interface\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Successfully created a framebuffer capture interface\n");
|
||||
|
||||
if(capture->Initialize()) {
|
||||
// Sleep
|
||||
Sleep(100);
|
||||
bool firstFrame = true;
|
||||
std::vector<tileRect> tiles {};
|
||||
hazelnut::FramebufferInformation framebuffer {};
|
||||
hazelnut::DiffInformation diff {};
|
||||
|
||||
bool firstFrame = true;
|
||||
std::vector<tileRect> tiles {};
|
||||
hazelnut::FramebufferInformation framebuffer{};
|
||||
hazelnut::DiffInformation diff{};
|
||||
while(true) {
|
||||
auto result = capture->CaptureFrame();
|
||||
if(result == hazelnut::DisplayCaptureResult::Ok || result == hazelnut::DisplayCaptureResult::OkButResized) {
|
||||
// Check for resize.
|
||||
if(result == hazelnut::DisplayCaptureResult::OkButResized) {
|
||||
framebuffer = capture->GetFramebufferInformation();
|
||||
diff = capture->GetDiffInformation();
|
||||
firstFrame = true;
|
||||
|
||||
while(true) {
|
||||
auto result = capture->CaptureFrame();
|
||||
if (result == hazelnut::DisplayCaptureResult::Ok || result == hazelnut::DisplayCaptureResult::OkButResized) {
|
||||
// Check for resize.
|
||||
if (result == hazelnut::DisplayCaptureResult::OkButResized) {
|
||||
framebuffer = capture->GetFramebufferInformation();
|
||||
diff = capture->GetDiffInformation();
|
||||
firstFrame = true;
|
||||
|
||||
client.SendResize({ framebuffer.width, framebuffer.height });
|
||||
}
|
||||
client.SendResize({ framebuffer.width, framebuffer.height });
|
||||
|
||||
// send empty frame
|
||||
tiles.clear();
|
||||
client.SendData(framebuffer.pFramebuffer, framebuffer.width, framebuffer.height, tiles);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(firstFrame == false) {
|
||||
for(u32 y = 0; y < diff.diffMapHeight; ++y) {
|
||||
for(u32 x = 0; x < diff.diffmapWidth; ++x) {
|
||||
auto& bl = diff.pDiffMap[y * diff.diffmapWidth + x];
|
||||
if(bl != 0) {
|
||||
tiles.push_back(tileRect {
|
||||
x * (framebuffer.width / diff.diffmapWidth), // x
|
||||
y * (framebuffer.height / diff.diffMapHeight), // y
|
||||
framebuffer.width / diff.diffmapWidth, // width
|
||||
framebuffer.height / diff.diffMapHeight // height
|
||||
});
|
||||
}
|
||||
tiles.clear();
|
||||
|
||||
if(firstFrame == false) {
|
||||
for(u32 y = 0; y < diff.diffMapHeight; ++y) {
|
||||
for(u32 x = 0; x < diff.diffmapWidth; ++x) {
|
||||
auto& bl = diff.pDiffMap[y * diff.diffmapWidth + x];
|
||||
if(bl != 0) {
|
||||
tiles.push_back(tileRect {
|
||||
x * (framebuffer.width / diff.diffmapWidth), // x
|
||||
y * (framebuffer.height / diff.diffMapHeight), // y
|
||||
framebuffer.width / diff.diffmapWidth, // width
|
||||
framebuffer.height / diff.diffMapHeight // height
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// send that to the server
|
||||
client.SendData(framebuffer.pFramebuffer, framebuffer.width, framebuffer.height, tiles);
|
||||
|
||||
if(firstFrame)
|
||||
firstFrame = false;
|
||||
} else {
|
||||
printf("Failed to capture\n");
|
||||
break;
|
||||
if(tiles.empty())
|
||||
continue;
|
||||
}
|
||||
|
||||
// send that to the server
|
||||
client.SendData(framebuffer.pFramebuffer, framebuffer.width, framebuffer.height, tiles);
|
||||
|
||||
if(firstFrame)
|
||||
firstFrame = false;
|
||||
} else {
|
||||
printf("Failed to capture\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,30 +135,48 @@ namespace hazelnut {
|
|||
default: return DisplayCaptureResult::Fail;
|
||||
}
|
||||
|
||||
|
||||
if(width != grabInfo.dwWidth || height != grabInfo.dwHeight) {
|
||||
width = grabInfo.dwWidth;
|
||||
height = grabInfo.dwHeight;
|
||||
|
||||
diffmapWidth = (u32)ceil((f32)width / 32);
|
||||
diffmapHeight = (u32)ceil((f32)height / 32);
|
||||
|
||||
convertedFramebuffer.resize(width * height);
|
||||
|
||||
return DisplayCaptureResult::OkButResized;
|
||||
}
|
||||
|
||||
// Splat to the converted framebuffer. It doesn't have padding on it.
|
||||
auto* pBufferData = convertedFramebuffer.data();
|
||||
auto* pBufferData = (u8*)convertedFramebuffer.data();
|
||||
auto* pSrcData = (u8*)&pRawFramebuffer[0];
|
||||
|
||||
for(u32 y = 0; y < grabInfo.dwHeight; ++y) {
|
||||
memcpy(&pBufferData[y * width], &pRawFramebuffer[(y * grabInfo.dwBufferWidth)], grabInfo.dwWidth * 4);
|
||||
usize srcStart = (y * grabInfo.dwBufferWidth) * 4;
|
||||
usize dstStart = (y * width) * 4;
|
||||
|
||||
// Convert to BGRA
|
||||
for(u32 x = 0; x < grabInfo.dwWidth * 4; x += 4) {
|
||||
pBufferData[(dstStart + x) + 0] = pSrcData[(srcStart + x) + 2]; // B
|
||||
pBufferData[(dstStart + x) + 1] = pSrcData[(srcStart + x) + 1]; // G
|
||||
pBufferData[(dstStart + x) + 2] = pSrcData[(srcStart + x) + 0]; // R
|
||||
pBufferData[(dstStart + x) + 3] = 0xff; // A
|
||||
}
|
||||
|
||||
// memcpy(&pBufferData[y * width], &pRawFramebuffer[(y * grabInfo.dwBufferWidth)], grabInfo.dwWidth * 4);
|
||||
}
|
||||
|
||||
// sleep
|
||||
// nvfbc->NvFBCToSysGPUBasedCPUSleep(16000);
|
||||
|
||||
return DisplayCaptureResult::Ok;
|
||||
}
|
||||
|
||||
FramebufferInformation GetFramebufferInformation() override { return FramebufferInformation { convertedFramebuffer.data(), width, height }; }
|
||||
|
||||
DiffInformation GetDiffInformation() override { return DiffInformation { pDiffMap, diffmapWidth, diffmapHeight }; }
|
||||
DiffInformation GetDiffInformation() override {
|
||||
diffmapWidth = (u32)ceil((f32)width / 32);
|
||||
diffmapHeight = (u32)ceil((f32)height / 32);
|
||||
return DiffInformation { pDiffMap, diffmapWidth, diffmapHeight };
|
||||
}
|
||||
};
|
||||
|
||||
IFramebufferCapture* CreateFramebufferCapture_NVFBC() {
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -39,6 +39,14 @@ fn read_message(stream: &mut TcpStream, argb_buffer: &mut Vec<u32>, width: u32)
|
|||
|
||||
//println!("{tile_count} tiles");
|
||||
|
||||
// tile data, painted directly onto the argb buffer. It's stupid
|
||||
let argb_slice = unsafe {
|
||||
std::slice::from_raw_parts_mut(
|
||||
argb_buffer.as_mut_ptr() as *mut u8,
|
||||
argb_buffer.len() * core::mem::size_of::<u32>(),
|
||||
)
|
||||
};
|
||||
|
||||
for i in 0..tile_count {
|
||||
// tile rect
|
||||
let tile_x = stream.read_u32::<LittleEndian>().expect("fuck");
|
||||
|
@ -48,13 +56,7 @@ fn read_message(stream: &mut TcpStream, argb_buffer: &mut Vec<u32>, width: u32)
|
|||
|
||||
//println!("tile{i}: {tile_x} {tile_y} {tile_width}x{tile_height}");
|
||||
|
||||
// tile data, painted directly onto the argb buffer. It's stupid
|
||||
let argb_slice = unsafe {
|
||||
std::slice::from_raw_parts_mut(
|
||||
argb_buffer.as_mut_ptr() as *mut u8,
|
||||
argb_buffer.len() * core::mem::size_of::<u32>(),
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
for y in tile_y..tile_y + tile_height {
|
||||
//println!("{y} {tile_y} {tile_height}");
|
||||
|
|
Loading…
Reference in a new issue