format_wav_gsm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 "msgsm.h"
  37. /* Some Ideas for this code came from makewave.c by Jeffrey Chilton */
  38. /* Portions of the conversion code are by guido@sienanet.it */
  39. #define GSM_FRAME_SIZE 33
  40. #define MSGSM_FRAME_SIZE 65
  41. #define MSGSM_DATA_OFFSET 60 /* offset of data bytes */
  42. #define GSM_SAMPLES 160 /* samples in a GSM block */
  43. #define MSGSM_SAMPLES (2*GSM_SAMPLES) /* samples in an MSGSM block */
  44. /* begin binary data: */
  45. static char msgsm_silence[] = /* 65 */
  46. {0x48,0x17,0xD6,0x84,0x02,0x80,0x24,0x49,0x92,0x24,0x89,0x02,0x80,0x24,0x49
  47. ,0x92,0x24,0x89,0x02,0x80,0x24,0x49,0x92,0x24,0x89,0x02,0x80,0x24,0x49,0x92
  48. ,0x24,0x09,0x82,0x74,0x61,0x4D,0x28,0x00,0x48,0x92,0x24,0x49,0x92,0x28,0x00
  49. ,0x48,0x92,0x24,0x49,0x92,0x28,0x00,0x48,0x92,0x24,0x49,0x92,0x28,0x00,0x48
  50. ,0x92,0x24,0x49,0x92,0x00};
  51. /* end binary data. size = 65 bytes */
  52. struct wavg_desc {
  53. /* Believe it or not, we must decode/recode to account for the
  54. weird MS format */
  55. int secondhalf; /* Are we on the second half */
  56. };
  57. #if __BYTE_ORDER == __LITTLE_ENDIAN
  58. #define htoll(b) (b)
  59. #define htols(b) (b)
  60. #define ltohl(b) (b)
  61. #define ltohs(b) (b)
  62. #else
  63. #if __BYTE_ORDER == __BIG_ENDIAN
  64. #define htoll(b) \
  65. (((((b) ) & 0xFF) << 24) | \
  66. ((( (b) >> 8) & 0xFF) << 16) | \
  67. ((( (b) >> 16) & 0xFF) << 8) | \
  68. ((( (b) >> 24) & 0xFF) ))
  69. #define htols(b) \
  70. (((((b) ) & 0xFF) << 8) | \
  71. ((( (b) >> 8) & 0xFF) ))
  72. #define ltohl(b) htoll(b)
  73. #define ltohs(b) htols(b)
  74. #else
  75. #error "Endianess not defined"
  76. #endif
  77. #endif
  78. static int check_header(FILE *f)
  79. {
  80. int type, size, formtype;
  81. int fmt, hsize, fact;
  82. short format, chans;
  83. int freq;
  84. int data;
  85. if (fread(&type, 1, 4, f) != 4) {
  86. ast_log(LOG_WARNING, "Read failed (type)\n");
  87. return -1;
  88. }
  89. if (fread(&size, 1, 4, f) != 4) {
  90. ast_log(LOG_WARNING, "Read failed (size)\n");
  91. return -1;
  92. }
  93. #if __BYTE_ORDER == __BIG_ENDIAN
  94. size = ltohl(size);
  95. #endif
  96. if (fread(&formtype, 1, 4, f) != 4) {
  97. ast_log(LOG_WARNING, "Read failed (formtype)\n");
  98. return -1;
  99. }
  100. if (memcmp(&type, "RIFF", 4)) {
  101. ast_log(LOG_WARNING, "Does not begin with RIFF\n");
  102. return -1;
  103. }
  104. if (memcmp(&formtype, "WAVE", 4)) {
  105. ast_log(LOG_WARNING, "Does not contain WAVE\n");
  106. return -1;
  107. }
  108. if (fread(&fmt, 1, 4, f) != 4) {
  109. ast_log(LOG_WARNING, "Read failed (fmt)\n");
  110. return -1;
  111. }
  112. if (memcmp(&fmt, "fmt ", 4)) {
  113. ast_log(LOG_WARNING, "Does not say fmt\n");
  114. return -1;
  115. }
  116. if (fread(&hsize, 1, 4, f) != 4) {
  117. ast_log(LOG_WARNING, "Read failed (formtype)\n");
  118. return -1;
  119. }
  120. if (ltohl(hsize) != 20) {
  121. ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
  122. return -1;
  123. }
  124. if (fread(&format, 1, 2, f) != 2) {
  125. ast_log(LOG_WARNING, "Read failed (format)\n");
  126. return -1;
  127. }
  128. if (ltohs(format) != 49) {
  129. ast_log(LOG_WARNING, "Not a GSM file %d\n", ltohs(format));
  130. return -1;
  131. }
  132. if (fread(&chans, 1, 2, f) != 2) {
  133. ast_log(LOG_WARNING, "Read failed (format)\n");
  134. return -1;
  135. }
  136. if (ltohs(chans) != 1) {
  137. ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
  138. return -1;
  139. }
  140. if (fread(&freq, 1, 4, f) != 4) {
  141. ast_log(LOG_WARNING, "Read failed (freq)\n");
  142. return -1;
  143. }
  144. if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
  145. ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
  146. return -1;
  147. }
  148. /* Ignore the byte frequency */
  149. if (fread(&freq, 1, 4, f) != 4) {
  150. ast_log(LOG_WARNING, "Read failed (X_1)\n");
  151. return -1;
  152. }
  153. /* Ignore the two weird fields */
  154. if (fread(&freq, 1, 4, f) != 4) {
  155. ast_log(LOG_WARNING, "Read failed (X_2/X_3)\n");
  156. return -1;
  157. }
  158. /* Ignore the byte frequency */
  159. if (fread(&freq, 1, 4, f) != 4) {
  160. ast_log(LOG_WARNING, "Read failed (Y_1)\n");
  161. return -1;
  162. }
  163. /* Check for the word fact */
  164. if (fread(&fact, 1, 4, f) != 4) {
  165. ast_log(LOG_WARNING, "Read failed (fact)\n");
  166. return -1;
  167. }
  168. if (memcmp(&fact, "fact", 4)) {
  169. ast_log(LOG_WARNING, "Does not say fact\n");
  170. return -1;
  171. }
  172. /* Ignore the "fact value" */
  173. if (fread(&fact, 1, 4, f) != 4) {
  174. ast_log(LOG_WARNING, "Read failed (fact header)\n");
  175. return -1;
  176. }
  177. if (fread(&fact, 1, 4, f) != 4) {
  178. ast_log(LOG_WARNING, "Read failed (fact value)\n");
  179. return -1;
  180. }
  181. /* Check for the word data */
  182. if (fread(&data, 1, 4, f) != 4) {
  183. ast_log(LOG_WARNING, "Read failed (data)\n");
  184. return -1;
  185. }
  186. if (memcmp(&data, "data", 4)) {
  187. ast_log(LOG_WARNING, "Does not say data\n");
  188. return -1;
  189. }
  190. /* Ignore the data length */
  191. if (fread(&data, 1, 4, f) != 4) {
  192. ast_log(LOG_WARNING, "Read failed (data)\n");
  193. return -1;
  194. }
  195. return 0;
  196. }
  197. static int update_header(FILE *f)
  198. {
  199. off_t cur,end,bytes;
  200. int datalen, filelen, samples;
  201. cur = ftello(f);
  202. fseek(f, 0, SEEK_END);
  203. end = ftello(f);
  204. /* in a gsm WAV, data starts 60 bytes in */
  205. bytes = end - MSGSM_DATA_OFFSET;
  206. samples = htoll(bytes / MSGSM_FRAME_SIZE * MSGSM_SAMPLES);
  207. datalen = htoll(bytes);
  208. filelen = htoll(MSGSM_DATA_OFFSET - 8 + bytes);
  209. if (cur < 0) {
  210. ast_log(LOG_WARNING, "Unable to find our position\n");
  211. return -1;
  212. }
  213. if (fseek(f, 4, SEEK_SET)) {
  214. ast_log(LOG_WARNING, "Unable to set our position\n");
  215. return -1;
  216. }
  217. if (fwrite(&filelen, 1, 4, f) != 4) {
  218. ast_log(LOG_WARNING, "Unable to write file size\n");
  219. return -1;
  220. }
  221. if (fseek(f, 48, SEEK_SET)) {
  222. ast_log(LOG_WARNING, "Unable to set our position\n");
  223. return -1;
  224. }
  225. if (fwrite(&samples, 1, 4, f) != 4) {
  226. ast_log(LOG_WARNING, "Unable to write samples\n");
  227. return -1;
  228. }
  229. if (fseek(f, 56, SEEK_SET)) {
  230. ast_log(LOG_WARNING, "Unable to set our position\n");
  231. return -1;
  232. }
  233. if (fwrite(&datalen, 1, 4, f) != 4) {
  234. ast_log(LOG_WARNING, "Unable to write datalen\n");
  235. return -1;
  236. }
  237. if (fseeko(f, cur, SEEK_SET)) {
  238. ast_log(LOG_WARNING, "Unable to return to position\n");
  239. return -1;
  240. }
  241. return 0;
  242. }
  243. static int write_header(FILE *f)
  244. {
  245. /* Samples per second (always 8000 for this format). */
  246. unsigned int sample_rate = htoll(8000);
  247. /* Bytes per second (always 1625 for this format). */
  248. unsigned int byte_sample_rate = htoll(1625);
  249. /* This is the size of the "fmt " subchunk */
  250. unsigned int fmtsize = htoll(20);
  251. /* WAV #49 */
  252. unsigned short fmt = htols(49);
  253. /* Mono = 1 channel */
  254. unsigned short chans = htols(1);
  255. /* Each block of data is exactly 65 bytes in size. */
  256. unsigned int block_align = htoll(MSGSM_FRAME_SIZE);
  257. /* Not actually 2, but rounded up to the nearest bit */
  258. unsigned short bits_per_sample = htols(2);
  259. /* Needed for compressed formats */
  260. unsigned short extra_format = htols(MSGSM_SAMPLES);
  261. /* This is the size of the "fact" subchunk */
  262. unsigned int factsize = htoll(4);
  263. /* Number of samples in the data chunk */
  264. unsigned int num_samples = htoll(0);
  265. /* Number of bytes in the data chunk */
  266. unsigned int size = htoll(0);
  267. /* Write a GSM header, ignoring sizes which will be filled in later */
  268. /* 0: Chunk ID */
  269. if (fwrite("RIFF", 1, 4, f) != 4) {
  270. ast_log(LOG_WARNING, "Unable to write header\n");
  271. return -1;
  272. }
  273. /* 4: Chunk Size */
  274. if (fwrite(&size, 1, 4, f) != 4) {
  275. ast_log(LOG_WARNING, "Unable to write header\n");
  276. return -1;
  277. }
  278. /* 8: Chunk Format */
  279. if (fwrite("WAVE", 1, 4, f) != 4) {
  280. ast_log(LOG_WARNING, "Unable to write header\n");
  281. return -1;
  282. }
  283. /* 12: Subchunk 1: ID */
  284. if (fwrite("fmt ", 1, 4, f) != 4) {
  285. ast_log(LOG_WARNING, "Unable to write header\n");
  286. return -1;
  287. }
  288. /* 16: Subchunk 1: Size (minus 8) */
  289. if (fwrite(&fmtsize, 1, 4, f) != 4) {
  290. ast_log(LOG_WARNING, "Unable to write header\n");
  291. return -1;
  292. }
  293. /* 20: Subchunk 1: Audio format (49) */
  294. if (fwrite(&fmt, 1, 2, f) != 2) {
  295. ast_log(LOG_WARNING, "Unable to write header\n");
  296. return -1;
  297. }
  298. /* 22: Subchunk 1: Number of channels */
  299. if (fwrite(&chans, 1, 2, f) != 2) {
  300. ast_log(LOG_WARNING, "Unable to write header\n");
  301. return -1;
  302. }
  303. /* 24: Subchunk 1: Sample rate */
  304. if (fwrite(&sample_rate, 1, 4, f) != 4) {
  305. ast_log(LOG_WARNING, "Unable to write header\n");
  306. return -1;
  307. }
  308. /* 28: Subchunk 1: Byte rate */
  309. if (fwrite(&byte_sample_rate, 1, 4, f) != 4) {
  310. ast_log(LOG_WARNING, "Unable to write header\n");
  311. return -1;
  312. }
  313. /* 32: Subchunk 1: Block align */
  314. if (fwrite(&block_align, 1, 4, f) != 4) {
  315. ast_log(LOG_WARNING, "Unable to write header\n");
  316. return -1;
  317. }
  318. /* 36: Subchunk 1: Bits per sample */
  319. if (fwrite(&bits_per_sample, 1, 2, f) != 2) {
  320. ast_log(LOG_WARNING, "Unable to write header\n");
  321. return -1;
  322. }
  323. /* 38: Subchunk 1: Extra format bytes */
  324. if (fwrite(&extra_format, 1, 2, f) != 2) {
  325. ast_log(LOG_WARNING, "Unable to write header\n");
  326. return -1;
  327. }
  328. /* 40: Subchunk 2: ID */
  329. if (fwrite("fact", 1, 4, f) != 4) {
  330. ast_log(LOG_WARNING, "Unable to write header\n");
  331. return -1;
  332. }
  333. /* 44: Subchunk 2: Size (minus 8) */
  334. if (fwrite(&factsize, 1, 4, f) != 4) {
  335. ast_log(LOG_WARNING, "Unable to write header\n");
  336. return -1;
  337. }
  338. /* 48: Subchunk 2: Number of samples */
  339. if (fwrite(&num_samples, 1, 4, f) != 4) {
  340. ast_log(LOG_WARNING, "Unable to write header\n");
  341. return -1;
  342. }
  343. /* 52: Subchunk 3: ID */
  344. if (fwrite("data", 1, 4, f) != 4) {
  345. ast_log(LOG_WARNING, "Unable to write header\n");
  346. return -1;
  347. }
  348. /* 56: Subchunk 3: Size */
  349. if (fwrite(&size, 1, 4, f) != 4) {
  350. ast_log(LOG_WARNING, "Unable to write header\n");
  351. return -1;
  352. }
  353. return 0;
  354. }
  355. static int wav_open(struct ast_filestream *s)
  356. {
  357. /* We don't have any header to read or anything really, but
  358. if we did, it would go here. We also might want to check
  359. and be sure it's a valid file. */
  360. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  361. if (check_header(s->f))
  362. return -1;
  363. fs->secondhalf = 0; /* not strictly necessary */
  364. return 0;
  365. }
  366. static int wav_rewrite(struct ast_filestream *s, const char *comment)
  367. {
  368. /* We don't have any header to read or anything really, but
  369. if we did, it would go here. We also might want to check
  370. and be sure it's a valid file. */
  371. if (write_header(s->f))
  372. return -1;
  373. return 0;
  374. }
  375. static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
  376. {
  377. /* Send a frame from the file to the appropriate channel */
  378. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  379. s->fr.frametype = AST_FRAME_VOICE;
  380. ast_format_set(&s->fr.subclass.format, AST_FORMAT_GSM, 0);
  381. s->fr.offset = AST_FRIENDLY_OFFSET;
  382. s->fr.samples = GSM_SAMPLES;
  383. s->fr.mallocd = 0;
  384. AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
  385. if (fs->secondhalf) {
  386. /* Just return a frame based on the second GSM frame */
  387. s->fr.data.ptr = (char *)s->fr.data.ptr + GSM_FRAME_SIZE;
  388. s->fr.offset += GSM_FRAME_SIZE;
  389. } else {
  390. /* read and convert */
  391. unsigned char msdata[MSGSM_FRAME_SIZE];
  392. int res;
  393. if ((res = fread(msdata, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
  394. if (res && (res != 1))
  395. ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
  396. return NULL;
  397. }
  398. /* Convert from MS format to two real GSM frames */
  399. conv65(msdata, s->fr.data.ptr);
  400. }
  401. fs->secondhalf = !fs->secondhalf;
  402. *whennext = GSM_SAMPLES;
  403. return &s->fr;
  404. }
  405. static int wav_write(struct ast_filestream *s, struct ast_frame *f)
  406. {
  407. int len;
  408. int size;
  409. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  410. if (f->frametype != AST_FRAME_VOICE) {
  411. ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
  412. return -1;
  413. }
  414. if (f->subclass.format.id != AST_FORMAT_GSM) {
  415. ast_log(LOG_WARNING, "Asked to write non-GSM frame (%s)!\n", ast_getformatname(&f->subclass.format));
  416. return -1;
  417. }
  418. /* XXX this might fail... if the input is a multiple of MSGSM_FRAME_SIZE
  419. * we assume it is already in the correct format.
  420. */
  421. if (!(f->datalen % MSGSM_FRAME_SIZE)) {
  422. size = MSGSM_FRAME_SIZE;
  423. fs->secondhalf = 0;
  424. } else {
  425. size = GSM_FRAME_SIZE;
  426. }
  427. for (len = 0; len < f->datalen ; len += size) {
  428. int res;
  429. unsigned char *src, msdata[MSGSM_FRAME_SIZE];
  430. if (fs->secondhalf) { /* second half of raw gsm to be converted */
  431. memcpy(s->buf + GSM_FRAME_SIZE, f->data.ptr + len, GSM_FRAME_SIZE);
  432. conv66((unsigned char *) s->buf, msdata);
  433. src = msdata;
  434. fs->secondhalf = 0;
  435. } else if (size == GSM_FRAME_SIZE) { /* first half of raw gsm */
  436. memcpy(s->buf, f->data.ptr + len, GSM_FRAME_SIZE);
  437. src = NULL; /* nothing to write */
  438. fs->secondhalf = 1;
  439. } else { /* raw msgsm data */
  440. src = f->data.ptr + len;
  441. }
  442. if (src && (res = fwrite(src, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
  443. ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
  444. return -1;
  445. }
  446. update_header(s->f); /* XXX inefficient! */
  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)) {
  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. .buf_size = 2*GSM_FRAME_SIZE + AST_FRIENDLY_OFFSET,
  530. .desc_size = sizeof(struct wavg_desc),
  531. };
  532. static int load_module(void)
  533. {
  534. ast_format_set(&wav49_f.format, AST_FORMAT_GSM, 0);
  535. if (ast_format_def_register(&wav49_f))
  536. return AST_MODULE_LOAD_FAILURE;
  537. return AST_MODULE_LOAD_SUCCESS;
  538. }
  539. static int unload_module(void)
  540. {
  541. return ast_format_def_unregister(wav49_f.name);
  542. }
  543. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Microsoft WAV format (Proprietary GSM)",
  544. .load = load_module,
  545. .unload = unload_module,
  546. .load_pri = AST_MODPRI_APP_DEPEND
  547. );