Java Code Examples for com.google.android.exoplayer2.util.Log#e()

The following examples show how to use com.google.android.exoplayer2.util.Log#e() . 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: DownloadManager.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void initialize(int notMetRequirements) {
  this.notMetRequirements = notMetRequirements;
  DownloadCursor cursor = null;
  try {
    downloadIndex.setDownloadingStatesToQueued();
    cursor =
        downloadIndex.getDownloads(
            STATE_QUEUED, STATE_STOPPED, STATE_DOWNLOADING, STATE_REMOVING, STATE_RESTARTING);
    while (cursor.moveToNext()) {
      downloads.add(cursor.getDownload());
    }
  } catch (IOException e) {
    Log.e(TAG, "Failed to load index.", e);
    downloads.clear();
  } finally {
    Util.closeQuietly(cursor);
  }
  // A copy must be used for the message to ensure that subsequent changes to the downloads list
  // are not visible to the main thread when it processes the message.
  ArrayList<Download> downloadsForMessage = new ArrayList<>(downloads);
  mainHandler.obtainMessage(MSG_INITIALIZED, downloadsForMessage).sendToTarget();
  syncTasks();
}
 
Example 2
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private Download putDownload(Download download) {
  // Downloads in terminal states shouldn't be in the downloads list.
  Assertions.checkState(download.state != STATE_COMPLETED && download.state != STATE_FAILED);
  int changedIndex = getDownloadIndex(download.request.id);
  if (changedIndex == C.INDEX_UNSET) {
    downloads.add(download);
    Collections.sort(downloads, InternalHandler::compareStartTimes);
  } else {
    boolean needsSort = download.startTimeMs != downloads.get(changedIndex).startTimeMs;
    downloads.set(changedIndex, download);
    if (needsSort) {
      Collections.sort(downloads, InternalHandler::compareStartTimes);
    }
  }
  try {
    downloadIndex.putDownload(download);
  } catch (IOException e) {
    Log.e(TAG, "Failed to update index.", e);
  }
  DownloadUpdate update =
      new DownloadUpdate(download, /* isRemove= */ false, new ArrayList<>(downloads));
  mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
  return download;
}
 
Example 3
Source File: SimpleCache.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void release() {
  if (released) {
    return;
  }
  listeners.clear();
  removeStaleSpans();
  try {
    contentIndex.store();
  } catch (IOException e) {
    Log.e(TAG, "Storing index file failed", e);
  } finally {
    unlockFolder(cacheDir);
    released = true;
  }
}
 
Example 4
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private Download putDownload(Download download) {
  // Downloads in terminal states shouldn't be in the downloads list.
  Assertions.checkState(download.state != STATE_COMPLETED && download.state != STATE_FAILED);
  int changedIndex = getDownloadIndex(download.request.id);
  if (changedIndex == C.INDEX_UNSET) {
    downloads.add(download);
    Collections.sort(downloads, InternalHandler::compareStartTimes);
  } else {
    boolean needsSort = download.startTimeMs != downloads.get(changedIndex).startTimeMs;
    downloads.set(changedIndex, download);
    if (needsSort) {
      Collections.sort(downloads, InternalHandler::compareStartTimes);
    }
  }
  try {
    downloadIndex.putDownload(download);
  } catch (IOException e) {
    Log.e(TAG, "Failed to update index.", e);
  }
  DownloadUpdate update =
      new DownloadUpdate(download, /* isRemove= */ false, new ArrayList<>(downloads));
  mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
  return download;
}
 
Example 5
Source File: SimpleCache.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Loads the cache UID from the files belonging to the root directory.
 *
 * @param files The files belonging to the root directory.
 * @return The loaded UID, or {@link #UID_UNSET} if a UID has not yet been created.
 * @throws IOException If there is an error loading or generating the UID.
 */
private static long loadUid(File[] files) {
  for (File file : files) {
    String fileName = file.getName();
    if (fileName.endsWith(UID_FILE_SUFFIX)) {
      try {
        return parseUid(fileName);
      } catch (NumberFormatException e) {
        // This should never happen, but if it does delete the malformed UID file and continue.
        Log.e(TAG, "Malformed UID file: " + file);
        file.delete();
      }
    }
  }
  return UID_UNSET;
}
 
Example 6
Source File: SimpleCache.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Loads the cache UID from the files belonging to the root directory.
 *
 * @param files The files belonging to the root directory.
 * @return The loaded UID, or {@link #UID_UNSET} if a UID has not yet been created.
 * @throws IOException If there is an error loading or generating the UID.
 */
private static long loadUid(File[] files) {
  for (File file : files) {
    String fileName = file.getName();
    if (fileName.endsWith(UID_FILE_SUFFIX)) {
      try {
        return parseUid(fileName);
      } catch (NumberFormatException e) {
        // This should never happen, but if it does delete the malformed UID file and continue.
        Log.e(TAG, "Malformed UID file: " + file);
        file.delete();
      }
    }
  }
  return UID_UNSET;
}
 
Example 7
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void onDownloadTaskStopped(Download download, @Nullable Throwable finalError) {
  download =
      new Download(
          download.request,
          finalError == null ? STATE_COMPLETED : STATE_FAILED,
          download.startTimeMs,
          /* updateTimeMs= */ System.currentTimeMillis(),
          download.contentLength,
          download.stopReason,
          finalError == null ? FAILURE_REASON_NONE : FAILURE_REASON_UNKNOWN,
          download.progress);
  // The download is now in a terminal state, so should not be in the downloads list.
  downloads.remove(getDownloadIndex(download.request.id));
  // We still need to update the download index and main thread.
  try {
    downloadIndex.putDownload(download);
  } catch (IOException e) {
    Log.e(TAG, "Failed to update index.", e);
  }
  DownloadUpdate update =
      new DownloadUpdate(download, /* isRemove= */ false, new ArrayList<>(downloads));
  mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
}
 
Example 8
Source File: TeeAudioProcessor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void handleBuffer(ByteBuffer buffer) {
  try {
    maybePrepareFile();
    writeBuffer(buffer);
  } catch (IOException e) {
    Log.e(TAG, "Error writing data", e);
  }
}
 
Example 9
Source File: DefaultDrmSession.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({"sessionId", "offlineLicenseKeySetId"})
private boolean restoreKeys() {
  try {
    mediaDrm.restoreKeys(sessionId, offlineLicenseKeySetId);
    return true;
  } catch (Exception e) {
    Log.e(TAG, "Error trying to restore Widevine keys.", e);
    onError(e);
  }
  return false;
}
 
Example 10
Source File: DefaultHttpDataSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Closes the current connection quietly, if there is one.
 */
private void closeConnectionQuietly() {
  if (connection != null) {
    try {
      connection.disconnect();
    } catch (Exception e) {
      Log.e(TAG, "Unexpected error while disconnecting", e);
    }
    connection = null;
  }
}
 
Example 11
Source File: VorbisUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void readMappings(int channels, VorbisBitArray bitArray)
    throws ParserException {
  int mappingsCount = bitArray.readBits(6) + 1;
  for (int i = 0; i < mappingsCount; i++) {
    int mappingType = bitArray.readBits(16);
    if (mappingType != 0) {
      Log.e(TAG, "mapping type other than 0 not supported: " + mappingType);
      continue;
    }
    int submaps;
    if (bitArray.readBit()) {
      submaps = bitArray.readBits(4) + 1;
    } else {
      submaps = 1;
    }
    int couplingSteps;
    if (bitArray.readBit()) {
      couplingSteps = bitArray.readBits(8) + 1;
      for (int j = 0; j < couplingSteps; j++) {
        bitArray.skipBits(iLog(channels - 1)); // magnitude
        bitArray.skipBits(iLog(channels - 1)); // angle
      }
    } /*else {
        couplingSteps = 0;
      }*/
    if (bitArray.readBits(2) != 0x00) {
      throw new ParserException("to reserved bits must be zero after mapping coupling steps");
    }
    if (submaps > 1) {
      for (int j = 0; j < channels; j++) {
        bitArray.skipBits(4); // mappingMux
      }
    }
    for (int j = 0; j < submaps; j++) {
      bitArray.skipBits(8); // discard
      bitArray.skipBits(8); // submapFloor
      bitArray.skipBits(8); // submapResidue
    }
  }
}
 
Example 12
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void updateProgress() {
  for (int i = 0; i < downloads.size(); i++) {
    Download download = downloads.get(i);
    if (download.state == STATE_DOWNLOADING) {
      try {
        downloadIndex.putDownload(download);
      } catch (IOException e) {
        Log.e(TAG, "Failed to update index.", e);
      }
    }
  }
  sendEmptyMessageDelayed(MSG_UPDATE_PROGRESS, UPDATE_PROGRESS_INTERVAL_MS);
}
 
Example 13
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updateProgress() {
  for (int i = 0; i < downloads.size(); i++) {
    Download download = downloads.get(i);
    if (download.state == STATE_DOWNLOADING) {
      try {
        downloadIndex.putDownload(download);
      } catch (IOException e) {
        Log.e(TAG, "Failed to update index.", e);
      }
    }
  }
  sendEmptyMessageDelayed(MSG_UPDATE_PROGRESS, UPDATE_PROGRESS_INTERVAL_MS);
}
 
Example 14
Source File: ExoDatabaseProvider.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes a best effort to wipe the existing database. The wipe may be incomplete if the database
 * contains foreign key constraints.
 */
private static void wipeDatabase(SQLiteDatabase db) {
  String[] columns = {"type", "name"};
  try (Cursor cursor =
      db.query(
          "sqlite_master",
          columns,
          /* selection= */ null,
          /* selectionArgs= */ null,
          /* groupBy= */ null,
          /* having= */ null,
          /* orderBy= */ null)) {
    while (cursor.moveToNext()) {
      String type = cursor.getString(0);
      String name = cursor.getString(1);
      if (!"sqlite_sequence".equals(name)) {
        // If it's not an SQL-controlled entity, drop it
        String sql = "DROP " + type + " IF EXISTS " + name;
        try {
          db.execSQL(sql);
        } catch (SQLException e) {
          Log.e(TAG, "Error executing " + sql, e);
        }
      }
    }
  }
}
 
Example 15
Source File: DefaultDrmSession.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull({"sessionId", "offlineLicenseKeySetId"})
private boolean restoreKeys() {
  try {
    mediaDrm.restoreKeys(sessionId, offlineLicenseKeySetId);
    return true;
  } catch (Exception e) {
    Log.e(TAG, "Error trying to restore keys.", e);
    onError(e);
  }
  return false;
}
 
Example 16
Source File: Cea708Decoder.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
protected void decode(SubtitleInputBuffer inputBuffer) {
  // Subtitle input buffers are non-direct and the position is zero, so calling array() is safe.
  @SuppressWarnings("ByteBufferBackingArray")
  byte[] inputBufferData = inputBuffer.data.array();
  ccData.reset(inputBufferData, inputBuffer.data.limit());
  while (ccData.bytesLeft() >= 3) {
    int ccTypeAndValid = (ccData.readUnsignedByte() & 0x07);

    int ccType = ccTypeAndValid & (DTVCC_PACKET_DATA | DTVCC_PACKET_START);
    boolean ccValid = (ccTypeAndValid & CC_VALID_FLAG) == CC_VALID_FLAG;
    byte ccData1 = (byte) ccData.readUnsignedByte();
    byte ccData2 = (byte) ccData.readUnsignedByte();

    // Ignore any non-CEA-708 data
    if (ccType != DTVCC_PACKET_DATA && ccType != DTVCC_PACKET_START) {
      continue;
    }

    if (!ccValid) {
      // This byte-pair isn't valid, ignore it and continue.
      continue;
    }

    if (ccType == DTVCC_PACKET_START) {
      finalizeCurrentPacket();

      int sequenceNumber = (ccData1 & 0xC0) >> 6; // first 2 bits
      int packetSize = ccData1 & 0x3F; // last 6 bits
      if (packetSize == 0) {
        packetSize = 64;
      }

      currentDtvCcPacket = new DtvCcPacket(sequenceNumber, packetSize);
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++] = ccData2;
    } else {
      // The only remaining valid packet type is DTVCC_PACKET_DATA
      Assertions.checkArgument(ccType == DTVCC_PACKET_DATA);

      if (currentDtvCcPacket == null) {
        Log.e(TAG, "Encountered DTVCC_PACKET_DATA before DTVCC_PACKET_START");
        continue;
      }

      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++] = ccData1;
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++] = ccData2;
    }

    if (currentDtvCcPacket.currentIndex == (currentDtvCcPacket.packetSize * 2 - 1)) {
      finalizeCurrentPacket();
    }
  }
}
 
Example 17
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void onUtcTimestampResolutionError(IOException error) {
  Log.e(TAG, "Failed to resolve UtcTiming element.", error);
  // Be optimistic and continue in the hope that the device clock is correct.
  processManifest(true);
}
 
Example 18
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void onUtcTimestampResolutionError(IOException error) {
  Log.e(TAG, "Failed to resolve UtcTiming element.", error);
  // Be optimistic and continue in the hope that the device clock is correct.
  processManifest(true);
}
 
Example 19
Source File: Cea708Decoder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void decode(SubtitleInputBuffer inputBuffer) {
  // Subtitle input buffers are non-direct and the position is zero, so calling array() is safe.
  @SuppressWarnings("ByteBufferBackingArray")
  byte[] inputBufferData = inputBuffer.data.array();
  ccData.reset(inputBufferData, inputBuffer.data.limit());
  while (ccData.bytesLeft() >= 3) {
    int ccTypeAndValid = (ccData.readUnsignedByte() & 0x07);

    int ccType = ccTypeAndValid & (DTVCC_PACKET_DATA | DTVCC_PACKET_START);
    boolean ccValid = (ccTypeAndValid & CC_VALID_FLAG) == CC_VALID_FLAG;
    byte ccData1 = (byte) ccData.readUnsignedByte();
    byte ccData2 = (byte) ccData.readUnsignedByte();

    // Ignore any non-CEA-708 data
    if (ccType != DTVCC_PACKET_DATA && ccType != DTVCC_PACKET_START) {
      continue;
    }

    if (!ccValid) {
      // This byte-pair isn't valid, ignore it and continue.
      continue;
    }

    if (ccType == DTVCC_PACKET_START) {
      finalizeCurrentPacket();

      int sequenceNumber = (ccData1 & 0xC0) >> 6; // first 2 bits
      int packetSize = ccData1 & 0x3F; // last 6 bits
      if (packetSize == 0) {
        packetSize = 64;
      }

      currentDtvCcPacket = new DtvCcPacket(sequenceNumber, packetSize);
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++] = ccData2;
    } else {
      // The only remaining valid packet type is DTVCC_PACKET_DATA
      Assertions.checkArgument(ccType == DTVCC_PACKET_DATA);

      if (currentDtvCcPacket == null) {
        Log.e(TAG, "Encountered DTVCC_PACKET_DATA before DTVCC_PACKET_START");
        continue;
      }

      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++] = ccData1;
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++] = ccData2;
    }

    if (currentDtvCcPacket.currentIndex == (currentDtvCcPacket.packetSize * 2 - 1)) {
      finalizeCurrentPacket();
    }
  }
}
 
Example 20
Source File: Loader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleMessage(Message msg) {
  if (released) {
    return;
  }
  if (msg.what == MSG_START) {
    execute();
    return;
  }
  if (msg.what == MSG_FATAL_ERROR) {
    throw (Error) msg.obj;
  }
  finish();
  long nowMs = SystemClock.elapsedRealtime();
  long durationMs = nowMs - startTimeMs;
  if (canceled) {
    callback.onLoadCanceled(loadable, nowMs, durationMs, false);
    return;
  }
  switch (msg.what) {
    case MSG_CANCEL:
      callback.onLoadCanceled(loadable, nowMs, durationMs, false);
      break;
    case MSG_END_OF_SOURCE:
      try {
        callback.onLoadCompleted(loadable, nowMs, durationMs);
      } catch (RuntimeException e) {
        // This should never happen, but handle it anyway.
        Log.e(TAG, "Unexpected exception handling load completed", e);
        fatalError = new UnexpectedLoaderException(e);
      }
      break;
    case MSG_IO_EXCEPTION:
      currentError = (IOException) msg.obj;
      errorCount++;
      LoadErrorAction action =
          callback.onLoadError(loadable, nowMs, durationMs, currentError, errorCount);
      if (action.type == ACTION_TYPE_DONT_RETRY_FATAL) {
        fatalError = currentError;
      } else if (action.type != ACTION_TYPE_DONT_RETRY) {
        if (action.type == ACTION_TYPE_RETRY_AND_RESET_ERROR_COUNT) {
          errorCount = 1;
        }
        start(
            action.retryDelayMillis != C.TIME_UNSET
                ? action.retryDelayMillis
                : getRetryDelayMillis());
      }
      break;
    default:
      // Never happens.
      break;
  }
}