rk3399_arm_lvds/usb/usbimageprocqueue.h

100 lines
2.2 KiB
C
Raw Normal View History

2024-03-05 03:46:18 +00:00
#pragma once
#include <queue>
#include "imgproc.h"
#include "mutex"
#include "itransmit.h"
#include "inotify.h"
#include "ireceive.h"
#include "BlockingQueue.h"
class UsbImageProcQueue
{
public:
UsbImageProcQueue(NotifyPtr notify)
{
this->notify = notify;
}
void push(MemoryPtr image,bool containsimg,uint32_t scan_index = 0 ,uint32_t error_code = 0)
{
std::lock_guard<std::mutex> lck(mx);
HGIntInfo info{.From=IMG,.Code =0,.Img_Index = 0,.Img_Status = img_status::IMG_STATUS_OK};
if(containsimg)
{
images.push(image);
//images.Put(image);
info.From = IMG;
info.Code = image->size();
info.Img_Index = scan_index;
if(error_code == 0x20)
info.Img_Status = img_status::IMG_STATUS_DOUBLE;
}
else
{
info = *((HGIntInfo*)image->data());
}
if(notify)
notify->notify(&info, sizeof(info));
}
MemoryPtr front()
{
std::lock_guard<std::mutex> lck(mx);
auto front = images.front();
return front;
//return images.Front();
}
MemoryPtr pop()
{
std::lock_guard<std::mutex> lck(mx);
if(images.size()>0)
{
auto front = images.front();
images.pop();
//auto front=images.Take();
return front;
}
return MemoryPtr();
}
bool empty()
{
std::lock_guard<std::mutex> lck(mx);
return images.empty();
//return images.Size()>0;
}
int size()
{
std::lock_guard<std::mutex> lck(mx);
return images.size();
//return images.Size();
}
int front_datasize()
{
std::lock_guard<std::mutex> lck(mx);
if(images.size()<1)
return 0;
auto img=images.front();
return images.empty() ? 0 : images.front()->size();
//return (images.Size()>0) ? 0 : images.Front()->size();
}
void clear()
{
std::lock_guard<std::mutex> lck(mx);
while(images.size()>0)
images.pop();
}
private:
std::queue<MemoryPtr> images;
//BlockingQueue<MemoryPtr> images;
NotifyPtr notify;
std::mutex mx;
};