2012/01/23

How video frame catched.

VSYNC  indicates when a new image is about to start being sent out on the pixel data bus.

HREF indicates when a new line is about to start being sent out on the pixel data bus.

PCLK indicates when there is valid pixel data on the pixel data bus.

The VIP engine latches data into the VIP buffers during the following conditions:
• On the active EDGE of VSYNC (0 = falling-edge, 1 = rising-edge), the VIP engine will count until the number of expected lines are received (i.e. any extraneous lines are ignored).
• On the active LEVEL of HREF (0 = active high, 1 = active low), the VIP engine will count until the number of expected pixels are received (i.e. any extraneous pixels are ignored).

2012/01/17

Thread Condition Wait Coding Pattern

The reason why we need pthread_mutex_lock(&mutex) before pthread_cond_wait(&cond, &mutex) :
Need to protect the condition read/wirte of variables that changes the conditions.
Before we call pthread_cond_wait, we need to check if condition is met or not, if it is met, not call to pthread_cond_wait is needed.

Below sample code can be found at
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Fapis%2Fusers_78.htm


#define _MULTI_THREADED #include <pthread.h> #include <stdio.h> #include "check.h" /* For safe condition variable usage, must use a boolean predicate and */ /* a mutex with the condition. */ int conditionMet = 0; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #define NTHREADS 5 void *threadfunc(void *parm) { int rc; rc = pthread_mutex_lock(&mutex); checkResults("pthread_mutex_lock()\n", rc); while (!conditionMet) { printf("Thread blocked\n"); rc = pthread_cond_wait(&cond, &mutex); checkResults("pthread_cond_wait()\n", rc); } rc = pthread_mutex_unlock(&mutex); checkResults("pthread_mutex_lock()\n", rc); return NULL; } int main(int argc, char **argv) { int rc=0; int i; pthread_t threadid[NTHREADS]; printf("Enter Testcase - %s\n", argv[0]); printf("Create %d threads\n", NTHREADS); for(i=0; i<NTHREADS; ++i) { rc = pthread_create(&threadid[i], NULL, threadfunc, NULL); checkResults("pthread_create()\n", rc); } sleep(5); /* Sleep is not a very robust way to serialize threads */ rc = pthread_mutex_lock(&mutex); checkResults("pthread_mutex_lock()\n", rc); /* The condition has occured. Set the flag and wake up any waiting threads */ conditionMet = 1; printf("Wake up all waiting threads...\n"); rc = pthread_cond_broadcast(&cond); checkResults("pthread_cond_broadcast()\n", rc); rc = pthread_mutex_unlock(&mutex); checkResults("pthread_mutex_unlock()\n", rc); printf("Wait for threads and cleanup\n"); for (i=0; i<NTHREADS; ++i) { rc = pthread_join(threadid[i], NULL); checkResults("pthread_join()\n", rc); } pthread_cond_destroy(&cond); pthread_mutex_destroy(&mutex); printf("Main completed\n"); return 0; }

2012/01/03

JavaScript Create Object

Create Object with constructor
http://www.w3schools.com/js/js_objects.asp
function person(firstname,lastname,age,eyecolor) { this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; this.newlastname=newlastname; } function newlastname(new_lastname) { this.lastname=new_lastname; } var myFather=new person("John","Doe",50,"blue"); var myMother=new person("Sally","Rally",48,"green"); myFather.newlastname("Gu");

2011/12/13

iPhone Device Setup for Develop



http://boga.wordpress.com/2008/07/16/debugging-ipod-provision-profilescertificates/

If you’re in the iPhone Developer Program, you’ll be able to run you code in a phisical device, with the following process:
- Create a Certificate Signing Request (CSR) and submit to the developer portal
- Download and install the code singing certificate (Development/Distribution certificate) to your Keychain
- Download and install the WWDR certificate
- Create/Download a Provisioning profile listing the devices you intend to run the program on
- Install the provisioning profile to your development machine by dropping it into iTunes
- Set the Certificate/Provision profile in your XCode project

2011/12/11

CentOS Server Setup

http://www.howtoforge.com/quick-n-easy-lamp-server-centos-rhel

yum install httpd httpd-devel
/etc/init.d/httpd start

yum install mysql mysql-server mysql-devel
/etc/init.d/mysqld start
mysql

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('root') WHERE user='root';
mysql> FLUSH PRIVILEGES;

yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

yum install phpmyadmin
(Point your browser to: http://ip.address/phpmyadmin.)

The configuration file now needs a secret passphrase
vim /usr/share/phpmyadmin/conf.inc.php
Look for a line and enter any password. Just dont leave it empty!
$cfg['blowfish_secret'] = 'mydemopass';

chkconfig httpd on
chkconfig mysqld on


http://chrisschuld.com/2009/11/installing-webmin-with-yum-centosrhel/
echo -e "[Webmin]\nname=Webmin Distribution Neutral\nbaseurl=http://download.webmin.com/download/yum\nenabled=1" > /etc/yum.repos.d/webmin.repo
rpm --import http://www.webmin.com/jcameron-key.asc
yum install webmin

2011/12/09

Objective C Memory-Management

From book Programming in Objective-C 2.0

Sending a release message does not necessarily destroy an object. When an object’'s reference count is decremented to 0, the object is destroyed. The system does this by sending the dealloc message to the object to free its memory.

If you need to hold onto an object to make sure it doesn’t get destroyed by someone else, you should retain it. Make sure to release the object when you’re done with it.

Release any objects that you have retained or have created using a copy, mutable-Copy, alloc, or new method.This includes properties that have the retain or copy attribute. You can override dealloc to release your instance variables at the time
your object is to be destroyed.

The autorelease pool provides for the automatic release of objects when the pool itself is drained.The system does this by sending a release message to each object in the pool for each time it was autoreleased. Each object in the autorelease pool whose reference count goes down to 0 is sent a dealloc message to destroy the object.

If you no longer need an object from within a method but need to return it, send it an autorelease message to mark it for later release.The autorelease message does not affect the reference count of the object.

When your application terminates, all the memory your objects take up is released, regardless of whether they were in the autorelease pool.

When you develop Cocoa or iOS applications, autorelease pools will be created and drained throughout execution of the program (this will happen each time an event occurs). In such cases, if you want to ensure that your object survives automatic deallocation when the autorelease pool is drained, you need to retain it.All objects that have a reference count greater than the number of autorelease messages they have been sent will survive the release of the pool.

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...