int CFFMPEGLoader::LoadFrame() { AVPacket packet; int ret=-1; while(av_read_frame(pFormatCon, &packet)>=0) { ret=1; // Is this a packet from the video stream? if(bVideoIsNeeded&&packet.stream_index==videoStream&&iPKTVideoLength<iBufferSize) { // Decode video frame av_dup_packet(&packet); pktLastVideo[iPKTVideoLength++]=packet; //.... } else if(bAudioIsNeeded&&packet.stream_index==audioStream&&iPKTAudioLength<iBufferSize) { av_dup_packet(&packet); pktLastAudio[iPKTAudioLength++]=packet; } else { av_free_packet(&packet); } if(iPKTVideoLength>=iBufferSize||iPKTAudioLength>=iBufferSize) break; } return ret; }
AVPacket * FFMpegDemuxer::getPacket(int streamIndex) { // Make sure enableStream was called on streamIndex. AVG_ASSERT(m_PacketLists.size() > 0); AVG_ASSERT(streamIndex > -1 && streamIndex < 10); if (m_PacketLists.find(streamIndex) == m_PacketLists.end()) { cerr << this << ": getPacket: Stream " << streamIndex << " not found." << endl; dump(); AVG_ASSERT(false); } PacketList& curPacketList = m_PacketLists.find(streamIndex)->second; AVPacket* pPacket; if (!curPacketList.empty()) { // The stream has packets queued already. pPacket = curPacketList.front(); curPacketList.pop_front(); } else { // No packets queued for this stream -> read and queue packets until we get one // that is meant for this stream. do { pPacket = new AVPacket; memset(pPacket, 0, sizeof(AVPacket)); int err = av_read_frame(m_pFormatContext, pPacket); if (err < 0) { // EOF or error if (err != int(AVERROR_EOF)) { char sz[256]; av_strerror(err, sz, 256); AVG_TRACE(Logger::category::PLAYER, Logger::severity::ERROR, "Error decoding video: " << sz); } av_free_packet(pPacket); delete pPacket; pPacket = 0; return 0; } if (pPacket->stream_index != streamIndex) { if (m_PacketLists.find(pPacket->stream_index) != m_PacketLists.end()) { // Relevant stream, but not ours av_dup_packet(pPacket); PacketList& otherPacketList = m_PacketLists.find(pPacket->stream_index)->second; otherPacketList.push_back(pPacket); } else { // Disabled stream av_free_packet(pPacket); delete pPacket; pPacket = 0; } } else { // Our stream av_dup_packet(pPacket); } } while (!pPacket || pPacket->stream_index != streamIndex); } return pPacket; }
DTerr HWVideoPlayerFFPacketQueue::push_back (AVPacket *pkt) { // Duplicate if not a flush packet if (!is_flush(pkt) && !is_play(pkt) && !is_pause(pkt)) { if(av_dup_packet(pkt) < 0) return DT3_ERR_FILE_OPEN_FAILED; } AVPacketList *packet_list = (AVPacketList *) ::av_malloc(sizeof(AVPacketList)); packet_list->pkt = *pkt; packet_list->next = NULL; _lock.lock(); // Queue is empty if (!_first_pkt) { _first_pkt = _last_pkt = packet_list; } else { _last_pkt->next = packet_list; _last_pkt = packet_list; } ++_size; _lock.unlock(); return 0; }
int packet_queue_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; if(av_dup_packet(pkt) < 0) { return -1; } pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if(!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&q->mutex); if(!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; pthread_cond_signal(&q->cond); pthread_mutex_unlock(&q->mutex); return 0; }
int packet_queue_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; if(av_dup_packet(pkt) < 0) { return -1; } pkt1 = av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; SDL_LockMutex(q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; SDL_CondSignal(q->cond); SDL_UnlockMutex(q->mutex); return 0; }
int packet_queue_put (PacketQueue *q, AVPacket *pkt) { AVPacketList *node; if (q->stop_request) return -1; if (av_dup_packet (pkt) < 0) return -1; SDL_LockMutex(q->mutex); node = av_malloc (sizeof *node); if (!node) return -1; node->pkt = *pkt; node->next = NULL; if (!q->last_pkt) q->first_pkt = node; else q->last_pkt->next = node; q->last_pkt = node; q->nb_packets++; q->size += node->pkt.size; SDL_CondSignal (q->cond); SDL_UnlockMutex (q->mutex); return 0; }
static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; /* duplicate the packet */ if (pkt != &flush_pkt && av_dup_packet(pkt) < 0) { return -1; } pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) { return -1; } pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&q->mutex); if (!q->last_pkt) { q->first_pkt = pkt1; } else { q->last_pkt->next = pkt1; } q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size + sizeof(*pkt1); pthread_cond_signal(&q->cond); pthread_mutex_unlock(&q->mutex); return 0; }
Omm::AvStream::Frame* FFmpegMeta::readFrame() { AVPacket packet; LOG(ffmpeg, trace, "ffmpeg::av_read_frame() ..."); int ret = av_read_frame(_pFormatContext, &packet); _frameNumber++; if (ret < 0) { LOG(ffmpeg, error, "ffmpeg::av_read_frame() returns: " + Poco::NumberFormatter::format(ret) + " (" + errorMessage(ret) + ")"); return new Omm::AvStream::Frame(_frameNumber, streamInfo(0), true); } FFmpegFrame* pFrame = new FFmpegFrame(_frameNumber, streamInfo(packet.stream_index)); LOG(ffmpeg, trace, "av_dup_packet()"); if (av_dup_packet(&packet) < 0) { LOG(ffmpeg, warning, "av_dup_packet() failed"); } // allocate AVPacket struc LOG(ffmpeg, trace, "av_malloc()"); pFrame->_pAvPacket = (AVPacket*)av_malloc(sizeof(AVPacket)); // copy fields of AVPacket struc *(pFrame->_pAvPacket) = packet; pFrame->_data = (char*)packet.data; pFrame->_size = packet.size; pFrame->setPts(packet.pts); return pFrame; }
int packet_queue_put(PacketQueue *q, AVPacket *pkt, int video) { AVPacketList* pkt1; if (pkt != &flush_pkt && av_dup_packet(pkt) < 0) { return -1; } pkt1 = (AVPacketList*) av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; SDL_LockMutex(q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; printf("%s packet_queue_put return q->nb_packets:%d q->size%d\n", video ? "video" : "audio", q->nb_packets, q->size); fflush(stdout); SDL_CondSignal(q->cond); SDL_UnlockMutex(q->mutex); return 0; }
static int packet_queue_put(PacketQueue * q, AVPacket * pkt) { AVPacketList *pkt1; if (pkt != &flush_pkt && av_dup_packet(pkt) < 0) { return -1; } pkt1 = av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; al_lock_mutex(q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; al_signal_cond(q->cond); al_unlock_mutex(q->mutex); return 0; }
int PacketQueue::put(AVPacket* pkt) { AVPacketList *pkt1; /* duplicate the packet */ if (av_dup_packet(pkt) < 0) return -1; pkt1 = (AVPacketList *) av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&mLock); if (!mLast) { mFirst = pkt1; } else { mLast->next = pkt1; } mLast = pkt1; mNbPackets++; mSize += pkt1->pkt.size + sizeof(*pkt1); pthread_cond_signal(&mCondition); pthread_mutex_unlock(&mLock); return 0; }
void THAVPacketQueue::push(AVPacket *pPacket) { AVPacketList* pNode; if(av_dup_packet(pPacket) < 0) { throw -1; } pNode = (AVPacketList*)av_malloc(sizeof(AVPacketList)); pNode->pkt = *pPacket; pNode->next = nullptr; SDL_LockMutex(m_pMutex); if(m_pLastPacket == nullptr) { m_pFirstPacket = pNode; } else { m_pLastPacket->next = pNode; } m_pLastPacket = pNode; iCount++; SDL_CondSignal(m_pCond); SDL_UnlockMutex(m_pMutex); }
int queue_push(PacketQueue _q, AVPacket *pkt) { _PacketQueue *q = _q; AVPacketList *pkt1; if (strcmp((const char *)pkt->data, "FLUSH") != 0 && av_dup_packet(pkt) < 0) return -1; pkt1 = malloc(sizeof(AVPacketList)); pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&q->mutex); if (q->last == NULL) q->first = pkt1; else q->last->next = pkt1; q->npkts++; q->last = pkt1; pthread_mutex_unlock(&q->mutex); return 0; }
void THAVPacketQueue::push(AVPacket *pPacket) { #if (defined(CORSIX_TH_USE_LIBAV) && LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 12, 100)) || \ (defined(CORSIX_TH_USE_FFMPEG) && LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 8, 0)) if(av_dup_packet(pPacket) < 0) { throw -1; } #endif AVPacketList* pNode = (AVPacketList*)av_malloc(sizeof(AVPacketList)); pNode->pkt = *pPacket; pNode->next = nullptr; SDL_LockMutex(m_pMutex); if(m_pLastPacket == nullptr) { m_pFirstPacket = pNode; } else { m_pLastPacket->next = pNode; } m_pLastPacket = pNode; iCount++; SDL_CondSignal(m_pCond); SDL_UnlockMutex(m_pMutex); }
int packet_queue_put(struct ff_packet_queue *q, struct ff_packet *packet) { struct ff_packet_list *new_packet; if (packet != &q->flush_packet && av_dup_packet(&packet->base) < 0) return FF_PACKET_FAIL; new_packet = av_malloc(sizeof(struct ff_packet_list)); if (new_packet == NULL) return FF_PACKET_FAIL; new_packet->packet = *packet; new_packet->next = NULL; pthread_mutex_lock(&q->mutex); if (q->last_packet == NULL) q->first_packet = new_packet; else q->last_packet->next = new_packet; q->last_packet = new_packet; q->count++; q->total_size += new_packet->packet.base.size; pthread_cond_signal(&q->cond); pthread_mutex_unlock(&q->mutex); return FF_PACKET_SUCCESS; }
static int packet_queue_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; /* duplicate the packet */ if (av_dup_packet(pkt) < 0) return -1; pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; if (q->nb_packets > 5000) fprintf(stderr, "%ld storing %p, %s\n", q->nb_packets, q, q == &videoqueue ? "videoqueue" : "audioqueue"); q->size += pkt1->pkt.size + sizeof(*pkt1); pthread_cond_signal(&q->cond); pthread_mutex_unlock(&q->mutex); return 0; }
int packet_queue_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; // if(pkt != &flush_pkt && av_dup_packet(pkt) < 0) { // return -1; // } if(av_dup_packet(pkt) < 0) { return -1; } pkt1 = av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; pthread_mutex_unlock(&q->mutex); return 0; }
/*将一个packet放到队列*/ int ff_queue_packet_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; if (av_dup_packet(pkt) < 0) { return -1; } pkt1 = av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; #ifndef SDL_MUTEX pthread_mutex_lock(&q->mutex); #else SDL_LockMutex(q->mutex); #endif if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; #ifndef SDL_MUTEX pthread_mutex_unlock(&q->mutex); #else SDL_CondSignal(q->cond); SDL_UnlockMutex(q->mutex); #endif return 0; }
void av_packet_queue::push(AVPacket *pPacket) { #if (defined(CORSIX_TH_USE_LIBAV) && LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 8, 0)) || \ (defined(CORSIX_TH_USE_FFMPEG) && LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 12, 100)) if(av_dup_packet(pPacket) < 0) { throw -1; } #endif AVPacketList* pNode = (AVPacketList*)av_malloc(sizeof(AVPacketList)); pNode->pkt = *pPacket; pNode->next = nullptr; std::lock_guard<std::mutex> lock(mutex); if(last_packet == nullptr) { first_packet = pNode; } else { last_packet->next = pNode; } last_packet = pNode; count++; cond.notify_one(); }
void FFmpegDecodeQueue::rawPush(CustomAVPacket& packet) { //CustomAVPacket p; av_dup_packet(&packet); //av_copy_packet(&p, &packet); packets_.push_back(packet); size_ += packet.size; }
/*============================================================================== * - packet_queue_put() * * - put a packet to queue. wait 3 seconds, if can't we discard it */ int packet_queue_put(PacketQueue *q, AVPacket *pkt) { if(pkt != &_G_flush_pkt && av_dup_packet(pkt) < 0) { return -1; } msgQ_send(q->msgQ, (char *)pkt, sizeof(AVPacket), 3 * SYS_CLK_RATE); return 0; }
AVPacket *CFFMPEGLoader::GetNextPacket() { AVPacket packet; if(av_read_frame(pFormatCon, &packet)<0) return NULL; if(packet.stream_index!=videoStream&&packet.stream_index!=audioStream) { av_free_packet(&packet); return NULL; } av_dup_packet(&packet); return &packet; }
void cSoftPlayer::RemuxAndQueue(AVPacket &pkt) { // set audio index if not yet set if ( AudioIdx== -1 && #if LIBAVFORMAT_BUILD > 4628 ic->streams[pkt.stream_index]->codec->codec_type == CODEC_TYPE_AUDIO #else ic->streams[pkt.stream_index]->codec.codec_type == CODEC_TYPE_AUDIO #endif ) AudioIdx=pkt.stream_index; // set video index if not yet set if ( VideoIdx== -1 && #if LIBAVFORMAT_BUILD > 4628 ic->streams[pkt.stream_index]->codec->codec_type == CODEC_TYPE_VIDEO #else ic->streams[pkt.stream_index]->codec.codec_type == CODEC_TYPE_VIDEO #endif ) VideoIdx=pkt.stream_index; // skip packets which do not belong to the current streams if ( pkt.stream_index != VideoIdx && pkt.stream_index != AudioIdx ) { printf("Drop Packet PTS: %lld\n",pkt.pts); return; }; #if LIBAVFORMAT_BUILD > 4623 AVRational time_base; time_base=ic->streams[pkt.stream_index]->time_base; if ( pkt.pts != (int64_t) AV_NOPTS_VALUE ) { pkt.pts=av_rescale(pkt.pts, AV_TIME_BASE* (int64_t)time_base.num, time_base.den)/100 ; }; //printf("PTS: %lld new %lld num %d den %d\n",PTS,pkt.pts, // time_base.num,time_base.den); #else if ( pkt.pts != (int64_t) AV_NOPTS_VALUE ) pkt.pts/=100; #endif //pkt.pts*=1000/AV_TIME_BASE; av_dup_packet(&pkt); // length = -2 : queue packet PKTDBG("Queue Packet index: %d PTS: %lld\n",pkt.stream_index,pkt.pts); #if VDRVERSNUM >= 10330 SoftHandles.QueuePacket(SoftDevice,ic,pkt); #else SoftDevice->PlayVideo((uchar *)&pkt,-2); #endif };
AVPacket * FFMpegDemuxer::getPacket(int StreamIndex) { // Make sure enableStream was called on StreamIndex. assert (m_PacketLists.find(StreamIndex) != m_PacketLists.end()); PacketList & CurPacketList = m_PacketLists.find(StreamIndex)->second; AVPacket * pPacket; if (!CurPacketList.empty()) { pPacket = CurPacketList.front(); CurPacketList.pop_front(); } else { do { pPacket = new AVPacket; memset(pPacket, 0, sizeof(AVPacket)); int err = av_read_frame(m_pFormatContext, pPacket); // TODO: Check url_ferror here too. if (err < 0) { av_free_packet(pPacket); delete pPacket; pPacket = 0; return 0; } if (pPacket->stream_index != StreamIndex) { if (m_PacketLists.find(pPacket->stream_index) != m_PacketLists.end()) { av_dup_packet(pPacket); PacketList& OtherPacketList = m_PacketLists.find(pPacket->stream_index)->second; OtherPacketList.push_back(pPacket); } else { av_free_packet(pPacket); delete pPacket; pPacket = 0; } } else { av_dup_packet(pPacket); } } while (!pPacket || pPacket->stream_index != StreamIndex); } return pPacket; }
AVPacket * Demux::getPacket(const int theStreamIndex) { DB(AC_TRACE << "Demux::getPacket for stream: " << theStreamIndex); if (_myPacketLists.find(theStreamIndex) == _myPacketLists.end()) { AC_ERROR << "Demux::getPacket called with nonexistent stream index " << theStreamIndex << "."; } PacketList & myCurPacketList = _myPacketLists.find(theStreamIndex)->second; if (!myCurPacketList.empty()) { DB(AC_TRACE << "Demux::getPacket: packet already there."); AVPacket * myPacket = myCurPacketList.front(); myCurPacketList.pop_front(); return myPacket; } else { DB(AC_TRACE << "Demux::getPacket: packet needs to be read."); AVPacket * myPacket; do { DB(AC_TRACE << "Demux::getPacket: read."); myPacket = new AVPacket; memset(myPacket, 0, sizeof(AVPacket)); bool myEndOfFileFlag = (av_read_frame(_myFormatContext, myPacket) < 0); if (myEndOfFileFlag) { AC_DEBUG << "Demux::getPacket: end of file."; av_free_packet(myPacket); delete myPacket; myPacket = 0; return 0; } if (myPacket->stream_index != theStreamIndex) { if (_myPacketLists.find(myPacket->stream_index) != _myPacketLists.end()) { DB(AC_TRACE << "Demux::getPacket: caching packet."); // Without av_dup_packet, ffmpeg reuses myPacket->data at first // opportunity and trashes our memory. av_dup_packet(myPacket); PacketList& myOtherPacketList = _myPacketLists.find(myPacket->stream_index)->second; myOtherPacketList.push_back(myPacket); } else { DB(AC_DEBUG << "Demux::getPacket: rejecting packet."); av_free_packet(myPacket); delete myPacket; myPacket = 0; } } } while (!myPacket || myPacket->stream_index != theStreamIndex); DB(AC_TRACE << "Demux::getPacket: end."); return myPacket; } }
int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)) { int ret; AVPacketList **next_point, *this_pktl; this_pktl = av_mallocz(sizeof(AVPacketList)); if (!this_pktl) return AVERROR(ENOMEM); this_pktl->pkt = *pkt; #if FF_API_DESTRUCT_PACKET FF_DISABLE_DEPRECATION_WARNINGS pkt->destruct = NULL; // do not free original but only the copy FF_ENABLE_DEPRECATION_WARNINGS #endif pkt->buf = NULL; // Duplicate the packet if it uses non-allocated memory if ((ret = av_dup_packet(&this_pktl->pkt)) < 0) { av_free(this_pktl); return ret; } if (s->streams[pkt->stream_index]->last_in_packet_buffer) { next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next); } else next_point = &s->internal->packet_buffer; if (*next_point) { if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) { while (!compare(s, &(*next_point)->pkt, pkt)) next_point = &(*next_point)->next; goto next_non_null; } else { next_point = &(s->internal->packet_buffer_end->next); } } assert(!*next_point); s->internal->packet_buffer_end = this_pktl; next_non_null: this_pktl->next = *next_point; s->streams[pkt->stream_index]->last_in_packet_buffer = *next_point = this_pktl; return 0; }
void packetQueue::put(AVPacket* packet) { AVPacketList* pktList; av_dup_packet(packet); pktList = (AVPacketList*)av_malloc(sizeof(AVPacketList)); pktList->pkt = *packet; pktList->next = NULL; pthread_mutex_lock(mut); if(last_packet == NULL) first_packet = pktList; else last_packet->next = pktList; last_packet = pktList; num_packets++; size += pktList->pkt.size; pthread_mutex_unlock(mut); }
int packet_queue_put(PacketQueue *q, AVPacket *pkt) { //ffplay_info("Start.\n"); AVPacketList *pkt1; if(av_dup_packet(pkt) < 0) { ffplay_info("av_dup_packet(pkt) < 0\n"); return -1; } pkt1 = av_malloc(sizeof(AVPacketList)); if (!pkt1) { ffplay_info("pkt1 = 0x%8x\n",pkt1); return -1; } pkt1->pkt = *pkt; pkt1->next = NULL; SDL_LockMutex(q->mutex); ffplay_info("pkt = 0x%8x, q->first_pkt = 0x%8x, q->last_pkt =0x%8x, pkt1 = 0x%8x\n",pkt,q->first_pkt,q->last_pkt,pkt1); if (!q->last_pkt) { q->first_pkt = pkt1; } else { q->last_pkt->next = pkt1; } q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; SDL_CondSignal(q->cond); ffplay_info("pkt = 0x%8x, q->first_pkt = 0x%8x, q->last_pkt =0x%8x, pkt1 = 0x%8x\n",pkt,q->first_pkt,q->last_pkt,pkt1); SDL_UnlockMutex(q->mutex); //ffplay_info("end.\n"); return 0; }
int av_packet_split_side_data(AVPacket *pkt) { if (!pkt->side_data_elems && pkt->size >12 && AV_RB64(pkt->data + pkt->size - 8) == FF_MERGE_MARKER) { int i; unsigned int size; uint8_t *p= pkt->data + pkt->size - 8 - 5; av_dup_packet(pkt); for (i=1; ; i++) { size = AV_RB32(p); if (size>INT_MAX || p - pkt->data <= size) return 0; if (p[4]&128) break; p-= size+5; } pkt->side_data = av_malloc(i * sizeof(*pkt->side_data)); if (!pkt->side_data) return AVERROR(ENOMEM); p= pkt->data + pkt->size - 8 - 5; for (i=0; ; i++) { size= AV_RB32(p); av_assert0(size<=INT_MAX && p - pkt->data > size); pkt->side_data[i].data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); pkt->side_data[i].size = size; pkt->side_data[i].type = p[4]&127; if (!pkt->side_data[i].data) return AVERROR(ENOMEM); memcpy(pkt->side_data[i].data, p-size, size); pkt->size -= size + 5; if(p[4]&128) break; p-= size+5; } pkt->size -= 8; pkt->side_data_elems = i+1; return 1; } return 0; }
static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; // Drop Packet if queue size is > 1GB if (avpacket_queue_size(q) > 1024 * 1024 * 1024 ) { av_log(q->avctx, AV_LOG_WARNING, "Decklink input buffer overrun!\n"); return -1; } /* duplicate the packet */ if (av_dup_packet(pkt) < 0) { return -1; } pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) { return -1; } pkt1->pkt = *pkt; pkt1->next = NULL; pthread_mutex_lock(&q->mutex); if (!q->last_pkt) { q->first_pkt = pkt1; } else { q->last_pkt->next = pkt1; } q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size + sizeof(*pkt1); pthread_cond_signal(&q->cond); pthread_mutex_unlock(&q->mutex); return 0; }