added SAMPLE_FORMAT_XXX defines to enable more generic code
added code to identify app instance via PID, used generic macros SAMPLE_FORMAT_xxx
replaced raw pointer by smart one to simplify resource maintainance