⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stream.h.svn-base

📁 sigmadesign smp8623 gui source code ,bingo
💻 SVN-BASE
字号:
#ifndef __STREAM_H#define __STREAM_H//#include "mp_msg.h"#include <string.h>//#include <inttypes.h>//#include <sys/types.h>#include "rmdef/rmdef.h"#include "rmcore/include/rmascii.h"RM_EXTERN_C_BLOCKSTART#define STREAMTYPE_DUMMY -1    // for placeholders, when the actual reading is handled in the demuxer#define STREAMTYPE_FILE 0      // read from seekable file#define STREAMTYPE_STREAM 2    // same as FILE but no seeking (for net/stdin)#define STREAM_BUFFER_SIZE 2048/// atm it will always use mode == STREAM_READ/// streams that use the new api should check the mode at open#define STREAM_READ  0#define STREAM_WRITE 1/// Seek flags, if not mannualy set and s->seek isn't NULL/// STREAM_SEEK is automaticly set#define STREAM_SEEK_BW  2#define STREAM_SEEK_FW  4#define STREAM_SEEK  (STREAM_SEEK_BW|STREAM_SEEK_FW)//////////// Open return code/// This can't open the requested protocol (used by stream wich have a/// * protocol when they don't know the requested protocol)#define STREAM_UNSUPORTED -1#define STREAM_ERROR 0#define STREAM_OK    1#define MAX_STREAM_PROTOCOLS 5#define STREAM_CTRL_RESET 0#define STREAM_CTRL_GET_TIME_LENGTH 1#define STREAM_CTRL_SEEK_TO_CHAPTER 2#define STREAM_CTRL_GET_CURRENT_CHAPTER 3#define STREAM_CTRL_GET_NUM_CHAPTERS 4struct stream_st;typedef struct stream_info_st {  const RMascii *info;  const RMascii *name;  const RMascii *author;  const RMascii *comment;  /// mode isn't used atm (ie always READ) but it shouldn't be ignored  /// opts is at least in it's defaults settings and may have been  /// altered by url parsing if enabled and the options string parsing.  RMint32 (*open)(struct stream_st* st, RMint32 mode, void* opts, RMint32* file_format);  RMascii* protocols[MAX_STREAM_PROTOCOLS];//  void* opts;//  RMint32 opts_url; /* If this is 1 we will parse the url as an option string//		 * too. Otherwise options are only parsed from the//		 * options string given to open_stream_plugin */} stream_info_t;typedef struct stream_st {  // Read  RMint32 (*fill_buffer)(struct stream_st *s, RMascii* buffer, RMint32 max_len);  // Write  RMint32 (*write_buffer)(struct stream_st *s, RMascii* buffer, RMint32 len);  // Seek  RMint32 (*seek)(struct stream_st *s,off_t pos);  // Control  // Will be later used to let streams like dvd and cdda report  // their structure (ie tracks, chapters, etc)  RMint32 (*control)(struct stream_st *s,RMint32 cmd,void* arg);  // Close  void (*close)(struct stream_st *s);  RMint32 fd;   // file descriptor, see man open(2)  RMint32 type; // see STREAMTYPE_*  RMint32 flags;  RMint32 sector_size; // sector size (seek will be aligned on this size if non 0)  RMuint32 buf_pos,buf_len;  off_t pos,start_pos,end_pos;  RMint32 eof;  void* cache_data;  void* priv; // used for DVD, TV, RTSP etc  RMascii* url;  // strdup() of filename/url  RMuint8 buffer[STREAM_BUFFER_SIZE];} stream_t;RMint32 stream_seek_long(stream_t *s,off_t pos);RMint32 stream_fill_buffer(stream_t *s);// no cache, define wrappers:#define cache_stream_fill_buffer(x) stream_fill_buffer(x)#define cache_stream_seek_long(x,y) stream_seek_long(x,y)#define stream_enable_cache(x,y,z,w) 1void fixup_network_stream_cache(stream_t *stream);inline static RMint32 stream_read_char(stream_t *s){  return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]:    (cache_stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256);//  if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];//  stream_fill_buffer(s);//  if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];//  return 0; // EOF}inline static RMuint32 stream_read_word(stream_t *s){  RMint32 x,y;  x=stream_read_char(s);  y=stream_read_char(s);  return (x<<8)|y;}inline static RMuint32 stream_read_dword(stream_t *s){  RMuint32 y;  y=stream_read_char(s);  y=(y<<8)|stream_read_char(s);  y=(y<<8)|stream_read_char(s);  y=(y<<8)|stream_read_char(s);  return y;}#define stream_read_fourcc stream_read_dword_leinline static RMuint32 stream_read_word_le(stream_t *s){  RMint32 x,y;  x=stream_read_char(s);  y=stream_read_char(s);  return (y<<8)|x;}inline static RMuint32 stream_read_dword_le(stream_t *s){  RMuint32 y;  y=stream_read_char(s);  y|=stream_read_char(s)<<8;  y|=stream_read_char(s)<<16;  y|=stream_read_char(s)<<24;  return y;}//inline static uint64_t stream_read_qword(stream_t *s){//  uint64_t y;//  y = stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  y=(y<<8)|stream_read_char(s);//  return y;//}//inline static uint64_t stream_read_qword_le(stream_t *s){//  uint64_t y;//  y = stream_read_char(s);//  y|=stream_read_char(s)<<8;//  y|=stream_read_char(s)<<16;//  y|=stream_read_char(s)<<24;//  y|=(uint64_t)stream_read_char(s)<<32;//  y|=(uint64_t)stream_read_char(s)<<40;//  y|=(uint64_t)stream_read_char(s)<<48;//  y|=(uint64_t)stream_read_char(s)<<56;//  return y;//}inline static RMuint32 stream_read_int24(stream_t *s){  RMuint32 y;  y = stream_read_char(s);  y=(y<<8)|stream_read_char(s);  y=(y<<8)|stream_read_char(s);  return y;}inline static RMint32 stream_read(stream_t *s,RMascii* mem,RMint32 total){  RMint32 len=total;  while(len>0){    RMint32 x;    x=s->buf_len-s->buf_pos;    if(x==0){      if(!cache_stream_fill_buffer(s)) return total-len; // EOF      x=s->buf_len-s->buf_pos;    } //   if(s->buf_pos>s->buf_len) mp_msg(MSGT_DEMUX, MSGL_WARN, "stream_read: WARNING! s->buf_pos>s->buf_len\n");    if(x>len) x=len;    memcpy(mem,&s->buffer[s->buf_pos],x);    s->buf_pos+=x; mem+=x; len-=x;  }  return total;}inline static RMuint8* stream_read_line(stream_t *s,RMuint8* mem, RMint32 max) {  RMint32 len;  RMuint8* end,*ptr = mem; // for(j = 0; j < STREAM_BUFFER_SIZE; j++) // 	printf("%d, read_line: %X\n", (RMint16)j, s->buffer[j]);  do {    len = s->buf_len-s->buf_pos;    // try to fill the buffer    if(len <= 0 &&       (!cache_stream_fill_buffer(s) ||        (len = s->buf_len-s->buf_pos) <= 0)) break;  //  RMFindAsciiCharacter(s->buffer+s->buf_pos, '\n', (RMascii**)&end);    end = (RMuint8*) memchr((void*)(s->buffer+s->buf_pos),'\n',len);    if(end) len = end - (s->buffer+s->buf_pos) + 1;    if(len > 0 && max > 1) {      int l = len > max-1 ? max-1 : len;      RMMemcpy(ptr,s->buffer+s->buf_pos,l);      max -= l;      ptr += l;    }    s->buf_pos += len;  } while(!end);  if(s->eof && ptr == mem) return NULL;  if(max > 0) ptr[0] = 0;  return mem;}inline static RMint32 stream_eof(stream_t *s){  return s->eof;}inline static off_t stream_tell(stream_t *s){  return s->pos+s->buf_pos-s->buf_len;}inline static RMint32 stream_seek(stream_t *s,off_t pos){ // mp_dbg(MSGT_DEMUX, MSGL_DBG3, "seek to 0x%qX\n",(long long)pos);  if(pos<s->pos){    off_t x=pos-(s->pos-s->buf_len);    if(x>=0){      s->buf_pos=x;//      putchar('*');fflush(stdout);      return 1;    }  }  return cache_stream_seek_long(s,pos);}inline static RMint32 stream_skip(stream_t *s,off_t len){  if( (len<0 && (s->flags & STREAM_SEEK_BW)) || (len>2*STREAM_BUFFER_SIZE && (s->flags & STREAM_SEEK_FW)) ) {    // negative or big skip!    return stream_seek(s,stream_tell(s)+len);  }  while(len>0){    RMint32 x=s->buf_len-s->buf_pos;    if(x==0){      if(!cache_stream_fill_buffer(s)) return 0; // EOF      x=s->buf_len-s->buf_pos;    }    if(x>len) x=len;    //memcpy(mem,&s->buf[s->buf_pos],x);    s->buf_pos+=x; len-=x;  }  return 1;}void stream_reset(stream_t *s);RMint32 stream_control(stream_t *s, RMint32 cmd, void *arg);stream_t* new_stream(RMint32 fd,RMint32 type);void free_stream(stream_t *s);//stream_t* new_memory_stream(RMuint8* data,RMint32 len);stream_t* open_stream_gfx(RMascii* filename,RMascii** options,RMint32* file_format);stream_t* open_stream_full(RMascii* filename,RMint32 mode, RMascii** options, RMint32* file_format);RM_EXTERN_C_BLOCKEND#endif // __STREAM_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -