简体   繁体   English

Wowza流时间测量而不会增加额外的线程

[英]Wowza stream time measurement without spamming additional threads

I'm trying to write module which will monitor how long did user watch stream. 我正在尝试编写模块来监视用户观看视频流的时间。 It's not live stream, but a video on demand. 它不是实时流,而是点播视频。

My question is what is most efficient way to do so. 我的问题是最有效的方法是什么。 I went this route: 我走了这条路:

created class that implements IMediaStreamActionNotify2 and then when onPlay event is triggered I would create new thread that would periodically check for elapsed time since the start of the stream and update duration variable. 创建的实现IMediaStreamActionNotify2类,然后在触发onPlay事件时,我将创建一个新线程,该线程将定期检查IMediaStreamActionNotify2开始以来经过的时间并更新duration变量。

This is the way I decided to run additional thread: 这是我决定运行其他线程的方式:

BalanceTimerMonitor btm = new BalanceTimerMonitor(...);

ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(btm, 0, 5, TimeUnit.SECONDS);

BalanceTimerMonitor implements Runnable BalanceTimerMonitor实现Runnable

Now all of this works, but I'm concerned about amount of new threads created for every stream, since I assume that each stream already runs as separate thread from main wowza app. 现在所有这些工作正常,但是我担心为每个流创建新线程的数量,因为我假设每个流已经作为独立于主wowza应用程序的线程运行。 Will this big amount of threads slow down my server? 如此大量的线程会降低我的服务器的速度吗? Is there another more elegant way of measuring stream duration? 还有另一种更优雅的方式来测量流持续时间吗?

My approach is that I have a single thread that loops over the connected clients and the Wowza API allows me to query the elapsed time for each connected client. 我的方法是,我有一个线程在连接的客户端上循环,并且Wowza API允许我查询每个连接的客户端的经过时间。 I use the same trick in another project, but in that case, I don't deal with the identity of players. 我在另一个项目中使用了相同的技巧,但是在那种情况下,我不处理玩家的身份。 And you can use IClient.getTimeRunningSeconds() to get the time, don't need to administer it on your own. 而且,您可以使用IClient.getTimeRunningSeconds()来获取时间,而无需自己进行管理。 Hope it helped! 希望能有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM