<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.linuxtv.org/wiki/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;feed=atom&amp;action=history</id>
		<title>MPEG-2 Frame Aligner - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;action=history"/>
		<updated>2013-05-24T07:54:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.5</generator>

	<entry>
		<id>http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=12576&amp;oldid=prev</id>
		<title>CityK: MPEG2 Frame Aligner moved to MPEG-2 Frame Aligner: name</title>
		<link rel="alternate" type="text/html" href="http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=12576&amp;oldid=prev"/>
				<updated>2008-01-06T22:05:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;a href=&quot;/wiki/index.php?title=MPEG2_Frame_Aligner&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;MPEG2 Frame Aligner (page does not exist)&quot;&gt;MPEG2 Frame Aligner&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/MPEG-2_Frame_Aligner&quot; title=&quot;MPEG-2 Frame Aligner&quot;&gt;MPEG-2 Frame Aligner&lt;/a&gt;: name&lt;/p&gt;
&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 22:05, 6 January 2008&lt;/td&gt;
		&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>CityK</name></author>	</entry>

	<entry>
		<id>http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=12575&amp;oldid=prev</id>
		<title>CityK: fixed links</title>
		<link rel="alternate" type="text/html" href="http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=12575&amp;oldid=prev"/>
				<updated>2008-01-06T22:05:09Z</updated>
		
		<summary type="html">&lt;p&gt;fixed links&lt;/p&gt;
&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 22:05, 6 January 2008&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Introduction ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Introduction ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Most hardware does not provides aligned &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;MPEG2 &lt;/del&gt;data streams, also the linux-dvb API's DVR device can get out of sync if the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;MPEG2 &lt;/del&gt;TS data stream is interrupted, e.g. due to DMA buffer overflows or if the demod delivers partial packets in case of uncorrectable block errors.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Most hardware does not provides aligned &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;MPEG-2 &lt;/ins&gt;data streams, also the linux-dvb API's DVR device can get out of sync if the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;MPEG-2 &lt;/ins&gt;TS data stream is interrupted, e.g. due to DMA buffer overflows or if the demod delivers partial packets in case of uncorrectable block errors.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;MPEG2 &lt;/del&gt;TS packets can be 188 (without FEC data) or 204 bytes long (including&amp;nbsp; 16 FEC bytes).&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;MPEG-2 &lt;/ins&gt;TS packets can be 188 (without FEC data) or 204 bytes long (including&amp;nbsp; 16 FEC bytes).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Algorithm ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Algorithm ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;MPEG2 &lt;/del&gt;Frame Aligner can get implemented as simple state machine, whenever we are in an &amp;quot;out-of-sync&amp;quot;-state we check all followig bytes until we encounter a &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;MPEG2 &lt;/del&gt;TS Sync Byte (0x47). From then on we check every 188 or 204 bytes if the next 0x47-sync-byte is present. If so the packet is passed to the [[PID_Filter_-_Demultiplexer|PID filter]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;MPEG-2 &lt;/ins&gt;Frame Aligner can get implemented as simple state machine, whenever we are in an &amp;quot;out-of-sync&amp;quot;-state we check all followig bytes until we encounter a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;MPEG-2 &lt;/ins&gt;TS Sync Byte (0x47). From then on we check every 188 or 204 bytes if the next 0x47-sync-byte is present. If so the packet is passed to the [[PID_Filter_-_Demultiplexer|PID filter]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Sample Code ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Sample Code ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>CityK</name></author>	</entry>

	<entry>
		<id>http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=5799&amp;oldid=prev</id>
		<title>Guidod: +cat</title>
		<link rel="alternate" type="text/html" href="http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=5799&amp;oldid=prev"/>
				<updated>2005-04-02T22:33:48Z</updated>
		
		<summary type="html">&lt;p&gt;+cat&lt;/p&gt;
&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 22:33, 2 April 2005&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 56:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 56:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;nbsp; }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;nbsp; }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/tt&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/tt&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Technology]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Guidod</name></author>	</entry>

	<entry>
		<id>http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=1192&amp;oldid=prev</id>
		<title>Holger at 20:38, 1 November 2004</title>
		<link rel="alternate" type="text/html" href="http://www.linuxtv.org/wiki/index.php?title=MPEG-2_Frame_Aligner&amp;diff=1192&amp;oldid=prev"/>
				<updated>2004-11-01T20:38:22Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Most hardware does not provides aligned MPEG2 data streams, also the linux-dvb API's DVR device can get out of sync if the MPEG2 TS data stream is interrupted, e.g. due to DMA buffer overflows or if the demod delivers partial packets in case of uncorrectable block errors.&lt;br /&gt;
&lt;br /&gt;
MPEG2 TS packets can be 188 (without FEC data) or 204 bytes long (including  16 FEC bytes).&lt;br /&gt;
&lt;br /&gt;
== Algorithm ==&lt;br /&gt;
&lt;br /&gt;
The MPEG2 Frame Aligner can get implemented as simple state machine, whenever we are in an &amp;quot;out-of-sync&amp;quot;-state we check all followig bytes until we encounter a MPEG2 TS Sync Byte (0x47). From then on we check every 188 or 204 bytes if the next 0x47-sync-byte is present. If so the packet is passed to the [[PID_Filter_-_Demultiplexer|PID filter]]&lt;br /&gt;
&lt;br /&gt;
== Sample Code ==&lt;br /&gt;
&lt;br /&gt;
The following sample code works for 188-byte packets. This code is taken from the LinuxDVB kernel driver (originally written by Florian Schirmer) and thus GPL'd.&lt;br /&gt;
&lt;br /&gt;
A more generic and robust version based on a state machine should not be too hard to implement and would be able to synchronize both 188- and 204-byte-packets. Please let us know when you feel in the mood to implement+test this, we'll be happy to help whereever possible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
 struct framealigner {&lt;br /&gt;
         char tsbuf[188];&lt;br /&gt;
         int tsbufp;&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 void framealigner_process_ts_data (struct framealigner *fa,&lt;br /&gt;
                                    const char *buf,&lt;br /&gt;
                                    unsigned int count)&lt;br /&gt;
 {&lt;br /&gt;
         unsigned int p = 0, i, j;&lt;br /&gt;
 &lt;br /&gt;
         if ((i = fa-&amp;gt;tsbufp)) {&lt;br /&gt;
                 if (count &amp;lt; (j=188-i)) {&lt;br /&gt;
                         memcpy(&amp;amp;fa-&amp;gt;tsbuf[i], buf, count);&lt;br /&gt;
                         fa-&amp;gt;tsbufp += count;&lt;br /&gt;
                         return;&lt;br /&gt;
                 }&lt;br /&gt;
                 memcpy(&amp;amp;fa-&amp;gt;tsbuf[i], buf, j);&lt;br /&gt;
                 pidfilter_ts_packet(fa-&amp;gt;tsbuf);&lt;br /&gt;
                 fa-&amp;gt;tsbufp = 0;&lt;br /&gt;
                 p += j;&lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
         while (p &amp;lt; count) {&lt;br /&gt;
                 if (buf[p] == 0x47) {&lt;br /&gt;
                         if (count-p &amp;gt;= 188) {&lt;br /&gt;
                                 pidfilter_process_ts_packet(buf+p);&lt;br /&gt;
                                 p += 188;&lt;br /&gt;
                         } else {&lt;br /&gt;
                                 i = count - p;&lt;br /&gt;
                                 memcpy(fa-&amp;gt;tsbuf, buf+p, i);&lt;br /&gt;
                                 fa-&amp;gt;tsbufp = i;&lt;br /&gt;
                                 return;&lt;br /&gt;
                         }&lt;br /&gt;
                 } else&lt;br /&gt;
                         p++;&lt;br /&gt;
         }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;/div&gt;</summary>
		<author><name>Holger</name></author>	</entry>

	</feed>