[Live-devel] Buffer size in MPEG2TransportStreamFromESSource

Gilles Chanteperdrix gilles.chanteperdrix at xenomai.org
Wed Jun 22 08:36:25 PDT 2016


Hi Ross,

I use the MPEG2TransportStreamFromESSource class to stream H264
frames using an MPEG transport stream. It happens that the encoder
I use has some frames larger than the 100 KB buffer size.

I know you have repeated many times on this list that we should
configure the encoder to use slices instead of large frames, but
since you provide OutPacketBuffer::maxSize to increase the default
size of RTPSink objects, I thought that it would make sense to have
a way to change the size of the MPEG2TransportStreamFromESSource
objects buffer too.

So, here is a patch adding a parameter to the class
addNewVideoSource and addNewAudioSource methods, to do just that.
The parameter has a default value of 0, which is converted
internally to INPUT_BUFFER_SIZE, so as to avoid breaking existing
users of this class.

Thanks in advance.
Regards.

diff -Naurdp live.2016.05.20.orig/liveMedia/MPEG2TransportStreamFromESSource.cpp live.2016.05.20/liveMedia/MPEG2TransportStreamFromESSource.cpp
--- live.2016.05.20.orig/liveMedia/MPEG2TransportStreamFromESSource.cpp	2016-05-20 02:11:05.000000000 +0200
+++ live.2016.05.20/liveMedia/MPEG2TransportStreamFromESSource.cpp	2016-06-09 15:21:58.000000000 +0200
@@ -32,6 +32,7 @@ class InputESSourceRecord {
 public:
   InputESSourceRecord(MPEG2TransportStreamFromESSource& parent,
 		      FramedSource* inputSource,
+		      unsigned bufferSize,
 		      u_int8_t streamId, int mpegVersion,
 		      InputESSourceRecord* next, int16_t PID = -1);
   virtual ~InputESSourceRecord();
@@ -80,16 +81,16 @@ MPEG2TransportStreamFromESSource* MPEG2T
 }
 
 void MPEG2TransportStreamFromESSource
-::addNewVideoSource(FramedSource* inputSource, int mpegVersion, int16_t PID) {
+::addNewVideoSource(FramedSource* inputSource, int mpegVersion, int16_t PID, unsigned bufferSize) {
   u_int8_t streamId = 0xE0 | (fVideoSourceCounter++&0x0F);
-  addNewInputSource(inputSource, streamId, mpegVersion, PID);
+  addNewInputSource(inputSource, streamId, mpegVersion, PID, bufferSize);
   fHaveVideoStreams = True;
 }
 
 void MPEG2TransportStreamFromESSource
-::addNewAudioSource(FramedSource* inputSource, int mpegVersion, int16_t PID) {
+::addNewAudioSource(FramedSource* inputSource, int mpegVersion, int16_t PID, unsigned bufferSize) {
   u_int8_t streamId = 0xC0 | (fAudioSourceCounter++&0x0F);
-  addNewInputSource(inputSource, streamId, mpegVersion, PID);
+  addNewInputSource(inputSource, streamId, mpegVersion, PID, bufferSize);
 }
 
 MPEG2TransportStreamFromESSource
@@ -146,10 +147,10 @@ void MPEG2TransportStreamFromESSource
 
 void MPEG2TransportStreamFromESSource
 ::addNewInputSource(FramedSource* inputSource,
-		    u_int8_t streamId, int mpegVersion, int16_t PID) {
+		    u_int8_t streamId, int mpegVersion, int16_t PID, unsigned bufferSize) {
   if (inputSource == NULL) return;
-  fInputSources = new InputESSourceRecord(*this, inputSource, streamId,
-					  mpegVersion, fInputSources, PID);
+  fInputSources = new InputESSourceRecord(*this, inputSource, bufferSize, 
+					  streamId, mpegVersion, fInputSources, PID);
 }
 
 
@@ -158,11 +159,12 @@ void MPEG2TransportStreamFromESSource
 InputESSourceRecord
 ::InputESSourceRecord(MPEG2TransportStreamFromESSource& parent,
 		      FramedSource* inputSource,
+		      unsigned bufferSize,
 		      u_int8_t streamId, int mpegVersion,
 		      InputESSourceRecord* next, int16_t PID)
   : fNext(next), fParent(parent), fInputSource(inputSource),
     fStreamId(streamId), fMPEGVersion(mpegVersion), fPID(PID) {
-  fInputBuffer = new unsigned char[INPUT_BUFFER_SIZE];
+  fInputBuffer = new unsigned char[bufferSize ? bufferSize : INPUT_BUFFER_SIZE];
   reset();
 }
 
diff -Naurdp live.2016.05.20.orig/liveMedia/include/MPEG2TransportStreamFromESSource.hh live.2016.05.20/liveMedia/include/MPEG2TransportStreamFromESSource.hh
--- live.2016.05.20.orig/liveMedia/include/MPEG2TransportStreamFromESSource.hh	2016-05-20 02:11:05.000000000 +0200
+++ live.2016.05.20/liveMedia/include/MPEG2TransportStreamFromESSource.hh	2016-06-09 15:15:03.000000000 +0200
@@ -30,9 +30,9 @@ class MPEG2TransportStreamFromESSource:
 public:
   static MPEG2TransportStreamFromESSource* createNew(UsageEnvironment& env);
 
-  void addNewVideoSource(FramedSource* inputSource, int mpegVersion, int16_t PID = -1);
+  void addNewVideoSource(FramedSource* inputSource, int mpegVersion, int16_t PID = -1, unsigned bufferSize = 0);
       // Note: For MPEG-4 video, set "mpegVersion" to 4; for H.264 video, set "mpegVersion" to 5.
-  void addNewAudioSource(FramedSource* inputSource, int mpegVersion, int16_t PID = -1);
+  void addNewAudioSource(FramedSource* inputSource, int mpegVersion, int16_t PID = -1, unsigned bufferSize = 0);
       // Note: In these functions, if "PID" is not -1, then it (currently, just the low 8 bits)
       // is used as the stream's PID.  Otherwise (if "PID" is -1) the 'stream_id' is used as
       // the PID.
@@ -43,7 +43,7 @@ protected:
   virtual ~MPEG2TransportStreamFromESSource();
 
   void addNewInputSource(FramedSource* inputSource,
-			 u_int8_t streamId, int mpegVersion, int16_t PID = -1);
+			u_int8_t streamId, int mpegVersion, int16_t PID = -1, unsigned bufferSize = 0);
   // used to implement addNew*Source() above
 
 private:


-- 
					    Gilles.
https://click-hack.org


More information about the live-devel mailing list