09.02.2013 Views

Sviluppo di una piattaforma per lo streaming multimediale - MobiLab ...

Sviluppo di una piattaforma per lo streaming multimediale - MobiLab ...

Sviluppo di una piattaforma per lo streaming multimediale - MobiLab ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

90<br />

Integer getStateLock() {<br />

return stateLock;<br />

}<br />

<strong>Sviluppo</strong> <strong>di</strong> <strong>una</strong> <strong>piattaforma</strong> <strong>per</strong> <strong>lo</strong> <strong>streaming</strong> multime<strong>di</strong>ale in ambiente Android<br />

void setFailed() {<br />

failed = true;<br />

}<br />

private synchronized boolean waitForState(Processor p, int state) {<br />

p.addControllerListener(new StateListener());<br />

failed = false;<br />

// Chiama il metodo richiesto sul processore<br />

if (state == Processor.Configured) {<br />

p.configure();<br />

} else if (state == Processor.Realized) {<br />

p.realize();<br />

}<br />

// Wait until we get an event that confirms the<br />

// success of the method, or a failure event.<br />

while (p.getState() < state && !failed) {<br />

synchronized (getStateLock()) {<br />

try {<br />

getStateLock().wait();<br />

} catch (InterruptedException ie) {<br />

return false;<br />

}<br />

}<br />

}<br />

if (failed) return false;<br />

else return true;<br />

}<br />

class StateListener implements ControllerListener {<br />

public void controllerUpdate(ControllerEvent ce) {<br />

}<br />

// If there was an error during configure or<br />

// realize, the processor will be c<strong>lo</strong>sed<br />

if (ce instanceof ControllerC<strong>lo</strong>sedEvent)<br />

setFailed();<br />

// All controller events, send a notification<br />

// to the waiting thread in waitForState method.<br />

if (ce instanceof ControllerEvent) {<br />

synchronized (getStateLock()) {<br />

getStateLock().notifyAll();<br />

}<br />

}<br />

}<br />

public static void main(String[] args) {<br />

Socket client = null;<br />

Format fmt = null;<br />

Me<strong>di</strong>aLocator <strong>lo</strong>cator = null;<br />

int i = 0;<br />

ServerSocket t;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!