实现录屏功能,需要将Android设备通过Socket发送到客户端的AVPacket数据保存成文件。
在前面的文章中讲过界面如何通过OpenGL绘制AVPacket.
简单回顾下:Demuxer线程不断的读取视频socket链路上的数据,以AVPacket对象的形式交给解码器,解码器遍历PacketSink列表,PacketSink按照各自的实现使用AVPacket数据。我们继承PacketSink类,分别实现
RecoderVideoSink和RecoderAudioSink
class RecoderVideoSink:public PacketSink{
public:
RecoderVideoSink(RecorderThread *handler);
~RecoderVideoSink();
virtual bool open(AVCodecContext *ctx);
virtual void close();
virtual bool push(AVPacket *packet);
//virtual void disable();
private:
RecorderThread *recorder;
};
class RecoderAudioSink:public PacketSink{
public:
RecoderAudioSink(RecorderThread *handler);
~RecoderAudioSink();
virtual bool open(AVCodecContext *ctx);
virtual void close();
virtual bool push(AVPacket *packet);
//virtual void disable();
private:
RecorderThread *recorder;
};
将实现的这两个Sink,加入到Decoder的Sink列表,这样在解码过程中AV