The decoding process is divided into two processes:
1. Get the H264 view screen flow, keep abreast of the video streaming into the decoder in the buffer
2. Obtain the buffer of the decoder and obtain the decoded data in the buffer and set it to the Surfaceview for display
Display interface:
Msurfaceview = (Surfaceview) Findviewbyid (R.ID.SV);
Msurfaceholder = Msurfaceview.getholder ();
Msurfaceholder.addcallback (this);
Open the loop thread in the surfacecreated callback that reads the decoded data in 2.
public class Harddecodethread extends thread{@Override public void Run () {try {Mmediacodec = Mediacodec.crea
Tedecoderbytype ("VIDEO/AVC");
Mediaformat format = Mediaformat.createvideoformat ("VIDEO/AVC", 1280, 720);
Mmediacodec.configure (format, msurfaceholder.getsurface (), null, 0);
Mmediacodec.start ()//Pay attention to open the code, or the following will be an error Showlog ("Start get output Veido info");
while (isplay) {bufferinfo bufinfo = new Bufferinfo ();
int outputindex = 0; while ((Outputindex = Mmediacodec.dequeueoutputbuffer (bufinfo,20 * 1000)) >= 0) {mmediacodec.releaseoutputbuffer (o
Utputindex, True);
} if (Outputindex = = mediacodec.info_output_buffers_changed) {showlog ("info_output_buffers_changed");
}else if (Outputindex = = mediacodec.info_output_format_changed) {showlog ("info_output_format_changed");
} if (Mmediacodec!= null) {mmediacodec.stop ();
Mmediacodec.release ();
Mmediacodec = null; catch (Exceptione) {e.printstacktrace ();
Showlog ("Not supported hard coded _error:" + e.getmessage ()); }
}}
Perform 1 parts: continuously obtain H264 code stream for decoding
if (Mmediacodec!= null) {
bytebuffer[] buffers = Mmediacodec.getinputbuffers ();
int inputbufferindex = mmediacodec.dequeueinputbuffer (* 1000);
Showlog ("Inputbufferindex:" + inputbufferindex);
if (inputbufferindex >= 0) {
bytebuffer buffer = Buffers[inputbufferindex];
Buffer.clear ();
Buffer.put (data);
Mmediacodec.queueinputbuffer (inputbufferindex, 0, data.length, 0, 0);//data byte array representing H264
}
}