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

📄 rmff.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 C
📖 第 1 页 / 共 2 页
字号:
      mdpr=rmff_scan_mdpr(ptr);      chunk_size=mdpr->size;      header->streams[mdpr->stream_number]=mdpr;      break;    case CONT_TAG:      header->cont=rmff_scan_cont(ptr);      chunk_size=header->cont->size;      break;    case DATA_TAG:      header->data=rmff_scan_dataheader(ptr);      chunk_size=34;     /* hard coded header size */      break;    default:      mp_msg(MSGT_STREAM, MSGL_WARN, "unknown chunk\n");      hexdump(ptr,10);      chunk_size=1;      break;    }    ptr+=chunk_size;  }	return header;}rmff_header_t *rmff_scan_header_stream(int fd) {  rmff_header_t *header;  char *buf=xbuffer_init(1024);  int index=0;  uint32_t chunk_type;  uint32_t chunk_size;  do {    buf = xbuffer_ensure_size(buf, index+8);    recv(fd, buf+index, 8, 0);    chunk_type=AV_RB32(buf+index); index+=4;    chunk_size=AV_RB32(buf+index); index+=4;    switch (chunk_type) {      case DATA_TAG:        chunk_size=18;      case MDPR_TAG:      case CONT_TAG:      case RMF_TAG:      case PROP_TAG:        buf = xbuffer_ensure_size(buf, index+chunk_size-8);        recv(fd, buf+index, (chunk_size-8), 0);	index+=(chunk_size-8);        break;      default:        mp_msg(MSGT_STREAM, MSGL_WARN, "rmff_scan_header_stream: unknown chunk");        hexdump(buf+index-8, 8);        chunk_type=DATA_TAG;    }  } while (chunk_type != DATA_TAG);  header = rmff_scan_header(buf);  xbuffer_free(buf);  return header;}void rmff_scan_pheader(rmff_pheader_t *h, char *data) {  h->object_version=AV_RB16(data);  h->length=AV_RB16(data+2);  h->stream_number=AV_RB16(data+4);  h->timestamp=AV_RB32(data+6);  h->reserved=(uint8_t)data[10];  h->flags=(uint8_t)data[11];}rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers) {  rmff_fileheader_t *fileheader=malloc(sizeof(rmff_fileheader_t));  fileheader->object_id=RMF_TAG;  fileheader->size=18;  fileheader->object_version=0;  fileheader->file_version=0;  fileheader->num_headers=num_headers;  return fileheader;}rmff_prop_t *rmff_new_prop (    uint32_t max_bit_rate,    uint32_t avg_bit_rate,    uint32_t max_packet_size,    uint32_t avg_packet_size,    uint32_t num_packets,    uint32_t duration,    uint32_t preroll,    uint32_t index_offset,    uint32_t data_offset,    uint16_t num_streams,    uint16_t flags ) {  rmff_prop_t *prop=malloc(sizeof(rmff_prop_t));  prop->object_id=PROP_TAG;  prop->size=50;  prop->object_version=0;  prop->max_bit_rate=max_bit_rate;  prop->avg_bit_rate=avg_bit_rate;  prop->max_packet_size=max_packet_size;  prop->avg_packet_size=avg_packet_size;  prop->num_packets=num_packets;  prop->duration=duration;  prop->preroll=preroll;  prop->index_offset=index_offset;  prop->data_offset=data_offset;  prop->num_streams=num_streams;  prop->flags=flags;     return prop;}rmff_mdpr_t *rmff_new_mdpr(      uint16_t   stream_number,      uint32_t   max_bit_rate,      uint32_t   avg_bit_rate,      uint32_t   max_packet_size,      uint32_t   avg_packet_size,      uint32_t   start_time,      uint32_t   preroll,      uint32_t   duration,      const char *stream_name,      const char *mime_type,      uint32_t   type_specific_len,      const char *type_specific_data ) {  rmff_mdpr_t *mdpr=malloc(sizeof(rmff_mdpr_t));    mdpr->object_id=MDPR_TAG;  mdpr->object_version=0;  mdpr->stream_number=stream_number;  mdpr->max_bit_rate=max_bit_rate;  mdpr->avg_bit_rate=avg_bit_rate;  mdpr->max_packet_size=max_packet_size;  mdpr->avg_packet_size=avg_packet_size;  mdpr->start_time=start_time;  mdpr->preroll=preroll;  mdpr->duration=duration;  mdpr->stream_name_size=0;  if (stream_name) {    mdpr->stream_name=strdup(stream_name);    mdpr->stream_name_size=strlen(stream_name);  }  mdpr->mime_type_size=0;  if (mime_type) {    mdpr->mime_type=strdup(mime_type);    mdpr->mime_type_size=strlen(mime_type);  }  mdpr->type_specific_len=type_specific_len;  mdpr->type_specific_data=malloc(type_specific_len);  memcpy(mdpr->type_specific_data,type_specific_data,type_specific_len);  mdpr->mlti_data=NULL;    mdpr->size=mdpr->stream_name_size+mdpr->mime_type_size+mdpr->type_specific_len+46;  return mdpr;}rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *copyright, const char *comment) {  rmff_cont_t *cont=malloc(sizeof(rmff_cont_t));  cont->object_id=CONT_TAG;  cont->object_version=0;  cont->title=NULL;  cont->author=NULL;  cont->copyright=NULL;  cont->comment=NULL;    cont->title_len=0;  cont->author_len=0;  cont->copyright_len=0;  cont->comment_len=0;  if (title) {    cont->title_len=strlen(title);    cont->title=strdup(title);  }  if (author) {    cont->author_len=strlen(author);    cont->author=strdup(author);  }  if (copyright) {    cont->copyright_len=strlen(copyright);    cont->copyright=strdup(copyright);  }  if (comment) {    cont->comment_len=strlen(comment);    cont->comment=strdup(comment);  }  cont->size=cont->title_len+cont->author_len+cont->copyright_len+cont->comment_len+18;  return cont;}rmff_data_t *rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header) {  rmff_data_t *data=malloc(sizeof(rmff_data_t));  data->object_id=DATA_TAG;  data->size=18;  data->object_version=0;  data->num_packets=num_packets;  data->next_data_header=next_data_header;  return data;}  void rmff_print_header(rmff_header_t *h) {  rmff_mdpr_t **stream;    if(!h) {    printf("rmff_print_header: NULL given\n");    return;  }  if(h->fileheader)  {    printf("\nFILE:\n");    printf("file version      : %d\n", h->fileheader->file_version);    printf("number of headers : %d\n", h->fileheader->num_headers);  }  if(h->cont)  {    printf("\nCONTENT:\n");    printf("title     : %s\n", h->cont->title);    printf("author    : %s\n", h->cont->author);    printf("copyright : %s\n", h->cont->copyright);    printf("comment   : %s\n", h->cont->comment);  }  if(h->prop)  {    printf("\nSTREAM PROPERTIES:\n");    printf("bit rate (max/avg)    : %i/%i\n", h->prop->max_bit_rate, h->prop->avg_bit_rate);    printf("packet size (max/avg) : %i/%i bytes\n", h->prop->max_packet_size, h->prop->avg_packet_size);    printf("packets       : %i\n", h->prop->num_packets);    printf("duration      : %i ms\n", h->prop->duration);    printf("pre-buffer    : %i ms\n", h->prop->preroll);    printf("index offset  : %i bytes\n", h->prop->index_offset);    printf("data offset   : %i bytes\n", h->prop->data_offset);    printf("media streams : %i\n", h->prop->num_streams);    printf("flags         : ");    if (h->prop->flags & PN_SAVE_ENABLED) printf("save_enabled ");    if (h->prop->flags & PN_PERFECT_PLAY_ENABLED) printf("perfect_play_enabled ");    if (h->prop->flags & PN_LIVE_BROADCAST) printf("live_broadcast ");    printf("\n");  }  stream=h->streams;  if(stream)  {    while (*stream)    {      printf("\nSTREAM %i:\n", (*stream)->stream_number);      printf("stream name [mime type] : %s [%s]\n", (*stream)->stream_name, (*stream)->mime_type);      printf("bit rate (max/avg)      : %i/%i\n", (*stream)->max_bit_rate, (*stream)->avg_bit_rate);      printf("packet size (max/avg)   : %i/%i bytes\n", (*stream)->max_packet_size, (*stream)->avg_packet_size);      printf("start time : %i\n", (*stream)->start_time);      printf("pre-buffer : %i ms\n", (*stream)->preroll);      printf("duration   : %i ms\n", (*stream)->duration);      printf("type specific data:\n");      hexdump((*stream)->type_specific_data, (*stream)->type_specific_len);      stream++;    }  }  if(h->data)  {    printf("\nDATA:\n");    printf("size      : %i\n", h->data->size);    printf("packets   : %i\n", h->data->num_packets);    printf("next DATA : 0x%08x\n", h->data->next_data_header);  } }void rmff_fix_header(rmff_header_t *h) {  int num_headers=0;  int header_size=0;  rmff_mdpr_t **streams;  int num_streams=0;  if (!h) {    mp_msg(MSGT_STREAM, MSGL_ERR, "rmff_fix_header: fatal: no header given.\n");    return;  }  if (!h->streams) {    mp_msg(MSGT_STREAM, MSGL_WARN, "rmff_fix_header: warning: no MDPR chunks\n");  } else  {    streams=h->streams;    while (*streams)    {      num_streams++;      num_headers++;      header_size+=(*streams)->size;      streams++;    }  }    if (h->prop) {    if (h->prop->size != 50)    {#ifdef LOG      printf("rmff_fix_header: correcting prop.size from %i to %i\n", h->prop->size, 50);#endif      h->prop->size=50;    }    if (h->prop->num_streams != num_streams)    {#ifdef LOG      printf("rmff_fix_header: correcting prop.num_streams from %i to %i\n", h->prop->num_streams, num_streams);#endif      h->prop->num_streams=num_streams;    }    num_headers++;    header_size+=50;  } else    mp_msg(MSGT_STREAM, MSGL_WARN, "rmff_fix_header: warning: no PROP chunk.\n");  if (h->cont) {    num_headers++;    header_size+=h->cont->size;  } else    mp_msg(MSGT_STREAM, MSGL_WARN, "rmff_fix_header: warning: no CONT chunk.\n");  if (!h->data) {#ifdef LOG    printf("rmff_fix_header: no DATA chunk, creating one\n");#endif    h->data=malloc(sizeof(rmff_data_t));    h->data->object_id=DATA_TAG;    h->data->object_version=0;    h->data->size=34;    h->data->num_packets=0;    h->data->next_data_header=0;  }  num_headers++;    if (!h->fileheader) {#ifdef LOG    printf("rmff_fix_header: no fileheader, creating one");#endif    h->fileheader=malloc(sizeof(rmff_fileheader_t));    h->fileheader->object_id=RMF_TAG;    h->fileheader->size=34;    h->fileheader->object_version=0;    h->fileheader->file_version=0;    h->fileheader->num_headers=num_headers+1;  }  header_size+=h->fileheader->size;  num_headers++;  if(h->fileheader->num_headers != num_headers) {#ifdef LOG    printf("rmff_fix_header: setting num_headers from %i to %i\n", h->fileheader->num_headers, num_headers); #endif    h->fileheader->num_headers=num_headers;  }  if(h->prop) {    if (h->prop->data_offset != header_size) {#ifdef LOG      printf("rmff_fix_header: setting prop.data_offset from %i to %i\n", h->prop->data_offset, header_size); #endif      h->prop->data_offset=header_size;    }    if (h->prop->num_packets == 0) {      int p=(int)(h->prop->avg_bit_rate/8.0*(h->prop->duration/1000.0)/h->prop->avg_packet_size);#ifdef LOG      printf("rmff_fix_header: assuming prop.num_packets=%i\n", p); #endif      h->prop->num_packets=p;    }    if (h->data->num_packets == 0) {#ifdef LOG      printf("rmff_fix_header: assuming data.num_packets=%i\n", h->prop->num_packets); #endif      h->data->num_packets=h->prop->num_packets;    }    #ifdef LOG    printf("rmff_fix_header: assuming data.size=%i\n", h->prop->num_packets*h->prop->avg_packet_size); #endif    h->data->size=h->prop->num_packets*h->prop->avg_packet_size;  }}int rmff_get_header_size(rmff_header_t *h) {  if (!h) return 0;  if (!h->prop) return -1;  return h->prop->data_offset+18;  }void rmff_free_header(rmff_header_t *h) {  if (!h) return;  if (h->fileheader) free(h->fileheader);  if (h->prop) free(h->prop);  if (h->data) free(h->data);  if (h->cont)  {    free(h->cont->title);    free(h->cont->author);    free(h->cont->copyright);    free(h->cont->comment);    free(h->cont);  }  if (h->streams)  {    rmff_mdpr_t **s=h->streams;    while(*s) {      free((*s)->stream_name);      free((*s)->mime_type);      free((*s)->type_specific_data);      free(*s);      s++;    }    free(h->streams);  }  free(h);}

⌨️ 快捷键说明

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