本文整理汇总了Java中android.media.MediaCodec.createDecoderByType方法的典型用法代码示例。如果您正苦于以下问题:Java MediaCodec.createDecoderByType方法的具体用法?Java MediaCodec.createDecoderByType怎么用?Java MediaCodec.createDecoderByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaCodec
的用法示例。
在下文中一共展示了MediaCodec.createDecoderByType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import android.media.MediaCodec; //导入方法依赖的package包/类
@Override
public Point open(SurfaceTexture surface) {
try {
if(!extractMedia()){
return new Point(0,0);
}
mFrameSem=new Semaphore(0);
mDecodeSem=new Semaphore(1);
videoProvideEndFlag=false;
isUserWantToStop=false;
mAudioEncodeTrack=mStore.addTrack(mExtractor.getTrackFormat(mAudioDecodeTrack));
MediaFormat format=mExtractor.getTrackFormat(mVideoDecodeTrack);
mVideoDecoder = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
mVideoDecoder.configure(format,new Surface(surface),null,0);
mVideoDecoder.start();
startDecodeThread();
} catch (IOException e) {
e.printStackTrace();
}
return mVideoSize;
}
示例2: setup
import android.media.MediaCodec; //导入方法依赖的package包/类
@Override
public void setup() throws IOException {
mExtractor.selectTrack(mTrackIndex);
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
mEncoderStarted = true;
final MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
mDecoder.configure(inputFormat, null, null, 0);
mDecoder.start();
mDecoderStarted = true;
mAudioChannel = new AudioChannel(mDecoder, mEncoder, mOutputFormat);
}
示例3: setup
import android.media.MediaCodec; //导入方法依赖的package包/类
@Override
public void setup() throws IOException {
mExtractor.selectTrack(mTrackIndex);
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoderInputSurfaceWrapper = new InputSurface(mEncoder.createInputSurface());
mEncoder.start();
mEncoderStarted = true;
mEncoderOutputBuffers = mEncoder.getOutputBuffers();
MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
// if (inputFormat.containsKey(MediaUtil.KEY_ROTATION)) {
// // Decoded video is rotated automatically in Android 5.0 lollipop.
// // Turn off here because we don't want to encode rotated one.
// // refer: https://android.googlesource
// // .com/platform/frameworks/av/+blame/lollipop-release/media/libstagefright/Utils.cpp
// inputFormat.setInteger(MediaUtil.KEY_ROTATION, 0);
// }
mDecoderOutputSurfaceWrapper = new OutputSurface(mSurfaceRender);
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
mDecoder.configure(inputFormat, mDecoderOutputSurfaceWrapper.getSurface(), null, 0);
mDecoder.start();
mDecoderStarted = true;
mDecoderInputBuffers = mDecoder.getInputBuffers();
}
示例4: prepare
import android.media.MediaCodec; //导入方法依赖的package包/类
@Override
protected void prepare() throws IOException {
if (mState < STATE_PREPARED) {
MediaFormat format;
if (mState == STATE_UNINITIALIZED) {
mTrackIndex = selectTrack();
if (mTrackIndex < 0) {
setState(STATE_NO_TRACK_FOUND);
return;
}
mExtractor.selectTrack(mTrackIndex);
format = mExtractor.getTrackFormat(mTrackIndex);
mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int audioChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
mAudioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
mSampleRate,
(audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
AudioFormat.ENCODING_PCM_16BIT,
AudioTrack.getMinBufferSize(
mSampleRate,
(audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
AudioFormat.ENCODING_PCM_16BIT
),
AudioTrack.MODE_STREAM
);
mState = STATE_INITIALIZED;
} else {
format = mExtractor.getTrackFormat(mTrackIndex);
}
String mime = format.getString(MediaFormat.KEY_MIME);
Log.d(TAG, mime);
mMediaCodec = MediaCodec.createDecoderByType(mime);
// mMediaCodec.setCallback(mCallback);
mMediaCodec.configure(format, null, null, 0);
setState(STATE_PREPARED);
}
super.prepare();
}
示例5: readyVideoDecoder
import android.media.MediaCodec; //导入方法依赖的package包/类
/**
* デコーダを準備する
*/
private MediaFormat readyVideoDecoder() {
MediaFormat srcVideoFormat = selectTrack(mExtractor);
Log.d(TAG, "startVideoDecoder format:" + srcVideoFormat);
if (srcVideoFormat == null) {
return null;
}
try {
//TODO HW decoderがハングアップしている場合がある
//その場合createDecoderByTypeで止まってしまう
mDecoder = MediaCodec.createDecoderByType(
srcVideoFormat.getString(MediaFormat.KEY_MIME));
//mDecoder.configure( srcVideoFormat, null, null, 0 );
mDecoder.configure(srcVideoFormat, mOutSurface, null, 0);
mDecoder.start();
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "Failed to start mDecoder id:" + id);
if (mDecoder != null) {
mDecoder.release();
}
srcVideoFormat = null;
//TODO 同じファイルに対して規定回数 or 規定秒数エラーを起こした場合、
//あきらめる( filePathをNullにする )
}
return srcVideoFormat;
}
示例6: createDecoder
import android.media.MediaCodec; //导入方法依赖的package包/类
public int createDecoder(int videoWidth, int videoHeight, Surface surface) throws IOException {
Log.d(LOG_TAG, "start create decoder, videoWidth:" + String.valueOf(videoWidth) + "videoHeight:" + String.valueOf(videoHeight));
if (videoWidth <= 0 || videoHeight <= 0) {
Log.d(LOG_TAG, "invalid width or height");
return -1;
}
this.mWidth = videoWidth;
this.mHeight = videoHeight;
this.mSurface = surface;
this.codec = MediaCodec.createDecoderByType("video/avc");
if (this.codec == null) {
Log.d(LOG_TAG, "Hardware codec is not available");
return -1;
}
try {
this.format = MediaFormat.createVideoFormat("video/avc", videoWidth, videoHeight);
Log.d(LOG_TAG, "configure mediacodec");
this.codec.configure(this.format, surface, null, 0);
this.codec.setVideoScalingMode(1);
Log.d(LOG_TAG, "start mediacodec");
this.codec.start();
Log.d(LOG_TAG, "get input and output buffer");
this.codecInputBuffers = this.codec.getInputBuffers();
this.codecOutputBuffers = this.codec.getOutputBuffers();
return 1;
} catch (IllegalStateException e) {
Log.d(LOG_TAG, "Exception catched in createDecoder");
return -1;
}
}
示例7: prepareAudio
import android.media.MediaCodec; //导入方法依赖的package包/类
public boolean prepareAudio() {
try {
audioDecoder = MediaCodec.createDecoderByType(mime);
audioDecoder.configure(audioFormat, null, null, 0);
return true;
} catch (IOException e) {
Log.e(TAG, "Prepare decoder error:", e);
return false;
}
}
示例8: prepareVideo
import android.media.MediaCodec; //导入方法依赖的package包/类
public boolean prepareVideo(Surface surface) {
try {
videoDecoder = MediaCodec.createDecoderByType(mime);
videoDecoder.configure(videoFormat, surface, null, 0);
return true;
} catch (IOException e) {
Log.e(TAG, "Prepare decoder error:", e);
return false;
}
}