From 18a05d269516a5e33d8460291c2f93e73d95adce Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 26 十二月 2023 10:45:31 +0800
Subject: [PATCH] GetYUV format is NV12

---
 csrc/ffmpeg/format/FormatIn.hpp |   68 ++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/csrc/ffmpeg/format/FormatIn.hpp b/csrc/ffmpeg/format/FormatIn.hpp
index 2bdafd1..c558aa6 100644
--- a/csrc/ffmpeg/format/FormatIn.hpp
+++ b/csrc/ffmpeg/format/FormatIn.hpp
@@ -3,9 +3,8 @@
 
 #include <stdint.h>
 #include <memory>
-#ifdef GB28181
+#include <deque>
 #include "PsToEs.hpp"
-#endif
 
 struct AVFormatContext;
 struct AVDictionary;
@@ -15,6 +14,7 @@
 struct AVFrame;
 struct AVCodec;
 struct AVIOContext;
+struct AVCodecParserContext;
 
 typedef int(* read_packet)(void *opaque,uint8_t *buf, int buf_size);
 
@@ -27,52 +27,64 @@
 	public:
 		explicit FormatIn(bool hw=true);
 		explicit FormatIn(const VideoProp &prop, bool hw=true);
-		~FormatIn();
+		virtual ~FormatIn();
 		
 	public:
-		int openWithCustomIO(void *opaque, read_packet fn, AVDictionary **options=NULL);
-#ifdef GB28181
-        int openGb28181(const char *filename, AVDictionary **options);
-#endif
 
-		int open(const char *filename, AVDictionary **options);
-		bool findStreamInfo(AVDictionary **options);
-
-		bool openCodec(AVDictionary **options);
-		
-		int readPacket(AVPacket *pkt_out);
-
-		int decode(AVFrame* frame, AVPacket *pkt);
-		
-		bool isVideoPkt(AVPacket *pkt);
-		bool isAudioPkt(AVPacket *pkt);
+		virtual int open(const char *filename, AVDictionary **options);
+		virtual const bool IsHEVC()const;
+		virtual const bool IsAVC1()const;
+		virtual int readPacket(AVPacket *pkt_out);
+		virtual bool isVideoPkt(AVPacket *pkt);
+		virtual bool isAudioPkt(AVPacket *pkt);
 		bool notVideoAudio(AVPacket *pkt);
-	private:
+
+		int openWithCustomIO(void *opaque, read_packet fn, AVDictionary **options=NULL);
+		bool openCodec(AVDictionary **options);
+		int decode(AVFrame* frame, AVPacket *pkt);
+
+	protected:
 		bool allocCodec(AVCodec *dec, AVStream *s, AVDictionary **options);
 	public:
 		AVStream *getStream(int type = -1);
 		AVCodecContext *getCodecContext(int type = 0);
 		AVFormatContext *getFromatContext(){return ctx_;}
 		const double getFPS()const{return fps_;}
-		const bool IsHEVC()const;
-		const bool IsAVC1()const;
-	private:
+	protected:
 	 	AVFormatContext 	*ctx_;
 	 	AVCodecContext 		*dec_ctx_;
 	 	int 				vs_idx_;
 		int 				as_idx_;
 
-
 		VideoProp 			*prop_;
-	 	bool 				hw_accl_;
-		double 				fps_;
+		int 				fps_;
 	private:
 		AVIOContext			*io_ctx_;
 		uint8_t 			*read_io_buff_;
 		const int 			read_io_buff_size_;
-#ifdef GB28181
-		GB28181API			*handle_gb28181;
-#endif
+	};
+
+	class FormatInGB : public FormatIn{
+	public:
+		FormatInGB();
+		explicit FormatInGB(const VideoProp &prop);
+		~FormatInGB();
+
+		virtual int open(const char *filename, AVDictionary **options) override;
+		virtual const bool IsHEVC()const override;
+		virtual const bool IsAVC1()const override;
+		virtual int readPacket(AVPacket *pkt_out) override;
+
+		virtual bool isVideoPkt(AVPacket *pkt) override;
+		virtual bool isAudioPkt(AVPacket *pkt) override;
+
+	private:
+		GB28181API* 			gb28181_;
+		AVCodecParserContext* 	parser_ctx_;
+		unsigned char*  		buffer_;
+		int 					buffer_size_;
+
+		std::deque<AVPacket*>   q_pkt_;
 	};
 }
 

--
Gitblit v1.8.0