\doxysection{com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy Class Reference}
\hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy}{}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy}\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection*{Classes}
\begin{DoxyCompactItemize}
\item 
enum \mbox{\hyperlink{enumcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_1_1State}{State}}
\item 
interface \mbox{\hyperlink{interfacecom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_1_1StateChangedListener}{State\+Changed\+Listener}}
\begin{DoxyCompactList}\small\item\em Interface to be implemented in order to be notified about the important changes of state of the server. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
void \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a6aac1ed7272efcdfbaf21891d0835601}{set\+Client}} (Client client)
\item 
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ab6d8a4e6017e603dcb71755d83f27157}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ab6d8a4e6017e603dcb71755d83f27157} 
Client {\bfseries get\+Client} ()
\begin{DoxyCompactList}\small\item\em Gets the client to be used to connect to the stream. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a689c26b0ce4fbf3f50144f81f8241d64}{set\+Server}} (Server server)
\item 
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a10913a1dcab223d09b76eecff035b2a8}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a10913a1dcab223d09b76eecff035b2a8} 
void {\bfseries set\+Stream\+Container\+Decoder} (Stream\+Container\+Decoder stream\+Container\+Decoder)
\begin{DoxyCompactList}\small\item\em Sets the instance that decodes the data received by the client and links it to the client. \end{DoxyCompactList}\item 
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a5a42282a8c2190d71b3f6d4fe73c2739}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a5a42282a8c2190d71b3f6d4fe73c2739} 
Stream\+Container\+Decoder {\bfseries get\+Stream\+Container\+Decoder} ()
\begin{DoxyCompactList}\small\item\em Gets the instance that decodes the data received by the client. \end{DoxyCompactList}\item 
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a2276fa955cd7184d9fac0f2b6c3318cc}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a2276fa955cd7184d9fac0f2b6c3318cc} 
void {\bfseries set\+Data\+Provider} (Data\+Provider data\+Provider)
\begin{DoxyCompactList}\small\item\em Gets the instance that provides data to the server (after re-\/encoding it if needed) and links it to the server. \end{DoxyCompactList}\item 
URI \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ac35452c037681a36456b0679ef695ec4}{start}} (URI uri)
\begin{DoxyCompactList}\small\item\em Starts proxying the stream at the given uri. \end{DoxyCompactList}\item 
String \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a6e4c079af1c20728a9d7a778d227d4dd}{start}} (String uri\+Str)
\begin{DoxyCompactList}\small\item\em Starts proxying the stream at the given uri. \end{DoxyCompactList}\item 
URI \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_acfe430a49c0936f776677ab08d246722}{start\+Async}} (URI uri)
\begin{DoxyCompactList}\small\item\em Starts proxying the stream asynchronously at the given uri. \end{DoxyCompactList}\item 
String \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a1a92a2288f16f3afa25044660aa1f4d5}{start\+Async}} (String uri\+Str)
\begin{DoxyCompactList}\small\item\em Starts proxying the stream asynchronously at the given uri. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ac912f17b66d6ad604fefcc820860d710}{stop}} ()
\begin{DoxyCompactList}\small\item\em Stops proxying the stream at the given uri. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ab38adf23167ef965fa0b104cdf905b76}{audio\+Playback\+Did\+Start}} ()
\begin{DoxyCompactList}\small\item\em Called by the media player class, which typically also starts the proxy, when the playback starts. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Public Attributes}
\begin{DoxyCompactItemize}
\item 
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a347543f0cc733fab3be2dea040c3a2d3}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a347543f0cc733fab3be2dea040c3a2d3} 
final String {\bfseries TAG} = "{}Proxy"{}
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
This class allows connecting to a server to receive a stream, extract the Meta Data (if any), the Audio Data, repacketize it in a different streaming protocol and open a local server to be used instead of the original one. The proxy is transparent to the application client. It is started with the original URI that the application wishes to connect to, then it returns a different URL that the application client should use instead.

If the local server type is not a Raw Data type or has a different transport than the original stream, a repacking will occur to transform the original data into something appropriate for the server. For example, there is no repacking if the client is Flv (which uses Http) and the local server is Http Raw Data (the data is simply passed through). On the other side, an Flv client with an RTSP server automatically implies repacking, because the protocol changes.

The purpose of this is to support additional stream transport protocols than the platform originally supports. A good example is Android, which does not allow, as of this writing, streaming from an FLV source. However, it supports streaming from RTSP sources. This proxy can then be used to connect to the FLV server, convert all the data at runtime and produce a RTSP server for the Android media server to connect to. The advantage of using the proxy as a repacking tool is that it may allow supporting more formats, because some formats (like AAC on Android) are only supported over some protocols. The disadvantage of using it to convert is that it may decrease performances, especially due to the intermediate bytes array that may need to be created and garbage-\/collected. Great efforts have been made to reduce those creation to a minimum by reusing buffers, but there may still be cases where new bytes array are created and copied, which may impact the performance. Always benchmark before using the repacking.

It can be also be used without any repacking, just to extract Meta\+Data from the streaming source, which is something that is not supported for all platforms. Again, as of this writing, Android supports stream raw MP3, but not streaming FLV. In order have Cue\+Point, this proxy could be used to connect to the FLV source, extract the Meta\+Data to notify a listener, extract the MP3 data and pass it as-\/is to the media player. The advantage is that it reduces the overhead since there is no repackaging of the packets. This feature is currently not available out of the box, it requires writing an extension to the Server class which would simply take all data decoded and sent it to the client as is.

The Metadata is sent to the listener when the associated timestamp is reached. When receiving the Metadata from the original stream, its timestamp may refer to a date in the future. This is especially true if the stream is sent by burst instead of in real time. There is also a delay caused by the Android Media\+Player implementation of RTSP which requires a very large buffering to occur before the playback actually starts. To compensate for all this, when the proxy receives a Metadata, it computes the time at which this metadata should be treated, based on the the metadata timestamp sent by the server and the reference timestamp at which the playback actually started. It then waits for the good delay and only notify the listener when the metadata should be treated. For this to work, the proxy needs to be notified when the playback starts. This is done by calling audio\+Playback\+Did\+Start on the Proxy instance.

In total, the Proxy can use up to 6 threads. It uses one thread for the Client, two for the Decoder and two or three for the server. See each component\textquotesingle{}s documentation for details. When stopping, either because the media player closed the connection, because of an error an because of a manual stop, all those threads are stopped gracefully.

The simplest way to create a Proxy is by using the Proxy\+Factory, which takes care of the creation of all the layers needed by a proxy (Client, Stream Container Decoder, packetizer that provides data to the local server, local server). However, for more grained control or to add additional protocols for the client or the local server, it is possible to create all instances manually.

The proxy is implemented as a small state machine. See the documentation of Proxy.\+State for details.

Usage example for manual creation of a Proxy\+: 
\begin{DoxyPre}
    public void startPlayback()
    \{
       Proxy proxy = new Proxy();
       proxy.setClient(new HttpClient());
       proxy.setStreamContainerDecoder(new FlvDecoder());
       proxy.setDataProvider(new RtpPacketProviderMp4Latm());
       proxy.setServer(new RtspServer());

       // Connect metadata listener
      proxy.getStreamContainerDecoder().setMetaDataDecodedListener(metadataDecodedListener);

       // Start using the proxy and playing (mMediaPlayer could be, for example, an allocated instance of the Android MediaPlayer class)
       mMediaPlayer.start(proxy.startAsync("{}http://myFlvUrl"{}));

       // Optionally, but strongly recommended, make sure that the MediaPlayer.OnPreparedListener calls proxy.audioPlaybackDidStart() in
       // its 'onPrepared' implementation.
    \}

 \end{DoxyPre}
 

\doxysubsection{Member Function Documentation}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ab38adf23167ef965fa0b104cdf905b76}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ab38adf23167ef965fa0b104cdf905b76} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!audioPlaybackDidStart@{audioPlaybackDidStart}}
\index{audioPlaybackDidStart@{audioPlaybackDidStart}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{audioPlaybackDidStart()}{audioPlaybackDidStart()}}
{\footnotesize\ttfamily void com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+audio\+Playback\+Did\+Start (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Called by the media player class, which typically also starts the proxy, when the playback starts. 

This is used to reset internal counters and timers which ensure that the data is treated at the right time. More specifically, it makes sure that the Metadata is sent to the listeners at the right time, based on the timestamp associated with it. \Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a6aac1ed7272efcdfbaf21891d0835601}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a6aac1ed7272efcdfbaf21891d0835601} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!setClient@{setClient}}
\index{setClient@{setClient}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{setClient()}{setClient()}}
{\footnotesize\ttfamily void com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+set\+Client (\begin{DoxyParamCaption}\item[{Client}]{client }\end{DoxyParamCaption})}

Sets the client to be used to connect to the stream. This client should be preconfigured (or at least configured before {\ttfamily start} is called).

Note that the proxy automatically registers to be the listener of the client, replacing the previous listener. There is no need to keep a listener on the client directly as the proxy already forwards all the important messages in its own listener implementation. When it comes to messages and listeners, the proxy should be seen as a whole, not as an individual client and server.


\begin{DoxyParams}{Parameters}
{\em client} & The client that will be used to connect to the remote server, which will do the job of pulling the data from the external server. Should be configured with its Listener, that will decode, extract data (Meta and Audio) and repack for the local server before {\ttfamily start} is called. \\
\hline
\end{DoxyParams}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a689c26b0ce4fbf3f50144f81f8241d64}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a689c26b0ce4fbf3f50144f81f8241d64} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!setServer@{setServer}}
\index{setServer@{setServer}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{setServer()}{setServer()}}
{\footnotesize\ttfamily void com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+set\+Server (\begin{DoxyParamCaption}\item[{Server}]{server }\end{DoxyParamCaption})}

Sets the server to be used locally to send the stream to the Media Player (or the actual client that the application wishes to use). This server should be preconfigured (or at least configured before {\ttfamily start} is called).

Note that the proxy automatically registers to be the listener of the server, replacing the previous listener. There is no need to keep a listener on the server directly as the proxy already forwards all the important messages in its own listener implementation. When it comes to messages and listeners, the proxy should be seen as a whole, not as an individual client and server.


\begin{DoxyParams}{Parameters}
{\em server} & The server that will be used to listen locally, to which the Media Player should connect. Should be configured with its Data Provider before {\ttfamily start} is called. \\
\hline
\end{DoxyParams}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a6e4c079af1c20728a9d7a778d227d4dd}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a6e4c079af1c20728a9d7a778d227d4dd} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!start@{start}}
\index{start@{start}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{start()}{start()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily String com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+start (\begin{DoxyParamCaption}\item[{String}]{uri\+Str }\end{DoxyParamCaption})}



Starts proxying the stream at the given uri. 

Convenience method to work with uri as Strings.


\begin{DoxyParams}{Parameters}
{\em uri\+Str} & The uri (as a String) of the external server that will send the stream.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The uri (as a String) of the local server, that should be used in the Media Player instead of the original one or null if there was an error starting the proxy. 
\end{DoxyReturn}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ac35452c037681a36456b0679ef695ec4}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ac35452c037681a36456b0679ef695ec4} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!start@{start}}
\index{start@{start}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{start()}{start()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily URI com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+start (\begin{DoxyParamCaption}\item[{URI}]{uri }\end{DoxyParamCaption})}



Starts proxying the stream at the given uri. 

This method blocks until the server has started (which may need to wait for some data from the server at the given uri), then returns the URI that should be used instead of the original one.


\begin{DoxyParams}{Parameters}
{\em uri} & The URI of the external server that will send the stream.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The uri (as a String) of the local server, that should be used in the Media Player instead of the original one or null if there was an error starting the proxy. 
\end{DoxyReturn}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a1a92a2288f16f3afa25044660aa1f4d5}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_a1a92a2288f16f3afa25044660aa1f4d5} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!startAsync@{startAsync}}
\index{startAsync@{startAsync}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{startAsync()}{startAsync()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily String com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+start\+Async (\begin{DoxyParamCaption}\item[{String}]{uri\+Str }\end{DoxyParamCaption})}



Starts proxying the stream asynchronously at the given uri. 

Convenience method to work asynchronously with uri as Strings.


\begin{DoxyParams}{Parameters}
{\em uri\+Str} & The uri (as a String) of the external server that will send the stream.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The uri (as a String) of the local server, that should be used in the Media Player instead of the original one or null if there was an error starting the proxy. 
\end{DoxyReturn}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_acfe430a49c0936f776677ab08d246722}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_acfe430a49c0936f776677ab08d246722} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!startAsync@{startAsync}}
\index{startAsync@{startAsync}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{startAsync()}{startAsync()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily URI com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+start\+Async (\begin{DoxyParamCaption}\item[{URI}]{uri }\end{DoxyParamCaption})}



Starts proxying the stream asynchronously at the given uri. 

Unlike start(\+URI), this method does not block until the server has started but returns immediately with the Uri that should be used as a replacement for the original one. However, before using this Uri, the caller could wait for the on\+Proxy\+Server\+Ready notification (this listener should be added before the call to connect\+Async to avoid missing the notification). If the caller does not wait for the ready notification, then the server might block when responding to an RTSP request, until the available data is ready. A sensitive client might consider this as a timeout.


\begin{DoxyParams}{Parameters}
{\em uri} & The URI of the external server that will send the stream.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The uri (as a String) of the local server, that should be used in the Media Player instead of the original one or null if there was an error starting the proxy.
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
start(\+URI) 
\end{DoxySeeAlso}
\Hypertarget{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ac912f17b66d6ad604fefcc820860d710}\label{classcom_1_1tritondigital_1_1net_1_1streaming_1_1proxy_1_1Proxy_ac912f17b66d6ad604fefcc820860d710} 
\index{com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}!stop@{stop}}
\index{stop@{stop}!com.tritondigital.net.streaming.proxy.Proxy@{com.tritondigital.net.streaming.proxy.Proxy}}
\doxysubsubsection{\texorpdfstring{stop()}{stop()}}
{\footnotesize\ttfamily void com.\+tritondigital.\+net.\+streaming.\+proxy.\+Proxy.\+stop (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Stops proxying the stream at the given uri. 

Cuts the connection to the remote server, flushes any data accumulated internally and disconnect the local server. 

The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
sdk/src/main/java/com/tritondigital/net/streaming/proxy/Proxy.\+java\end{DoxyCompactItemize}
