Exemple #1
0
 @Override
 public Format setInputFormat(Format format) {
   final VideoFormat videoFormat = (VideoFormat) format;
   if (videoFormat.getSize() == null) return null; // must set a size.
   // TODO: check VideoFormat and compatibility
   return super.setInputFormat(format);
 }
Exemple #2
0
  @Override
  public Format[] getSupportedOutputFormats(Format input) {
    if (input == null) return supportedOutputFormats;

    final VideoFormat inputCast = (VideoFormat) input;
    final Format[] result =
        new Format[] {
          new RGBFormat(
              inputCast.getSize(), -1, Format.byteArray, inputCast.getFrameRate(), -1, -1, -1, -1)
        };
    // TODO: we don't know the details of the output format (pixel masks,
    // etc) until we actually parse one!

    return result;
  }
Exemple #3
0
 @Override
 protected void copy(Format f) {
   super.copy(f);
   final GIFFormat oCast = (GIFFormat) f; // it has to be a GIFFormat, or
   // ClassCastException will be
   // thrown.
 }
  /**
   * Read screen.
   *
   * @param output output buffer for screen bytes
   * @param dim dimension of the screen
   * @return raw bytes, it could be equal to output or not. Take care in the caller to check if
   *     output is the returned value.
   */
  public byte[] readScreen(byte[] output, Dimension dim) {
    VideoFormat format = (VideoFormat) getFormat();
    Dimension formatSize = format.getSize();
    int width = formatSize.width;
    int height = formatSize.height;
    BufferedImage scaledScreen = null;
    BufferedImage screen = null;
    byte data[] = null;
    int size = width * height * 4;

    // If output is not large enough, enlarge it.
    if ((output == null) || (output.length < size)) output = new byte[size];

    /* get desktop screen via native grabber if available */
    if (desktopInteract.captureScreen(displayIndex, x, y, dim.width, dim.height, output)) {
      return output;
    }

    System.out.println("failed to grab with native! " + output.length);

    /* OK native grabber failed or is not available,
     * try with AWT Robot and convert it to the right format
     *
     * Note that it is very memory consuming since memory are allocated
     * to capture screen (via Robot) and then for converting to raw bytes
     * Moreover support for multiple display has not yet been investigated
     *
     * Normally not of our supported platform (Windows (x86, x64),
     * Linux (x86, x86-64), Mac OS X (i386, x86-64, ppc) and
     * FreeBSD (x86, x86-64) should go here.
     */
    screen = desktopInteract.captureScreen();

    if (screen != null) {
      /* convert to ARGB BufferedImage */
      scaledScreen =
          ImgStreamingUtils.getScaledImage(screen, width, height, BufferedImage.TYPE_INT_ARGB);
      /* get raw bytes */
      data = ImgStreamingUtils.getImageBytes(scaledScreen, output);
    }

    screen = null;
    scaledScreen = null;
    return data;
  }
Exemple #5
0
 /**
  * Copies the attributes from the specified <CODE>Format</CODE> into this <CODE>YUVFormat</CODE>.
  *
  * @param f The <CODE>Format</CODE> to copy the attributes from.
  */
 protected void copy(Format f) {
   super.copy(f);
   if (f instanceof YUVFormat) {
     YUVFormat other = (YUVFormat) f;
     yuvType = other.yuvType;
     strideY = other.strideY;
     strideUV = other.strideUV;
     offsetY = other.offsetY;
     offsetU = other.offsetU;
     offsetV = other.offsetV;
   }
 }
Exemple #6
0
 public static VideoFormat buildVideoFormatForResolution(String s) {
   if (s == null || s.length() == 0) return null;
   VideoFormat rv = new VideoFormat();
   rv.setFormatName(s);
   try {
     int xidx = s.indexOf('x');
     if (xidx == -1) return rv;
     rv.width = Integer.parseInt(s.substring(0, xidx));
     int lastIdx = xidx + 1;
     while (Character.isDigit(s.charAt(lastIdx))) {
       lastIdx++;
       if (lastIdx >= s.length()) break;
     }
     rv.height = Integer.parseInt(s.substring(xidx + 1, lastIdx));
     if (lastIdx < s.length() && s.charAt(lastIdx) == 'i') rv.interlaced = true;
     int atSym = s.indexOf('@');
     if (atSym != -1) {
       lastIdx = atSym + 1;
       while (Character.isDigit(s.charAt(lastIdx)) || s.charAt(lastIdx) == '.') {
         lastIdx++;
         if (lastIdx >= s.length()) break;
       }
       rv.fps = Float.parseFloat(s.substring(atSym + 1, lastIdx));
     }
     return rv;
   } catch (Exception e) {
     System.out.println("Error parsing resolution:" + s + " of:" + e);
     return rv;
   }
 }
  protected void getFileInfo() {
    try {
      mediaFileInfo = new MediaFileInfo(new AndroidMediaObjectFactory(getApplicationContext()));
      mediaFileInfo.setUri(mediaUri1);

      duration = mediaFileInfo.getDurationInMicroSec();

      audioFormat = (AudioFormat) mediaFileInfo.getAudioFormat();
      if (audioFormat == null) {
        showMessageBox(
            "Audio format info unavailable",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {}
            });
      }

      videoFormat = (VideoFormat) mediaFileInfo.getVideoFormat();
      if (videoFormat == null) {
        showMessageBox(
            "Video format info unavailable",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {}
            });
      } else {
        videoWidthIn = videoFormat.getVideoFrameSize().width();
        videoHeightIn = videoFormat.getVideoFrameSize().height();
      }
    } catch (Exception e) {
      String message = (e.getMessage() != null) ? e.getMessage() : e.toString();

      showMessageBox(
          message,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {}
          });
    }
  }
  protected void copy(Format f) {

    super.copy(f);
    final RGBFormat oCast =
        (RGBFormat) f; // it has to be a RGBFormat, or ClassCastException will be thrown.
    this.bitsPerPixel = oCast.bitsPerPixel;
    this.redMask = oCast.redMask;
    this.greenMask = oCast.greenMask;
    this.blueMask = oCast.blueMask;
    this.pixelStride = oCast.pixelStride;
    this.lineStride = oCast.lineStride;
    this.flipped = oCast.flipped;
    this.endian = oCast.endian;
  }
Exemple #9
0
 public static VideoFormat buildVideoFormatFromProperty(String str) {
   VideoFormat rv = new VideoFormat();
   int currNameStart = 0;
   int currValueStart = -1;
   for (int i = 0; i < str.length(); i++) {
     char c = str.charAt(i);
     if (c == '\\') {
       // Escaped character, so skip the next one
       i++;
       continue;
     } else if (c == '=') {
       // We found the name=value delimeter, set the value start position
       currValueStart = i + 1;
     } else if ((c == ';' || i == str.length() - 1) && currValueStart != -1) {
       if (c != ';' && i == str.length() - 1) i++;
       // We're at the end of the name value pair, get their values!
       String name = str.substring(currNameStart, currValueStart - 1);
       String value = str.substring(currValueStart, i);
       currNameStart = i + 1;
       currValueStart = -1;
       if (value.length() > 0) {
         try {
           if ("f".equals(name)) rv.setFormatName(unescapeString(value));
           else if ("fps".equals(name)) rv.fps = Float.parseFloat(value);
           else if ("fpsd".equals(name)) rv.fpsDen = Integer.parseInt(value);
           else if ("fpsn".equals(name)) rv.fpsNum = Integer.parseInt(value);
           else if ("ar".equals(name)) rv.aspectRatio = Float.parseFloat(value);
           else if ("ard".equals(name)) rv.arDen = Integer.parseInt(value);
           else if ("arn".equals(name)) rv.arNum = Integer.parseInt(value);
           else if ("w".equals(name)) rv.width = Integer.parseInt(value);
           else if ("h".equals(name)) rv.height = Integer.parseInt(value);
           else if ("lace".equals(name) && "1".equals(value)) rv.interlaced = true;
           else if ("cs".equals(name)) rv.colorspace = unescapeString(value).intern();
           else if ("br".equals(name)) rv.bitrate = Integer.parseInt(value);
           else if ("vbr".equals(name)) rv.vbr = "1".equals(value);
           else if ("main".equals(name)) rv.primary = "yes".equalsIgnoreCase(value);
           else if ("index".equals(name)) rv.orderIndex = Integer.parseInt(value);
           else if ("tag".equals(name)) rv.id = value.intern();
           else if ("fpa".equals(name)) rv.framePack3D = value.intern();
         } catch (Exception e) {
           System.out.println("ERROR parsing video format info " + str + " of:" + e);
         }
       }
     }
   }
   return rv;
 }