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

Backup stream #4033

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/main/java/io/antmedia/AntMediaApplicationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public Broadcast updateBroadcastStatus(String streamId, long absoluteStartTimeMs
if (broadcast == null)
{

broadcast = saveUndefinedBroadcast(streamId, null, this, IAntMediaStreamHandler.BROADCAST_STATUS_BROADCASTING, absoluteStartTimeMs, publishType, "", "");
broadcast = saveUndefinedBroadcast(streamId, null, this, IAntMediaStreamHandler.BROADCAST_STATUS_BROADCASTING, absoluteStartTimeMs, publishType, "", "", "");
}
else {

Expand All @@ -476,7 +476,7 @@ public ServerSettings getServerSettings()
}


public static Broadcast saveUndefinedBroadcast(String streamId, String streamName, AntMediaApplicationAdapter appAdapter, String streamStatus, long absoluteStartTimeMs, String publishType, String mainTrackStreamId, String metaData) {
public static Broadcast saveUndefinedBroadcast(String streamId, String streamName, AntMediaApplicationAdapter appAdapter, String streamStatus, long absoluteStartTimeMs, String publishType, String mainTrackStreamId, String metaData, String outputId) {
Broadcast newBroadcast = new Broadcast();
long now = System.currentTimeMillis();
newBroadcast.setDate(now);
Expand All @@ -485,6 +485,7 @@ public static Broadcast saveUndefinedBroadcast(String streamId, String streamNam
newBroadcast.setName(streamName);
newBroadcast.setMainTrackStreamId(mainTrackStreamId);
newBroadcast.setMetaData(metaData);
newBroadcast.setOutputId(outputId);
try {
newBroadcast.setStreamId(streamId);
newBroadcast.setPublishType(publishType);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/antmedia/datastore/db/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public boolean updateSourceQualityParameters(String id, String quality, double s
*/
public abstract List<Broadcast> getBroadcastList(int offset, int size, String type, String sortBy, String orderBy, String search);


/**
* Return the broadcast in data store, searches with outputId instead of streamId
* @param id
* @return broadcast
*/
public abstract List<Broadcast> getStreamsWithOutputId(String id);


/**
* Returns the Conference Room List in order
*
Expand Down Expand Up @@ -685,6 +694,18 @@ else if (sortBy.contentEquals("date"))
}

}
protected ArrayList<Broadcast> searchForOutputId(ArrayList<Broadcast> broadcastList, String outputId){
if(outputId != null && !outputId.isEmpty()) {
for (Iterator<Broadcast> i = broadcastList.iterator(); i.hasNext(); ) {
Broadcast item = i.next();
if (item.getOutputId() != null && !(item.getOutputId().isEmpty()) && item.getOutputId().equalsIgnoreCase(outputId))
continue;
else i.remove();
}
}
return broadcastList;
}

protected ArrayList<Broadcast> searchOnServer(ArrayList<Broadcast> broadcastList, String search){
if(search != null && !search.isEmpty()) {
for (Iterator<Broadcast> i = broadcastList.iterator(); i.hasNext(); ) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ public List<Broadcast> getBroadcastList(int offset, int size, String type, Strin
return sortAndCropBroadcastList(list, offset, size, sortBy, orderBy);
}

@Override
public List<Broadcast> getStreamsWithOutputId(String id) {

Collection<Broadcast> values = broadcastMap.values();

ArrayList<Broadcast> list = new ArrayList<>();

for (Broadcast broadcast : values)
{
if(broadcast.getOutputId() != null && !broadcast.getOutputId().isEmpty()){
list.add(broadcast);
}
}

if(id != null && !id.isEmpty()){
logger.info("Searching for outputId in broadcasts = {}", id);
list = searchForOutputId(list, id);
}
return list;
}




Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/antmedia/datastore/db/MapDBStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,24 @@ public List<Broadcast> getBroadcastListV2(String type, String search) {
return list;
}

public List<Broadcast> getStreamsWithOutputId(String id) {
ArrayList<Broadcast> list = new ArrayList<>();
synchronized (this) {
Collection<String> broadcasts = map.getValues();

for (String broadcastString : broadcasts) {
Broadcast broadcast = gson.fromJson(broadcastString, Broadcast.class);
list.add(broadcast);
}

if (id != null && !id.isEmpty()) {
logger.info("Searching for outputId in broadcasts = {}", id);
list = searchForOutputId(list, id);
}
return list;
}
}

@Override
public List<Broadcast> getBroadcastList(int offset, int size, String type, String sortBy, String orderBy, String search) {
List<Broadcast> list = null;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/io/antmedia/datastore/db/MongoStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,30 @@ public List<Broadcast> getBroadcastList(int offset, int size, String type, Strin
return null;
}

@Override
public List<Broadcast> getStreamsWithOutputId(String id) {
synchronized(this) {
try {
Query<Broadcast> query = datastore.find(Broadcast.class);

FindOptions findingOptions = new FindOptions();

if(id != null && !id.isEmpty())
{
logger.info("Searching for outputId in broadcasts = {}", id);
query.filter(Filters.or(
Filters.regex("outputId").caseInsensitive().pattern(".*" + id + ".*")
)
);
return query.iterator(findingOptions).toList();
}
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
}
}
return null;
}

public Datastore getDataStore() {
return datastore;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/antmedia/datastore/db/types/Broadcast.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class Broadcast {
@ApiModelProperty(value = "the id of the stream")
private String streamId;

/**
* id of the output, used for backing up the streams
*/
@ApiModelProperty(value = "the id of the stream")
private String outputId;

/**
* "finished", "broadcasting", "created"
*/
Expand Down Expand Up @@ -379,6 +385,13 @@ public void setStreamId(String id) throws Exception {
this.streamId = id;
}

public String getOutputId() {
return outputId;
}

public void setOutputId(String outputId) {
this.outputId = outputId;
}

public double getSpeed() {
return speed;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/antmedia/webrtc/api/IWebRTCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface IWebRTCClient {

public void removeWebRTCMuxer(IWebRTCMuxer webRTCMuxer);

public void stop();
public void stop(boolean stopCompletely);



Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/antmedia/websocket/WebSocketConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ private WebSocketConstants() {
* It's sent for conference in MCU mode
*/
public static final String MULTI_TRACK = "multitrack";

/**
* It's sent for back up streams
*/
public static final String OUTPUT_ID = "outputId";

/**
* It's sent for conference in legacy mode
Expand Down