流媒体程序开发之:H264解码器移植到OPhone
2009-09-22 00:00:00 来源:WEB开发网BMPImage是一个工具类,主要用于把RGB序列,转换为BMP图象用于显示:
@author ophone
* @email 3751624@qq.com
*/
package ophone.streaming.video.h264;
import java.nio.ByteBuffer;
public class BMPImage {
// --- 私有常量
private final static int BITMAPFILEHEADER_SIZE = 14;
private final static int BITMAPINFOHEADER_SIZE = 40;
// --- 位图文件标头
private byte bfType[] = { 'B', 'M' };
private int bfSize = 0;
private int bfReserved1 = 0;
private int bfReserved2 = 0;
private int bfOffBits = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
// --- 位图信息标头
private int biSize = BITMAPINFOHEADER_SIZE;
private int biWidth = 176;
private int biHeight = 144;
private int biPlanes = 1;
private int biBitCount = 24;
private int biCompression = 0;
private int biSizeImage = biWidth*biHeight*3;
private int biXPelsPerMeter = 0x0;
private int biYPelsPerMeter = 0x0;
private int biClrUsed = 0;
private int biClrImportant = 0;
ByteBuffer bmpBuffer = null;
public BMPImage(byte[] Data,int Width,int Height){
biWidth = Width;
biHeight = Height;
biSizeImage = biWidth*biHeight*3;
bfSize = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE + biWidth*biHeight*3;
bmpBuffer = ByteBuffer.allocate(BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE + biWidth*biHeight*3);
writeBitmapFileHeader();
writeBitmapInfoHeader();
bmpBuffer.put(Data);
}
public byte[] getByte(){
return bmpBuffer.array();
}
private byte[] intToWord(int parValue) {
byte retValue[] = new byte[2];
retValue[0] = (byte) (parValue & 0x00FF);
retValue[1] = (byte) ((parValue >> 8) & 0x00FF);
return (retValue);
}
private byte[] intToDWord(int parValue) {
byte retValue[] = new byte[4];
retValue[0] = (byte) (parValue & 0x00FF);
retValue[1] = (byte) ((parValue >> 8) & 0x000000FF);
retValue[2] = (byte) ((parValue >> 16) & 0x000000FF);
retValue[3] = (byte) ((parValue >> 24) & 0x000000FF);
return (retValue);
}
private void writeBitmapFileHeader () {
bmpBuffer.put(bfType);
bmpBuffer.put(intToDWord (bfSize));
bmpBuffer.put(intToWord (bfReserved1));
bmpBuffer.put(intToWord (bfReserved2));
bmpBuffer.put(intToDWord (bfOffBits));
}
private void writeBitmapInfoHeader () {
bmpBuffer.put(intToDWord (biSize));
bmpBuffer.put(intToDWord (biWidth));
bmpBuffer.put(intToDWord (biHeight));
bmpBuffer.put(intToWord (biPlanes));
bmpBuffer.put(intToWord (biBitCount));
bmpBuffer.put(intToDWord (biCompression));
bmpBuffer.put(intToDWord (biSizeImage));
bmpBuffer.put(intToDWord (biXPelsPerMeter));
bmpBuffer.put(intToDWord (biYPelsPerMeter));
bmpBuffer.put(intToDWord (biClrUsed));
bmpBuffer.put(intToDWord (biClrImportant));
}
}
测试程序完整工程在此暂不提供。
5.5集成测试
集成测试有两点需要注意,在运行程序前,需要把动态库复制到模拟器的/system/lib目录下面,还需要把需要解码的视频传到模拟器的/tmp目录下。
这里要明确的是,OPhone和Symbian的模拟器都做的太不人性化了,Symbian复制一个文件到模拟器中,要进一堆很深的目录,OPhone的更恼火,需要敲命令把文件传递到模拟器里,说实话,仅在这点上,Mobile的模拟器做的还是非常人性化的。
命令:
PATH=D:"OPhone"OPhone SDK"tools"
adb.exe remount
adb.exe push D:"Eclipse"workspace"H264Example"libs"armeabi"libH264Decode.so /system/lib
adb.exe push D:"Eclipse"workspace"H264Example"Demo.264 /tmp
pause
这里解释一下abd push命令:
adb push <本地文件路径> <远程文件路径> - 复制文件或者目录到模拟器
在Eclipse中,启动库测试程序,得到画面如下:
FAQ 3:
模拟器黑屏怎么办?
这可能是由于模拟器启动速度比较慢所引起的,所以需要多等一会。希望下个版本能够改进。
更多精彩
赞助商链接