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

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 Data
    enum { IDD = IDD_FILEMEDIAINFO };
	//显示信息的控件
    CEdit m_mediainfo;
    CString m_fn;
    CFont* m_pCFont;
	//信息
    CString MI_Text;

#if !USE_STATIC_MEDIAINFO
    static 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 dialog

IMPLEMENT_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;
#else
    MediaInfoDLL::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 control
    OldControlProc = (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 源代码分析

    VC2010 编译 Media Player Classic - Home Cinema (mpc-hc) Media Player Classic - Home Cinema (mpc-hc)播放器 ...

  8. MediaInfo源代码分析 1:整体结构

    MediaInfo 用来分析视频和音频文件的编码和内容信息,是一款是自由软件 (免费使用.免费获得源代码).之前编程的时候,都是直接调用它提供的Dll,这次突然来了兴趣,想研究一下它内部究竟是怎么实现 ...

  9. CVE-2012-0003 Microsoft Windows Media Player ‘winmm.dll’ MIDI文件解析远程代码执行漏洞 分析

    [CNNVD]Microsoft Windows Media Player ‘winmm.dll’ MIDI文件解析远程代码执行漏洞(CNNVD-201201-110)    Microsoft Wi ...

随机推荐

  1. gloox配置聊天室

    gloox配置聊天室 (金庆的专栏) gloox是XMPP协议的C++客户端库.以下代码测试创建多人聊天室(MUC), 并进行配置.参照gloox中的muc示例代码.gloox代码示例中没有聊天室的配 ...

  2. [openresty]安装nginx_lua

    这种方式是直接安装openresty ,不是通过重新编译nginx Ubuntu 安装 安装依赖包 $ sudo apt-get install libreadline-dev libncurses5 ...

  3. 一个 Linux 上分析死锁的简单方法

    简介 死锁 (deallocks): 是指两个或两个以上的进程(线程)在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这 ...

  4. everything of people’s life can changed in their twenties

    还记得三年前,独自背着行李,流浪远方,来到曾经只在地理课本上才熟悉的北国,带着好奇,带着期望,带着激动的心情,想感受毛爷爷当年霸气的北国风光,千里冰封的美丽,想知道北方的面条到底有多少种花样,想走进那 ...

  5. 安卓程序员要拿到5000和1w的薪资,分别需要掌握哪些技术?

    这个是我在逛知乎的时候发现的一个帖子,在这里小小的整理了一下,收集了一些评论,然后我分享出来,希望对自己还有同行有所帮助. 著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 链接 ...

  6. Libgdx教程目录

    Libgdx教程 Note:本教程用的Libgdx 1.9.2版本,在教程更新完毕之前应该不会更新版本.之前的博客中也发表过Libgdx的内容,不过当时都从别人那里拷贝的,因此现在想做一个Libgdx ...

  7. 由源代码编译SpriteBuilder最新版本1.5.0搭配最新的Cocos2D 3.4.9

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 大家知道SpriteBuilder版本停留在1.4.9已经很久 ...

  8. git提交代码到github

    前言:转载请注明出处:http://blog.csdn.net/hejjunlin/article/details/52117504 git提交代码到github 命令汇总: git init git ...

  9. 08 ListView 优化的例子

    package com.fmy.homework; import java.util.List; import com.fmy.homework.httputil.HttpUtil; import c ...

  10. Dynamics CRM 注册插件dll到GAC

    以server2012为例,搜索cmd,打开红框中的命令框,gacutil.exe -i "dll路径" 通过该命令把需要用到dll注册进gac(这里包括你的插件dll和你插件中引 ...