mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 05:45:33 +00:00
Move a couple packet queue methods into the struct
This commit is contained in:
parent
90294c589b
commit
5221298a7f
2 changed files with 53 additions and 50 deletions
|
@ -42,41 +42,38 @@ namespace MWRender
|
|||
return stream->tell();
|
||||
}
|
||||
|
||||
void packet_queue_init(PacketQueue *q)
|
||||
{ memset(q, 0, sizeof(PacketQueue)); }
|
||||
|
||||
int packet_queue_put(PacketQueue *q, AVPacket *pkt)
|
||||
void PacketQueue::put(AVPacket *pkt)
|
||||
{
|
||||
AVPacketList *pkt1;
|
||||
if(av_dup_packet(pkt) < 0)
|
||||
return -1;
|
||||
throw std::runtime_error("Failed to duplicate packet");
|
||||
|
||||
pkt1 = (AVPacketList*)av_malloc(sizeof(AVPacketList));
|
||||
if(!pkt1) return -1;
|
||||
if(!pkt1) throw std::bad_alloc();
|
||||
pkt1->pkt = *pkt;
|
||||
pkt1->next = NULL;
|
||||
|
||||
q->mutex.lock ();
|
||||
this->mutex.lock ();
|
||||
|
||||
if (!q->last_pkt)
|
||||
q->first_pkt = pkt1;
|
||||
if(!last_pkt)
|
||||
this->first_pkt = pkt1;
|
||||
else
|
||||
q->last_pkt->next = pkt1;
|
||||
q->last_pkt = pkt1;
|
||||
q->nb_packets++;
|
||||
q->size += pkt1->pkt.size;
|
||||
q->cond.notify_one();
|
||||
q->mutex.unlock ();
|
||||
return 0;
|
||||
this->last_pkt->next = pkt1;
|
||||
this->last_pkt = pkt1;
|
||||
this->nb_packets++;
|
||||
this->size += pkt1->pkt.size;
|
||||
this->cond.notify_one();
|
||||
|
||||
this->mutex.unlock();
|
||||
}
|
||||
|
||||
static int packet_queue_get(PacketQueue *q, AVPacket *pkt, VideoState *is, int block)
|
||||
int PacketQueue::get(AVPacket *pkt, VideoState *is, int block)
|
||||
{
|
||||
AVPacketList *pkt1;
|
||||
int ret;
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(q->mutex);
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(this->mutex);
|
||||
for(;;)
|
||||
{
|
||||
if(is->quit)
|
||||
|
@ -85,16 +82,18 @@ namespace MWRender
|
|||
break;
|
||||
}
|
||||
|
||||
pkt1 = q->first_pkt;
|
||||
if (pkt1)
|
||||
pkt1 = this->first_pkt;
|
||||
if(pkt1)
|
||||
{
|
||||
q->first_pkt = pkt1->next;
|
||||
if (!q->first_pkt)
|
||||
q->last_pkt = NULL;
|
||||
q->nb_packets--;
|
||||
q->size -= pkt1->pkt.size;
|
||||
this->first_pkt = pkt1->next;
|
||||
if(!this->first_pkt)
|
||||
this->last_pkt = NULL;
|
||||
this->nb_packets--;
|
||||
this->size -= pkt1->pkt.size;
|
||||
|
||||
*pkt = pkt1->pkt;
|
||||
av_free(pkt1);
|
||||
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -105,7 +104,7 @@ namespace MWRender
|
|||
break;
|
||||
}
|
||||
|
||||
q->cond.wait(lock);
|
||||
this->cond.wait(lock);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -116,7 +115,8 @@ namespace MWRender
|
|||
AVPacketList *pkt, *pkt1;
|
||||
|
||||
this->mutex.lock();
|
||||
for(pkt = this->first_pkt; pkt != NULL; pkt = pkt1) {
|
||||
for(pkt = this->first_pkt; pkt != NULL; pkt = pkt1)
|
||||
{
|
||||
pkt1 = pkt->next;
|
||||
av_free_packet(&pkt->pkt);
|
||||
av_freep(&pkt);
|
||||
|
@ -294,7 +294,7 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
|
|||
return -1;
|
||||
|
||||
/* next packet */
|
||||
if(packet_queue_get(&is->audioq, pkt, is, 1) < 0)
|
||||
if(is->audioq.get(pkt, is, 1) < 0)
|
||||
return -1;
|
||||
|
||||
/* if update, update the audio clock w/pts */
|
||||
|
@ -630,7 +630,7 @@ public:
|
|||
|
||||
for(;;)
|
||||
{
|
||||
if(packet_queue_get(&is->videoq, packet, is, 1) < 0)
|
||||
if(is->videoq.get(packet, is, 1) < 0)
|
||||
{
|
||||
// means we quit getting packets
|
||||
break;
|
||||
|
@ -701,7 +701,6 @@ public:
|
|||
is->audio_diff_threshold = 2.0 * 0.1/* 100 ms */;
|
||||
|
||||
memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
|
||||
packet_queue_init(&is->audioq);
|
||||
|
||||
decoder.reset(new MovieAudioDecoder(is));
|
||||
is->AudioTrack = MWBase::Environment::get().getSoundManager()->playTrack(decoder);
|
||||
|
@ -722,8 +721,6 @@ public:
|
|||
is->frame_last_delay = 40e-3;
|
||||
is->video_current_pts_time = av_gettime();
|
||||
|
||||
packet_queue_init(&is->videoq);
|
||||
|
||||
codecCtx->get_buffer = our_get_buffer;
|
||||
codecCtx->release_buffer = our_release_buffer;
|
||||
is->video_thread = boost::thread(video_thread, is);
|
||||
|
@ -764,9 +761,9 @@ public:
|
|||
|
||||
// Is this a packet from the video stream?
|
||||
if(packet->stream_index == is->videoStream)
|
||||
packet_queue_put(&is->videoq, packet);
|
||||
is->videoq.put(packet);
|
||||
else if(packet->stream_index == is->audioStream)
|
||||
packet_queue_put(&is->audioq, packet);
|
||||
is->audioq.put(packet);
|
||||
else
|
||||
av_free_packet(packet);
|
||||
}
|
||||
|
|
|
@ -33,10 +33,13 @@ extern "C"
|
|||
|
||||
namespace MWRender
|
||||
{
|
||||
struct VideoState;
|
||||
|
||||
struct PacketQueue {
|
||||
PacketQueue () :
|
||||
first_pkt(NULL), last_pkt(NULL), nb_packets(0), size(0)
|
||||
{}
|
||||
PacketQueue()
|
||||
: first_pkt(NULL), last_pkt(NULL), nb_packets(0), size(0)
|
||||
{ }
|
||||
|
||||
AVPacketList *first_pkt, *last_pkt;
|
||||
int nb_packets;
|
||||
int size;
|
||||
|
@ -44,20 +47,23 @@ namespace MWRender
|
|||
boost::mutex mutex;
|
||||
boost::condition_variable cond;
|
||||
|
||||
void flush ();
|
||||
};
|
||||
struct VideoPicture {
|
||||
VideoPicture () :
|
||||
data(NULL), pts(0)
|
||||
{}
|
||||
uint8_t* data;
|
||||
void put(AVPacket *pkt);
|
||||
int get(AVPacket *pkt, VideoState *is, int block);
|
||||
|
||||
void flush();
|
||||
};
|
||||
|
||||
struct VideoPicture {
|
||||
VideoPicture () : data(NULL), pts(0)
|
||||
{ }
|
||||
|
||||
uint8_t *data;
|
||||
double pts;
|
||||
};
|
||||
|
||||
struct VideoState {
|
||||
VideoState () :
|
||||
videoStream(-1), audioStream(-1), av_sync_type(0), external_clock(0),
|
||||
VideoState ()
|
||||
: videoStream(-1), audioStream(-1), av_sync_type(0), external_clock(0),
|
||||
external_clock_time(0), audio_clock(0), audio_st(NULL), audio_diff_cum(0),
|
||||
audio_diff_avg_coef(0), audio_diff_threshold(0), audio_diff_avg_count(0), frame_timer(0),
|
||||
frame_last_pts(0), frame_last_delay(0), video_clock(0), video_current_pts(0),
|
||||
|
@ -68,11 +74,11 @@ namespace MWRender
|
|||
|
||||
~VideoState()
|
||||
{
|
||||
audioq.flush ();
|
||||
audioq.flush();
|
||||
videoq.flush();
|
||||
|
||||
if (pictq_size >= 1)
|
||||
free (pictq[0].data);
|
||||
if(pictq_size >= 1)
|
||||
free(pictq[0].data);
|
||||
}
|
||||
|
||||
int videoStream, audioStream;
|
||||
|
@ -82,7 +88,7 @@ namespace MWRender
|
|||
int64_t external_clock_time;
|
||||
|
||||
double audio_clock;
|
||||
AVStream *audio_st;
|
||||
AVStream *audio_st;
|
||||
PacketQueue audioq;
|
||||
AVPacket audio_pkt;
|
||||
double audio_diff_cum; /* used for AV difference average computation */
|
||||
|
|
Loading…
Reference in a new issue