Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[what][draft][mov] 引入 mov_block_t 将部分内存管理控制权转给到调用方 #265

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HR1025
Copy link

@HR1025 HR1025 commented Mar 15, 2023

#264

针对于 mov_sample_t 结构体积累导致的内存增长, 有一个特点即为单个 mov_sample_t 所占用的内存空间是固定的;所以我想一下,可能使用 std::vector 这种方式暴露内存分配的方式比 new 的方式合适一点;所以定义了 mov_blocks_t :

struct mov_blocks_t
{
	/// create a blocks
    /// @param[in] param       user-defined parameter
    /// @param[in] id          blocks identifier
    /// @param[in] block_size  single block size
    /// @return 0-ok, <0-error
	int  (*create)(void* param, uint32_t id, uint32_t block_size);

	/// destroy a blocks
    /// @param[in]  param user-defined parameter
    /// @param[in]  id    blocks identifier
    /// @return 0-ok, <0-error
	int  (*destroy)(void* param, uint32_t id);

	/// set blocks capacity
    /// @param[in]  param     user-defined parameter
    /// @param[in]  id        blocks identifier
    /// @param[in]  capacity  blocks capacity
	int  (*set_capacity)(void* param, uint32_t id, uint64_t capacity);

	/// get block by index
    /// @param[in]  param   user-defined parameter
    /// @param[in]  id      blocks identifier
    /// @param[in]  index   block index in blocks
    /// @return     memory pointer
	void* (*at)(void* param, uint32_t id, uint64_t index);
};

原型上参考的大致是 STL vector arrary.

所以我将其命名成 block,体现单个 mov_sample_t 固定长度的含义; 不过还是感觉看起来怪怪的, 不知道有什么其他合适的命名.

然后再所有地方操作 mov_sample_t 的地方都使用 libmov/source/mov-blocks-util.h 的接口进行操作.

@HR1025
Copy link
Author

HR1025 commented Mar 15, 2023

这个提交只是草案,不能运行;只适配了 mov write, mov read 、fmp4 write、 read 都还没有实现完整的替换, 而且其他替换部分逻辑没有严谨地检查,更多的是伪代码的方案设计.

使用 mov_sample_t 这种方式暴露内存分配的方式, 调用者如果使用双内存缓冲区作为 cache, 文件缓存作为 store; 应该是会比较好解决内存增长的问题.

我看了一下代码, mov_sample_t 的空间连续性相当得高; 使用双内存缓冲区+文件缓存的方式应该是不会引起文件和内存的频繁交换的; 此外, mov_blocks_t 也可以使用 realloc 这种现在 media-server 的方式进行实现.

@HR1025 HR1025 marked this pull request as draft March 15, 2023 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant