- 浏览: 858396 次
- 性别:
- 来自: 上海
最新评论
-
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 1594推荐下载: iWidsets最新版2.0.0下载(J2ME) ... -
J2ME时间例子
2009-11-04 01:51 2057下面是一个时间例子: Calendar.getInst ... -
MP3Dict应用发布了
2009-11-03 18:33 1601iWidsets发布新用MP3Dict了 ... -
一些很特别的J2ME开源项目
2009-11-03 04:35 2135StrutsME 一个轻量级的序列化协议,使J2ME客户端能调 ... -
基于J2ME平台的Log4j
2009-11-03 03:55 2065J2ME平台并没有提供LOG来获取一些有用的信息,如 ... -
iWidsets公告
2009-10-21 15:16 1784由于前段时间忘记备案,国庆前关闭网站,导致软件无法下载,请见谅 ... -
iWidsets 发布1.8.1版本(20090920)
2009-09-20 21:21 19421.1 iWidsets 发布1.8.1版本,此版本主要修正B ... -
iWidsets J2ME客户端首次发布了
2009-09-13 13:40 1071经过九个月的开发,iWidsets J2ME客户端首次发布了, ... -
iWidsets J2ME客户端首次发布了
2009-09-13 12:20 1193经过九个月的开发,iWidsets J2ME客户端首次发布了, ... -
解决java.lang.SecurityException: Access denied
2009-08-13 15:42 11128NOKIA的一些目录不允许创建文件,所以会抛出java.lan ... -
J2ME FileConnection开发
2009-08-07 00:00 2577下面是对开发J2ME FileConnection的一些总结: ... -
Experiments in Streaming Content in Java ME(源码下载)
2009-08-04 09:38 1290Experiments in Streaming Conten ... -
keyRepeated和keyPressed处理
2009-07-26 21:38 3079今天修改了一个很重要的Bug,这个BUG会不断向服务端请求相同 ... -
Experiments in Streaming Content in Java ME(3)
2009-07-14 11:47 1927Back to RTPSourceStream and Str ... -
Experiments in Streaming Content in Java ME(2)
2009-07-14 11:12 2740Creating an RTSP Protocol Handl ... -
J2ME实现RTSP(只有在支持的手机才能用)
2009-07-12 21:09 1939最近在研究J2ME实现RTSP协议,在索爱开发网站中看到一个类 ... -
少用System.out.println()
2009-07-11 16:13 3450之前就知道System.out.println ... -
读取流最快方式
2009-07-09 11:42 2547读取流最快方式,当你知道流的长度时,如流长度是maxLengt ... -
让你的J2ME安装包跑起来及其优化
2009-07-09 11:21 1238一、无法下载:通过HTTP下载安装包时,可能会出现“未知文件类 ... -
安装Jar提示“jar文件无效”的另一个奇怪原因
2009-06-24 15:29 8631今天在做魔橙推送邮时遇到一个奇怪的问题,在安装jar时总是提示 ...
相关推荐
NULL 博文链接:https://fonter.iteye.com/blog/439086
这本书对反应式机器人和行为式机器人有各种介绍,对智能机器人的爱好者是一个很不错的启发学习。
The Puzzle of Thought Experiments in Conceptual
Experiments in segmentation using a facet model region grower
主要是讲他的 Braitenberg 小车,千辛万苦才搞到的,淘宝也没有卖的,感谢舍友。只设置一积分 下载,如果后续变多,那是xxdn系统的问题。
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 ...
“The definitive master class in performance tuning Java applications…if you love all the gory details, this is the book for you.” –James Gosling, creator of the Java Programming Language ...
涵盖实验设计和分析的基本主题,适用于研究生和高级本科生。
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 ...
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 ...
In statistics, an experiment refers to any process that generates a set of data. An experimental design involves making purposeful changes of the inputs (factors) to a process (or product) in order...
"The definitive master class in performance tuning Java applications…if you love all the gory details, this is the book for you." –James Gosling, creator of the Java Programming Language ...
Improvements in the Java platform and new multicore/multiprocessor hardware have made it possible to dramatically improve the performance and scalability of Java software. You’ll learn how to ...
Experiments on the Use of Corpus-based Word BI-gram in Chinese Word Segmentation
06,Lessons In Electric Circuits, Volume VI – Experiments.pdf
Design and Analysis of Experiments,试验设计与分析.
David S. Lee:Randomized Experiments from Non-random Selection in U.S. House Elections._ Journal of Econometrics,
Design and Analysis of Experiments Vol. 1 Introduction to Experimental design 2nd (2008)