uvc攝像頭代碼解析1

一.FAQ

1.判斷自己的攝像頭是否支持uvc標準

輸入lsusb //列出usb設備

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub  
Bus 001 Device 003: ID 0c45:62f1 Microdia                       //攝像頭  
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub  
Bus 002 Device 002: ID 1a40:0101 TERMINUS TECHNOLOGY INC.   
Bus 002 Device 003: ID 17ef:6025 Lenovo  

更詳細的樹形圖lsusb -t
    /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=musb-hdrc/1p, 480M  
        |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/4p, 480M  
    /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=musb-hdrc/1p, 480M  
        |__ Port 1: Dev 4, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=, 480M  
        |__ Port 1: Dev 4, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=, 480M  
        |__ Port 1: Dev 4, If 2, Class=audio, Driver=snd-usb-audio, 480M  
        |__ Port 1: Dev 4, If 3, Class=audio, Driver=snd-usb-audio, 480M  

lsusb -d 0c45:62f1 -v | grep "14 Video" 檢測設備屬性
bFunctionClasss      14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video  
bInterfaceClass        14 Video

顯示類似上面信息表示該攝像頭是支持uvc標準的

2.使能/關閉調試的trace打印信息

echo 0xffff > /sys/module/uvcvideo/parameters/trace  
echo 0 > /sys/module/uvcvideo/parameters/trace 

3.播放測試
mplayer tv:// -tv fps=25 
mplayer的交叉編譯移植請參考http://blog.csdn.net/orz415678659/article/details/9469271

二.uvc類標準

1.下載標準協議地址

    http://www.usb.org/developers/devclass_docs  

2. Video Class 基礎概念   

    Usb協議中,除了通用的軟硬件電氣接口規範等,還包含了各種各樣的Class協議,用來爲不同的功能定義各自的標準接口和具體的總線上的數據交互格式和內容。這些Class協議的數量非常多,最常見的比如支持U盤功能的Mass Storage Class,以及通用的數據交換協議:CDC class。此外還包括Audio Class, Print Class等等。理論上說,即使沒有這些Class,通過專用驅動也能夠實現各種各樣的應用功能。但是,正如Mass Storage Class的使用,使得各個廠商生產的U盤都能通過操作系統自帶的統一的驅動程序來使用,對U盤的普及使用起了極大的推動作用,制定其它這些Class也是爲了同樣的目的。

    Video Class 協議的目的是給USB接口的視頻設備提供一個統一的數據交換規範。最初1.0版本是在2003年9月添加到USB Class規範中的,1.1的版本更是在2005年發佈。相比之下,Mass Storage Class 早在1998年就發佈了。支持Video Class協議的多媒體芯片也是在2005年才陸續發佈。所以USB 視頻設備在設備端,多數採用通用USB功能的多媒體處理芯片,主機端需要安裝專用的驅動程序,基本上各個產品之間不具備兼容性。甚至對於操作系統而言,也只有在XP的SP2以後,才包含了對通用的Video class協議的支持。所以即使是某些多媒體設備(比如Logitech最新的幾款攝像頭)包含了對Video Class的支持,在Win2000等操作系統上依然需要安裝驅動程序。不過使用Video Class無疑會是一個趨勢,在相應的多媒體芯片陸續投入市場後,支持Video Class的多媒體設備應該會在一兩年內會迅速普及開來。

    除了在硬件上通過相應的多媒體芯片支持Video Class的設備以外,對於包含了操作系統的智能手機,當然也可以在手機端通過驅動程序來實現對Video Class的支持,就好像原先支持任何一種專用的USB驅動一樣。只不過數據交換的格式不是自己隨意制訂的,而是按照Video Class的規範來實現的。本文在介紹USB Video Class架構的基礎上,主要是探討Linux操作系統下設備端Video Class驅動的實現。不過在其它平臺下的實現思路應該也是類似的。

3. USB Video Class 協議結構

3.1 設備拓撲結構
在拓撲結構上VideoClass 將視頻設備抽象爲幾個主要的硬件功能模塊:

    輸入端點 Input Terminal
    輸出端點 OutputTerminal
    camera端點 Camera Terminal
    選擇單元 SelectorUnit
    處理單元Processing Unit
    拓展單元 ExtensionUnit

3.2 功能特徵

Each video function has a single VideoControl (VC) interface and can have several VideoStreaming (VS) interfaces
每個視頻有且僅有1個VideoControl (VC)接口和可有多個 VideoStreaming (VS) 接口

The VideoControl (VC) interface is used to access the device controls of the function whereas the VideoStreaming (VS) interfaces are used to transport data streams into and out of the function.
VC接口用於設備功能控制,VS接口用於傳輸數據流進出

Video Interface Class Code(A.1 P171)

視頻接口類代碼 就是宏定義的USB_CLASS_VIDEO

總共有3種子類subclass

1.VideoControl Interface 視頻控制接口子類

2.VideoStreaming Interface 視頻數據流接口子類

3.Video Interface Collection 視頻接口集合子類

宏定義

/* A.2. Video Interface Subclass Codes */  
#define UVC_SC_UNDEFINED                        0x00  
#define UVC_SC_VIDEOCONTROL                     0x01  
#define UVC_SC_VIDEOSTREAMING                   0x02  
#define UVC_SC_VIDEO_INTERFACE_COLLECTION       0x03 

Units provide the basic building blocks to fully describe most video functions ,A Unit has one or more Input Pins and a single Output Pin,
Unit提供了基礎模塊來全面描述大部分的視頻功能,一個Unit可以由一個或多個輸入引腳和僅一個輸出引腳(這裏的每一個pin代表一個邏輯上的數據流)

Unit可以通過pin引腳連接在一起,一個輸出pin可以連接多個輸入pin,但一個輸入pin只能連接一個輸出pin

An Input Terminal (IT) is an entity that represents a starting point for data streams inside the video function.

一個輸入Terminal (IT)終端是一個實體代表數據流的開始端點

An Output Terminal (OT) represents an ending point for data streams.

一個輸出Terminal (OT)終端是一個實體代表數據流的結束端點

Terminals have one Input or Output Pin that is always numbered one.

Terminal只有1個輸入或一個輸出引腳pin

The Camera Terminal (CT) controls mechanical (or equivalent digital) features of the device component that transmits the video stream.

攝像頭Terminal (CT)控制傳輸視頻流的設備組件特性(Scanning Mode掃描模式 Auto-Exposure Mode自動曝光模式 Auto-Exposure Priority自動曝光優先級

Exposure Time 曝光時間 Focus聚焦 Auto-Focus自動聚焦 Simple Focus簡單聚焦 Iris紅外 Zoom放大 Pan搖動 Roll滾動 Tilt傾斜 Digital Windowing數字窗口

Region of Interest 感應區)

The Selector Unit (SU) selects from n input data streams and routes them unaltered to the single output stream.

選擇Unit (SU)選擇多個輸入數據流並路由它們到單一的輸出流


The Processing Unit (PU) controls image attributes of the video being streamed through it.

處理Unit (PU)控制流經它的視頻流圖像屬性(【Brightness背光 Hue色度 Saturation飽和度 Sharpness銳度 Gamma伽馬值 Digital Multiplier (Zoom)數字放大】

【White Balance Temperature白平衡色溫 White Balance Component白平衡組件 Backlight Compensation背光補償 Contrast對比度】

【Gain增益 Power Line Frequency電源線頻率 Analog Video Standard模擬視頻標準 Analog Video Lock Status模擬視頻鎖存狀態】)

The Encoding Unit controls attributes of the encoder that encodes the video being streamed through it.

編碼Unit (EU)控制流過的視頻流編碼的編碼器的屬性(...)

The Extension Unit (XU) is the method provided by this specification to add vendor-specific building blocks to the specification

擴展Unit (XU)提供廠商特殊控制模塊方法

這樣我們就可以用組件Terminal和Unit組成一個usb攝像頭模型

從sensor(傳感器)和另一個複合視頻設備得到的數據流由IT 和 CT輸入,經SU選擇送PU處理,再由OT綁定到指定的USB端點。最後由USB端點與主機交互將數據發送到host端。在實際設備中,可能沒有其中的某些功能模塊,也可能其中的幾個模塊都是由同一硬件來完成的。上圖中,左半部的框架組成了Video Class中的控制接口界面,右半部的框架組成了視頻流傳輸接口界面。這兩部分構成了Video Class的主要協議框架。

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章