JavaTM Media Framework API Guide NO.2
High-Level Architecture
Media Data Storage and Transmission
Storage Controls
Implementing Plug-Ins
Implementing MediaHandlers and DataSources
Time Model
關於TIME,可實作二個相關的interface:
Clock Interface:定義了basic timing和同步時所需的資料,clock是使用TimeBase作為track行進的時間(而time-base提供的資訊只有目前的時間,以system clock為主)
Duration Interface:影片的開始到結束的時間(片長時間)
為了維持track目前時間,Clock使用:
以time來記錄
以position來記錄
以play back rate:rate=張數 / 秒數 * 時間
公式:MediaTime=MediaStartTime+Rate(TimeBaseTime-TimeBaseStartTime)
位置 絕對時間
JMF time model
Managers
對於媒體的擷取、處理和播放時間性的媒體,JMF都有提供相關的API。
JMF所使用的 4 個managers:
1. Manager--包含Players, Processors, DataSources和DataSink四種classes,object都是用此四種去建構成的。
2. PackageManager--可自定classes,如:自定的Players、 Processors、 DataSources、DataSinks
3. CaptureDeviceManager--當我們要從input device去capturing媒體資料的話,就需使用CaptureDeviceManager去尋找可以使用、存取的devices。
4. PlugInManager--當我們要處理資料的performance時(如:編碼),可以使用 plug-in的處理元件,如Multiplexers,Demultiplexers, Codecs, Effects、Renderers.
在JMF的程式中,我們將使用到這些Manager去create methods去建構Players、 Processors、 DataSources、DataSinks。
Event Model
MediaEvent 是定義許多JMF事件的子集合。如:我們要implement一個 listener的interface,我們就需呼叫事件:addListener;我們要去controller objects(像Players和Processors)和creatain Control objects就需呼叫事件:GainControl。
Data Model
JMFmedia players通常使〞DataSources〞管理媒體的傳輸、連結。
DataSource包含了媒體位置、protocol、和使用何種軟體來傳送媒體。
DataSource不是透過MediaLocator就是透過URL來定義,MediaLocator很類似URL而且可以從URL中去建構,即使系統上沒有安裝符合的protocol handler仍可被create。(但在Java中,只有在系統上安裝符合的protocol handler時才可被create)
DataSource管理一或多個SourceStream objects。一個標準的data source是使用byte為傳送單位;一個buffer data source是使用buffer為傳送單位。JMF定義了幾種DataSource objects的型態:
根據資料傳送方式分類:
- PullDataSource:client端開始傳送資料,並控制pull data-sources的資料流,使用的protocols型態為HTTP、FILE。JMF定義二種pull data sources型態:PullDataSource、PullBufferDataSouce。
- PushDataSource:server端開始傳送資料,並控制push data-sources的資料流。使用的protocols型態包括RTP、multicast media、VOD。JMF定義二種push data sources型態:PushDataSource、PushBufferDataSouce
client端程式可依使用者自訂,並將其以dataSource型態播出。例如:MPEG:使用者可自行改變播放位置、重播。相對的,廣播則是由server端控制,則無法改變播放位置,有些VOD支援使用者控制─例如:client端程式允許使用者能尋找到新的位置,但無法快轉或倒帶。
Specialty DataSources
JMF定義了二個特殊的Data Sources型態:Cloneable data Sources、Merging data Source
必須注意的是合併時DataSource須都皆為同一型態,例如:PullDataSource與PushDataSource不可合併。而合併後的Content Type為application/mixed-media。
Data Formats
描述媒體編碼格式名稱,資料格式型態的需求。
JMF繼承Format去定義audio和video的格式:
AudioFormat:記載audio格式的屬性,例如:頻率、bits數、和channel數量
VideoFormat:包含video相關的資料訊息。VideoFormate包含以下數個共同的格式: IndexedColorFormat 、RGBFormat 、YUVFormat 、JPEGFormat 、H261Format 、H263Format
Controls
提供設定、查詢物件屬性,通常提供存取符合的使用者介面元件,可讓使用者控制物件的屬性。許多JMF objects有接觸到Controls,包括:Controller objects、DataSource objects、DataSink objects、JMF plut-ins。
上圖為JMF controls
JMF定義的Standard Controls:
- CachingControl:監控下載進度和播放,假如,Player或Processor可以記載download progress,CachingControl就可以implements interface,讓progress bar可以display出來。
- GainControl:能夠調整audio音量,例如:對於player或processor輸出的聲音做調整或消音,它同時支援音量改變的mechanism。
上圖為Gain control
l StreamWriterControl:可使用DataSink或Multiplexer等objects從Data Source讀入媒體,並寫至目的地(如:file),可實作StreamWriterControl介面,且這個Control可限制stream產生的大小。
l FramePositioningControl
:可在
Player
或
Processor
物件的
media stream
中正確地取得
Frame
的位置。
l FrameGrabbingControl
:可以從video stream中攫取video frame,且此Control也支援Render。
l FromatControl:提供查詢與設定格式的method。
l TrackControl:是屬於FormatControl的一種型態,用在個別的tracks處理processor object performs上(如:Effect、Codec、Render plug-ins)
l PortControl、MonitorControl:可以用來控制capture process。PortControl定義了用來控制屬於capture輸出設備的method。MonitorControl可以預覽capture完、encode完後的media data。
l BufferControl:在特別的objects上控制 buffer的處理。
l Codec control:可以控制軟、硬體的編、解碼器
Ø BitRateControl
Ø FrameProcessingControl
Ø FrameRateControl
Ø H261Control
Ø H263Control
Ø KeyFrameControl
Ø MpegAudioControl
Ø QualityControl
Ø SilenceSuppressionControl
Ueser Interface Components
Control提供可以存取user interface Component(讓使用者可以看得到媒體撥放的狀態)
Ø getControlComponent:這個method是繼承AWT Component下來的,可以讓我們增加applet’s presentation space或application window。
Ø getVisualComponent、getControlPanelComponent:這二個方法可以得到player執行的畫面和控制狀態畫面。
當然,如果你不使用這些內定的control component時,也可以自定自己的component
Extensibility
可透過二種方式繼承JMF的功能
1、經由實作自訂的處理元件(plug-ins)
2、透過實作the Controller, Player, Processor, DataSource, 或 DataSink
介面
這部分屬於plug-in部分,講到p.85時會重新提到
Presentation
在JMF中,播放的處理都是由Controller interface來完成。
Controller定義了物件的控制、播放或擷取時間性媒體的控制機制。
〞Controller〞:為一介面,繼承自Clock,提供來源配置的狀態訊息,事件的產生,並且於獲得物件的機制提供控制。
JMF API 定義二種型態的Controllers: Players and Processors。 Player or Processor 產生於特定資料來源時,且不再被重複使用去播放其他的媒體
上圖為JMF controllers
Players
Player:繼承自Controller interface,用於傳送和控制時間性的媒體資料,對於AWT元件的取得、媒體的處理控制,Player都有提供methods 處理傳入的媒體