class TVideo : public TRect {
public:
TVideo(const char *DeviceName = "/dev/video0"): TRect(), fd(-1) {
Width = 640;
Height = 512;
BPP = 16;
LineLen = Width * BPP / 8;
Size = LineLen * Height;
Addr = 0;
fd = ::open(DeviceName, O_RDONLY);
if (fd < 0) {
printf("fd < 0,TryAnotherCamera\n");
TryAnotherCamera();
}
Addr = new unsigned char<:Size:>;
Clear();
}
bool FetchPicture() const {
int count = ::read(fd, Addr, Size);
printf("count:%d Size:%d\n",count,Size);//count 一直等于0
if (count not_eq Size) {
throw TError("error in fetching picture from video");
}
return true;
}
virtual ~TVideo() {
::close(fd);
fd = -1;
delete<::> Addr;
Addr = 0;
}
protected:
TVideo(const TVideo bitand);
TVideo bitand operator=(const TVideo bitand);
private:
int fd;
void TryAnotherCamera();
};
-------------------------------------------------------------------------------------------------------------------------------------------
bool FetchPicture() const {
int count = ::read(fd, Addr, Size);
printf("count:%d Size:%d\n",count,Size);
if (count not_eq Size) {
throw TError("error in fetching picture from video");
}
return true;
}
count一直等于0,求解,在运行这程序之前还要进行什么初始化吗?