Skip to content

Commit 35e6728

Browse files
authored
Merge branch 'master' into feature/vod-metadata-rest
2 parents af89581 + 969cdb7 commit 35e6728

File tree

11 files changed

+305
-50
lines changed

11 files changed

+305
-50
lines changed

src/main/java/io/antmedia/datastore/db/DataStore.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,37 +1227,38 @@ protected void updateStreamInfo(Broadcast broadcast, BroadcastUpdate newBroadcas
12271227
* They are used by InMemoryDataStore and MapDBStore, Mongodb implements the same functionality inside its own class.
12281228
*/
12291229
protected ArrayList<VoD> searchOnServerVod(ArrayList<VoD> broadcastList, String search){
1230-
1230+
12311231
long startTime = System.nanoTime();
12321232
if(search != null && !search.isEmpty()) {
1233+
String searchLower = search.toLowerCase();
12331234
for (Iterator<VoD> i = broadcastList.iterator(); i.hasNext(); ) {
12341235
VoD item = i.next();
1235-
if(item.getVodName() != null && item.getStreamName() != null && item.getStreamId() != null && item.getVodId() != null) {
1236-
if (item.getVodName().toLowerCase().contains(search.toLowerCase()) || item.getStreamId().toLowerCase().contains(search.toLowerCase()) || item.getStreamName().toLowerCase().contains(search.toLowerCase()) || item.getVodId().toLowerCase().contains(search.toLowerCase()))
1237-
continue;
1238-
else i.remove();
1239-
}
1240-
else if (item.getVodName()!= null && item.getVodId() != null){
1241-
if (item.getVodName().toLowerCase().contains(search.toLowerCase()) || item.getVodId().toLowerCase().contains(search.toLowerCase()))
1242-
continue;
1243-
else i.remove();
1244-
}
1245-
else{
1246-
if (item.getVodId() != null){
1247-
if (item.getVodId().toLowerCase().contains(search.toLowerCase()))
1248-
continue;
1249-
else i.remove();
1250-
}
1236+
if (matchesVodSearch(item, searchLower)) {
1237+
continue;
12511238
}
1239+
i.remove();
12521240
}
12531241
}
1254-
1242+
12551243
long elapsedNanos = System.nanoTime() - startTime;
12561244
addQueryTime(elapsedNanos);
12571245
showWarningIfElapsedTimeIsMoreThanThreshold(elapsedNanos, "searchOnServerVod");
12581246
return broadcastList;
12591247
}
12601248

1249+
private boolean matchesVodSearch(VoD item, String searchLower) {
1250+
return containsIgnoreCase(item.getVodId(), searchLower) ||
1251+
containsIgnoreCase(item.getVodName(), searchLower) ||
1252+
containsIgnoreCase(item.getStreamId(), searchLower) ||
1253+
containsIgnoreCase(item.getStreamName(), searchLower) ||
1254+
containsIgnoreCase(item.getDescription(), searchLower) ||
1255+
containsIgnoreCase(item.getMetadata(), searchLower);
1256+
}
1257+
1258+
private boolean containsIgnoreCase(String field, String searchLower) {
1259+
return field != null && field.toLowerCase().contains(searchLower);
1260+
}
1261+
12611262
protected List<VoD> sortAndCropVodList(List<VoD> vodList, int offset, int size, String sortBy, String orderBy)
12621263
{
12631264
long startTime = System.nanoTime();

src/main/java/io/antmedia/datastore/db/MongoStore.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,9 @@ public List<VoD> getVodList(int offset, int size, String sortBy, String orderBy,
825825
Filters.regex(STREAM_ID).caseInsensitive().pattern(".*" + search + ".*"),
826826
Filters.regex("streamName").caseInsensitive().pattern(".*" + search + ".*"),
827827
Filters.regex(VOD_ID).caseInsensitive().pattern(".*" + search + ".*"),
828-
Filters.regex("vodName").caseInsensitive().pattern(".*" + search + ".*")
828+
Filters.regex("vodName").caseInsensitive().pattern(".*" + search + ".*"),
829+
Filters.regex("description").caseInsensitive().pattern(".*" + search + ".*"),
830+
Filters.regex("metadata").caseInsensitive().pattern(".*" + search + ".*")
829831
)
830832
);
831833

@@ -973,14 +975,16 @@ public long getPartialVodNumber(String search)
973975
synchronized(vodLock) {
974976

975977
Query<VoD> query = vodDatastore.find(VoD.class);
976-
if (search != null && !search.isEmpty())
978+
if (search != null && !search.isEmpty())
977979
{
978980
logger.info("Server side search is called for {}", search);
979981
query.filter(Filters.or(
980982
Filters.regex("streamId").caseInsensitive().pattern(".*" + search + ".*"),
981983
Filters.regex("streamName").caseInsensitive().pattern(".*" + search + ".*"),
982984
Filters.regex(VOD_ID).caseInsensitive().pattern(".*" + search + ".*"),
983-
Filters.regex("vodName").caseInsensitive().pattern(".*" + search + ".*")
985+
Filters.regex("vodName").caseInsensitive().pattern(".*" + search + ".*"),
986+
Filters.regex("description").caseInsensitive().pattern(".*" + search + ".*"),
987+
Filters.regex("metadata").caseInsensitive().pattern(".*" + search + ".*")
984988
));
985989
}
986990
partialVodNumber = query.count();

src/main/java/io/antmedia/licence/ILicenceService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface ILicenceService {
99
public static final String LICENCE_TYPE_STANDARD = "standard";
1010
public static final String LICENCE_TYPE_OFFLINE = "offline";
1111
public static final String LICENCE_TYPE_MARKETPLACE = "marketplace";
12+
public static final String LICENCE_TYPE_LOCAL_SERVER = "local_server";
1213

1314

1415
public enum BeanName {

src/main/java/io/antmedia/muxer/RtmpMuxer.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class RtmpMuxer extends Muxer {
5353
boolean keyFrameReceived = false;
5454

5555
private AtomicBoolean preparedIO = new AtomicBoolean(false);
56+
private AtomicBoolean cancelOpenIO = new AtomicBoolean(false);
5657

5758
public RtmpMuxer(String url, Vertx vertx) {
5859
super(vertx);
@@ -141,32 +142,34 @@ public synchronized boolean prepareIO()
141142
return false;
142143
}
143144
preparedIO.set(true);
145+
cancelOpenIO.set(false);
144146
boolean result = false;
145147
//if there is a stream in the output format context, try to push
146148
if (getOutputFormatContext().nb_streams() > 0)
147149
{
148150
this.vertx.executeBlocking(() -> {
149-
150151
if (openIO())
151152
{
152153
if (bsfFilterContextList.isEmpty())
153154
{
154155
writeHeader();
155156
return null;
156157
}
157-
isRunning.set(true);
158-
setStatus(IAntMediaStreamHandler.BROADCAST_STATUS_BROADCASTING);
158+
if (!exitIfCancelled())
159+
{
160+
isRunning.set(true);
161+
setStatus(IAntMediaStreamHandler.BROADCAST_STATUS_BROADCASTING);
162+
}
163+
159164
}
160165
else
161166
{
162167
clearResource();
163168
setStatus(IAntMediaStreamHandler.BROADCAST_STATUS_FAILED);
164169
logger.error("Cannot initializeOutputFormatContextIO for rtmp endpoint:{}", url);
165170
}
166-
171+
167172
return null;
168-
169-
170173
}, false);
171174

172175
result = true;
@@ -210,19 +213,24 @@ public synchronized boolean writeHeader() {
210213
*/
211214
@Override
212215
public synchronized void writeTrailer() {
216+
cancelOpenIO.set(true);
213217
if(headerWritten){
214218
super.writeTrailer();
215219
trailerWritten = true;
216220
}
217221
else{
218222
logger.info("Not writing trailer because header is not written yet");
223+
clearResource();
219224
}
220225
setStatus(IAntMediaStreamHandler.BROADCAST_STATUS_FINISHED);
221226
}
222227

223228
@Override
224229
public synchronized void clearResource() {
225230
super.clearResource();
231+
if (!headerWritten) {
232+
preparedIO.set(false);
233+
}
226234
/**
227235
* Don't free the allocatedExtraDataPointer because it's internally deallocated
228236
*
@@ -235,6 +243,15 @@ public synchronized void clearResource() {
235243
//allocatedExtraDataPointer is freed when the context is closing
236244
}
237245

246+
private boolean exitIfCancelled() {
247+
if (!cancelOpenIO.get()) {
248+
return false;
249+
}
250+
logger.info("RTMP muxer openIO cancelled for {}", url);
251+
clearResource();
252+
return true;
253+
}
254+
238255
/**
239256
* {@inheritDoc}
240257
*/

src/main/java/io/antmedia/settings/ServerSettings.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public class ServerSettings implements ApplicationContextAware, Serializable {
101101

102102
private static final String RTMPS_ENABLED = "rtmps.enabled";
103103

104+
private static final String LOCAL_LICENCE_SERVER_IP = "server.localLicenceServerIp";
105+
104106
/**
105107
* The IP filter that is allowed to access the web panel of Ant Media Server
106108
*/
@@ -277,6 +279,13 @@ public class ServerSettings implements ApplicationContextAware, Serializable {
277279
private String serverStatusWebHookURL;
278280

279281

282+
/**
283+
* Customer License Key
284+
*/
285+
@Value( "${"+LOCAL_LICENCE_SERVER_IP+":#{null}}" )
286+
private String localLicenceServerIps;
287+
288+
280289
public String getJwksURL() {
281290
return jwksURL;
282291
}
@@ -697,4 +706,11 @@ public void setRtmpsEnabled(boolean rtmpsEnabled) {
697706
ServerSettings.rtmpsEnabled = rtmpsEnabled;
698707
}
699708

709+
public String getLocalLicenceServerIps() {
710+
return localLicenceServerIps;
711+
}
712+
713+
public void setLocalLicenceServerIps(String localLicenceServerIps) {
714+
this.localLicenceServerIps = localLicenceServerIps;
715+
}
700716
}

src/main/java/io/antmedia/streamsource/StreamFetcherManager.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,23 +540,20 @@ public void controlStreamFetchers(boolean restart) {
540540

541541
//get the updated broadcast object
542542
Broadcast broadcast = datastore.get(streamScheduler.getStreamId());
543-
544-
if (broadcast != null && AntMediaApplicationAdapter.PLAY_LIST.equals(broadcast.getType())) {
545-
//if it's playlist, continue
543+
544+
if (broadcast != null && AntMediaApplicationAdapter.PLAY_LIST.equals(broadcast.getType())) {
545+
// For playlists, only check auto-stop if autoStartStopEnabled is true
546+
if (broadcast.isAutoStartStopEnabled() && isToBeStoppedAutomatically(broadcast)) {
547+
logger.info("Auto-stopping playlist {} because no viewers are watching", streamScheduler.getStreamId());
548+
stopPlayList(streamScheduler.getStreamId());
549+
}
546550
continue;
547551
}
548-
552+
549553
boolean autoStop = false;
550-
if (restart || broadcast == null ||
551-
(autoStop = isToBeStoppedAutomatically(broadcast)))
554+
if (restart || broadcast == null ||
555+
(autoStop = isToBeStoppedAutomatically(broadcast)))
552556
{
553-
//logic of If condition is
554-
555-
// stop it if it's restart = true
556-
// or
557-
// brodcast == null because it means stream is deleted
558-
// or
559-
// autoStop
560557

561558
logger.info("Calling stop stream {} due to restart -> {}, broadcast is null -> {}, auto stop because no viewer -> {}",
562559
streamScheduler.getStreamId(), restart, broadcast == null, autoStop);

src/main/java/io/antmedia/websocket/WebSocketCommunityHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ else if (cmd.equals(WebSocketConstants.STOP_COMMAND)) {
153153
else if (cmd.equals(WebSocketConstants.PING_COMMAND)) {
154154
sendPongMessage(session);
155155
}
156-
else if (cmd.equals(WebSocketConstants.GET_STREAM_INFO_COMMAND) || cmd.equals(WebSocketConstants.PLAY_COMMAND))
156+
else if (cmd.equals(WebSocketConstants.GET_STREAM_INFO_COMMAND) || cmd.equals(WebSocketConstants.PLAY_COMMAND))
157157
{
158158
sendNotFoundJSON(streamId, session);
159159
}
@@ -166,7 +166,6 @@ else if (cmd.equals(WebSocketConstants.GET_STREAM_INFO_COMMAND) || cmd.equals(We
166166
}
167167

168168
}
169-
170169

171170
private void startRTMPAdaptor(Session session, final String streamId, boolean enableVideo) {
172171
int rtmpPort = appAdaptor.getServerSettings().getRtmpPort();

0 commit comments

Comments
 (0)