audiostream.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef __AUDIOSTREAM_H__
  2. #define __AUDIOSTREAM_H__
  3. #pragma once
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "audioframe.h"
  8. /** stream direction flag */
  9. #define STREAM_DIR_NONE 0
  10. #define STREAM_DIR_READ 1
  11. #define STREAM_DIR_WRITE 2
  12. #define STREAM_DIR_BOTH 3
  13. #define EVT_STREAM_BASE 0x00000000
  14. #define STREAM_EVT_FILE_REPLAY (EVT_STREAM_BASE + 0) // file replay
  15. #define STREAM_EVT_FILE_IOERROR (EVT_STREAM_BASE + 1) // io error, param1: GetLastError()
  16. #define STREAM_EVT_RTP_DTMF (EVT_STREAM_BASE + 2) // receive dtmf, for AudioRtpStream
  17. #define STREAM_EVT_RTP_TIMEOUT (EVT_STREAM_BASE + 3) // not receive any peer packet in specified time, for AudioRtpStream
  18. #define STREAM_EVT_FAX_END (EVT_STREAM_BASE + 4) // for fax stream
  19. #define STREAM_EVT_REC_END (EVT_STREAM_BASE + 5) // for recply record
  20. #define STREAM_EVT_PLY_END (EVT_STREAM_BASE + 6) // for recply play
  21. #define STREAM_EVT_TFX_END (EVT_STREAM_BASE + 7) // for recply send fax
  22. #define STREAM_EVT_RFX_END (EVT_STREAM_BASE + 8) // for recply recv fax
  23. #define MAX_DTMF 72
  24. typedef struct audiostream_vtbl_t
  25. {
  26. apr_status_t (*read_frame)(void *self, audioframe_t *frame);
  27. apr_status_t (*write_frame)(void *self, const audioframe_t *frame);
  28. }audiostream_vtbl_t;
  29. typedef struct audiostream_t audiostream_t;
  30. typedef struct audiocontext_t audiocontext_t;
  31. typedef struct audioengine_t audioengine_t;
  32. struct audiostream_t {
  33. audiostream_vtbl_t *vtbl;
  34. int direction;
  35. void *user_data;
  36. int (__stdcall *event_handler)(audiostream_t *stream, void *user_data, int evt, int param1, int param2);
  37. audiostream_t *upstream;
  38. audiostream_t *downstream;
  39. audioengine_t *engine;
  40. audiocontext_t *ctx;
  41. };
  42. void audiostream_init(audioengine_t *engine, audiostream_vtbl_t *vtbl, audiostream_t *stream);
  43. static void audiostream_set_upstream(audiostream_t *stream, audiostream_t *upstream){stream->upstream = upstream;}
  44. static audiostream_t* audiostream_get_upstream(audiostream_t *stream) {return stream->upstream;}
  45. static void audiostream_set_downstream(audiostream_t *stream, audiostream_t *downstream) { stream->downstream = downstream;}
  46. static audiostream_t* audiostream_get_downstream(audiostream_t *stream){return stream->downstream;}
  47. static audiocontext_t* audiostream_get_context(audiostream_t *stream){return stream->ctx;}
  48. static void audiostream_set_direction(audiostream_t *stream, int dir){stream->direction =dir;}
  49. static int audiostream_get_direction(audiostream_t *stream) {return stream->direction;}
  50. void audiostream_raise_event(audiostream_t *stream, int evt, int param1, int param2);
  51. // stream utility
  52. /** must be end with NULL */
  53. audiostream_t* audiostream_connect_pipeline(int direction, ...);
  54. void audiostream_disconnect_pipeline(audiostream_t *stream);
  55. #ifdef __cplusplus
  56. } // extern "C" {
  57. #endif
  58. #endif //__AUDIOSTREAM_H__