Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Module for authorizing requests for all stream types - getting the client request url

  1. #11

    Default

    Hi Sean,

    ILogNotify is called before every log event is written to the actual log files. At this point, you can manipulate what is actually logged by adding fields etc. it is also a good place to capture events that are not visible anywhere else but if the event is available somewhere then you should use that instead as you will have more control.

    I think the bit you are struggling with is the event flow for different types of connections. Http has create and destroy events. You can access most of the info you need in these 2 events. In the logs, you will see stream events like play and stop events but these are pseudo events based on the actual create & destroy events. Rtmp has a lot more events and they are split into client and stream events. Client events are connect-pending, connect, disconnect. Stream events are create, play, stop, destroy. There are also pause, seek, publish & unpublished events. All these events are based on actual calls from the rtmp client.

    Stream info is only available between stream create and stream destroy. The stream name is only available once play has been fired.

    From a client perspective, you need to store any stream info you want to keep in something that is available to the client after the stream is destroyed. By the time onDisconnect is called for the client, the stream has already been destroyed. Using client properties or a custom class is the best way to do it. If you have a lot of info to store then have a custom class that stores it and then reference it in client properties instead of each value separately. The class instance can be updated at any time then passed on to your web service handler once the disconnect event is fired.

    For sending info to any external endpoint, web service or db etc, it is best to use a custom ThreadPoolExecutor with a LinkedBlockingQueue for the work queue. This way , you create a task that uploads the data and then pass that task to the executor. It processes them using its own thread pool and doesn't tie up the thread that is trying to shut down the client connection. This is very important as it will slow down wowza very quickly if it has to wait for external services to complete an operation. You can size the thread pool to suit the capabilities of the web service and the load on wowza. A size of 1 will use a single thread to work through the queue in order of arrival.

    Roger.

  2. #12

    Default

    Roger,
    The more I interact with you guys, the more impressed I am with the Wowza support staff!

    You're right about my main problem being the event flow. The HTTP Streams are easy enough; it's RTMP I'm struggling with because if the stateful connection. Is onDisconnect the best place to trigger that logging call? I need to log data transfer (and a bunch of other things) against each video watched, and I haven't accounted for playlists. I didn't think of the scenario wherein the user might watch more than one video in the course of a single connection. So, my question is, what is the best way to capture that data as they move from video to video? It's important that I'm able to log at that level, because the system we're building then compiles that data and is able to show stats on a file by file basis...

    Thanks for the idea about the custom class to hold stream properties; I'll definitely do that...

    Regarding the performance issues, I'm glad that you mentioned the ThreadPoolExecutor. I actually mentioned to Richard in a different thread that I am planning to use an ExecutorService with a CachedThreadPool to make the web service calls async. I was thinking of creating a singleton that would hold the ExecutorService, and then delegate the webservice calls to that. What do you think? I'll have a look at the LinkedBlockingQueue; not sure what that is. It's been 6 years since I developed in Java (been doing .net/c# for the last 6 - 7 years), so I'm not as versed as I should be.

    Thanks,
    Sean

  3. #13

    Default

    Hi Sean,

    If you are just logging stream stats then onStreamDestroy would probably be the best place to gather the info. You will need to detect if it is a play stream as opposed to a publish stream and then get the client id or session id to link it to that.

    public void onStreamDestroy(IMediaStream stream) {
    	 if(stream.isPlay()) {
    		// get required stream info.
    	
    		WMSProperties props = null;
    		IClient client = stream.getClient();
    		IHTTPStreamerSession httpSession = stream.getHttpStreamerSession();
    		RTPStream rtpStream = stream.getRTPStream();
    		
    		if(client != null) {
    			props = client.getProperties();
    			// get client info.
    		} else if(httpSession != null) {
    			props = httpSession.getProperties();
    			// get session info.
    		} else if(rtpStream != null) {
    			props = rtpStream.getSession().getProperties();
    			// get session info.
    		}
    		
    		if(props != null) {
    			// store info in props.
    		}
    		
    		// or send it to web service.
    	}
    }
    If you don't need any more info then you could send it to the web service at this point. Most of the time, the session will be destroyed shortly after so there would only be a few more seconds and probably only a few more bytes transfered.

    Any type of Executor service would work but there would be different performance factors. The LinkedBlockingQueue is a standard fifo queue that will block on the take method until there is something available. It is used a lot in a producer - consumer setup.

    Roger.

  4. #14

    Default

    Hi Roger,
    So I'm attempting to execute the code you wrote above, with some small corrections:

    	public void onStreamDestroy(IMediaStream stream) {
    		if(stream.isPlay()) {
    			// get required stream info.
    			try
    			{
    				WMSProperties props = null;
    				IClient client = stream.getClient();
    				IHTTPStreamerSession httpSession = stream.getHTTPStreamerSession();
    				RTPStream rtpStream = stream.getRTPStream();
    				
    				if(client != null) {
    					props = client.getProperties();
    					// get client info.
    				} 
    				else if(httpSession != null) {
    					props = httpSession.getProperties();
    					// get session info.
    				} 
    				else if(rtpStream != null) {
    					props = rtpStream.getSession().getProperties();
    					// get session info.
    				}
    		 
    				if(props != null) {
    					// store info in props.
    				}
    		 
    				// or send it to web service.
    			}
    			catch (Exception e)
    			{
    				getLogger().error("Error in onStreamDestroy method of MediaCommanderAuthorizationModule", e);
    			}
    		}
    	}
    When I try to execute this code, it just stops executing when it hits this line: props=client.getProperties();

    It's late so I might be missing something stupid, but I'm getting pretty annoyed at this. It's not raising an exception or anything, it just exits the method the moment that line is executed. I don't understand this behavior of the eclipse debugger. Am I missing something obvious?

    Thanks,
    Sean
    Last edited by seanngreen; 02-18-2013 at 01:22 AM.

  5. #15

    Default

    Hi Sean,

    I probably didn't make it clear but each of the comments is areas where you need to add your own code.

    // get stream info. Gather the info you need from the stream object.

    // get client info. Gather the info about the client if it exists.

    // get session info. Same for the sessions.

    // store the info in props. Store the info gathered above of later use.

    // or send it to the web service.

    Does this make it clearer? You need to fill in the gaps.

    Roger.

  6. #16

    Default

    Hi Roger,
    I understand that perfectly. The first thing I do when someone gives me code is to paste it in and run it through once in debug mode before I start adding my own code; that's where I was last night... Anyway, the problem I was asking about is not a problem, rather it was a lack of understanding of the eclipse debugger on my part. I figured it out within a few minutes this morning. Sorry to have wasted your time...

    Thanks,
    Sean

  7. #17

    Default

    Hi Roger,
    In an earlier post in this thread, you wrote:

    You can set Wowza to use ipv4 only by setting JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" in setenv.sh or setenv.bat. This will cause Wowza to bind to ipv4 addresses only.

    I just got around to trying this. I uncommented this line in the setenv.bat:

    set JAVA_OPTS=%JAVA_OPTS% -Djava.net.preferIPv4Stack=true

    Restarted wowza, and then restarted my computer. Still giving me ipv6 addresses...

  8. #18

    Default

    Hi,

    I am using a Mac and when I use that setting, I get connected with an ipv4 address.

    Are you running Wowza from within the IDE using debug? If that is the case then you need to make the setting in your Debug Configuration for your project. It doesn't use setenv.bat when run from here.

    Run/Debug Configurations... Arguments tab for your project, VM Arguments. You should see some there already. Add it on a new line and save.

    Roger.

  9. #19

    Default

    Yep, was running in debug. Your suggestion worked like a charm. Thanks!

  10. #20

    Default

    Another question. Can a HTTPStreamerSession span multipe streams, like in the case of a playlist, or is a new session always created for each new stream? I'm finishing up that logging module we have talked about, and I'm triggering my logging at onStreamDestroy as you suggested. For the HTTPStreamers I'm using the IOperformance metrics at the session level and I want to make sure that is the right thing to do?

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Wowza module to start stream on HLS request
    By cipris in forum General Forum
    Replies: 4
    Last Post: 12-12-2014, 02:47 AM
  2. Samsung TV app: changing ordering of URL parameters for HLS requests
    By jules27 in forum Media Players and Devices Discussion
    Replies: 2
    Last Post: 06-19-2012, 05:00 PM
  3. Intercepting client requests for streams
    By michael401 in forum Server-side Modules and Code Samples Discussion
    Replies: 5
    Last Post: 02-26-2012, 08:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •