maybe fixes, maybe big memleaks

This commit is contained in:
Isaac Connor 2016-09-20 16:59:43 -04:00
parent 364a80fb94
commit 19a60b01da
4 changed files with 34 additions and 10 deletions

View File

@ -167,7 +167,7 @@ int FfmpegCamera::Capture( Image &image )
Error( "Unable to read packet from stream %d: error %d \"%s\".", packet.stream_index, avResult, errbuf ); Error( "Unable to read packet from stream %d: error %d \"%s\".", packet.stream_index, avResult, errbuf );
return( -1 ); return( -1 );
} }
Debug( 5, "Got packet from stream %d", packet.stream_index ); Debug( 5, "Got packet from stream %d dts (%d) pts(%d)", packet.stream_index, packet.pts, packet.dts );
// What about audio stream? Maybe someday we could do sound detection... // What about audio stream? Maybe someday we could do sound detection...
if ( packet.stream_index == mVideoStreamId ) { if ( packet.stream_index == mVideoStreamId ) {
#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0) #if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0)
@ -290,7 +290,6 @@ int FfmpegCamera::OpenFfmpeg() {
Debug ( 1, "Opened input" ); Debug ( 1, "Opened input" );
Info( "Stream open %s", mPath.c_str() ); Info( "Stream open %s", mPath.c_str() );
startTime=av_gettime();//FIXME here or after find_Stream_info
//FIXME can speed up initial analysis but need sensible parameters... //FIXME can speed up initial analysis but need sensible parameters...
//mFormatContext->probesize = 32; //mFormatContext->probesize = 32;
@ -305,6 +304,7 @@ int FfmpegCamera::OpenFfmpeg() {
#endif #endif
Fatal( "Unable to find stream info from %s due to: %s", mPath.c_str(), strerror(errno) ); Fatal( "Unable to find stream info from %s due to: %s", mPath.c_str(), strerror(errno) );
startTime=av_gettime();//FIXME here or after find_Stream_info
Debug ( 1, "Got stream info" ); Debug ( 1, "Got stream info" );
// Find first video stream present // Find first video stream present
@ -584,7 +584,7 @@ Debug(5, "After av_read_frame (%d)", ret );
Error( "Unable to read packet from stream %d: error %d \"%s\".", packet->stream_index, ret, errbuf ); Error( "Unable to read packet from stream %d: error %d \"%s\".", packet->stream_index, ret, errbuf );
return( -1 ); return( -1 );
} }
Debug( 5, "Got packet from stream %d", packet->stream_index ); Debug( 4, "Got packet from stream %d dts (%d) pts(%d)", packet->stream_index, packet->dts, packet->pts );
//Video recording //Video recording
if ( recording ) { if ( recording ) {
@ -636,7 +636,7 @@ Debug(5, "After av_read_frame (%d)", ret );
while ( ( queued_packet = packetqueue.popPacket() ) ) { while ( ( queued_packet = packetqueue.popPacket() ) ) {
packet_count += 1; packet_count += 1;
//Write the packet to our video store //Write the packet to our video store
Debug(2, "Writing queued packet stream: %d KEY %d", queued_packet->stream_index, packet->flags & AV_PKT_FLAG_KEY ); Debug(2, "Writing queued packet stream: %d KEY %d, remaining (%d)", queued_packet->stream_index, packet->flags & AV_PKT_FLAG_KEY, packetqueue.size() );
if ( queued_packet->stream_index == mVideoStreamId ) { if ( queued_packet->stream_index == mVideoStreamId ) {
ret = videoStore->writeVideoFramePacket( queued_packet, mFormatContext->streams[mVideoStreamId]); ret = videoStore->writeVideoFramePacket( queued_packet, mFormatContext->streams[mVideoStreamId]);
} else if ( queued_packet->stream_index == mAudioStreamId ) { } else if ( queued_packet->stream_index == mAudioStreamId ) {
@ -748,6 +748,7 @@ Debug(5, "After av_read_frame (%d)", ret );
Debug( 3, "Some other stream index %d", packet->stream_index ); Debug( 3, "Some other stream index %d", packet->stream_index );
#endif #endif
} }
if ( videoStore )
zm_av_unref_packet( packet ); zm_av_unref_packet( packet );
} // end while ! frameComplete } // end while ! frameComplete
return (frameCount); return (frameCount);

View File

@ -37,10 +37,14 @@ bool zm_packetqueue::queuePacket( AVPacket* packet ) {
//AVPacket *input_ref = (AVPacket *)av_malloc(sizeof(AVPacket)); //AVPacket *input_ref = (AVPacket *)av_malloc(sizeof(AVPacket));
//if ( av_packet_ref( input_ref, packet ) < 0 ) { //if ( av_packet_ref( input_ref, packet ) < 0 ) {
//free(input_ref); if ( av_packet_ref( packet, packet ) < 0 ) {
//return false; Error("error refing packet");
//} //av_free_packet(input_ref);
return false;
}
pktQueue.push( packet ); pktQueue.push( packet );
//pktQueue.push( input_ref );
return true; return true;
} }
@ -66,3 +70,7 @@ void zm_packetqueue::clearQueue() {
zm_av_unref_packet( packet ); zm_av_unref_packet( packet );
} }
} }
unsigned int zm_packetqueue::size() {
return pktQueue.size();
}

View File

@ -38,6 +38,7 @@ public:
bool popVideoPacket(AVPacket* packet); bool popVideoPacket(AVPacket* packet);
bool popAudioPacket(AVPacket* packet); bool popAudioPacket(AVPacket* packet);
void clearQueue( ); void clearQueue( );
unsigned int size();
private: private:
std::queue<AVPacket *> pktQueue; std::queue<AVPacket *> pktQueue;

View File

@ -274,6 +274,7 @@ Debug(2, "Have audio_output_context");
startDts = 0; startDts = 0;
filter_in_rescale_delta_last = AV_NOPTS_VALUE; filter_in_rescale_delta_last = AV_NOPTS_VALUE;
// now - when streaming started
startTime=av_gettime()-nStartTime;//oc->start_time; startTime=av_gettime()-nStartTime;//oc->start_time;
Info("VideoStore startTime=%d\n",startTime); Info("VideoStore startTime=%d\n",startTime);
} // VideoStore::VideoStore } // VideoStore::VideoStore
@ -342,26 +343,39 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt, AVStream *input_video_stre
Debug(2, "writeVideoFrame init_packet"); Debug(2, "writeVideoFrame init_packet");
av_init_packet(&opkt); av_init_packet(&opkt);
if ( 1 ) {
if ( ! startPts ) {
//never gets set, so the first packet can set it.
startPts = ipkt->pts;
}
//Scale the PTS of the outgoing packet to be the correct time base //Scale the PTS of the outgoing packet to be the correct time base
if (ipkt->pts != AV_NOPTS_VALUE) { if (ipkt->pts != AV_NOPTS_VALUE) {
opkt.pts = av_rescale_q(ipkt->pts-startPts, input_video_stream->time_base, video_stream->time_base) - ost_tb_start_time; opkt.pts = av_rescale_q(ipkt->pts-startPts, input_video_stream->time_base, video_stream->time_base);
//- ost_tb_start_time;
Debug(3, "opkt.pts = %d from ipkt->pts(%d) - startPts(%d), input->time_base(%d) video_stream->time-base(%d)", opkt.pts, ipkt->pts, startPts, input_video_stream->time_base, video_stream->time_base ); Debug(3, "opkt.pts = %d from ipkt->pts(%d) - startPts(%d), input->time_base(%d) video_stream->time-base(%d)", opkt.pts, ipkt->pts, startPts, input_video_stream->time_base, video_stream->time_base );
} else { } else {
Debug(3, "opkt.pts = undef");
opkt.pts = AV_NOPTS_VALUE; opkt.pts = AV_NOPTS_VALUE;
} }
if ( ! startDts ) {
startDts = input_video_stream->cur_dts;
}
//Scale the DTS of the outgoing packet to be the correct time base //Scale the DTS of the outgoing packet to be the correct time base
if(ipkt->dts == AV_NOPTS_VALUE) { if(ipkt->dts == AV_NOPTS_VALUE) {
opkt.dts = av_rescale_q(input_video_stream->cur_dts-startDts, AV_TIME_BASE_Q, video_stream->time_base); opkt.dts = av_rescale_q(input_video_stream->cur_dts-startDts, AV_TIME_BASE_Q, video_stream->time_base);
Debug(3, "opkt.dts = %d from input_video_stream->cur_dts(%d) - startDts(%d), video_stream->time-base(%d)", opkt.dts, input_video_stream->cur_dts, startDts, video_stream->time_base ); Debug(3, "opkt.dts = %d from input_video_stream->cur_dts(%d) - startDts(%d), video_stream->time-base(%d)", opkt.dts, input_video_stream->cur_dts, startDts, video_stream->time_base );
} else { } else {
opkt.dts = av_rescale_q(ipkt->dts-startDts, input_video_stream->time_base, video_stream->time_base); opkt.dts = av_rescale_q(ipkt->dts-startDts, input_video_stream->time_base, video_stream->time_base);
Debug(3, "opkt.dts = %d from ipkt->dts(%d) - startDts(%d), video_stream->time-base(%d)", opkt.dts, ipkt->dts, startDts, video_stream->time_base ); Debug(3, "opkt.dts = %d from ipkt->dts(%d) - startDts(%d), video_stream->time-base(%d)", opkt.dts, ipkt->dts, startDts, video_stream->time_base );
} }
opkt.dts -= ost_tb_start_time; //opkt.dts -= ost_tb_start_time;
opkt.duration = av_rescale_q(ipkt->duration, input_video_stream->time_base, video_stream->time_base); opkt.duration = av_rescale_q(ipkt->duration, input_video_stream->time_base, video_stream->time_base);
} else {
av_packet_rescale_ts( &opkt, input_video_stream->time_base, video_stream->time_base );
}
opkt.flags = ipkt->flags; opkt.flags = ipkt->flags;
opkt.pos=-1; opkt.pos=-1;