hxaudply.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:13k
源码类别:

Symbian

开发平台:

Visual C++

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