hxaudply.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:12k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #ifndef _HXAUPLY_H_
  36. #define _HXAUPLY_H_
  37. #include "hxaudtyp.h" 
  38. #include "hxaudses.h" 
  39. // forward decls
  40. struct IHXAudioPlayerResponse;
  41. struct IHXAudioStream;
  42. struct IHXAudioHook;
  43. struct IHXAudioStreamInfoResponse;
  44. struct IHXScheduler;
  45. struct IHXVolume;
  46. struct IHXPreferences;
  47. struct IHXAudioCrossFade;
  48. typedef struct _HXAudioFormat HXAudioFormat;
  49. class CHXAudioSession;
  50. class CHXSimpleList;
  51. class CHXAudioStream;
  52. class Timeval;
  53. #ifdef _MACINTOSH
  54. extern BOOL gSoundCallbackTime;
  55. #endif
  56. /****************************************************************************
  57.  *
  58.  *  Class:
  59.  *
  60.  *      CHXAudioPlayer
  61.  *
  62.  *  Purpose:
  63.  *
  64.  *      PN implementation of audio player.
  65.  *
  66.  */
  67. class CHXAudioPlayer: public IHXAudioPlayer,
  68. #ifdef HELIX_FEATURE_VOLUME 
  69.                       public IHXVolumeAdviseSink,
  70. #endif 
  71.                       public IHXAudioCrossFade,
  72.                       public IHXCallback
  73. {
  74. private:
  75. LONG32 m_lRefCount;
  76. BOOL m_bAdjustForRealAudio;
  77. HXAudioFormat m_PlayerFmt; // This players audio format
  78. IHXAudioPlayerResponse* m_pPlayerResponse; // Notification interface
  79. IHXScheduler* m_pScheduler;
  80. IHXPreferences* m_pPreferences;
  81. ULONG32 m_ulCurrentTime;  // Current playback time 
  82. ULONG32 m_ulLastCurrentTimeReturned; 
  83. ULONG32 m_ulLastDeviceTimeAdjusted;
  84. BOOL m_bTimeReturned;
  85. BOOL m_bDisableDeviceWrite; // Don't write to audio device
  86. ULONG32 m_ulBytesPerGran;  // Num bytesper granularity
  87. CHXSimpleList* m_pStreamRespList; // Stream response list
  88. ULONG32 m_ulASstartTime; // This player's start time.
  89. // This is in audio session time.
  90. ULONG32 m_ulAPplaybackTime;  // This player's playback time
  91. // within the timeline
  92. ULONG32 m_ulAPstartTime;  // This player's playback start time
  93. // within the timeline.
  94. ULONG32 m_ulADresumeTime; // This is the audio device time
  95. // when this player resumed.
  96. EPlayerState m_eState; // Status
  97.         BOOL    m_bPrefUse11khz; // Sampling rate from prefs
  98.         UINT16  m_uPrefBitsPerSample; // Bits per sample from prefs
  99.         UINT16  m_uPrefAudioQuality; // Audio quality from prefs
  100. BOOL m_bDisableWrite;
  101. BOOL m_bIsResumed;
  102. UINT32 m_ulTimeAdjustDoneAt;
  103. UINT16 m_uVolume;
  104. BOOL m_bMute;
  105. INT64 m_llLastWriteTime;
  106.     
  107. #ifdef HELIX_FEATURE_VOLUME        
  108.         IHXVolume* m_pPlayerVolume;
  109. #endif        
  110. protected:
  111.         ~CHXAudioPlayer();
  112. PRIVATE_DESTRUCTORS_ARE_NOT_A_CRIME
  113. public:
  114. CHXAudioPlayer(CHXAudioSession* owner);
  115. void     Close(void);
  116.         //IHXCallback methods
  117.         STDMETHOD(Func)(THIS);
  118.         
  119. /*
  120.    * IUnknown methods
  121.    */
  122. STDMETHOD(QueryInterface)   (THIS_
  123.                                 REFIID riid,
  124.                                 void** ppvObj);
  125. STDMETHOD_(ULONG32,AddRef)  (THIS);
  126. STDMETHOD_(ULONG32,Release) (THIS);
  127. /*
  128.  *      IHXAudioPlayer methods
  129.  */
  130. STDMETHOD(CreateAudioStream) (THIS_
  131. IHXAudioStream** pAudioStream
  132. );
  133. /* AddPostMixHook Interface is called by renderers to set a 
  134.  * post mix hook of the audio data.
  135.  */
  136.         STDMETHOD(AddPostMixHook)(THIS_
  137. IHXAudioHook* pHook,
  138. const BOOL bDisableWrite,
  139. const BOOL bFinal
  140. );
  141.         STDMETHOD(RemovePostMixHook)(THIS_
  142. IHXAudioHook* pHook
  143. );
  144. #ifdef HELIX_FEATURE_VOLUME        
  145.         // IHXVolumeAdviseSink methods
  146.         inline STDMETHOD(OnVolumeChange)(THIS_ const UINT16 uVol )
  147.         {
  148.             m_uVolume = uVol;
  149.             return HXR_OK;
  150.         }
  151.         
  152.         inline STDMETHOD(OnMuteChange)(THIS_ const BOOL bMute )
  153.         {
  154.             m_bMute = bMute;
  155.             return HXR_OK;
  156.         }
  157.         inline UINT16 GetVolume()
  158.         {
  159.             return m_bMute? 0 : m_uVolume;
  160.         }
  161.         
  162. #endif        
  163.         
  164. /************************************************************************
  165. *  Method:
  166. *      IHXAudioPlayer::GetAudioStreamCount
  167. *  Purpose:
  168. * Get the number of audio streams currently active in the 
  169. * audio player. Since streams can be added mid-presentation
  170. * this function may return different values on different calls.
  171. * If the user needs to know about all the streams as they get
  172. * get added to the player, IHXAudioStreamInfoResponse should
  173. * be implemented and passed in SetStreamInfoResponse.
  174. */
  175. STDMETHOD_(UINT16,GetAudioStreamCount) (THIS);
  176. /* Get an audio stream from the stream list at position given.
  177.  */
  178.         STDMETHOD_(IHXAudioStream*,GetAudioStream)(THIS_
  179. UINT16 uIndex
  180. );
  181. /* Set a stream info response. This is used to get the number
  182.  * of streams associated with this player.
  183.  */
  184.         STDMETHOD(SetStreamInfoResponse)(THIS_
  185. IHXAudioStreamInfoResponse* pResponse
  186. );
  187. /************************************************************************
  188. *  Method:
  189. *      IHXAudioPlayer::RemoveStreamInfoResponse
  190. *  Purpose:
  191. * Remove stream info response that was added earlier
  192. */
  193. STDMETHOD(RemoveStreamInfoResponse) (THIS_
  194.     IHXAudioStreamInfoResponse* /*IN*/ pResponse);
  195. /* Return the this player's volume interface. */
  196. STDMETHOD_(IHXVolume*, GetAudioVolume)  (THIS);
  197. /* Return the session device volume interface. */
  198. STDMETHOD_(IHXVolume*, GetDeviceVolume) (THIS);
  199. /*
  200.  *  IHXAudioCrossFade methods
  201.  */
  202. /************************************************************************
  203.  *  Method:
  204.  *      IHXAudioCrossFade::CrossFade
  205.  *  Purpose:
  206.  * Cross-fade two audio streams.
  207.  * pStreamFrom - Stream to be cross faded from
  208.  * pStreamTo - Stream to be cross faded to
  209.  * ulFromCrossFadeStartTime- "From" Stream time when cross fade is 
  210.  *   to be started
  211.  * ulToCrossFadeStartTime - "To" Stream time when cross fade is to 
  212.  *   be started
  213.  * ulCrossFadeDuration - Duration over which cross-fade needs
  214.  *       to be done
  215.  *     
  216.  */
  217. STDMETHOD(CrossFade) (THIS_
  218. IHXAudioStream* pStreamFrom,
  219. IHXAudioStream* pStreamTo,
  220. UINT32  ulFromCrossFadeStartTime,
  221. UINT32  ulToCrossFadeStartTime,
  222. UINT32  ulCrossFadeDuration);
  223.   STDMETHOD(SetError)     (THIS_
  224.       HX_RESULT theErr
  225.       );
  226.  
  227. /*
  228.  *   Other public methods.
  229.  */
  230. HX_RESULT InitializeStructures (void);
  231. HX_RESULT Init (
  232. IUnknown* pContext
  233. );
  234. HX_RESULT Setup(ULONG32 ulGranuarity);
  235. void SetGranularity (
  236. const ULONG32  ulGranularity
  237. );
  238. HX_RESULT Resume(void);
  239. HX_RESULT Pause(void);
  240. HX_RESULT Stop (
  241. const BOOL bFlush
  242. );
  243. void DonePlayback(void)   {m_bIsDonePlayback = TRUE;};
  244. BOOL IsDonePlayback(void) {return m_bIsDonePlayback;};
  245. HX_RESULT Seek (
  246. const ULONG32 ulSeekTime
  247. );
  248. CHXAudioSession* GetOwner(void) 
  249. { return m_Owner; };
  250. void GetFormat( 
  251. HXAudioFormat* pAudioFormat
  252. );
  253. CHXSimpleList* GetStreamList(void) 
  254. return m_pStreamList; 
  255. };
  256. HX_RESULT OnTimeSync(
  257. ULONG32 ulCurrentTime
  258. );
  259. ULONG32 GetCurrentPlayBackTime(void);
  260. UINT16 GetStreamCount(void);
  261. /* Return the post process hook list. */
  262. CHXSimpleList* GetPostMixHookList(void) 
  263. return m_pPMixHookList; 
  264. };
  265. EPlayerState GetState(void)
  266. {
  267. return m_eState;
  268. }
  269. void StreamInitialized(CHXAudioStream* pAudioStream);
  270. BOOL IsDisableWrite(void) {return m_bDisableWrite;};
  271. ULONG32 GetInitialPushdown(BOOL bAtStart = FALSE);
  272. void SetLive(BOOL bIsLive);
  273. void AudioFormatNowKnown(void);
  274. void RegisterRealAudioStream  
  275.     (CHXAudioStream* pAudioStream);
  276. void UnRegisterRealAudioStream
  277.     (CHXAudioStream* pAudioStream);
  278. INT64 GetLastAudioWriteTime(void) {return m_llLastWriteTime;};
  279. BOOL IsThisAudioStream(IHXValues* pHeader);
  280. BOOL IsAudioOnlyTrue(void);
  281. double NumberOfBytesWritten();
  282. double ConvertMsToBytes(UINT32 ulTime);
  283. void UpdateStreamLastWriteTime();
  284. void UpdateLastWriteTime(UINT32 ulGranularity)
  285.     {m_llLastWriteTime += (INT64) ulGranularity;};
  286. void SaveLastNMilliSeconds(BOOL bSave, UINT32 ulNMilliSeconds);
  287. void RewindPlayer(UINT32 ulTimeToRewind);
  288. void DataInAudioDevice(BOOL bHasDataInAudioDevice) {m_bHasDataInAudioDevice = bHasDataInAudioDevice;};
  289. BOOL HasDataInAudioDevice() {return m_bHasDataInAudioDevice;};
  290. HX_RESULT SetSoundLevel(CHXSimpleList* pAudioStreamList, UINT16 uSoundLevel, BOOL bReflushAudioDevice);
  291.         typedef enum
  292.         {
  293.             STR_REMOVE,
  294.             STR_PAUSE,
  295.             STR_RESUME,
  296.             STR_SEEK,
  297.             STR_STOP,
  298.             STR_SETHINT
  299.         } STREAM_ACTION;
  300.         
  301.         HX_RESULT ManageAudioStreams(CHXSimpleList* pStreamLst,
  302.                                      STREAM_ACTION what,
  303.                                      UINT32 ulTime = 0
  304.                                      );
  305.         
  306.         
  307. HX_RESULT AudioStreamStateChanged(EPlayerState eState);
  308. CHXAudioStream* GetCHXAudioStream(UINT16 uIndex);
  309. BOOL IsLastNMilliSecsToBeStored();
  310. HX_RESULT ActualAddPostMixHook(IHXAudioHook* pHook,
  311.           const BOOL     bDisableWrite,
  312.      const BOOL     bFinal);
  313. HX_RESULT ActualRemovePostMixHook(IHXAudioHook* pHook);
  314. UINT32 GetGranularity(void) { return m_ulGranularity; };
  315. BOOL IsResumed(void) { return m_bIsResumed; };
  316. inline void     UseCoreThread()
  317.         {
  318.             m_Owner->UseCoreThread();
  319.         }
  320.         
  321. virtual HX_RESULT   _CreateAudioStream(IHXAudioStream** pAudioStream);
  322. virtual HX_RESULT   ProcessAudioHook(PROCESS_ACTION action, 
  323.      IHXAudioHook* pAudioHook);
  324. virtual void     ResetPlayer(void);
  325. friend class CHXAudioStream;
  326. protected:
  327.         ULONG32                 m_ulCallbackID;
  328. IUnknown* m_pContext;
  329. BOOL m_bInited; // Initialized?
  330. BOOL m_bHasStreams; // Player has streams..
  331. BOOL m_bIsLive;
  332. ULONG32 m_ulGranularity;  // Playback granularity
  333. CHXAudioSession* m_Owner;
  334. CHXSimpleList* m_pStreamList;
  335. CHXSimpleList* m_pRealAudioStreamList;
  336. CHXSimpleList* m_pPMixHookList; // Post mix hooks
  337. HXAudioFormat m_DeviceFmt; // Audio device format
  338. Timeval* m_pFakeAudioCBTime;
  339. ULONG32 m_ulLastFakeCallbackTime;
  340. ULONG32 m_ulIncreasingTimer;
  341. BOOL m_bIsDonePlayback;
  342. BOOL m_bIsFirstResume;
  343. BOOL m_bCanBeRewound;
  344. BOOL m_bHasDataInAudioDevice;
  345. void OnTimerCallback();
  346. void SetupStreams(void);
  347. void AddStreams(void);
  348. void RemoveStreams(void);
  349. UINT16 NumberOfResumedStreams(void);
  350. /* Get audio prefs.
  351.  */
  352. HX_RESULT GetAudioPrefs(void);
  353. void AdjustForRealAudio(void);
  354. HX_RESULT ResumeFakeTimeline(void);
  355. HX_RESULT StopFakeTimeline(void);
  356. };
  357. #endif /* HXAUPLY_H_ */