- 浏览: 867558 次
- 性别:
- 来自: 上海
最新评论
-
waterflow:
感谢分享
简单的ChartDirector生成图表例子 -
YQuite:
写到最后一种文件才看到这个,洼的一声哭了出来 - - !
java简单解析docx、pptx、xlsx文档 -
q394469902:
Android通过selector改变界面状态 -
db6623919:
直接粘贴别人帖子还是英文的,有意思?
实现RTSP协议的简单例子 -
ykou314:
请问下,这些超级命令,是否需要android root权限,尤 ...
Android系统在超级终端下必会的命令大全(七)
Since my book on Mobile Media API (MMAPI), Pro Java ME MMAPI: Mobile Media API for Java Micro Edition, was published in May, I have been inundated with requests to help readers with streaming content via MMAPI for Java-enabled mobile devices. This topic was an important omission from the book, but one that was simply not feasible to include because of the lack of support for it within various MMAPI implementations. In this article, I will show you the results of experiments I have conducted since the publication of the book to stream content via MMAPI using a custom datasource.
DISCLAIMER: Before I commence, I would like to point out that even though I was able to stream data from a streaming server and receive it successfully in a MIDlet using a custom datasource, I wasn't able to utilize this data in any meaningful manner because of limitations in the way this data is read by the MMAPI implementation at my disposal. You may have more success if you have access to a MMAPI implementation that doesn't read its data fully. Even if you don't, this article still provides a good study of the issues involved in streaming media data. At the very least, it shows you how to create and utilize your own custom datasource.
For a background on Java ME please see my previous tutorial series on getting started. For an introduction to MMAPI, tutorial 4 is a good start, or you can always buy the book.
Background to the streaming problem
MMAPI is a format- and protocol-agnostic API, which means that the API doesn't dictate mandatory support from device manufacturers for any particular format or protocol. One of the protocols that is widely requested by application developers is the Real Time Streaming Protocol (RTSP) and the associated Real-time Transport Protocol (RTP) for streaming audio/video content. The advantage of streaming content is that it provides a fast turnaround time for the user, control over the content distribution to the distributor, and an overall richer user experience.
However, hardly any manufacturer supports this protocol through Java ME. Some new phones provide support for RTSP, but that support is only on a smattering of devices. A majority of devices still do not support this protocol, therefore limiting useful application development in the streaming media department. A majority of questions in the MMAPI forums of various device manufacturers revolve around this very issue, that is, how to provide streaming data when RTSP is not supported. This article aims to point you in the right direction. I'll start by cutting through the clutter to try to provide an understanding of what streaming means.
What is streaming?
Streaming is the process of transferring data via a channel to its destination, where it is decoded and consumed via the user or device in real time, that is, as the data is being delivered. It differs from non-streaming processes because it doesn't require the data to be fully downloaded before it can be seen or used. Streaming is not the property of the data that is being delivered, but is an attribute of the distribution channel. This means, technically, that most media can be streamed.
HTTP and RTSP
HTTP and RTSP are application-level protocols that allow remote retrieval of data. So why can't you use HTTP for streaming media content? The truth is, you can. When you click on a Web page link to play an audio file, in most cases the media data is streamed to your machine. However, streaming content over HTTP is inherently inefficient. This is because HTTP is based on the Transmission Control Protocol (TCP), which makes sure that media packets are delivered to their destination reliably without worrying about when they are delivered. On the other hand, RTSP can be based on both User Datagram Protocol (UDP), which is a connectionless protocol ensuring faster delivery over reliability, and on TCP. Besides, RTSP has control mechanisms built in that allow random access to the media data, allowing you to seek, pause, and play.
Making sense of RTSP, RTP, and RTCP
There is a lot of confusion among newcomers over the acronyms RTSP, RTP, and RTCP. All three represent different protocols related to streaming of media content. An RTSP session initiates both Real-time Transport Protocol (RTP) and RTP Control Protocol (RTCP) sessions. RTSP is only the control protocol, a bit like a remote control for a DVD player, in that it allows you to start, stop, resume, and seek data remotely. The actual data delivery is done via RTP, and RTCP is a partner protocol to RTP providing feedback to both the sender and receiver on the quality of media data that is being transferred.
With this basic introduction about RTSP and streaming out of the way, let's set up our own streaming server to conduct some experiments. You can read more about RTSP, RTP, and RTCP at http://www.rtsp.org.
Set up a streaming server
To conduct experiments for the purposes of this article, you will need access to a specialty streaming server that can create RTSP streams for media objects. One such server is the Darwin Streaming Server, which is an open-source streaming server based on the same source code as Apple's commercial QuickTime streaming server. Implementations of this free server are available for Mac OS, Linux, and Windows. Download the version that is suitable for your OS and run the installer. You can also choose to download the source code and build it in your environment. I have run the examples in this article on a Windows XP machine, and the server is installed in C:\Program Files\Darwin Streaming Server .
For the purposes of this article, you will also need to have Perl installed on your computer, to administer the Darwin server. For Windows, you can download ActivePerl.
As part of the installation, you will be asked to provide an administrator username and password, but make sure that you run the administration server after the installation (by running the streamingadminserver.pl file). This starts an administration server on port 1220 with which you can monitor the current activity within the streaming server. More importantly, you will need to supply a username/password combination the first time you log into the administrative console (by navigating to http://localhost:1220 in your browser) for running the movie and MP3 broadcast service. It is important to set this (even though you never really need to supply this username/password combination anywhere when running the examples in this article).
Note: On Windows, if you download the latest version of ActivePerl, streamingadminserver.pl is likely to fail with the following error:
ActivePerl 5.8.0 or higher is required in order to run the Darwin Streaming Server web-based administration. Please download it from http://www.activeperl.com/ and install it.
This is because of an incorrect configuration check in this script, and you can easily fix it by commenting out lines 33 and 34 (put a #
in front of these lines).
The streaming server starts on port 554 and comes with a few sample movie files, ready for streaming in the installation folder under the Movies directory. The Darwin server can stream MPEG-4, 3GPP, and QuickTime movie files natively. This means that these files don't need to be "hinted" in order to be streamed. Hinting is a process by which media files are prepared with track information for streaming using the professional version of QuickTime. For the purposes of this article, I will work with natively streamable files like 3GPP and MPEG-4 only.
To test that your streaming server is working correctly, use the QuickTime player to launch a file via RTSP. For example, if you can open the URL rtsp://localhost:554/sample_50kbit.3gp correctly in the Quicktime player and view the file, pause it, stop it, and seek it, then your streaming server is working correctly.
Model an RTP packet
As I said earlier, RTP is the actual delivery protocol for streaming data. Each streaming session involves the streaming server sending RTP packets to its destination based on the client request (requests that are delivered via the RTSP protocol). A full knowledge of the RTP RFC is not required for the purposes of this article, so the following base class will model an RTP packet to its best possible approximation.
Note: I have used the Java ME Wireless Toolkit 2.3 (beta) to create and run the examples in this article. You can start by creating a project called "StreamingData" (or whatever you prefer) in this toolkit to place your code in. The J2ME tutorial part 1 gives more details on the process of creating projects in this toolkit.
public class RTPPacket { // used to identify separate streams that may contribute to this packet private long SSRC; // incrementing identifier for each packet that is sent private long sequenceNumber; // used to place this packet in the correct timing order // that is, where this packet fits in time based media private long timeStamp; // the type of the media data, or the payload type private long payloadType; // the actual media data, also called the payload private byte data[]; // the get and set methods public long getSSRC() { return this.SSRC; } public void setSSRC(long SSRC) { this.SSRC = SSRC; } public long getSequenceNumber() { return this.sequenceNumber; } public void setSequenceNumber(long sequenceNumber) { this.sequenceNumber = sequenceNumber; } public long getTimeStamp() { return this.timeStamp; } public void setTimeStamp(long timeStamp) { this.timeStamp = timeStamp; } public long getPayloadType() { return this.payloadType; } public void setPayloadType(long payloadType) { this.payloadType = payloadType; } public byte[] getData() { return this.data; } public void setData(byte[] data) { this.data = data; } public String toString() { return "RTPPacket " + sequenceNumber + ": [" + " ssrc=0x" + SSRC + ", timestamp=" + timeStamp + ", payload type=" + payloadType + " ]"; } }
The comments within the code should offer you some idea about the various features of an RTP packet. Since you won't be building a complete RTP client and will be running this code within the confines of this example, the main feature of the above class is the data, or the payload contained within such a packet. Note that an RTP packet contains other information as well, which is not modeled by this class.
Create a custom DataSource
A DataSource
is a MMAPI abstract class, implementations of which encapsulate the task of media data location and retrieval. Device manufacturers provide their own implementations in the Java ME toolkit for most sources. Developers don't need to create their own custom datasources because the task of locating data over file or network is rudimentary and fulfilled by the device manufacturer's implementation. However, in cases where the developer needs to do data retrieval from a custom source, a custom datasource is the answer, and media data fetched from a streaming server is a perfect example.
Data retrieval is one thing, while data consumption is another. Since MMAPI doesn't allow you to create custom media players, will a custom datasource suffice in this example? Let's proceed further with the creation of the custom datasource before I answer that question. The following listing shows the starting of the custom datasource class that I will use for talking to the streaming server:
import javax.microedition.media.Control; import javax.microedition.media.protocol.DataSource; import javax.microedition.media.protocol.SourceStream; public class StreamingDataSource extends DataSource { // the full URL like locator to the destination private String locator; // the internal stream that connects to the source private SourceStream[] streams; public StreamingDataSource(String locator) { super(locator); setLocator(locator); } public void setLocator(String locator) { this.locator = locator; } public String getLocator() { return locator; } public void connect() {} public void stop() {} public void start() {} public void disconnect() {} public String getContentType() { return ""; } public Control[] getControls() { return null; } public Control getControl(String controlType) { return null; } public SourceStream[] getStreams() { return streams; } }
This class contains only placeholder methods at the moment. Internally, each datasource uses a SourceStream
implementation to read individual streams of data from; therefore, let's create a simple SourceStream
implementation for reading RTP packets:
import java.io.IOException; import javax.microedition.media.Control; import javax.microedition.media.protocol.SourceStream; import javax.microedition.media.protocol.ContentDescriptor; public class RTPSourceStream implements SourceStream { public RTPSourceStream(String address) throws IOException { } public void close() { } public int read(byte[] buffer, int offset, int length) throws IOException { return 0; } public long seek(long where) throws IOException { throw new IOException("cannot seek"); } public long tell() { return -1; } public int getSeekType() { return NOT_SEEKABLE; } public Control[] getControls() { return null; } public Control getControl(String controlType) { return null; } public long getContentLength() { return -1; } public int getTransferSize() { return -1; } public ContentDescriptor getContentDescriptor() { return new ContentDescriptor("audio/rtp"); } }
发表评论
-
j2me to android 例子源码下载
2009-11-11 12:21 1635推荐下载: iWidsets最新版2.0.0下载(J2ME) ... -
J2ME时间例子
2009-11-04 01:51 2099下面是一个时间例子: Calendar.getInst ... -
MP3Dict应用发布了
2009-11-03 18:33 1669iWidsets发布新用MP3Dict了 ... -
一些很特别的J2ME开源项目
2009-11-03 04:35 2199StrutsME 一个轻量级的序列化协议,使J2ME客户端能调 ... -
基于J2ME平台的Log4j
2009-11-03 03:55 2112J2ME平台并没有提供LOG来获取一些有用的信息,如 ... -
iWidsets公告
2009-10-21 15:16 1841由于前段时间忘记备案,国庆前关闭网站,导致软件无法下载,请见谅 ... -
iWidsets 发布1.8.1版本(20090920)
2009-09-20 21:21 19951.1 iWidsets 发布1.8.1版本,此版本主要修正B ... -
iWidsets J2ME客户端首次发布了
2009-09-13 13:40 1112经过九个月的开发,iWidsets J2ME客户端首次发布了, ... -
iWidsets J2ME客户端首次发布了
2009-09-13 12:20 1233经过九个月的开发,iWidsets J2ME客户端首次发布了, ... -
解决java.lang.SecurityException: Access denied
2009-08-13 15:42 11237NOKIA的一些目录不允许创建文件,所以会抛出java.lan ... -
J2ME FileConnection开发
2009-08-07 00:00 2645下面是对开发J2ME FileConnection的一些总结: ... -
Experiments in Streaming Content in Java ME(源码下载)
2009-08-04 09:38 1330Experiments in Streaming Conten ... -
keyRepeated和keyPressed处理
2009-07-26 21:38 3131今天修改了一个很重要的Bug,这个BUG会不断向服务端请求相同 ... -
Experiments in Streaming Content in Java ME(3)
2009-07-14 11:47 1977Back to RTPSourceStream and Str ... -
Experiments in Streaming Content in Java ME(2)
2009-07-14 11:12 2801Creating an RTSP Protocol Handl ... -
J2ME实现RTSP(只有在支持的手机才能用)
2009-07-12 21:09 2006最近在研究J2ME实现RTSP协议,在索爱开发网站中看到一个类 ... -
少用System.out.println()
2009-07-11 16:13 3504之前就知道System.out.println ... -
读取流最快方式
2009-07-09 11:42 2600读取流最快方式,当你知道流的长度时,如流长度是maxLengt ... -
让你的J2ME安装包跑起来及其优化
2009-07-09 11:21 1281一、无法下载:通过HTTP下载安装包时,可能会出现“未知文件类 ... -
安装Jar提示“jar文件无效”的另一个奇怪原因
2009-06-24 15:29 8756今天在做魔橙推送邮时遇到一个奇怪的问题,在安装jar时总是提示 ...
相关推荐
标题“Experiments in Streaming Content in Java ME(源码下载)”涉及的是在Java ME环境中实现流媒体内容的实验。Java ME(Micro Edition)是Java平台的一个版本,主要用于移动设备和嵌入式系统。这个项目可能专注于...
这本书对反应式机器人和行为式机器人有各种介绍,对智能机器人的爱好者是一个很不错的启发学习。
《车辆:合成心理学的实验》是由Valentino Braitenberg所著的一本经典著作,它深入探讨了人工生命和智能机器人的概念,特别是在心理学视角下的机器行为。这本书的核心是Braitenberg小车,这是一种简单的机器人设计,...
java8流源码java-flow-experiments 在这个存储库中,我正在试验 ,它将成为 Java 8 应用程序java.util.concurrent包中的 Java 9 的一部分。 这个存储库是为我的主题为 java.util.concurrent.Flow 做好准备的演讲准备...
ideally, intermediate-level data analysts and data scientists with experience in Java. Preferably, you will have experience with the fundamentals of machine learning and now have a desire to explore ...
1. **循环反馈机制**:思维实验中的假设会被不断地测试和修正,这类似于科学研究中的假设检验过程。每一次假设的调整都会影响到后续的推论,形成一个不断迭代的循环。 2. **棱镜式再评估**:通过不同的视角重新审视...
1 the fruit-fly experiments described in Carl Zimmer’s piece in the Science Times on Tuesday. Fruit flies who were taught to be smarter than the average fruit fly 2 to live shorter lives. This ...
- 《实验设计:理论与应用》(Design and Analysis of Experiments)由Douglas C. Montgomery著。 - 《统计学原理》(Principles of Statistics)等相关教材。 通过以上概述,我们可以看到《实验设计与分析第一门...
The release of Java 9 has brought many subtle and not-so-subtle changes to the way in which Java programmers approach their code. The most important ones are definitely the availability of a REPL, ...
Design of Experiments for Engineers and Scientists Second Edition Design of Experiments (DOE) is a powerful technique used for both exploring new processes and gaining increased knowledge of existing ...
1. **初步分割**:采用一种能够保留图像细节分辨率的方法进行初步分割。 2. **构建结构**: - **区域属性列表**:记录每个分割出的子区域的属性信息,如面积、形状、灰度均值等。 - **区域邻接图**:表示各个子...
In conclusion, this Java laboratory report covers fundamental programming structures in Java, including data types, variables, assignments, and operators. The three experiments demonstrate the ...
实验设计(Design Of Experiments,简称DOE)是统计学中的一个重要概念,它是指在进行一项研究或实验时,有目的性地改变过程(或产品)的输入变量(因素),以便观察输出变量(响应)的变化情况。DOE的核心在于通过...
"gradle_java_experiments"项目是一个专注于探索Gradle与Java结合使用的实验性项目,旨在帮助开发者深入理解这两个工具的协同工作方式。 **Gradle特性与优势** 1. **灵活的构建模型**:Gradle基于Groovy或Kotlin ...
1. 书籍的版权归属于John Wiley & Sons, Inc.,表明该书是由知名的学术出版机构出版。 2. 文档中包含版权声明,说明了版权所有、复制、存储、检索、传输等方面的规定,反映了对于知识产权的保护。 3. 提到了可以通过...
David S. Lee:Randomized Experiments from Non-random Selection in U.S. House Elections._ Journal of Econometrics,
在IT领域,Prolog(Programming in Logic)是一种专门用于逻辑编程的高级编程语言,常用于人工智能领域的研究与开发。 在本书的介绍部分,作者首先带领读者入门Prolog语言,随后以一系列实验加深对离散数学、逻辑...
Java8实验 酿什么呢? Java8是! 这个实验项目深入到Java8中,并探讨了其中引入的一些非常酷的功能。 该代码包含以下Java8功能: 内置功能接口 谓词 职能 溪流 map() reduce filter collect 自定义功能界面 ...
Design And Analysis Of Experiments, 5Th Edition (Douglas C Montgomery)-Keep 试验设计与分析 5ed