[PATCH] mplex A/V precedence order

[email protected] Sat, 06 Mar 2010 07:49:12 +0100
Newsgroups gmane.comp.video.mjpeg.devel
Message-ID <[email protected]>
Hi,

The multiplex strategy in mplex will add all non-video packages at the  
end of a GOP. While i don't know about other formats (VCD and so on),  
in case of DVD all video information is put at the beginning of a VOBU  
and the remaining streams are sent to the end of a VOBU, regardless of  
their timestamps This behaviour may cause a buffer underrun in  
standalone players.
I cannot give concrete example for a real-live failure, but looking at  
produced A/V streams (and code) gives me a strange feeling.

The simple patch attached should cover this problem: It runs backwards  
through the vector of elementary streams so that the video stream will  
not gain too much precedence over the other streams.

Roland

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
Mjpeg-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mjpeg-developer
multiplexor.diff (text/plain, 1.5 KB)
--- mplex/multiplexor.cpp	2008-05-10 12:56:04.000000000 +0200
+++ mplex.new/multiplexor.cpp	2010-03-06 07:15:06.000000000 +0100
@@ -1074,7 +1085,8 @@
 	std::vector<bool> completed;
 	std::vector<bool>::iterator pcomp;
 	std::vector<ElementaryStream *>::iterator str;
-
+	std::vector<ElementaryStream *>::iterator str1 = estreams.begin();
+	
 	unsigned int packets_left_in_pack = 0; /* Suppress warning */
 	bool padding_packet;
 	bool video_first = true;
@@ -1255,8 +1267,19 @@
 		//
 		ElementaryStream *despatch = 0;
 		clockticks earliest = 0;
-		for( str = estreams.begin(); str < estreams.end(); ++str )
+		// hmm... the original code gives video precedence over all other streams
+		// regardless of their DTS timestamp. This forces all non-video streams
+		// to be appended after a GOP ends. That behaviour may cause an underrun
+		// in the decoder's buffer
+		// original code:
+		//
+		// for( str = estreams.begin(); str < estreams.end(); ++str )
+		//
+		// solution: simply go backwards through the stream vector
+		str =estreams.end();
+		do 
 		{
+		 --str;
 #ifdef STREAM_LOGGING
             if( (*str)->MuxCompleted() )
                 mjpeg_debug( "%02x: complete", (*str)->stream_id );
@@ -1271,6 +1294,7 @@
                             
 				    );
 #endif
+			
 			if( (*str)->MuxPossible(current_SCR) && 
 				( !video_first || (*str)->Kind() == ElementaryStream::video )
 				 )
@@ -1281,7 +1305,7 @@
 					earliest = (*str)->RequiredDTS();
 				}
 			}
-		}
+		} while (str != estreams.begin());
 		
 		if( underrun_ignore > 0 )
 			--underrun_ignore;