mp3_port.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /*
  19. * Contributed by:
  20. * Toni < buldozer at aufbix dot org >
  21. */
  22. #ifndef __PJMEDIA_MP3_PORT_H__
  23. #define __PJMEDIA_MP3_PORT_H__
  24. /**
  25. * @file mp3_port.h
  26. * @brief MP3 writer
  27. */
  28. #include <pjmedia/port.h>
  29. /**
  30. * @defgroup PJMEDIA_MP3_FILE_REC MP3 Audio File Writer (Recorder)
  31. * @ingroup PJMEDIA_PORT
  32. * @brief MP3 Audio File Writer (Recorder)
  33. * @{
  34. *
  35. * This section describes MP3 file writer. Currently it only works on Windows
  36. * using BladeEncDLL of the LAME MP3 encoder. <b>Note that the LAME_ENC.DLL
  37. * file must exist in the PATH so that the encoder can work properly.</b>
  38. *
  39. * The MP3 file writer is created with #pjmedia_mp3_writer_port_create() which
  40. * among other things specifies the desired file name and audio properties.
  41. * It then takes PCM input when #pjmedia_port_put_frame() is called and encode
  42. * the PCM input into MP3 streams before writing it to the .mp3 file.
  43. */
  44. PJ_BEGIN_DECL
  45. /**
  46. * This structure contains encoding options that can be specified during
  47. * MP3 writer port creation. Application should always zero the structure
  48. * before setting some value to make sure that default options will be used.
  49. */
  50. typedef struct pjmedia_mp3_encoder_option
  51. {
  52. /** Specify whether variable bit rate should be used. Variable bitrate
  53. * would normally produce better quality at the expense of probably
  54. * larger file.
  55. */
  56. pj_bool_t vbr;
  57. /** Target bitrate, in bps. If VBR is enabled, this settings specifies
  58. * the average bit-rate requested, and will make the encoder ignore
  59. * the quality setting. For CBR, this specifies the actual bitrate,
  60. * and if this option is zero, it will be set to the sampling rate
  61. * multiplied by number of channels.
  62. */
  63. unsigned bit_rate;
  64. /** Encoding quality, 0-9, with 0 is the highest quality. For VBR, the
  65. * quality setting will only take effect when bit_rate setting is zero.
  66. */
  67. unsigned quality;
  68. } pjmedia_mp3_encoder_option;
  69. /**
  70. * Create a media port to record PCM media to a MP3 file. After the port
  71. * is created, application can call #pjmedia_port_put_frame() to feed the
  72. * port with PCM frames. The port then will encode the PCM frame into MP3
  73. * stream, and store it to MP3 file specified in the argument.
  74. *
  75. * When application has finished with writing MP3 file, it must destroy the
  76. * media port with #pjmedia_port_destroy() so that the MP3 file can be
  77. * closed properly.
  78. *
  79. * @param pool Pool to create memory buffers for this port.
  80. * @param filename File name.
  81. * @param clock_rate The sampling rate.
  82. * @param channel_count Number of channels.
  83. * @param samples_per_frame Number of samples per frame.
  84. * @param bits_per_sample Number of bits per sample (eg 16).
  85. * @param option Optional option to set encoding parameters.
  86. * @param p_port Pointer to receive the file port instance.
  87. *
  88. * @return PJ_SUCCESS on success.
  89. */
  90. PJ_DECL(pj_status_t)
  91. pjmedia_mp3_writer_port_create(pj_pool_t *pool,
  92. const char *filename,
  93. unsigned clock_rate,
  94. unsigned channel_count,
  95. unsigned samples_per_frame,
  96. unsigned bits_per_sample,
  97. const pjmedia_mp3_encoder_option *option,
  98. pjmedia_port **p_port );
  99. #if !DEPRECATED_FOR_TICKET_2251
  100. /**
  101. * Register the callback to be called when the file writing has reached
  102. * certain size. Application can use this callback, for example, to limit
  103. * the size of the output file.
  104. *
  105. * @param port The file writer port.
  106. * @param pos The file position on which the callback will be called.
  107. * @param user_data User data to be specified in the callback, and will be
  108. * given on the callback.
  109. * @param cb Callback to be called. If the callback returns non-
  110. * PJ_SUCCESS, the writing will stop. Note that if
  111. * application destroys the port in the callback, it must
  112. * return non-PJ_SUCCESS here.
  113. *
  114. * @return PJ_SUCCESS on success.
  115. */
  116. PJ_DECL(pj_status_t)
  117. pjmedia_mp3_writer_port_set_cb( pjmedia_port *port,
  118. pj_size_t pos,
  119. void *user_data,
  120. pj_status_t (*cb)(pjmedia_port *port,
  121. void *usr_data));
  122. #endif
  123. /**
  124. * Register the callback to be called when the file writing has reached
  125. * certain size. Application can use this callback, for example, to limit
  126. * the size of the output file.
  127. *
  128. * @param port The file writer port.
  129. * @param pos The file position on which the callback will be called.
  130. * @param user_data User data to be specified in the callback, and will be
  131. * given on the callback.
  132. * @param cb Callback to be called. Note that if
  133. * application wishes to stop the playback, it
  134. * can disconnect the port in the callback, and
  135. * only after all connections have been removed
  136. * could the application safely destroy the port.
  137. *
  138. * @return PJ_SUCCESS on success.
  139. */
  140. PJ_DECL(pj_status_t)
  141. pjmedia_mp3_writer_port_set_cb2(pjmedia_port *port,
  142. pj_size_t pos,
  143. void *user_data,
  144. void (*cb)(pjmedia_port *port,
  145. void *usr_data));
  146. /**
  147. * @}
  148. */
  149. PJ_END_DECL
  150. #endif /* __PJMEDIA_MP3_PORT_H__ */