You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
19KB

  1. /*
  2. * FLAC (Free Lossless Audio Codec) decoder
  3. * Copyright (c) 2003 Alex Beregszaszi
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file flacdec.c
  23. * FLAC (Free Lossless Audio Codec) decoder
  24. * @author Alex Beregszaszi
  25. *
  26. * For more information on the FLAC format, visit:
  27. * http://flac.sourceforge.net/
  28. *
  29. * This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed
  30. * through, starting from the initial 'fLaC' signature; or by passing the
  31. * 34-byte streaminfo structure through avctx->extradata[_size] followed
  32. * by data starting with the 0xFFF8 marker.
  33. */
  34. #include <limits.h>
  35. #define ALT_BITSTREAM_READER
  36. #include "libavutil/crc.h"
  37. #include "avcodec.h"
  38. #include "bitstream.h"
  39. #include "golomb.h"
  40. #include "flac.h"
  41. #undef NDEBUG
  42. #include <assert.h>
  43. #define MAX_CHANNELS 8
  44. #define MAX_BLOCKSIZE 65535
  45. #define FLAC_STREAMINFO_SIZE 34
  46. enum decorrelation_type {
  47. INDEPENDENT,
  48. LEFT_SIDE,
  49. RIGHT_SIDE,
  50. MID_SIDE,
  51. };
  52. typedef struct FLACContext {
  53. FLACSTREAMINFO
  54. AVCodecContext *avctx;
  55. GetBitContext gb;
  56. int blocksize/*, last_blocksize*/;
  57. int curr_bps;
  58. enum decorrelation_type decorrelation;
  59. int32_t *decoded[MAX_CHANNELS];
  60. uint8_t *bitstream;
  61. unsigned int bitstream_size;
  62. unsigned int bitstream_index;
  63. unsigned int allocated_bitstream_size;
  64. } FLACContext;
  65. #define METADATA_TYPE_STREAMINFO 0
  66. static const int sample_rate_table[] =
  67. { 0,
  68. 88200, 176400, 192000,
  69. 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
  70. 0, 0, 0, 0 };
  71. static const int sample_size_table[] =
  72. { 0, 8, 12, 0, 16, 20, 24, 0 };
  73. static const int blocksize_table[] = {
  74. 0, 192, 576<<0, 576<<1, 576<<2, 576<<3, 0, 0,
  75. 256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
  76. };
  77. static int64_t get_utf8(GetBitContext *gb)
  78. {
  79. int64_t val;
  80. GET_UTF8(val, get_bits(gb, 8), return -1;)
  81. return val;
  82. }
  83. static void allocate_buffers(FLACContext *s);
  84. static int metadata_parse(FLACContext *s);
  85. static av_cold int flac_decode_init(AVCodecContext *avctx)
  86. {
  87. FLACContext *s = avctx->priv_data;
  88. s->avctx = avctx;
  89. if (avctx->extradata_size > 4) {
  90. /* initialize based on the demuxer-supplied streamdata header */
  91. if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) {
  92. ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, avctx->extradata);
  93. allocate_buffers(s);
  94. } else {
  95. init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
  96. metadata_parse(s);
  97. }
  98. }
  99. avctx->sample_fmt = SAMPLE_FMT_S16;
  100. return 0;
  101. }
  102. static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
  103. {
  104. av_log(avctx, AV_LOG_DEBUG, " Blocksize: %d .. %d\n", s->min_blocksize, s->max_blocksize);
  105. av_log(avctx, AV_LOG_DEBUG, " Max Framesize: %d\n", s->max_framesize);
  106. av_log(avctx, AV_LOG_DEBUG, " Samplerate: %d\n", s->samplerate);
  107. av_log(avctx, AV_LOG_DEBUG, " Channels: %d\n", s->channels);
  108. av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps);
  109. }
  110. static void allocate_buffers(FLACContext *s)
  111. {
  112. int i;
  113. assert(s->max_blocksize);
  114. if (s->max_framesize == 0 && s->max_blocksize) {
  115. s->max_framesize= (s->channels * s->bps * s->max_blocksize + 7)/ 8; //FIXME header overhead
  116. }
  117. for (i = 0; i < s->channels; i++) {
  118. s->decoded[i] = av_realloc(s->decoded[i], sizeof(int32_t)*s->max_blocksize);
  119. }
  120. if (s->allocated_bitstream_size < s->max_framesize)
  121. s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
  122. }
  123. void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
  124. const uint8_t *buffer)
  125. {
  126. GetBitContext gb;
  127. init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8);
  128. /* mandatory streaminfo */
  129. s->min_blocksize = get_bits(&gb, 16);
  130. s->max_blocksize = get_bits(&gb, 16);
  131. skip_bits(&gb, 24); /* skip min frame size */
  132. s->max_framesize = get_bits_long(&gb, 24);
  133. s->samplerate = get_bits_long(&gb, 20);
  134. s->channels = get_bits(&gb, 3) + 1;
  135. s->bps = get_bits(&gb, 5) + 1;
  136. avctx->channels = s->channels;
  137. avctx->sample_rate = s->samplerate;
  138. skip_bits(&gb, 36); /* total num of samples */
  139. skip_bits(&gb, 64); /* md5 sum */
  140. skip_bits(&gb, 64); /* md5 sum */
  141. dump_headers(avctx, s);
  142. }
  143. /**
  144. * Parse a list of metadata blocks. This list of blocks must begin with
  145. * the fLaC marker.
  146. * @param s the flac decoding context containing the gb bit reader used to
  147. * parse metadata
  148. * @return 1 if some metadata was read, 0 if no fLaC marker was found
  149. */
  150. static int metadata_parse(FLACContext *s)
  151. {
  152. int i, metadata_last, metadata_type, metadata_size, streaminfo_updated=0;
  153. int initial_pos= get_bits_count(&s->gb);
  154. if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) {
  155. skip_bits(&s->gb, 32);
  156. do {
  157. metadata_last = get_bits1(&s->gb);
  158. metadata_type = get_bits(&s->gb, 7);
  159. metadata_size = get_bits_long(&s->gb, 24);
  160. if (get_bits_count(&s->gb) + 8*metadata_size > s->gb.size_in_bits) {
  161. skip_bits_long(&s->gb, initial_pos - get_bits_count(&s->gb));
  162. break;
  163. }
  164. if (metadata_size) {
  165. switch (metadata_type) {
  166. case METADATA_TYPE_STREAMINFO:
  167. ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, s->gb.buffer+get_bits_count(&s->gb)/8);
  168. streaminfo_updated = 1;
  169. default:
  170. for (i = 0; i < metadata_size; i++)
  171. skip_bits(&s->gb, 8);
  172. }
  173. }
  174. } while (!metadata_last);
  175. if (streaminfo_updated)
  176. allocate_buffers(s);
  177. return 1;
  178. }
  179. return 0;
  180. }
  181. static int decode_residuals(FLACContext *s, int channel, int pred_order)
  182. {
  183. int i, tmp, partition, method_type, rice_order;
  184. int sample = 0, samples;
  185. method_type = get_bits(&s->gb, 2);
  186. if (method_type > 1) {
  187. av_log(s->avctx, AV_LOG_ERROR, "illegal residual coding method %d\n", method_type);
  188. return -1;
  189. }
  190. rice_order = get_bits(&s->gb, 4);
  191. samples= s->blocksize >> rice_order;
  192. if (pred_order > samples) {
  193. av_log(s->avctx, AV_LOG_ERROR, "invalid predictor order: %i > %i\n", pred_order, samples);
  194. return -1;
  195. }
  196. sample=
  197. i= pred_order;
  198. for (partition = 0; partition < (1 << rice_order); partition++) {
  199. tmp = get_bits(&s->gb, method_type == 0 ? 4 : 5);
  200. if (tmp == (method_type == 0 ? 15 : 31)) {
  201. tmp = get_bits(&s->gb, 5);
  202. for (; i < samples; i++, sample++)
  203. s->decoded[channel][sample] = get_sbits(&s->gb, tmp);
  204. } else {
  205. for (; i < samples; i++, sample++) {
  206. s->decoded[channel][sample] = get_sr_golomb_flac(&s->gb, tmp, INT_MAX, 0);
  207. }
  208. }
  209. i= 0;
  210. }
  211. return 0;
  212. }
  213. static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order)
  214. {
  215. const int blocksize = s->blocksize;
  216. int32_t *decoded = s->decoded[channel];
  217. int a, b, c, d, i;
  218. /* warm up samples */
  219. for (i = 0; i < pred_order; i++) {
  220. decoded[i] = get_sbits(&s->gb, s->curr_bps);
  221. }
  222. if (decode_residuals(s, channel, pred_order) < 0)
  223. return -1;
  224. if (pred_order > 0)
  225. a = decoded[pred_order-1];
  226. if (pred_order > 1)
  227. b = a - decoded[pred_order-2];
  228. if (pred_order > 2)
  229. c = b - decoded[pred_order-2] + decoded[pred_order-3];
  230. if (pred_order > 3)
  231. d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4];
  232. switch (pred_order) {
  233. case 0:
  234. break;
  235. case 1:
  236. for (i = pred_order; i < blocksize; i++)
  237. decoded[i] = a += decoded[i];
  238. break;
  239. case 2:
  240. for (i = pred_order; i < blocksize; i++)
  241. decoded[i] = a += b += decoded[i];
  242. break;
  243. case 3:
  244. for (i = pred_order; i < blocksize; i++)
  245. decoded[i] = a += b += c += decoded[i];
  246. break;
  247. case 4:
  248. for (i = pred_order; i < blocksize; i++)
  249. decoded[i] = a += b += c += d += decoded[i];
  250. break;
  251. default:
  252. av_log(s->avctx, AV_LOG_ERROR, "illegal pred order %d\n", pred_order);
  253. return -1;
  254. }
  255. return 0;
  256. }
  257. static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
  258. {
  259. int i, j;
  260. int coeff_prec, qlevel;
  261. int coeffs[pred_order];
  262. int32_t *decoded = s->decoded[channel];
  263. /* warm up samples */
  264. for (i = 0; i < pred_order; i++) {
  265. decoded[i] = get_sbits(&s->gb, s->curr_bps);
  266. }
  267. coeff_prec = get_bits(&s->gb, 4) + 1;
  268. if (coeff_prec == 16) {
  269. av_log(s->avctx, AV_LOG_ERROR, "invalid coeff precision\n");
  270. return -1;
  271. }
  272. qlevel = get_sbits(&s->gb, 5);
  273. if (qlevel < 0) {
  274. av_log(s->avctx, AV_LOG_ERROR, "qlevel %d not supported, maybe buggy stream\n", qlevel);
  275. return -1;
  276. }
  277. for (i = 0; i < pred_order; i++) {
  278. coeffs[i] = get_sbits(&s->gb, coeff_prec);
  279. }
  280. if (decode_residuals(s, channel, pred_order) < 0)
  281. return -1;
  282. if (s->bps > 16) {
  283. int64_t sum;
  284. for (i = pred_order; i < s->blocksize; i++) {
  285. sum = 0;
  286. for (j = 0; j < pred_order; j++)
  287. sum += (int64_t)coeffs[j] * decoded[i-j-1];
  288. decoded[i] += sum >> qlevel;
  289. }
  290. } else {
  291. for (i = pred_order; i < s->blocksize-1; i += 2) {
  292. int c;
  293. int d = decoded[i-pred_order];
  294. int s0 = 0, s1 = 0;
  295. for (j = pred_order-1; j > 0; j--) {
  296. c = coeffs[j];
  297. s0 += c*d;
  298. d = decoded[i-j];
  299. s1 += c*d;
  300. }
  301. c = coeffs[0];
  302. s0 += c*d;
  303. d = decoded[i] += s0 >> qlevel;
  304. s1 += c*d;
  305. decoded[i+1] += s1 >> qlevel;
  306. }
  307. if (i < s->blocksize) {
  308. int sum = 0;
  309. for (j = 0; j < pred_order; j++)
  310. sum += coeffs[j] * decoded[i-j-1];
  311. decoded[i] += sum >> qlevel;
  312. }
  313. }
  314. return 0;
  315. }
  316. static inline int decode_subframe(FLACContext *s, int channel)
  317. {
  318. int type, wasted = 0;
  319. int i, tmp;
  320. s->curr_bps = s->bps;
  321. if (channel == 0) {
  322. if (s->decorrelation == RIGHT_SIDE)
  323. s->curr_bps++;
  324. } else {
  325. if (s->decorrelation == LEFT_SIDE || s->decorrelation == MID_SIDE)
  326. s->curr_bps++;
  327. }
  328. if (get_bits1(&s->gb)) {
  329. av_log(s->avctx, AV_LOG_ERROR, "invalid subframe padding\n");
  330. return -1;
  331. }
  332. type = get_bits(&s->gb, 6);
  333. if (get_bits1(&s->gb)) {
  334. wasted = 1;
  335. while (!get_bits1(&s->gb))
  336. wasted++;
  337. s->curr_bps -= wasted;
  338. }
  339. //FIXME use av_log2 for types
  340. if (type == 0) {
  341. tmp = get_sbits(&s->gb, s->curr_bps);
  342. for (i = 0; i < s->blocksize; i++)
  343. s->decoded[channel][i] = tmp;
  344. } else if (type == 1) {
  345. for (i = 0; i < s->blocksize; i++)
  346. s->decoded[channel][i] = get_sbits(&s->gb, s->curr_bps);
  347. } else if ((type >= 8) && (type <= 12)) {
  348. if (decode_subframe_fixed(s, channel, type & ~0x8) < 0)
  349. return -1;
  350. } else if (type >= 32) {
  351. if (decode_subframe_lpc(s, channel, (type & ~0x20)+1) < 0)
  352. return -1;
  353. } else {
  354. av_log(s->avctx, AV_LOG_ERROR, "invalid coding type\n");
  355. return -1;
  356. }
  357. if (wasted) {
  358. int i;
  359. for (i = 0; i < s->blocksize; i++)
  360. s->decoded[channel][i] <<= wasted;
  361. }
  362. return 0;
  363. }
  364. static int decode_frame(FLACContext *s, int alloc_data_size)
  365. {
  366. int blocksize_code, sample_rate_code, sample_size_code, assignment, i, crc8;
  367. int decorrelation, bps, blocksize, samplerate;
  368. blocksize_code = get_bits(&s->gb, 4);
  369. sample_rate_code = get_bits(&s->gb, 4);
  370. assignment = get_bits(&s->gb, 4); /* channel assignment */
  371. if (assignment < 8 && s->channels == assignment+1)
  372. decorrelation = INDEPENDENT;
  373. else if (assignment >=8 && assignment < 11 && s->channels == 2)
  374. decorrelation = LEFT_SIDE + assignment - 8;
  375. else {
  376. av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", assignment, s->channels);
  377. return -1;
  378. }
  379. sample_size_code = get_bits(&s->gb, 3);
  380. if (sample_size_code == 0)
  381. bps= s->bps;
  382. else if ((sample_size_code != 3) && (sample_size_code != 7))
  383. bps = sample_size_table[sample_size_code];
  384. else {
  385. av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", sample_size_code);
  386. return -1;
  387. }
  388. if (get_bits1(&s->gb)) {
  389. av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");
  390. return -1;
  391. }
  392. if (get_utf8(&s->gb) < 0) {
  393. av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n");
  394. return -1;
  395. }
  396. if (blocksize_code == 0)
  397. blocksize = s->min_blocksize;
  398. else if (blocksize_code == 6)
  399. blocksize = get_bits(&s->gb, 8)+1;
  400. else if (blocksize_code == 7)
  401. blocksize = get_bits(&s->gb, 16)+1;
  402. else
  403. blocksize = blocksize_table[blocksize_code];
  404. if (blocksize > s->max_blocksize) {
  405. av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, s->max_blocksize);
  406. return -1;
  407. }
  408. if (blocksize * s->channels * sizeof(int16_t) > alloc_data_size)
  409. return -1;
  410. if (sample_rate_code == 0)
  411. samplerate= s->samplerate;
  412. else if (sample_rate_code < 12)
  413. samplerate = sample_rate_table[sample_rate_code];
  414. else if (sample_rate_code == 12)
  415. samplerate = get_bits(&s->gb, 8) * 1000;
  416. else if (sample_rate_code == 13)
  417. samplerate = get_bits(&s->gb, 16);
  418. else if (sample_rate_code == 14)
  419. samplerate = get_bits(&s->gb, 16) * 10;
  420. else {
  421. av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n", sample_rate_code);
  422. return -1;
  423. }
  424. skip_bits(&s->gb, 8);
  425. crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
  426. s->gb.buffer, get_bits_count(&s->gb)/8);
  427. if (crc8) {
  428. av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch crc=%2X\n", crc8);
  429. return -1;
  430. }
  431. s->blocksize = blocksize;
  432. s->samplerate = samplerate;
  433. s->bps = bps;
  434. s->decorrelation= decorrelation;
  435. // dump_headers(s->avctx, (FLACStreaminfo *)s);
  436. /* subframes */
  437. for (i = 0; i < s->channels; i++) {
  438. if (decode_subframe(s, i) < 0)
  439. return -1;
  440. }
  441. align_get_bits(&s->gb);
  442. /* frame footer */
  443. skip_bits(&s->gb, 16); /* data crc */
  444. return 0;
  445. }
  446. static int flac_decode_frame(AVCodecContext *avctx,
  447. void *data, int *data_size,
  448. const uint8_t *buf, int buf_size)
  449. {
  450. FLACContext *s = avctx->priv_data;
  451. int tmp = 0, i, j = 0, input_buf_size = 0;
  452. int16_t *samples = data;
  453. int alloc_data_size= *data_size;
  454. *data_size=0;
  455. if (s->max_framesize == 0) {
  456. s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header
  457. s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
  458. }
  459. if (1 && s->max_framesize) { //FIXME truncated
  460. if (s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
  461. buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));
  462. input_buf_size= buf_size;
  463. if (s->bitstream_size + buf_size < buf_size || s->bitstream_index + s->bitstream_size + buf_size < s->bitstream_index)
  464. return -1;
  465. if (s->allocated_bitstream_size < s->bitstream_size + buf_size)
  466. s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->bitstream_size + buf_size);
  467. if (s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size) {
  468. memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
  469. s->bitstream_index=0;
  470. }
  471. memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
  472. buf= &s->bitstream[s->bitstream_index];
  473. buf_size += s->bitstream_size;
  474. s->bitstream_size= buf_size;
  475. if (buf_size < s->max_framesize && input_buf_size) {
  476. return input_buf_size;
  477. }
  478. }
  479. init_get_bits(&s->gb, buf, buf_size*8);
  480. if (metadata_parse(s))
  481. goto end;
  482. tmp = show_bits(&s->gb, 16);
  483. if ((tmp & 0xFFFE) != 0xFFF8) {
  484. av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n");
  485. while (get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8)
  486. skip_bits(&s->gb, 8);
  487. goto end; // we may not have enough bits left to decode a frame, so try next time
  488. }
  489. skip_bits(&s->gb, 16);
  490. if (decode_frame(s, alloc_data_size) < 0) {
  491. av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");
  492. s->bitstream_size=0;
  493. s->bitstream_index=0;
  494. return -1;
  495. }
  496. #define DECORRELATE(left, right)\
  497. assert(s->channels == 2);\
  498. for (i = 0; i < s->blocksize; i++) {\
  499. int a= s->decoded[0][i];\
  500. int b= s->decoded[1][i];\
  501. *samples++ = ((left) << (24 - s->bps)) >> 8;\
  502. *samples++ = ((right) << (24 - s->bps)) >> 8;\
  503. }\
  504. break;
  505. switch (s->decorrelation) {
  506. case INDEPENDENT:
  507. for (j = 0; j < s->blocksize; j++) {
  508. for (i = 0; i < s->channels; i++)
  509. *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8;
  510. }
  511. break;
  512. case LEFT_SIDE:
  513. DECORRELATE(a,a-b)
  514. case RIGHT_SIDE:
  515. DECORRELATE(a+b,b)
  516. case MID_SIDE:
  517. DECORRELATE( (a-=b>>1) + b, a)
  518. }
  519. *data_size = (int8_t *)samples - (int8_t *)data;
  520. end:
  521. i= (get_bits_count(&s->gb)+7)/8;
  522. if (i > buf_size) {
  523. av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
  524. s->bitstream_size=0;
  525. s->bitstream_index=0;
  526. return -1;
  527. }
  528. if (s->bitstream_size) {
  529. s->bitstream_index += i;
  530. s->bitstream_size -= i;
  531. return input_buf_size;
  532. } else
  533. return i;
  534. }
  535. static av_cold int flac_decode_close(AVCodecContext *avctx)
  536. {
  537. FLACContext *s = avctx->priv_data;
  538. int i;
  539. for (i = 0; i < s->channels; i++) {
  540. av_freep(&s->decoded[i]);
  541. }
  542. av_freep(&s->bitstream);
  543. return 0;
  544. }
  545. static void flac_flush(AVCodecContext *avctx)
  546. {
  547. FLACContext *s = avctx->priv_data;
  548. s->bitstream_size=
  549. s->bitstream_index= 0;
  550. }
  551. AVCodec flac_decoder = {
  552. "flac",
  553. CODEC_TYPE_AUDIO,
  554. CODEC_ID_FLAC,
  555. sizeof(FLACContext),
  556. flac_decode_init,
  557. NULL,
  558. flac_decode_close,
  559. flac_decode_frame,
  560. CODEC_CAP_DELAY,
  561. .flush= flac_flush,
  562. .long_name= NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
  563. };