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.

683 lines
20KB

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