PropsTheoraEncoder.cpp

Go to the documentation of this file.
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         //debugLog.open("G:\\logs\\TheoProps.log", ios_base::out);
00010         *outHR = S_OK;
00011 }
00012 
00013 PropsTheoraEncoder::~PropsTheoraEncoder(void)
00014 {
00015         //debugLog.close();
00016 }
00017 
00018 CUnknown* PropsTheoraEncoder::CreateInstance(LPUNKNOWN inUnk, HRESULT* outHR)
00019 {
00020     return new PropsTheoraEncoder(inUnk, outHR);
00021 }
00022 
00023 //LRESULT PropsTheoraEncoder::addNumberToCombo(int inComboID, int inNum) {
00024 //      char locStrBuff[16];
00025 //      itoa(inNum, (char*)&locStrBuff, 10);
00026 //      return SendDlgItemMessage(m_Dlg, IDC_COMBO_BITRATE, CB_ADDSTRING, NOT_USED, (LPARAM)&locStrBuff);
00027 //
00028 //}
00029 //
00030 //void PropsTheoraEncoder::SetupBitrateCombo() {
00031 //      addNumberToCombo(IDC_COMBO_BITRATE, 64000);
00032 //      addNumberToCombo(IDC_COMBO_BITRATE, 96000);
00033 //      addNumberToCombo(IDC_COMBO_BITRATE, 128000);
00034 //      addNumberToCombo(IDC_COMBO_BITRATE, 192000);
00035 //      addNumberToCombo(IDC_COMBO_BITRATE, 256000);
00036 //      addNumberToCombo(IDC_COMBO_BITRATE, 384000);
00037 //      addNumberToCombo(IDC_COMBO_BITRATE, 512000);
00038 //      addNumberToCombo(IDC_COMBO_BITRATE, 768000);
00039 //      addNumberToCombo(IDC_COMBO_BITRATE, 1024000);
00040 //      addNumberToCombo(IDC_COMBO_BITRATE, 1536000);
00041 //      addNumberToCombo(IDC_COMBO_BITRATE, 2000000);
00042 //
00043 //}
00044 //
00045 //void PropsTheoraEncoder::SetupKeyframeFreqCombo() {
00046 //      
00047 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 1);
00048 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 2);
00049 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 3);
00050 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 4);
00051 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 5);
00052 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 6);
00053 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 7);
00054 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 8);
00055 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 9);
00056 //      addNumberToCombo(IDC_COMBO_LOG_KEYFRAME_FREQ, 10);
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         //SetupBitrateCombo();
00092         //SetupKeyframeFreqCombo();
00093         
00094         //Set up the sliders
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                 //mTheoraEncodeSettings->Release();
00126                 mTheoraEncodeSettings = NULL;
00127         }
00128 
00129     HRESULT locHR;
00130     // Query pUnk for the filter's custom interface.
00131     locHR = pUnk->QueryInterface(IID_ITheoraEncodeSettings, (void**)(&mTheoraEncodeSettings));
00132     return locHR;
00133 }
00134 
00135 HRESULT PropsTheoraEncoder::OnDisconnect(void)
00136 {
00137         if (mTheoraEncodeSettings != NULL) {
00138                 //mTheoraEncodeSettings->Release();
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     } // switch
00188 
00189     // Did not handle the message.
00190     return CBasePropertyPage::OnReceiveMessage(hwnd, uMsg, wParam, lParam);
00191 }
00192 
00193 

Generated on Tue Feb 15 14:54:16 2005 for oggdsf by  doxygen 1.3.9