real ai code
This commit is contained in:
parent
beed5abe93
commit
1c5d29302e
49
main.cpp
49
main.cpp
@ -1,7 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <vector>
|
||||||
#include <libcamera/libcamera.h>
|
#include <libcamera/libcamera.h>
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
@ -13,7 +15,24 @@ static std::shared_ptr<Camera> camera;
|
|||||||
|
|
||||||
static void requestComplete(Request *request)
|
static void requestComplete(Request *request)
|
||||||
{
|
{
|
||||||
|
if (request->status() == Request::RequestCancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto const &bufferPair : request->buffers()) {
|
||||||
|
FrameBuffer *buffer = bufferPair.second;
|
||||||
|
const FrameMetadata &metadata = buffer->metadata();
|
||||||
|
if (metadata.status != FrameMetadata::FrameSuccess)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int fd = buffer->planes()[0].fd.get(); // Import this dma-buf fd into EGL/OpenGL.
|
||||||
|
std::cout << "frame " << std::setw(6) << std::setfill('0') << metadata.sequence
|
||||||
|
<< " fd " << fd << " bytes " << metadata.planes()[0].bytesused
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
request->reuse(Request::ReuseBuffers);
|
||||||
|
if (capturing)
|
||||||
|
camera->queueRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -40,17 +59,39 @@ int main()
|
|||||||
config->validate();
|
config->validate();
|
||||||
camera->configure(config.get());
|
camera->configure(config.get());
|
||||||
|
|
||||||
|
FrameBufferAllocator *allocator = new FrameBufferAllocator(camera);
|
||||||
|
Stream *stream = streamConfig.stream();
|
||||||
|
if (allocator->allocate(stream) < 0) {
|
||||||
|
std::cerr << "Can't allocate buffers" << std::endl;
|
||||||
|
delete allocator;
|
||||||
|
camera->release();
|
||||||
|
cm->stop();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator->buffers(stream);
|
||||||
|
std::vector<std::unique_ptr<Request>> requests;
|
||||||
|
for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
|
||||||
|
std::unique_ptr<Request> request = camera->createRequest();
|
||||||
|
if (!request || request->addBuffer(stream, buffer.get()) < 0) {
|
||||||
|
std::cerr << "Can't create request" << std::endl;
|
||||||
|
allocator->free(stream);
|
||||||
|
delete allocator;
|
||||||
|
camera->release();
|
||||||
|
cm->stop();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
requests.push_back(std::move(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
camera->requestCompleted.connect(requestComplete);
|
||||||
|
|
||||||
|
|
||||||
camera->requestCompleted.connect(requestCompleted);
|
|
||||||
camera->start();
|
camera->start();
|
||||||
for (auto &req : requests) {
|
for (auto &req : requests) {
|
||||||
camera->queueRequest(req.get());
|
camera->queueRequest(req.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(10000ms);
|
||||||
|
|
||||||
// end the cameras
|
// end the cameras
|
||||||
capturing = false;
|
capturing = false;
|
||||||
camera->stop();
|
camera->stop();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user