<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<base href="https://wiki.asterisk.org/wiki" />
<title>Message Title</title>
<style type="text/css">@media only screen and (max-device-width: 480px) {.mobile-only {
width: auto !important;
height: auto !important;
overflow: visible !important;
line-height: normal !important;
font-size: inherit !important;
mso-hide: all;
}
.desktop-only {
display: none !important;
}
/* iPhone 3GS fix for unwanted 20px right margin */
body { min-width: 100% !important; padding: 0; margin: 0; }
#center-content-table { max-width: none; !important; }
#header-pattern-container { padding: 10px 10px 10px 10px !important; line-height: 20px !important; }
#header-avatar-image-container { padding-right: 8px !important; }
#email-content-container { padding: 0 !important; }
.mobile-expand { border-radius: 0 !important; border-left: 0 !important; border-right: 0 !important; padding-left: 26px !important;}
.mobile-resize-text { font-size: 16px !important; line-height: 22px !important; }
#page-title-pattern-header { font-size: 20px !important; line-height: 28px !important; }
#page-title-pattern-icon-image-container-cell { padding-top: 7px !important; }
#inline-user-pattern { display: block !important; }
#inline-user-pattern-avatar { padding-top: 3px !important; }
.contextual-area-pattern { border-bottom: 1px solid #ccc !important; padding: 15px 10px 0 10px !important;}
.users-involved-pattern-column-table { width: 100% !important; }
.users-involved-pattern-avatar-table-cell { padding: 3px 5px 5px 0 !important; }
.users-involved-pattern-column-container { padding-right: 0 !important; }
.contextual-excerpt-pattern, #users-involved-pattern { border: 0 !important; }
/** Aui Typography upsized for mobile **/
#content-excerpt-pattern-container, #contextual-excerpt-pattern-text-container { font-size: 16px !important; line-height: 22px !important; }
#content-excerpt-pattern-container h1, #contextual-excerpt-pattern-text-container h1 { font-size: 24px !important; line-height: 28px !important; }
#content-excerpt-pattern-container h2, #contextual-excerpt-pattern-text-container h2 { font-size: 20px !important; line-height: 28px !important; }
#content-excerpt-pattern-container h3, #contextual-excerpt-pattern-text-container h3 { font-size: 18px !important; line-height: 24px !important; }
#content-excerpt-pattern-container h4, #contextual-excerpt-pattern-text-container h4 { font-size: 16px !important; line-height: 22px !important; }
#content-excerpt-pattern-container h5, #contextual-excerpt-pattern-text-container h5 { font-size: 14px !important; line-height: 20px !important; }
#content-excerpt-pattern-container h6, #contextual-excerpt-pattern-text-container h6 { font-size: 14px !important; line-height: 20px !important; }
.user-mention { line-height: 18px !important; }
/** Aui Typography end **/
/* Show appropriate footer logo on mobile, display links vertically */
#footer-pattern { padding: 15px 10px !important; }
#footer-pattern-logo-desktop-container { padding: 0 !important; }
#footer-pattern-logo-desktop { width: 0 !important; height: 0 !important; }
#footer-pattern-logo-mobile {
padding-top: 10px !important;
width: 30px !important;
height: 27px !important;
display: inline !important;
}
#footer-pattern-text {
display: block !important;
}
#footer-pattern-links-container { line-height: 0 !important;}
.footer-pattern-links.mobile-resize-text,
.footer-pattern-links.mobile-resize-text,
#footer-pattern-text.mobile-resize-text,
#footer-pattern-links-container.no-footer-links {
font-size: 14px !important;
line-height: 20px !important;
}
.footer-link { display: block !important; }
#footer-pattern-links-container table { display: inline-block !important; float: none !important; }
#footer-pattern-links-container, #footer-pattern-text { text-align: center !important; }
#footer-pattern-links { padding-bottom: 5px !important; }
/** Team Calendar overrides, these should be removed when notifications are updated in Team Calendars. For now CSS
overrides are being used because the structure of the content can't change without rereleasing the plugin */
.mail-calendar-container .day-header + table tr td:first-child {
vertical-align: top !important;
padding-top: 5px !important;
}}
@media (min-width: 900px) {#center-content-table { width: 900px; }}
@media all {#outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */
/* Prevent Webkit and Windows Mobile platforms from changing default font sizes.*/
body{-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;}
.ExternalClass {width:100%;} /* Force Hotmail to display emails at full width */
#background-table {margin:0; padding:0; width:100% !important; }
/* Needed to override highlighting on date and time links in iOS */
.grey a {color: #707070; text-decoration: none; }/* These styles are appended to the head element of a notification in order to prevent Apple Mail and similar
clients from underlining the due dates with a blue hyperlink */
/* a lozenge outside an inline task should always be #333, lozenges inside an inline task should be
colored according to their upcoming due dates, a completed task date lozenge or deleted task date
lozenge should always be #707070 */
.date-time-lozenge a {color: #333333; text-decoration: none; }
.inline-task-text-container .date-time-lozenge.date-upcoming a {color: #DF6F00; text-decoration: none; }
.inline-task-text-container .date-time-lozenge.date-past a {color: #D04437; text-decoration: none; }
.inline-task-text-container.content-deleted-color .date-time-lozenge a,
.inline-task-text-container.checked .date-time-lozenge a {
color: #707070; text-decoration: none;
}}
</style>
</head>
<body>
<table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; background-color: #f5f5f5">
<tbody>
<tr>
<td id="header-pattern-container" style="padding: 0px; border-collapse: collapse; padding: 10px 20px">
<table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td id="header-avatar-image-container" valign="top" style="padding: 0px; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 9px"><a href="https://wiki.asterisk.org/wiki/display/~jcolp?src=email" style="color: #3b73af; text-decoration: none"><img id="header-avatar-image" class="image_fix" src="cid:avatar_68773ae9e6f3a25da47088e9dd96d1b8" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top" /></a></td>
<td id="header-text-container" valign="middle" style="padding: 0px; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px">Joshua Colp <strong>created</strong> a page</td>
</tr>
</tbody>
</table> </td>
</tr>
<!-- End Header pattern -->
<tr>
<td id="email-content-container" style="padding: 0px; border-collapse: collapse; padding: 0 20px">
<table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; border-spacing: 0; border-collapse: separate">
<tbody>
<tr>
<td class="email-content-rounded-top mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 15px; background-color: #fff; border-left: 1px solid #ccc; border-top: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px"> </td>
</tr>
<tr>
<td class="email-content-main mobile-expand" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 15px 16px; background-color: #fff">
<table id="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td id="page-title-pattern-icon-image-container" valign="top" style="padding: 0px; border-collapse: collapse; width: 16px; vertical-align: top">
<table cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td id="page-title-pattern-icon-image-container-cell" style="padding: 0px; border-collapse: collapse; width: 16px; padding: 9px 8px 0px 0px; mso-text-raise: 5px; mso-line-height-rule: exactly"><a href="https://wiki.asterisk.org/wiki/display/AST/Stream+Support?src=email" title="page icon" style="vertical-align: top;; color: #3b73af; text-decoration: none"><img style="vertical-align: top; display: block;" src="cid:page-icon" alt="page icon" title="page icon" height="16" width="16" border="0" /></a></td>
</tr>
</tbody>
</table> </td>
<td style="vertical-align: top;; padding: 0px; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" id="page-title-pattern-header-container"><span id="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"><a href="https://wiki.asterisk.org/wiki/display/AST/Stream+Support?src=email" title="Stream Support" style="color: #3b73af; text-decoration: none">Stream Support</a></span></td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td class="email-content-main mobile-expand" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 15px 16px; background-color: #fff">
<table class="content-excerpt-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px">
<tbody>
<tr>
<td class="content-excerpt-pattern-container mobile-resize-text " style="padding: 0px; border-collapse: collapse; padding: 0 0 0 24px"> <h1 id="StreamSupport-Streams!ALLTHESTREAMS!" style="margin: 10px 0 0 0; margin-top: 0; font-size: 24px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0; margin-top: 0">Streams! ALL THE STREAMS!</h1> <p style="margin: 10px 0 0 0">Let's start with talking about what streams are. Streams at their core are a flow of media. They can be unidirectional or bidirectional and are comprised of media formats. The media formats also contain a type. To simplify things streams only carry a single type of media. Streams can also carry an identifier in the form of a name.</p> <p style="margin: 10px 0 0 0">Asterisk currently has no explicit interface for streams and simply has a single pipe that frames are written to and read from. The negotiated formats are scoped to the entire channel as a result. Interfaces that need to manipulate media have injected themselves into this single pipe and have to take special care to not manipulate frames they do not need to. This pipe also carries control frames and other signaling related operations. This means that there is a single very loose stream for each type of media.</p> <h1 id="StreamSupport-Sowhatdoweneedtobeabletodoforstreams?" style="margin: 10px 0 0 0; font-size: 24px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">So what do we need to be able to do for streams?</h1>
<ul style="margin: 10px 0 0 0">
<li>We need to be able to know what streams are present</li>
<li>We need to be able to know the details about the streams</li>
<li>We need to be able to add, remove, and change a stream (or streams)</li>
<li>We need to be able to know that a frame has come from a specific stream</li>
<li>We need to be able to send a frame and have it go out a specific stream</li>
<li>We need to be able to negotiate two streams</li>
<li>We need to be able to exchange media between two streams</li>
</ul> <p style="margin: 10px 0 0 0">All of this needs to be present and existing functionality needs to continue to work as expected.</p> <h1 id="StreamSupport-Butwhataboutallthemediastuffthatexistsnow?" style="margin: 10px 0 0 0; font-size: 24px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">But what about all the media stuff that exists now?</h1> <p style="margin: 10px 0 0 0">This is the complicated part. Let's take a look at impacted functionality.</p> <h2 id="StreamSupport-Audiohooks" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Audiohooks</h2> <p style="margin: 10px 0 0 0">As they exist now audiohooks hook themselves into every audio frame that is passing through a channel. This works since there is only ever a single 'virtual' stream.</p> <h4 id="StreamSupport-InitialSupport" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Initial Support</h4> <p style="margin: 10px 0 0 0">Audiohooks will only hook themselves into the first audio stream on a channel.</p> <h4 id="StreamSupport-LongTerm" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Long Term</h4> <p style="margin: 10px 0 0 0">Audiohooks will be expanded to allow selecting the stream that it is to be placed on. If no stream is specified it will select the first.</p> <h2 id="StreamSupport-Framehooks" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Framehooks</h2> <p style="margin: 10px 0 0 0">Framehooks currently are invoked for every frame passing through a channel.</p> <h4 id="StreamSupport-InitialSupport.1" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Initial Support</h4> <p style="margin: 10px 0 0 0">Framehooks will only hook themselves into control frames and the first stream of each type. This mirrors the current behavior.</p> <h4 id="StreamSupport-LongTerm.1" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Long Term</h4> <p style="margin: 10px 0 0 0">Framehooks will allow specifying what streams are to be hooked into. The callback will provide information about what stream a frame is in relation to.</p> <h2 id="StreamSupport-Translation" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Translation</h2> <p style="margin: 10px 0 0 0">Translation currently only reliably creates a translation path for the audio portion of a channel.</p> <h4 id="StreamSupport-InitialSupport.2" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Initial Support</h4> <p style="margin: 10px 0 0 0">The code will only create a translation path for the first audio stream.</p> <h4 id="StreamSupport-MiddleTerm" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Middle Term</h4> <p style="margin: 10px 0 0 0">Each audio stream will create an appropriate translation path.</p> <h2 id="StreamSupport-FilePlayback/Recording" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">File Playback/Recording</h2> <p style="margin: 10px 0 0 0">The file API is one of the oldest things in Asterisk. Given a set of formats on the channel it will decide what file (without a container) will be played.</p> <h4 id="StreamSupport-InitialSupport.3" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Initial Support</h4> <p style="margin: 10px 0 0 0">The code will use the formats on the first audio and video stream to determine what file should be used for playback. It will be played out to those streams.</p> <h4 id="StreamSupport-LongTerm.2" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Long Term</h4> <p style="margin: 10px 0 0 0">A container format will be implemented which supports multiple streams within itself. Based on the characteristics of the streams the best file will be chosen and played back. Each stream within the container will be played out. For existing files without a container the initial support logic will be used.</p> <h2 id="StreamSupport-Bridging" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Bridging</h2> <h4 id="StreamSupport-InitialSupport.4" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Initial Support</h4> <p style="margin: 10px 0 0 0">The first stream of each type will be connected. This mirrors the existing behavior. While it does not utilize streams (yet) it ensures that existing behavior works.</p> <h4 id="StreamSupport-MiddleTerm.1" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Middle Term</h4> <p style="margin: 10px 0 0 0"> <span class="inline-comment-marker" data-ref="76c79cc8-e3a7-46a1-a9d9-87260c6f60b5">Each stream in order of type from each channel is connected. If stream changes are required (adding/removing) then they are initiated and the result taken into account. If a translation path is required it is set up for audio.</span> </p> <h2 id="StreamSupport-OlderChannelDrivers" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Older Channel Drivers</h2> <p style="margin: 10px 0 0 0">The older channel drivers should have a default stream representation based on the formats on the channel. If audio and video is negotiated, then there should be an audio and video stream and it should be transparent to the channel driver. Ideally _no_ changes would be required to the channel drivers. Any requests to change, manipulate, add, or remove streams will result in an error and the operation failing.</p> <h1 id="StreamSupport-SoHowDoWeGetThere?" style="margin: 10px 0 0 0; font-size: 24px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">So How Do We Get There?</h1> <p style="margin: 10px 0 0 0">By not burning down what already exists so we don't go crazy updating everything so it all works again.</p> <h2 id="StreamSupport-Legacy" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Legacy</h2> <p style="margin: 10px 0 0 0">The below design attempts to strike the balance between implementing the functionality we need in streams while maintaining the full media related APIs that exist today. It does this by bringing into code what logically exists within the 'virtual' streams.The API refers to these as default streams. Default streams are the first stream present on a channel for each media type. This mirrors the behavior of the 'virtual' streams present in the original single pipe. All consumers of the existing media related APIs deal with these default streams without knowing it. The internal implementation of each core API is changed to use the default stream that is applicable.</p> <h2 id="StreamSupport-CoreConcepts" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Core Concepts</h2> <p style="margin: 10px 0 0 0">As part of the addition of streams support two new core concepts have been added: streams and stream topologies.</p> <p style="margin: 10px 0 0 0">Streams are a representation of a flow of media and contain the details described at the beginning of this wiki page.</p> <p style="margin: 10px 0 0 0">Stream topologies are an ordered list of associated media streams. </p> <h2 id="StreamSupport-stream.h" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">stream.h</h2> <p style="margin: 10px 0 0 0">This file holds the public stream API. This covers functionality for inspection by components in the system (such as applications), stream creation, stream manipulation, topology creation, and topology manipulation.</p>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0">/*!
* \brief Forward declaration for a stream, as it is opaque
*/
struct ast_stream;
/*!
* \brief The topology of a set of streams
*/
struct ast_stream_topology;
enum ast_stream_state {
/*!
* \brief Set when the stream has been removed
*/
AST_STREAM_STATE_REMOVED = 0,
/*!
* \brief Set when the stream is sending and receiving media
*/
AST_STREAM_STATE_SENDRECV,
/*!
* \brief Set when the stream is sending media only
*/
AST_STREAM_STATE_SENDONLY,
/*!
* \brief Set when the stream is receiving media only
*/
AST_STREAM_STATE_RECVONLY,
/*!
* \brief Set when the stream is not sending OR receiving media
*/
AST_STREAM_STATE_INACTIVE,
};
/*!
* \brief Create a new media stream representation
*
* \param name A name for the stream
* \param type The media type the stream is handling
*
* \retval non-NULL success
* \retval NULL failure
*
* \note This is NOT an AO2 object and has no locking. It is expected that a higher level object provides protection.
*
* \note The stream will default to an inactive state until changed.
*/
struct ast_stream *ast_stream_create(const char *name, enum ast_media_type type);
/*!
* \brief Destroy a media stream representation
*
* \param stream The media stream
*/
void ast_stream_destroy(struct ast_stream *stream);
/*!
* \brief Get the name of a stream
*
* \param stream The media stream
*
* \return The name of the stream
*/
const char *ast_stream_get_name(const struct ast_stream *stream);
/*!
* \brief Get the media type of a stream
*
* \param stream The media stream
*
* \return The media type of the stream
*/
enum ast_media_type ast_stream_get_type(const struct ast_stream *stream);
/*!
* \brief Change the media type of a stream
*
* \param stream The media stream
* \param type The new media type
*/
void ast_stream_set_type(struct ast_stream *stream, enum ast_media_type type);
/*!
* \brief Get the current negotiated formats of a stream
*
* \param stream The media stream
*
* \return The negotiated media formats
*
* \note The reference count is not increased
*/
struct ast_format_cap *ast_stream_get_formats(const struct ast_stream *stream);
/*!
* \brief Set the current negotiated formats of a stream
*
* \param stream The media stream
* \param caps The current negotiated formats
*/
void ast_stream_set_formats(struct ast_stream *stream, ast_format_cap *caps);
/*!
* \brief Get the current state of a stream
*
* \param stream The media stream
*
* \return The state of the stream
*/
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream);
/*!
* \brief Set the state of a stream
*
* \param stream The media stream
* \param state The new state that the stream is in
*
* \note Used by stream creator to update internal state
*/
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state);
/*!
* \brief Get the number of the stream
*
* \param stream The media stream
*
* \return The number of the stream
*/
unsigned int ast_stream_get_num(const struct ast_stream *stream);
/*!
* \brief Create a stream topology
*
* \retval non-NULL success
* \retval NULL failure
*/
struct ast_stream_topology *ast_stream_topology_new(void);
/*!
* \brief Add a stream to the topology
*
* \param topology The topology of streams
* \param stream The stream to add
*
* \retval 0 success
* \retval -1 failure
*/
int ast_stream_topology_add(struct ast_stream_topology *topology, struct ast_stream *stream);
/*!
* \brief Get the number of streams in a topology
*
* \param topology The topology of streams
*
* \return the number of streams
*/
size_t ast_stream_topology_num(const struct ast_stream_topology *topology);
/*!
* \brief Get a specific stream from the topology
*
* \param topology The topology of streams
*
* \retval non-NULL success
* \retval NULL failure
*/
struct ast_stream *ast_stream_topology_get(const struct ast_stream_topology *topology, unsigned int stream_num);
/*!
* \brief Copy an existing stream topology
*
* \param topology The existing topology of streams
*
* \retval non-NULL success
* \retval NULL failure
*/
struct ast_stream_topology *ast_stream_topology_copy(const struct ast_stream_topology *topology);
/*!
* \brief Set a specific numbered stream in a topology
*
* \brief topology The topology of streams
* \brief num The stream number to set
* \brief stream The stream to put in its place
*
* \retval 0 success
* \retval -1 failure
*
* \note If an existing stream exists it will be destroyed
*/
int ast_stream_topology_set(struct ast_stream_topology *topology, unsigned int num, struct ast_stream *stream);
/*!
* \brief A helper function that given a set of formats creates a topology with the required streams to satisfy them
*
* \param caps The format capabilities containing formats
*
* \retval non-NULL success
* \retval NULL failure
*
* \note The format capabilities reference is NOT stolen by this function
*
* \note Each stream will be to sendrecv state
*/
struct ast_stream_topology *ast_stream_topology_make(struct ast_format_cap *caps);
/*!
* \brief Destroy a stream topology
*
* \param topology The topology of streams
*
* \note All streams contained within the topology will be destroyed
*/
void ast_stream_topology_destroy(struct ast_stream_topology *topology);</pre>
</div>
</div> <p style="margin: 10px 0 0 0">These functions can be used by anything to examine a stream after retrieving a stream (from a channel for example) and to manipulate a stream by a stream user.</p> <p style="margin: 10px 0 0 0">As you can see a stream has various attributes: the media type being carried on, a unique (to a channel) identifier, the formats negotiated on it, its current state, a name, and an opaque data. In the case of the name this may be constructed externally (as a result of receiving an SDP offer) or generated locally if we are sending an offer.</p> <p style="margin: 10px 0 0 0">It is expected that the originator of a stream associate data within itself using the stream numerical identifier. This allows an array (or a vector) to be used for an easy mapping.</p> <p style="margin: 10px 0 0 0">Stream creation is up to the originator of a stream. In the case of a channel driver the channel driver may know a new stream exists, create it, and then place it on a channel. <span class="inline-comment-marker" data-ref="46d617e4-6d94-4336-9e2d-a02896d497a7">For file playback it may do something similar but place the stream in an internal structure instead</span>. For stream destruction it is up to the holder of stream. This can be the internal channel core, or the file playback implementation. If the channel driver does not support multiple streams the internal core API will take care of the management of default streams.</p> <p style="margin: 10px 0 0 0">A common method of describing (and passing around) a topology of streams is also present. This is an ordered list of streams that can be added to, queried, and manipulated.</p> <h2 id="StreamSupport-stream.c" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">stream.c</h2> <p style="margin: 10px 0 0 0">The stream implementation will hold the actual definition of a stream and the implementation of the various functions.</p>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0">struct ast_stream {
/*!
* \brief The type of media the stream is handling
*/
enum ast_media_type type;
/*!
* \brief Unique number for the stream within the context of the channel it is on
*/
unsigned int num;
/*!
* \brief Current formats negotiated on the stream
*/
struct ast_format_cap *formats;
/*!
* \brief The current state of the stream
*/
enum ast_stream_state state;
/*!
* \brief Name for the stream within the context of the channel it is on
*/
char name[0];
};
struct ast_stream_topology {
/*!
* \brief A vector of all the streams in this topology
*/
AST_VECTOR(, struct ast_stream *) streams;
};</pre>
</div>
</div> <p style="margin: 10px 0 0 0">The contents of a stream very much mirror that of the public and internal APIs. There is not anything truly hidden away yet.</p> <h2 id="StreamSupport-channel.h" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">channel.h</h2> <p style="margin: 10px 0 0 0">The channel header file will be minimally changed to add multiple stream support.</p>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0"> /*!
* \brief Channels with this particular technology support multiple simultaneous streams
*/
AST_CHAN_TP_MULTISTREAM = (1 << 3),
struct ast_channel_tech {
/*!
* \brief Callback invoked to write a frame to a specific stream
*/
int (* const write_stream)(struct ast_channel *chan, unsigned int stream_num, struct ast_frame *frame);
};
/*!
* \brief Write a frame to a specific stream on a channel
*
* \param chan The channel to write to
* \param stream_num The number of the specific stream to send the frame out on
* \param frame The frame to write out
*
* \pre chan is locked
*
* \retval 0 success
* \retval -1 failure
*/
int ast_write_stream(struct ast_channel *chan, unsigned int stream_num, struct ast_frame *frame);
/*!
* \brief Read a frame from all streams
*
* \param chan The channel to read from
* \param stream_num[out] The number of the specific stream the frame originated from, if a media frame
*
* \pre chan is locked
*
* \retval non-NULL success
* \retval NULL failure
*/
struct ast_frame *ast_read_streams(struct ast_channel *chan, unsigned int *stream_num);
/*!
* \brief Retrieve the topology of streams on a channel
*
* \param chan The channel to get the stream topology of
*
* \pre chan is locked
*
* \retval non-NULL success
* \retval NULL failure
*/
struct ast_stream_topology *ast_channel_get_stream_topology(const struct ast_channel *chan);
/*!
* \brief Request that the stream topology of a channel change
*
* \param chan The channel to change
* \param topology The new stream topology
*
* \pre chan is locked
*
* \retval 0 request has been accepted to be attempted
* \retval -1 request could not be attempted
*
* \note This function initiates an asynchronous request to change the stream topology. It is not
* guaranteed that the topology will change and until an AST_CONTROL_STREAM_TOPOLOGY_CHANGED
* frame is received from the channel the current handler of the channel must tolerate the
* stream topology as it currently exists.
*
* \note This interface is provided for applications and resources to request that the topology change.
* It is not for use by the channel driver itself.
*/
int ast_channel_stream_topology_request_change(struct ast_channel *chan, struct ast_stream_topology *topology);
/*!
* \brief Provide notice to a channel that the stream topology has changed
*
* \param chan The channel to provide notice to
* \param topology The new stream topology
*
* \retval 0 success
* \retval -1 failure
*
* \note This interface is provided for applications and resources to accept a topology change.
* It is not for use by the channel driver itself.
*/
int ast_channel_stream_topology_changed(struct ast_channel *chan, struct ast_stream_topology *topology);</pre>
</div>
</div> <p style="margin: 10px 0 0 0">To indicate support for multiple streams a property has been added for channel technologies to enable. An inspection function exists for the purpose of getting the topology of streams on the channel. Once retrieved the normal topology functions can be used to inspect each stream individually. In the case of channel drivers they can also manipulate the stream topology provided the channel lock is held.</p> <h4 id="StreamSupport-StreamCreation" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Stream Creation</h4> <p style="margin: 10px 0 0 0">If the multiple stream property is not set the act of setting nativeformats for a channel will automatically create (or revive if removed) streams in the background. A stream will exist for each media type of formats on the channel. If the channel has both an audio and video format an audio stream and a video stream will exist. These will be set as the default stream for each media type.</p> <p style="margin: 10px 0 0 0">If the multiple stream property is set the act of creating and adding streams is left up to the specific channel driver. As each stream is added to the channel if a default stream for that media type does not exist then the stream will be set as the default.</p> <h4 id="StreamSupport-WritingFrames" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Writing Frames</h4> <p style="margin: 10px 0 0 0">The ast_write function will choose a default stream based on the media type of the frame being written. If no default stream exists the frame will not be written.</p> <p style="margin: 10px 0 0 0">The ast_write_stream function will provide the given frame to the channel driver with the given stream. It is up to the channel driver to write the frame out on that stream. All frames written using either ast_write or ast_write_stream will be provided to the channel driver using the write_stream technology callback.</p> <h4 id="StreamSupport-ReadingFrames" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Reading Frames</h4> <p style="margin: 10px 0 0 0">The ast_read function will read frames from ONLY default streams and non-media. If a frame is received on a non-default stream it will be discarded and a null frame returned. This mirrors current behavior.</p> <p style="margin: 10px 0 0 0">The ast_read_streams function will read frames from ALL streams and non-media. It is up to the caller to then decide to do based on the stream.</p> <h4 id="StreamSupport-ChangingStreamTopology" style="margin: 10px 0 0 0; font-size: 14px; line-height: 20px; margin: 20px 0 0 0">Changing Stream Topology</h4> <p style="margin: 10px 0 0 0">An external entity (such as a SIP phone) can request that the stream topology change at any time. The channel driver receives the change in an implementation specific fashion and queues an AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE on the channel. The current handler of the channel reads the frame and acts upon the stream topology within it. The stream topology (whether it is changed or not) is provided to the channel using the ast_channel_stream_topology_changed function. For legacy reasons the ast_read() function will not allow topology changes and the current negotiated stream topology will be returned within its implementation, signaling that the topology change did not result in an accepted change.</p> <p style="margin: 10px 0 0 0">Components in Asterisk can request that a stream topology change by providing a new topology to the ast_channel_stream_topology_request_change function. This is provided to the channel driver and is implementation specific how it is done. The existing stream topology can be used as a base by retrieving the topology from the channel and calling the ast_stream_topology_copy function to copy it. Once the stream topology change result is known in the channel driver it queues an AST_CONTROL_STREAM_TOPOLOGY_CHANGED frame.</p> <p style="margin: 10px 0 0 0">Both of these control frames contain the complete stream topology.</p> <h2 id="StreamSupport-frame.h" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">frame.h</h2> <p style="margin: 10px 0 0 0">The only change to frame related stuff is mere control frame additions.</p>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0">enum ast_control_frame_type {
AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE = 35, /*!< Channel indication that a stream topology change has been requested by the channel driver (only visible if ast_read_streams is used) */
AST_CONTROL_STREAM_TOPOLOGY_CHANGED = 36, /*!< Channel indication that a stream topology change has occurred on the channel driver */
};</pre>
</div>
</div> <p style="margin: 10px 0 0 0">The control frame type is used to communicate a request to change the stream topology or an indication that the stream topology has changed. When written it is a request, when read it is informational.</p> <h1 id="StreamSupport-Examples" style="margin: 10px 0 0 0; font-size: 24px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Examples</h1> <h2 id="StreamSupport-Creatingstreamsonachannel" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0; margin-top: 10px">Creating streams on a channel</h2>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0"> struct ast_stream *audio_stream, *video_stream;
audio_stream = ast_stream_create("audio", AST_MEDIA_TYPE_AUDIO);
video_stream = ast_stream_create("video", AST_MEDIA_TYPE_VIDEO);
ast_channel_lock(chan);
ast_stream_topology_add(ast_channel_get_stream_topology(chan), audio_stream);
ast_stream_topology_add(ast_channel_get_stream_topology(chan), video_stream);
ast_channel_unlock(chan);</pre>
</div>
</div> <p style="margin: 10px 0 0 0">This creates an audio and video stream and places them on the channel.</p> <h2 id="StreamSupport-Iterating" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Iterating</h2>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0"> int i;
struct ast_stream_topology *topology;
ast_channel_lock(chan);
topology = ast_channel_get_stream_topology(chan);
for (i = 0; i < ast_stream_topology_num(topology); i++) {
struct ast_stream *stream;
stream = ast_stream_topology_get(topology, i);
}
ast_channel_unlock(chan);</pre>
</div>
</div> <p style="margin: 10px 0 0 0">This just loops through all the streams on a channel.</p> <h2 id="StreamSupport-Requestingachangetothestreamtopology" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Requesting a change to the stream topology</h2>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0"> struct ast_stream_topology *modified;
struct ast_stream *first;
ast_channel_lock(chan);
modified = ast_stream_topology_copy(ast_channel_get_stream_topology(chan));
first = ast_stream_topology_get(modified, 0);
ast_stream_set_state(first, AST_STREAM_STATE_INACTIVE);
ast_channel_stream_topology_request_change(chan, modified);
ast_channel_unlock(chan);</pre>
</div>
</div> <p style="margin: 10px 0 0 0">This code requests that the first stream on the channel be set to inactive.</p> <h2 id="StreamSupport-Handlingarequesttochangethestreamtopology" style="margin: 10px 0 0 0; font-size: 20px; font-weight: normal; line-height: 30px; margin: 40px 0 0 0">Handling a request to change the stream topology</h2>
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;; margin: 10px 0 0 0; margin-top: 0"> struct ast_frame *frame;
unsigned int stream_num;
frame = ast_read_streams(chan, &stream_num);
if (frame->frametype == AST_CONTROL && frame->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE) {
ast_channel_stream_topology_changed(chan, frame->data.ptr);
}
ast_frfree(frame);</pre>
</div>
</div> <p style="margin: 10px 0 0 0">This code reads in a request to change the topology and accepts the topology as requested. Note that we only receive request changes if we are capable of supporting multiple streams. If this were to use ast_read() the topology request change would be internally handled.</p> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td class="email-content-main mobile-expand action-padding last-row-padding" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 15px 16px; background-color: #fff; padding-bottom: 10px; padding-bottom: 10px">
<table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px">
<tbody>
<tr>
<td id="actions-pattern-container" valign="middle" style="padding: 0px; border-collapse: collapse; padding: 15px 0 0 24px; vertical-align: middle">
<table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0px; vertical-align: middle"><a href="https://wiki.asterisk.org/wiki/display/AST/Stream+Support?src=email" title="View page Icon" style="color: #3b73af; text-decoration: none"><img class="actions-pattern-action-icon-image" height="16" width="16" border="0" title="View page Icon" src="cid:com.atlassian.confluence.plugins.confluence-email-resources%3Aview-page-email-adg-footer-item%3Aicon" alt="View page Icon" style="vertical-align: middle" /></a></td>
<td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px; white-space: nowrap"><a href="https://wiki.asterisk.org/wiki/display/AST/Stream+Support?src=email" title="View page" style="color: #3b73af; text-decoration: none">View page</a></td>
<td class="actions-pattern-action-bull" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; color: #999; padding: 0 5px">•</td>
</tr>
</tbody>
</table>
<table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0px; vertical-align: middle"><a href="https://wiki.asterisk.org/wiki/display/AST/Stream+Support?showComments=true&showCommentArea=true&src=email#addcomment" title="Add comment Icon" style="color: #3b73af; text-decoration: none"><img class="actions-pattern-action-icon-image" height="16" width="16" border="0" title="Add comment Icon" src="cid:com.atlassian.confluence.plugins.confluence-email-resources%3Aadd-comment-to-content-email-adg-footer-item%3Aicon" alt="Add comment Icon" style="vertical-align: middle" /></a></td>
<td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px; white-space: nowrap"><a href="https://wiki.asterisk.org/wiki/display/AST/Stream+Support?showComments=true&showCommentArea=true&src=email#addcomment" title="Add comment" style="color: #3b73af; text-decoration: none">Add comment</a></td>
<td class="actions-pattern-action-bull" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; color: #999; padding: 0 5px">•</td>
</tr>
</tbody>
</table>
<table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0px; vertical-align: middle"><a href="https://wiki.asterisk.org/wiki/plugins/likes/like.action?contentId=36800306&src=email" title="Like Icon" style="color: #3b73af; text-decoration: none"><img class="actions-pattern-action-icon-image" height="16" width="16" border="0" title="Like Icon" src="cid:com.atlassian.confluence.plugins.confluence-like%3Aview-email-adg-content-item%3Aicon" alt="Like Icon" style="vertical-align: middle" /></a></td>
<td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px; white-space: nowrap"><a href="https://wiki.asterisk.org/wiki/plugins/likes/like.action?contentId=36800306&src=email" title="Like" style="color: #3b73af; text-decoration: none">Like</a></td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td class="email-content-rounded-bottom mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; height: 5px; line-height: 5px; padding: 0 15px 0 16px; background-color: #fff; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; border-top: 0; border-left: 1px solid #ccc; border-bottom: 1px solid #ccc; border-right: 1px solid #ccc; mso-line-height-rule: exactly"> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td id="footer-pattern" style="padding: 0px; border-collapse: collapse; padding: 12px 20px">
<table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333">
<tbody>
<tr>
<td id="footer-pattern-links-container" width="100%" style="padding: 0px; border-collapse: collapse; color: #999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">
<table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">
<tbody>
<tr>
<td class="footer-pattern-links mobile-resize-text" style="padding: 0px; border-collapse: collapse"><a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST&src=email" title="" style="color: #3b73af; text-decoration: none">Stop watching space</a></td>
<td class="footer-pattern-links-bull" style="padding: 0px; border-collapse: collapse; padding: 0 5px; color: #999">•</td>
</tr>
</tbody>
</table>
<table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">
<tbody>
<tr>
<td class="footer-pattern-links mobile-resize-text" style="padding: 0px; border-collapse: collapse"><a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action?src=email" title="" style="color: #3b73af; text-decoration: none">Manage notifications</a></td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0px; border-collapse: collapse; color: #999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px; display: none">This message was sent by Atlassian Confluence 5.6.6</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
</table>
<table id="sealed-section" border="0" cellpadding="0" cellspacing="0" width="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; color: #333; display: none">
<tbody>
<tr>
<td style="padding: 0px; border-collapse: collapse; border: 0; font-size: 0px; line-height: 0; mso-line-height-rule: exactly"></td>
</tr>
</tbody>
</table>
</body>
</html>