Improve scanning extension

There is one fail-case in previous commit that makes the process of
scanning for extension take twice of the time.
The fail-case looks like:
/very/very/long/long/long/path/without/dots/in/any/part/of/the/path

Since we know the maximum length of extension we can handle is 5 (at
compile time), so we can stop backward scanning if it exceeds.

Please refer to the following link for further discuss.
https://github.com/yumeyao/android_platform_frameworks_av/issues/1

Signed-off-by: YumeYao <yumeyao@gmail.com>