Find Your Forum
  
Welcome, Guest. Please login or register.
Did you miss your activation email?

News: HTC Evo 4G by Sprint
Instinct Forum, Samsung Instinct message board, Samsung Instinct By Sprint, Samsung Instinct phone, new Samsung Instinct, Samsung Instinct phone, Sprint Instinct, Samsung Instinct phone
Best Screen Protector for Samsung Instinct                 Free Sprint Phones and Cheap Plans
                Samsung Instinct Scratch Protection
Pages: [1]
Reply Print
Author Topic: MediaProcessor woes  (Read 1421 times)
Twelve
[I]
*

Cookies: 0
Hometown: Colorado
Posts: 6



« on: April 07, 2009, 10:34:27 PM »

Greetings Everyone,  I have been posting over at the official forum for awhile and find that...  it's not much help (trying not to offend anyone here on my first post).  I recognize a few names over here and am positive this will be a better experience. So without further ado.
Has anyone had any experience with the javax.microedition.amms.MediaProcessor?  (jsr234) I am attempting to use the processor for the MIME types "image/jpg" or "image/raw".  The following code illustrates the two alternative code paths:

Code:
    private Image resizeImage(InputStream src) {
      MediaProcessor mp = null;
      ByteArrayOutputStream bos = null;
      try {
         mp = GlobalManager.createMediaProcessor("image/jpeg");
         mp.setInput(src, MediaProcessor.UNKNOWN);// or set the size of the InputStream
         
         /*Alternative path for above using "raw/image"
          * private Image resizeImage(Image srcImg){
          *    MediaProcessor mp = null;
          *    ByteArrayOutputStream bos = null;
          *    try {
          *       mp = GlobalManager.createMediaProcessor("image/raw");
          *       mp.setInput(srcImg);
          */
         log.log("mp input set.");
         bos = new ByteArrayOutputStream();
         mp.setOutput(bos);
         // Tries to instantiate the ImageTransformControl. If not supported it returns null.
         ImageTransformControl transformCtl = (ImageTransformControl) mp.getControl("javax.microedition.amms.control.imageeffect.ImageTransformControl");
         //set output size
         transformCtl.setTargetSize(displayImgWidth, displayImgHeight, 0);
         transformCtl.setEnforced(true);
         transformCtl.setEnabled(true);

         // Do the actual processing. If you do not want to use a blocking call,
         // use start() and MediaProcessorListener.
         mp.complete();

         log.log("completed without exception");
      } catch (MediaException e) {
         log.log("MediaException: " + e);
      } catch (Exception e) {
         System.out.println("Exception(): " + e);
      } finally {
         if(bos.size() == 0){
            log.log("bos returned empty");
         }
         return Image.createImage(bos.toByteArray(), 0, bos.size());
      }
   }


I have spent several hours in this routine and have found it not very consistent, It's testing the very patience of my soul.  :Smiley  I would ditch it if it weren't for the performance. I find that some Stream/Images are handled fine but for some unapparent reason others are not, in which case the after the setInput() method the remaining code is never executed and the OutputStream (bos) size in the finally block is zero yet an exception is never caught/thrown.  Angry This seems to happen every time with an image captured by the phone.

Any insight is appreciated.   -thanks!
Logged

-Twelve
Twelve
[I]
*

Cookies: 0
Hometown: Colorado
Posts: 6



« Reply #1 on: April 07, 2009, 11:04:44 PM »

Woa! is that code block really hard to read on this forum or is it just me?
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #2 on: April 08, 2009, 06:37:06 AM »

It is a little hard to read, but I highlighted it and that was better.

I suspect you're treading new ground here, and I have the feeling that parts of that API may not have been fully tested.  There is one member I can think of on here that may have tried it, and if so hopefully he will speak up.

I noticed that in the few days after the S30 and open APIs were announced, the Sprint dev team was in the forum answering lots of questions, and now it's back to the old occasional answer.
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #3 on: April 08, 2009, 01:03:02 PM »

By the way, did you see Ryan's response to another question on JSR-234?

"For JSR234, a JSR234-like API does exist in the handset but we considering it unsupported because it did not go through our full testing and requirements phase. I'll see if we can move this into the 'supported' space, much of this gets tricky with passing the TCK test and what we can claim is supported."
Logged
Twelve
[I]
*

Cookies: 0
Hometown: Colorado
Posts: 6



« Reply #4 on: April 08, 2009, 09:08:51 PM »

Thanks for the replies. Why am I not surprised by their standing on 234.  I have started 3 different projects for the instinct since early this year and two have had serious issues due to the lack of complete or working API implementations.  Good thing this isn't my full time job or I'd be trading my instinct on the street for food.  laugh
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #5 on: April 08, 2009, 09:18:45 PM »

Apparently it's a Java-like OS on the phone...  laugh
Logged
mugwumpj
[I][N]
**

Cookies: 11
Hometown: outerspace
Posts: 14


« Reply #6 on: April 09, 2009, 06:46:57 PM »

12s:  you are most likely running out of memory while loading the image.  there was a thread in the adp forums about loading an image taken by the camera and throwing oom.  i don't remember if it ever got resolved.   but if that's your problem, then you can get around it by increasing your heap size.   there's a jad tag to define the desired heap size.   i can't remember what it is off hand.   either check the jads that ship with the instinct or the recent adp threads.
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #7 on: April 09, 2009, 07:27:44 PM »

MIDlet-Heap-Size:# of bytes

Logged
mugwumpj
[I][N]
**

Cookies: 11
Hometown: outerspace
Posts: 14


« Reply #8 on: April 10, 2009, 09:10:37 AM »

fwiw, here's a chunk of code I wrote last summer that does pretty much the same thing.   I never tested it with a large image.   The image returned by getSnapshot() is fairly small.  Somewhere around 640x480 or 320x240.   

Code:
// set up a player for image capture
Player player = Manager.createPlayer("capture://video");
player.realize();
player.start();

// set up the video control
VideoControl videoControl = (VideoControl)player.getControl("VideoControl");
videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
int width = videoControl.getSourceWidth();
int height = videoControl.getSourceHeight();

// grab a snapshot from the camera
byte[] imageData = videoControl.getSnapshot("encoding=jpeg");
Image image = Image.createImage(imageData, 0, imageData.length);

// set up media processor
ByteArrayOutputStream out = new ByteArrayOutputStream();
MediaProcessor processor = GlobalManager.createMediaProcessor("image/raw");
processor.setInput(image);
processor.setOutput(out);

// create a square icon from the image.
ImageTransformControl trans = (ImageTransformControl)processor.getControl("javax.microedition.amms.control.imageeffect.ImageTransformControl");
trans.setSourceRect((width - height) / 2, 0, width, width);
trans.setTargetSize(32, 32, 0);
processor.complete();
byte[] bytes = out.toByteArray();
Image icon = Image.createImage(bytes, 0, bytes.length);
Logged
Twelve
[I]
*

Cookies: 0
Hometown: Colorado
Posts: 6



« Reply #9 on: April 10, 2009, 04:57:38 PM »

Thanks for the reply guys!  Yea, I originally thought that memory was the problem myself but after some research I maxed out my memory and continuously monitor the total and free mem during the process (thanks to the hints on getting that from the Runtime mugwumpj)   Wink  .  I'll take a look at the code you posted and keep you posted.   Grin 
Logged
Pages: [1]
Reply Print
Jump to:  

Got a new phone? Find the forum here


Subject Started by Replies Views Last post
had to get a new Instinct, now i have email woes
Email
sturmie 7 1137 Last post July 10, 2009, 10:13:10 AM
by ajmcf




Galaxy S3 | Galaxy Note | Galaxy Nexus | Kindle Fire | Atrix 4G | Motorola Xoom | Windows Phone 7
Nokia Lumia | Top Hosts | Samsung Galaxy Tab | Samsung Galaxy S2 | Samsung Galaxy S | Samsung Wave
HTC Evo 3D | HTC Evo 4G | HTC Incredible | HTC Incredible 2 | HTC Incredible S | HTC Thunderbolt
Motorola Droid Razr
| HTC Desire | HTC Desire HD | HTC Desire Z | HTC Desire S | HTC Wildfire
Motorola Droid | Galaxy Indulge | Nokia N8 | Droid Charge | Droid X | Droid X2 | Droid 2| Droid 3 | Fascinate
HTC Sensation | HTC Flyer | LG Revolution | Asus Transformer | Xperia Play | iPhone 4 | Nexus S | Droid Bionic
HTC One | HTC Wildfire S | HTC Droid Eris


This is an Un-Official fan based Website. The views expressed on this website are solely those of the proprietor, or contributors to the site, and do not necessarily reflect the views or opinions of the parties it covers, and is not affiliated with, endorsed or sponsored by parties involved.
If you have a problem with any of the content posted on this website, please contact "sales@verticalscope.com"
Term of Use | Privacy Policy | BlackRain 2006 by, Crip





















CopyRight 2008 www.instinct-samsung.com
Powered by SMF 1.1.11 | SMF © 2006-2007, Simple Machines LLC