Fixed a big memory leak on the FFmpegReader while processing audio packets.

This commit is contained in:
Jonathan Thomas
2014-09-22 00:40:21 -05:00
parent 348ff39e87
commit 663e0d4129
3 changed files with 14 additions and 7 deletions

View File

@@ -52,6 +52,7 @@
<listOptionValue builtIn="false" value="/opt/local/include"/>
<listOptionValue builtIn="false" value="/usr/include/qt4"/>
<listOptionValue builtIn="false" value="/usr/include/qt4/QtMultimedia/"/>
<listOptionValue builtIn="false" value="/usr/include/ImageMagick-6"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1807071462" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
@@ -338,7 +339,7 @@
</target>
<target name="Linux: CMake Debug" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>cmake</buildCommand>
<buildArguments>-G "Unix Makefiles" ../ -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -D"ENABLE_BLACKMAGIC=0" -D"CMAKE_BUILD_TYPE:STRING=Debug"</buildArguments>
<buildArguments>-G "Unix Makefiles" ../ -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -D"ENABLE_BLACKMAGIC=0" -D"CMAKE_BUILD_TYPE:STRING=Debug"</buildArguments>
<buildTarget/>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>

View File

@@ -870,6 +870,9 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int
int16_t *audio_buf = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
int packet_samples = 0;
uint8_t *original_packet_data = my_packet->data;
int original_packet_size = my_packet->size;
while (my_packet->size > 0) {
// re-initialize buffer size (it gets changed in the avcodec_decode_audio2 method call)
int buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE;
@@ -888,6 +891,10 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int
my_packet->size -= used;
}
// Restore packet size and data (to avoid crash in av_free_packet)
my_packet->data = original_packet_data;
my_packet->size = original_packet_size;
// Estimate the # of samples and the end of this packet's location (to prevent GAPS for the next timestamp)
int pts_remaining_samples = packet_samples / info.channels; // Adjust for zero based array
@@ -935,11 +942,7 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int
}
#pragma omp critical (packet_cache)
{
// Remove packet
av_init_packet(my_packet); // TODO: this is a hack, to prevent a bug calling av_free_packet after avcodec_decode_audio3(). It causes a memory leak by not freeing pkt->data.
RemoveAVPacket(my_packet);
}
RemoveAVPacket(my_packet);
#pragma omp task firstprivate(requested_frame, target_frame, my_cache, starting_sample, audio_buf)
{

View File

@@ -60,7 +60,10 @@ int main(int argc, char* argv[])
//f->AddOverlayNumber(frame_number);
//f->Display();
if (x == 5000)
if (x == 32)
sinelReader.debug = true;
if (x == 50)
break;
}