MPlayer Cache机制
来源:互联网 发布:橱柜 设计软件 编辑:程序博客网 时间:2024/05/07 07:31
1.Mplayer Cache机制概述
Mplayer的cache机制作为播放文件或URL的预缓冲。对速度满的媒体特别有用。MPlayer可以通过相应的命令选项控制缓冲的大小,是否需要设置缓冲等。以下列出Mplyaer为用户提供的几个关于cache的命令选项。几个选项分别是:
-cache XXX---该选项用于指定cache的大小为XXXkbytes;
-nocache----表示关闭缓存。
-cache-min XXX----表示当缓冲填充到总数的XXX/100%时开始播放。
-cache-seek-min XXX---如果查询到的位置处于从当前位置算起的缓存大小的(百分数)之内,mplayer等待填充缓存到此位置而不是执行流查询(默认是50)。
MPlayer的cache机制的实现依赖linux系统提供的进程复制函数fork();当用于需要启用cache功能后,MPlayer会调用fork函数复制当前进程,在进程表中创建一个新的表项,执行完全相同的代码。新的进程一旦创建成功,父进程用于文件的解码的播放,子进程用于维护cache。
图1.cache简要原理图
2.Mplayer Cache Data Structure
2.1.cache_vars_t
typedef struct {
unsigned char *buffer; // 缓存的基地址
int buffer_size; // 缓存大小
int sector_size; // 缓存每段大小
int back_size; // we should keep back_size amount of old bytes for backward seek
int fill_limit; // 填充缓存的空间限制we should fill buffer only if space>=fill_limit
int seek_limit; // 缓存中可以seek最小值keep filling cache if distance is less that seek limit
// filler's pointers:
int eof; //流或文件是否结束。
off_t min_filepos; // buffer contain only a part of the file, from min-max pos
off_t max_filepos; //缓存中包含的数据在整个文件中的位置。从min-max
off_t offset; // filepos <-> bufferpos offset value (filepos of the buffer's first byte)
文件在缓存开始的位置。
// reader's pointers:
off_t read_filepos; 缓存读位置/
// commands/locking:
// int seek_lock; // 1 if we will seek/reset buffer, 2 if we are ready for cmd
// int fifo_flag; // 1 if we should use FIFO to notice cache about buffer reads.
// callback
stream_t* stream;
volatile int control;
volatile unsigned control_uint_arg;
volatile double control_double_arg;
volatile int control_res;
volatile off_t control_new_pos;
volatile double stream_time_length;
} cache_vars_t;
3.Mplayer Cache Function
1、int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit)
name:
stream_enable_cache
Description:
使能cache功能
Parameter:
stream 流处理数据参数
size 缓存的大小
min 指定预填充cache的最少数据大小
seek_limit 指定seek限制大小
Return:
Int 1 on success,
0 if the function was interrupted
-1 on error
Remark:
1)、cache_init(): 主要是分配cache_vars_t *s及cache缓冲s->buffer(cache) 内存空间,
并通过shared_alloc ()函数使父子进程共享s数据结构及cache。
2)、fork()
(1) 父进程:达到一定条件并返回
read:stream_read()->cache_stream_fill_buffer()->cache_read()
seek:
stream_seek() ->cache_stream_seek_long()->cache_stream_fill_buffer()->cache_read()
(2)子进程
read:cache_fill->stream_read->cache_stream_fill_buffer->stream_fill_buffer
2、int cache_stream_fill_buffer(stream_t *s);
Function:
cache_stream_fill_buffer
Description:
从cache中读取数据或往cache中填充数据
Parameter:
s
Return:
Int 返回填充数据的长度
Remark:
1、无cache机制中,从媒体中读取STREAM_BUFFER_SIZE 数据填充到s->buffer中。
2、在cache机制中,父进程从cache中读取sector_size数据填充到s->buffer中;而子进程从媒体中读取STREAM_BUFFER_SIZE 数据填充到s->buffer中。
3、int cache_stream_seek_long(stream_t *stream,off_t pos)
Function:
cache_stream_seek_long
Description:
Seek
Parameter:
stream 流处理结构参数
pos seek的位置
Return:
Int 0:seek成功,1:seek失败
Remark:
4、int cache_do_control(stream_t *stream, int cmd, void *arg)
Function:
cache_do_control
Description:
控制处理
Parameter:
stream 流处理结构参数
cmd 控制命令类型
args 输入或输出的参数
Return:
int STREAM_UNSUPPORTED:表示不支持
1:表示成功
Remark:
4
Mplayer的cache机制作为播放文件或URL的预缓冲。对速度满的媒体特别有用。MPlayer可以通过相应的命令选项控制缓冲的大小,是否需要设置缓冲等。以下列出Mplyaer为用户提供的几个关于cache的命令选项。几个选项分别是:
-cache XXX---该选项用于指定cache的大小为XXXkbytes;
-nocache----表示关闭缓存。
-cache-min XXX----表示当缓冲填充到总数的XXX/100%时开始播放。
-cache-seek-min XXX---如果查询到的位置处于从当前位置算起的缓存大小的(百分数)之内,mplayer等待填充缓存到此位置而不是执行流查询(默认是50)。
MPlayer的cache机制的实现依赖linux系统提供的进程复制函数fork();当用于需要启用cache功能后,MPlayer会调用fork函数复制当前进程,在进程表中创建一个新的表项,执行完全相同的代码。新的进程一旦创建成功,父进程用于文件的解码的播放,子进程用于维护cache。
图1.cache简要原理图
2.Mplayer Cache Data Structure
2.1.cache_vars_t
typedef struct {
unsigned char *buffer; // 缓存的基地址
int buffer_size; // 缓存大小
int sector_size; // 缓存每段大小
int back_size; // we should keep back_size amount of old bytes for backward seek
int fill_limit; // 填充缓存的空间限制we should fill buffer only if space>=fill_limit
int seek_limit; // 缓存中可以seek最小值keep filling cache if distance is less that seek limit
// filler's pointers:
int eof; //流或文件是否结束。
off_t min_filepos; // buffer contain only a part of the file, from min-max pos
off_t max_filepos; //缓存中包含的数据在整个文件中的位置。从min-max
off_t offset; // filepos <-> bufferpos offset value (filepos of the buffer's first byte)
文件在缓存开始的位置。
// reader's pointers:
off_t read_filepos; 缓存读位置/
// commands/locking:
// int seek_lock; // 1 if we will seek/reset buffer, 2 if we are ready for cmd
// int fifo_flag; // 1 if we should use FIFO to notice cache about buffer reads.
// callback
stream_t* stream;
volatile int control;
volatile unsigned control_uint_arg;
volatile double control_double_arg;
volatile int control_res;
volatile off_t control_new_pos;
volatile double stream_time_length;
} cache_vars_t;
3.Mplayer Cache Function
1、int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit)
name:
stream_enable_cache
Description:
使能cache功能
Parameter:
stream 流处理数据参数
size 缓存的大小
min 指定预填充cache的最少数据大小
seek_limit 指定seek限制大小
Return:
Int 1 on success,
0 if the function was interrupted
-1 on error
Remark:
1)、cache_init(): 主要是分配cache_vars_t *s及cache缓冲s->buffer(cache) 内存空间,
并通过shared_alloc ()函数使父子进程共享s数据结构及cache。
2)、fork()
(1) 父进程:达到一定条件并返回
read:stream_read()->cache_stream_fill_buffer()->cache_read()
seek:
stream_seek() ->cache_stream_seek_long()->cache_stream_fill_buffer()->cache_read()
(2)子进程
read:cache_fill->stream_read->cache_stream_fill_buffer->stream_fill_buffer
2、int cache_stream_fill_buffer(stream_t *s);
Function:
cache_stream_fill_buffer
Description:
从cache中读取数据或往cache中填充数据
Parameter:
s
Return:
Int 返回填充数据的长度
Remark:
1、无cache机制中,从媒体中读取STREAM_BUFFER_SIZE 数据填充到s->buffer中。
2、在cache机制中,父进程从cache中读取sector_size数据填充到s->buffer中;而子进程从媒体中读取STREAM_BUFFER_SIZE 数据填充到s->buffer中。
3、int cache_stream_seek_long(stream_t *stream,off_t pos)
Function:
cache_stream_seek_long
Description:
Seek
Parameter:
stream 流处理结构参数
pos seek的位置
Return:
Int 0:seek成功,1:seek失败
Remark:
4、int cache_do_control(stream_t *stream, int cmd, void *arg)
Function:
cache_do_control
Description:
控制处理
Parameter:
stream 流处理结构参数
cmd 控制命令类型
args 输入或输出的参数
Return:
int STREAM_UNSUPPORTED:表示不支持
1:表示成功
Remark:
4
- MPlayer Cache机制
- mplayer with on cache
- cache机制
- cache机制
- Linux Page Cache机制
- Linux Cache 机制探究
- Openfire 的 Cache机制
- SNMP Cache机制
- Linux Cache 机制
- Cache-Control缓存机制
- [zz]Linux Cache 机制
- Linux Cache 机制探究
- ARM中的CACHE机制
- oracle sequence cache 机制
- Linux Cache 机制
- Linux Cache 机制探究
- Linux Cache 机制探究
- Linux Cache 机制
- 《30天精通iPhone手机编程》-Day9-密码生成器
- Oracle 分区表 导出导入 迁移
- How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition [ID 846405.1]
- Tomcat 又爆安全漏洞,情何以堪
- 从面试题看继承
- MPlayer Cache机制
- How to Partition a Non-partitioned Table [ID 1070693.6]
- 多线程11天--07
- How To Partition Existing Table Using DBMS_Redefinition [ID 472449.1]
- 【原】解决php ajax乱码
- 工作于内存和文件之间的页缓存, Page Cache, the Affair Between Memory and Files
- 学习Android界面设计的超级利器HierarchyView.bat
- wince makefile 入门
- 【转】linux 系统服务详解