android.media.AudioRecordingConfiguration源码实例Demo

类android.media.AudioRecordingConfiguration源码实例Demo

下面列出了android.media.AudioRecordingConfiguration 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: talkback   文件: MediaRecorderMonitor.java
public MediaRecorderMonitor(Context context) {
  audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  if (BuildVersionUtils.isAtLeastN()) {
    audioRecordingCallback =
        new AudioRecordingCallback() {
          @Override
          public void onRecordingConfigChanged(List<AudioRecordingConfiguration> configs) {
            super.onRecordingConfigChanged(configs);
            isVoiceRecognitionActive =
                containsAudioSource(configs, AudioSource.VOICE_RECOGNITION);
            final boolean isRecording = containsAudioSources(configs);
            if (!MediaRecorderMonitor.this.isRecording && isRecording) {
              listener.onMicrophoneActivated();
            }
            MediaRecorderMonitor.this.isRecording = isRecording;
          }
        };
  } else {
    audioRecordingCallback = null;
  }
}
 
源代码2 项目: talkback   文件: MediaRecorderMonitor.java
@TargetApi(Build.VERSION_CODES.N)
private boolean containsAudioSources(List<AudioRecordingConfiguration> configs) {
  if (configs == null) {
    return false;
  }
  // Try to find a target audio source in the recording configurations.
  for (AudioSource source : AudioSource.values()) {
    int sourceId = source.getId();
    for (AudioRecordingConfiguration config : configs) {
      if (sourceId == config.getClientAudioSource()) {
        return true;
      }
    }
  }
  return false;
}
 
/**
 * Implementation of android.media.AudioSystem.AudioRecordingCallback
 */
public void onRecordingConfigurationChanged(int event, int uid, int session, int source,
        int[] recordingInfo, String packName) {
    if (MediaRecorder.isSystemOnlyAudioSource(source)) {
        return;
    }
    final List<AudioRecordingConfiguration> configsSystem =
            updateSnapshot(event, uid, session, source, recordingInfo);
    if (configsSystem != null){
        synchronized (mClients) {
            // list of recording configurations for "public consumption". It is only computed if
            // there are non-system recording activity listeners.
            final List<AudioRecordingConfiguration> configsPublic = mHasPublicClients ?
                    anonymizeForPublicConsumption(configsSystem) :
                        new ArrayList<AudioRecordingConfiguration>();
            final Iterator<RecMonitorClient> clientIterator = mClients.iterator();
            while (clientIterator.hasNext()) {
                final RecMonitorClient rmc = clientIterator.next();
                try {
                    if (rmc.mIsPrivileged) {
                        rmc.mDispatcherCb.dispatchRecordingConfigChange(configsSystem);
                    } else {
                        rmc.mDispatcherCb.dispatchRecordingConfigChange(configsPublic);
                    }
                } catch (RemoteException e) {
                    Log.w(TAG, "Could not call dispatchRecordingConfigChange() on client", e);
                }
            }
        }
    }
}
 
protected void dump(PrintWriter pw) {
    // players
    pw.println("\nRecordActivityMonitor dump time: "
            + DateFormat.getTimeInstance().format(new Date()));
    synchronized(mRecordConfigs) {
        for (AudioRecordingConfiguration conf : mRecordConfigs.values()) {
            conf.dump(pw);
        }
    }
    pw.println("\n");
    // log
    sEventLogger.dump(pw);
}
 
private ArrayList<AudioRecordingConfiguration> anonymizeForPublicConsumption(
        List<AudioRecordingConfiguration> sysConfigs) {
    ArrayList<AudioRecordingConfiguration> publicConfigs =
            new ArrayList<AudioRecordingConfiguration>();
    // only add active anonymized configurations,
    for (AudioRecordingConfiguration config : sysConfigs) {
        publicConfigs.add(AudioRecordingConfiguration.anonymizedCopy(config));
    }
    return publicConfigs;
}
 
List<AudioRecordingConfiguration> getActiveRecordingConfigurations(boolean isPrivileged) {
    synchronized(mRecordConfigs) {
        if (isPrivileged) {
            return new ArrayList<AudioRecordingConfiguration>(mRecordConfigs.values());
        } else {
            final List<AudioRecordingConfiguration> configsPublic =
                    anonymizeForPublicConsumption(
                        new ArrayList<AudioRecordingConfiguration>(mRecordConfigs.values()));
            return configsPublic;
        }
    }
}
 
源代码7 项目: talkback   文件: SpeechControllerImpl.java
/**
 * Called when transitioning from an idle state to a speaking state, e.g. the queue was empty,
 * there was no current speech, a speech item was added to the queue, and {@link #resume()} is
 * called when status is {@link #STATUS_PAUSE} .
 *
 * @see #handleSpeechCompleted(int status)
 */
@TargetApi(Build.VERSION_CODES.N)
private void handleSpeechStarting() {
  for (SpeechController.Observer observer : mObservers) {
    observer.onSpeechStarting();
  }

  boolean useAudioFocus = mUseAudioFocus;
  if (BuildVersionUtils.isAtLeastN()) {
    List<AudioRecordingConfiguration> recordConfigurations =
        mAudioManager.getActiveRecordingConfigurations();
    if (recordConfigurations.size() != 0) {
      useAudioFocus = false;
    }
  }

  if (useAudioFocus) {
    if (BuildVersionUtils.isAtLeastO()) {
      mAudioManager.requestAudioFocus(mAudioFocusRequest);
    } else {
      mAudioManager.requestAudioFocus(
          mAudioFocusListener, DEFAULT_STREAM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
    }
  }

  if (mIsSpeaking) {
    LogUtils.e(TAG, "Started speech while already speaking!");
  }

  mIsSpeaking = true;
}
 
源代码8 项目: talkback   文件: MediaRecorderMonitor.java
private boolean containsAudioSource(
    List<AudioRecordingConfiguration> configs, AudioSource targetSource) {
  if (configs == null || targetSource == null) {
    return false;
  }
  for (AudioRecordingConfiguration config : configs) {
    if (config.getClientAudioSource() == targetSource.getId()) {
      return true;
    }
  }
  return false;
}
 
/**
 * Update the internal "view" of the active recording sessions
 * @param event
 * @param session
 * @param source
 * @param recordingFormat see
 *     {@link AudioSystem.AudioRecordingCallback#onRecordingConfigurationChanged(int, int, int, int[])}
 *     for the definition of the contents of the array
 * @return null if the list of active recording sessions has not been modified, a list
 *     with the current active configurations otherwise.
 */
private List<AudioRecordingConfiguration> updateSnapshot(int event, int uid, int session,
        int source, int[] recordingInfo) {
    final boolean configChanged;
    final ArrayList<AudioRecordingConfiguration> configs;
    synchronized(mRecordConfigs) {
        switch (event) {
        case AudioManager.RECORD_CONFIG_EVENT_STOP:
            // return failure if an unknown recording session stopped
            configChanged = (mRecordConfigs.remove(new Integer(session)) != null);
            if (configChanged) {
                sEventLogger.log(new RecordingEvent(event, uid, session, source, null));
            }
            break;
        case AudioManager.RECORD_CONFIG_EVENT_START:
            final AudioFormat clientFormat = new AudioFormat.Builder()
                    .setEncoding(recordingInfo[0])
                    // FIXME this doesn't support index-based masks
                    .setChannelMask(recordingInfo[1])
                    .setSampleRate(recordingInfo[2])
                    .build();
            final AudioFormat deviceFormat = new AudioFormat.Builder()
                    .setEncoding(recordingInfo[3])
                    // FIXME this doesn't support index-based masks
                    .setChannelMask(recordingInfo[4])
                    .setSampleRate(recordingInfo[5])
                    .build();
            final int patchHandle = recordingInfo[6];
            final Integer sessionKey = new Integer(session);

            final String[] packages = mPackMan.getPackagesForUid(uid);
            final String packageName;
            if (packages != null && packages.length > 0) {
                packageName = packages[0];
            } else {
                packageName = "";
            }
            final AudioRecordingConfiguration updatedConfig =
                    new AudioRecordingConfiguration(uid, session, source,
                            clientFormat, deviceFormat, patchHandle, packageName);

            if (mRecordConfigs.containsKey(sessionKey)) {
                if (updatedConfig.equals(mRecordConfigs.get(sessionKey))) {
                    configChanged = false;
                } else {
                    // config exists but has been modified
                    mRecordConfigs.remove(sessionKey);
                    mRecordConfigs.put(sessionKey, updatedConfig);
                    configChanged = true;
                }
            } else {
                mRecordConfigs.put(sessionKey, updatedConfig);
                configChanged = true;
            }
            if (configChanged) {
                sEventLogger.log(new RecordingEvent(event, uid, session, source, packageName));
            }
            break;
        default:
            Log.e(TAG, String.format("Unknown event %d for session %d, source %d",
                    event, session, source));
            configChanged = false;
        }
        if (configChanged) {
            configs = new ArrayList<AudioRecordingConfiguration>(mRecordConfigs.values());
        } else {
            configs = null;
        }
    }
    return configs;
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法