Android Open Source - spydroid-ipcamera Video Quality






From Project

Back to project page spydroid-ipcamera.

License

The source code is released under:

GNU General Public License

If you think the Android project spydroid-ipcamera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2011-2014 GUIGUI Simon, fyhertz@gmail.com
 * /*from   w ww .j  av  a2  s  .  c  o  m*/
 * This file is part of libstreaming (https://github.com/fyhertz/libstreaming)
 * 
 * Spydroid is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This source code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this source code; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package net.majorkernelpanic.streaming.video;

import java.util.Iterator;
import java.util.List;

import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.util.Log;

/**
 * A class that represents the quality of a video stream. 
 * It contains the resolution, the framerate (in fps) and the bitrate (in bps) of the stream.
 */
public class VideoQuality {

  public final static String TAG = "VideoQuality";
  
  /** Default video stream quality. */
  public final static VideoQuality DEFAULT_VIDEO_QUALITY = new VideoQuality(176,144,20,500000);

  /**  Represents a quality for a video stream. */ 
  public VideoQuality() {}

  /**
   * Represents a quality for a video stream.
   * @param resX The horizontal resolution
   * @param resY The vertical resolution
   */
  public VideoQuality(int resX, int resY) {
    this.resX = resX;
    this.resY = resY;
  }  

  /**
   * Represents a quality for a video stream.
   * @param resX The horizontal resolution
   * @param resY The vertical resolution
   * @param framerate The framerate in frame per seconds
   * @param bitrate The bitrate in bit per seconds 
   */
  public VideoQuality(int resX, int resY, int framerate, int bitrate) {
    this.framerate = framerate;
    this.bitrate = bitrate;
    this.resX = resX;
    this.resY = resY;
  }

  public int framerate = 0;
  public int bitrate = 0;
  public int resX = 0;
  public int resY = 0;

  public boolean equals(VideoQuality quality) {
    if (quality==null) return false;
    return (quality.resX == this.resX         &
        quality.resY == this.resY         &
        quality.framerate == this.framerate  &
        quality.bitrate == this.bitrate);
  }

  public VideoQuality clone() {
    return new VideoQuality(resX,resY,framerate,bitrate);
  }

  public static VideoQuality parseQuality(String str) {
    VideoQuality quality = DEFAULT_VIDEO_QUALITY.clone();
    if (str != null) {
      String[] config = str.split("-");
      try {
        quality.bitrate = Integer.parseInt(config[0])*1000; // conversion to bit/s
        quality.framerate = Integer.parseInt(config[1]);
        quality.resX = Integer.parseInt(config[2]);
        quality.resY = Integer.parseInt(config[3]);
      }
      catch (IndexOutOfBoundsException ignore) {}
    }
    return quality;
  }

  /** 
   * Checks if the requested resolution is supported by the camera.
   * If not, it modifies it by supported parameters. 
   **/
  public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
    VideoQuality v = quality.clone();
    int minDist = Integer.MAX_VALUE;
    String supportedSizesStr = "Supported resolutions: ";
    List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
    for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
      Size size = it.next();
      supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
      int dist = Math.abs(quality.resX - size.width);
      if (dist<minDist) {
        minDist = dist;
        v.resX = size.width;
        v.resY = size.height;
      }
    }
    Log.v(TAG, supportedSizesStr);
    if (quality.resX != v.resX || quality.resY != v.resY) {
      Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
    }
    
    return v;
  }

  public static int[] determineMaximumSupportedFramerate(Camera.Parameters parameters) {
    int[] maxFps = new int[]{0,0};
    String supportedFpsRangesStr = "Supported frame rates: ";
    List<int[]> supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
    for (Iterator<int[]> it = supportedFpsRanges.iterator(); it.hasNext();) {
      int[] interval = it.next();
      supportedFpsRangesStr += interval[0]/1000+"-"+interval[1]/1000+"fps"+(it.hasNext()?", ":"");
      if (interval[1]>maxFps[1] || (interval[0]>maxFps[0] && interval[1]==maxFps[1])) {
        maxFps = interval; 
      }
    }
    Log.v(TAG,supportedFpsRangesStr);
    return maxFps;
  }
  
}




Java Source Code List

net.majorkernelpanic.http.ModAssetServer.java
net.majorkernelpanic.http.ModInternationalization.java
net.majorkernelpanic.http.ModSSL.java
net.majorkernelpanic.http.TinyHttpServer.java
net.majorkernelpanic.spydroid.SpydroidApplication.java
net.majorkernelpanic.spydroid.Utilities.java
net.majorkernelpanic.spydroid.api.CustomHttpServer.java
net.majorkernelpanic.spydroid.api.CustomRtspServer.java
net.majorkernelpanic.spydroid.api.RequestHandler.java
net.majorkernelpanic.spydroid.ui.AboutFragment.java
net.majorkernelpanic.spydroid.ui.HandsetFragment.java
net.majorkernelpanic.spydroid.ui.OptionsActivity.java
net.majorkernelpanic.spydroid.ui.PreviewFragment.java
net.majorkernelpanic.spydroid.ui.SpydroidActivity.java
net.majorkernelpanic.spydroid.ui.TabletFragment.java
net.majorkernelpanic.streaming.MediaStream.java
net.majorkernelpanic.streaming.SessionBuilder.java
net.majorkernelpanic.streaming.Session.java
net.majorkernelpanic.streaming.Stream.java
net.majorkernelpanic.streaming.audio.AACStream.java
net.majorkernelpanic.streaming.audio.AMRNBStream.java
net.majorkernelpanic.streaming.audio.AudioQuality.java
net.majorkernelpanic.streaming.audio.AudioStream.java
net.majorkernelpanic.streaming.exceptions.CameraInUseException.java
net.majorkernelpanic.streaming.exceptions.ConfNotSupportedException.java
net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException.java
net.majorkernelpanic.streaming.exceptions.StorageUnavailableException.java
net.majorkernelpanic.streaming.gl.SurfaceManager.java
net.majorkernelpanic.streaming.gl.SurfaceView.java
net.majorkernelpanic.streaming.gl.TextureManager.java
net.majorkernelpanic.streaming.hw.CodecManager.java
net.majorkernelpanic.streaming.hw.EncoderDebugger.java
net.majorkernelpanic.streaming.hw.NV21Convertor.java
net.majorkernelpanic.streaming.mp4.MP4Config.java
net.majorkernelpanic.streaming.mp4.MP4Parser.java
net.majorkernelpanic.streaming.rtcp.SenderReport.java
net.majorkernelpanic.streaming.rtp.AACADTSPacketizer.java
net.majorkernelpanic.streaming.rtp.AACLATMPacketizer.java
net.majorkernelpanic.streaming.rtp.AMRNBPacketizer.java
net.majorkernelpanic.streaming.rtp.AbstractPacketizer.java
net.majorkernelpanic.streaming.rtp.H263Packetizer.java
net.majorkernelpanic.streaming.rtp.H264Packetizer.java
net.majorkernelpanic.streaming.rtp.MediaCodecInputStream.java
net.majorkernelpanic.streaming.rtp.RtpSocket.java
net.majorkernelpanic.streaming.rtsp.RtspClient.java
net.majorkernelpanic.streaming.rtsp.RtspServer.java
net.majorkernelpanic.streaming.rtsp.UriParser.java
net.majorkernelpanic.streaming.video.CodecManager.java
net.majorkernelpanic.streaming.video.H263Stream.java
net.majorkernelpanic.streaming.video.H264Stream.java
net.majorkernelpanic.streaming.video.VideoQuality.java
net.majorkernelpanic.streaming.video.VideoStream.java