Results 1 to 6 of 6

Thread: FileRandomAccessReader & Media cache

  1. #1
    Join Date
    Oct 2012
    Posts
    9

    Default FileRandomAccessReader & Media cache

    I FileRandomAccessReader have been implemented.
    it is hadoop filesystem accessreader.

    how can i add mediacache plugin?
    Both of which can be used for?

    package com.mycom;
    
    import java.io.*;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FSDataInputStream;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IOUtils;
    
    import com.wowza.io.*;
    import com.wowza.wms.logging.*;
    import com.wowza.wms.stream.*;
    import com.wowza.wms.application.*;
    
    public class HdfsRAR implements IRandomAccessReader 
    {
    	private final String __FS_DEFAULT_NAME__		= "hdfs://192.168.0.11:50000";	
    	
    	private String basePath = "";
    	private String mediaName = "";
    	private String mediaExtension = "";
    	private String fullPath = "";
    	
    	private Configuration hdfs_conf = null;
    	private FileSystem hdfs = null;
    	private FSDataInputStream hdfsFile = null;
    	
    	
    	private int direction = IRandomAccessReader.FORWARD;
    	private boolean sentSeekError = false;
    	
    	public HdfsRAR()
    	{
    		hdfs_conf = new Configuration(); 
    		hdfs_conf.set("fs.default.name",__FS_DEFAULT_NAME__);
    		try {
    			hdfs = FileSystem.get(this.hdfs_conf);
    		} catch (IOException e) {
    			WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.cons: "+e.toString());
    		}
    	}
    	
    	public void init(IApplicationInstance appInstance, IMediaStream stream, String basePath, String mediaName, String mediaExtension)
    	{	
    		this.basePath = "/user";	//
    		this.mediaName = mediaName;	//   /hadoop/exam.mp4
    		this.mediaExtension = mediaExtension;	//	mp4
    
    		while (true)
    		{
    			try {
    				this.fullPath = this.basePath + File.separatorChar + this.mediaName;
    				if (this.hdfs.exists(new Path(this.fullPath)))
    					break;
    
    				this.fullPath = this.basePath + File.separatorChar + this.mediaName + "." + this.mediaExtension;			
    				if (this.hdfs.exists(new Path(this.fullPath)))
    					break;
    				
    				this.fullPath = this.basePath + File.separatorChar + this.mediaName + this.mediaExtension;			
    				if (this.hdfs.exists(new Path(this.fullPath)))
    					break;
    	
    				if (this.mediaExtension.equalsIgnoreCase("flv") || this.mediaExtension.equalsIgnoreCase("mp3"))
    				{
    					this.fullPath = this.basePath + File.separatorChar + this.mediaName + "." + this.mediaExtension;				
    				}
    				else
    				{
    					this.fullPath = this.basePath + File.separatorChar + this.mediaName;				
    				}
    	
    				break;
    			} catch (IOException e) {
    				WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.init: "+e.toString());
    				break;
    			}
    		}
    	}
    
    	public long getFilePointer()
    	{
    		if (this.hdfsFile == null)
    			return 0;
    		
    		try
    		{			
    			return this.hdfsFile.getPos();
    		}
    		catch (Exception e)
    		{
    			WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.getFilePointer: "+e.toString());
    		}
    		return 0;
    	}
    
    	public void seek(long pos)
    	{
    		if (this.hdfsFile == null)
    			return;
    		
    		try
    		{
    			if (pos < 0)
    				pos = 0;
    			this.hdfsFile.seek(pos);
    		}
    		catch (Exception e)
    		{
    			if (!sentSeekError)
    			{
        			String stackTrace = "unknown";
        			Throwable cause = e;
                	if (cause != null)
                	{
            			StackTraceElement[] elements = cause.getStackTrace();
            			if (elements != null)
            			{
            				if (elements.length > 0)
            					stackTrace = elements[0].getClassName()+"."+elements[0].getMethodName()+"("+elements[0].getFileName()+":"+elements[0].getLineNumber()+")";
            			}
            			
            			stackTrace = cause.toString() + " ("+stackTrace+")";
                	}
    
                	WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.seek["+this.mediaName+","+stackTrace+"]: "+e.toString());
    				e.printStackTrace();
                	sentSeekError = true;
    			}
    		}
    	}
    
    	public int read(byte[] buf, int off, int size)
    	{
    		if (this.hdfsFile == null)
    			return 0;
    		
    		try
    		{	
    			return this.hdfsFile.read(buf, off, size);
    		}
    		catch (Exception e)
    		{
    			WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.read: "+e.toString());
    		}
    		return 0;
    	}
    
    	public void open() throws IOException
    	{	
    		if (this.hdfsFile != null)
    			close();
    		
    		this.hdfsFile = this.hdfs.open(new Path(this.fullPath));
    	}
    
    	public void close() throws IOException
    	{	
    		if (this.hdfsFile != null)
    			IOUtils.closeStream(this.hdfsFile);
    		this.hdfsFile = null;
    	}
    
    	public boolean isOpen()
    	{
    		return this.hdfsFile != null;
    	}
    	
    	public int getDirecton()
    	{
    		return this.direction;
    	}
    
    	public void setDirecton(int directon)
    	{
    		this.direction = direction;
    	}
    			
    	public String getBasePath()
    	{	
    		return this.basePath;
    	}
    
    	public String getMediaName()
    	{
    		return this.mediaName;
    	}
    
    	public String getMediaExtension()
    	{
    		return mediaExtension;
    	}
    	
    	public boolean exists()
    	{
    		try {
    			return this.hdfs.exists(new Path(this.fullPath));
    		} catch (IOException e) {
    			WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.exists: "+e.toString());
    		}
    		return false;
    	}
    	
    	public long lastModified()
    	{
    		try
    		{
    			this.hdfs.getFileStatus(new Path(this.fullPath)).getModificationTime();
    		}
    		catch (Exception e)
    		{
    			WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.lastModified: "+e.toString());
    		}
    		return 0;
    	}
    	
    	public long length()
    	{
    		try
    		{	
    			return this.hdfs.getFileStatus(new Path(this.fullPath)).getLen(); 
    		}
    		catch (Exception e)
    		{
    			WMSLoggerFactory.getLogger(HdfsRAR.class).error("HdfsRAR.length: "+e.toString());
    		}
    		return 0;
    	}
    	
    	public String getPath()
    	{
    		return this.fullPath;
    	}
    
    }

    <MediaReader>
    <Properties>
    <Property>
    <Name>randomAccessReaderClass</Name>
    <Value>com.mycom.HdfsRAR</Value>
    </Property>
    <Property>
    <Name>bufferSeekIO</Name>
    <Value>true</Value>
    <Type>Boolean</Type>
    </Property>
    </Properties>
    </MediaReader>

  2. #2
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    MediaCache is here:
    http://www.wowza.com/forums/content....and-streaming)

    MediaCache is used to stream vod assets (static files) from a content server: a web server, s3 or remote file system like NFS or NAS.

    Richard

  3. #3
    Join Date
    Oct 2012
    Posts
    9

    Default

    I've read its contents.
    Can I modify the "wms-plugin-mediacache.jar"?
    to read hadoop-hdfs.....

  4. #4
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    It might, should work. Did you try it?

    Richard

  5. #5
    Join Date
    Oct 2012
    Posts
    9

    Default

    I do not know how to write a application.xml file.

    http://www.wowza.com/downloads/forum...cessReader.zip
    I have access to the Hadoop file with a FileRandomAccessReader succeeding.
    My FileRandomAccessReader class use "MediaReader" tag in application.xml.
    But Mediacache also uses the same tag.

    How can i add my RandomAccessReader class and Mediacache class?

  6. #6
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    I don't think you can do both in the same Application.xml

    Richard

Similar Threads

  1. media cache
    By akaplan in forum General Forum
    Replies: 3
    Last Post: 07-22-2014, 01:55 AM
  2. Media Cache
    By Assuzza in forum On-Demand Streaming
    Replies: 1
    Last Post: 06-09-2014, 05:04 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
  •