format_wav_gsm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief Save GSM in the proprietary Microsoft format.
  21. *
  22. * Microsoft WAV format (Proprietary GSM)
  23. * \arg File name extension: WAV,wav49 (Upper case WAV, lower case is another format)
  24. * This format can be played on Windows systems, used for
  25. * e-mail attachments mainly.
  26. * \ingroup formats
  27. */
  28. /*** MODULEINFO
  29. <support_level>core</support_level>
  30. ***/
  31. #include "asterisk.h"
  32. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  33. #include "asterisk/mod_format.h"
  34. #include "asterisk/module.h"
  35. #include "asterisk/endian.h"
  36. #include "asterisk/format_cache.h"
  37. #include "msgsm.h"
  38. /* Some Ideas for this code came from makewave.c by Jeffrey Chilton */
  39. /* Portions of the conversion code are by guido@sienanet.it */
  40. #define GSM_FRAME_SIZE 33
  41. #define MSGSM_FRAME_SIZE 65
  42. #define MSGSM_DATA_OFFSET 60 /* offset of data bytes */
  43. #define GSM_SAMPLES 160 /* samples in a GSM block */
  44. #define MSGSM_SAMPLES (2*GSM_SAMPLES) /* samples in an MSGSM block */
  45. /* begin binary data: */
  46. static char msgsm_silence[] = /* 65 */
  47. {0x48,0x17,0xD6,0x84,0x02,0x80,0x24,0x49,0x92,0x24,0x89,0x02,0x80,0x24,0x49
  48. ,0x92,0x24,0x89,0x02,0x80,0x24,0x49,0x92,0x24,0x89,0x02,0x80,0x24,0x49,0x92
  49. ,0x24,0x09,0x82,0x74,0x61,0x4D,0x28,0x00,0x48,0x92,0x24,0x49,0x92,0x28,0x00
  50. ,0x48,0x92,0x24,0x49,0x92,0x28,0x00,0x48,0x92,0x24,0x49,0x92,0x28,0x00,0x48
  51. ,0x92,0x24,0x49,0x92,0x00};
  52. /* end binary data. size = 65 bytes */
  53. struct wavg_desc {
  54. /* Believe it or not, we must decode/recode to account for the
  55. weird MS format */
  56. int secondhalf; /* Are we on the second half */
  57. };
  58. #if __BYTE_ORDER == __LITTLE_ENDIAN
  59. #define htoll(b) (b)
  60. #define htols(b) (b)
  61. #define ltohl(b) (b)
  62. #define ltohs(b) (b)
  63. #else
  64. #if __BYTE_ORDER == __BIG_ENDIAN
  65. #define htoll(b) \
  66. (((((b) ) & 0xFF) << 24) | \
  67. ((( (b) >> 8) & 0xFF) << 16) | \
  68. ((( (b) >> 16) & 0xFF) << 8) | \
  69. ((( (b) >> 24) & 0xFF) ))
  70. #define htols(b) \
  71. (((((b) ) & 0xFF) << 8) | \
  72. ((( (b) >> 8) & 0xFF) ))
  73. #define ltohl(b) htoll(b)
  74. #define ltohs(b) htols(b)
  75. #else
  76. #error "Endianess not defined"
  77. #endif
  78. #endif
  79. static int check_header(FILE *f)
  80. {
  81. int type, size, formtype;
  82. int fmt, hsize, fact;
  83. short format, chans;
  84. int freq;
  85. int data;
  86. if (fread(&type, 1, 4, f) != 4) {
  87. ast_log(LOG_WARNING, "Read failed (type)\n");
  88. return -1;
  89. }
  90. if (fread(&size, 1, 4, f) != 4) {
  91. ast_log(LOG_WARNING, "Read failed (size)\n");
  92. return -1;
  93. }
  94. #if __BYTE_ORDER == __BIG_ENDIAN
  95. size = ltohl(size);
  96. #endif
  97. if (fread(&formtype, 1, 4, f) != 4) {
  98. ast_log(LOG_WARNING, "Read failed (formtype)\n");
  99. return -1;
  100. }
  101. if (memcmp(&type, "RIFF", 4)) {
  102. ast_log(LOG_WARNING, "Does not begin with RIFF\n");
  103. return -1;
  104. }
  105. if (memcmp(&formtype, "WAVE", 4)) {
  106. ast_log(LOG_WARNING, "Does not contain WAVE\n");
  107. return -1;
  108. }
  109. if (fread(&fmt, 1, 4, f) != 4) {
  110. ast_log(LOG_WARNING, "Read failed (fmt)\n");
  111. return -1;
  112. }
  113. if (memcmp(&fmt, "fmt ", 4)) {
  114. ast_log(LOG_WARNING, "Does not say fmt\n");
  115. return -1;
  116. }
  117. if (fread(&hsize, 1, 4, f) != 4) {
  118. ast_log(LOG_WARNING, "Read failed (formtype)\n");
  119. return -1;
  120. }
  121. if (ltohl(hsize) != 20) {
  122. ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
  123. return -1;
  124. }
  125. if (fread(&format, 1, 2, f) != 2) {
  126. ast_log(LOG_WARNING, "Read failed (format)\n");
  127. return -1;
  128. }
  129. if (ltohs(format) != 49) {
  130. ast_log(LOG_WARNING, "Not a GSM file %d\n", ltohs(format));
  131. return -1;
  132. }
  133. if (fread(&chans, 1, 2, f) != 2) {
  134. ast_log(LOG_WARNING, "Read failed (format)\n");
  135. return -1;
  136. }
  137. if (ltohs(chans) != 1) {
  138. ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
  139. return -1;
  140. }
  141. if (fread(&freq, 1, 4, f) != 4) {
  142. ast_log(LOG_WARNING, "Read failed (freq)\n");
  143. return -1;
  144. }
  145. if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
  146. ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
  147. return -1;
  148. }
  149. /* Ignore the byte frequency */
  150. if (fread(&freq, 1, 4, f) != 4) {
  151. ast_log(LOG_WARNING, "Read failed (X_1)\n");
  152. return -1;
  153. }
  154. /* Ignore the two weird fields */
  155. if (fread(&freq, 1, 4, f) != 4) {
  156. ast_log(LOG_WARNING, "Read failed (X_2/X_3)\n");
  157. return -1;
  158. }
  159. /* Ignore the byte frequency */
  160. if (fread(&freq, 1, 4, f) != 4) {
  161. ast_log(LOG_WARNING, "Read failed (Y_1)\n");
  162. return -1;
  163. }
  164. /* Check for the word fact */
  165. if (fread(&fact, 1, 4, f) != 4) {
  166. ast_log(LOG_WARNING, "Read failed (fact)\n");
  167. return -1;
  168. }
  169. if (memcmp(&fact, "fact", 4)) {
  170. ast_log(LOG_WARNING, "Does not say fact\n");
  171. return -1;
  172. }
  173. /* Ignore the "fact value" */
  174. if (fread(&fact, 1, 4, f) != 4) {
  175. ast_log(LOG_WARNING, "Read failed (fact header)\n");
  176. return -1;
  177. }
  178. if (fread(&fact, 1, 4, f) != 4) {
  179. ast_log(LOG_WARNING, "Read failed (fact value)\n");
  180. return -1;
  181. }
  182. /* Check for the word data */
  183. if (fread(&data, 1, 4, f) != 4) {
  184. ast_log(LOG_WARNING, "Read failed (data)\n");
  185. return -1;
  186. }
  187. if (memcmp(&data, "data", 4)) {
  188. ast_log(LOG_WARNING, "Does not say data\n");
  189. return -1;
  190. }
  191. /* Ignore the data length */
  192. if (fread(&data, 1, 4, f) != 4) {
  193. ast_log(LOG_WARNING, "Read failed (data)\n");
  194. return -1;
  195. }
  196. return 0;
  197. }
  198. static int update_header(FILE *f)
  199. {
  200. off_t cur,end,bytes;
  201. int datalen, filelen, samples;
  202. cur = ftello(f);
  203. fseek(f, 0, SEEK_END);
  204. end = ftello(f);
  205. /* in a gsm WAV, data starts 60 bytes in */
  206. bytes = end - MSGSM_DATA_OFFSET;
  207. samples = htoll(bytes / MSGSM_FRAME_SIZE * MSGSM_SAMPLES);
  208. datalen = htoll(bytes);
  209. filelen = htoll(MSGSM_DATA_OFFSET - 8 + bytes);
  210. if (cur < 0) {
  211. ast_log(LOG_WARNING, "Unable to find our position\n");
  212. return -1;
  213. }
  214. if (fseek(f, 4, SEEK_SET)) {
  215. ast_log(LOG_WARNING, "Unable to set our position\n");
  216. return -1;
  217. }
  218. if (fwrite(&filelen, 1, 4, f) != 4) {
  219. ast_log(LOG_WARNING, "Unable to write file size\n");
  220. return -1;
  221. }
  222. if (fseek(f, 48, SEEK_SET)) {
  223. ast_log(LOG_WARNING, "Unable to set our position\n");
  224. return -1;
  225. }
  226. if (fwrite(&samples, 1, 4, f) != 4) {
  227. ast_log(LOG_WARNING, "Unable to write samples\n");
  228. return -1;
  229. }
  230. if (fseek(f, 56, SEEK_SET)) {
  231. ast_log(LOG_WARNING, "Unable to set our position\n");
  232. return -1;
  233. }
  234. if (fwrite(&datalen, 1, 4, f) != 4) {
  235. ast_log(LOG_WARNING, "Unable to write datalen\n");
  236. return -1;
  237. }
  238. if (fseeko(f, cur, SEEK_SET)) {
  239. ast_log(LOG_WARNING, "Unable to return to position\n");
  240. return -1;
  241. }
  242. return 0;
  243. }
  244. static int write_header(FILE *f)
  245. {
  246. /* Samples per second (always 8000 for this format). */
  247. unsigned int sample_rate = htoll(8000);
  248. /* Bytes per second (always 1625 for this format). */
  249. unsigned int byte_sample_rate = htoll(1625);
  250. /* This is the size of the "fmt " subchunk */
  251. unsigned int fmtsize = htoll(20);
  252. /* WAV #49 */
  253. unsigned short fmt = htols(49);
  254. /* Mono = 1 channel */
  255. unsigned short chans = htols(1);
  256. /* Each block of data is exactly 65 bytes in size. */
  257. unsigned int block_align = htoll(MSGSM_FRAME_SIZE);
  258. /* Not actually 2, but rounded up to the nearest bit */
  259. unsigned short bits_per_sample = htols(2);
  260. /* Needed for compressed formats */
  261. unsigned short extra_format = htols(MSGSM_SAMPLES);
  262. /* This is the size of the "fact" subchunk */
  263. unsigned int factsize = htoll(4);
  264. /* Number of samples in the data chunk */
  265. unsigned int num_samples = htoll(0);
  266. /* Number of bytes in the data chunk */
  267. unsigned int size = htoll(0);
  268. /* Write a GSM header, ignoring sizes which will be filled in later */
  269. /* 0: Chunk ID */
  270. if (fwrite("RIFF", 1, 4, f) != 4) {
  271. ast_log(LOG_WARNING, "Unable to write header\n");
  272. return -1;
  273. }
  274. /* 4: Chunk Size */
  275. if (fwrite(&size, 1, 4, f) != 4) {
  276. ast_log(LOG_WARNING, "Unable to write header\n");
  277. return -1;
  278. }
  279. /* 8: Chunk Format */
  280. if (fwrite("WAVE", 1, 4, f) != 4) {
  281. ast_log(LOG_WARNING, "Unable to write header\n");
  282. return -1;
  283. }
  284. /* 12: Subchunk 1: ID */
  285. if (fwrite("fmt ", 1, 4, f) != 4) {
  286. ast_log(LOG_WARNING, "Unable to write header\n");
  287. return -1;
  288. }
  289. /* 16: Subchunk 1: Size (minus 8) */
  290. if (fwrite(&fmtsize, 1, 4, f) != 4) {
  291. ast_log(LOG_WARNING, "Unable to write header\n");
  292. return -1;
  293. }
  294. /* 20: Subchunk 1: Audio format (49) */
  295. if (fwrite(&fmt, 1, 2, f) != 2) {
  296. ast_log(LOG_WARNING, "Unable to write header\n");
  297. return -1;
  298. }
  299. /* 22: Subchunk 1: Number of channels */
  300. if (fwrite(&chans, 1, 2, f) != 2) {
  301. ast_log(LOG_WARNING, "Unable to write header\n");
  302. return -1;
  303. }
  304. /* 24: Subchunk 1: Sample rate */
  305. if (fwrite(&sample_rate, 1, 4, f) != 4) {
  306. ast_log(LOG_WARNING, "Unable to write header\n");
  307. return -1;
  308. }
  309. /* 28: Subchunk 1: Byte rate */
  310. if (fwrite(&byte_sample_rate, 1, 4, f) != 4) {
  311. ast_log(LOG_WARNING, "Unable to write header\n");
  312. return -1;
  313. }
  314. /* 32: Subchunk 1: Block align */
  315. if (fwrite(&block_align, 1, 4, f) != 4) {
  316. ast_log(LOG_WARNING, "Unable to write header\n");
  317. return -1;
  318. }
  319. /* 36: Subchunk 1: Bits per sample */
  320. if (fwrite(&bits_per_sample, 1, 2, f) != 2) {
  321. ast_log(LOG_WARNING, "Unable to write header\n");
  322. return -1;
  323. }
  324. /* 38: Subchunk 1: Extra format bytes */
  325. if (fwrite(&extra_format, 1, 2, f) != 2) {
  326. ast_log(LOG_WARNING, "Unable to write header\n");
  327. return -1;
  328. }
  329. /* 40: Subchunk 2: ID */
  330. if (fwrite("fact", 1, 4, f) != 4) {
  331. ast_log(LOG_WARNING, "Unable to write header\n");
  332. return -1;
  333. }
  334. /* 44: Subchunk 2: Size (minus 8) */
  335. if (fwrite(&factsize, 1, 4, f) != 4) {
  336. ast_log(LOG_WARNING, "Unable to write header\n");
  337. return -1;
  338. }
  339. /* 48: Subchunk 2: Number of samples */
  340. if (fwrite(&num_samples, 1, 4, f) != 4) {
  341. ast_log(LOG_WARNING, "Unable to write header\n");
  342. return -1;
  343. }
  344. /* 52: Subchunk 3: ID */
  345. if (fwrite("data", 1, 4, f) != 4) {
  346. ast_log(LOG_WARNING, "Unable to write header\n");
  347. return -1;
  348. }
  349. /* 56: Subchunk 3: Size */
  350. if (fwrite(&size, 1, 4, f) != 4) {
  351. ast_log(LOG_WARNING, "Unable to write header\n");
  352. return -1;
  353. }
  354. return 0;
  355. }
  356. static int wav_open(struct ast_filestream *s)
  357. {
  358. /* We don't have any header to read or anything really, but
  359. if we did, it would go here. We also might want to check
  360. and be sure it's a valid file. */
  361. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  362. if (check_header(s->f))
  363. return -1;
  364. fs->secondhalf = 0; /* not strictly necessary */
  365. return 0;
  366. }
  367. static int wav_rewrite(struct ast_filestream *s, const char *comment)
  368. {
  369. /* We don't have any header to read or anything really, but
  370. if we did, it would go here. We also might want to check
  371. and be sure it's a valid file. */
  372. if (write_header(s->f))
  373. return -1;
  374. return 0;
  375. }
  376. static void wav_close(struct ast_filestream *s)
  377. {
  378. if (s->mode == O_RDONLY) {
  379. return;
  380. }
  381. if (s->filename) {
  382. update_header(s->f);
  383. }
  384. }
  385. static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
  386. {
  387. /* Send a frame from the file to the appropriate channel */
  388. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  389. s->fr.samples = GSM_SAMPLES;
  390. AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
  391. if (fs->secondhalf) {
  392. /* Just return a frame based on the second GSM frame */
  393. s->fr.data.ptr = (char *)s->fr.data.ptr + GSM_FRAME_SIZE;
  394. s->fr.offset += GSM_FRAME_SIZE;
  395. } else {
  396. /* read and convert */
  397. unsigned char msdata[MSGSM_FRAME_SIZE];
  398. size_t res;
  399. if ((res = fread(msdata, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
  400. if (res && res != 1) {
  401. ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
  402. ast_format_get_name(s->fr.subclass.format), MSGSM_FRAME_SIZE, res,
  403. strerror(errno));
  404. }
  405. return NULL;
  406. }
  407. /* Convert from MS format to two real GSM frames */
  408. conv65(msdata, s->fr.data.ptr);
  409. }
  410. fs->secondhalf = !fs->secondhalf;
  411. *whennext = GSM_SAMPLES;
  412. return &s->fr;
  413. }
  414. static int wav_write(struct ast_filestream *s, struct ast_frame *f)
  415. {
  416. int len;
  417. int size;
  418. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  419. /* XXX this might fail... if the input is a multiple of MSGSM_FRAME_SIZE
  420. * we assume it is already in the correct format.
  421. */
  422. if (!(f->datalen % MSGSM_FRAME_SIZE)) {
  423. size = MSGSM_FRAME_SIZE;
  424. fs->secondhalf = 0;
  425. } else {
  426. size = GSM_FRAME_SIZE;
  427. }
  428. for (len = 0; len < f->datalen ; len += size) {
  429. int res;
  430. unsigned char *src, msdata[MSGSM_FRAME_SIZE];
  431. if (fs->secondhalf) { /* second half of raw gsm to be converted */
  432. memcpy(s->buf + GSM_FRAME_SIZE, f->data.ptr + len, GSM_FRAME_SIZE);
  433. conv66((unsigned char *) s->buf, msdata);
  434. src = msdata;
  435. fs->secondhalf = 0;
  436. } else if (size == GSM_FRAME_SIZE) { /* first half of raw gsm */
  437. memcpy(s->buf, f->data.ptr + len, GSM_FRAME_SIZE);
  438. src = NULL; /* nothing to write */
  439. fs->secondhalf = 1;
  440. } else { /* raw msgsm data */
  441. src = f->data.ptr + len;
  442. }
  443. if (src && (res = fwrite(src, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
  444. ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
  445. return -1;
  446. }
  447. }
  448. return 0;
  449. }
  450. static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
  451. {
  452. off_t offset = 0, min = MSGSM_DATA_OFFSET, distance, max, cur;
  453. struct wavg_desc *s = (struct wavg_desc *)fs->_private;
  454. if ((cur = ftello(fs->f)) < 0) {
  455. ast_log(AST_LOG_WARNING, "Unable to determine current position in WAV filestream %p: %s\n", fs, strerror(errno));
  456. return -1;
  457. }
  458. if (fseeko(fs->f, 0, SEEK_END) < 0) {
  459. ast_log(AST_LOG_WARNING, "Unable to seek to end of WAV filestream %p: %s\n", fs, strerror(errno));
  460. return -1;
  461. }
  462. /* XXX ideally, should round correctly */
  463. if ((max = ftello(fs->f)) < 0) {
  464. ast_log(AST_LOG_WARNING, "Unable to determine max position in WAV filestream %p: %s\n", fs, strerror(errno));
  465. return -1;
  466. }
  467. /* Compute the distance in bytes, rounded to the block size */
  468. distance = (sample_offset/MSGSM_SAMPLES) * MSGSM_FRAME_SIZE;
  469. if (whence == SEEK_SET)
  470. offset = distance + min;
  471. else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
  472. offset = distance + cur;
  473. else if (whence == SEEK_END)
  474. offset = max - distance;
  475. /* always protect against seeking past end of header */
  476. if (offset < min)
  477. offset = min;
  478. if (whence != SEEK_FORCECUR) {
  479. if (offset > max)
  480. offset = max;
  481. } else if (offset > max) {
  482. int i;
  483. fseek(fs->f, 0, SEEK_END);
  484. for (i=0; i< (offset - max) / MSGSM_FRAME_SIZE; i++) {
  485. if (fwrite(msgsm_silence, 1, MSGSM_FRAME_SIZE, fs->f) != MSGSM_FRAME_SIZE) {
  486. ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
  487. }
  488. }
  489. }
  490. s->secondhalf = 0;
  491. return fseeko(fs->f, offset, SEEK_SET);
  492. }
  493. static int wav_trunc(struct ast_filestream *fs)
  494. {
  495. int fd;
  496. off_t cur;
  497. if ((fd = fileno(fs->f)) < 0) {
  498. ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for WAV filestream %p: %s\n", fs, strerror(errno));
  499. return -1;
  500. }
  501. if ((cur = ftello(fs->f)) < 0) {
  502. ast_log(AST_LOG_WARNING, "Unable to determine current position in WAV filestream %p: %s\n", fs, strerror(errno));
  503. return -1;
  504. }
  505. /* Truncate file to current length */
  506. if (ftruncate(fd, cur)) {
  507. return -1;
  508. }
  509. return update_header(fs->f);
  510. }
  511. static off_t wav_tell(struct ast_filestream *fs)
  512. {
  513. off_t offset;
  514. offset = ftello(fs->f);
  515. /* since this will most likely be used later in play or record, lets stick
  516. * to that level of resolution, just even frames boundaries */
  517. return (offset - MSGSM_DATA_OFFSET)/MSGSM_FRAME_SIZE*MSGSM_SAMPLES;
  518. }
  519. static struct ast_format_def wav49_f = {
  520. .name = "wav49",
  521. .exts = "WAV|wav49",
  522. .open = wav_open,
  523. .rewrite = wav_rewrite,
  524. .write = wav_write,
  525. .seek = wav_seek,
  526. .trunc = wav_trunc,
  527. .tell = wav_tell,
  528. .read = wav_read,
  529. .close = wav_close,
  530. .buf_size = 2*GSM_FRAME_SIZE + AST_FRIENDLY_OFFSET,
  531. .desc_size = sizeof(struct wavg_desc),
  532. };
  533. static int load_module(void)
  534. {
  535. wav49_f.format = ast_format_gsm;
  536. if (ast_format_def_register(&wav49_f))
  537. return AST_MODULE_LOAD_DECLINE;
  538. return AST_MODULE_LOAD_SUCCESS;
  539. }
  540. static int unload_module(void)
  541. {
  542. return ast_format_def_unregister(wav49_f.name);
  543. }
  544. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Microsoft WAV format (Proprietary GSM)",
  545. .support_level = AST_MODULE_SUPPORT_CORE,
  546. .load = load_module,
  547. .unload = unload_module,
  548. .load_pri = AST_MODPRI_APP_DEPEND
  549. );