Chapter 14. Streaming Audio and Video

Introduction

Streaming is used to deliver, and simultaneously view, time-based media. Time-based media includes video and audio. Other kinds of presentations include play lists of audio or video, or perhaps image slide shows expressed in a markup language that specifies when they should be displayed.

The alternative to streaming media is download and play. In this style of playing time-based media, the media file is first downloaded and then played. This is suitable for media of short duration and/or small size. For long media, the user would not want to wait 10 minutes for download before watching a 10-minute video. Streaming allows the user to view the media while it is being downloaded.

Streaming media on a personal computer can be viewed in the following manners:

  • From a streaming media player such as RealPlayer, Windows Media Player, Quicktime, or others.

  • From a browser plug-in based on a plug-in associated with a dedicated streaming media player or a Java applet.

Streaming media players can either be invoked by the user who supplies a location for the data, either a local file or a location over the network using various streaming protocols, or by an anchor tag that is associated with the media type in the browser. The user experience would then be that he or she would click on a hyperlink in a Web page and the media player would open in another window and start playing the media.

If the streaming media is to be displayed within a Web page plug-in, a metafile is necessary. This metafile indicates what media will be played, rather than the data itself. The metafile is necessary because a browser plug-in will download the file specified. So, if the media was specified in the plug-in, the media would be downloaded obviating the desired streaming effect.

For Internet Explorer, an ActiveX Control may be used instead of a plug-in. This will not work with other browsers, such as the Firefox browser, but there are techniques to have the browser use the ActiveX control in Internet Explorer, and a browser plug-in in other browsers.

Streaming media can also be viewed on wireless devices. Most popular streaming players have been ported to work on various mobile phones. Streaming to mobile phones typically uses the same servers used to stream media over the Internet, but because of the smaller screen, and lower connection bandwidth, the media itself is typically geared to the mobile device.

When using interMedia with either RealServer or Microsoft Media Server, the source of data is an Oracle database procedure. Combining streaming media with the power of the database allows the endpoint of data to be either a discrete presentation or something more abstract, like the most popular song of the day, a random video, or anything else that can be created dynamically.

Microsoft Media Services

Background

As we have seen before, interMedia supports streaming data directly from the database to the client. The client media player itself is unaware that the media is being delivered from the database.

Microsoft Media Services supports formats that include:

  • Windows Media Video (.wmv)

  • Windows Media Audio (.wma)

  • Advanced Systems Format (.asf)

  • MP3 (.mp3)

  • SMIL-based play list (a limited subset of SMIL) (.wsx)

It should be noted that the Advanced Systems Format is a binary format that can contain other media and delivers it in a coordinated (or synchronized) manner. This should not be confused with a Microsoft ASX file that is an XML-formatted script that is a metafile used to coordinate the delivery of media from the client player side and is typically delivered from an HTTP Web server.

The Windows Media Player supports a much wider number of formats than Windows Media Services. These other supported formats are typically delivered with an HTTP server. For example, synchronized media presentations, in the form of markup tags, can be delivered by an HTTP Web server.

For Windows Media Services, static synchronized presentations can be put together by a presentation GUI and embedded within a single ASF file.

The Windows Media Player supports HTML pages. These Web pages can themselves contain media presentations that use the Windows Media Player ActiveX control plug-in.

To coordinate the delivery of media from a Microsoft Media Services server the choices are:

  • Advanced Systems Format (ASF)

  • SMIL-based play list—limited to playing a list of Windows media files in sequence

To coordinate media from the client side, the choices are:

  • ASX metafiles

  • XHTML+TIME SMIL profile within Internet Explorer

In addition to the above formats, time-based captioning can be added to a streaming presentation with a synchronized accessible media interchange (SAMI) file that is similar to SMIL or XHTML+TIME, but limited to captioning as it is designed for captioning media. As with the SMIL implementations, SAMI can be used to add captioning to a video or audio in different languages based on the settings of the language of the client Windows system.

Windows media presentations, like slide shows, are typically a mix of XHTML+TIME delivered from a Web server, and streaming audio or video from Microsoft Media Services. To view presentations using HTML+TIME within the Windows Media Player, the media player must include a Web page.

Integration with Oracle

Integration of Windows Media Services and Oracle is accomplished with the interMedia data source plug-in for Windows Media Services (Figure 14.1). This plug-in allows the creation of mount points then publishing points (the first part of a path in a URL) with the interMedia plug-in.

Microsoft Windows Media Services with Oracle interMedia

Figure 14.1. Microsoft Windows Media Services with Oracle interMedia

The Microsoft streaming server can stream Windows media audio and video, JPEG, or MP3 files. Play lists are also recognized and can be represented as a directory, in which all the files in the directory are played, or in SMIL or WSX formats. Other formats could be added with plug-ins from third-party providers. Other formats that are supported by the Microsoft Media Player can be encapsulated in a Windows media file.

The Oracle plug-in will stream any format that can be streamed from the Microsoft streaming server. However, if the data is not in WMF, a pseudo–file name with the extension used by the requested format must be used (more on this later).

Creating a Mount Point

After installation of the Oracle interMedia data source plug-in for WMS, the creation of a mount point is done through the Microsoft Media Services management GUI. When you click on the “Show All Plug-in Categories” checkbox, the “Data Source” category appears in the category list. Selecting the Data Source category shows a screen similar to Figure 14.2.

Selecting the Oracle interMedia Custom Data Source

Figure 14.2. Selecting the Oracle interMedia Custom Data Source

The interMedia plug-in is enabled by right clicking the plug-in and selecting “Enable” from the list of options. Double clicking on the interMedia plug-in results in the window in Figure 14.3 being displayed.

Data Source Plug-in Mount Points

Figure 14.3. Data Source Plug-in Mount Points

Initially, no mount points are defined. When the Add or Properties button is pressed, the dialog in Figure 14.4 allows the user to define or change a mount point.

Adding an interMedia Data Source Mount Point

Figure 14.4. Adding an interMedia Data Source Mount Point

Creating a Publishing Point

After a mount point has been defined, a publishing point must be created. To start this process, “Publishing Point” is selected from the navigation menu on the left of the Microsoft Media Services administration screen. You must choose the advanced option when adding an interMedia publishing point. Figure 14.5 shows a publishing point being defined on an interMedia mount point.

Adding an interMedia Publishing Point

Figure 14.5. Adding an interMedia Publishing Point

If at any time an error occurs, for example, when connecting to the database while defining a publishing point, look at Windows event viewer for the error.

Now that a publishing point is defined, you can use a media PL/SQL procedure to select or compose the media (as in a text-based SMIL play list).

File Types Supported by the interMedia MMS Data Source Plug-in

Files delivered by the interMedia data source plug-in are, by default, Windows media files. Other MIME types can be used, but only if the requesting URL has an appropriate file extension. This is because the data source plug-in interface for MMS does not use the MIME type passed back from the database procedure. However, it should be programmed for compatibility with procedures written for the Real/Helix server, and since in the future the use of the MIME type in MMS may be supported.

For example, if a procedure has one input field, and the data referenced by the key is in MP3 format, the following URL will not work:

mms://mediaserver/orclPubPoint/1

However, if a filename is appended to the URL, which will not be passed or used by the database procedure, the data will be successfully delivered and played as the following example:

mms://mediaserver/orclPubPoint/1/dummy.mp3

Since many of the Web pages that deliver or expose streaming media are created dynamically, this is typically not a large problem to solve.

For creating appropriate file extensions for MMS-served files in a Web page, a function like the following can be used:

--
-- Return an appropriate file extension for a mime type
--
create or replace
function get_file_ext_from_mime(mime in varchar2)
        return varchar2 as
    ext varchar2(8) := '';
    typ varchar2(20);
    pos integer;
begin
   pos := instr(mime, '/'),
   if pos != 0 then
       ext := substr(mime, pos + 1);
       typ := substr(mime, 1, pos - 1);
   end if;
   if typ = 'audio' and ext = 'mpeg' then
       ext := 'mp3';
   end if;
   -- Skip x-ms part.
   pos := instr(ext, 'x-ms-'),
   if pos != 0 then
      ext := substr(ext, pos + 5);
   end if;

   return ext;
end;
/

Real/Helix Server

Background

The Real/Helix servers can stream just about any kind of data you like. The infrastructure is such that plug-ins can be added to stream just about any data format. These include:

  • Video formats

  • Audio formats

  • Image formats

  • Streaming text formats

  • SMIL

In general, the only time that an HTTP server is typically necessary is to deliver a metafile. The Real/Helix server includes HTTP services that can also generate needed metafiles (.ram and .rpm) using its ramgen facility. Ramgen takes parameters from the passed URL and constructs a ram or rpm file from these contents. These metafiles can include a list of media to play in sequence, but typically only include one item. As with the Microsoft Media Services, you can use your favorite Web application environment to deliver or construct metafiles. Unlike HTML+TIME, a SMIL presentation is interpreted by the player, and not the browser.

Integration with Oracle

Integration with Oracle is accomplished with a Real/Helix server file system plug-in. Using administration functions, or a text editor, a mount point is defined to access a database procedure through the plug-in. The plug-in connects to the database and returns the contents and MIME type of data from the database procedure. See Figure 14.6.

Real/Helix with Oracle interMedia

Figure 14.6. Real/Helix with Oracle interMedia

The kind of data delivered to the Real/Helix server by the Oracle procedure is only limited by what the streaming server is configured to handle. This includes script files like SMIL, RealText, and RealPix, as well as media binary data like images, audio, and video.

The database procedure can return anything from a discrete piece of media, like the image in row 1, or something more abstract, like the most viewed video to a SMIL presentation that includes elements based on any programmable selection criteria.

Note that it is possible to use the HTTP file system plug-in that comes with Real/Helix server to obtain streaming media from the database. As you know, interMedia data can be served from a URL. The disadvantage to this is it adds another level of indirection and would, in theory, add more overhead.

Creating a Mount Point

A Real/Helix server mount point defines the initial URL path for the streaming data URL. In the following example, it defines <PATH>.

RTSP://<SERVER>:<PORT>/<PATH>/.....

The rest of the URL is the file portion of the URL that can be used by procedures to pass parameters to the procedure.

The mount point can be created with the Real/Helix server management page, or it can be edited directly into the Real/Helix XML configuration file.

After installation, the Oracle Real/Helix configuration screen looks like Figure 14.7.

Creating an interMedia Mount Point for Real/Helix Server

Figure 14.7. Creating an interMedia Mount Point for Real/Helix Server

The above mount point results in the following XML section inserted into the Real/Helix configuration file in the <List Name="FSMount"> section.

    <List Name="Oracle Tunes">
        <Var Database="orcl10g"/>
        <Var MountPoint="/oratunes/"/>
        <Var Password="dGlnZXI="/>
        <Var ShortName="pn-oracle"/>
        <Var SQL="get_song"/>
        <Var Username="scott"/>
    </List>

If we were to add values for the “Header Cache Size,” “Lob Fetch Size,” and “Max Cached Connections” parameters, the configuration would look like the following sample.

<List Name="Oracle Tunes">
     <Var Database="orcl10g"/>
     <Var MountPoint="/oratunes/"/>
     <Var Password="dGlnZXI="/>
     <Var ShortName="pn-oracle"/>
     <Var SQL="get_song"/>
     <Var Username="scott"/>
     <Var HeaderCacheSize=î2048î/>
     <Var LobFetchSize=î32768î/>
     <Var MaxCachedConnections=î1î/>
 </List>

The extra optional parameters are:

  • The header cache size parameter controls how many bytes from the beginning of the file are cached in order to satisfy frequent requests for bytes located in the file header. The minimum value is 512 bytes, the maximum is 8,192 bytes, and the default value is 2,048 bytes. Up to three times the size of the header cache can be allocated per streaming file request.

  • The lob fetch size parameter controls how much data is retrieved from the database whenever new data is required. Fetching larger chunks of data in fewer requests is more efficient than fetching smaller chunks using more requests. The fetched data is cached in the plug-in to satisfy subsequent requests. The minimum value is 8,192 bytes and the maximum and default values are 32,768 bytes. Up to three times the size of the lob fetch size parameter can be allocated per streaming file request.

  • The max cached connections parameter controls the maximum number of connections to the Oracle database that will be maintained during periods of inactivity. A cached connection is used to decrease the time required to begin streaming a new request. The minimum value is 0, the maximum value is 10, and the default value is 1.

Creating an interMedia Streaming Server Plug-in Procedure

The database procedures for either the Real/Helix server or the Microsoft streaming server are the same. The only thing to be aware of is that they may or may not support the same data MIME types.

As you can see from the configurations, an Oracle interMedia streaming server mount point specifies a PL/SQL procedure. This is the procedure that is invoked. The procedure should have a call signature of the form:

<PROCEDURE_NAME>(<INPUT_PARAM1> in <TYPE>,    (optional)
                 <INPUT_PARAM2> in <TYPE>,    (optional)
                    :     :      :   :    :
                 <INPUT_PARAMn> in VARCHAR2, (optional)
                 MIMETYPE out VARCHAR2        (required)
                 DATA out BLOB or BFILE,      (required)
                 )

The <TYPE> parameter should be VARCHAR2, NUMBER, or integer. If you want to use other types, it is recommended that the input is converted to the type you need, for example, with the TO_DATE function in PL/SQL if you need to query with a DATE or DATE range. Below is an example of a somewhat generalized procedure.

create or replace
procedure getMedia(tbl IN VARCHAR2,
                   col IN VARCHAR2,
                   keycol IN VARCHAR2,
                   key IN VARCHAR2,
                   mimetype OUT VARCHAR2,
                   data OUT BLOB)
is
begin
   EXECUTE IMMEDIATE
     'SELECT t.'|| col || '.getMimeType(),' ||
            't.'|| col || '.getContent()' ||
     ' INTO :mime, :blob' ||
     ' FROM ' || tbl || ' t ' ||
     ' WHERE t.' || keycol || ' = ''' || key || ''''
   INTO mimetype, data;
end;
/

The above procedure would take a URL of the following form:

rtsp://<SERVER>:<PORT>/<MOUNTPOINT>/<TABLE>/<COLUMN>/
<KEYCOL>/<KEY>

For example, for a mount point called dbpoint with a table name vidtbl with two columns and an ID of type INTEGER and VIDEO of type ORDVideo, the following URL would return the video in column 1 in this table for the user specified in the mount point:

rtsp://yourserver/dbpoint/vidtbl/video/id/1

This will play the implied video in the database defined by dbpoint mount point, in the vidtbl table from the video column where the ID column is one.

These procedures can return any data that is supported by a Real/Helix server and the format plug-ins that are installed. Along with binary formats, this returned data can also include text formats like SMIL, RealText, and RealPix. When returning text formats, it is advisable to cast the text into a known character set when being placed into the BLOB.

For example, the following procedure will return a play list for all the songs by a particular band in the songs table, or a particular audio depending on the “type.”

procedure PlayList(type IN VARCHAR2,
                   key IN VARCHAR2,
                   mimetype OUT VARCHAR2,
                   data OUT BLOB)
is
  s VARCHAR2(4096);
  tempBLOB BLOB;
  bad_type exception;
  CURSOR band_cursor IS
       select id from songs where band = key;
begin
   if (UPPER(type) = 'SMIL') then
     s := '<smil
           xmlns="http://www.w3.org/2001/SMIL20/Language">
          <body><seq>';
     FOR row_rec in band_cursor
     LOOP
       s := s || '
         <audio src="../audio/' || row_rec.id || '" />';
     END LOOP;
     s := s || '</seq></body></smil>';
     DBMS_LOB.CREATETEMPORARY( tempBLOB, TRUE,
                               DBMS_LOB.SESSION );
     DBMS_LOB.WRITEAPPEND(tempBLOB, length(s),
         utl_raw.cast_to_raw(convert(s,'WE8ISO8859P1')));
     data := tempBlob;
     mimetype := 'application/smil';
  elsif (UPPER(type) = 'AUDIO') then
     select t.audio.getContent(), t.audio.getMimetype()
       into data, mimetype
       from songs t where t.id = key;
  else
     raise bad_type;
  end if;
end;
/

What should be noted, as highlighted, is that when returning a character-based script, it should be cast to a character set recognized by the media server. This procedure will use a URL similar to the following for a play list:

rtsp://server.com/oracleMountPoint/smil/The%20Loonies

The playlist will play all the songs from a particular band in the songs table.

For a particular audio:

rtsp://server.com/oracleMountPoint/audio/3

Summary

interMedia supports streaming technologies from both Microsoft and Real/ Helix with a custom plug-in.

Alternatively, it is possible to support these servers by providing a URL that represents streaming data stored in a database. The server would refer to the URL, and an application, perhaps a servlet, would query the database for the streaming data and deliver it to the streaming server, via HTTP, for delivery to the streaming client.

Other streaming technologies can be supported by writing a custom plug-in, or by using the alternative approach.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.177.86