MediaInfo源代码分析 4:Inform()函数
我们来看一下MediaInfo中的Inform()函数的内部调用过程
首先Inform()函数封装了MediaInfo_Internal类中的Inform()函数
//返回文件信息
String MediaInfo::Inform(size_t)
{
//封装了一层
return Internal->Inform();
}
查看一下MediaInfo_Internal类中的Inform()函数的源代码:
// 获取信息
Ztring MediaInfo_Internal::Inform()
{
CS.Enter();
if (Info && Info->Status[File__Analyze::IsUpdated])
Info->Open_Buffer_Update();
CS.Leave(); if (MediaInfoLib::Config.Inform_Get()==__T("MPEG-7"))
return Export_Mpeg7().Transform(*this);
if (MediaInfoLib::Config.Inform_Get()==__T("PBCore") || MediaInfoLib::Config.Inform_Get()==__T("PBCore_1.2"))
return Export_PBCore().Transform(*this);
if (MediaInfoLib::Config.Inform_Get()==__T("reVTMD"))
return __T("reVTMD is disabled due to its non-free licensing."); //return Export_reVTMD().Transform(*this);
//获取相应的信息
if (!(
MediaInfoLib::Config.Inform_Get(__T("General")).empty()
&& MediaInfoLib::Config.Inform_Get(__T("Video")).empty()
&& MediaInfoLib::Config.Inform_Get(__T("Audio")).empty()
&& MediaInfoLib::Config.Inform_Get(__T("Text")).empty()
&& MediaInfoLib::Config.Inform_Get(__T("Chapters")).empty()
&& MediaInfoLib::Config.Inform_Get(__T("Image")).empty()
&& MediaInfoLib::Config.Inform_Get(__T("Menu")).empty()
))
{
//获取各种信息
//Retour即为返回的字符串
Ztring Retour;
Retour+=MediaInfoLib::Config.Inform_Get(__T("File_Begin"));
Retour+=MediaInfoLib::Config.Inform_Get(__T("General_Begin"));
Retour+=Inform(Stream_General, 0, false);
Retour+=MediaInfoLib::Config.Inform_Get(__T("General_End"));
if (Count_Get(Stream_Video))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Video_Begin"));
for (size_t I1=0; I1<Count_Get(Stream_Video); I1++)
{
Retour+=Inform(Stream_Video, I1, false);
if (I1!=Count_Get(Stream_Video)-1)
Retour+=MediaInfoLib::Config.Inform_Get(__T("Video_Middle"));
}
if (Count_Get(Stream_Video))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Video_End"));
if (Count_Get(Stream_Audio))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Audio_Begin"));
for (size_t I1=0; I1<Count_Get(Stream_Audio); I1++)
{
Retour+=Inform(Stream_Audio, I1, false);
if (I1!=Count_Get(Stream_Audio)-1)
Retour+=MediaInfoLib::Config.Inform_Get(__T("Audio_Middle"));
}
if (Count_Get(Stream_Audio))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Audio_End"));
if (Count_Get(Stream_Text))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Text_Begin"));
for (size_t I1=0; I1<Count_Get(Stream_Text); I1++)
{
Retour+=Inform(Stream_Text, I1, false);
if (I1!=Count_Get(Stream_Text)-1)
Retour+=MediaInfoLib::Config.Inform_Get(__T("Text_Middle"));
}
if (Count_Get(Stream_Text))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Text_End"));
if (Count_Get(Stream_Other))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Chapters_Begin"));
for (size_t I1=0; I1<Count_Get(Stream_Other); I1++)
{
Retour+=Inform(Stream_Other, I1, false);
if (I1!=Count_Get(Stream_Other)-1)
Retour+=MediaInfoLib::Config.Inform_Get(__T("Chapters_Middle"));
}
if (Count_Get(Stream_Other))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Chapters_End"));
if (Count_Get(Stream_Image))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Image_Begin"));
for (size_t I1=0; I1<Count_Get(Stream_Image); I1++)
{
Retour+=Inform(Stream_Image, I1, false);
if (I1!=Count_Get(Stream_Image)-1)
Retour+=MediaInfoLib::Config.Inform_Get(__T("Image_Middle"));
}
if (Count_Get(Stream_Image))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Image_End"));
if (Count_Get(Stream_Menu))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Menu_Begin"));
for (size_t I1=0; I1<Count_Get(Stream_Menu); I1++)
{
Retour+=Inform(Stream_Menu, I1, false);
if (I1!=Count_Get(Stream_Menu)-1)
Retour+=MediaInfoLib::Config.Inform_Get(__T("Menu_Middle"));
}
if (Count_Get(Stream_Menu))
Retour+=MediaInfoLib::Config.Inform_Get(__T("Menu_End"));
Retour+=MediaInfoLib::Config.Inform_Get(__T("File_End"));
//可以在此加入视频质量检测----------------------------------------- //字符串替换?各种换行符统统改为“\n”-----------------------------
Retour.FindAndReplace(__T("\\r\\n"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\\r"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\\n"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\n"), MediaInfoLib::Config.LineSeparator_Get(), 0, Ztring_Recursive); //Special characters
Retour.FindAndReplace(__T("|SC1|"), __T("\\"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC2|"), __T("["), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC3|"), __T("]"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC4|"), __T(","), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC5|"), __T(";"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC6|"), __T("("), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC7|"), __T(")"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC8|"), __T(")"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC9|"), __T("),"), 0, Ztring_Recursive); return Retour;
} //Informations
Ztring Retour;
bool HTML=false;
bool XML=false;
bool CSV=false;
//获取配置信息(输出格式)
if (MediaInfoLib::Config.Inform_Get()==__T("HTML"))
HTML=true;
if (MediaInfoLib::Config.Inform_Get()==__T("XML"))
XML=true;
if (MediaInfoLib::Config.Inform_Get()==__T("CSV"))
CSV=true; if (HTML) Retour+=__T("<html>\n\n<head>\n<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head>\n<body>\n");
if (XML) Retour+=__T("<File>\n"); for (size_t StreamKind=(size_t)Stream_General; StreamKind<Stream_Max; StreamKind++)
{
//Pour chaque type de flux
for (size_t StreamPos=0; StreamPos<(size_t)Count_Get((stream_t)StreamKind); StreamPos++)
{
//Pour chaque stream
//输出为HTML
if (HTML) Retour+=__T("<table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"2\" style=\"border:1px solid Navy\">\n<tr>\n <td width=\"150\"><h2>");
//输出为XML
if (XML) Retour+=__T("<track type=\"");
Ztring A=Get((stream_t)StreamKind, StreamPos, __T("StreamKind/String"));
Ztring B=Get((stream_t)StreamKind, StreamPos, __T("StreamKindPos"));
if (!XML && !B.empty())
{
if (CSV)
A+=__T(",");
else
A+=MediaInfoLib::Config.Language_Get(__T(" Config_Text_NumberTag"));
A+=B;
}
Retour+=A;
if (XML)
{
Retour+=__T("\"");
if (!B.empty())
{
Retour+=__T(" streamid=\"");
Retour+=B;
Retour+=__T("\"");
}
}
//输出为HTML
if (HTML) Retour+=__T("</h2></td>\n </tr>");
//输出为XML
if (XML) Retour+=__T(">");
Retour+=MediaInfoLib::Config.LineSeparator_Get();
Retour+=Inform((stream_t)StreamKind, StreamPos, false);
Retour.FindAndReplace(__T("\\"), __T("|SC1|"), 0, Ztring_Recursive);
if (HTML) Retour+=__T("</table>\n<br />");
if (XML) Retour+=__T("</track>\n");
Retour+=MediaInfoLib::Config.LineSeparator_Get();
}
}
//输出为HTML
if (HTML) Retour+=__T("\n</body>\n</html>\n");
//输出为XML
if (XML) Retour+=__T("</File>\n");
//字符串替换?
Retour.FindAndReplace(__T("\\r\\n"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\\r"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\\n"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("\n"), MediaInfoLib::Config.LineSeparator_Get(), 0, Ztring_Recursive); //Special characters
Retour.FindAndReplace(__T("|SC1|"), __T("\\"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC2|"), __T("["), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC3|"), __T("]"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC4|"), __T(","), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC5|"), __T(";"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC6|"), __T("("), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC7|"), __T(")"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC8|"), __T(")"), 0, Ztring_Recursive);
Retour.FindAndReplace(__T("|SC9|"), __T("),"), 0, Ztring_Recursive);
return Retour;
}
函数比较复杂,从代码中我们可以看出,Inform()的实质还是使用Get()一个一个取出所有的属性值。
当指定输出为XML或者是HTML的时候,在输出的字符串上加上相应的标签(例如,输出为HTML的时候,字符串每一行上加上“</tr><tr>”,首尾加上“<table></table>”)
具体每一块代码的含义已经写在注释中了。
MediaInfo源代码分析 4:Inform()函数的更多相关文章
- MediaInfo源代码分析 2:API函数
本文主要分析MediaInfo的API函数.它的API函数位于MediaInfo.h文件中的一个叫做MediaInfo的类中. 该类如下所示,部分重要的方法已经加上了注释: //MediaInfo类 ...
- MediaInfo源代码分析 3:Open()函数
我们来看一下MediaInfo中的Open()函数的内部调用过程 首先open函数封装了MediaInfo_Internal类中的open()函数 //打开文件 size_t MediaInfo::O ...
- MediaInfo源代码分析 1:整体结构
MediaInfo 用来分析视频和音频文件的编码和内容信息,是一款是自由软件 (免费使用.免费获得源代码).之前编程的时候,都是直接调用它提供的Dll,这次突然来了兴趣,想研究一下它内部究竟是怎么实现 ...
- 1.2. chromium源代码分析 - chromiumframe - 入口函数
ChromiumFrame的入口函数在main.cpp中,打开main.cpp.中包含3个类和_tWinMain函数._tWinMain就是我们要找的入口函数.我做了部分注释: int APIENTR ...
- javascript 引擎Rhino源代码分析 浅析 实例函数对象及this
http://blog.csdn.net/liantian_wu/article/details/49797481
- Media Player Classic - HC 源代码分析 6:MediaInfo选项卡 (CPPageFileMediaInfo)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
- Media Player Classic - HC 源代码分析 7:详细信息选项卡(CPPageFileInfoDetails)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
- Media Player Classic - HC 源代码分析 5:关于对话框 (CAboutDlg)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
- Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
随机推荐
- MYSQL 错误 :Out of resources when opening file './datagather/mx_domain#P#p178.MYD' (Errcode: 24) 解决办法
出现Out of resources when opening file './xxx.MYD' (Errcode: 24)错误是因为打开的文件数超过了my.cnf的--open-files-limi ...
- JS实现继承多态
//类对象构造模版,无new访问,类似静态访问 var Class = { create: function () { return function () { //initialize初始化 //a ...
- Python学习笔记(一)Python安装及环境变量的配置
1.下载python安装包. 下载地址:https://www.python.org/ 2.配置环境变量 找到python的安装路径.C:\Python27;script的路径:C:\Python27 ...
- VC下Debug和Release区别
整理日: 2015年3月23日 最近写代码过程中,发现 Debug 下运行正常,Release 下就会出现问题,百思不得其解,而Release 下又无法进行调试,于是只能采用printf方式逐步定位到 ...
- oracle技巧-持续更新
1. 登录oracle数据库,执行select status from v$encryption_wallet,如果返回OPEN,表示钱夹已自动打开. 2.
- Two-phase Termination模式
停止线程是一个目标简单而实现却不那么简单的任务.首先,Java没有提供直接的API用于停止线程.此外,停止线程时还有一些额外的细节需要考虑,如待停止的线程处于阻塞(等待锁)或者等待状态(等待其它线程) ...
- Jqgrid动态拖拽
//注册事件 jQuery("#list1").jqGrid('setGridParam', { gridComplete : function() { $("#_emp ...
- 2.5.3 使用alertDialog创建自定义对话框
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- java学习面向对象之异常之一
一.异常的概述: 什么是异常?在我们编写java程序的时候,会出现一些问题,比如内存溢出啊或者数组索引超出最大索引啊,这些编程当中出现的这些个问题就是异常.但是异常也分为可以处理的和不可以处理的.比如 ...
- 【转】vc中使用SendMessage正确发送自定义消息的方法--不错
原文网址:http://zhoumf1214.blog.163.com/blog/static/5241940200910265532959/ 最近在用VC2008做开发,后来由于要用到消息的发送,而 ...