CVSROOT: /sources/gnash Module name: gnash Changes by: Benjamin Wolsey <bwy> 07/11/26 20:11:05
Modified files: . : ChangeLog server/asobj : NetStreamFfmpeg.cpp NetStreamFfmpeg.h Log message: * server/asobj/NetStreamFfmpeg.{cpp,h}: add PktPointer class to make sure AVPackets are initialized and (more importantly) destroyed when no longer needed. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4970&r2=1.4971 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.96&r2=1.97 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.h?cvsroot=gnash&r1=1.48&r2=1.49 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.4970 retrieving revision 1.4971 diff -u -b -r1.4970 -r1.4971 --- ChangeLog 26 Nov 2007 17:54:12 -0000 1.4970 +++ ChangeLog 26 Nov 2007 20:11:04 -0000 1.4971 @@ -1,3 +1,9 @@ +2007-11-26 Benjamin Wolsey <[EMAIL PROTECTED]> + + * server/asobj/NetStreamFfmpeg.{cpp,h}: add PktPointer class + to make sure AVPackets are initialized and (more importantly) + destroyed when no longer needed. + 2007-11-26 Sandro Santilli <[EMAIL PROTECTED]> * testsuite/actionscript.all/MovieClip.as: add failing test Index: server/asobj/NetStreamFfmpeg.cpp =================================================================== RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v retrieving revision 1.96 retrieving revision 1.97 diff -u -b -r1.96 -r1.97 --- server/asobj/NetStreamFfmpeg.cpp 25 Nov 2007 17:50:01 -0000 1.96 +++ server/asobj/NetStreamFfmpeg.cpp 26 Nov 2007 20:11:05 -0000 1.97 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: NetStreamFfmpeg.cpp,v 1.96 2007/11/25 17:50:01 strk Exp $ */ +/* $Id: NetStreamFfmpeg.cpp,v 1.97 2007/11/26 20:11:05 bwy Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -720,7 +720,7 @@ bool NetStreamFfmpeg::decodeFLVFrame() { - AVPacket packet; + PktPointer packet; FLVFrame* frame = NULL; if (m_qvideo.size() < m_qaudio.size() && m_VCodecCtx) { @@ -745,18 +745,18 @@ return false; } - packet.destruct = avpacket_destruct; - packet.size = frame->dataSize; - packet.data = frame->data; + packet->destruct = avpacket_destruct; + packet->size = frame->dataSize; + packet->data = frame->data; // FIXME: is this the right value for packet.dts? - packet.pts = packet.dts = static_cast<int64_t>(frame->timestamp); + packet->pts = packet->dts = static_cast<int64_t>(frame->timestamp); if (frame->tag == 9) { - packet.stream_index = 0; - return decodeVideo(&packet); + packet->stream_index = 0; + return decodeVideo(packet.get()); } else { - packet.stream_index = 1; - return decodeAudio(&packet); + packet->stream_index = 1; + return decodeAudio(packet.get()); } } @@ -974,34 +974,32 @@ // Also, heap-allocating and storing in an auto_ptr // would make this function body simpler. // - AVPacket packet; - int rc = av_read_frame(m_FormatCtx, &packet); + PktPointer packet; + //std::auto_ptr<AVPacket> packet(new AVPacket); + + int rc = av_read_frame(m_FormatCtx, packet.get()); if (rc >= 0) { - if (packet.stream_index == m_audio_index && get_sound_handler()) + if (packet->stream_index == m_audio_index && get_sound_handler()) { - if (!decodeAudio(&packet)) { + if (!decodeAudio(packet.get())) { log_error(_("Problems decoding audio frame")); - av_free_packet(&packet); return false; } } else - if (packet.stream_index == m_video_index) + if (packet->stream_index == m_video_index) { - if (!decodeVideo(&packet)) { + if (!decodeVideo(packet.get())) { log_error(_("Problems decoding video frame")); - av_free_packet(&packet); return false; } } - av_free_packet(&packet); } else { log_error(_("Problems decoding frame")); - av_free_packet(&packet); return false; } @@ -1052,20 +1050,20 @@ if (m_VCodecCtx) m_last_video_timestamp = newpos; m_current_timestamp = newpos; } else { - AVPacket Packet; - av_init_packet(&Packet); + PktPointer packet; + //av_init_packet(&Packet); double newtime = 0; while (newtime == 0) { - if ( av_read_frame(m_FormatCtx, &Packet) < 0) { + if ( av_read_frame(m_FormatCtx, packet.get()) < 0) { av_seek_frame(m_FormatCtx, -1, 0,AVSEEK_FLAG_BACKWARD); - av_free_packet(&Packet); + //av_free_packet(&Packet); return; } newtime = timebase * (double)m_FormatCtx->streams[m_video_index]->cur_dts; } - av_free_packet(&Packet); + //av_free_packet(&Packet); av_seek_frame(m_FormatCtx, m_video_index, newpos, 0); uint32_t newtime_ms = static_cast<int32_t>(newtime / 1000.0); m_start_clock += m_last_audio_timestamp - newtime_ms; Index: server/asobj/NetStreamFfmpeg.h =================================================================== RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.h,v retrieving revision 1.48 retrieving revision 1.49 diff -u -b -r1.48 -r1.49 --- server/asobj/NetStreamFfmpeg.h 17 Jul 2007 22:05:03 -0000 1.48 +++ server/asobj/NetStreamFfmpeg.h 26 Nov 2007 20:11:05 -0000 1.49 @@ -15,7 +15,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -/* $Id: NetStreamFfmpeg.h,v 1.48 2007/07/17 22:05:03 nihilus Exp $ */ +/* $Id: NetStreamFfmpeg.h,v 1.49 2007/11/26 20:11:05 bwy Exp $ */ #ifndef __NETSTREAMFFMPEG_H__ #define __NETSTREAMFFMPEG_H__ @@ -280,6 +280,39 @@ private: + /// A smart pointer class that creates AVPackets used in decodeVideo() + /// and decodeAudio() and frees them when no longer needed. + /// Use PktPointer.get (as with auto_ptr) to access. + class PktPointer + { + public: + + /// Constructs an auto_ptr containing a heap-allocated (is that + /// the best idea?) AVPacket and initializes the usual data fields + PktPointer () : pktptr(new AVPacket) { + av_init_packet(pktptr.get()); + } + + /// Destructor automatically frees the AVPacket when it goes out + /// of scope. + ~PktPointer () { + av_free_packet(pktptr.get()); + } + + /// @ return AVPacket* pointed to by auto_ptr. + AVPacket* get () { + return pktptr.get(); + } + + // @ return pointers to AVPacket* members in + // auto_ptr + AVPacket* operator-> () { + return pktptr.get(); + } + private: + std::auto_ptr<AVPacket> pktptr; + }; + // Setups the playback bool startPlayback(); _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit