From 1d2e7ce97e33c74a949d443a226df531fbf5c7dd Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 25 九月 2019 14:04:09 +0800
Subject: [PATCH] bug fix
---
csrc/worker/stream.cpp | 54 ++++++++++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/csrc/worker/stream.cpp b/csrc/worker/stream.cpp
index 0f8dadc..9fe11da 100644
--- a/csrc/worker/stream.cpp
+++ b/csrc/worker/stream.cpp
@@ -1,51 +1,57 @@
#include "stream.hpp"
+extern "C"{
+#include <libavcodec/avcodec.h>
+}
+
+#include "../ffmpeg/format/FormatIn.hpp"
#include "../ffmpeg/data/CodedData.hpp"
namespace cffmpeg_wrap{
- stream::stream(const int maxSize)
- :max_size_(maxSize)
+ stream::stream(ffwrapper::FormatIn *in, const int maxSize)
+ :streamRef_(in)
+ ,max_size_(maxSize)
+ ,audio_(false)
{}
stream::~stream(){
std::lock_guard<std::mutex> locker(mutex_avpkt_);
- list_avpkt_.clear();
+ list_pkt_.clear();
}
- int stream::SetPacket(std::shared_ptr<ffwrapper::CodedData> data){
+ int stream::SetPacket(std::shared_ptr<ffwrapper::CodedData> data, int64_t &id){
if (data){
- std::lock_guard<std::mutex> locker(mutex_avpkt_);
- list_avpkt_.push_back(data);
-
- while(list_avpkt_.size() > max_size_){
- list_avpkt_.pop_front();
- while(!list_avpkt_.empty()){
- auto &cache = list_avpkt_.front();
- AVPacket &avpkt = cache->getAVPacket();
- if (!(avpkt.flags & AV_PKT_FLAG_KEY)){
- list_avpkt_.pop_front();
- }else{
- break;
- }
- }
+
+ // 濡傛灉鍖呮槸闊抽鍖�,浣嗘槸涓嶄娇鐢ㄩ煶棰�,鐩存帴杩斿洖
+ if (!audio_ && streamRef_->isAudioPkt(&data->getAVPacket())){
+ return 0;
}
- return list_avpkt_.size();
+
+ std::lock_guard<std::mutex> locker(mutex_avpkt_);
+ list_pkt_.push_back({data, id});
+
+ while(list_pkt_.size() > max_size_/2*3){
+ list_pkt_.pop_front();
+ }
+
+ return list_pkt_.size();
}
return 0;
}
void stream::GetPacket(unsigned char **pktData, int *size, int *key){
std::lock_guard<std::mutex> l(mutex_avpkt_);
- if(list_avpkt_.empty()){
+ if(list_pkt_.empty()){
return;
}
- auto data = list_avpkt_.front();
- auto pkt = data->getAVPacket();
+
+ auto data = list_pkt_.front();
+ list_pkt_.pop_front();
+
+ auto pkt = data.data->getAVPacket();
*key = pkt.flags & AV_PKT_FLAG_KEY;
*size = pkt.size;
*pktData = (unsigned char *)malloc(*size);
memcpy(*pktData, pkt.data, pkt.size);
-
- list_avpkt_.pop_front();
}
}
\ No newline at end of file
--
Gitblit v1.8.0