use of android.media.MediaFormat in project libstreaming by fyhertz.
the class EncoderDebugger method configureEncoder.
/**
* Instantiates and starts the encoder.
* @throws IOException The encoder cannot be configured
*/
private void configureEncoder() throws IOException {
mEncoder = MediaCodec.createByCodecName(mEncoderName);
MediaFormat mediaFormat = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, BITRATE);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, FRAMERATE);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, mEncoderColorFormat);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
mEncoder.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
}
use of android.media.MediaFormat in project speechutils by Kaljurand.
the class MediaFormatFactory method createMediaFormat.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static MediaFormat createMediaFormat(String mime, int sampleRate) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
MediaFormat format = new MediaFormat();
// TODO: this causes a crash in MediaCodec.configure
// format.setString(MediaFormat.KEY_FRAME_RATE, null);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
format.setString(MediaFormat.KEY_MIME, mime);
if ("audio/mp4a-latm".equals(mime)) {
// TODO: or 39?
format.setInteger(MediaFormat.KEY_AAC_PROFILE, 2);
format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
} else if ("audio/flac".equals(mime)) {
// format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_FLAC); // API=21
format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
// TODO: use another bit rate, does not seem to have effect always
// format.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
// TODO: experiment with 0 (fastest/least) to 8 (slowest/most)
// format.setInteger(MediaFormat.KEY_FLAC_COMPRESSION_LEVEL, 0);
} else if ("audio/opus".equals(mime)) {
// format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_OPUS); // API=21
format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
} else {
// TODO: assuming: "audio/amr-wb"
format.setInteger(MediaFormat.KEY_BIT_RATE, 23050);
}
return format;
}
return null;
}
use of android.media.MediaFormat in project speechutils by Kaljurand.
the class EncodedAudioRecorder method recorderLoop.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@RequiresPermission(RECORD_AUDIO)
@Override
protected void recorderLoop(AudioRecord speechRecord) {
mNumBytesSubmitted = 0;
mNumBytesDequeued = 0;
MediaFormat format = MediaFormatFactory.createMediaFormat(MIME, getSampleRate());
MediaCodec codec = getCodec(format);
if (codec == null) {
handleError("no codec found");
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Log.i("Using codec: " + codec.getCanonicalName());
}
int status = recorderEncoderLoop(codec, speechRecord);
if (Log.DEBUG) {
AudioUtils.showMetrics(format, mNumBytesSubmitted, mNumBytesDequeued);
}
if (status < 0) {
handleError("encoder error");
}
}
}
use of android.media.MediaFormat in project robolectric by robolectric.
the class MediaCodecInfoBuilderTest method createMediaFormat.
/**
* Create a sample {@link MediaFormat}.
*
* @param mime one of MIMETYPE_* from {@link MediaFormat}.
* @param features an array of CodecCapabilities.FEATURE_ features to be enabled.
*/
private static MediaFormat createMediaFormat(String mime, String[] features) {
MediaFormat mediaFormat = new MediaFormat();
mediaFormat.setString(MediaFormat.KEY_MIME, mime);
for (String feature : features) {
mediaFormat.setFeatureEnabled(feature, true);
}
return mediaFormat;
}
use of android.media.MediaFormat in project robolectric by robolectric.
the class ShadowMediaCodecTest method getBasicAacFormat.
private static MediaFormat getBasicAacFormat() {
MediaFormat format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_AAC);
format.setInteger(MediaFormat.KEY_BIT_RATE, 96000);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 16000);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, CodecProfileLevel.AACObjectLC);
return format;
}
Aggregations