簡介
UVC : USB video device class撵渡,是一種USB設(shè)備類,這種設(shè)備用于通過USB總線傳輸視頻流,例如網(wǎng)絡(luò)攝像頭(webcam)等,這些年隨著監(jiān)控和網(wǎng)絡(luò)直播的興起拒贱,webcam類的設(shè)備大量出現(xiàn),而這些設(shè)備與上位機的數(shù)據(jù)傳輸佛嬉,必然繞不開uvc協(xié)議逻澳。
相關(guān)資料鏈接
維基百科中的描述:
https://en.wikipedia.org/wiki/USB_video_device_class
uvc協(xié)議下載:
https://www.usb.org/documents
https://www.usb.org/document-library/video-class-v15-document-set
https://www.usb.org/document-library/video-class-v11-document-set
https://www.usb.org/document-library/audiovideo-device-class-v10-spec-and-adopters-agreement
目前uvc協(xié)議主要分為1.0,1.1和1.5這三種暖呕,前兩者使用相對較為廣泛斜做。上面的連接分別是這三種協(xié)議的文檔,讀者可自行下載參考湾揽。
<=======================>
下面詳細摘一些UVC相關(guān)的知識點
<=======================>
UVC Descriptor Hierarchy(來自UVC1.1規(guī)范)
幾個名詞的解釋:
術(shù)語 | 解釋 |
---|---|
Configuration | A collection of one or more interfaces that may be selected on a USB device. |
Descriptor | Data structure used to describe a USB device capability or characteristic. |
Device | USB peripheral. |
Endpoint | Source or sink of data on a USB device. |
Interface | An Entity representing a collection of zero or more endpoints that present functionality to a Host. |
IAD | Interface Association Descriptor. This is used to describe that two or more interfaces are associated to the same function. An ‘a(chǎn)ssociation’ includes two or more interfaces and all of their alternate setting interfaces. |
文摘與解讀:
根據(jù)上文描述瓤逼,USB設(shè)備的視頻相關(guān)的功能是由設(shè)備層級架構(gòu)中的interface層來具體實現(xiàn)的。每個video function(此處應(yīng)該理解為configuration)均是由一個VC interface和若干個VS interface共同組成的库物,事實上霸旗,我接觸的攝像頭設(shè)備中,大多只有一個VS interface戚揭。
當(dāng)然了诱告,除了視頻功能,該設(shè)備也可以同時擁有其它功能民晒,比如MTP精居,這樣的話,設(shè)備層往下會有第二個configuration潜必,這個configuration又會有其它的interfaces靴姿。
UVC協(xié)議的具體實現(xiàn)就放在這些interfaces中,為了實現(xiàn)UVC的相關(guān)功能刮便,協(xié)議特別引入了units和terminals兩個概念:
units可以理解為UVC相關(guān)子功能的具體實現(xiàn)單元空猜,這種模塊單元由多個輸入和一個輸出構(gòu)成。terminal可以理解為數(shù)據(jù)流的端節(jié)點恨旱,分為input terminal (IT)和 output terminal(OT)辈毯,分別代碼視頻數(shù)據(jù)流的輸入起始點和輸出終點。當(dāng)然了搜贤,IT和OT之間少不了還有一些units谆沃,用于對數(shù)據(jù)進行相應(yīng)處理。注意仪芒,unit和terminal都有對應(yīng)的descriptor唁影。
UVC規(guī)范中定義了一些基礎(chǔ)的unit和terminal:
? Input Terminal
? Output Terminal
? Selector Unit
? Processing Unit
? Extension Unit
這些unit和terminal可以實現(xiàn)絕大部分的功能耕陷。除此之外,還有一些特殊的terminal据沈,比如Media Transport Terminal和Camera Terminal哟沫,用于實現(xiàn)一些特殊的功能。當(dāng)然了锌介,對于初級玩家來說嗜诀,上面5個unit和terminal已經(jīng)足夠使用了。
每一個unit或者terminal中又包含了若干個setting孔祸,用于實現(xiàn)不同的video controls隆敢,比如,在processing unit中崔慧,相機的亮度(brightness)信息包含在current setting中拂蝎,如果主機側(cè)想讀取現(xiàn)在的亮度值,可以向這個setting發(fā)起request來獲得惶室。主要的setting分為:
? Current setting
? Minimum setting
? Maximum setting
? Resolution
? Size
? Default
對主機側(cè)來說温自,通過 unit descriptor,terminal descriptor和video control皇钞,就可以完整獲取到該UVC設(shè)備的控制信息捣作。
下面是interface層幾個主要組件的介紹:
下面一段話關(guān)于操作模式的,比較有意思:
這段話也再次確認了鹅士,一個設(shè)備可以有多個configuration,每個configuration可以有多個interface惩坑。同一個設(shè)備中可以同時存在多個獨立的視頻功能(我個人理解為這指的就是configuration)掉盅,每個視頻功能是由多個interface去支撐的,因此隸屬于同一個功能的interface就形成了一個組以舒,這個組就叫video interface collection趾痘,其描述符就叫IAD。如果一個設(shè)備有多個獨立的視頻功能蔓钟,則它必然擁有多個video interface collection永票。
如前所述,一個video interface collection含有一個(且是唯一一個)video control interface和若干個video streaming interface滥沫。 這個VC interface是由兩個endpoint組成的:
? A control endpoint for manipulating Unit and Terminal settings and retrieving the state of the video function. This endpoint is mandatory, and the default endpoint 0 is used for this purpose.
? An interrupt endpoint for status returns. This endpoint is optional, but may be mandatory under certain conditions. See section 2.4.2.2, "Status Interrupt Endpoint" for further information.
下面是對這兩種endpoint的詳細描述:
下面是video streaming interface相關(guān)的內(nèi)容:
A video (or still image) sample refers to an encoded block of video
data that the format-specific decoder is able to accept and interpret in
a single transmission.
Sample Bulk Transfers
主機如何去控制設(shè)備侣集?
2.4.4 Control Transfer and Request Processing
Control transfers minimally have two transaction stages: Setup and Status. A control transfer
may optionally contain a Data stage between the Setup and Status stages. The Setup stage
contains all information necessary to address a particular entity, specify the desired
operation, and prepare for an optional Data stage. A Data stage can be host-to-device (OUT
transactions), or device-to-host (IN transactions), depending on the direction and operation
specified in the Setup stage via the bmRequestType and bRequest fields.
In the context of the Video Class specification, SET_CUR requests will always involve a
Data stage from host to device, and GET_* requests will always involve a Data stage from
device to host. Although none are defined currently, an exception to this rule would be a
SET_CUR request where the bRequest field contains all information necessary to place the
device into a known state. However, “toggle” requests without a Data stage are explicitly
disallowed.