=====================================================

Media Player Classic - HC 源代码分析系列文章列表:

Media Player Classic - HC 源代码分析 1:整体结构

Media Player Classic - HC 源代码分析 2:核心类 (CMainFrame)(1)

Media Player Classic - HC 源代码分析 3:核心类 (CMainFrame)(2)

Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)

Media Player Classic - HC 源代码分析 5:关于对话框 (CAboutDlg)

Media Player Classic - HC 源代码分析 6:MediaInfo选项卡 (CPPageFileMediaInfo)

Media Player Classic - HC 源代码分析 7:详细信息选项卡(CPPageFileInfoDetails)

=====================================================

前几篇文章分析了Media Player Classic - HC(mpc-hc)的核心类(CMainFrame):

Media Player Classic - HC 源代码分析 2:核心类 (CMainFrame)(1)

Media Player Classic - HC 源代码分析 3:核心类 (CMainFrame)(2)

Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)

核心类分析完之后,分析了一下CAboutDlg:

Media Player Classic - HC 源代码分析 5:关于对话框 (CAboutDlg)

发现CAboutDlg和普通的MFC对话框类其实没有什么区别。CAboutDlg功能相对比较简单,本文将会分析一个功能相对比较复杂的类:MediaInfo选项卡。在播放视频的时候,右键点击视频->选择“属性”->MediaInfo就可以查看该选项卡。一般情况下,该选项卡给出了正在播放的视频文件的详细参数(确实是非常的详细),包括:封装格式,视频编码,音频编码等等。是获取视频详细参数的最佳途径。

该选项卡的功能实际上是调用了开源项目MediaInfo的库。MediaInfo之前已经进行过详细介绍:

C++中使用MediaInfo库获取视频信息

MediaInfo使用简介(新版本支持HEVC)

在此不再重复。先看看该选项卡长什么样子。

先来看看MediaInfo选项卡类的定义是什么样的吧。该类的定义位于PPageFileMediaInfo.h文件中。

/* 雷霄骅 * 中国传媒大学/数字电视技术 * leixiaohua1020@126.com * */
/** (C) 2009-2013 see Authors.txt** This file is part of MPC-HC.** MPC-HC is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 3 of the License, or* (at your option) any later version.** MPC-HC is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program.  If not, see <http://www.gnu.org/licenses/>.**/#pragma once// CPPageFileMediaInfo dialog
// 【属性】页面里面的【MediaInfo】
class CPPageFileMediaInfo : public CPropertyPage
{DECLARE_DYNAMIC(CPPageFileMediaInfo)private:CComPtr<IFilterGraph> m_pFG;
public://构造函数都是两个参数CPPageFileMediaInfo(CString fn, IFilterGraph* pFG);virtual ~CPPageFileMediaInfo();// Dialog Dataenum { IDD = IDD_FILEMEDIAINFO };//显示信息的控件CEdit m_mediainfo;CString m_fn;CFont* m_pCFont;//信息CString MI_Text;#if !USE_STATIC_MEDIAINFOstatic bool HasMediaInfo();
#endif
protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//初始化,加载MediaInfo库,读取文件信息virtual BOOL OnInitDialog();DECLARE_MESSAGE_MAP()public://显示窗口,并不做其他事情afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
};

该类和普通的MFC对话框类差别也不大。需要注意的有以下几点:

1.有一个变量:CComPtr<IFilterGraph> m_pFG,这个是mpc-hc中的变量,先不分析该变量的全部代码,在这里仅说一下它的作用:获取正在播放的视频文件的路径。

2.有一个控件类:CEdit m_mediainfo,对应界面上那个大框框,用于显示信息。

3.有一个字符串变量:CString MI_Text,用于存储MediaInfo得到的媒体信息。

下面来看看具体类的实现,该类的实现位于PPageFileMediaInfo.cpp文件中。

/* 雷霄骅 * 中国传媒大学/数字电视技术 * leixiaohua1020@126.com * */
/** (C) 2009-2013 see Authors.txt** This file is part of MPC-HC.** MPC-HC is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 3 of the License, or* (at your option) any later version.** MPC-HC is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program.  If not, see <http://www.gnu.org/licenses/>.**/// PPageFileMediaInfo.cpp : implementation file#include "stdafx.h"
#include "mplayerc.h"
#include "PPageFileMediaInfo.h"
#include "WinAPIUtils.h"#if USE_STATIC_MEDIAINFO
#include "MediaInfo/MediaInfo.h"
using namespace MediaInfoLib;
#else
#include "MediaInfoDLL.h"
using namespace MediaInfoDLL;
#endif// CPPageFileMediaInfo dialogIMPLEMENT_DYNAMIC(CPPageFileMediaInfo, CPropertyPage)
CPPageFileMediaInfo::CPPageFileMediaInfo(CString fn, IFilterGraph* pFG): CPropertyPage(CPPageFileMediaInfo::IDD, CPPageFileMediaInfo::IDD), m_fn(fn), m_pFG(pFG), m_pCFont(nullptr)
{
}CPPageFileMediaInfo::~CPPageFileMediaInfo()
{delete m_pCFont;m_pCFont = nullptr;
}void CPPageFileMediaInfo::DoDataExchange(CDataExchange* pDX)
{__super::DoDataExchange(pDX);DDX_Control(pDX, IDC_MIEDIT, m_mediainfo);
}BEGIN_MESSAGE_MAP(CPPageFileMediaInfo, CPropertyPage)ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()// CPPageFileMediaInfo message handlers
static WNDPROC OldControlProc;static LRESULT CALLBACK ControlProc(HWND control, UINT message, WPARAM wParam, LPARAM lParam)
{if (message == WM_KEYDOWN) {if ((LOWORD(wParam) == 'A' || LOWORD(wParam) == 'a')&& (GetKeyState(VK_CONTROL) < 0)) {CEdit* pEdit = (CEdit*)CWnd::FromHandle(control);pEdit->SetSel(0, pEdit->GetWindowTextLength(), TRUE);return 0;}}return CallWindowProc(OldControlProc, control, message, wParam, lParam); // call edit control's own windowproc
}
//初始化,加载MediaInfo库,读取文件信息
BOOL CPPageFileMediaInfo::OnInitDialog()
{__super::OnInitDialog();if (!m_pCFont) {m_pCFont = DEBUG_NEW CFont;}if (!m_pCFont) {return TRUE;}if (m_fn.IsEmpty()) {BeginEnumFilters(m_pFG, pEF, pBF) {CComQIPtr<IFileSourceFilter> pFSF = pBF;if (pFSF) {//当前文件路径LPOLESTR pFN = nullptr;//媒体类型AM_MEDIA_TYPE mt;//获取当前文件的路径和媒体类型if (SUCCEEDED(pFSF->GetCurFile(&pFN, &mt)) && pFN && *pFN) {m_fn = CStringW(pFN);CoTaskMemFree(pFN);}break;}}EndEnumFilters;}#if USE_STATIC_MEDIAINFO//使用静态库MediaInfo//文件路径MediaInfoLib::String f_name = m_fn;MediaInfoLib::MediaInfo MI;
#elseMediaInfoDLL::String f_name = m_fn;MediaInfo MI;
#endif//设置MI.Option(_T("ParseSpeed"), _T("0"));MI.Open(f_name);MI.Option(_T("Complete"));MI.Option(_T("Language"), _T("  Config_Text_ColumnSize;30"));//信息字符串MI_Text = MI.Inform().c_str();MI.Close();if (!MI_Text.Find(_T("Unable to load"))) {MI_Text = _T("");}LOGFONT lf;ZeroMemory(&lf, sizeof(lf));lf.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN;// The empty string will fallback to the first font that matches the other specified attributes.LPCTSTR fonts[] = { _T("Lucida Console"), _T("Courier New"), _T("") };// Use a negative value to match the character height instead of the cell height.int fonts_size[] = { -10, -11, -11 };UINT i = 0;BOOL success;do {_tcscpy_s(lf.lfFaceName, fonts[i]);lf.lfHeight = fonts_size[i];success = IsFontInstalled(fonts[i]) && m_pCFont->CreateFontIndirect(&lf);i++;} while (!success && i < _countof(fonts));//控件设置字体和内容m_mediainfo.SetFont(m_pCFont);m_mediainfo.SetWindowText(MI_Text);// subclass the edit controlOldControlProc = (WNDPROC)SetWindowLongPtr(m_mediainfo.m_hWnd, GWLP_WNDPROC, (LONG_PTR)ControlProc);return TRUE;  // return TRUE unless you set the focus to a control// EXCEPTION: OCX Property Pages should return FALSE
}
//显示or不显示?
void CPPageFileMediaInfo::OnShowWindow(BOOL bShow, UINT nStatus)
{__super::OnShowWindow(bShow, nStatus);if (bShow) {GetParent()->GetDlgItem(IDC_BUTTON_MI)->ShowWindow(SW_SHOW);} else {GetParent()->GetDlgItem(IDC_BUTTON_MI)->ShowWindow(SW_HIDE);}
}#if !USE_STATIC_MEDIAINFO
bool CPPageFileMediaInfo::HasMediaInfo()
{MediaInfo MI;return MI.IsReady();
}
#endif

可以看出,主要的工作都是在OnInitDialog()函数中实现的。大体的步骤如下:

1.通过调用pFSF->GetCurFile(&pFN, &mt),获得当前文件的路径,存入pFN中。

2.因为字符串类型不同,几经转换把pFN转换为MediaInfo可以识别的字符串f_name

3.根据该路径,调用MediaInfo库,获得视频的详细信息存入字符串变量MI_Text。

4.将MI_Text显示到控件上。

总体说来,过程并不复杂,理解起来还是比较简单的。

Media Player Classic - HC 源代码分析 6:MediaInfo选项卡 (CPPageFileMediaInfo)相关推荐

  1. Media Player Classic - HC 源代码分析 7:详细信息选项卡(CPPageFileInfoDetails)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  2. Media Player Classic - HC 源代码分析 5:关于对话框 (CAboutDlg)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  3. Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  4. Media Player Classic - HC 源代码分析 3:核心类 (CMainFrame)(2)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  5. Media Player Classic - HC 源代码分析 2:核心类 (CMainFrame)(1)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  6. Media Player Classic - HC 源代码分析 1:整体结构

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  7. Media Player Classic - HC 源代码分析 8:RenderFile函数详细分析(CFGManager)

    前面有两篇文章分析了Media Player Classic - HC(mpc-hc)的源代码中的核心类 CMainFrame: Media Player Classic - HC 源代码分析 2:核 ...

  8. Media Player Classic - HC 源代码分析 9:CFGManager类详细分析(CFGManager)

    上一篇文章分析了Media Player Classic - HC(mpc-hc)的源代码中的CFGManager类的RenderFile函数: Media Player Classic - HC 源 ...

  9. Media Player Classic - HC 源代码分析 14:PIN连接过程中推模式和拉模式区别

    前面有两篇文章讲解了PIN连接过程中需要做2件事情: 媒体类型的协商 分配器的协商 推模式和拉模式关于媒体类型的协商调用的接口都一样,主要的区别还是在分配器的协商. 前面讲解的分配器的协商过程是推模式 ...

最新文章

  1. Linux之编辑器 vim
  2. 【剑指offer-Java版】28字符串的排列
  3. python数字排序分组代码_python pandas 组内排序、单组排序、标号的实例
  4. bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
  5. 谷歌入职邮件_为什么我全职学习了8个月以接受Google采访
  6. Python绘制sigmoid函数及其导数图像
  7. Sikuli -- 创新的图形化编程技术
  8. 论文笔记_S2D.26_2017-ICCV_半监督深度学习的单目深度图预测
  9. pytorch基础API介绍
  10. 管理小故事精髓 100例(转)
  11. ios苹果越狱教程(奥德赛)
  12. 获取下载Qt安装包,Qt源码全国网址备忘录(不用注册Qt账户,即可下载各版本Qt安装包和Qt源码包)
  13. gcc 编译隐藏符号
  14. P0 口输出级具有能带 8个 LSTTL 门负载能力(指每个端口线例如P0.0P0.1每条位线,而不是整个P0口反证P2地址高8位,如果只能带4个怎么用)这个是门电路的扇出系数也就扇出带门负载能力
  15. c语言打鱼晒网问题报告书,2021年C语言渔夫打鱼晒网问题.pdf
  16. 浅谈web前端工程师hr面试经典问题20+
  17. 计算机运行异常怎么办,电脑启动异常怎么办
  18. java web—水果店管理系统
  19. uniapp开发抖音小程序注意事项
  20. 染色质调控区域的研究:对CHIP-seq和ATAC-seq发展的深入思考

热门文章

  1. HDU2012 素数判定【入门】
  2. Bailian3728 Blah数集【数学+set】
  3. HDU3784 继续xxx定律【角谷猜想】
  4. Bailian3718 位操作练习【位运算】
  5. POJ3069 Saruman's Army【贪心】
  6. 奇妙的证明 —— 0! = 1(a^0=1)
  7. windows tensorflow 版本与升级
  8. Boltzmann 玻尔兹曼机(BM)
  9. 容斥原理 —— 不重不漏的计数
  10. 栈的典型应用 —— 逆序输出