#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define req_buf_num 4//申請的緩衝區個數,最多5個,緩衝區太少可能會導致影象有間斷
unsigned char bmp_head_t = ;
typedef struct buffer_type_r buffer_type;
struct buffer_type_r//申請到的緩衝區資訊
;buffer_type *user_buffer;
int buffer_count = 0;//實際申請到的緩衝區個數
int open_video()
return fb;
}void init_mmap(int fb)
buffer_count = tv4l2_reqbuf.count;
printf("succefful get %d buffer\n",tv4l2_reqbuf.count);
user_buffer = calloc(tv4l2_reqbuf.count,sizeof(*user_buffer));
if(user_buffer == null)
for(i = 0;i < tv4l2_reqbuf.count;i++)
// 把核心空間緩衝區對映到使用者空間緩衝區
user_buffer[i].length = tv4l2buf.length;
user_buffer[i].start = (char *)mmap( null, /* start anywhere */
tv4l2buf.length,
prot_read | prot_write, /* access privilege */
map_shared, /* recommended */
fb,tv4l2buf.m.offset);
if(map_failed == user_buffer[i].start) }
}void init_video(int fb)
printf("driver name %s card = %s cap = %0x\n",cap.driver,cap.card,cap.capabilities);
fmt.index = 0;
while((ioctl(fb,vidioc_enum_fmt, &fmt)) == 0)\n",
fmt.pixelformat & 0xff, (fmt.pixelformat >> 8) & 0xff, (fmt.pixelformat >> 16) & 0xff,
(fmt.pixelformat >> 24) & 0xff, fmt.description);
} v4_format.type = v4l2_buf_type_video_capture;
v4_format.fmt.pix.width = 480;
v4_format.fmt.pix.height = 272;
v4_format.fmt.pix.pixelformat = v4l2_pix_fmt_rgb565;
v4_format.fmt.pix.field = v4l2_field_interlaced;
if((ioctl(fb, vidioc_s_fmt, &v4_format)) != 0)
printf("set fmt ok!\n");
init_mmap(fb);
}void start_capturing(int fb)
perror("vidioc_streamon");
} } }
void process_image(char *addr,int length)
fwrite(bmp_head_t,1,66,bmpfile);
if(addr != null)//經測試,申請緩衝區個數為2時,編譯會出現段錯誤,追蹤發現addr為null
fwrite((void *)addr,1,length,bmpfile);
fclose(bmpfile);
}int read_buffer(int fb)
process_image(user_buffer[buf.index].start,user_buffer[buf.index].length);
return 0;
}void main_loop(int fb)
if(0 == r)
if(read_buffer(fb) == 0)
break;
} }}void stop_capturing(int fb) }
void uninit_camer_device(int fb) }
free(user_buffer);
}void close_camer_device(int fb)
}int main()
V4L2程式設計
include include include include include include include include include include typedef struct buftype buftype user buf int n buffer 0 開啟攝像頭裝置 int ope...
V4L2 程式設計
v4l2程式設計 1.定義 2.工作流程 開啟裝置 檢查和設定裝置屬性 設定幀格式 設定一種輸入輸出方法 緩衝區管理 迴圈獲取資料 關閉裝置。3.裝置的開啟和關閉 include int open const char device name,int flags include int close ...
V4L2程式設計 轉
前言 目前正在忙於arm 平台的linux 應用程式的開發 其實是剛剛起步學習啦 底層的東西不用考慮了,開發板子提供了 nand bootloader 和linux 2.6 的原始碼,而且都編譯好了。自己編譯的 bootloader 可以用,但是 linux 編譯後,檔案很大,暫且就用人家編譯的系統...