您的位置:首页 > 理论基础 > 计算机网络

ISTV中基于HTTP的VOD缺陷分析和优化

2011-07-18 17:37 281 查看
1. 流媒体应用项目的介绍
目前应用到ISTV项目的流媒体技术主要有RTSP和HTTP,目前绝大部分项目都是基于HTTP来做在线点播的,只有黄龙项目的在线点播是基于RTSP的,RTSP源来自于华数。

2. HTTP应用流媒体分析
严格意义上,基于HTTP的VOD不算是真的流媒体,英文称为“progressive downloading”或者“pseudo streaming”,为什么这样呢?因为HTTP缺乏流媒体基本的流控,由此基于HTTP协议很难实现媒体播放的快进,快退,暂停。那么,通常的媒体播放器又是如何利用HTTP来实现这样的功能呢?
我们都知道,不管媒体文件有多大,HTTP都只是视它为一个HTTP的元素,可以只需要发送一个HTTP请求,WEB Server就会源源不断地将媒体流推送给客户端,而不管客户端是否接受,这就是HTTP协议本身没有流控的原因,那这样会带来什么后果呢?
如果服务器的推流速度和客户端同步, 那么基本不会出现什么大问题;如果小于客户端的接收流的速度,那么播放就会一卡一卡的;如果大于或者远大于客户端的接收速度,那又会是怎么样的结果呢?很不幸,在我们所有的ISTV项目中,只要是基于HTTP的VOD,都无一例外是第三种情况。因为我们VOD是基于局域网的,大家都知道,局域网的带宽资源是很丰富的,服务器的推流的速度肯定大于播放器的播放速度,那么在这么速度极端不协调的情况下,服务器的推流速度究竟由谁来限制呢?
答案是:TCP协议栈。我们的VOD点播是基于TCP的HTTP协议。TCP是安全的,可靠的,包肯定不会丢,服务器检测到客户端的接收缓冲区满了,就会减小发送数据滑动窗口的大小。所以HTTP的流控是通过TCP协议栈来调节的,不是HTTP本身。试想,这样对服务器造成的压力有多大!!!
下面就分析基于HTTP协议如何实现SEEK,PAUSE等操作。
1)SEEK(快进和快退)
先关闭之前的tcp连接,重新连接,发送http请求,该请求带了媒体的偏移位置。由此可见,每一次的快进和快退,都等于是重新开始播放,只是每次开始播放的位置不一样。
2)PAUSE
该操作就更有意思了,客户端暂停了播放,也就是不从缓冲区读取数据了,但是服务器不知道客户端停止了播放,依然不停地发送数据给客户端,直到客户端的接收缓冲区已满,然后服务器的数据发送不出去了,理论上是服务器端的滑动窗口的大小估计就是0了,然后协议栈还在不停在尝试发送数据,因为是基于tcp,这些数据还不能丢。nnd,这种方式实现暂停,协议栈都哭了。很不幸,MPLAYER就是这么干的。所以暂停的时间长了,就容易出现问题。
虽然HTTP没有PAUSE的支持,但是针对PAUSE是可以优化的,优化的方法是,将媒体文件分片,分片的大小以稍小于TCP协议栈的缓冲区大小为宜。HTTP请求一次只请求一个分片的大小,暂停播放后,就不在发送分片请求了。这样可以保证让服务器运行的时间长一些,播放器暂停理论上可以无限长了。

3. RTSP应用流媒体介绍
这个网上的文章很多,就不做详细介绍了。

附上关于HTTP流分析的一片英文:
HTTP Streaming Video Tutorial"HTTP streaming", also called "progressive downloading" or "pseudo streaming", is when you make use of your web server to deliver your streaming media files. For this, there is no need for any specialized web hosting server. As long as your webserver recognizes common video files, there's no problem. Actually, it is not really "streaming" at all. It's a simple bulk download of your video file to the end user's machine. What makes it appear to be "streaming" is that your video file will begin playing while the download is still in progress. However, there is one main difference that could be noticed by the viewer between HTTP video streaming and true video streaming - the end viewer will not be able to fast-forward to the end of the clip until the whole video file is downloaded. But, for those on a tight budget who would still like to pseudo stream their video clips, this is really the best and cheapest alternative for websites that have little to moderate traffic flow. When using progressive downloading of videos, there are some disadvantages. If you have a good deal of webtraffic to your website, HTTP streaming videos may not work for you since it will not be able to handle the larger traffic loads. You will be unable to broadcast live events. Also, when using HTTP streaming video files, it is not able to read and adjust to the data rate (end users' connection speed) automatically. As a result, if you want to create individual versions for various speeds, it will be needful for you to create separate video files for each speed. As long as you don't have a heavy website traffic load, this should not be a problem for most webservers. Realistically, though, this isn't practical, so you must decide which video formats to make available. To create HTTP streaming videos, you must first create a video file. It's best to use a common video streaming format, such as Windows Media Player (.wmv), MPEG-4, Macomedia Flash (.swf), Apple Quicktime (.mov), etc. Next, you need to upload your file to your web hosting server. Lastly, embed the video clip in a web page using special HTML tags (see how to embed Flash media files or the other links to the left about embeding videos; or you could make a hyperlink to your file). That's about it. With the embedded video file, the clip will begin to play as soon as your web page loads. If you use a hyperlink, when it's clicked on, it will open the viewer's defualt video player and your file will begin streaming, however you won't necessarily have control of how your video will appear within your webpage. For this reason, in the next parts of this videohosting tutorial we'll be talking mostly about progressive downloading of videos. The next step of this free video hosting tutorial guide is how to create streaming videos.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: