Interface IMediaReader
-
- All Superinterfaces:
IMediaCoder,IMediaGenerator
public interface IMediaReader extends IMediaCoder
AnIMediaCoderthat reads and decodes media from anIContainer.An
IMediaReaderopens up a media container, reads packets from it, decodes the data, and then dispatches information about the data to any registeredIMediaListenerobjects. The main method of interest isreadPacket().Here's an example of a very simple program that prints out a line when the
IMediaReaderdecides to open a container.IMediaDebugListener myListener = new MediaListenerAdapter(){ public void onOpen(IMediaGenerator pipe) { System.out.println("opened: " + ((IMediaReader)pipe).getUrl()); } }; IMediaReader reader = ToolFactory.makeReader("myinputfile.flv"); reader.addListener(myListener); while(reader.readPacket() == null) ;And here's a slightly more involved example where we read a file and display it on screen in real-time:
IMediaReader reader = ToolFactory.makeReader("myinputfile.flv"); reader.addListener(ToolFactory.makeViewer()); while(reader.readPacket() == null) ;For examples of this class in action, see the com.avpkit.mediatool.demos package.
- Author:
- trebor, aclarke
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancanAddDynamicStreams()Report if the underlying media container supports adding dynamic streams.voidclose()Close thisIMediaCoder.intgetBufferedImageTypeToGenerate()Get theBufferedImagetype thisIMediaReaderwill generate.IContainergetContainer()Get the underlying mediaIContainerthat theIMediaCoderis reading from or writing to.java.lang.StringgetUrl()The URL from which theIContaineris being read or written to.voidopen()Open thisIMediaCoder.IErrorreadPacket()Decodes the next packet and calls all registeredIMediaListenerobjects.voidsetAddDynamicStreams(boolean streamsCanBeAddedDynamically)Set if the underlying media container supports adding dynamic streams.voidsetBufferedImageTypeToGenerate(int bufferedImageType)Asks theIMediaReaderto generateBufferedImageimages when callingIMediaListener.onVideoPicture(IVideoPictureEvent).voidsetCloseOnEofOnly(boolean closeOnEofOnly)voidsetQueryMetaData(boolean queryStreamMetaData)Set if the underlying media container will attempt to establish all meta data when the container is opened, which will potentially block until it has ready enough data to find all streams in a container.booleanwillCloseOnEofOnly()Report if close will called only if ERROR_EOF is returned fromreadPacket().booleanwillQueryMetaData()Report if the underlying media container will attempt to establish all meta data when the container is opened, which will potentially block until it has ready enough data to find all streams in a container.-
Methods inherited from interface com.avpkit.mediatool.IMediaCoder
isOpen
-
Methods inherited from interface com.avpkit.mediatool.IMediaGenerator
addListener, getListeners, removeListener
-
-
-
-
Method Detail
-
setAddDynamicStreams
void setAddDynamicStreams(boolean streamsCanBeAddedDynamically)
Set if the underlying media container supports adding dynamic streams. SeeIContainer.open(String, IContainer.Type, IContainerFormat, boolean, boolean). The default value for this is false.If set to false, the
IMediaReadercan assume no new streams will be added afteropen()has been called, and may decide to query the entire media file to find all meta data. If true thenIMediaReaderwill not read ahead; instead it will only query meta data for a stream when areadPacket()returns the first packet in a new stream. Note that aIMediaWritercan only initialize itself from aIMediaReaderthat has this parameter set to false.To have an effect, the MediaReader must not have been created with an already open
IContainer, and this method must be called before the first call toreadPacket().- Parameters:
streamsCanBeAddedDynamically- true if new streams may appear at any time during areadPacket()call- Throws:
java.lang.RuntimeException- if the media container is already open
-
canAddDynamicStreams
boolean canAddDynamicStreams()
Report if the underlying media container supports adding dynamic streams. SeeIContainer.open(String, IContainer.Type, IContainerFormat, boolean, boolean).- Returns:
- true if new streams can may appear at any time during a
readPacket()call - See Also:
setAddDynamicStreams(boolean)
-
setQueryMetaData
void setQueryMetaData(boolean queryStreamMetaData)
Set if the underlying media container will attempt to establish all meta data when the container is opened, which will potentially block until it has ready enough data to find all streams in a container. If false, it will only block to read a minimal header for this container format. SeeIContainer.open(String, IContainer.Type, IContainerFormat, boolean, boolean). The default value for this is true.To have an effect, the MediaReader must not have been created with an already open
IContainer, and this method must be called before the first call toreadPacket().- Parameters:
queryStreamMetaData- true if meta data is to be queried- Throws:
java.lang.RuntimeException- if the media container is already open
-
willQueryMetaData
boolean willQueryMetaData()
Report if the underlying media container will attempt to establish all meta data when the container is opened, which will potentially block until it has ready enough data to find all streams in a container. If false, it will only block to read a minimal header for this container format. SeeIContainer.open(String, IContainer.Type, IContainerFormat, boolean, boolean).- Returns:
- true meta data will be queried
- See Also:
setQueryMetaData(boolean)
-
setCloseOnEofOnly
void setCloseOnEofOnly(boolean closeOnEofOnly)
ShouldIMediaReaderautomatically callclose(), only if ERROR_EOF is returned fromreadPacket(). Otherwiseclose()is automatically called when any error value is returned. The default value for this is false.- Parameters:
closeOnEofOnly- true if meta data is to be queried- Throws:
java.lang.RuntimeException- if the media container is already open
-
willCloseOnEofOnly
boolean willCloseOnEofOnly()
Report if close will called only if ERROR_EOF is returned fromreadPacket(). Otherwise close is called when any error value is returned. The default value for this is false.- Returns:
- true if will close on ERROR_EOF only
- See Also:
setCloseOnEofOnly(boolean)
-
readPacket
IError readPacket()
Decodes the next packet and calls all registeredIMediaListenerobjects.If a complete
IVideoPictureorIAudioSamplesset are decoded, it will be dispatched to the listeners added to the media reader.This method will automatically call
open()if it has not already been called, and will automatically callclose()when it reads an error or end of file from the file. The default close behavior can be changed withsetCloseOnEofOnly(boolean).- Returns:
- null if there are more packets to read, otherwise return an IError
instance. If
IError.getType()==IError.Type.ERROR_EOFthen end of file has been reached.
-
setBufferedImageTypeToGenerate
void setBufferedImageTypeToGenerate(int bufferedImageType)
Asks theIMediaReaderto generateBufferedImageimages when callingIMediaListener.onVideoPicture(IVideoPictureEvent).NOTE: Only
BufferedImage.TYPE_3BYTE_BGRis supported today.If set to a non-negative value,
IMediaReaderwill resample any video data it has decoded into the right colorspace for theBufferedImage, and generate a newBufferedImageto pass in on eachIMediaListener.onVideoPicture(IVideoPictureEvent)call.- Parameters:
bufferedImageType- The buffered image type (e.g.BufferedImage.TYPE_3BYTE_BGR) you wantIMediaReaderto generate. Set to -1 to disable this feature.- See Also:
BufferedImage
-
getBufferedImageTypeToGenerate
int getBufferedImageTypeToGenerate()
Get theBufferedImagetype thisIMediaReaderwill generate.- Returns:
- the type, or -1 if disabled.
- See Also:
getBufferedImageTypeToGenerate()
-
getContainer
IContainer getContainer()
Get the underlying mediaIContainerthat theIMediaCoderis reading from or writing to. The returnedIContainercan be further interrogated for media stream details.- Specified by:
getContainerin interfaceIMediaCoder- Returns:
- the media container.
-
getUrl
java.lang.String getUrl()
The URL from which theIContaineris being read or written to.- Specified by:
getUrlin interfaceIMediaCoder- Returns:
- the source or destination URL.
-
open
void open()
Open thisIMediaCoder. This will open the internalIContainer. Typically the tool will open itself at the right time, but there may exist rare cases where the calling context may need to open the tool.- Specified by:
openin interfaceIMediaCoder
-
close
void close()
Close thisIMediaCoder. This will close allIStreamCoders explicitly opened by tool, then close the internalIContainer, again only if it was explicitly opened by tool.Typically the tool will close itself at the right time, but there are instances where the calling context may need to close the tool.
- Specified by:
closein interfaceIMediaCoder
-
-