Results 1 to 3 of 3

Thread: To display vod if requirements for live are not met

  1. #1

    Default To display vod if requirements for live are not met

    Im doing a filtering system where on certain time on the day, it will stop displaying live content and display a vod content.. Somehome, I need help on how to play vod at this address rtmp://localhost/vod/mp4:sample.mp4

    Should I put on onPlay() method ?

    PHP Code:
    package com.mycompany.wms.filterChannel;

    import java.sql.*;
    import com.wowza.wms.amf.*;
    import com.wowza.wms.application.*;
    import com.wowza.wms.client.*;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;

    public class 
    filterChannel extends ModuleBase {

        
        public 
    void onAppStart(IApplicationInstance appInstance)
        {
            
    // preload the driver class
            
    try 
            {
                Class.
    forName("com.mysql.jdbc.Driver").newInstance(); 
            } 
            catch (
    Exception e
            { 
                
    getLogger().error("Error loading: com.mysql.jdbc.Driver: "+e.toString());
            } 
        }
        

        public 
    void onConnect(IClient clientRequestFunction function, AMFDataList params
        {
            
            
            
    Connection conn null;
            try 
            {
                
    conn DriverManager.getConnection("jdbc:mysql:/xx.xx.xx.xx/vod?user=user&password=password");

                
    Statement stmt null;
                
    ResultSet rs null;

                try 
                {
                    
    stmt conn.createStatement();
                    
    rs stmt.executeQuery("SELECT count(*) as filter_count FROM `filterings` WHERE channel_id = 1  AND NOW() between date_start and date_end;");
                    if (
    rs.next() == true)
                    {
                        if (
    rs.getInt("filter_count") > 0)
                        {
                            
    // block , should play vod over here
                            //client.acceptConnection();
                        
    } else {
                            
                            
    client.acceptConnection();
                        }
                    }

                } 
                catch (
    SQLException sqlEx
                {
                    
    getLogger().error("sqlexecuteException: " sqlEx.toString());
                } 
                
    finally 
                
    {
                    
    // it is a good idea to release
                    // resources in a finally{} block
                    // in reverse-order of their creation
                    // if they are no-longer needed

                    
    if (rs != null
                    {
                        try 
                        {
                            
    rs.close();
                        } 
                        catch (
    SQLException sqlEx
                        {

                            
    rs null;
                        }
                    }

                    if (
    stmt != null
                    {
                        try 
                        {
                            
    stmt.close();
                        } 
                        catch (
    SQLException sqlEx
                        {
                            
    stmt null;
                        }
                    }
                }

                
    conn.close();
            } 
            catch (
    SQLException ex
            {
                
    // handle any errors
                
    System.out.println("SQLException: " ex.getMessage());
                
    System.out.println("SQLState: " ex.getSQLState());
                
    System.out.println("VendorError: " ex.getErrorCode());
            }

            
    getLogger().info("onConnect: " client.getClientId());
        }



  2. #2

    Default

    NVM, I got it solved.

    PHP Code:
    package com.mycompany.wms.filtering;

    import com.wowza.wms.amf.*;
    import com.wowza.wms.client.*;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;
    import java.sql.*;

    public class 
    channel extends ModuleBase {
        
        public 
    void play(IClient clientRequestFunction function, AMFDataList params) {
            
    getLogger().info("Filtering Channel");    
            
    // preload the driver class
            
    try 
            {
                Class.
    forName("com.mysql.jdbc.Driver").newInstance(); 
            } 
            catch (
    Exception e
            { 
                
    getLogger().error("Error loading: com.mysql.jdbc.Driver: "+e.toString());
            } 
            
    Connection conn null;
            try 
            {
                
    conn DriverManager.getConnection("jdbc:mysql://xx.xx.xx.xx/vod?user=myuser&password=mypassword");

                
    Statement stmt null;
                
    ResultSet rs null;

                try 
                {
                    
    stmt conn.createStatement();
                    
    String streamName getParamString(paramsPARAM1);
                    if( 
    streamName.equals("tv1") ){
                        
    getLogger().info("TV1 Filtering");
                        
    rs stmt.executeQuery("SELECT count(*) as filter_count FROM `filterings` WHERE channel_id = 1  AND NOW() between date_start and date_end;");
                        
                    }
                    
                    if( 
    streamName.equals("tv2") ){
                        
    getLogger().info("TV2 Filtering");
                        
    rs stmt.executeQuery("SELECT count(*) as filter_count FROM `filterings` WHERE channel_id = 2  AND NOW() between date_start and date_end;");
                
                    }                
                    
                    if (
    rs.next() == true)
                    {
                        if (
    rs.getInt("filter_count") > 0)
                        {
                            
    // block
                            
    getLogger().info("Deny Play");    
                            
    //String streamName = getParamString(params, PARAM1);
                            
    params.set(PARAM1"denied.stream");
                            
    invokePrevious(client, function, params);
                            
                        } else {
                            
                            
    //client.acceptConnection();
                            //String streamName = getParamString(params, PARAM1);
                            //params.set(PARAM1, "sample.mp4");
                            
    getLogger().info("Allow Play");    
                            
    invokePrevious(client, function, params);
                        }
                    }

                } 
                catch (
    SQLException sqlEx
                {
                    
    getLogger().error("sqlexecuteException: " sqlEx.toString());
                } 
                
    finally 
                
    {
                    
    // it is a good idea to release
                    // resources in a finally{} block
                    // in reverse-order of their creation
                    // if they are no-longer needed

                    
    if (rs != null
                    {
                        try 
                        {
                            
    rs.close();
                        } 
                        catch (
    SQLException sqlEx
                        {

                            
    rs null;
                        }
                    }

                    if (
    stmt != null
                    {
                        try 
                        {
                            
    stmt.close();
                        } 
                        catch (
    SQLException sqlEx
                        {
                            
    stmt null;
                        }
                    }
                }

                
    conn.close();
            } 
            catch (
    SQLException ex
            {
                
    // handle any errors
                
    System.out.println("SQLException: " ex.getMessage());
                
    System.out.println("SQLState: " ex.getSQLState());
                
    System.out.println("VendorError: " ex.getErrorCode());
            }
            
        } 
    // play

    when the channel is block, it will play streamName ="denied", which I pre start using Wowza StartupStreams

  3. #3

    Default

    Hi

    Your code will work but it is not very efficient and will not scale well.

    Database lookups can sometimes take a few seconds to return and this will affect the time taken for the play command to complete.

    Rather than do a lookup for every single play request, you should use a timer to do the database lookup for both channels on a regular basis and then cache the result locally.

    A timer runs in a separate thread so will not load up the main vhost threads. You would start in in onAppStart and shut it down in onAppStop. At regular intervals, it would do the database lookup for both channels and then store the result in local variables. The play command then just needs to check the local variable to see if it should play the original stream or the denied stream.

    	boolean tv1Allow = true;
    	boolean tv2Allow = true;
    
    	Timer timer;
    
    	public void onAppStart(IApplicationInstance appInstance) {
    		timer = new Timer();
    		timer.schedule(new TimerTask() {
    
    			@Override
    			public void run() {
    				doLookup();
    			}
    		}, 0, 60000);
    	}
    
    	public void onAppStop(IApplicationInstance appInstance) {
    		if(timer != null)
    			timer.cancel();
    		timer = null;
    	}
    
    	private void doLookup() {
    		//initialise database here.
    		for(int i = 1; i <= 2; i++) {
    			// Do database lookup here and set allow booleans.  call stmt.executeQuery and process rs.
    		}
    		// cleanup database connections here.
    	}
    
    	public void play(IClient client, RequestFunction function, AMFDataList params) {
    		String playName = "denied.stream";
    		String streamName = getParamString(params, PARAM1);
    
    		if(streamName.contains("tv1") && tv1Allow) {
    			playName = streamName;
    		}
    		if(streamName.contains("tv2") && tv2Allow) {
    			playName = streamName;
    		}
    
    		params.set(PARAM1, playName); 
    		invokePrevious(client, function, params);
    	}
    You could easily extend this by storing the information about each stream in it's own class and then using a Map to reference it instead of using separate instance variables for each channel.

    	class ChannelHolder {
    		String name;
    		int id;
    		boolean allowed = true;
    	}
    
    	Map<String, ChannelHolder channels = new HashMap<String, ChannelHolder>();
    You could initially populate the channels map from appInstance properties. The key would be the name.

    Roger.

Similar Threads

  1. Server requirements for VOD
    By lincoln in forum Performance Tuning Discussion
    Replies: 11
    Last Post: 11-26-2012, 01:45 AM
  2. VOD mp4 buffering display problems
    By kasax666 in forum Video On Demand Streaming Discussion
    Replies: 4
    Last Post: 02-15-2012, 01:03 PM
  3. my live stream video didn't display
    By viking in forum Live Streaming and Encoder Discussion
    Replies: 1
    Last Post: 12-24-2011, 03:01 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
  •