Hello,
I'm working on an application that receives raw H264 stream from a socket, decode it and display on a SurfaceView. Since the H264 stream has no need to extract, no transport protocol like RTP, it just transports from my hardware with a socket to my application.
I'd try to extend a MediaSource, a MediaPeriod, Timeline, SampleStream, Loadable, and it still not works now, cause ExoPlayer has so many class I should extend, I'm a little lost. Am I in the right way? Waiting for your reply.
Thanks.
One way to do this is to implement a DataSource that reads from the socket and an Extractor that parses the stream. Then you can use those with the provided ExtractorMediaSource by constructing it with a custom DataSourceFactory and ExtractorsFactory that return instances of your components.
Your Extractor implementation will need to split up the incoming stream into samples. If it's an Annex B bytestream you can probably just copy Ac3Extractor, make sniff return true and use an H264Reader instead of an Ac3Reader. There will be a few more details to work out, like how to set timing information on output samples (via H264Reader.packetStarted), but hopefully this is useful as a starting point.
I have made it as you said, it works well.
Thank you so much!
Most helpful comment
One way to do this is to implement a
DataSourcethat reads from the socket and anExtractorthat parses the stream. Then you can use those with the providedExtractorMediaSourceby constructing it with a customDataSourceFactoryandExtractorsFactorythat return instances of your components.Your
Extractorimplementation will need to split up the incoming stream into samples. If it's an Annex B bytestream you can probably just copyAc3Extractor, makesniffreturn true and use anH264Readerinstead of anAc3Reader. There will be a few more details to work out, like how to set timing information on output samples (viaH264Reader.packetStarted), but hopefully this is useful as a starting point.