Java Reference
In-Depth Information
catch (IOException ioe) {
} catch (MediaException me)
{
} // now take a picture
try {
byte[] pngImage = vc.getSnapshot(null);
// do something with the image ...
} catch (MediaException me)
{
}
Apparently this capture can be performed in the same thread, since it's
not reading or writing any data from or to the disk or network, therefore
no I/O operations are being executed. A closer examination however
proves this to be wrong. In older devices, such as the Nokia 6600 (S60
2nd Edition), the supported resolution was only 160
120 pixels, making
a photo capture very fast since there was not much data to copy from the
camera buffer to a Java byte array. However, newer devices these days
support resolutions of up to 1600
×
1200 pixels, which in JPEG format,
with reasonable quality, can result in about 550 KB of data! Copying all
these bytes from one buffer to another is an expensive process, which
can easily hang the main application thread, preventing the user from
interacting with the application. As a result, it should also be performed
on a separate thread.
We mentioned at the beginning of this section that for most audio and
video formats, data must be loaded entirely into a memory buffer before
it can be decoded and played. Notable exceptions are the streaming
formats, such as Real-Time Streaming Protocol (RTSP). Therefore, besides
expensive I/O operations being performed to load the data, players for
those formats keep huge buffers in memory, containing the decoded data
ready to be played. This makes the players very memory-intensive and
their use must be accompanied by careful memory management.
There are two best practices on memory management for Player
objects: do not keep too many pre-fetched players in memory and
explicitly close any unneeded players.
As we discussed in Chapter 2, players go through some states before
they are ready to play media data:
×
UNREALIZED , where it has just been created
REALIZED , where it acquires the media resources it needs (by com-
municating with a server, reading a file, etc.)
PREFETCHED , where it acquires scarce or exclusive resources (an
audio device, for example), fills buffers with data and does other
start-up processing.
 
Search WWH ::




Custom Search