This file is indexed.

/usr/include/sipxtapi/mp/MprFromFile.h is in libsipxtapi-dev 3.3.0~test17-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
//  
// Copyright (C) 2006-2008 SIPez LLC. 
// Licensed to SIPfoundry under a Contributor Agreement. 
//
// Copyright (C) 2004-2008 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////

#ifndef _MprFromFile_h_
#define _MprFromFile_h_

// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include "mp/MpFlowGraphMsg.h"
#include "mp/MpAudioResource.h"
#include "os/OsProtectEvent.h"
#include "mp/MpResourceMsg.h"
#include "mp/MpResNotificationMsg.h"

// DEFINES
// MACROS
// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STRUCTS
// TYPEDEFS
// FORWARD DECLARATIONS

/**
*  @brief The "Play audio from file" media processing resource
*/
class MprFromFile : public MpAudioResource
{
/* //////////////////////////// PUBLIC //////////////////////////////////// */
public:

/* ============================ CREATORS ================================== */
///@name Creators
//@{

     /// Constructor
   MprFromFile(const UtlString& rName);

     /// Destructor
   virtual
   ~MprFromFile();

   typedef enum
   {
      PLAY_FINISHED,
      PLAY_STOPPED,
      PLAYING,
      READ_ERROR,
      PLAY_IDLE,
      INVALID_SETUP
   } Completion;

//@}

/* ============================ MANIPULATORS ============================== */
///@name Manipulators
//@{

      /// Play sound from buffer w/repeat option
    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);
      /**<
      *  @param[in] fgRate - the sample rate that the flowgraph is running at
      *             (this cannot determine that because it is a static method)
      *  @param[in] type - can be one of following:  (need a OsSoundType)<br>
      *             0 = RAW<br>
      *             1 = muLaw
      *  @param[in] repeat - TRUE/FALSE after the fromFile reaches the end of
      *             the buffer, go back to the beginning and continue to play.
      *  @param[in] autoStopAfterFinish - if set to TRUE, resource will
      *             automatically transition to IDLE state immediately after
      *             FINISHED state is reached. Otherwise you need to call
      *             stopFile() to transition to IDLE state.
      *
      *  @returns the result of attempting to queue the message to this
      *           resource and/or converting the audio buffer data.
      */

     /// @brief Sends an MPRM_FROMFILE_START message to the named MprFromFile resource.
   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
     *  within the flowgraph who's queue is supplied. When the message 
     *  is received, the above resource will then begin playing the file
     *  specified.
     *
     *  @param[in]  namedResource - the name of the resource to send a message to.
     *  @param[in]  fgQ - the queue of the flowgraph containing the resource which
     *              the message is to be received by.
     *  @param[in]  fgSampleRate - flowgraph sample rate -- needed to check if 
     *              read file is compatible with the flowgraph rate, and for 
     *              resampling.
     *  @param[in]  filename - the filename of the file to start playing.
     *  @param[in]  repeat - boolean indicating whether to loop-play the file.
     *  @param[in]  autoStopAfterFinish - if set to TRUE, resource will
     *              automatically transition to IDLE state immediately after
     *              FINISHED state is reached. Otherwise you need to call
     *              stopFile() to transition to IDLE state.
     *
     *  @retval The result of attempting to queue the message to this resource.
     */

     /// @brief Sends an MPRM_FROMFILE_STOP message to the named MprFromFile resource.
   static OsStatus stopFile(const UtlString& namedResource,
                            OsMsgQ& fgQ);
     /**<
     *  Sends an MPRM_FROMFILE_STOP message to the named MprFromFile resource
     *  within the flowgraph who's queue is supplied. When the message 
     *  is received, the above resource will then stop playing the file
     *  it has been playing.
     *
     *  @param[in] namedResource - the name of the resource to send a message to.
     *  @param[in] fgQ - the queue of the flowgraph containing the resource which
     *  the message is to be received by.
     *  @returns the result of attempting to queue the message to this resource.
     */

     /// @brief Sends an MPRM_FROMFILE_PAUSE message to the named MprFromFile resource.
   static OsStatus pauseFile(const UtlString& namedResource,
                             OsMsgQ& fgQ);
     /**<
     *  Sends an MPRM_FROMFILE_PAUSE message to the named MprFromFile resource
     *  within the flowgraph who's queue is supplied. When the message 
     *  is received, the above resource will then pause the file that 
     *  has been playing.
     *
     *  @param[in] namedResource - the name of the resource to send a message to.
     *  @param[in] fgQ - the queue of the flowgraph containing the resource which
     *  the message is to be received by.
     *  @returns the result of attempting to queue the message to this resource.
     */

     /// @brief Sends an MPRM_FROMFILE_RESUME message to the named MprFromFile resource.
   static OsStatus resumeFile(const UtlString& namedResource,
                             OsMsgQ& fgQ);
     /**<
     *  Sends an MPRM_FROMFILE_RESUME message to the named MprFromFile resource
     *  within the flowgraph who's queue is supplied. When the message 
     *  is received, the above resource, if in a paused state, will then resume 
     *  playing it's buffer.
     *
     *  @param[in] namedResource - the name of the resource to send a message to.
     *  @param[in] fgQ - the queue of the flowgraph containing the resource which
     *  the message is to be received by.
     *  @returns the result of attempting to queue the message to this resource.
     */

     /// @brief Sends an MPRM_FROMFILE_SEND_PROGRESS message to the named MprFromFile resource.
   static OsStatus sendProgressPeriod(const UtlString& namedResource,
                                      OsMsgQ& fgQ,
                                      int32_t updatePeriodMS);
     /**<
     *  Sends an MPRM_FROMFILE_SEND_PROGRESS message to the named MprFromFile resource
     *  within the flowgraph who's queue is supplied. When the message 
     *  is received, the above resource will then begin to send progress updates
     *  at the interval specified by \p updatePeriodMS.
     *  
     *  To stop progress updates, you must call this function again with an 
     *  update period of 0.
     *
     *  @param[in] namedResource - the name of the resource to send a message to.
     *  @param[in] fgQ - the queue of the flowgraph containing the resource which
     *  the message is to be received by.
     *  @param[in] updatePeriodMS - the period to wait between sending progress updates.
     *  @returns the result of attempting to queue the message to this resource.
     */

//@}

/* ============================ ACCESSORS ================================= */
///@name Accessors
//@{

//@}

/* ============================ INQUIRY =================================== */
///@name Inquiry
//@{

//@}

/* //////////////////////////// PROTECTED ///////////////////////////////// */
protected:

/* //////////////////////////// PRIVATE /////////////////////////////////// */
private:

   typedef enum
   {
      MPRM_FROMFILE_START = MpResourceMsg::MPRM_EXTERNAL_MESSAGE_START,
                                ///< Start playing.
      MPRM_FROMFILE_PAUSE,      ///< Pause playing.
      MPRM_FROMFILE_RESUME,     ///< Resume playing that was paused.
      MPRM_FROMFILE_SEND_PROGRESS, ///< Set progress updates period.
      MPRM_FROMFILE_STOP,       ///< Stop playing.
      MPRM_FROMFILE_ERROR       ///< Report failed operation
   } AddlMsgTypes;

   typedef enum
   {
      STATE_IDLE,      ///< Playing is stopped
      STATE_PLAYING,   ///< Playing is in process
      STATE_PAUSED,    ///< Playing is in process, but paused
      STATE_FINISHED   ///< Playing has finished, but stopFile() hasn't called yet
   } State;

   static const unsigned int sFromFileReadBufferSize;

   UtlString* mpFileBuffer;
   int mFileBufferIndex;
   UtlBoolean mFileRepeat;
   State mState;
   UtlBoolean mAutoStopAfterFinish; ///< If set to TRUE, resource will automatically
                                ///< transition to IDLE state immediately after
                                ///< FINISHED state is reached. Otherwise you need
                                ///< to call stopFile() to transition to IDLE state.

   OsTime mLastProgressUpdate;
   int32_t mProgressIntervalMS; ///< The progress interval for sending update
                                ///< notifications. A progress interval of 0
                                ///< means send no progress updates.

     /// @brief Convert generic audio data into flowgraph audio data.
   static OsStatus genericAudioBufToFGAudioBuf(
                                             UtlString*& fgAudioBuf,
                                             const char* audioBuffer, 
                                             unsigned long bufSize, 
                                             uint32_t inRate,
                                             uint32_t fgRate,
                                             int type);
     /**<
     *  Method to convert a generic char* audio buffer, in one of several
     *  acceptable formats, to a format that can be passed through the 
     *  flowgraph.
     *  
     *  @param[out] fgAudioBuf - a pointer to a string to store a newly allocated
     *              string with the processed audio suitable for the flowgraph.
     *  @param[in] audioBuffer - the audio data to re-work for the flowgraph.
     *  @param[in] bufSize - the size of /p audioBuffer, in bytes.
     *  @param[in] inRate - the sample rate that /p audioBuffer was recorded at.
     *  @param[in] fgRate - the sample rate that the flowgraph is running at
     *             (this cannot determine that because it is a static method)
     *  @param[in] type - can be one of following:  (need a OsSoundType)<br>
     *  0 = RAW<br>
     *  1 = muLaw
     */

     /// Read in an audio file into a new UtlString audio buffer.
   static OsStatus readAudioFile(uint32_t fgSampleRate,
                                 UtlString*& audioBuffer,
                                 const char* audioFileName);
     /**<
     *  @param audioBuffer - a reference to a pointer that will be filled
     *   with a new buffer holding the audio data.  Ownership will then
     *   transfer to the caller.
     *
     *  @NOTE WARNING: This allocates a buffer for the whole file -- thus,
     *                 files read in should not be huge.  This does occur
     *                 outside of the media task, so the time it takes to 
     *                 resample should not incur any latency, but memory 
     *                 utilization with large files may become an issue.
     *  @NOTE TODO: Replace this whole file reading code with some that 
     *              happens in a separate file-reading thread that can 
     *              happen while mediaTask is going on, so files of 
     *              extremely large length can be used.
     *  
     *  @param[in]  fgSampleRate - flowgraph sample rate -- needed to check if 
     *              read file is compatible with the flowgraph rate, and for 
     *              resampling.
     *
     *  @param[in] audioFileName - the name of a file to read flowgraph
     *   audio data from.  (exact format that the FG will accept -
     *   sample size, rate, & number of channels)
     *
     *  @retval OS_INVALID_ARGUMENT if the filename was null,
     *  the file was unopenable, or the file contained less than one sample.
     *  @retval OS_SUCCESS if the file was read successfully.
     */

     /// @brief allocate enough space for the resampled data, and resample data passed in.
   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 to store a resampled version of the audio passed in
     *  as /p audBuf.  Indicate the sample rate of /p audBuf with /p inRate,
     *  and resample it to a rate of /p outRate.
     *  
     *  @param[in] inAudBuf - the audio buffer to resample - assumes 16bit signed.
     *  @param[in] inAudBufSz - the size of the audio buffer, in bytes.
     *  @param[in] inRate - the sample rate that audBuf was recorded at.
     *  @param[out] outAudBuf - the audio buffer to allocate and store resampled
     *              audio into. (16bit signed)
     *  @param[out] outAudBufSz - the place to store the size of the resampled 
     *              audio buffer, in bytes.
     *  @param[in] outRate - the sample rate that audBuf will be resampled to.
     */

   virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[],
                                     MpBufPtr outBufs[],
                                     int inBufsSize,
                                     int outBufsSize,
                                     UtlBoolean isEnabled,
                                     int samplesPerFrame,
                                     int samplesPerSecond);

     /// Initialize things to start playing the given buffer, upon receiving request to start.
   UtlBoolean handlePlay(UtlString* pBuffer, UtlBoolean repeat,
                         UtlBoolean autoStopAfterFinish);

     /// Handle playback finish when the end of file/buffer is reached.
   UtlBoolean handleFinish();

     /// Perform resetting of state, etc. upon receiving request to stop playing.
   UtlBoolean handleStop();

     /// Pause playback upon receiving request to pause.
   UtlBoolean handlePause();

     /// Resume playback upon receiving request to resume.
   UtlBoolean handleResume();

     /// Set an update period for sending progress updates.
   UtlBoolean handleSetUpdatePeriod(int32_t periodMS);

     /// Handle resource messages for this resource (new messaging model - 2007).
   virtual UtlBoolean handleMessage(MpResourceMsg& rMsg);

     /// Copy constructor (not implemented for this class)
   MprFromFile(const MprFromFile& rMprFromFile);

     /// Assignment operator (not implemented for this class)
   MprFromFile& operator=(const MprFromFile& rhs);

};

/* ============================ INLINE METHODS ============================ */

#endif  // _MprFromFile_h_