<chapter><title>The Output Module</title>


<para>
The Output Module takes the
data from the TsStreamer, gather the TS packets together and add RTP header when needed, and then writes the datas to a file of to the network.

Refer to <xref linkend="l-arch" endterm="t-arch"> to see the position of
Output between other parts of vls.
</para>


<sect1><title>The Module itself</title>
<para>
As other modules of vls, a core file
<filename>server/output.*</filename> describes the definition of the
output, and its behavior against others parts of vls. The modules
<filename>NetOutput</filename> and <filename>FileOutput</filename>
differs from their implementation of the virtual function
<function>WriteToPort()</function>.
</para>

<para>
The Output is created by the Channel Module. 
In <filename>modules/filechannel.cpp</filename>  :

<programlisting>
  m_pOutput = new C_FileOutput(strFilename, bAppend);
</programlisting>

and in <filename>modules/netchannel.cpp</filename>:

<programlisting>
    m_pOutput = new C_Net4Output(m_strName);
</programlisting>
</para>
</sect1>

<sect1><title>The internal Fifo</title>
<para>
<mediaobject>
 <imageobject>
    <imagedata fileref="outputfifo.eps" format="EPS" scalefit="1" scale="30">
  </imageobject>
  <imageobject>
    <imagedata fileref="outputfifo.jpg" format="JPG">
  </imageobject>
 <textobject>
    <phrase>Internal Fifo for Output</phrase>
  </textobject>
</mediaobject>
</para>

<para>

Since the output may have to gather packets, it needs a Fifo of
TsPackets. Its name is <function>m_cBuffer()</function>.

The capacity (ie the maximum size) of m_cBuffer() is specified in the Output constructor :

<programlisting>
C_Output::C_Output(unsigned int iBuffSize) : m_cTsBuff(iBuffSize)
</programlisting>
</para>

<para>
In the case of FileOutput, the vls can write the packet when he
wants, to we don't care about the number of packets written.
<function>iBuffSize</function> can be 1, or 7 if we want to store 7
TsPackets in an RTP packet when using RTP.
</para> 

<para>
In the case of NetOutput, this is more important since this will influence the size of each UDP packets.
The maximum amount is 7. Indeed, the maximum payload size for an UDP packet is 1472 Bytes. Each TsPacket is 188 Bytes, and 1472/188 = 7.
</para>

<para>
Moreover, when using RTP output, 12 extra header bytes are added. But it's still ok since :
<programlisting>
7 * 188 + 12 = 1328 < 1472.
</programlisting>
</para>

<para>
By default, the TS_IN_ETHER value defined in
<filename>server/output.h</filename> is set to 7. You may change that
depending on how your network hardware can handle big UDP packets.
</para>

</sect1>

