java - How to optimize getFrameBuffer method to take less time to write an image? -


/*the method taking of time last call of read(adbchan,reply) method. possible send image directly server without saving first in device? if how? or can optimize method take less time */

static rawimage getframebuffer(inetsocketaddress adbsockaddr, device device)             throws timeoutexception, adbcommandrejectedexception, ioexception {          rawimage imageparams = new rawimage();         byte[] request = formadbrequest("framebuffer:"); //$non-nls-1$          byte[] nudge = {             0         };         byte[] reply;          socketchannel adbchan = null;         try {             adbchan = socketchannel.open(adbsockaddr);             adbchan.configureblocking(false);             setdevice(adbchan, device);              write(adbchan, request);              adbresponse resp = readadbresponse(adbchan, false);             if (!resp.okay) {                 throw new adbcommandrejectedexception(resp.message);             }               reply = new byte[4];             read(adbchan, reply);              bytebuffer buf = bytebuffer.wrap(reply);             buf.order(byteorder.little_endian);              int version = buf.getint();               int headersize = rawimage.getheadersize(version);               reply = new byte[headersize * 4];              read(adbchan, reply);             buf = bytebuffer.wrap(reply);              buf.order(byteorder.little_endian);                  if (!imageparams.readheader(version, buf)) {                 log.e("screenshot", "unsupported protocol: " + version);                 return null;             }              log.d("ddms", "image params: bpp=" + imageparams.bpp + ", size="                     + imageparams.size + ", width=" + imageparams.width                     + ", height=" + imageparams.height);              write(adbchan, nudge);              reply = new byte[imageparams.size];               read(adbchan, reply);             imageparams.data = reply;           } {             if (adbchan != null) {                 adbchan.close();             }         }          return imageparams;     }   static void read(socketchannel chan, byte[] data, int length, int timeout)             throws timeoutexception, ioexception {         bytebuffer buf = bytebuffer.wrap(data, 0, length != -1 ? length : data.length);         int numwaits = 0;          while (buf.position() != buf.limit()) {             int count;              count = chan.read(buf);             if (count < 0) {                 log.d("ddms", "read: channel eof");                 throw new ioexception("eof");             } else if (count == 0) {                 // todo: need more accurate timeout?                 if (timeout != 0 && numwaits * wait_time > timeout) {                     log.d("ddms", "read: timeout");                     throw new timeoutexception();                 }                 // non-blocking spin                 try {                     thread.sleep(wait_time);                 } catch (interruptedexception ie) {                 }                 numwaits++;             } else {                 numwaits = 0;             }         }     } 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -