mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 02:45:32 +00:00
Make sure packets are cleaned up properly
This commit is contained in:
parent
db23c8152e
commit
fa1ad381da
1 changed files with 16 additions and 9 deletions
|
@ -118,7 +118,6 @@ struct VideoState {
|
||||||
double audio_clock;
|
double audio_clock;
|
||||||
AVStream *audio_st;
|
AVStream *audio_st;
|
||||||
PacketQueue audioq;
|
PacketQueue audioq;
|
||||||
AVPacket audio_pkt;
|
|
||||||
double audio_diff_cum; /* used for AV difference average computation */
|
double audio_diff_cum; /* used for AV difference average computation */
|
||||||
double audio_diff_avg_coef;
|
double audio_diff_avg_coef;
|
||||||
double audio_diff_threshold;
|
double audio_diff_threshold;
|
||||||
|
@ -239,8 +238,19 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
|
||||||
throw std::runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AutoAVPacket : public AVPacket {
|
||||||
|
AutoAVPacket(int size=0)
|
||||||
|
{
|
||||||
|
if(av_new_packet(this, size) < 0)
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
~AutoAVPacket()
|
||||||
|
{ av_free_packet(this); }
|
||||||
|
};
|
||||||
|
|
||||||
VideoState *is;
|
VideoState *is;
|
||||||
|
|
||||||
|
AutoAVPacket mPacket;
|
||||||
AVFrame *mFrame;
|
AVFrame *mFrame;
|
||||||
ssize_t mFramePos;
|
ssize_t mFramePos;
|
||||||
ssize_t mFrameSize;
|
ssize_t mFrameSize;
|
||||||
|
@ -276,7 +286,7 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
|
||||||
|
|
||||||
int audio_decode_frame(AVFrame *frame)
|
int audio_decode_frame(AVFrame *frame)
|
||||||
{
|
{
|
||||||
AVPacket *pkt = &is->audio_pkt;
|
AVPacket *pkt = &mPacket;
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
@ -292,8 +302,7 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
|
||||||
/* Move the unread data to the front and clear the end bits */
|
/* Move the unread data to the front and clear the end bits */
|
||||||
int remaining = pkt->size - len1;
|
int remaining = pkt->size - len1;
|
||||||
memmove(pkt->data, &pkt->data[len1], remaining);
|
memmove(pkt->data, &pkt->data[len1], remaining);
|
||||||
memset(&pkt->data[remaining], 0, pkt->size - remaining);
|
av_shrink_packet(pkt, remaining);
|
||||||
pkt->size -= len1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No data yet? Look for more frames */
|
/* No data yet? Look for more frames */
|
||||||
|
@ -307,7 +316,6 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
|
||||||
return frame->nb_samples * av_get_bytes_per_sample(is->audio_st->codec->sample_fmt) *
|
return frame->nb_samples * av_get_bytes_per_sample(is->audio_st->codec->sample_fmt) *
|
||||||
is->audio_st->codec->channels;
|
is->audio_st->codec->channels;
|
||||||
}
|
}
|
||||||
if(pkt->data)
|
|
||||||
av_free_packet(pkt);
|
av_free_packet(pkt);
|
||||||
|
|
||||||
if(is->quit)
|
if(is->quit)
|
||||||
|
@ -717,6 +725,8 @@ void VideoState::video_thread_loop(VideoState *self)
|
||||||
pts = *(uint64_t*)pFrame->opaque;
|
pts = *(uint64_t*)pFrame->opaque;
|
||||||
pts *= av_q2d(self->video_st->time_base);
|
pts *= av_q2d(self->video_st->time_base);
|
||||||
|
|
||||||
|
av_free_packet(packet);
|
||||||
|
|
||||||
// Did we get a video frame?
|
// Did we get a video frame?
|
||||||
if(frameFinished)
|
if(frameFinished)
|
||||||
{
|
{
|
||||||
|
@ -724,7 +734,6 @@ void VideoState::video_thread_loop(VideoState *self)
|
||||||
if(self->queue_picture(pFrame, pts) < 0)
|
if(self->queue_picture(pFrame, pts) < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
av_free_packet(packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
av_free(pFrame);
|
av_free(pFrame);
|
||||||
|
@ -814,8 +823,6 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx)
|
||||||
/* Correct audio only if larger error than this */
|
/* Correct audio only if larger error than this */
|
||||||
this->audio_diff_threshold = 2.0 * 0.050/* 50 ms */;
|
this->audio_diff_threshold = 2.0 * 0.050/* 50 ms */;
|
||||||
|
|
||||||
memset(&this->audio_pkt, 0, sizeof(this->audio_pkt));
|
|
||||||
|
|
||||||
decoder.reset(new MovieAudioDecoder(this));
|
decoder.reset(new MovieAudioDecoder(this));
|
||||||
this->AudioTrack = MWBase::Environment::get().getSoundManager()->playTrack(decoder);
|
this->AudioTrack = MWBase::Environment::get().getSoundManager()->playTrack(decoder);
|
||||||
if(!this->AudioTrack)
|
if(!this->AudioTrack)
|
||||||
|
|
Loading…
Reference in a new issue