Posted by Codehead on September 29, 2008 at 10:14 pm
I worked 2 full days to get Red5 0.7.0 working with custom applications but I had no luck.
I couldn’t even get the tutorials written by Red5 developers working, it doesn’t have proper documentation either so it was a real nightmare.
So many other people have these problems too and there seem to be no answer to these problems.
So here is what I did, I installed Red5 0.6.2 and voila! it worked, all the tutorials worked and all the examples worked too!
I’m not a Java guru and I’m glad I’m not, it looks really huge and complicated, it doesn’t look fun to program in at all. I’m sure so many people like it very much but I really think even C is nicer than Java.
For example, to make an even “Hello World” Red5 application you have to make ~5 folders, 4 XML files, 1 Java class, compile your class, upload it to your server and restart Red5!!!
Posted by Codehead on September 28, 2008 at 3:37 pm
Here is how to fix this:
(Assume the name of my script is myscript)
1 - Copy your script into /etc/init.d folder
2 - cd /etc/init.d
3 - chmod +x myscript
4 - Add these lines, including #, right after #!/bin/bash or #!/bin/sh:
# chkconfig: 2345 95 20
# description: Some description
# What your script does (not sure if this is necessary though)
# processname: myscript
This is also one of those things that I couldn’t really find a real solution to online, so with some tests and experiments, I came up with this solution which I’m not sure if it’s the best solution.
First you will need to attach an event to your incoming stream, assuming your stream is clientStream:
Then you will need a member variable or a variable in the global scope to keep the latest status:
var playerLastEvent:String = newString();
Now the PlayerStatusHandler which again, I don’t think it’s very pretty:
function PlayerStatusHandler(event:NetStatusEvent){if(playerLastEvent == "NetStream.Buffer.Flush"&&
event.info.code == "NetStream.Buffer.Empty"){/* Stopped */
StopPlayback(event); /* Or any other thing you want to do */}elseif(playerLastEvent == "NetStream.Buffer.Flush"&&
event.info.code!= "NetStream.Buffer.Empty")
playerLastEvent = ""; /* Sometimes it throws the Flush event */elseif(event.info.code == "NetStream.Buffer.Flush")
playerLastEvent = "NetStream.Buffer.Flush";
}
So as you can see, we are looking for the Flush event that is followed by an Empty event.
This is just tested on my connection and I don’t really know how this works on slow connections, where the buffer is empty often but maybe you can tell me
I wish there was an event to show the real end of the stream.
Posted by Codehead on September 21, 2008 at 2:31 am
Funny, I couldn’t find the answer to this anywhere, either the answers are unrelated or they are overly complicated. So here is what I did:
var imageLoader:Loader = new Loader();
imageLoader.load(new URLRequest("path to your image/some image.png"));
varbutton:Sprite = new Sprite();
button.addChild(imageLoader);
button.buttonMode = true;
button.useHandCursor = true;
addChild(button);
Put it *inside* the folder that you want to delete and run it.
Be very careful when using this code, I warned you! Don’t use this if you don’t know any PHP.
Posted by Codehead on September 18, 2008 at 3:50 pm
Wouldn’t it be cool if everyone had a GPS device in their car, used it during rush hours and the device would connect to a central server, maybe through AT&T (!!!) and load balance the streets?
For example, it could find the best route based on traffic load on different routes to a destination.
Posted by Codehead on September 18, 2008 at 3:47 pm
It turns out that it’s Google toolbar, try uninstalling it and you will see the difference.
I tried installing the latest version of Google toolbar but it didn’t really make much difference.
It made some difference when I disabled some buttons on the toolbar though, such as bookmarks.
My buttons are now: news, pop up blocker, PageRank, spell checker and Autofill.
Probably some of these buttons try to contact some server for some reason when you open a new tab and it makes everything slow.
Posted by Codehead on September 17, 2008 at 3:03 pm
Sometimes you can see that your script is running slow but if you don’t have a lot of experience you don’t know how to find out what’s the problem and where to start looking for it.
You then naturally start looking at your loops and things like that, but from my experience the bottleneck is almost always somewhere you are not expecting.
It’s often in your database queries or calling external resources. The ones that look so innocent
To find out where the issue is, you can use these two functions:
function benchmark(){static$start=NULL;if(is_null($start)){$start= get_microtime();}else{$benchmark= get_microtime()-$start;$start= get_microtime();return$benchmark;}}function get_microtime(){list($usec,$sec)=explode(" ",microtime());return((float)$usec+(float)$sec);}
Place these 2 functions on top of your code and place these in your code:
benchmark();/* The first call will initialize the function *//* Some code */echo benchmark().'<br />';/* Some more code */echo benchmark().'<br />';/* Yet more code */echo benchmark().'<br />';
This will show you numbers like 0.02341… etc.
People usually don’t say how long part of a script should run or how long is too long but I’ll tell you that if you get numbers like 0.1, 0.2, 0.4 or 1.4 then you have a problem and your application might not scale well.
If this is the case then you should use PHPCache and cache the results of those slow parts, even for 1 minute at a time, this will bring those numbers down to 0.02 or 0.01…
The other thing you should do first is to check out your queries, use PHPMyAdmin, try “EXPLAIN your query” and see if MySQL is using your indexes properly. (If you indexed your tables well to begin with)
Query optimization is a big topic, I will write about that more later but sometimes query optimization won’t help you because your query is too nasty and you can’t do it any other way. (With your level of experience)
PHPCache::set_expire($key)
Which will set the expiration of the cache record for $key in the past, I think this method has some advantages over deleting the key all together.
PHPCache::remove($key)
Will completely remove the row.
PHPCache::clean_up()
This method will be called when ever you construct/configure a new PHPCache object with PHPCache::configure($database) method and does two things:
1 - Will delete all the old keys on the table, you can control how often this happens with 2 constants:
PHPCACHE_GC_PROBABILITY & PHPCACHE_GC_DIVISOR
If you set PHPCACHE_GC_PROBABILITY to 10 and PHPCACHE_GC_DIVISOR to 100, then when ever you configure the PHPCache object with PHPCache::configure($database); there will be 10% chance that the garbage collector will delete the old rows.
The default value is 1%.
2 - It will optimize the table PHPCache is using, you can also control how often this happens through 2 other constants:
PHPCACHE_TO_PROBABILITY & PHPCACHE_TO_DIVISOR
It works similar to #1 and default value is 10%.
PHPCache::gc()
Will delete the old rows anytime you call this method, it doesn’t care about PHPCACHE_GC_PROBABILITY & PHPCACHE_GC_DIVISOR
One place to use this would be a cron tab.
PHPCache::optimize_table()
Will optimize PHPCache’s table and doesn’t care about
PHPCACHE_TO_PROBABILITY & PHPCACHE_TO_DIVISOR
This new version has some more minor improvements over the old one too.
Posted by Codehead on September 11, 2008 at 8:02 pm
I wrote this a while back, if you wrote a better one please let me know
function break_words($text,$length,$result_length,$append){preg_match_all('#([^ ]{'.$length.',})#',$text,$matches);foreach($matches[1]as$word){$word=trim($word);$text=str_replace($word,substr($word,0,$result_length).$append,$text);}return$text;}
This function will break the long words in string $text, which are more than $length to be maximum $result_length characters and appends what ever you pass in as $append.
Posted by Codehead on September 11, 2008 at 1:16 pm
I was working on this for a few days and came up with 3 versions of this function, don’t even ask for the first one.
Here is the second version which is inspired by K&R’s example:
The problem with this (or my problem ;)) is that I don’t like creation of stack frames and local variables over and over here, it might need like 40 of them and I knew I could do better so I came up with this version:
/** Second Version **/void BTree_Store(BTree *t, char*key, void*elem){
Node **n;
int cmpResult;
n =&t->root;
while(*n !=NULL){
cmpResult = t->cmpfn((*n)->key, key, BTREE_MAX_KEY_SIZE);
if(cmpResult ==0)break;
elseif(cmpResult < 0)
n =&((*n)->lnode);
else
n =&((*n)->rnode);
}if(cmpResult ==0)
memcpy((*n)->elem, elem, t->elemSize);
else*n = BTree_NewNode(t, key, elem);
}
I actually love this version, it’s quick, compact and right to the point.
Here is how the node and the tree structures look like:
struct node {char*key; /* Owned by tree */void*elem; /* Owned by tree */struct node *lnode;
struct node *rnode;
};
typedefstruct node Node;
struct btree {
Node *root;
int elemSize;
int numNodes;
int memUsed;
int(*cmpfn)(constchar*, constchar*, size_t);
};
typedefstruct btree BTree;
The cmpfn is strncmp by defaults because keys are char *, here are the tree & node construction and destruction functions:
Node *BTree_FindNode(BTree *t, char*key){
Node *n;
int cmpResult;
n = t->root;
while(n !=NULL){
cmpResult = t->cmpfn(n->key, key, BTREE_MAX_KEY_SIZE);
if(cmpResult ==0)return n;
elseif(cmpResult < 0&& n->lnode !=NULL)
n = n->lnode;
elseif(n->rnode !=NULL)
n = n->rnode;
elsebreak;
}return BTREE_KEY_NOT_FOUND;
}void*BTree_Get(BTree *t, char*key){
Node *n;
n = BTree_FindNode(t, key);
return n != BTREE_KEY_NOT_FOUND ? n->elem : BTREE_KEY_NOT_FOUND;
}
The only problem with this tree is that if you store sorted data you will end up with a linked list rather than a binary search tree so I’m working on a self balancing binary search tree which is very chalanging but I love chalanges
Posted by Codehead on September 9, 2008 at 11:25 pm
I am sick and tired of Windows and Internet Explorer and all of their problems, some of you might think it’s just fine and you don’t have any issues with these products, but I do complicated stuff and some times lose all my work.
What are you doing every day at Microsoft? Apparently you are not doing your job properly, open source and free applications are more stable than your products.
I can’t believe a huge software company with that many employees releases these garbage pieces of software for people to use and charges a lot of money for them and I’m sure they know about it, but the question is why?
Why is it like this?
Don’t you have enough smart people to figure these issues out?
Don’t you have enough smart people to fix these bugs?
If you do have smart people then what are they doing every day going to work for Microsoft?
Your products are all buggy and you release new versions!!!!!!!!! How about you fix the old ones first? How about you test your products a lot and make them with good quality so they are not this buggy in the first place?
Do you care about your customers? They lose their work and it’s annoying to pay a lot of money for garbage products.
Microsoft, you lost me, I know I don’t matter at all but you lost me and I will buy a MAC and install Linux on this computer instead of this piece of crap “Windows Vista Home Premium” which is a copy of MAC OS 10 anyway. Windows is a copy of MAC in the first place anyway. http://www.google.com/search?q=Windows+copies+MAC