Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CHAPTER 1
Introduction
1.1 Introduction to Smooth Streaming
Smooth Streaming is a relatively new way to stream videos at an adaptive rate giving viewers
the best possible viewing experience. Smooth streaming can determine the available
bandwidth and select the appropriate bit-rate to display video.
Smooth Streaming delivers small fragments of a video at a time and verifies that each has
arrived at the destination within the appropriate time and played back at the expected quality.
If a fragment of video is not up to the expected quality then the next one will be delivered at
a slightly lower bit-rate. This process uses HTTP protocol.
Smooth Streaming dynamically detects local bandwidth and CPU conditions and switches in
real time the quality of the media file that the player receives. It is a combination of
progressive HTTP download with bandwidth conscious media delivery.
The Smooth Streaming technology works on the principle of client-server architecture and is
formed by two different parts:
The purpose and requirement of an URLBuilder comes at the client side of the Smooth
Streaming technology. In Smooth Streaming technology the requested file is not delivered to
the client as one large block but instead it is divided in the form of small chunks each with a
minimum duration of 2 to 3 seconds and can be up to 10 second maximum duration
depending on the architecture. There will be different copies of the same file each with equal
number of chunks which all together make up one whole file that was requested with
different bitrates. Different bitrates represent various copies of the requested file one of them
being the best quality other copy of medium quality and least quality file.
In order to download a file we need to download all the chunks corresponding to that file
sequentially and separately. These chunks are identified by the client Manifest file, which has
information of that particular file to be downloaded. The information carried by the Manifest
file is
• Chunk Number
• Bitrate
Suppose we have a smooth streaming media file with 3 different qualities and each quality
having 10 chunks representing one complete media file then we will have 10 different URL’s
representing 10 chunks for a particular media quality file.
An URLBuilder is used to generate URL for each chunk for all quality files available for the
requested file by the customer. The information that the URLBuilder uses to generate URL
for a particular chunk is obtained form the client Manifest file which hold complete
information about the requested file. This is the first piece of information that the client
receives from the server when it request for a file.
Hence URLBuilder becomes an important aspect of Smooth Streaming client without which
URL for each chunk cannot be generated and a file can never be downloaded using Smooth
Streaming technology.
Chapter 2
Requirement Analysis
The requirement analysis for the development of URLBuilder for Smooth Streaming consists
of:
User requirements
Functional requirements
Software requirements
Hardware requirements
User Requirements
• User needs to download a file depending on the available bitrates which would
suite customer bandwidth availability. A particular file has different copies based
on different quality. Depending on the customer bandwidth a particular quality
(high quality, average quality or least available quality) file must be downloaded.
• Proper URL must be generated corresponding to the bitrates that the available
bandwidth of the customer would easily support. Since the file has different copies
representing different quality the customer must be able to download a copy of the file
irrespective of the quality that suites his bandwidth criteria.
• Generated URL must be stored in a sequential manner corresponding to bitrates and
chunk numbers. As each copy of the file is divided into chunks URL must be generated to
represent each chunk for a particular quality that suites customer bandwidth and each chunk
must be downloaded as per its chunk number to avoid loss of chunk.
• The process of downloading and generation of URL must be quick to avoid
latency in further stages. As each chunk vary from 2 to 10 second depending on
architecture, number of chunks depend on duration of the file. Hence URL for
each chunk must be generated at quick pace to allow continuous download in
order to avoid/ minimize buffer time.
Software Requirements
2.3.1 Languages
• C++
2.3.2 Platform
• Linux
2.3.3 Tools
• Cross compiler.
Hardware Requirements
• STB
Chapter 3
System Analysis
3.1 INTRODUCTION
Smooth Streaming dynamically detects local bandwidth and CPU conditions and seamlessly
switches, in near real time, the video quality of a media file that a player receives. Consumers
with high-bandwidth connections can experience high definition (HD) quality streaming
while others with lower bandwidth speeds receive the appropriate stream for their
connectivity, allowing consumers across the board to enjoy a compelling, uninterrupted
streaming experience and alleviating the need for media companies to cater to the lowest
common denominator quality level within their audience base.
This enables companies to boost brand awareness and advertising revenues by extending
average viewing times through higher quality true HD (resolution greater than 720p)
experiences. They can also benefit from unprecedented network scalability using distributed
HTTP-based Web servers and offer better quality to more customers.
When a client requests a specific source time segment from the server, the server
dynamically finds the appropriate Fragment box within the contiguous file and sends it over
the wire as a standalone file, thus ensuring full cacheability downstream.
In other words, with Smooth Streaming, file chunks are created virtually upon client request,
but the actual video is stored on disk as a single full-length file per encoded bit rate. This
offers tremendous file-management benefits.
• MP4 is based on a widely used standard, making 3rd party adoption and support
more straightforward.
• MP4 is architected with H.264 video codec support .
• MP4 is designed to natively support payload fragmentation within the file.
• Text streams
Chapter 4
System Design
This chapter presents an architectural design of the URLBuilder for Smooth Streaming and
explains the modules used in the development.
9
8
1
2
Manifest
3 HTTP
Downloader
Downloader Queue
4
SERVER
MP4
MP4
fragmented
fragmented
Parser (audio)
Parser (video)
URLBuilder
Audio
.::::::::::::Sync:::::::::::::Video
Decoder Decoder
Manifest
Parser
CLIENT
1: client requests for a file; 2: server responds by sending the URL of the Manifest file; 3: Manifest Downloader
requests for Manifest file; 4: server responds by sending the Manifest file; 5: the downloaded Manifest file is
wafer sent to Manifest Parser; 6: the Parsed file is sent to URLBuilder; 7: URL of the chunk is sent to HTTP
Downloader; 8: HTTP Downloader requests for the chunk; 9: server responds by sending the chunk
Figure depicts the general block diagram of Smooth Streaming client architecture. It works as
a client-server architecture.
In Smooth Streaming technology a single file has multiple copies based on quality i.e. one
copy for best quality video, one for average quality, one for least quality video and so on.
These multiple copies of a file are stored virtually and identified by a Manifest file. Each
copy is further divided into small fragments called chunk each with minimum of 2 second
duration and maximum of 10 second depending on the architecture.
Following are the steps followed in order to download a Smooth Streaming file:
Client requests for a file from the server.
Server checks for the file if it has it, sends a URL as response to the client. This
URL tells the client where it can find the Manifest file for the requested media file.
Manifest downloader picks up this URL and sends a request to the server asking for
the required Manifest file.
The server responds by sending the requested Manifest file to the Manifest
downloader.
The Manifest file has all the information of the requested file such as
Different qualities of the requested file available
Available bitrates
Total duration of the file
Number of chunks making up the file
Which encoder is used to encode the file
Version of the xml file
Duration of each chunk
This file is taken up by the Manifest Parser, stores it in some location in the
memory and parses this file and creates a tree structure so that the information can
be accessed easily.
Using the information available from the parsed file URLBuilder build a URL of
the first chunk and gives it to the HTTP downloader.
The first chunk given to the HTTP downloader is always from the low quality file.
This is because the system has to analyze the network bandwidth, network status
and CPU conditions. Based on the analysis the system decides which quality file it
can go to download the next chunk.
The HTTP downloader requests the server for the chunk whose URL is obtained
from URLBuilder.
The server responds by sending the requested chunk to the HTTP downloader.
By the time the chunk is downloaded the system uses the analyzed output to build
the URL for the next chunk and sends it to the HTTP downloader. In the mean time
the HTTP downloader checks the status of the queue. If the queue is empty the
downloaded chunk is placed as the first element in the queue if the queue is not
empty it appends the chunk to end of the queue.
The queue holds the downloaded chunk according to the chunk number and its size
may vary depending on the architecture but has a minimum capacity of holding 5
chunks.
Each chunk based on its number and the format (audio or video) is given to the
corresponding MP4 Fragment Parser (audio or video) and based on the timestamp
obtained from the parser from each chunk it is sent to corresponding decoder to
obtain synchronization.
Manifest Manifest
Download URLBuilder
Parser
Smooth streaming uses XML based manifest files to describe media parameters. Two sets of
manifests are used, one for server ingest and the other for the client. The Smooth Streaming
Wire/File Format specification defines the MP4 box structure as well as the manifest XML
language. As the manifests are based on XML, they are highly extensible.
The manifest enables support for the following
Text streams
Multi-language audio tracks
Alternate video and audio tracks (for example, multiple camera angles,
director's commentary, etc.)
Multiple hardware profiles (for example, a bit rate targeted at different
playback devices)
Script commands, markers/chapters, captions
URL obfuscation
Live encoding and streaming
Manifest tells the client which codec’s were used to compress the content, which bit rates and
resolutions are available, and a list of the available chunks and format of a client manifest file
is as shown below.
The manifest file consists of various tags the explanation to few of the tags are as given
below:
HTTP requests
An HTTP request is made by a client, to a named host, which is located on a server. The aim
of the request is to access a resource on the server. To make the request, the client uses
components of a URL (Uniform Resource Locator), which includes the information needed
to access the resource.
• A correctly composed HTTP request contains the following elements:
• A request line.
• A series of HTTP headers, or header fields.
• A message body, if needed.
Each HTTP header is followed by a carriage return line feed (CRLF). After the last of the
HTTP headers, an additional CRLF is used (to give an empty line), and then any message
body begins.
GET /Manifest.xml HTTP/1.1 Request Line
Date: Thu, 28 Apr 2011 10:14:49 GMT
Connection: close General Headers
Host: 10.10.40.16
Accept: text/xml Request Headers
User-Agent: Mozilla/4.0 (compatible: MSIE 5.0; Windows NT 5.1)
HTTP
REQUEST
Entity Headers
Message Body
START
Put Request
Put the request to the Server. A method i.e.“GET”
“POST” etc is used to begin request. URL of the file
is only the part path
YES
Is the
Request
status A
already issued
IDLE
NO
Set status line
If the status line is not in IDLE state then the status
line is set to request started
Send body
Check for body data in the request message, if it is
there than send the body
NO
Valid
YES
Connect to Server
Handles the socket connection, issuing of
requests and managing responses.
A
C
Update the connection
Regularly check the connection established
Pump
Called regularly to service outstanding
requests.
Connection close
Close connection, discarding any pending
requests
STOP
HTTP responses
An HTTP response is made by a server to a client. The aim of the response is to provide the
client with the resource it requested, or inform the client that the action it requested has been
carried out; or else to inform the client that an error occurred in processing its request.
An HTTP response contains:
• A status line.
• A series of HTTP headers, or header fields.
• A message body, which is usually needed.
As in a request message, each HTTP header is followed by a carriage return line feed
(CRLF). After the last of the HTTP headers, an additional CRLF is used (to give an empty
line), and then the message body begins.
Server: Apache/2.2.3
Accept-Ranges: bytes Response Headers
<html>
<head>
<title>Welcome to this site</title>
</head>
<body> Message Body
<p>This site is under construction</p>
</body>
</html>
START
B
Get headers
Retrieve a header from the request
returns 0 if not present
Is YES
<100 A
or C
>999
NO
Get content length
If the status line is greater than 100
and less than 999 then get the length
of the content requested
Get location
Get the location where the requested
content is stored
Get reason
Get the HTTP response reason string
Pump
Pump some data in for processing.
Returns the number of bytes used
YES
Request
B s
waiting
NO
Connection close
A Tell in response that connection has
closed
STOP
The response obtained for the first request is an example for GOOD request while the
response got for the second request is an example for BAD request.
In an event-driven approach for processing XML data, a parser reads the data and notifies
specialized handlers that undertake the desired actions. Note that here the term event-driven
means a process that calls specific handlers when the contents of the XML document are
encountered.
The various XML parser implementations differ in their application program interfaces. For
example, one parser could notify a handler of the start of an element, passing it only the
name of the element and then requiring another call for the handling of attributes. Another
parser could notify a handler when it finds the same start-element tag and pass it not only the
name of the element, but a list of the attributes and values of that element.
Another important difference between XML parsers is in which representation they use to
pass data from the parser to the application: e.g. one parser could use an STL list of strings,
while another could use a specially made class to hold attributes and values. The methods for
handling a start-element tag with each approach would be very different and would certainly
affect how you program them.
START
Write to a file
Write the contents of the opened file
one string at a time
NO All
character
s
obtained
Obtain next
character
YES
YES
STOP
4.1.3 URLBuilder
It generates the URL based on the information that is available from the parsed Manifest file.
The URL will contain the following information
• XML version
• Number of Chunks
• Bitrate
• Encoding type
• Duration of the file
• Type of information (Audio or Video)
Start
Z
NOT EMPTY
Chec Wait for the
k consumer to
Y
Buffe consume the data
r
EMPTY
NO
Is there a
A
URL
YES
TRUE
Request
is from
X the
beginning
FALSE
C
C
Dept of PG X
Studies in CE&A, NIE, Mysore. 27
URLBuilder for Smooth Streaming 2010-11
Build URL
Builds into pointer a URL with the base path
FALSE
No
P more
chunks
Z TRUE
A
Exit from reader thread
Data completely read
Stop
An example showing the format of the URL generated from the client Manifest file is as
shown below
http://10.10.40.16/Manifest.ism/QualityLevels(3450000)/Fragments(video= 610275114)
The URLBuilder gets the parsed Manifest file as input. This file has all the information
regarding the file to be downloaded. The URLBuilder uses the information obtained from the
previous stage to build the URL.
The URLBuilder gets the format of the URL to be build for each chunk from the parsed
client Manifest file.
Chapter 5
System Implementation
This chapter describes the development of URLBuilder for Smooth Streaming through the
languages used. This chapter also explains the pseudo code for subroutines used to
implement in each of the modules. The modules have been implemented using C++
language.
void connect()
Don't need to call connect() explicitly as issuing a request will call it automatically if
needed. But it could block (for name lookup etc), so you might prefer to call it in advance.
void close()
It closes the connection, discarding any pending requests.
void pump()
Update the connection (non-blocking) Just keep calling this regularly to service
outstanding requests. As responses are received, the callbacks will be invoked.
void request( const char* method, const char* url, const char* headers[], const
unsigned char* body, int bodysize )
High-level request interface. Issues a request.
Method - "GET", "POST" etc...
url - eg "/Manifest.xml"
headers - array of name/value pairs, terminated by a null-ptr
body, bodysize - specify body data of request (eg values for a form)
void endheaders()
Indicate that your are finished adding headers and the request can be issued.
7. parseString(xmlDoc,"XYZ ")
Pseudo code of some of the important functions used for parsing are as shown below
To manipulate the data contained inside the XML file, the first operation is to get an instance
of the class XMLNode that is representing the XML file in memory.
This function is used to create the top node of the Tree structure and return the root node of
type static XMLNode.
This will create an object called xMainNode that represents the first tag named “XYZ” found
inside the XML document. This object is the top of tree structure representing the XML file
in memory.
XMLNode xNode=xMainNode.getChildNode("Header");
This function is used to append header information to the first tag obtained from the previous
function. The header information may contain the tag number, tag length etc.
This command creates a new object called xNode that represents the "Header" tag inside the
first tag and returns the address of the first tag of type XMLNode.
5.3 URLBuilder
Here we have only one class namely, URLBuilder and it’s methods are as follows :
URLBuilder()
~URLBuilder()
struct Stream *openstream(char *url, int buflen, int flags, struct Stream *sstream )
void closestream()
int consumestream(int lg, unsigned char **pbuf, struct ChunkBuf **pattr)
bool pump ( void )
int Duration(void)
void setcallbacks(ResponseBegin_CB begincb, ResponseData_CB datacb, ResponseComplete_CB
completecb, void *UserData)
int build_url(char *pdest, char *pbase, char *purl, int maxlen)
static void *reader_thread(void *p)
struct stream openstream (char *url, int buflen, int flags, stream *sstream )
This function opens a new adaptative stream for reading and has three input arguments. The
first argument has an address of the URL requested by the user, second argument is an
integer variable whose initial value is assumed to be zero, the third argument specifies what
has to be done with the supplied URL i.e. just open the contents in the URL, open it quickly
and completely and so on and the final argument is the address of the stream structure which
has the information about the stream.
This will open the given URL, read the appropriate playlists (if required) and allocate all
internal buffers. The function will return as soon as stream reading has been launched (no
data yet).buflen indicates the desired buffer size in seconds; if 0, the library will decide the
size. Returns a pointer to the allocated Stream struct or NULL on error. The members of the
stream structure as shown
unsigned long maxbitrate
unsigned long minbitrate
unsigned long duration
unsigned long no_chunks
Maxbitrate holds the maximum bitrate obtained from client Manifest file where as minbitrate
holds the minimum bitrate, duration gives a value equivalent to (Total duration/Total number
of chunks) where total duration and total number of chunks gives maximum duration of the
file and maximum chunks available and no_chunks has Total number of chunks obtained
from client Manifest file
closestream()
It will close the given adaptative stream, kills reading threads and frees buffers.
This function takes three arguments as input, first argument is of integer type and has a
default value equivalent to Play size. The second argument is a double pointer of unsigned
character type and holds an address of a unsigned character pointer. The final argument is a
pointer to a structure Chunk.
The members of structure Chunk are as shown,
unsigned long lg
unsigned long received
unsigned long consumed
unsigned long seq
unsigned long pos
int br
int netbr
unsigned char *pdata
This structure has seven members, member lg represents value equal to chunk length,
member received represents number of received bytes, consumed represents number of
consumed bytes, members seq and pos represents sequence number and position of file from
the beginning in milliseconds respectively, members br and netbr represents value of bitrate
of a particular quality file and content of that bitrate respectively final member holds the
address of the actual chunk.
This function returns (into pbuf) a pointer where the desired data or less is present. Actual
length of piece is returned as function result. More information about the provided data can
be found in structure whose address is stored in *pattr (unless pattr is NULL). This function
never blocks. If there is nothing available, it returns 0. If the file is finished or if there was an
error, returns -1.
bool pump(void)
pumps the data to the consumer thread
int Duration(void)
Gives total duration of the stream and return a integer value equivalent to total
duration divided by 1000.
Chapter 6
Bibliography
[1] Alex Zambelli, Media Technology Evangelist” IIS Smooth Streaming Technical
Overview”, March 2009.
[2] Docum Tak Cheung Lam and Jianxun Jason Dingent “XML Document Parsing:
Operational and Performance Characteristics”, October 2008
[3] http://www.alcatel-lucent.com
[4] http://www.xml.com/