📄 wma文件信息格式分析及代码 - mokemars的专栏 - csdnblog.htm
字号:
1;<BR>}<BR>enum metadata_s<BR>{<BR> /* common info
*/<BR> META_INFO_TITLE=0,<BR>
META_INFO_AUTHOR,<BR>
META_INFO_COPYRIGHT,<BR>
META_INFO_COMMENT,<BR>
META_INFO_WMFSDKVERSION,<BR>
META_INFO_WMFSDKNEEDED,<BR>
META_INFO_ISVBR,<BR>
META_INFO_WMPROMOTIONURL,<BR>
META_INFO_WMGENREID,<BR>
META_INFO_WMTRACK,<BR>
META_INFO_WMTRACENUMBER,<BR>
META_INFO_WMYEAR,<BR>
META_INFO_WMENCODINGTIME,<BR>
META_INFO_WMGENRE,<BR>
META_INFO_WMALBUMTITLE,<BR>
META_INFO_PEAKVALE,<BR>
META_INFO_AVERAGELEVEL<BR>};<BR>typedef enum metadata_s metadata_t;<BR>static
char *get_asf_info (struct asf_tags* tags,char *tag)<BR>{<BR>
char **info = tags->ext_info;<BR> int
n;<BR> if (!info || !tag)<BR>
return NULL;<BR> for (n = 0; info[2*n] !=
NULL ; n++)<BR> {<BR> if
(!strcmp (info[2*n], tag))<BR>
break;<BR> }<BR> return
info[2*n+1] ? strdup (info[2*n+1]) : NULL;<BR>}<BR>char *get_metadata (struct
asf_tags* tags,metadata_t type)<BR>{<BR> switch
(type)<BR> {<BR> case
META_INFO_TITLE:<BR>
{<BR> return
tags->title;<BR> }<BR>
case META_INFO_AUTHOR:<BR>
{<BR>
return tags->author;<BR>
}<BR> case
META_INFO_COPYRIGHT:<BR>
{<BR> return
tags->copyright;<BR>
}<BR> case
META_INFO_COMMENT:<BR>
{<BR> return
tags->comment;<BR>
}<BR> case
META_INFO_WMFSDKVERSION:<BR>
{<BR> return
get_asf_info(tags,"WMFSDKVersion");<BR>
}<BR> case
META_INFO_WMFSDKNEEDED:<BR>
{<BR> return
get_asf_info(tags,"WMFSDKNeeded");<BR>
}<BR> case
META_INFO_ISVBR:<BR>
{<BR> return
get_asf_info(tags,"IsVBR");<BR>
}<BR> case
META_INFO_WMPROMOTIONURL:<BR>
{<BR> return
get_asf_info(tags,"WM/PromotionURL");<BR>
}<BR> case
META_INFO_WMGENREID:<BR>
{<BR> return
get_asf_info(tags,"WM/GenreID");<BR>
}<BR> case
META_INFO_WMTRACK:<BR>
{<BR>
return get_asf_info(tags,"WM/Track");<BR>
}<BR> case
META_INFO_WMTRACENUMBER:<BR>
{<BR>
return get_asf_info(tags,"WM/TrackNumber");<BR>
}<BR> case
META_INFO_WMYEAR:<BR>
{<BR> return
get_asf_info(tags,"WM/Year");<BR>
}<BR> case
META_INFO_WMENCODINGTIME:<BR>
{<BR> return
get_asf_info(tags,"WM/EncodingTime");<BR>
}<BR> case
META_INFO_WMGENRE:<BR>
{<BR> return
get_asf_info(tags,"WM/Genre");<BR>
}<BR> case
META_INFO_WMALBUMTITLE:<BR>
{<BR> return
get_asf_info(tags,"WM/AlbumTitle");<BR>
}<BR> case
META_INFO_PEAKVALE:<BR>
{<BR> return
get_asf_info(tags,"PeakValue");<BR>
}<BR> case
META_INFO_AVERAGELEVEL:<BR>
{<BR> return
get_asf_info(tags,"AverageLevel");<BR>
}<BR> }<BR>}<BR>int read_asf_header(char
*filename,struct asf_tags* tags)<BR>{<BR> int
hdr_len;<BR> char *hdr = NULL;<BR> int
pos;<BR> int fd;<BR> char
buffer[16];<BR> struct stat sb;<BR>
fd=open(filename,O_RDONLY);<BR>
if(fd==-1)<BR> {<BR>
printf("open file error\n");<BR> return
0;<BR> }<BR>
memset(buffer,0,16);<BR> fstat(fd,&sb);
/*取得文件大小*/<BR>
hdr=mmap(NULL,sb.st_size,PROT_READ,MAP_PRIVATE,fd,0);<BR>
if(hdr== MAP_FAILED) /*判断是否映射成功*/<BR> {<BR>
return 0;<BR>
close(fd);<BR> }<BR>
strncpy(buffer,hdr,16);<BR>
if(strcmp(buffer,asf_file_format_guid))/*根据ASF标志信息判断是否为ASF文件*/<BR>
{<BR> printf("file not an asf
file\n");<BR>
close(fd);<BR>
munmap(hdr,sb.st_size);<BR> return
0;<BR> }<BR>
hdr_len=sb.st_size;<BR> pos = find_asf_guid(hdr,
asf_content_desc_guid, 0, hdr_len);/*找到标志信息位置*/<BR> if (pos
>= 0)<BR> {<BR>
ASF_content_description_t *contenth = (ASF_content_description_t
*)&hdr[pos];<BR> unsigned char
*string=NULL;<BR> uint16_t* wstring =
NULL;<BR> uint16_t
len;<BR> pos +=
sizeof(ASF_content_description_t);<BR> if
(pos > hdr_len) goto len_err_out;<BR>
//le2me_ASF_content_description_t(contenth);<BR>
// extract the title<BR>
if((len = contenth->title_size) != 0)<BR>
{<BR>
wstring = (uint16_t*)&hdr[pos];<BR>
pos += len;<BR>
if (pos > hdr_len) goto len_err_out;<BR>
if ((string = get_ucs2str(wstring,
len)))/*J解析成UTF8*/<BR>
{<BR>
strcpy(tags->title,
string);<BR>
free(string);<BR>
}<BR>
}<BR> // extract the author
<BR> if((len = contenth->author_size) !=
0) <BR> {<BR>
wstring =
(uint16_t*)&hdr[pos];<BR>
pos += len;<BR>
if (pos > hdr_len) goto len_err_out;<BR>
if ((string = get_ucs2str(wstring,
len)))<BR>
{<BR>
strcpy(tags->author, string);<BR>
free(string);<BR>
}<BR>
}<BR> if((len =
contenth->copyright_size) != 0)<BR>
{<BR> wstring =
(uint16_t*)&hdr[pos];<BR>
pos += len;<BR>
if (pos > hdr_len) goto len_err_out;<BR>
if ((string = get_ucs2str(wstring,
len)))<BR>
{<BR>
strcpy(tags->copyright, string);<BR>
free(string);<BR>
}<BR>
}<BR> // extract the
comment<BR> if((len =
contenth->comment_size) != 0)<BR>
{<BR> wstring =
(uint16_t*)&hdr[pos];<BR>
pos += len;<BR>
if (pos > hdr_len) goto len_err_out;<BR>
if ((string = get_ucs2str(wstring,
len)))<BR>
{<BR>
strcpy(tags->comment, string);<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -