Java Code Examples for com.google.android.exoplayer2.C#StereoMode

The following examples show how to use com.google.android.exoplayer2.C#StereoMode . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectionDecoder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public static @Nullable Projection decode(byte[] projectionData, @C.StereoMode int stereoMode) {
  ParsableByteArray input = new ParsableByteArray(projectionData);
  // MP4 containers include the proj box but webm containers do not.
  // Both containers use mshp.
  ArrayList<Mesh> meshes = null;
  try {
    meshes = isProj(input) ? parseProj(input) : parseMshp(input);
  } catch (ArrayIndexOutOfBoundsException ignored) {
    // Do nothing.
  }
  if (meshes == null) {
    return null;
  } else {
    switch (meshes.size()) {
      case 1:
        return new Projection(meshes.get(0), stereoMode);
      case 2:
        return new Projection(meshes.get(0), meshes.get(1), stereoMode);
      case 0:
      default:
        return null;
    }
  }
}
 
Example 2
Source File: ProjectionDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static @Nullable Projection decode(byte[] projectionData, @C.StereoMode int stereoMode) {
  ParsableByteArray input = new ParsableByteArray(projectionData);
  // MP4 containers include the proj box but webm containers do not.
  // Both containers use mshp.
  ArrayList<Mesh> meshes = null;
  try {
    meshes = isProj(input) ? parseProj(input) : parseMshp(input);
  } catch (ArrayIndexOutOfBoundsException ignored) {
    // Do nothing.
  }
  if (meshes == null) {
    return null;
  } else {
    switch (meshes.size()) {
      case 1:
        return new Projection(meshes.get(0), stereoMode);
      case 2:
        return new Projection(meshes.get(0), meshes.get(1), stereoMode);
      case 0:
      default:
        return null;
    }
  }
}
 
Example 3
Source File: ProjectionDecoder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static @Nullable Projection decode(byte[] projectionData, @C.StereoMode int stereoMode) {
  ParsableByteArray input = new ParsableByteArray(projectionData);
  // MP4 containers include the proj box but webm containers do not.
  // Both containers use mshp.
  ArrayList<Mesh> meshes = null;
  try {
    meshes = isProj(input) ? parseProj(input) : parseMshp(input);
  } catch (ArrayIndexOutOfBoundsException ignored) {
    // Do nothing.
  }
  if (meshes == null) {
    return null;
  } else {
    switch (meshes.size()) {
      case 1:
        return new Projection(meshes.get(0), stereoMode);
      case 2:
        return new Projection(meshes.get(0), meshes.get(1), stereoMode);
      case 0:
      default:
        return null;
    }
  }
}
 
Example 4
Source File: Projection.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a complete sphere equirectangular projection.
 *
 * @param stereoMode A {@link C.StereoMode} value.
 */
public static Projection createEquirectangular(@C.StereoMode int stereoMode) {
  return createEquirectangular(
      /* radius= */ 50, // Should be large enough that there are no stereo artifacts.
      /* latitudes= */ 36, // Should be large enough to prevent videos looking wavy.
      /* longitudes= */ 72, // Should be large enough to prevent videos looking wavy.
      /* verticalFovDegrees= */ 180,
      /* horizontalFovDegrees= */ 360,
      stereoMode);
}
 
Example 5
Source File: Projection.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a complete sphere equirectangular projection.
 *
 * @param stereoMode A {@link C.StereoMode} value.
 */
public static Projection createEquirectangular(@C.StereoMode int stereoMode) {
  return createEquirectangular(
      /* radius= */ 50, // Should be large enough that there are no stereo artifacts.
      /* latitudes= */ 36, // Should be large enough to prevent videos looking wavy.
      /* longitudes= */ 72, // Should be large enough to prevent videos looking wavy.
      /* verticalFovDegrees= */ 180,
      /* horizontalFovDegrees= */ 360,
      stereoMode);
}
 
Example 6
Source File: Projection.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a complete sphere equirectangular projection.
 *
 * @param stereoMode A {@link C.StereoMode} value.
 */
public static Projection createEquirectangular(@C.StereoMode int stereoMode) {
  return createEquirectangular(
      /* radius= */ 50, // Should be large enough that there are no stereo artifacts.
      /* latitudes= */ 36, // Should be large enough to prevent videos looking wavy.
      /* longitudes= */ 72, // Should be large enough to prevent videos looking wavy.
      /* verticalFovDegrees= */ 180,
      /* horizontalFovDegrees= */ 360,
      stereoMode);
}
 
Example 7
Source File: Projection.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Generates an equirectangular projection.
 *
 * @param radius Size of the sphere. Must be &gt; 0.
 * @param latitudes Number of rows that make up the sphere. Must be &gt;= 1.
 * @param longitudes Number of columns that make up the sphere. Must be &gt;= 1.
 * @param verticalFovDegrees Total latitudinal degrees that are covered by the sphere. Must be in
 *     (0, 180].
 * @param horizontalFovDegrees Total longitudinal degrees that are covered by the sphere.Must be
 *     in (0, 360].
 * @param stereoMode A {@link C.StereoMode} value.
 * @return an equirectangular projection.
 */
public static Projection createEquirectangular(
    float radius,
    int latitudes,
    int longitudes,
    float verticalFovDegrees,
    float horizontalFovDegrees,
    @C.StereoMode int stereoMode) {
  Assertions.checkArgument(radius > 0);
  Assertions.checkArgument(latitudes >= 1);
  Assertions.checkArgument(longitudes >= 1);
  Assertions.checkArgument(verticalFovDegrees > 0 && verticalFovDegrees <= 180);
  Assertions.checkArgument(horizontalFovDegrees > 0 && horizontalFovDegrees <= 360);

  // Compute angular size in radians of each UV quad.
  float verticalFovRads = (float) Math.toRadians(verticalFovDegrees);
  float horizontalFovRads = (float) Math.toRadians(horizontalFovDegrees);
  float quadHeightRads = verticalFovRads / latitudes;
  float quadWidthRads = horizontalFovRads / longitudes;

  // Each latitude strip has 2 * (longitudes quads + extra edge) vertices + 2 degenerate vertices.
  int vertexCount = (2 * (longitudes + 1) + 2) * latitudes;
  // Buffer to return.
  float[] vertexData = new float[vertexCount * POSITION_COORDS_PER_VERTEX];
  float[] textureData = new float[vertexCount * TEXTURE_COORDS_PER_VERTEX];

  // Generate the data for the sphere which is a set of triangle strips representing each
  // latitude band.
  int vOffset = 0; // Offset into the vertexData array.
  int tOffset = 0; // Offset into the textureData array.
  // (i, j) represents a quad in the equirectangular sphere.
  for (int j = 0; j < latitudes; ++j) { // For each horizontal triangle strip.
    // Each latitude band lies between the two phi values. Each vertical edge on a band lies on
    // a theta value.
    float phiLow = quadHeightRads * j - verticalFovRads / 2;
    float phiHigh = quadHeightRads * (j + 1) - verticalFovRads / 2;

    for (int i = 0; i < longitudes + 1; ++i) { // For each vertical edge in the band.
      for (int k = 0; k < 2; ++k) { // For low and high points on an edge.
        // For each point, determine it's position in polar coordinates.
        float phi = k == 0 ? phiLow : phiHigh;
        float theta = quadWidthRads * i + (float) Math.PI - horizontalFovRads / 2;

        // Set vertex position data as Cartesian coordinates.
        vertexData[vOffset++] = -(float) (radius * Math.sin(theta) * Math.cos(phi));
        vertexData[vOffset++] = (float) (radius * Math.sin(phi));
        vertexData[vOffset++] = (float) (radius * Math.cos(theta) * Math.cos(phi));

        textureData[tOffset++] = i * quadWidthRads / horizontalFovRads;
        textureData[tOffset++] = (j + k) * quadHeightRads / verticalFovRads;

        // Break up the triangle strip with degenerate vertices by copying first and last points.
        if ((i == 0 && k == 0) || (i == longitudes && k == 1)) {
          System.arraycopy(
              vertexData,
              vOffset - POSITION_COORDS_PER_VERTEX,
              vertexData,
              vOffset,
              POSITION_COORDS_PER_VERTEX);
          vOffset += POSITION_COORDS_PER_VERTEX;
          System.arraycopy(
              textureData,
              tOffset - TEXTURE_COORDS_PER_VERTEX,
              textureData,
              tOffset,
              TEXTURE_COORDS_PER_VERTEX);
          tOffset += TEXTURE_COORDS_PER_VERTEX;
        }
      }
      // Move on to the next vertical edge in the triangle strip.
    }
    // Move on to the next triangle strip.
  }
  SubMesh subMesh =
      new SubMesh(SubMesh.VIDEO_TEXTURE_ID, vertexData, textureData, DRAW_MODE_TRIANGLES_STRIP);
  return new Projection(new Mesh(subMesh), stereoMode);
}
 
Example 8
Source File: Projection.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generates an equirectangular projection.
 *
 * @param radius Size of the sphere. Must be &gt; 0.
 * @param latitudes Number of rows that make up the sphere. Must be &gt;= 1.
 * @param longitudes Number of columns that make up the sphere. Must be &gt;= 1.
 * @param verticalFovDegrees Total latitudinal degrees that are covered by the sphere. Must be in
 *     (0, 180].
 * @param horizontalFovDegrees Total longitudinal degrees that are covered by the sphere.Must be
 *     in (0, 360].
 * @param stereoMode A {@link C.StereoMode} value.
 * @return an equirectangular projection.
 */
public static Projection createEquirectangular(
    float radius,
    int latitudes,
    int longitudes,
    float verticalFovDegrees,
    float horizontalFovDegrees,
    @C.StereoMode int stereoMode) {
  Assertions.checkArgument(radius > 0);
  Assertions.checkArgument(latitudes >= 1);
  Assertions.checkArgument(longitudes >= 1);
  Assertions.checkArgument(verticalFovDegrees > 0 && verticalFovDegrees <= 180);
  Assertions.checkArgument(horizontalFovDegrees > 0 && horizontalFovDegrees <= 360);

  // Compute angular size in radians of each UV quad.
  float verticalFovRads = (float) Math.toRadians(verticalFovDegrees);
  float horizontalFovRads = (float) Math.toRadians(horizontalFovDegrees);
  float quadHeightRads = verticalFovRads / latitudes;
  float quadWidthRads = horizontalFovRads / longitudes;

  // Each latitude strip has 2 * (longitudes quads + extra edge) vertices + 2 degenerate vertices.
  int vertexCount = (2 * (longitudes + 1) + 2) * latitudes;
  // Buffer to return.
  float[] vertexData = new float[vertexCount * POSITION_COORDS_PER_VERTEX];
  float[] textureData = new float[vertexCount * TEXTURE_COORDS_PER_VERTEX];

  // Generate the data for the sphere which is a set of triangle strips representing each
  // latitude band.
  int vOffset = 0; // Offset into the vertexData array.
  int tOffset = 0; // Offset into the textureData array.
  // (i, j) represents a quad in the equirectangular sphere.
  for (int j = 0; j < latitudes; ++j) { // For each horizontal triangle strip.
    // Each latitude band lies between the two phi values. Each vertical edge on a band lies on
    // a theta value.
    float phiLow = quadHeightRads * j - verticalFovRads / 2;
    float phiHigh = quadHeightRads * (j + 1) - verticalFovRads / 2;

    for (int i = 0; i < longitudes + 1; ++i) { // For each vertical edge in the band.
      for (int k = 0; k < 2; ++k) { // For low and high points on an edge.
        // For each point, determine it's position in polar coordinates.
        float phi = k == 0 ? phiLow : phiHigh;
        float theta = quadWidthRads * i + (float) Math.PI - horizontalFovRads / 2;

        // Set vertex position data as Cartesian coordinates.
        vertexData[vOffset++] = -(float) (radius * Math.sin(theta) * Math.cos(phi));
        vertexData[vOffset++] = (float) (radius * Math.sin(phi));
        vertexData[vOffset++] = (float) (radius * Math.cos(theta) * Math.cos(phi));

        textureData[tOffset++] = i * quadWidthRads / horizontalFovRads;
        textureData[tOffset++] = (j + k) * quadHeightRads / verticalFovRads;

        // Break up the triangle strip with degenerate vertices by copying first and last points.
        if ((i == 0 && k == 0) || (i == longitudes && k == 1)) {
          System.arraycopy(
              vertexData,
              vOffset - POSITION_COORDS_PER_VERTEX,
              vertexData,
              vOffset,
              POSITION_COORDS_PER_VERTEX);
          vOffset += POSITION_COORDS_PER_VERTEX;
          System.arraycopy(
              textureData,
              tOffset - TEXTURE_COORDS_PER_VERTEX,
              textureData,
              tOffset,
              TEXTURE_COORDS_PER_VERTEX);
          tOffset += TEXTURE_COORDS_PER_VERTEX;
        }
      }
      // Move on to the next vertical edge in the triangle strip.
    }
    // Move on to the next triangle strip.
  }
  SubMesh subMesh =
      new SubMesh(SubMesh.VIDEO_TEXTURE_ID, vertexData, textureData, DRAW_MODE_TRIANGLES_STRIP);
  return new Projection(new Mesh(subMesh), stereoMode);
}
 
Example 9
Source File: Projection.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generates an equirectangular projection.
 *
 * @param radius Size of the sphere. Must be &gt; 0.
 * @param latitudes Number of rows that make up the sphere. Must be &gt;= 1.
 * @param longitudes Number of columns that make up the sphere. Must be &gt;= 1.
 * @param verticalFovDegrees Total latitudinal degrees that are covered by the sphere. Must be in
 *     (0, 180].
 * @param horizontalFovDegrees Total longitudinal degrees that are covered by the sphere.Must be
 *     in (0, 360].
 * @param stereoMode A {@link C.StereoMode} value.
 * @return an equirectangular projection.
 */
public static Projection createEquirectangular(
    float radius,
    int latitudes,
    int longitudes,
    float verticalFovDegrees,
    float horizontalFovDegrees,
    @C.StereoMode int stereoMode) {
  Assertions.checkArgument(radius > 0);
  Assertions.checkArgument(latitudes >= 1);
  Assertions.checkArgument(longitudes >= 1);
  Assertions.checkArgument(verticalFovDegrees > 0 && verticalFovDegrees <= 180);
  Assertions.checkArgument(horizontalFovDegrees > 0 && horizontalFovDegrees <= 360);

  // Compute angular size in radians of each UV quad.
  float verticalFovRads = (float) Math.toRadians(verticalFovDegrees);
  float horizontalFovRads = (float) Math.toRadians(horizontalFovDegrees);
  float quadHeightRads = verticalFovRads / latitudes;
  float quadWidthRads = horizontalFovRads / longitudes;

  // Each latitude strip has 2 * (longitudes quads + extra edge) vertices + 2 degenerate vertices.
  int vertexCount = (2 * (longitudes + 1) + 2) * latitudes;
  // Buffer to return.
  float[] vertexData = new float[vertexCount * POSITION_COORDS_PER_VERTEX];
  float[] textureData = new float[vertexCount * TEXTURE_COORDS_PER_VERTEX];

  // Generate the data for the sphere which is a set of triangle strips representing each
  // latitude band.
  int vOffset = 0; // Offset into the vertexData array.
  int tOffset = 0; // Offset into the textureData array.
  // (i, j) represents a quad in the equirectangular sphere.
  for (int j = 0; j < latitudes; ++j) { // For each horizontal triangle strip.
    // Each latitude band lies between the two phi values. Each vertical edge on a band lies on
    // a theta value.
    float phiLow = quadHeightRads * j - verticalFovRads / 2;
    float phiHigh = quadHeightRads * (j + 1) - verticalFovRads / 2;

    for (int i = 0; i < longitudes + 1; ++i) { // For each vertical edge in the band.
      for (int k = 0; k < 2; ++k) { // For low and high points on an edge.
        // For each point, determine it's position in polar coordinates.
        float phi = k == 0 ? phiLow : phiHigh;
        float theta = quadWidthRads * i + (float) Math.PI - horizontalFovRads / 2;

        // Set vertex position data as Cartesian coordinates.
        vertexData[vOffset++] = -(float) (radius * Math.sin(theta) * Math.cos(phi));
        vertexData[vOffset++] = (float) (radius * Math.sin(phi));
        vertexData[vOffset++] = (float) (radius * Math.cos(theta) * Math.cos(phi));

        textureData[tOffset++] = i * quadWidthRads / horizontalFovRads;
        textureData[tOffset++] = (j + k) * quadHeightRads / verticalFovRads;

        // Break up the triangle strip with degenerate vertices by copying first and last points.
        if ((i == 0 && k == 0) || (i == longitudes && k == 1)) {
          System.arraycopy(
              vertexData,
              vOffset - POSITION_COORDS_PER_VERTEX,
              vertexData,
              vOffset,
              POSITION_COORDS_PER_VERTEX);
          vOffset += POSITION_COORDS_PER_VERTEX;
          System.arraycopy(
              textureData,
              tOffset - TEXTURE_COORDS_PER_VERTEX,
              textureData,
              tOffset,
              TEXTURE_COORDS_PER_VERTEX);
          tOffset += TEXTURE_COORDS_PER_VERTEX;
        }
      }
      // Move on to the next vertical edge in the triangle strip.
    }
    // Move on to the next triangle strip.
  }
  SubMesh subMesh =
      new SubMesh(SubMesh.VIDEO_TEXTURE_ID, vertexData, textureData, DRAW_MODE_TRIANGLES_STRIP);
  return new Projection(new Mesh(subMesh), stereoMode);
}