1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-21 19:41:35 +00:00

Move a couple packet queue methods into the struct

This commit is contained in:
Chris Robinson 2012-12-14 01:14:14 -08:00
parent 90294c589b
commit 5221298a7f
2 changed files with 53 additions and 50 deletions

View file

@ -42,41 +42,38 @@ namespace MWRender
return stream->tell(); 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; AVPacketList *pkt1;
if(av_dup_packet(pkt) < 0) if(av_dup_packet(pkt) < 0)
return -1; throw std::runtime_error("Failed to duplicate packet");
pkt1 = (AVPacketList*)av_malloc(sizeof(AVPacketList)); pkt1 = (AVPacketList*)av_malloc(sizeof(AVPacketList));
if(!pkt1) return -1; if(!pkt1) throw std::bad_alloc();
pkt1->pkt = *pkt; pkt1->pkt = *pkt;
pkt1->next = NULL; pkt1->next = NULL;
q->mutex.lock (); this->mutex.lock ();
if (!q->last_pkt) if(!last_pkt)
q->first_pkt = pkt1; this->first_pkt = pkt1;
else else
q->last_pkt->next = pkt1; this->last_pkt->next = pkt1;
q->last_pkt = pkt1; this->last_pkt = pkt1;
q->nb_packets++; this->nb_packets++;
q->size += pkt1->pkt.size; this->size += pkt1->pkt.size;
q->cond.notify_one(); this->cond.notify_one();
q->mutex.unlock ();
return 0; 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; AVPacketList *pkt1;
int ret; int ret;
boost::unique_lock<boost::mutex> lock(q->mutex); boost::unique_lock<boost::mutex> lock(this->mutex);
for(;;) for(;;)
{ {
if(is->quit) if(is->quit)
@ -85,16 +82,18 @@ namespace MWRender
break; break;
} }
pkt1 = q->first_pkt; pkt1 = this->first_pkt;
if(pkt1) if(pkt1)
{ {
q->first_pkt = pkt1->next; this->first_pkt = pkt1->next;
if (!q->first_pkt) if(!this->first_pkt)
q->last_pkt = NULL; this->last_pkt = NULL;
q->nb_packets--; this->nb_packets--;
q->size -= pkt1->pkt.size; this->size -= pkt1->pkt.size;
*pkt = pkt1->pkt; *pkt = pkt1->pkt;
av_free(pkt1); av_free(pkt1);
ret = 1; ret = 1;
break; break;
} }
@ -105,7 +104,7 @@ namespace MWRender
break; break;
} }
q->cond.wait(lock); this->cond.wait(lock);
} }
return ret; return ret;
@ -116,7 +115,8 @@ namespace MWRender
AVPacketList *pkt, *pkt1; AVPacketList *pkt, *pkt1;
this->mutex.lock(); this->mutex.lock();
for(pkt = this->first_pkt; pkt != NULL; pkt = pkt1) { for(pkt = this->first_pkt; pkt != NULL; pkt = pkt1)
{
pkt1 = pkt->next; pkt1 = pkt->next;
av_free_packet(&pkt->pkt); av_free_packet(&pkt->pkt);
av_freep(&pkt); av_freep(&pkt);
@ -294,7 +294,7 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
return -1; return -1;
/* next packet */ /* next packet */
if(packet_queue_get(&is->audioq, pkt, is, 1) < 0) if(is->audioq.get(pkt, is, 1) < 0)
return -1; return -1;
/* if update, update the audio clock w/pts */ /* if update, update the audio clock w/pts */
@ -630,7 +630,7 @@ public:
for(;;) for(;;)
{ {
if(packet_queue_get(&is->videoq, packet, is, 1) < 0) if(is->videoq.get(packet, is, 1) < 0)
{ {
// means we quit getting packets // means we quit getting packets
break; break;
@ -701,7 +701,6 @@ public:
is->audio_diff_threshold = 2.0 * 0.1/* 100 ms */; is->audio_diff_threshold = 2.0 * 0.1/* 100 ms */;
memset(&is->audio_pkt, 0, sizeof(is->audio_pkt)); memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
packet_queue_init(&is->audioq);
decoder.reset(new MovieAudioDecoder(is)); decoder.reset(new MovieAudioDecoder(is));
is->AudioTrack = MWBase::Environment::get().getSoundManager()->playTrack(decoder); is->AudioTrack = MWBase::Environment::get().getSoundManager()->playTrack(decoder);
@ -722,8 +721,6 @@ public:
is->frame_last_delay = 40e-3; is->frame_last_delay = 40e-3;
is->video_current_pts_time = av_gettime(); is->video_current_pts_time = av_gettime();
packet_queue_init(&is->videoq);
codecCtx->get_buffer = our_get_buffer; codecCtx->get_buffer = our_get_buffer;
codecCtx->release_buffer = our_release_buffer; codecCtx->release_buffer = our_release_buffer;
is->video_thread = boost::thread(video_thread, is); is->video_thread = boost::thread(video_thread, is);
@ -764,9 +761,9 @@ public:
// Is this a packet from the video stream? // Is this a packet from the video stream?
if(packet->stream_index == is->videoStream) if(packet->stream_index == is->videoStream)
packet_queue_put(&is->videoq, packet); is->videoq.put(packet);
else if(packet->stream_index == is->audioStream) else if(packet->stream_index == is->audioStream)
packet_queue_put(&is->audioq, packet); is->audioq.put(packet);
else else
av_free_packet(packet); av_free_packet(packet);
} }

View file

@ -33,10 +33,13 @@ extern "C"
namespace MWRender namespace MWRender
{ {
struct VideoState;
struct PacketQueue { struct PacketQueue {
PacketQueue () : PacketQueue()
first_pkt(NULL), last_pkt(NULL), nb_packets(0), size(0) : first_pkt(NULL), last_pkt(NULL), nb_packets(0), size(0)
{ } { }
AVPacketList *first_pkt, *last_pkt; AVPacketList *first_pkt, *last_pkt;
int nb_packets; int nb_packets;
int size; int size;
@ -44,20 +47,23 @@ namespace MWRender
boost::mutex mutex; boost::mutex mutex;
boost::condition_variable cond; boost::condition_variable cond;
void put(AVPacket *pkt);
int get(AVPacket *pkt, VideoState *is, int block);
void flush(); void flush();
}; };
struct VideoPicture {
VideoPicture () :
data(NULL), pts(0)
{}
uint8_t* data;
struct VideoPicture {
VideoPicture () : data(NULL), pts(0)
{ }
uint8_t *data;
double pts; double pts;
}; };
struct VideoState { struct VideoState {
VideoState () : VideoState ()
videoStream(-1), audioStream(-1), av_sync_type(0), external_clock(0), : 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), 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), 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), frame_last_pts(0), frame_last_delay(0), video_clock(0), video_current_pts(0),