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

Add configuration property 'streamPublisherPassPlaylistAttributesAsMetadata' #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import com.wowza.wms.amf.AMFDataObj;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -54,13 +55,15 @@ private class ScheduledItem implements Comparable<ScheduledItem>
private Timer timer;
private Date start;
private Playlist playlist;
private Map<String, String> playlistMetadata;
private Stream stream;

public ScheduledItem(IApplicationInstance appInstance, Date start, Playlist playlist, Stream stream)
public ScheduledItem(IApplicationInstance appInstance, Date start, Playlist playlist, Map<String, String> playlistMetadata, Stream stream)
{
this.appInstance = appInstance;
this.start = start;
this.playlist = playlist;
this.playlistMetadata = playlistMetadata;
this.stream = stream;
timer = new Timer();
}
Expand All @@ -86,6 +89,15 @@ public void run()
{
playlist.open(stream);
logger.info(CLASS_NAME + " Scheduled stream is now live: " + stream.getName());

if (playlistMetadata != null && playlistMetadata.size() > 0)
{
AMFDataObj amfData = new AMFDataObj();
for (Map.Entry<String, String> m : playlistMetadata.entrySet())
amfData.put(m.getKey(), m.getValue());
stream.getPublisher().getStream().sendDirect("onMetaData", amfData);
}

removeFromList();
timer = null;
}
Expand Down Expand Up @@ -362,7 +374,9 @@ public String loadSchedule(IApplicationInstance appInstance) throws Exception
timeOffsetBetweenItems = props.getPropertyInt(PROP_NAME_PREFIX + "TimeOffsetBetweenItems", timeOffsetBetweenItems);
boolean updateMetadata = serverProps.getPropertyBoolean(PROP_NAME_PREFIX + "UpdateMetadataOnNewItem", true);
updateMetadata = props.getPropertyBoolean(PROP_NAME_PREFIX + "UpdateMetadataOnNewItem", updateMetadata);

String metadataPlaylistAttributes = serverProps.getPropertyStr(PROP_NAME_PREFIX + "PassPlaylistAttributesAsMetadata");
metadataPlaylistAttributes = props.getPropertyStr(PROP_NAME_PREFIX + "PassPlaylistAttributesAsMetadata", metadataPlaylistAttributes);

String storageDir = appInstance.getStreamStorageDir();
try
{
Expand Down Expand Up @@ -481,6 +495,18 @@ public String loadSchedule(IApplicationInstance appInstance) throws Exception
if (streamName.length() == 0)
continue;

Map<String, String> playlistMetadata = null;
if (metadataPlaylistAttributes != null)
{
playlistMetadata = new HashMap<>();
for (String playlistAttribute : metadataPlaylistAttributes.split(","))
{
if (!e.hasAttribute(playlistAttribute))
continue;
playlistMetadata.put(playlistAttribute, e.getAttribute(playlistAttribute));
}
}

Playlist playlist = new Playlist(streamName);
playlist.setRepeat((e.getAttribute("repeat").equals("false")) ? false : true);

Expand Down Expand Up @@ -531,7 +557,7 @@ public String loadSchedule(IApplicationInstance appInstance) throws Exception
stream.setStartLiveOnPreviousKeyFrame(startLiveOnPreviousKeyFrame);
stream.setStartLiveOnPreviousBufferTime(startLiveOnPreviousBufferTime);
stream.setTimeOffsetBetweenItems(timeOffsetBetweenItems);
ScheduledItem schedule = new ScheduledItem(appInstance, startTime, playlist, stream);
ScheduledItem schedule = new ScheduledItem(appInstance, startTime, playlist, playlistMetadata, stream);
schedules.add(schedule);
logger.info(CLASS_NAME + " Scheduled: " + stream.getName() + " for: " + scheduled);
}
Expand Down