Skip to content

Commit

Permalink
decode: fix memory leak in decoder simple sample
Browse files Browse the repository at this point in the history
  • Loading branch information
zlatinski committed Mar 5, 2025
1 parent f468fc9 commit b5d0d26
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions vk_video_decoder/test/vulkan-video-simple-dec/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ static void DumpDecoderStreamInfo(VkSharedBaseObj<VulkanVideoDecoder>& vulkanVid
std::cout << std::endl;
}

static std::vector<VulkanDecodedFrame> frameDataQueue;
static uint32_t curFrameDataQueueIndex = 0;
bool GetNextFrame(VkSharedBaseObj<VulkanVideoDecoder>& vulkanVideoDecoder)
static size_t init(std::vector<VulkanDecodedFrame>& frameDataQueue, uint32_t& curFrameDataQueueIndex,
const uint32_t decoderQueueSize)
{
curFrameDataQueueIndex = 0;
frameDataQueue.resize(decoderQueueSize);
return frameDataQueue.size();
}

static bool GetNextFrame(VkSharedBaseObj<VulkanVideoDecoder>& vulkanVideoDecoder,
std::vector<VulkanDecodedFrame>& frameDataQueue,
uint32_t& curFrameDataQueueIndex)
{
bool continueLoop = true;

Expand Down Expand Up @@ -84,6 +92,13 @@ bool GetNextFrame(VkSharedBaseObj<VulkanVideoDecoder>& vulkanVideoDecoder)
return continueLoop;
}

static void deinit(std::vector<VulkanDecodedFrame>& frameDataQueue,
uint32_t& curFrameDataQueueIndex)
{
frameDataQueue.clear();
curFrameDataQueueIndex = 0;
}

int main(int argc, const char** argv)
{
std::cout << "Enter decoder test" << std::endl;
Expand Down Expand Up @@ -151,14 +166,19 @@ int main(int argc, const char** argv)

DumpDecoderStreamInfo(vulkanVideoDecoder);

std::vector<VulkanDecodedFrame> frameDataQueue;
uint32_t curFrameDataQueueIndex = 0;

frameDataQueue.resize(decoderConfig.decoderQueueSize);

init(frameDataQueue, curFrameDataQueueIndex, decoderConfig.decoderQueueSize);

bool continueLoop = true;
do {
continueLoop = GetNextFrame(vulkanVideoDecoder);
continueLoop = GetNextFrame(vulkanVideoDecoder, frameDataQueue, curFrameDataQueueIndex);
} while (continueLoop);

/*******************************************************************************************/
deinit(frameDataQueue, curFrameDataQueueIndex);

std::cout << "Exit decoder test" << std::endl;
}
Expand Down

0 comments on commit b5d0d26

Please sign in to comment.