From baf10db48ef1b3097134fd19fc782b569e8a26a8 Mon Sep 17 00:00:00 2001 From: Johns Date: Mon, 26 Dec 2011 14:27:12 +0100 Subject: [PATCH] Cleanup video packet ringbuffer. --- softhddev.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/softhddev.c b/softhddev.c index 8e2b13c..040fae3 100644 --- a/softhddev.c +++ b/softhddev.c @@ -213,11 +213,12 @@ static int VideoMaxPacketSize; ///< biggest used packet buffer static void VideoPacketInit(void) { int i; - AVPacket *avpkt; Debug(4, "[softhddev]: %s\n", __FUNCTION__); for (i = 0; i < VIDEO_PACKET_MAX; ++i) { + AVPacket *avpkt; + avpkt = &VideoPacketRb[i]; // build a clean ffmpeg av packet if (av_new_packet(avpkt, VIDEO_BUFFER_SIZE)) { @@ -229,8 +230,32 @@ static void VideoPacketInit(void) atomic_set(&VideoPacketsFilled, 0); } +/** +** Cleanup video packet ringbuffer. +*/ +static void VideoPacketExit(void) +{ + int i; + + Debug(4, "[softhddev]: %s\n", __FUNCTION__); + + atomic_set(&VideoPacketsFilled, 0); + + for (i = 0; i < VIDEO_PACKET_MAX; ++i) { + AVPacket *avpkt; + + avpkt = &VideoPacketRb[i]; + // build a clean ffmpeg av packet + av_free_packet(avpkt); + } +} + /** ** Place video data in packet ringbuffer. +** +** @param pts presentation timestamp of pes packet +** @param data data of pes packet +** @param data size of pes packet */ static void VideoEnqueue(int64_t pts, const void *data, int size) { @@ -242,18 +267,16 @@ static void VideoEnqueue(int64_t pts, const void *data, int size) if (!avpkt->stream_index) { // add pts only for first added avpkt->pts = pts; } - if (avpkt->stream_index + size + FF_INPUT_BUFFER_PADDING_SIZE >= - avpkt->size) { + if (avpkt->stream_index + size >= avpkt->size) { Warning(_("video: packet buffer too small for %d\n"), - avpkt->stream_index + size + FF_INPUT_BUFFER_PADDING_SIZE); + avpkt->stream_index + size); - av_grow_packet(avpkt, - ((size + FF_INPUT_BUFFER_PADDING_SIZE + VIDEO_BUFFER_SIZE / 2) - / (VIDEO_BUFFER_SIZE / 2)) * (VIDEO_BUFFER_SIZE / 2)); + // new + grow reserves FF_INPUT_BUFFER_PADDING_SIZE + av_grow_packet(avpkt, ((size + VIDEO_BUFFER_SIZE / 2) + / (VIDEO_BUFFER_SIZE / 2)) * (VIDEO_BUFFER_SIZE / 2)); #ifdef DEBUG - if (avpkt->size < - avpkt->stream_index + size + FF_INPUT_BUFFER_PADDING_SIZE) { + if (avpkt->size <= avpkt->stream_index + size ) { abort(); } #endif @@ -444,6 +467,7 @@ int PlayVideo(const uint8_t * data, int size) Debug(3, "video: new stream %d\n", GetMsTicks() - VideoSwitch); // FIXME: hack to test results if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX - 1) { + Debug(3, "video: new video stream lost\n"); NewVideoStream = 0; return 0; } @@ -452,7 +476,7 @@ int PlayVideo(const uint8_t * data, int size) NewVideoStream = 0; } // must be a PES start code - if (size < 9 || data[0] || data[1] || data[2] != 0x01) { + if (size < 9 || !data || data[0] || data[1] || data[2] != 0x01) { Error(_("[softhddev] invalid PES video packet\n")); return size; } @@ -867,6 +891,7 @@ void Stop(void) VideoExit(); AudioExit(); CodecExit(); + VideoPacketExit(); if (StartX11Server) { Debug(3, "x-setup: Stop x11 server\n");