Search in sources :

Example 1 with SurfaceView

use of net.majorkernelpanic.streaming.gl.SurfaceView in project libstreaming by fyhertz.

the class VideoStream method encodeWithMediaCodecMethod2.

/**
	 * Video encoding is done by a MediaCodec.
	 * But here we will use the buffer-to-surface method
	 */
@SuppressLint({ "InlinedApi", "NewApi" })
protected void encodeWithMediaCodecMethod2() throws RuntimeException, IOException {
    Log.d(TAG, "Video encoded using the MediaCodec API with a surface");
    // Updates the parameters of the camera if needed
    createCamera();
    updateCamera();
    // Estimates the frame rate of the camera
    measureFramerate();
    EncoderDebugger debugger = EncoderDebugger.debug(mSettings, mQuality.resX, mQuality.resY);
    mMediaCodec = MediaCodec.createByCodecName(debugger.getEncoderName());
    MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/avc", mQuality.resX, mQuality.resY);
    mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, mQuality.bitrate);
    mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, mQuality.framerate);
    mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
    mMediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    Surface surface = mMediaCodec.createInputSurface();
    ((SurfaceView) mSurfaceView).addMediaCodecSurface(surface);
    mMediaCodec.start();
    // The packetizer encapsulates the bit stream in an RTP stream and send it over the network
    mPacketizer.setInputStream(new MediaCodecInputStream(mMediaCodec));
    mPacketizer.start();
    mStreaming = true;
}
Also used : MediaFormat(android.media.MediaFormat) EncoderDebugger(net.majorkernelpanic.streaming.hw.EncoderDebugger) MediaCodecInputStream(net.majorkernelpanic.streaming.rtp.MediaCodecInputStream) SurfaceView(net.majorkernelpanic.streaming.gl.SurfaceView) Surface(android.view.Surface) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 MediaFormat (android.media.MediaFormat)1 Surface (android.view.Surface)1 SurfaceView (net.majorkernelpanic.streaming.gl.SurfaceView)1 EncoderDebugger (net.majorkernelpanic.streaming.hw.EncoderDebugger)1 MediaCodecInputStream (net.majorkernelpanic.streaming.rtp.MediaCodecInputStream)1