2011年10月13日

[Android] Media Player Design

Software Architecture

轉到AP team之後接到的第一份工作是這個media player board的application design,開發的平台是android 2.3,需要有video, audio, picture的播放、旋轉、放大縮小等等功能,除此之外還需要透過UART port讓這個media payer board可以接受外部的控制。

由於android app life cycle的特性,activity在Pause與Stop期間都可能會被清出系統中,所以還是打算有一個在背景執行的shell daemon service做為整個app的流程與資源掌控者,由它去把主操作介面與其它播放程式的介面喚起來,並且在當前的畫面結束之後把預設的介面叫起來。

除此之外,還有一個service專門負責透過UART與外部的裝置溝通。

System Life Cycle
基本上所有的Player都在Active期間執行,但是從Inactive期間就必需可以接收並且處理UART傳送過來的command。而系統可能因為power state的指令而在active與inactive之間切換狀態。


JNI Design
JNI是android platform用來與底層溝通的介面,上層是使用Java Language來實作,每個Java method都會對應到一個C function,由C function所撰寫的程式來完成對硬體或OS資源的控制,而Java method則去呼叫C function並且完成應用程式所需要的功能。

下表列出需要存取底層資源的功能,這個部份必需與OS member做進一步的討論。

Name
Input Data
Output Data
Description
ActionSleep

True: success
False: fail
Trigger softwear sleep/weakup that request by host command.
EnableDbgMsg
True: enable
False: disable
True: success
False: fail
Enable/Disable debug message that request by host command.
ActionFactorySetting


Set factory data.
ReqDiagnosticData

I2C1
I2C2
I2C3
SD
USB
Get diagnostic data when customer request.
ClearDiagnosticData

True: success
False: fail
Clear diagnostic data when customer request.
ReqMediaConnection

SD
USB
Get media connection state when customer request.
EnableI2C
True: enable
False: disable
True: success
False: fail
Enable/Disable I2C control interface when customer request.
ReqModelName

Model name
Vender code
Function1
Function2
Get model name and vender code when customer request.
ReqSoftwareUpdate

True: success
False: fail
Update software according to SD card or USB mass storage when customer request.
ClearHistory

True: success
False: fail
Clear history log when customer request.
ReqVersion

EEP
SFT
Get EEPROM version and software version.
ResEmergency

Error Code
Response error code when emergency event occur (include H/W and S/W issue).





Reference Data
1.Audio Player的部份會參考 \src\packages\apps\Gallery
2.Video與Picture的部份會參考 \src\packages\apps\Music



Study Topic
1.Activity and service life cycle control
2.Internal process communication
3.GUI layout design
4.Timer mechanism
5.Data share mechanism

參考資料
Service的life cycle與sample code
Android Service-概念(一)
Android Service-幾種應用範例(二)
Android Bind Service机制详解
Android的 IPC機制及多線程技術
具有Software Timer功能的Widget物件 - Toast
Bundle的介紹與應用
JNI的介紹
Activity和Service之間的通信
Activity與Service透過Broadcast交換資料