Skip to content

NullPointerException in TsExtractor #2149

@clhols

Description

@clhols

With some of my streams I get the following NullPointerException with r2.0.4:

E/LoadTask: Unexpected exception loading stream
    java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.exoplayer2.extractor.ts.ElementaryStreamReader.init(com.google.android.exoplayer2.extractor.ExtractorOutput, com.google.android.exoplayer2.extractor.ts.ElementaryStreamReader$TrackIdGenerator)' on a null object reference
        at com.google.android.exoplayer2.extractor.ts.TsExtractor$PmtReader.consume(TsExtractor.java:470)
        at com.google.android.exoplayer2.extractor.ts.TsExtractor.read(TsExtractor.java:242)
        at com.google.android.exoplayer2.source.hls.HlsMediaChunk.load(HlsMediaChunk.java:180)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:295)

It happens because streamReaderFactory.createStreamReader in TxExtractor returns null in the following snippet:

pesPayloadReader = streamReaderFactory.createStreamReader(streamType, esInfo);
pesPayloadReader.init(output, new TrackIdGenerator(trackId, MAX_PID_PLUS_ONE));

The reason why createStreamReader returns null is because the flag FLAG_IGNORE_H264_STREAM in DefaultStreamReaderFactory is set. The reason why that flag is set is due to the following lines in HlsChunkSource:

// Sometimes AAC and H264 streams are declared in TS chunks even though they don't really
// exist. If we know from the codec attribute that they don't exist, then we can
// explicitly ignore them even if they're declared.
if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) {
  esReaderFactoryFlags |= DefaultStreamReaderFactory.FLAG_IGNORE_AAC_STREAM;
}
**if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) {
  esReaderFactoryFlags |= DefaultStreamReaderFactory.FLAG_IGNORE_H264_STREAM;
}**

After debugging this I see that the "codecs" variable only contains the audio codec mp4a.40.2. Other streams that doesn't have this issue lists both the video and audio codecs.

So I looked into the TS data and it is:

GET /session/b40d3704-ba06-11e6-8abc-90b11c442bb3/zfynsx/c/9/5/1/c_283_95119f3b0523409cbf735f15b01ec35b/11_17.m3u8 HTTP/1.1

HTTP/1.1 200 OK
Content-Length: 645
Cache-Control: no-cache
Connection: Keep-Alive
Date: Sun, 04 Dec 2016 09:47:43 GMT
Content-Type: application/x-mpegURL

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=6190800,CODECS="mp4a.40.2"
tv11.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=4320800,CODECS="mp4a.40.2"
tv12.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2820400,CODECS="mp4a.40.2"
tv13.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1720364,CODECS="mp4a.40.2"
tv14.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1170400,CODECS="mp4a.40.2"
tv15.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=620364,CODECS="mp4a.40.2"
tv16.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=290400,CODECS="mp4a.40.2"
tv17.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=61600,CODECS="mp4a.40.2"
tv18.m3u8

And when a stream is chosen, the you get this:

GET /session/b40d3704-ba06-11e6-8abc-90b11c442bb3/zfynsx/c/9/5/1/c_283_95119f3b0523409cbf735f15b01ec35b/tv15.m3u8 HTTP/1.1

HTTP/1.1 200 OK
Content-Length: 581
Cache-Control: no-cache
Connection: Keep-Alive
Date: Sun, 04 Dec 2016 09:47:43 GMT
Content-Type: application/x-mpegURL

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:12
#EXT-X-MEDIA-SEQUENCE:275842
#EXT-X-DISCONTINUITY-SEQUENCE:1
#EXTINF:12.000,
tv15_20161204T094540_275842.ts
#EXTINF:12.000,
tv15_20161204T094552_275843.ts
#EXTINF:12.000,
tv15_20161204T094604_275844.ts
#EXTINF:12.000,
tv15_20161204T094616_275845.ts
#EXTINF:12.000,
tv15_20161204T094628_275846.ts
#EXTINF:12.000,
tv15_20161204T094640_275847.ts
#EXTINF:12.000,
tv15_20161204T094652_275848.ts
#EXTINF:12.000,
tv15_20161204T094704_275849.ts
#EXTINF:12.000,
tv15_20161204T094716_275850.ts
#EXTINF:12.000,
tv15_20161204T094728_275851.ts


GET /session/b40d3704-ba06-11e6-8abc-90b11c442bb3/zfynsx/c/9/5/1/c_283_95119f3b0523409cbf735f15b01ec35b/tv15_20161204T094704_275849.ts HTTP/1.1

HTTP/1.1 200 OK
Content-Length: 1812320
Cache-Control: no-cache
Connection: Keep-Alive
Date: Sun, 04 Dec 2016 09:47:44 GMT
Content-Type: video/MP2T

So there is video in the stream.
I then tried to remove esReaderFactoryFlags |= DefaultStreamReaderFactory.FLAG_IGNORE_H264_STREAM in HlsChunkSource and then both video and audio plays just fine.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions