This project has moved and is read-only. For the latest updates, please go here.

Errors in som streams

Oct 7, 2016 at 11:00 AM
Can you tell me where to search? On some HLS streams i have this (and no image). On others works okay.
'AgHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\en-US\mscorlib.debug.resources.dll'. Module was built without symbols.
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
Unable to get us-ascii encoding
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
Unable to get Windows-1252 encoding
BufferingManager.Flush()
++++ Starting http://URL at 10/7/2016 12:03:06 PM +02:00.  Total memory: 3.05 MiB
TsMediaStreamSource.OpenMediaAsync()
Media OpenMediaAsyncCalled: Idle -> Opening at 10/7/2016 12:03:06 PM +02:00
Create PES Video stream (AVC video stream conforming to one or more profiles defined in Annex A of ITU-T Rec. H.264 | ISO/IEC 14496-10 or AVC video sub-bitstream as defined in 2.1.78) with PID 256
Exception thrown: 'System.FormatException' in SM.Media.DLL
Callback failed: Read past the end of the RBSP stream
Exception thrown: 'System.AggregateException' in SM.Media.DLL
Exception thrown: 'System.AggregateException' in mscorlib.ni.dll
CallbackReader.ReadAsync() failed: System.AggregateException: One or more errors occurred.
   System.FormatException: Read past the end of the RBSP stream
   System.FormatException: Read past the end of the RBSP stream

SmMediaManager.StartReaders() ReadAsync failed: System.AggregateException: One or more errors occurred.
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream

SmMediaManager.SetMediaState() Opening -> Error
SmMediaManager.CloseMediaAsync()
SmMediaManager.ReportState() state Error message System.AggregateException: One or more errors occurred.
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream

MediaStreamFacadeBase.MediaManagerOnStateChange() to Error: System.AggregateException: One or more errors occurred.
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream

SmMediaManager.CloseAsync()
SmMediaManager.SetMediaState() Error -> Closing
SmMediaManager.ReportState() state Closing message 
MediaStreamFacadeBase.MediaManagerOnStateChange() to Closing: 
SmMediaManager.CloseCleanupAsync()
TsMediaStreamSource.CloseMedia()
Media CloseMediaCalled: Opening -> Closing at 10/7/2016 12:03:08 PM +02:00
TsMediaStreamSource.CloseMediaHandler()
TsMediaStreamSource.CloseAsync(): close RanToCompletion
SmMediaManager.CloseReadersAsync() closing readers
Exception thrown: 'System.AggregateException' in mscorlib.ni.dll
Exception thrown: 'System.AggregateException' in mscorlib.ni.dll
MediaReader.StopReadingAsync(): callback reader stop failed: One or more errors occurred.
BufferingManager.Flush()
BufferingManager.ReportEndOfData()
BufferingManager.UpdateState done buffering (eof): duration none size none starting True memory 3.75 MiB
  Video count 1 size 0 newest  oldest 
BufferingManager.Shutdown()
SmMediaManager.CloseReadersAsync() readers closed
TsMediaStreamSource.Dispose()
Media DisposeCalled: Closing -> Idle at 10/7/2016 12:03:08 PM +02:00
The thread 0xfa8 has exited with code 0 (0x0).
SmMediaManager.DisposeReaders()
SmMediaManager.DisposeReaders() completed
Exception thrown: 'System.AggregateException' in mscorlib.ni.dll
SmMediaManager.SetMediaState() Closing -> Closed
SmMediaManager.ReportState() state Closed message 
MediaStreamFacadeBase.MediaManagerOnStateChange() to Closed: 
MediaStreamFacadeBase.StopMediaAsync()
Exception thrown: 'System.AggregateException' in mscorlib.ni.dll
SmMediaManager.StopMediaAsync()
SmMediaManager.CloseAsync() completed
CallbackReader.Close() failed: System.AggregateException: One or more errors occurred.
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream
   System.AggregateException: One or more errors occurred.
      System.FormatException: Read past the end of the RBSP stream
      System.FormatException: Read past the end of the RBSP stream
Oct 7, 2016 at 5:00 PM
Edited Oct 7, 2016 at 5:05 PM
Exception is here:
if (0 != seq_scaling_matrix_present_flag)
            {
                for (var i = 0; i < (3 != chroma_format_idc ? 8 : 12); ++i)
                {
                    var seq_scaling_list_present_flag = r.ReadBits(1);

                    if (0 != seq_scaling_list_present_flag)
                        ParseScalingList(r, i < 6 ? 16 : 64);
                }
            }
Second call to PraseSacllingList throws when loop is 20.

Commenting out this part of code fixes problem:
/*
            if (0 = seq_scaling_matrix_present_flag)
            {
                for (var i = 0; i < (3 != chroma_format_idc ? 8 : 12); ++i)
                {
                    var seq_scaling_list_present_flag = r.ReadBits(1);

                    if (0 != seq_scaling_list_present_flag)
                        ParseScalingList(r, i < 6 ? 16 : 16);
                }
            }
             */
Coordinator
Oct 7, 2016 at 7:15 PM
Could you capture and PM me a section of the stream that is causing this?

Thanks.
Oct 8, 2016 at 10:23 AM
Look, h264_parser gives this (part):
Seq Scaling List[0] Present Flag: 1
 delta: 8
 scaling list[0][0]: 16
 delta: -16
 scaling list[0][1]: 16
 scaling list[0][2]: 16
 scaling list[0][3]: 16
 scaling list[0][4]: 16
 scaling list[0][5]: 16
 scaling list[0][6]: 16
 scaling list[0][7]: 16
 scaling list[0][8]: 16
 scaling list[0][9]: 16
 scaling list[0][10]: 16
 scaling list[0][11]: 16
 scaling list[0][12]: 16
 scaling list[0][13]: 16
 scaling list[0][14]: 16
 scaling list[0][15]: 16
In your code delta gives value of 7 and then all further calcuations are wrong.
Oct 8, 2016 at 11:02 AM
Hacking this code to really bad version:
 void ParseScalingList(H264Bitstream r, int sizeOfScalingList)
        {
            var lastScale = 8;
            var nextScale = 8;

            for (var j = 0; j < sizeOfScalingList; ++j)
            {
                if (0 != nextScale)
                {
                    var delta_scale = r.ReadSe();
                    if (delta_scale == 7) delta_scale = 8;
                    nextScale = (lastScale + delta_scale + 256) % 256;
                    var useDefaultScalingMatrixFlag = (0 == j && 0 == nextScale);
                }

                var scalingList = 0 == nextScale ? lastScale : nextScale;
                lastScale = scalingList;
            }
        }
if (delta_scale == 7) delta_scale = 8; - this fix works but is ugly as hell. Maybe this will help you track the glitch faster.
Oct 8, 2016 at 11:47 AM
Edited Oct 8, 2016 at 11:49 AM
Another bug. In some encoders that produces SPS and PPS every IDR picture packet will not be playble using your lib.

In this situation the Configurator will never pass this line in ReaderCheckConfigure:
if (!_slicePicParameterSetId.HasValue || !_ppsSeqParameterSetId.HasValue || !_seqParameterSetId.HasValue)
            return false;
This happens i think that when setting those parameters in ReadPps and ReadSps you null it again even when they are already set:

I fixed that by this conditional in ReadPps and ReadSps functions so if SPS and PPS are already set - dont null them.
if (!_slicePicParameterSetId.HasValue)
{
            _slicePicParameterSetId = null;
}
and this:
if (!_ppsSeqParameterSetId.HasValue)
        {
            _ppsSeqParameterSetId = null;
        }
After those two patches (and this with delta wrong calculated) - 99% of my streams works in HLSView in my Win 8.1 App.
Coordinator
Oct 11, 2016 at 9:14 PM
MarcinW344 wrote:
Can you tell me where to search? On some HLS streams i have this (and no image). On others works okay.
      System.FormatException: Read past the end of the RBSP stream
The "read past the end" errors were from an off-by-one in H264BitstreamExtensions.ReadSe(). This should be fixed in ffea5d575c01.

I'll take a look at the SPS/PPS/IDR thing as well.

The only reason phonesm looks at the H.264 stream is that some streams, on at least some versions of WP8.1, play with an incorrect frame rate. Digging the frame rate out of the H.264 stream and setting it in the VideoStreamDescriptor avoids the issue (see WinRtMediaStreamConfigurator.CreateVideoDescriptor()).
Oct 17, 2016 at 1:39 PM
HI,
Yes, it fixed all problems. Almost all.
I have still some problems with VBR streams. Catch me on email if you want more details.
Coordinator
Oct 18, 2016 at 1:45 AM
MarcinW344 wrote:
HI,
Yes, it fixed all problems. Almost all.
I have still some problems with VBR streams. Catch me on email if you want more details.
PM or email a sample stream or two and I'll take a look.