svvitch
digital signage player
D:/vs_workspace/switch_sf/src/svvitch/FFBaseDecoder.cpp
Go to the documentation of this file.
00001 #ifdef USE_FFMPEG
00002 
00003 #include "FFBaseDecoder.h"
00004 #include <Poco/format.h>
00005 
00006 FFBaseDecoder::FFBaseDecoder(Renderer& renderer, AVFormatContext* ic, const int streamNo):
00007     _log(Poco::Logger::get("")), _renderer(renderer), _ic(ic), _streamNo(streamNo), _readTime(0), _readCount(0), _avgTime(0) {
00008 }
00009 
00010 FFBaseDecoder::‾FFBaseDecoder() {
00011     clearAllPackets();
00012 }
00013 
00014 void FFBaseDecoder::clearAllPackets() {
00015     //_log.information("clear packets");
00016     Poco::ScopedLock<Poco::FastMutex> lock(_lock);
00017     int count = 0;
00018     while (_packets.size() > 0) {
00019         AVPacketList* packetList = _packets.front();
00020         _packets.pop();
00021         av_free_packet(&packetList->pkt);
00022         av_freep(&packetList);
00023     }
00024     //_log.information(Poco::format("clear packets: %d", count));
00025 }
00026 
00027 const UINT FFBaseDecoder::bufferedPackets() {
00028     Poco::ScopedLock<Poco::FastMutex> lock(_lock);
00029     return _packets.size();
00030 }
00031 
00032 void FFBaseDecoder::pushPacket(AVPacket* packet) {
00033     if (av_dup_packet(packet) < 0) {
00034         _log.warning("failed av_dup_packet()");
00035     } else {
00036         AVPacketList* packetList = (AVPacketList*)av_malloc(sizeof(AVPacketList));
00037         if (!packetList) return;
00038         packetList->pkt = *packet;
00039         packetList->next = NULL;
00040         {
00041             Poco::ScopedLock<Poco::FastMutex> lock(_lock);
00042             _packets.push(packetList);
00043         }
00044     }
00045 }
00046 
00047 AVPacketList* FFBaseDecoder::popPacket() {
00048     Poco::ScopedLock<Poco::FastMutex> lock(_lock);
00049     AVPacketList* packetList = NULL;
00050     if (_packets.size() > 0) {
00051         packetList = _packets.front();
00052         _packets.pop();
00053     }
00054     return packetList;
00055 }
00056 
00057 const float FFBaseDecoder::getAvgTime() const {
00058     return _avgTime;
00059 }
00060 
00061 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines