Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
14 KiB

  1. #ifndef __MEDIAPROP_H__
  2. #define __MEDIAPROP_H__
  3. // These should be moved into some central location
  4. #define PIDISI_CX 0x00000003L // VT_UI4
  5. #define PIDISI_CY 0x00000004L // VT_UI4
  6. #define PIDISI_FRAME_COUNT 0x0000000CL // VT_LPWSTR
  7. #define PIDISI_DIMENSIONS 0x0000000DL // VT_LPWSTR
  8. #define IsEqualSCID(a, b) (((a).pid == (b).pid) && IsEqualIID((a).fmtid, (b).fmtid) )
  9. typedef struct
  10. {
  11. const SHCOLUMNID *pscid;
  12. LPCWSTR pszName; // Propstg string name for this property.
  13. VARTYPE vt; // Note that the type of a given FMTID/PID pair is a known, fixed value
  14. BOOL bEnumerate; // We don't want to enumerate alias properties.
  15. } COLMAP;
  16. #define DEFINE_SCID(name, fmtid, pid) const SHCOLUMNID name = { fmtid, pid }
  17. DEFINE_SCID(SCID_Author, PSGUID_SUMMARYINFORMATION, PIDSI_AUTHOR);
  18. DEFINE_SCID(SCID_Title, PSGUID_SUMMARYINFORMATION, PIDSI_TITLE);
  19. DEFINE_SCID(SCID_Comment, PSGUID_SUMMARYINFORMATION, PIDSI_COMMENTS);
  20. DEFINE_SCID(SCID_Category, PSGUID_DOCUMENTSUMMARYINFORMATION, PIDDSI_CATEGORY);
  21. DEFINE_SCID(SCID_MUSIC_Artist, PSGUID_MUSIC, PIDSI_ARTIST);
  22. DEFINE_SCID(SCID_MUSIC_Album, PSGUID_MUSIC, PIDSI_ALBUM);
  23. DEFINE_SCID(SCID_MUSIC_Year, PSGUID_MUSIC, PIDSI_YEAR);
  24. DEFINE_SCID(SCID_MUSIC_Track, PSGUID_MUSIC, PIDSI_TRACK);
  25. DEFINE_SCID(SCID_MUSIC_Genre, PSGUID_MUSIC, PIDSI_GENRE);
  26. DEFINE_SCID(SCID_MUSIC_Lyrics, PSGUID_MUSIC, PIDSI_LYRICS);
  27. DEFINE_SCID(SCID_DRM_Protected, PSGUID_DRM, PIDDRSI_PROTECTED);
  28. DEFINE_SCID(SCID_DRM_Description, PSGUID_DRM, PIDDRSI_DESCRIPTION);
  29. DEFINE_SCID(SCID_DRM_PlayCount, PSGUID_DRM, PIDDRSI_PLAYCOUNT);
  30. DEFINE_SCID(SCID_DRM_PlayStarts, PSGUID_DRM, PIDDRSI_PLAYSTARTS);
  31. DEFINE_SCID(SCID_DRM_PlayExpires, PSGUID_DRM, PIDDRSI_PLAYEXPIRES);
  32. DEFINE_SCID(SCID_VIDEO_StreamName, PSGUID_VIDEO, PIDVSI_STREAM_NAME);
  33. DEFINE_SCID(SCID_VIDEO_FrameRate, PSGUID_VIDEO, PIDVSI_FRAME_RATE);
  34. DEFINE_SCID(SCID_VIDEO_Bitrate, PSGUID_VIDEO, PIDVSI_DATA_RATE);
  35. DEFINE_SCID(SCID_VIDEO_SampleSize, PSGUID_VIDEO, PIDVSI_SAMPLE_SIZE);
  36. DEFINE_SCID(SCID_VIDEO_Compression, PSGUID_VIDEO, PIDVSI_COMPRESSION);
  37. DEFINE_SCID(SCID_AUDIO_Format, PSGUID_AUDIO, PIDASI_FORMAT);
  38. DEFINE_SCID(SCID_AUDIO_Duration, PSGUID_AUDIO, PIDASI_TIMELENGTH); //100ns units, not milliseconds. VT_UI8, not VT_UI4
  39. DEFINE_SCID(SCID_AUDIO_Bitrate, PSGUID_AUDIO, PIDASI_AVG_DATA_RATE);
  40. DEFINE_SCID(SCID_AUDIO_SampleRate, PSGUID_AUDIO, PIDASI_SAMPLE_RATE);
  41. DEFINE_SCID(SCID_AUDIO_SampleSize, PSGUID_AUDIO, PIDASI_SAMPLE_SIZE);
  42. DEFINE_SCID(SCID_AUDIO_ChannelCount, PSGUID_AUDIO, PIDASI_CHANNEL_COUNT);
  43. DEFINE_SCID(SCID_IMAGE_Width, PSGUID_IMAGESUMMARYINFORMATION, PIDISI_CX);
  44. DEFINE_SCID(SCID_IMAGE_Height, PSGUID_IMAGESUMMARYINFORMATION, PIDISI_CY);
  45. DEFINE_SCID(SCID_IMAGE_Dimensions, PSGUID_IMAGESUMMARYINFORMATION, PIDISI_DIMENSIONS);
  46. DEFINE_SCID(SCID_IMAGE_FrameCount, PSGUID_IMAGESUMMARYINFORMATION, PIDISI_FRAME_COUNT);
  47. // Docsummary props
  48. const COLMAP g_CM_Category = { &SCID_Category, L"Category", VT_LPWSTR, FALSE}; // Alias property of Genre
  49. // SummaryProps
  50. const COLMAP g_CM_Author = { &SCID_Author, L"Author", VT_LPWSTR, FALSE}; // Alias property of Artist
  51. const COLMAP g_CM_Title = { &SCID_Title, L"Title", VT_LPWSTR, TRUE};
  52. const COLMAP g_CM_Comment = { &SCID_Comment, L"Description", VT_LPWSTR, TRUE};
  53. // Music props
  54. const COLMAP g_CM_Artist = { &SCID_MUSIC_Artist, L"Author", VT_LPWSTR, TRUE};
  55. const COLMAP g_CM_Album = { &SCID_MUSIC_Album, L"AlbumTitle", VT_LPWSTR, TRUE};
  56. const COLMAP g_CM_Year = { &SCID_MUSIC_Year, L"Year", VT_LPWSTR, TRUE};
  57. const COLMAP g_CM_Track = { &SCID_MUSIC_Track, L"Track", VT_UI4, TRUE}; // NB: This is exposed as a WMT_ATTRTYPE_STRING for mp3. We may need to change it.
  58. const COLMAP g_CM_Genre = { &SCID_MUSIC_Genre, L"Genre", VT_LPWSTR, TRUE};
  59. const COLMAP g_CM_Lyrics = { &SCID_MUSIC_Lyrics, L"Lyrics", VT_LPWSTR, TRUE};
  60. // Audio props
  61. const COLMAP g_CM_Format = { &SCID_AUDIO_Format, L"Format", VT_LPWSTR, TRUE};
  62. const COLMAP g_CM_Duration = { &SCID_AUDIO_Duration, L"Duration", VT_UI8, TRUE};
  63. const COLMAP g_CM_Bitrate = { &SCID_AUDIO_Bitrate, L"Bitrate", VT_UI4, TRUE};
  64. const COLMAP g_CM_SampleRate = { &SCID_AUDIO_SampleRate, L"SampleRate", VT_UI4, TRUE}; // samples per sec
  65. const COLMAP g_CM_SampleSize = { &SCID_AUDIO_SampleSize, L"SampleSize", VT_UI4, TRUE};
  66. const COLMAP g_CM_ChannelCount ={ &SCID_AUDIO_ChannelCount, L"ChannelCount", VT_UI4, TRUE};
  67. // Video props
  68. const COLMAP g_CM_StreamName = { &SCID_VIDEO_StreamName, L"StreamName", VT_LPWSTR, TRUE};
  69. const COLMAP g_CM_FrameRate = { &SCID_VIDEO_FrameRate, L"FrameRate", VT_UI4, TRUE};
  70. const COLMAP g_CM_SampleSizeV = { &SCID_VIDEO_SampleSize, L"SampleSize", VT_UI4, TRUE}; // different from audio sample simple
  71. const COLMAP g_CM_BitrateV = { &SCID_VIDEO_Bitrate, L"Bitrate", VT_UI4, TRUE}; // different from audio bitrate
  72. const COLMAP g_CM_Compression = { &SCID_VIDEO_Compression, L"Compression", VT_LPWSTR, TRUE};
  73. // Image props
  74. const COLMAP g_CM_Width = { &SCID_IMAGE_Width, L"Width", VT_UI4, TRUE};
  75. const COLMAP g_CM_Height = { &SCID_IMAGE_Height, L"Height", VT_UI4, TRUE};
  76. const COLMAP g_CM_Dimensions = { &SCID_IMAGE_Dimensions, L"Dimensions", VT_LPWSTR, TRUE};
  77. const COLMAP g_CM_FrameCount = { &SCID_IMAGE_FrameCount, L"FrameCount", VT_UI4, TRUE};
  78. // DRM props
  79. const COLMAP g_CM_Protected = { &SCID_DRM_Protected, L"Protected", VT_BOOL, TRUE};
  80. const COLMAP g_CM_DRMDescription={&SCID_DRM_Description, L"DRMDescription", VT_LPWSTR, TRUE};
  81. const COLMAP g_CM_PlayCount = { &SCID_DRM_PlayCount, L"PlayCount", VT_UI4, TRUE};
  82. const COLMAP g_CM_PlayStarts = { &SCID_DRM_PlayStarts, L"PlayStarts", VT_FILETIME,TRUE};
  83. const COLMAP g_CM_PlayExpires = { &SCID_DRM_PlayExpires, L"PlayExpires", VT_FILETIME,TRUE};
  84. // Describes each of the property sets an IPropertySetStorage uses.
  85. typedef struct {
  86. GUID fmtid; // fmtid for this property set
  87. const COLMAP **pcmProps; // List of all properties that exist in this set
  88. ULONG cNumProps;
  89. } PROPSET_INFO;
  90. enum MUSICPROPSTG_AUTHLEVEL
  91. {
  92. AUTH = 0, NON_AUTH
  93. };
  94. enum PROPSTG_STATE
  95. {
  96. CLOSED = 0,
  97. OPENED_SHARED,
  98. OPENED_DENYREAD,
  99. OPENED_DENYWRITE,
  100. OPENED_DENYALL
  101. };
  102. class CMediaPropSetStg;
  103. // Base property storage implementation.
  104. class CMediaPropStorage : public IPropertyStorage, IQueryPropertyFlags
  105. {
  106. public:
  107. // IUnknown
  108. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  109. STDMETHODIMP_(ULONG) AddRef();
  110. STDMETHODIMP_(ULONG) Release();
  111. //IPropertyStorage
  112. STDMETHODIMP ReadMultiple (ULONG cpspec, const PROPSPEC rgpspec[], PROPVARIANT rgvar[]);
  113. STDMETHODIMP WriteMultiple (ULONG cpspec, PROPSPEC const rgpspec[], const PROPVARIANT rgvar[], PROPID propidNameFirst);
  114. STDMETHODIMP DeleteMultiple(ULONG cpspec, PROPSPEC const rgpspec[]);
  115. STDMETHODIMP ReadPropertyNames (ULONG cpspec, PROPID const rgpropid[], LPWSTR rglpwstrName[]);
  116. STDMETHODIMP WritePropertyNames (ULONG cpspec, PROPID const rgpropid[], LPWSTR const rglpwstrName[]);
  117. STDMETHODIMP DeletePropertyNames(ULONG cpspec, PROPID const rgpropid[]);
  118. STDMETHODIMP SetClass(REFCLSID clsid);
  119. STDMETHODIMP Commit(DWORD grfCommitFlags);
  120. STDMETHODIMP Revert();
  121. STDMETHODIMP Enum(IEnumSTATPROPSTG **ppenum);
  122. STDMETHODIMP Stat(STATPROPSETSTG *pstatpropstg);
  123. STDMETHODIMP SetTimes(FILETIME const *pctime, FILETIME const *patime, FILETIME const *pmtime);
  124. // IQueryPropertyFlags
  125. STDMETHODIMP GetFlags(const PROPSPEC *pspec, SHCOLSTATEF *pcsFlags);
  126. STDMETHODIMP SetEnumFlags(SHCOLSTATEF csFlags);
  127. CMediaPropStorage(CMediaPropSetStg *ppssParent, CMediaPropStorage *ppsAuthority, REFFMTID fmtid, const COLMAP **ppcmPropInfo, DWORD cNumProps, DWORD dwMode, CRITICAL_SECTION *pcs);
  128. HRESULT SetProperty(PROPSPEC *ppspec, PROPVARIANT *pvar);//called by the parent to set the initial data
  129. HRESULT QuickLookup(PROPSPEC *ppspec, PROPVARIANT **ppvar);
  130. private:
  131. ~CMediaPropStorage();
  132. HRESULT Open(DWORD dwShareMode, DWORD dwOpenMode, IPropertyStorage **ppPropStg);
  133. void _ResetPropStorage(); //Resets the Propstorage to a known empty state
  134. HRESULT CopyPropStorageData(PROPVARIANT *pvarProps);
  135. void OnClose();
  136. HRESULT DoCommit(DWORD grfCommitFlags, FILETIME *ftFlushTime, PROPVARIANT *pVarProps, BOOL *pbDirtyFlags);//flush the data to the parent
  137. HRESULT LookupProp(const PROPSPEC *pspec, const COLMAP **ppcmName, PROPVARIANT **ppvarReadData, PROPVARIANT **ppvarWriteData, BOOL **ppbDirty, BOOL bPropertySet);
  138. BOOL IsDirectMode();
  139. BOOL IsSpecialProperty(const PROPSPEC *pspec);
  140. HRESULT _EnsureSlowPropertiesLoaded();
  141. virtual BOOL _IsSlowProperty(const COLMAP *pPInfo);
  142. LONG _cRef;
  143. COLMAP const **_ppcmPropInfo;
  144. PROPVARIANT *_pvarProps, *_pvarChangedProps;
  145. PROPVARIANT _varCodePage;
  146. BOOL *_pbDirtyFlags;
  147. ULONG _cNumProps;
  148. MUSICPROPSTG_AUTHLEVEL _authLevel;
  149. CMediaPropStorage *_ppsAuthority;
  150. CMediaPropSetStg *_ppssParent;
  151. FMTID _fmtid;
  152. FILETIME _ftLastCommit;
  153. PROPSTG_STATE _state;
  154. DWORD _dwMode;
  155. BOOL _bRetrievedSlowProperties;
  156. HRESULT _hrSlowProps;
  157. SHCOLSTATEF _csEnumFlags;
  158. CRITICAL_SECTION *_pcs; // The parent storage set's critical section.
  159. friend class CMediaPropSetStg;
  160. };
  161. // Base property set storage implementation.
  162. class CMediaPropSetStg : public IPersistFile, IPropertySetStorage, protected IWMReaderCallback
  163. {
  164. public:
  165. CMediaPropSetStg();
  166. // IUnknown
  167. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  168. STDMETHODIMP_(ULONG) AddRef();
  169. STDMETHODIMP_(ULONG) Release();
  170. // IPersist
  171. STDMETHODIMP GetClassID(CLSID *pClassID);
  172. // IPersistFile
  173. STDMETHODIMP IsDirty(void);
  174. STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
  175. STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember);
  176. STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName);
  177. STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName);
  178. // IPropertySetStorage
  179. STDMETHODIMP Create(REFFMTID fmtid, const CLSID * pclsid, DWORD grfFlags, DWORD grfMode, IPropertyStorage** ppPropStg);
  180. STDMETHODIMP Open(REFFMTID fmtid, DWORD grfMode, IPropertyStorage** ppPropStg);
  181. STDMETHODIMP Delete(REFFMTID fmtid);
  182. STDMETHODIMP Enum(IEnumSTATPROPSETSTG** ppenum);
  183. // IWMReaderCallBack
  184. STDMETHODIMP OnStatus(WMT_STATUS Staus, HRESULT hr, WMT_ATTR_DATATYPE dwType, BYTE *pValue, void *pvContext);
  185. STDMETHODIMP OnSample(DWORD dwOutputNum, QWORD cnsSampleTime, QWORD cnsSampleDuration, DWORD dwFlags, INSSBuffer *pSample, void* pcontext);
  186. virtual HRESULT FlushChanges(REFFMTID fmtid, LONG cNumProps, const COLMAP **pcmapInfo, PROPVARIANT *pVarProps, BOOL *pbDirtyFlags);
  187. HRESULT Init();
  188. virtual BOOL _IsSlowProperty(const COLMAP *pPInfo);
  189. protected:
  190. HRESULT _ResolveFMTID(REFFMTID fmtid, CMediaPropStorage **ppps);
  191. HRESULT _PopulateProperty(const COLMAP *pPInfo, PROPVARIANT *pvar);
  192. BOOL _bIsWritable;
  193. WCHAR _wszFile[MAX_PATH];
  194. BOOL _bHasBeenPopulated;
  195. BOOL _bSlowPropertiesExtracted;
  196. HRESULT _hrSlowProps;
  197. HRESULT _hrPopulated;
  198. UINT _cPropertyStorages;
  199. CMediaPropStorage **_propStg;
  200. const PROPSET_INFO *_pPropStgInfo; // Indicates which propstorages to create, etc...
  201. HANDLE _hFileOpenEvent;
  202. ~CMediaPropSetStg();
  203. private:
  204. HRESULT _ResetPropertySet();
  205. HRESULT _CreatePropertyStorages();
  206. virtual HRESULT _PopulatePropertySet();
  207. virtual HRESULT _PopulateSlowProperties();
  208. virtual HRESULT _PreCheck();
  209. LONG _cRef;
  210. DWORD _dwMode;
  211. // This property handler needes to operate in a FTA because of the content indexing service. If
  212. // we're created in an STA, it turns out they can't properly impersonate a user across apartment
  213. // boundaries.
  214. // This is a critical section we use to provide very "simple" synchronized access to our internal
  215. // members. Basically, we just wrap every public interface member in Enter/Leave. The WMSDK
  216. // doesn't throw any exceptions, so we don't need any try-finally's (and hopefully the AVI and WAV
  217. // code doesn't either).
  218. // All public interface members in the CMediaPropStorage class are also protected by this same
  219. // critical section.
  220. CRITICAL_SECTION _cs;
  221. friend class CMediaPropStorage;
  222. };
  223. // Class used to enumerate through all COLMAPs for the properties supported by a propertysetstorage //
  224. // Used internally by a PSS when populating properties.
  225. class CEnumAllProps
  226. {
  227. public:
  228. CEnumAllProps(const PROPSET_INFO *pPropSets, UINT cPropSets);
  229. const COLMAP *Next();
  230. private:
  231. const PROPSET_INFO *_pPropSets;
  232. UINT _cPropSets;
  233. UINT _iPropSetPos;
  234. UINT _iPropPos;
  235. };
  236. #endif //__MEDIAPROP_H__