previous next

Chapter 19: Prefetching

Prefetching allows you to manage bandwidth in a complex presentation. This helps you to ensure that the presentation streams smoothly. You can stream data for high-bandwidth clips while low- bandwidth clips play, for example. To use prefetching, though, you must thoroughly understand how clips use bandwidth, as well as how to create a presentation timeline.

Note: Prefetching is not currently functional in RealOne Player.

For More Information: To learn more about bandwidth use, read Chapter 2. Chapter 13 describes the basics of SMIL timing.

Understanding Prefetching

Prefetching is a powerful feature for managing bandwidth in a streaming presentation. It lets you stream portions of large clips, or all data for small clips, before the clips play. RealOne Player stores the prefetched data in memory until clip playback begins. Using prefetched data, RealOne Player can display clips faster when they begin to play. This can reduce or eliminate the buffering that normally occurs when clips start to play.

Uses of prefetching include downloading small image files. If a presentation contains graphic buttons that display while a video plays, for example, you can prefetch the graphics files before the video begins. When the video-with- buttons segment starts, the graphics do not compete with the video for bandwidth. Another use of prefetching is to download an audio or video clip's preroll, which is described in the section "Buffering", before the clip plays.

Prefetching data is useful only when streaming across a network. It has no discernible effect when clips reside on the viewer's local computer. To use it effectively, you typically need to have a presentation in which low-bandwidth sections precede high-bandwidth sections. In these cases, prefetching lets you take advantage of low bandwidth use to download data for upcoming high- bandwidth segments. When you stream only a video, for example, prefetching offers no advantages. If a RealText clip precedes the video, though, you can use prefetching to stream the RealVideo clip's preroll while the RealText clip plays.

Warning! You should have a strong understanding of timelines and bandwidth management when prefetching clip data. Incorrect use of this feature may stall your presentation or cause RealOne Player to use excessive amounts of memory.

Using the <prefetch/> Tag

To prefetch data, you use a <prefetch/> tag, which is similar to a clip source tag like <video/>. Instead of playing a clip, though, the <prefetch/> tag downloads all or part of the clip data for playback later. As with a clip source tag, the <prefetch/> tag uses a URL to indicate the data to download, and can include timing attributes such as dur. Unlike clip source tags, a <prefetch/> tag has its own attributes that govern the speed and amount of data downloaded. In the following example, a <prefetch/> tag downloads a video clip's preroll to RealOne Player while a RealText clip plays presentation credits:

<seq>
<!-- Segment 1: Roll RealText credits and download video preroll. -->
<par endsync="credits">
<texstream src="rtsp://helixserver.example.com/credits.rt" id="credits" .../>
<prefetch src="rtsp://helixserver.example.com/video1.rm"
mediaTime="15s" bandwidth="18000" />
</par>
<!-- Segment 2: Play the video. -->
<video src="rtsp://helixserver.example.com/video1.rm" region="main"/>
</seq>

In this example, the <prefetch/> tag downloads the first 15 seconds of the clip video1.rm at a rate of approximately 18 Kbps. RealOne Player holds this data in memory until the video plays, eliminating the buffering that occurs when the clip starts to play. RealOne Player matches the prefetched data to the video through the identical URLs in the <prefetch/> and <video/> tags.

Note that in the preceding example, the <par> tag has an endsync attribute that ends the group when the RealText clip finishes. Without this attribute, there could be empty playback time if the prefetching does not complete before the RealText clip finishes. Because RealOne Player treats a <prefetch/> clip like other source clips when it determines presentation timing, always use a timing mechanism, such as endsync or dur, to ensure that prefetching does not interfere with presentation playback.

The following table summarizes the <prefetch/> tag attributes that control how much clip data is downloaded. The following sections describe how to use these attributes effectively.

<prefetch/> Attributes
Attribute Value Default Function Reference
bandwidth bps|percentage 100% Sets the bandwidth used to get data. click here
mediaSize bytes|percentage 100% Specifies the amount of data to prefetch based on the clip's size. Overrides mediaTime. click here
mediaTime h|min|s|ms|percentage 100% Sets the amount of data to prefetch based on the clip's duration. click here

Managing Prefetch Bandwidth

The <prefetch/> tag's bandwidth attribute governs how much bandwidth is assigned to fetching the clip's data. If you do not include the bandwidth attribute, prefetching uses all of the connection's available bandwidth, which is rarely desirable. You can specify a specific streaming speed in bits per second (bps), or indicate a percentage of the available bandwidth. Note that you can prefetch data at any bandwidth, regardless of the clip's normal streaming speed. For an audio clip that normally streams at 20 Kbps, for instance, you could prefetch data at any speed, from 1 Kbps to 100 Kbps or faster.

Specifying Prefetch Bandwidth in Bits Per Second

To specify the exact streaming speed in bits per second, start with the maximum recommended bandwidth for your slowest targeted connection. If 56 Kbps modems are your lowest-speed targets, for instance, use a 34 Kbps maximum streaming speed, as given in the table "Maximum Streaming Rates". Next, determine how much bandwidth you can dedicate to prefetching. If you want to stream the prefetched data in parallel with a 16 Kbps RealAudio clip, for example, you have a maximum of 18 Kbps for prefetching:

<par endsync="music">
<audio src="..." id="music" dur="50s"/>
<prefetch src="..." begin="10s" bandwidth="18000" mediaSize="20480"/>
</par>

In this example, data is prefetched at approximately 18 Kbps until either 20 Kilobytes of data have been received, or the audio clip stops playing. Note that the <prefetch/> tag's begin time means that the prefetching begins 10 seconds after the audio clip starts to play. This dedicates all available bandwidth to the audio clip during the first 10 seconds of playback, making the audio clip's own preroll stream faster. Although a begin value is optional, including it can help to manage bandwidth in the segment that includes prefetching.

Specifying Prefetch Bandwidth as a Percentage

Determining a percentage value to use for the bandwidth attribute is more complicated than specifying a specific bandwidth. It has useful benefits, though. Suppose that you use a bandwidth="50%" value when prefetching clip data. Over a 56 Kbps modem, the prefetching uses about 17 Kbps. Over a 256 Kbps DSL line, though, the prefetching uses over 100 Kbps, finishing much faster. If you used bandwidth="17000" instead, the prefetching would take place at the same rate over both connections.

The value you specify equates to a percentage of the usable bandwidth that RealOne Player detects, which may differ from the speeds listed in the table "Maximum Streaming Rates". For a 56 Kbps modem, for example, the detected bandwidth will likely be higher or lower than the maximum streaming speed of 34 Kbps. But it will definitely be less than the modem's raw speed of 56 Kbps. Because you don't know the exact prefetching speed when you use a percentage value, you need to decide upon a value carefully.

To select a percentage value, start with the maximum streaming speed for your slowest target connection. If your slowest targets are 56 Kbps modems, use a 34 Kbps maximum streaming speed. Then determine how much bandwidth is left for prefetching. For instance, you have 18 Kbps available for prefetching data while a 16 Kbps RealAudio clip plays. This 18 Kbps is approximately 53 percent of the 34 Kbps maximum speed. However, because the speed RealOne Player detects may be higher or lower, select a lower percentage value, such as 45 percent, as shown in the following example:

<par endsync="music">
<audio src="..." id="music" dur="50s"/>
<prefetch src="..." begin="10s" bandwidth="45%" mediaSize="20480"/>
</par>

Controlling Prefetch Data Download Size

Two attributes for the <prefetch/> tag, mediaSize and mediaTime, control the amount of data that RealOne Player downloads for each clip. Use just one of these attributes in each <prefetch/> tag. If you use both mediaSize and mediaTime, the mediaTime attribute is ignored. If you do not use either of these attributes, RealOne Player attempts to prefetch all the clip's data, which can cause RealOne Player to run out of memory with large clips such as videos.

Tip: The amount of data you can prefetch depends on the amount of computer memory available to RealOne Player. To reach the widest audience, do not try to prefetch more than one Megabyte of clip data.

Prefetching a Specific Amount of Data

The mediaSize attribute allows you to set how much of the clip data to prefetch based on the clip's file size. You must use mediaSize rather than mediaTime for clips that do not have internal timelines, such as images. Specify the mediaSize value in bytes, or as a percentage of the clip's total size.

Specifying mediaSize in bytes and bandwidth in bits per second lets you determine exactly how long the prefetching lasts. The following example prefetches 10 Kilobytes of clip data at a rate of approximately 6 Kilobits per second. The prefetching therefore takes approximately 13.7 seconds to complete:

<prefetch src="..." mediaSize="10240" bandwidth="6000"/>

Tip: Remember, the bandwidth attribute is in bits per second, whereas the mediaSize attribute is in bytes (8 bits = 1 byte).

If you want to prefetch entire clips, such as whole GIF files, specify mediaSize="100%" or leave the attribute out of the <prefetch/> tag. In these cases, you'll need to know the size of the prefetched clip to determine how long the prefetching lasts.

Prefetching a Specific Length of a Clip's Timeline

For clips that have internal timelines, such as RealAudio, RealVideo, or Flash, you can use mediaTime instead of mediaSize to prefetch a specific stretch of the clip's timeline. This is useful for prefetching the clip's preroll. You can specify a percentage value, or a timing value as described in "Specifying Time Values". The following example prefetches 10 seconds of clip data:

<prefetch src="..." mediaTime="10s" bandwidth="4000"/>

Keep in mind that mediaTime does not control how long prefetching lasts. The amount of time required for prefetching depends on the amount of data downloaded and the bandwidth. If the clip in the preceding example normally streams at 16 Kbps, for example, RealOne Player needs approximately 40 seconds to prefetch the first 10 seconds of the clip. This is because the prefetching bandwidth is only a quarter of the clip's streaming bandwidth.

Tip: To determine how much preroll a clip requires, open the clip in RealOne Player, and use File>Clip Properties>Clip Source to view the buffering information.

Tips for Prefetching Data

The following sections provide additional pointers for using <prefetch/> tags to stream clip data.

RealAudio and RealVideo Prefetching

Prefetch URLs

SMIL Timing with Prefetching

Prefetch Testing

Prefetching Examples

The following examples show different ways to use prefetching.

Displaying an Image Until Prefetching Completes

In the following example, standby.gif is a small image file that asks the viewer to wait while the presentation loads. The endsync attribute that targets the <prefetch/> tag makes the image display until the video prefetching has completed. The <prefetch/> tag's begin time gives 100% of the available bandwidth to the GIF download for five seconds. After that, the prefetching takes almost all of the usable bandwidth:

<seq>
<!-- Segment 1: Standby. -->
<par endsync="fetchvid">
<img src="http://www.example.com/standby.gif" fill="freeze" region="main"/>
<prefetch src="rtsp://helixserver.example.com/video.rm" id="fetchvid"
bandwidth="95%" mediaTime= "15s" begin="5s"/>
</par>
<!-- Segment 2: Play video. -->
<video src="rtsp://helixserver.example.com/video.rm" region="main"/>
</seq>

Prefetching and Caching an Image

The section "Caching Clips on RealOne Player" explains how to store clips in the RealOne Player cache for later use. While caching and prefetching are different activities, they can be used together effectively to download and retain small files that are used repeatedly. Caching should never be used with large clips, however, because RealOne Player's cache is only a few Megabytes in size.

The following SMIL sample, which omits layout attributes, prefetches a GIF image used as the background for two videos. Because the CHTTP protocol is used, the image is cached and does not need to be prefetched a second time:

<seq>
<!-- Segment 1: Play introductory section and download background. -->
<par endsync="credits">
<textstream src="rtsp://helixserver.example.com/credits.rt" id="credits" .../>
<prefetch src="chttp://helixserver.example.com/image1.gif"
bandwidth="10000"/>
</par>
<!-- Segment 2: Play video 1 against background. -->
<par>
<video src="rtsp://helixserver.example.com/video1.rm" .../>
<img src="chttp://helixserver.example.com/image1.gif" fill="freeze"/>
<par>
... other segments ...
<!-- Segment 6: Play video 2 against background. -->
<par>
<video src="rtsp://helixserver.example.com/video2.rm" .../>
<img src="chttp://helixserver.example.com/image1.gif" fill="freeze"/>
<par>
</seq>

Note: Keep in mind that prefetching stores clip data in memory until the clip plays. Caching stores a copy of the clip on the computer's hard disk. That copy may remain in the cache for several hours or even days.


RealNetworks, Inc. ©2002 RealNetworks, Inc. All rights reserved.
For more information, visit RealNetworks
Click here if the Table of Contents frame is not visible at the left side of your screen.
previous next