Package com.wowza.wms.stream.publish
Class Publisher
- Object
-
- com.wowza.wms.stream.publish.Publisher
-
public class Publisher extends Object
Publisher: clientless stream publisher. This class can be used to publish raw video, audio and metadata packets to the Wowza Pro server. Here is a quick snippet of code that illustrates how to use it.
This code below will publish data the stream named "myStream". It will be streamed to the default virtual host and avaible at the rtmp address rtmp://[server-ip-address]/streamtest.
IVHost vhost = VHostSingleton.getInstance(VHost.VHOST_DEFAULT); Publisher publisher = Publisher.createInstance(vhost, "streamtest"); publisher.setFileExtension("flv"); publisher.setStreamType("live"); publisher.publish("myStream", "live"); // sit in a loop adding data boolean done = false; while(true) { AMFPacket amfPacket; // read packet from audio, video, data source // amfPacket = readPacketFromSomewhere(); switch (amfPacket.getType()) { case IVHost.CONTENTTYPE_AUDIO: publisher.addAudioData(amfPacket.getData(), amfPacket.getSize(), amfPacket.getTimecode()); break; case IVHost.CONTENTTYPE_VIDEO: publisher.addVideoData(amfPacket.getData(), amfPacket.getSize(), amfPacket.getTimecode()); break; case IVHost.CONTENTTYPE_DATA: publisher.addDataData(amfPacket.getData(), amfPacket.getSize(), amfPacket.getTimecode()); break; } if (done) break; } publisher.unpublish(); publisher.close();
Basic packet format: Audio: AAC [1-byte header] [1-byte codec config indicator (1 - audio data, 0 - codec config packet)] [n-bytes audio content or codec config data] All others [1-byte header] [n-bytes audio content] Below is the bit layout of the header byte of data (table goes from least significant bit to most significant bit): 1 bit Number of channels: 0 mono 1 stereo 1 bit Sample size: 0 8 bits per sample 1 16 bits per sample 2 bits Sample rate: 0 special or 8KHz 1 11KHz 2 22KHz 3 44KHz 4 bits Audio type: 0 PCM (big endian) 1 PCM (swf - ADPCM) 2 MP3 3 PCM (little endian) 4 Nelly Moser ASAO 16KHz Mono 5 Nelly Moser ASAO 8KHz Mono 6 Nelly Moser ASAO 7 G.711 ALaw 8 G.711 MULaw 9 Reserved a AAC b Speex f MP3 8Khz Note: For AAC the codec config data is generally a two byte packet that describes the stream. It must be published first. Here is the basic code to fill in the codec config data. AACFrame frame = new AACFrame(); int sampleRate = 22100; int channels = 2; frame.setSampleRate(sampleRate); frame.setRateIndex(AACUtils.sampleRateToIndex(sampleRate)); frame.setChannels(channels); frame.setChannelIndex(AACUtils.channelCountToIndex(sampleRate)); byte[] codecConfig = new byte[2]; AACUtils.encodeAACCodecConfig(frame, codecConfig, 0); Note: For AAC the header byte is always 0xaf Note: For Speex the audio data must be encoded as 16000Hz wide band Video: H.264 [1-byte header] [1-byte codec config indicator (1 - video data, 0 - codec config packet)] [3-byte time difference between dts and pts in milliseconds] [n-bytes video content or codec config data] All others [1-byte header] [n-bytes audio content] Below is the bit layout of the header byte of data (table goes from least significant bit to most significant bit): 4 bits Video type: 2 Sorenson Spark (H.263) 3 Screen 4 On2 VP6 5 On2 VP6A 6 Screen2 7 H.264 2 bit Frame type: 1 K frame (key frame) 2 P frame 3 B frame Note: H.264 codec config data is the same as the AVCc packet in a QuickTime container. Note: All timecode data is in milliseconds
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAudioData(byte[] data, int offset, int len, long timecode)
void
addAudioData(byte[] data, int offset, int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
Add audio datavoid
addAudioData(byte[] data, int len, long timecode)
Add audio datavoid
addAudioData(byte[] data, long timecode)
Add audio datavoid
addAudioDataInc(byte[] data, int offset, int len)
void
addDataData(byte[] data, int offset, int len, long timecode)
void
addDataData(byte[] data, int offset, int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
Add metadatavoid
addDataData(byte[] data, int len, long timecode)
Add metadatavoid
addDataData(byte[] data, long timecode)
Add metadatavoid
addDataDataInc(byte[] data, int offset, int len)
void
addVideoData(byte[] data, int offset, int len, long timecode)
Add video datavoid
addVideoData(byte[] data, int offset, int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
Add video datavoid
addVideoData(byte[] data, int len, long timecode)
Add video datavoid
addVideoData(byte[] data, long timecode)
Add video datavoid
addVideoDataInc(byte[] data, int offset, int len)
void
close()
Close the publisherstatic Publisher
createInstance(IApplicationInstance appInstance)
static Publisher
createInstance(IVHost vhost, String applicationName)
static Publisher
createInstance(IVHost vhost, String applicationName, String appInstanceName)
void
createStream()
Create underlying IMediaStream object if not already createdvoid
flush()
Flush the packets from the input buffer to the output bufferIApplicationInstance
getAppInstance()
String
getFileExtension()
Get the file extension (default flv)long
getLastAudioTimecode()
Get last audio timecode written through this publisher (millseconds).long
getLastDataTimecode()
Get last data timecode written through this publisher (millseconds).long
getLastGapAudioTimecode()
Get gap time from last audio timecode.long
getLastGapVideoTimecode()
Get gap time from last video timecode.long
getLastVideoTimecode()
Get last video timecode written through this publisher (millseconds).long
getMaxTimecode()
Highest timecode written through this publisher (millseconds).IMediaStream
getStream()
Get the media stream objectString
getStreamType()
boolean
isPublishDataEvents()
void
publish(String streamName)
Publish a stream (null to stop publishing)void
publish(String streamName, String howToPublish)
Start publishing a stream (streamName = null to stop).void
setFileExtension(String fileExtension)
Set the file extensionvoid
setPublishDataEvents(boolean publishDataEvents)
void
setStreamType(String streamType)
Set the stream type (default live)void
startAudioData(int len, long timecode)
void
startAudioData(int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
void
startDataData(int len, long timecode)
void
startDataData(int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
void
startVideoData(int len, long timecode)
void
startVideoData(int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
void
unpublish()
void
unregisterStreamFromStreamMap()
Remove the stream from MediaStreamMap
-
-
-
Method Detail
-
createInstance
public static Publisher createInstance(IVHost vhost, String applicationName, String appInstanceName)
-
createInstance
public static Publisher createInstance(IApplicationInstance appInstance)
-
getStream
public IMediaStream getStream()
Get the media stream object- Returns:
- media stream object
-
getStreamType
public String getStreamType()
-
setStreamType
public void setStreamType(String streamType)
Set the stream type (default live)- Parameters:
streamType
- stream type
-
publish
public void publish(String streamName)
Publish a stream (null to stop publishing)- Parameters:
streamName
- stream name
-
getFileExtension
public String getFileExtension()
Get the file extension (default flv)- Returns:
- file extension
-
setFileExtension
public void setFileExtension(String fileExtension)
Set the file extension- Parameters:
fileExtension
- file extension
-
getAppInstance
public IApplicationInstance getAppInstance()
-
unpublish
public void unpublish()
-
createStream
public void createStream()
Create underlying IMediaStream object if not already created
-
unregisterStreamFromStreamMap
public void unregisterStreamFromStreamMap()
Remove the stream from MediaStreamMap
-
publish
public void publish(String streamName, String howToPublish)
Start publishing a stream (streamName = null to stop). Valid howToPublish values are (live, record, append)- Parameters:
streamName
- stream namehowToPublish
- publish method (live, record, append)
-
addVideoData
public void addVideoData(byte[] data, long timecode)
Add video data- Parameters:
data
- datatimecode
- absolute timecode (milliseconds)
-
addVideoData
public void addVideoData(byte[] data, int len, long timecode)
Add video data- Parameters:
data
- datalen
- data lengthtimecode
- absolute timecode (milliseconds)
-
addVideoData
public void addVideoData(byte[] data, int offset, int len, long timecode)
Add video data- Parameters:
data
- dataoffset
- offsetlen
- data lengthtimecode
- absolute timecode (milliseconds)
-
addVideoData
public void addVideoData(byte[] data, int offset, int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
Add video data- Parameters:
data
- dataoffset
- offsetlen
- data lengthtimecode
- absolute timecode (milliseconds)extraData
- extra data
-
startVideoData
public void startVideoData(int len, long timecode)
-
startVideoData
public void startVideoData(int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
-
addVideoDataInc
public void addVideoDataInc(byte[] data, int offset, int len)
-
startAudioData
public void startAudioData(int len, long timecode)
-
startAudioData
public void startAudioData(int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
-
addAudioDataInc
public void addAudioDataInc(byte[] data, int offset, int len)
-
addAudioData
public void addAudioData(byte[] data, long timecode)
Add audio data- Parameters:
data
- datatimecode
- absolute timecode (milliseconds)
-
addAudioData
public void addAudioData(byte[] data, int len, long timecode)
Add audio data- Parameters:
data
- datalen
- data lengthtimecode
- absolute timecode (milliseconds)
-
addAudioData
public void addAudioData(byte[] data, int offset, int len, long timecode)
-
addAudioData
public void addAudioData(byte[] data, int offset, int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
Add audio data- Parameters:
data
- datalen
- data lengthoffset
- offsettimecode
- absolute timecode (milliseconds)
-
addDataData
public void addDataData(byte[] data, long timecode)
Add metadata- Parameters:
data
- datatimecode
- absolute timecode (milliseconds)
-
addDataData
public void addDataData(byte[] data, int len, long timecode)
Add metadata- Parameters:
data
- datalen
- data lengthtimecode
- absolute timecode (milliseconds)
-
addDataData
public void addDataData(byte[] data, int offset, int len, long timecode)
-
addDataData
public void addDataData(byte[] data, int offset, int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
Add metadata- Parameters:
data
- dataoffset
- offsetlen
- data lengthtimecode
- absolute timecode (milliseconds)
-
startDataData
public void startDataData(int len, long timecode)
-
startDataData
public void startDataData(int len, long timecode, java.util.Map<String,IAMFPacketExtraData> extraData)
-
addDataDataInc
public void addDataDataInc(byte[] data, int offset, int len)
-
flush
public void flush()
Flush the packets from the input buffer to the output buffer
-
close
public void close()
Close the publisher
-
getMaxTimecode
public long getMaxTimecode()
Highest timecode written through this publisher (millseconds).- Returns:
- highest timecode written through this publisher (millseconds)
-
getLastAudioTimecode
public long getLastAudioTimecode()
Get last audio timecode written through this publisher (millseconds).- Returns:
- last audio timecode written through this publisher (millseconds).
-
getLastGapAudioTimecode
public long getLastGapAudioTimecode()
Get gap time from last audio timecode.- Returns:
- gap time from audio timecode written throughtime this publisher (millseconds).
-
getLastVideoTimecode
public long getLastVideoTimecode()
Get last video timecode written through this publisher (millseconds).- Returns:
- last video timecode written through this publisher (millseconds).
-
getLastGapVideoTimecode
public long getLastGapVideoTimecode()
Get gap time from last video timecode.- Returns:
- gap time from video timecode written through this publisher (millseconds).
-
getLastDataTimecode
public long getLastDataTimecode()
Get last data timecode written through this publisher (millseconds).- Returns:
- last data timecode written through this publisher (millseconds).
-
isPublishDataEvents
public boolean isPublishDataEvents()
-
setPublishDataEvents
public void setPublishDataEvents(boolean publishDataEvents)
-
-