title: Fetch raw data from an Image acquired from an AImageReader
body: <p>I have an ImageReader, whose surface is attached to a MediaCodec decoder to render into. </p>
  
  <pre><code>        AMediaCodec *videoDecoder = nullptr;
          ANativeWindow* surface = nullptr;
  
          AImageReader* imageReader = nullptr;
          AImageReader_ImageListener* imageListener = nullptr;
  
          if ((videoDecoder = AMediaCodec_createDecoderByType(mime)))
          {
              if (AImageReader_new(mWidth, mHeight, AIMAGE_FORMAT_YUV_420_888, 2, &amp;imageReader) == AMEDIA_OK)
              {
                  if (AImageReader_getWindow(imageReader, &amp;surface) == AMEDIA_OK)
                  {
                      if (AMediaCodec_configure(videoDecoder, mediaFormat, surface, NULL, 0) == AMEDIA_OK)
                      {
                          int32_t outputFormat{};
                          AMediaFormat_getInt32(AMediaCodec_getOutputFormat(videoDecoder), AMEDIAFORMAT_KEY_COLOR_FORMAT, &amp;outputFormat);
  
                          imageListener = new AImageReader_ImageListener();
                          imageListener-&gt;onImageAvailable = &amp;onImageAvailableCallback;
                          AImageReader_setImageListener(imageReader, imageListener);
  
                          if (AMediaCodec_start(videoDecoder) == AMEDIA_OK)
                          {
                              configCompleted = true;
                          }
                          else
                          {
                              TRACE("ImporterMP4Android", 0, "Failed to Start Video Decoder");
                          }
                      }
                      else
                      {
                          TRACE("ImporterMP4Android", 0, "Failed to Configure Video Decoder");
                      }
                  }
                  else
                  {
                      TRACE("ImporterMP4Android", 0, "Failed to Fetch Surface owned by the ImageReader");
                  }
              }
              else
              {
                  TRACE("ImporterMP4Android", 0, "Failed to Create ImageReader");
              }
          }
          else
          {
              TRACE("ImporterMP4Android", 0, "Failed to Create Decoder");
          }
  </code></pre>
  
  <p>The <code>onImageAvailableCallback</code> looks like this atm:</p>
  
  <pre><code>void onImageAvailableCallback(void *context, AImageReader *reader)
  {
      int32_t format;
      media_status_t  status = AImageReader_getFormat (reader, &amp;format);
  
      AImage *image;
      status = AImageReader_acquireLatestImage(reader, &amp;image);
  
  
      status = AImage_getFormat(image, &amp;format);
  
      // TODO: copy *raw data somewhere for downstream processing
  
      AImage_delete(image);
  }
  </code></pre>
  
  <p>As indicated in TODO comment, I want to copy out the <em>raw</em> data of the <code>Image</code> acquired from <code>ImageReader</code> for further processing. The interface provided by the Image class allows me to query the number of planes and fetch individual planar data, but I am interested in grabbing the entire frame at once. Any suggestions on how I might accomplish this?</p>
  
  <p>In a nutshell, I am using MediaCodec video decoder to render into a Surface owned by an ImageReader, and ultimately want to <em>grab</em> the decoded video frames from the ImageReader in their entirety in YUV420NV21 format for further processing.</p>