00001 #include "stdafx.h"
00002 #include "propstheoraencoder.h"
00003
00004 PropsTheoraEncoder::PropsTheoraEncoder(LPUNKNOWN inUnk, HRESULT* outHR)
00005 : CBasePropertyPage(NAME("illiminable Directshow Filters"), inUnk, IDD_THEORA_ENCODE_SETTINGS, IDS_THEORA_ENC_PROPS_STRING)
00006 , mTheoraEncodeSettings(NULL)
00007
00008 {
00009
00010 *outHR = S_OK;
00011 }
00012
00013 PropsTheoraEncoder::~PropsTheoraEncoder(void)
00014 {
00015
00016 }
00017
00018 CUnknown* PropsTheoraEncoder::CreateInstance(LPUNKNOWN inUnk, HRESULT* outHR)
00019 {
00020 return new PropsTheoraEncoder(inUnk, outHR);
00021 }
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 unsigned long PropsTheoraEncoder::log2(unsigned long inNum) {
00061 unsigned long ret = 0;
00062 while (inNum != 0) {
00063 inNum>>=1;
00064 ret++;
00065 }
00066 return ret - 1;
00067 }
00068
00069 unsigned long PropsTheoraEncoder::pow2(unsigned long inNum) {
00070 return 1 << (inNum);
00071 }
00072
00073 HRESULT PropsTheoraEncoder::OnApplyChanges(void)
00074 {
00075 if (mTheoraEncodeSettings == NULL) {
00076 return E_POINTER;
00077 }
00078
00079 mTheoraEncodeSettings->setQuality(SendDlgItemMessage(m_hwnd,IDC_SLIDER_QUALITY, TBM_GETPOS, NOT_USED, NOT_USED));
00080 mTheoraEncodeSettings->setKeyframeFreq(pow2(SendDlgItemMessage(m_hwnd,IDC_SLIDER_LOG_KEYFRAME, TBM_GETPOS, NOT_USED, NOT_USED)));
00081 mTheoraEncodeSettings->setTargetBitrate(SendDlgItemMessage(m_hwnd,IDC_SLIDER_BITRATE, TBM_GETPOS, NOT_USED, NOT_USED) * 1000);
00082 SetClean();
00083 return S_OK;
00084 }
00085
00086 HRESULT PropsTheoraEncoder::OnActivate(void)
00087 {
00088
00089 char* locStrBuff = new char[16];
00090
00091
00092
00093
00094
00095 SendDlgItemMessage(m_Dlg, IDC_SLIDER_QUALITY, TBM_SETRANGE, TRUE, MAKELONG(0, 63));
00096 SendDlgItemMessage(m_Dlg, IDC_SLIDER_QUALITY, TBM_SETTICFREQ, 1, 0);
00097 SendDlgItemMessage(m_Dlg, IDC_SLIDER_QUALITY, TBM_SETPOS, 1, mTheoraEncodeSettings->quality());
00098
00099 SendDlgItemMessage(m_Dlg, IDC_SLIDER_LOG_KEYFRAME, TBM_SETRANGE, TRUE, MAKELONG(0, 13));
00100 SendDlgItemMessage(m_Dlg, IDC_SLIDER_LOG_KEYFRAME, TBM_SETTICFREQ, 1, 0);
00101 SendDlgItemMessage(m_Dlg, IDC_SLIDER_LOG_KEYFRAME, TBM_SETPOS, 1, log2(mTheoraEncodeSettings->keyframeFreq()));
00102
00103 SendDlgItemMessage(m_Dlg, IDC_SLIDER_BITRATE, TBM_SETRANGE, TRUE, MAKELONG(64, 1984));
00104 SendDlgItemMessage(m_Dlg, IDC_SLIDER_BITRATE, TBM_SETTICFREQ, 32, 0);
00105 SendDlgItemMessage(m_Dlg, IDC_SLIDER_BITRATE, TBM_SETPOS, 1, mTheoraEncodeSettings->targetBitrate() / 1000);
00106
00107
00108 itoa(mTheoraEncodeSettings->quality(), locStrBuff, 10);
00109 SendDlgItemMessage(m_Dlg, IDC_LABEL_QUALITY, WM_SETTEXT, NOT_USED, (LPARAM)locStrBuff);
00110
00111 itoa(mTheoraEncodeSettings->keyframeFreq(), locStrBuff, 10);
00112 SendDlgItemMessage(m_Dlg, IDC_LABEL_LOG_KEYFRAME, WM_SETTEXT,NOT_USED, (LPARAM)locStrBuff);
00113
00114 itoa(mTheoraEncodeSettings->targetBitrate(), locStrBuff, 10);
00115 SendDlgItemMessage(m_Dlg, IDC_LABEL_BITRATE, WM_SETTEXT,NOT_USED, (LPARAM)locStrBuff);
00116
00117 delete[] locStrBuff;
00118 return S_OK;
00119 }
00120
00121 HRESULT PropsTheoraEncoder::OnConnect(IUnknown *pUnk)
00122 {
00123
00124 if (mTheoraEncodeSettings != NULL) {
00125
00126 mTheoraEncodeSettings = NULL;
00127 }
00128
00129 HRESULT locHR;
00130
00131 locHR = pUnk->QueryInterface(IID_ITheoraEncodeSettings, (void**)(&mTheoraEncodeSettings));
00132 return locHR;
00133 }
00134
00135 HRESULT PropsTheoraEncoder::OnDisconnect(void)
00136 {
00137 if (mTheoraEncodeSettings != NULL) {
00138
00139 mTheoraEncodeSettings = NULL;
00140 }
00141 return S_OK;
00142 }
00143 void PropsTheoraEncoder::SetDirty()
00144 {
00145 m_bDirty = TRUE;
00146 if (m_pPageSite)
00147 {
00148 m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
00149 }
00150 }
00151
00152 void PropsTheoraEncoder::SetClean()
00153 {
00154 m_bDirty = FALSE;
00155 if (m_pPageSite)
00156 {
00157 m_pPageSite->OnStatusChange(PROPPAGESTATUS_CLEAN);
00158 }
00159 }
00160 INT_PTR PropsTheoraEncoder::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
00161 {
00162 char locBuff[16];
00163 switch (uMsg) {
00164 case WM_COMMAND:
00165
00166 case WM_HSCROLL:
00167 if (HWND(lParam) == GetDlgItem(m_hwnd, IDC_SLIDER_QUALITY)) {
00168 SetDirty();
00169 itoa(SendDlgItemMessage(m_hwnd,IDC_SLIDER_QUALITY, TBM_GETPOS, NOT_USED, NOT_USED), (char*)&locBuff, 10);
00170 SendDlgItemMessage(m_hwnd, IDC_LABEL_QUALITY, WM_SETTEXT, NOT_USED, (LPARAM)&locBuff);
00171 return (INT_PTR)TRUE;
00172
00173 } else if (HWND(lParam) == GetDlgItem(m_hwnd, IDC_SLIDER_BITRATE)) {
00174 SetDirty();
00175 itoa(SendDlgItemMessage(m_hwnd,IDC_SLIDER_BITRATE, TBM_GETPOS, NOT_USED, NOT_USED) * 1000, (char*)&locBuff, 10);
00176 SendDlgItemMessage(m_hwnd, IDC_LABEL_BITRATE, WM_SETTEXT, NOT_USED, (LPARAM)&locBuff);
00177 return (INT_PTR)TRUE;
00178
00179 } else if (HWND(lParam) == GetDlgItem(m_hwnd, IDC_SLIDER_LOG_KEYFRAME)) {
00180 SetDirty();
00181 itoa(pow2(SendDlgItemMessage(m_hwnd,IDC_SLIDER_LOG_KEYFRAME, TBM_GETPOS, NOT_USED, NOT_USED)), (char*)&locBuff, 10);
00182 SendDlgItemMessage(m_hwnd, IDC_LABEL_LOG_KEYFRAME, WM_SETTEXT, NOT_USED, (LPARAM)&locBuff);
00183 return (INT_PTR)TRUE;
00184 }
00185
00186 break;
00187 }
00188
00189
00190 return CBasePropertyPage::OnReceiveMessage(hwnd, uMsg, wParam, lParam);
00191 }
00192
00193