You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Fixed another seek bug, and resolved some memory leaks with removing av_frames and av_packets.
This commit is contained in:
@@ -140,7 +140,7 @@ include_directories("../thirdparty/jsoncpp/include")
|
||||
|
||||
############### PROFILING #################
|
||||
#set(PROFILER "/usr/lib/libprofiler.so")
|
||||
#set(PROFILER "/usr/lib/libtcmalloc.so")
|
||||
#set(PROFILER "/usr/lib/libtcmalloc.so.4")
|
||||
|
||||
#### GET LIST OF EFFECT FILES ####
|
||||
FILE(GLOB EFFECT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/effects/*.cpp")
|
||||
|
||||
@@ -420,9 +420,9 @@ tr1::shared_ptr<Frame> FFmpegReader::GetFrame(int requested_frame) throw(OutOfBo
|
||||
// Get first frame
|
||||
ReadStream(1);
|
||||
|
||||
// Are we within 30 frames of the requested frame?
|
||||
// Are we within X frames of the requested frame?
|
||||
int diff = requested_frame - last_frame;
|
||||
if (diff >= 1 && diff <= 30)
|
||||
if (diff >= 1 && diff <= 20)
|
||||
{
|
||||
// Continue walking the stream
|
||||
return ReadStream(requested_frame);
|
||||
@@ -506,9 +506,13 @@ tr1::shared_ptr<Frame> FFmpegReader::ReadStream(int requested_frame)
|
||||
else
|
||||
check_seek = false;
|
||||
|
||||
if (check_seek)
|
||||
if (check_seek) {
|
||||
// Remove packet (since this packet is pointless)
|
||||
RemoveAVPacket(packet);
|
||||
|
||||
// Jump to the next iteration of this loop
|
||||
continue;
|
||||
}
|
||||
|
||||
#pragma omp critical (packet_cache)
|
||||
frame_finished = GetAVFrame();
|
||||
@@ -534,9 +538,13 @@ tr1::shared_ptr<Frame> FFmpegReader::ReadStream(int requested_frame)
|
||||
else
|
||||
check_seek = false;
|
||||
|
||||
if (check_seek)
|
||||
if (check_seek) {
|
||||
// Remove packet (since this packet is pointless)
|
||||
RemoveAVPacket(packet);
|
||||
|
||||
// Jump to the next iteration of this loop
|
||||
continue;
|
||||
}
|
||||
|
||||
// Update PTS / Frame Offset (if any)
|
||||
UpdatePTSOffset(false);
|
||||
@@ -608,6 +616,7 @@ int FFmpegReader::GetNextPacket()
|
||||
|
||||
// Update current packet pointer
|
||||
packet = packets[next_packet];
|
||||
|
||||
}else
|
||||
{
|
||||
// Free packet, since it's unused
|
||||
@@ -928,7 +937,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()
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1572,6 +1581,9 @@ void FFmpegReader::RemoveAVFrame(AVPicture* remove_frame)
|
||||
|
||||
// Remove from cache
|
||||
frames.erase(remove_frame);
|
||||
|
||||
// Delete the object
|
||||
delete remove_frame;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1581,12 +1593,14 @@ void FFmpegReader::RemoveAVPacket(AVPacket* remove_packet)
|
||||
// Remove packet (if any)
|
||||
if (packets.count(remove_packet))
|
||||
{
|
||||
// Remove from cache
|
||||
packets.erase(remove_packet);
|
||||
|
||||
// deallocate memory for packet
|
||||
av_free_packet(remove_packet);
|
||||
|
||||
// Remove from cache
|
||||
packets.erase(remove_packet);
|
||||
|
||||
// Delete the object
|
||||
delete remove_packet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
src/Main.cpp
23
src/Main.cpp
@@ -33,6 +33,8 @@
|
||||
#include "../include/OpenShot.h"
|
||||
#include "../include/Json.h"
|
||||
#include <omp.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
using namespace openshot;
|
||||
@@ -42,15 +44,24 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
FFmpegReader sinelReader("/home/jonathan/Videos/sintel_trailer-720p.mp4");
|
||||
sinelReader.debug = true;
|
||||
//sinelReader.debug = true;
|
||||
sinelReader.Open();
|
||||
|
||||
// init random #s
|
||||
//srand(time(NULL));
|
||||
|
||||
// Seek test
|
||||
int frames[15] = {1,624,585,222,333};
|
||||
for (int x = 0; x<6; x++) {
|
||||
tr1::shared_ptr<Frame> f = sinelReader.GetFrame(frames[x]);
|
||||
f->AddOverlayNumber(frames[x]);
|
||||
f->Display();
|
||||
int x = 0;
|
||||
while (true) {
|
||||
x++;
|
||||
int frame_number = (rand() % 625) + 1;
|
||||
cout << "X: " << x << ", Frame: " << frame_number << endl;
|
||||
tr1::shared_ptr<Frame> f = sinelReader.GetFrame(frame_number);
|
||||
//f->AddOverlayNumber(frame_number);
|
||||
//f->Display();
|
||||
|
||||
if (x == 5000)
|
||||
break;
|
||||
}
|
||||
|
||||
cout << sinelReader.OutputDebugJSON() << endl;
|
||||
|
||||
Reference in New Issue
Block a user