繁体   English   中英

具有MediaCodec解码器的TextureView,用于H264流

[英]TextureView with MediaCodec decoder for H264 streams

这是该问题的后续问题

这是我的TextureView代码:

public class VideoTextureView extends TextureView implements SurfaceTextureListener{

    private static final String LOG_TAG = VideoTextureView.class.getSimpleName();
    private MediaCodecDecoder mMediaDecoder;
    private MediaCodecAsyncDecoder mMediaAsyncDecoder;

    public VideoTextureView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setSurfaceTextureListener(this);
        Log.d(LOG_TAG, "Video texture created.");
    }

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        Log.d(LOG_TAG, "Surface Available: " + width + " x " + height);
        mMediaDecoder = new MediaCodecDecoder();
        mMediaDecoder.Start();
        mMediaDecoder.SetSurface(new Surface(getSurfaceTexture()));
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        mMediaDecoder.Stop();
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        // TODO Auto-generated method stub

    }

}

我的问题-我的TextureView实现可以通过MediaCodec解码H264流吗? 还是我需要进行EGL设置或其他?

提前致谢!

我目前正在使用TextureView在android上使用集合视图单元在一个活动中呈现多个流(抱歉,那里的ios术语)。

它工作正常,但问题是,例如当您旋转设备时,将出现surface_destroyed,然后是surface_available。 如我所见,您正在正确地停止和启动解码器。

我在解码器中所做的一件事是:

List<NaluSegment> segments = NaluParser.parseNaluSegments(buffer);
        for (NaluSegment segment : segments) {
            // ignore unspecified NAL units.
            if (segment.getType() != NaluType.UNSPECIFIED) {

                // Hold the parameter set for stop/start initialization speed
                if (segment.getType() == NaluType.PPS) {
                    lastParameterSet[0] = segment;
                } else if (segment.getType() == NaluType.SPS) {
                    lastParameterSet[1] = segment;
                } else if (segment.getType() == NaluType.CODED_SLICE_IDR) {
                    lastParameterSet[2] = segment;
                }

                // add to input queue
                naluSegmentQueue.add(segment);
            }
        }

我保留了最后一个参数集和最后一个关键帧,并从一开始就填充了naluSegmentQueue,以减少视频渲染的延迟。

我的TextureView实现也可以,因为我也尝试过SurfaceView并找到了相同的结果。 正如@fadden所说-

仅当使用GLES进行渲染时才需要EGL设置。 TextureView将SurfaceTexture与自定义View结合在一起,并为您执行GLES渲染。 这就是为什么必须对硬件进行硬件加速以使TextureView起作用的原因。

感谢@fadden。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM