#include "stream.hpp"
|
|
#include "../ffmpeg/data/CodedData.hpp"
|
|
namespace cffmpeg_wrap{
|
stream::stream(const int maxSize)
|
:max_size_(maxSize)
|
{}
|
|
stream::~stream(){
|
std::lock_guard<std::mutex> locker(mutex_avpkt_);
|
list_avpkt_.clear();
|
}
|
|
int stream::SetPacket(std::shared_ptr<ffwrapper::CodedData> data){
|
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;
|
}
|
}
|
}
|
return list_avpkt_.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()){
|
return;
|
}
|
auto data = list_avpkt_.front();
|
auto pkt = 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();
|
}
|
}
|