format_wav_gsm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. size = ltohl(size);
  94. if (fread(&formtype, 1, 4, f) != 4) {
  95. ast_log(LOG_WARNING, "Read failed (formtype)\n");
  96. return -1;
  97. }
  98. if (memcmp(&type, "RIFF", 4)) {
  99. ast_log(LOG_WARNING, "Does not begin with RIFF\n");
  100. return -1;
  101. }
  102. if (memcmp(&formtype, "WAVE", 4)) {
  103. ast_log(LOG_WARNING, "Does not contain WAVE\n");
  104. return -1;
  105. }
  106. if (fread(&fmt, 1, 4, f) != 4) {
  107. ast_log(LOG_WARNING, "Read failed (fmt)\n");
  108. return -1;
  109. }
  110. if (memcmp(&fmt, "fmt ", 4)) {
  111. ast_log(LOG_WARNING, "Does not say fmt\n");
  112. return -1;
  113. }
  114. if (fread(&hsize, 1, 4, f) != 4) {
  115. ast_log(LOG_WARNING, "Read failed (formtype)\n");
  116. return -1;
  117. }
  118. if (ltohl(hsize) != 20) {
  119. ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
  120. return -1;
  121. }
  122. if (fread(&format, 1, 2, f) != 2) {
  123. ast_log(LOG_WARNING, "Read failed (format)\n");
  124. return -1;
  125. }
  126. if (ltohs(format) != 49) {
  127. ast_log(LOG_WARNING, "Not a GSM file %d\n", ltohs(format));
  128. return -1;
  129. }
  130. if (fread(&chans, 1, 2, f) != 2) {
  131. ast_log(LOG_WARNING, "Read failed (format)\n");
  132. return -1;
  133. }
  134. if (ltohs(chans) != 1) {
  135. ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
  136. return -1;
  137. }
  138. if (fread(&freq, 1, 4, f) != 4) {
  139. ast_log(LOG_WARNING, "Read failed (freq)\n");
  140. return -1;
  141. }
  142. if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
  143. ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
  144. return -1;
  145. }
  146. /* Ignore the byte frequency */
  147. if (fread(&freq, 1, 4, f) != 4) {
  148. ast_log(LOG_WARNING, "Read failed (X_1)\n");
  149. return -1;
  150. }
  151. /* Ignore the two weird fields */
  152. if (fread(&freq, 1, 4, f) != 4) {
  153. ast_log(LOG_WARNING, "Read failed (X_2/X_3)\n");
  154. return -1;
  155. }
  156. /* Ignore the byte frequency */
  157. if (fread(&freq, 1, 4, f) != 4) {
  158. ast_log(LOG_WARNING, "Read failed (Y_1)\n");
  159. return -1;
  160. }
  161. /* Check for the word fact */
  162. if (fread(&fact, 1, 4, f) != 4) {
  163. ast_log(LOG_WARNING, "Read failed (fact)\n");
  164. return -1;
  165. }
  166. if (memcmp(&fact, "fact", 4)) {
  167. ast_log(LOG_WARNING, "Does not say fact\n");
  168. return -1;
  169. }
  170. /* Ignore the "fact value" */
  171. if (fread(&fact, 1, 4, f) != 4) {
  172. ast_log(LOG_WARNING, "Read failed (fact header)\n");
  173. return -1;
  174. }
  175. if (fread(&fact, 1, 4, f) != 4) {
  176. ast_log(LOG_WARNING, "Read failed (fact value)\n");
  177. return -1;
  178. }
  179. /* Check for the word data */
  180. if (fread(&data, 1, 4, f) != 4) {
  181. ast_log(LOG_WARNING, "Read failed (data)\n");
  182. return -1;
  183. }
  184. if (memcmp(&data, "data", 4)) {
  185. ast_log(LOG_WARNING, "Does not say data\n");
  186. return -1;
  187. }
  188. /* Ignore the data length */
  189. if (fread(&data, 1, 4, f) != 4) {
  190. ast_log(LOG_WARNING, "Read failed (data)\n");
  191. return -1;
  192. }
  193. return 0;
  194. }
  195. static int update_header(FILE *f)
  196. {
  197. off_t cur,end,bytes;
  198. int datalen, filelen, samples;
  199. cur = ftello(f);
  200. fseek(f, 0, SEEK_END);
  201. end = ftello(f);
  202. /* in a gsm WAV, data starts 60 bytes in */
  203. bytes = end - MSGSM_DATA_OFFSET;
  204. samples = htoll(bytes / MSGSM_FRAME_SIZE * MSGSM_SAMPLES);
  205. datalen = htoll(bytes);
  206. filelen = htoll(MSGSM_DATA_OFFSET - 8 + bytes);
  207. if (cur < 0) {
  208. ast_log(LOG_WARNING, "Unable to find our position\n");
  209. return -1;
  210. }
  211. if (fseek(f, 4, SEEK_SET)) {
  212. ast_log(LOG_WARNING, "Unable to set our position\n");
  213. return -1;
  214. }
  215. if (fwrite(&filelen, 1, 4, f) != 4) {
  216. ast_log(LOG_WARNING, "Unable to write file size\n");
  217. return -1;
  218. }
  219. if (fseek(f, 48, SEEK_SET)) {
  220. ast_log(LOG_WARNING, "Unable to set our position\n");
  221. return -1;
  222. }
  223. if (fwrite(&samples, 1, 4, f) != 4) {
  224. ast_log(LOG_WARNING, "Unable to write samples\n");
  225. return -1;
  226. }
  227. if (fseek(f, 56, SEEK_SET)) {
  228. ast_log(LOG_WARNING, "Unable to set our position\n");
  229. return -1;
  230. }
  231. if (fwrite(&datalen, 1, 4, f) != 4) {
  232. ast_log(LOG_WARNING, "Unable to write datalen\n");
  233. return -1;
  234. }
  235. if (fseeko(f, cur, SEEK_SET)) {
  236. ast_log(LOG_WARNING, "Unable to return to position\n");
  237. return -1;
  238. }
  239. return 0;
  240. }
  241. static int write_header(FILE *f)
  242. {
  243. /* Samples per second (always 8000 for this format). */
  244. unsigned int sample_rate = htoll(8000);
  245. /* Bytes per second (always 1625 for this format). */
  246. unsigned int byte_sample_rate = htoll(1625);
  247. /* This is the size of the "fmt " subchunk */
  248. unsigned int fmtsize = htoll(20);
  249. /* WAV #49 */
  250. unsigned short fmt = htols(49);
  251. /* Mono = 1 channel */
  252. unsigned short chans = htols(1);
  253. /* Each block of data is exactly 65 bytes in size. */
  254. unsigned int block_align = htoll(MSGSM_FRAME_SIZE);
  255. /* Not actually 2, but rounded up to the nearest bit */
  256. unsigned short bits_per_sample = htols(2);
  257. /* Needed for compressed formats */
  258. unsigned short extra_format = htols(MSGSM_SAMPLES);
  259. /* This is the size of the "fact" subchunk */
  260. unsigned int factsize = htoll(4);
  261. /* Number of samples in the data chunk */
  262. unsigned int num_samples = htoll(0);
  263. /* Number of bytes in the data chunk */
  264. unsigned int size = htoll(0);
  265. /* Write a GSM header, ignoring sizes which will be filled in later */
  266. /* 0: Chunk ID */
  267. if (fwrite("RIFF", 1, 4, f) != 4) {
  268. ast_log(LOG_WARNING, "Unable to write header\n");
  269. return -1;
  270. }
  271. /* 4: Chunk Size */
  272. if (fwrite(&size, 1, 4, f) != 4) {
  273. ast_log(LOG_WARNING, "Unable to write header\n");
  274. return -1;
  275. }
  276. /* 8: Chunk Format */
  277. if (fwrite("WAVE", 1, 4, f) != 4) {
  278. ast_log(LOG_WARNING, "Unable to write header\n");
  279. return -1;
  280. }
  281. /* 12: Subchunk 1: ID */
  282. if (fwrite("fmt ", 1, 4, f) != 4) {
  283. ast_log(LOG_WARNING, "Unable to write header\n");
  284. return -1;
  285. }
  286. /* 16: Subchunk 1: Size (minus 8) */
  287. if (fwrite(&fmtsize, 1, 4, f) != 4) {
  288. ast_log(LOG_WARNING, "Unable to write header\n");
  289. return -1;
  290. }
  291. /* 20: Subchunk 1: Audio format (49) */
  292. if (fwrite(&fmt, 1, 2, f) != 2) {
  293. ast_log(LOG_WARNING, "Unable to write header\n");
  294. return -1;
  295. }
  296. /* 22: Subchunk 1: Number of channels */
  297. if (fwrite(&chans, 1, 2, f) != 2) {
  298. ast_log(LOG_WARNING, "Unable to write header\n");
  299. return -1;
  300. }
  301. /* 24: Subchunk 1: Sample rate */
  302. if (fwrite(&sample_rate, 1, 4, f) != 4) {
  303. ast_log(LOG_WARNING, "Unable to write header\n");
  304. return -1;
  305. }
  306. /* 28: Subchunk 1: Byte rate */
  307. if (fwrite(&byte_sample_rate, 1, 4, f) != 4) {
  308. ast_log(LOG_WARNING, "Unable to write header\n");
  309. return -1;
  310. }
  311. /* 32: Subchunk 1: Block align */
  312. if (fwrite(&block_align, 1, 4, f) != 4) {
  313. ast_log(LOG_WARNING, "Unable to write header\n");
  314. return -1;
  315. }
  316. /* 36: Subchunk 1: Bits per sample */
  317. if (fwrite(&bits_per_sample, 1, 2, f) != 2) {
  318. ast_log(LOG_WARNING, "Unable to write header\n");
  319. return -1;
  320. }
  321. /* 38: Subchunk 1: Extra format bytes */
  322. if (fwrite(&extra_format, 1, 2, f) != 2) {
  323. ast_log(LOG_WARNING, "Unable to write header\n");
  324. return -1;
  325. }
  326. /* 40: Subchunk 2: ID */
  327. if (fwrite("fact", 1, 4, f) != 4) {
  328. ast_log(LOG_WARNING, "Unable to write header\n");
  329. return -1;
  330. }
  331. /* 44: Subchunk 2: Size (minus 8) */
  332. if (fwrite(&factsize, 1, 4, f) != 4) {
  333. ast_log(LOG_WARNING, "Unable to write header\n");
  334. return -1;
  335. }
  336. /* 48: Subchunk 2: Number of samples */
  337. if (fwrite(&num_samples, 1, 4, f) != 4) {
  338. ast_log(LOG_WARNING, "Unable to write header\n");
  339. return -1;
  340. }
  341. /* 52: Subchunk 3: ID */
  342. if (fwrite("data", 1, 4, f) != 4) {
  343. ast_log(LOG_WARNING, "Unable to write header\n");
  344. return -1;
  345. }
  346. /* 56: Subchunk 3: Size */
  347. if (fwrite(&size, 1, 4, f) != 4) {
  348. ast_log(LOG_WARNING, "Unable to write header\n");
  349. return -1;
  350. }
  351. return 0;
  352. }
  353. static int wav_open(struct ast_filestream *s)
  354. {
  355. /* We don't have any header to read or anything really, but
  356. if we did, it would go here. We also might want to check
  357. and be sure it's a valid file. */
  358. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  359. if (check_header(s->f))
  360. return -1;
  361. fs->secondhalf = 0; /* not strictly necessary */
  362. return 0;
  363. }
  364. static int wav_rewrite(struct ast_filestream *s, const char *comment)
  365. {
  366. /* We don't have any header to read or anything really, but
  367. if we did, it would go here. We also might want to check
  368. and be sure it's a valid file. */
  369. if (write_header(s->f))
  370. return -1;
  371. return 0;
  372. }
  373. static void wav_close(struct ast_filestream *s)
  374. {
  375. if (s->mode == O_RDONLY) {
  376. return;
  377. }
  378. if (s->filename) {
  379. update_header(s->f);
  380. }
  381. }
  382. static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
  383. {
  384. /* Send a frame from the file to the appropriate channel */
  385. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  386. s->fr.frametype = AST_FRAME_VOICE;
  387. ast_format_set(&s->fr.subclass.format, AST_FORMAT_GSM, 0);
  388. s->fr.offset = AST_FRIENDLY_OFFSET;
  389. s->fr.samples = GSM_SAMPLES;
  390. s->fr.mallocd = 0;
  391. AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
  392. if (fs->secondhalf) {
  393. /* Just return a frame based on the second GSM frame */
  394. s->fr.data.ptr = (char *)s->fr.data.ptr + GSM_FRAME_SIZE;
  395. s->fr.offset += GSM_FRAME_SIZE;
  396. } else {
  397. /* read and convert */
  398. unsigned char msdata[MSGSM_FRAME_SIZE];
  399. int res;
  400. if ((res = fread(msdata, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
  401. if (res && (res != 1))
  402. ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
  403. return NULL;
  404. }
  405. /* Convert from MS format to two real GSM frames */
  406. conv65(msdata, s->fr.data.ptr);
  407. }
  408. fs->secondhalf = !fs->secondhalf;
  409. *whennext = GSM_SAMPLES;
  410. return &s->fr;
  411. }
  412. static int wav_write(struct ast_filestream *s, struct ast_frame *f)
  413. {
  414. int len;
  415. int size;
  416. struct wavg_desc *fs = (struct wavg_desc *)s->_private;
  417. if (f->frametype != AST_FRAME_VOICE) {
  418. ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
  419. return -1;
  420. }
  421. if (f->subclass.format.id != AST_FORMAT_GSM) {
  422. ast_log(LOG_WARNING, "Asked to write non-GSM frame (%s)!\n", ast_getformatname(&f->subclass.format));
  423. return -1;
  424. }
  425. /* XXX this might fail... if the input is a multiple of MSGSM_FRAME_SIZE
  426. * we assume it is already in the correct format.
  427. */
  428. if (!(f->datalen % MSGSM_FRAME_SIZE)) {
  429. size = MSGSM_FRAME_SIZE;
  430. fs->secondhalf = 0;
  431. } else {
  432. size = GSM_FRAME_SIZE;
  433. }
  434. for (len = 0; len < f->datalen ; len += size) {
  435. int res;
  436. unsigned char *src, msdata[MSGSM_FRAME_SIZE];
  437. if (fs->secondhalf) { /* second half of raw gsm to be converted */
  438. memcpy(s->buf + GSM_FRAME_SIZE, f->data.ptr + len, GSM_FRAME_SIZE);
  439. conv66((unsigned char *) s->buf, msdata);
  440. src = msdata;
  441. fs->secondhalf = 0;
  442. } else if (size == GSM_FRAME_SIZE) { /* first half of raw gsm */
  443. memcpy(s->buf, f->data.ptr + len, GSM_FRAME_SIZE);
  444. src = NULL; /* nothing to write */
  445. fs->secondhalf = 1;
  446. } else { /* raw msgsm data */
  447. src = f->data.ptr + len;
  448. }
  449. if (src && (res = fwrite(src, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
  450. ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
  451. return -1;
  452. }
  453. }
  454. return 0;
  455. }
  456. static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
  457. {
  458. off_t offset = 0, min = MSGSM_DATA_OFFSET, distance, max, cur;
  459. struct wavg_desc *s = (struct wavg_desc *)fs->_private;
  460. if ((cur = ftello(fs->f)) < 0) {
  461. ast_log(AST_LOG_WARNING, "Unable to determine current position in WAV filestream %p: %s\n", fs, strerror(errno));
  462. return -1;
  463. }
  464. if (fseeko(fs->f, 0, SEEK_END) < 0) {
  465. ast_log(AST_LOG_WARNING, "Unable to seek to end of WAV filestream %p: %s\n", fs, strerror(errno));
  466. return -1;
  467. }
  468. /* XXX ideally, should round correctly */
  469. if ((max = ftello(fs->f)) < 0) {
  470. ast_log(AST_LOG_WARNING, "Unable to determine max position in WAV filestream %p: %s\n", fs, strerror(errno));
  471. return -1;
  472. }
  473. /* Compute the distance in bytes, rounded to the block size */
  474. distance = (sample_offset/MSGSM_SAMPLES) * MSGSM_FRAME_SIZE;
  475. if (whence == SEEK_SET)
  476. offset = distance + min;
  477. else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
  478. offset = distance + cur;
  479. else if (whence == SEEK_END)
  480. offset = max - distance;
  481. /* always protect against seeking past end of header */
  482. if (offset < min)
  483. offset = min;
  484. if (whence != SEEK_FORCECUR) {
  485. if (offset > max)
  486. offset = max;
  487. } else if (offset > max) {
  488. int i;
  489. fseek(fs->f, 0, SEEK_END);
  490. for (i=0; i< (offset - max) / MSGSM_FRAME_SIZE; i++) {
  491. if (!fwrite(msgsm_silence, 1, MSGSM_FRAME_SIZE, fs->f)) {
  492. ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
  493. }
  494. }
  495. }
  496. s->secondhalf = 0;
  497. return fseeko(fs->f, offset, SEEK_SET);
  498. }
  499. static int wav_trunc(struct ast_filestream *fs)
  500. {
  501. int fd;
  502. off_t cur;
  503. if ((fd = fileno(fs->f)) < 0) {
  504. ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for WAV filestream %p: %s\n", fs, strerror(errno));
  505. return -1;
  506. }
  507. if ((cur = ftello(fs->f)) < 0) {
  508. ast_log(AST_LOG_WARNING, "Unable to determine current position in WAV filestream %p: %s\n", fs, strerror(errno));
  509. return -1;
  510. }
  511. /* Truncate file to current length */
  512. if (ftruncate(fd, cur)) {
  513. return -1;
  514. }
  515. return update_header(fs->f);
  516. }
  517. static off_t wav_tell(struct ast_filestream *fs)
  518. {
  519. off_t offset;
  520. offset = ftello(fs->f);
  521. /* since this will most likely be used later in play or record, lets stick
  522. * to that level of resolution, just even frames boundaries */
  523. return (offset - MSGSM_DATA_OFFSET)/MSGSM_FRAME_SIZE*MSGSM_SAMPLES;
  524. }
  525. static struct ast_format_def wav49_f = {
  526. .name = "wav49",
  527. .exts = "WAV|wav49",
  528. .open = wav_open,
  529. .rewrite = wav_rewrite,
  530. .write = wav_write,
  531. .seek = wav_seek,
  532. .trunc = wav_trunc,
  533. .tell = wav_tell,
  534. .read = wav_read,
  535. .close = wav_close,
  536. .buf_size = 2*GSM_FRAME_SIZE + AST_FRIENDLY_OFFSET,
  537. .desc_size = sizeof(struct wavg_desc),
  538. };
  539. static int load_module(void)
  540. {
  541. ast_format_set(&wav49_f.format, AST_FORMAT_GSM, 0);
  542. if (ast_format_def_register(&wav49_f))
  543. return AST_MODULE_LOAD_FAILURE;
  544. return AST_MODULE_LOAD_SUCCESS;
  545. }
  546. static int unload_module(void)
  547. {
  548. return ast_format_def_unregister(wav49_f.name);
  549. }
  550. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Microsoft WAV format (Proprietary GSM)",
  551. .load = load_module,
  552. .unload = unload_module,
  553. .load_pri = AST_MODPRI_APP_DEPEND
  554. );