Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in TsExtractor #2149

Closed
clhols opened this issue Dec 4, 2016 · 4 comments
Closed

NullPointerException in TsExtractor #2149

clhols opened this issue Dec 4, 2016 · 4 comments
Assignees
Labels

Comments

@clhols
Copy link

clhols commented Dec 4, 2016

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.

@ojw28
Copy link
Contributor

ojw28 commented Dec 4, 2016

Already fixed in dev-v2: b2222f8

@ojw28 ojw28 closed this as completed Dec 4, 2016
@clhols
Copy link
Author

clhols commented Dec 4, 2016

Ok, but dev-v2 is still unable to play the video part of the stream. So what has replaced DefaultStreamReaderFactory.FLAG_IGNORE_H264_STREAM in dev-v2?

@ojw28
Copy link
Contributor

ojw28 commented Dec 4, 2016

If there's video in this stream then the HLS master playlist is in violation of the spec. From the HLS spec:

If an EXT-X-STREAM-INF tag or EXT-X-I-FRAME-STREAM-INF tag contains the CODECS attribute, the attribute value MUST include every media format [RFC6381] present in any Media Segment in any of the Renditions specified by the Variant Stream.

In your master playlist CODECS="mp4a.40.2" is indicating that only audio is present. The video codec needs to be listed there too. If the video codec were listed, we'd play the video part of the stream correctly.

@clhols
Copy link
Author

clhols commented Dec 4, 2016

Ok, I can't change the playlist, so I will have to fork the library and remove FLAG_IGNORE_H264_STREAM. Thanks for looking into it.

@google google locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants