sipxmedialib  Version 3.3
MprFromFile.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2008 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2008 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 #ifndef _MprFromFile_h_
15 #define _MprFromFile_h_
16 
17 // SYSTEM INCLUDES
18 // APPLICATION INCLUDES
19 #include "mp/MpFlowGraphMsg.h"
20 #include "mp/MpAudioResource.h"
21 #include "os/OsProtectEvent.h"
22 #include "mp/MpResourceMsg.h"
24 
25 // DEFINES
26 // MACROS
27 // EXTERNAL FUNCTIONS
28 // EXTERNAL VARIABLES
29 // CONSTANTS
30 // STRUCTS
31 // TYPEDEFS
32 // FORWARD DECLARATIONS
33 
38 {
39 /* //////////////////////////// PUBLIC //////////////////////////////////// */
40 public:
41 
42 /* ============================ CREATORS ================================== */
44 
45 
47  MprFromFile(const UtlString& rName);
48 
50  virtual
51  ~MprFromFile();
52 
53  typedef enum
54  {
61  } Completion;
62 
64 
65 /* ============================ MANIPULATORS ============================== */
67 
68 
70  static OsStatus playBuffer(const UtlString& namedResource,
71  OsMsgQ& fgQ,
72  const char* audioBuffer,
73  unsigned long bufSize,
74  uint32_t inRate, uint32_t fgRate,
75  int type, UtlBoolean repeat,
76  OsProtectedEvent* notify,
77  UtlBoolean autoStopAfterFinish = TRUE);
95  static OsStatus playFile(const UtlString& namedResource,
97  OsMsgQ& fgQ,
98  uint32_t fgSampleRate,
99  const UtlString& filename,
100  const UtlBoolean& repeat,
101  UtlBoolean autoStopAfterFinish = TRUE);
124  static OsStatus stopFile(const UtlString& namedResource,
126  OsMsgQ& fgQ);
139  static OsStatus pauseFile(const UtlString& namedResource,
141  OsMsgQ& fgQ);
154  static OsStatus resumeFile(const UtlString& namedResource,
156  OsMsgQ& fgQ);
169  static OsStatus sendProgressPeriod(const UtlString& namedResource,
171  OsMsgQ& fgQ,
172  int32_t updatePeriodMS);
189  static OsStatus readAudioFile(uint32_t fgSampleRate,
191  UtlString*& audioBuffer,
192  const char* audioFileName);
222 
223 /* ============================ ACCESSORS ================================= */
225 
226 
228 
229 /* ============================ INQUIRY =================================== */
231 
232 
234 
235 /* //////////////////////////// PROTECTED ///////////////////////////////// */
236 protected:
237 
238 /* //////////////////////////// PRIVATE /////////////////////////////////// */
239 private:
240 
241  typedef enum
242  {
250  } AddlMsgTypes;
251 
252  typedef enum
253  {
258  } State;
259 
260  static const unsigned int sFromFileReadBufferSize;
261 
262  UtlString* mpFileBuffer;
264  UtlBoolean mFileRepeat;
265  State mState;
266  UtlBoolean mAutoStopAfterFinish;
267 
273 
277  static OsStatus genericAudioBufToFGAudioBuf(
278  UtlString*& fgAudioBuf,
279  const char* audioBuffer,
280  unsigned long bufSize,
281  uint32_t inRate,
282  uint32_t fgRate,
283  int type);
301  static UtlBoolean allocateAndResample(const char* inAudBuf,
303  const uint32_t inAudBufSz,
304  const uint32_t inRate,
305  char*& outAudBuf,
306  uint32_t& outAudBufSz,
307  const uint32_t outRate);
323  virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[],
324  MpBufPtr outBufs[],
325  int inBufsSize,
326  int outBufsSize,
327  UtlBoolean isEnabled,
328  int samplesPerFrame,
329  int samplesPerSecond);
330 
332  UtlBoolean handlePlay(UtlString* pBuffer, UtlBoolean repeat,
333  UtlBoolean autoStopAfterFinish);
334 
336  UtlBoolean handleFinish();
337 
339  UtlBoolean handleStop();
340 
342  UtlBoolean handlePause();
343 
345  UtlBoolean handleResume();
346 
348  UtlBoolean handleSetUpdatePeriod(int32_t periodMS);
349 
351  virtual UtlBoolean handleMessage(MpResourceMsg& rMsg);
352 
354  MprFromFile(const MprFromFile& rMprFromFile);
355 
357  MprFromFile& operator=(const MprFromFile& rhs);
358 
359 };
360 
361 /* ============================ INLINE METHODS ============================ */
362 
363 #endif // _MprFromFile_h_
Message object used to communicate with the media processing task.
Definition: MpResourceMsg.h:30
Playing has finished, but stopFile() hasn't called yet.
Definition: MprFromFile.h:257
Playing is in process.
Definition: MprFromFile.h:255
The "Play audio from file" media processing resource.
Definition: MprFromFile.h:37
UtlBoolean handleSetUpdatePeriod(int32_t periodMS)
Set an update period for sending progress updates.
Definition: MprFromFile.cpp:936
int samplesPerFrame
AddlMsgTypes
Definition: MprFromFile.h:241
static OsStatus playFile(const UtlString &namedResource, OsMsgQ &fgQ, uint32_t fgSampleRate, const UtlString &filename, const UtlBoolean &repeat, UtlBoolean autoStopAfterFinish=TRUE)
Sends an MPRM_FROMFILE_START message to the named MprFromFile resource.
Definition: MprFromFile.cpp:125
UtlBoolean handlePause()
Pause playback upon receiving request to pause.
Definition: MprFromFile.cpp:904
int mFileBufferIndex
Definition: MprFromFile.h:263
virtual UtlBoolean handleMessage(MpResourceMsg &rMsg)
Handle resource messages for this resource (new messaging model - 2007).
Definition: MprFromFile.cpp:947
static OsStatus pauseFile(const UtlString &namedResource, OsMsgQ &fgQ)
Sends an MPRM_FROMFILE_PAUSE message to the named MprFromFile resource.
Definition: MprFromFile.cpp:165
UtlString * mpFileBuffer
Definition: MprFromFile.h:262
Definition: MpResourceMsg.h:56
static const unsigned int sFromFileReadBufferSize
Definition: MprFromFile.h:260
static OsStatus stopFile(const UtlString &namedResource, OsMsgQ &fgQ)
Sends an MPRM_FROMFILE_STOP message to the named MprFromFile resource.
Definition: MprFromFile.cpp:157
OsTime mLastProgressUpdate
Definition: MprFromFile.h:271
Definition: MprFromFile.h:59
MprFromFile(const UtlString &rName)
Constructor.
Definition: MprFromFile.cpp:67
int samplesPerSecond
Start playing.
Definition: MprFromFile.h:243
Completion
Definition: MprFromFile.h:53
UtlBoolean handlePlay(UtlString *pBuffer, UtlBoolean repeat, UtlBoolean autoStopAfterFinish)
Initialize things to start playing the given buffer, upon receiving request to start.
Definition: MprFromFile.cpp:817
Definition: MprFromFile.h:56
UtlBoolean mFileRepeat
Definition: MprFromFile.h:264
Stop playing.
Definition: MprFromFile.h:248
State mState
Definition: MprFromFile.h:265
Abstract base class for all audio processing objects.
Definition: MpAudioResource.h:38
Pause playing.
Definition: MprFromFile.h:245
Definition: MprFromFile.h:58
MprFromFile & operator=(const MprFromFile &rhs)
Assignment operator (not implemented for this class)
Resume playing that was paused.
Definition: MprFromFile.h:246
virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond)
This method does the real work for the media processing resource and must be defined in each class de...
Definition: MprFromFile.cpp:698
static OsStatus sendProgressPeriod(const UtlString &namedResource, OsMsgQ &fgQ, int32_t updatePeriodMS)
Sends an MPRM_FROMFILE_SEND_PROGRESS message to the named MprFromFile resource.
Definition: MprFromFile.cpp:181
State
Definition: MprFromFile.h:252
Playing is stopped.
Definition: MprFromFile.h:254
UtlBoolean handleResume()
Resume playback upon receiving request to resume.
Definition: MprFromFile.cpp:920
static OsStatus resumeFile(const UtlString &namedResource, OsMsgQ &fgQ)
Sends an MPRM_FROMFILE_RESUME message to the named MprFromFile resource.
Definition: MprFromFile.cpp:173
static UtlBoolean allocateAndResample(const char *inAudBuf, const uint32_t inAudBufSz, const uint32_t inRate, char *&outAudBuf, uint32_t &outAudBufSz, const uint32_t outRate)
allocate enough space for the resampled data, and resample data passed in.
Definition: MprFromFile.cpp:646
Definition: MprFromFile.h:60
static OsStatus playBuffer(const UtlString &namedResource, OsMsgQ &fgQ, const char *audioBuffer, unsigned long bufSize, uint32_t inRate, uint32_t fgRate, int type, UtlBoolean repeat, OsProtectedEvent *notify, UtlBoolean autoStopAfterFinish=TRUE)
Play sound from buffer w/repeat option.
Definition: MprFromFile.cpp:84
Smart pointer to MpBuf.
Definition: MpBuf.h:160
Definition: MprFromFile.h:55
UtlBoolean handleStop()
Perform resetting of state, etc. upon receiving request to stop playing.
Definition: MprFromFile.cpp:880
Playing is in process, but paused.
Definition: MprFromFile.h:256
UtlBoolean mAutoStopAfterFinish
Definition: MprFromFile.h:266
static OsStatus genericAudioBufToFGAudioBuf(UtlString *&fgAudioBuf, const char *audioBuffer, unsigned long bufSize, uint32_t inRate, uint32_t fgRate, int type)
Convert generic audio data into flowgraph audio data.
Definition: MprFromFile.cpp:202
virtual ~MprFromFile()
Destructor.
Definition: MprFromFile.cpp:77
Report failed operation.
Definition: MprFromFile.h:249
#define TRUE
Definition: PlgDefsV1.h:41
Set progress updates period.
Definition: MprFromFile.h:247
UtlBoolean isEnabled() const
Returns TRUE is this resource is currently enabled, FALSE otherwise.
Definition: MpResource.cpp:440
static OsStatus readAudioFile(uint32_t fgSampleRate, UtlString *&audioBuffer, const char *audioFileName)
Read in an audio file into a new UtlString audio buffer.
Definition: MprFromFile.cpp:263
Definition: MprFromFile.h:57
int32_t mProgressIntervalMS
Definition: MprFromFile.h:272
UtlBoolean handleFinish()
Handle playback finish when the end of file/buffer is reached.
Definition: MprFromFile.cpp:847