file_decoder.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:20k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* libFLAC - Free Lossless Audio Codec library
  2.  * Copyright (C) 2000,2001,2002,2003,2004,2005  Josh Coalson
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * - Redistributions of source code must retain the above copyright
  9.  * notice, this list of conditions and the following disclaimer.
  10.  *
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  * notice, this list of conditions and the following disclaimer in the
  13.  * documentation and/or other materials provided with the distribution.
  14.  *
  15.  * - Neither the name of the Xiph.org Foundation nor the names of its
  16.  * contributors may be used to endorse or promote products derived from
  17.  * this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22.  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
  23.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  */
  31. #include <stdio.h>
  32. #include <stdlib.h> /* for malloc() */
  33. #include <string.h> /* for strcmp() */
  34. #include "FLAC/assert.h"
  35. #include "protected/file_decoder.h"
  36. #include "protected/seekable_stream_decoder.h"
  37. /***********************************************************************
  38.  *
  39.  * Private class method prototypes
  40.  *
  41.  ***********************************************************************/
  42. static void set_defaults_(FLAC__FileDecoder *decoder);
  43. static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  44. static void metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  45. static void error_callback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  46. /***********************************************************************
  47.  *
  48.  * Private class data
  49.  *
  50.  ***********************************************************************/
  51. typedef struct FLAC__FileDecoderPrivate {
  52. FLAC__FileDecoderWriteCallback write_callback;
  53. FLAC__FileDecoderMetadataCallback metadata_callback;
  54. FLAC__FileDecoderErrorCallback error_callback;
  55. void *client_data;
  56. FILE *file;
  57. char *filename; /* == NULL if stdin */
  58. FLAC__SeekableStreamDecoder *seekable_stream_decoder;
  59. } FLAC__FileDecoderPrivate;
  60. /***********************************************************************
  61.  *
  62.  * Public static class data
  63.  *
  64.  ***********************************************************************/
  65. FLAC_API const char * const FLAC__FileDecoderStateString[] = {
  66. "FLAC__FILE_DECODER_OK",
  67. "FLAC__FILE_DECODER_END_OF_FILE",
  68. "FLAC__FILE_DECODER_ERROR_OPENING_FILE",
  69. "FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR",
  70. "FLAC__FILE_DECODER_SEEK_ERROR",
  71. "FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR",
  72. "FLAC__FILE_DECODER_ALREADY_INITIALIZED",
  73. "FLAC__FILE_DECODER_INVALID_CALLBACK",
  74. "FLAC__FILE_DECODER_UNINITIALIZED"
  75. };
  76. /***********************************************************************
  77.  *
  78.  * Class constructor/destructor
  79.  *
  80.  ***********************************************************************/
  81. FLAC_API FLAC__FileDecoder *FLAC__file_decoder_new()
  82. {
  83. FLAC__FileDecoder *decoder;
  84. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  85. decoder = (FLAC__FileDecoder*)calloc(1, sizeof(FLAC__FileDecoder));
  86. if(decoder == 0) {
  87. return 0;
  88. }
  89. decoder->protected_ = (FLAC__FileDecoderProtected*)calloc(1, sizeof(FLAC__FileDecoderProtected));
  90. if(decoder->protected_ == 0) {
  91. free(decoder);
  92. return 0;
  93. }
  94. decoder->private_ = (FLAC__FileDecoderPrivate*)calloc(1, sizeof(FLAC__FileDecoderPrivate));
  95. if(decoder->private_ == 0) {
  96. free(decoder->protected_);
  97. free(decoder);
  98. return 0;
  99. }
  100. decoder->private_->seekable_stream_decoder = FLAC__seekable_stream_decoder_new();
  101. if(0 == decoder->private_->seekable_stream_decoder) {
  102. free(decoder->private_);
  103. free(decoder->protected_);
  104. free(decoder);
  105. return 0;
  106. }
  107. decoder->private_->file = 0;
  108. set_defaults_(decoder);
  109. decoder->protected_->state = FLAC__FILE_DECODER_UNINITIALIZED;
  110. return decoder;
  111. }
  112. FLAC_API void FLAC__file_decoder_delete(FLAC__FileDecoder *decoder)
  113. {
  114. FLAC__ASSERT(0 != decoder);
  115. FLAC__ASSERT(0 != decoder->protected_);
  116. FLAC__ASSERT(0 != decoder->private_);
  117. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  118. (void)FLAC__file_decoder_finish(decoder);
  119. FLAC__seekable_stream_decoder_delete(decoder->private_->seekable_stream_decoder);
  120. free(decoder->private_);
  121. free(decoder->protected_);
  122. free(decoder);
  123. }
  124. /***********************************************************************
  125.  *
  126.  * Public class methods
  127.  *
  128.  ***********************************************************************/
  129. FLAC_API FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder)
  130. {
  131. FLAC__ASSERT(0 != decoder);
  132. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  133. return decoder->protected_->state = FLAC__FILE_DECODER_ALREADY_INITIALIZED;
  134. if(0 == decoder->private_->write_callback || 0 == decoder->private_->metadata_callback || 0 == decoder->private_->error_callback)
  135. return decoder->protected_->state = FLAC__FILE_DECODER_INVALID_CALLBACK;
  136.   decoder->private_->file = fopen(decoder->private_->filename, "rb");
  137. if(decoder->private_->file == 0)
  138. return decoder->protected_->state = FLAC__FILE_DECODER_ERROR_OPENING_FILE;
  139. FLAC__seekable_stream_decoder_set_read_callback(decoder->private_->seekable_stream_decoder, read_callback_);
  140. FLAC__seekable_stream_decoder_set_seek_callback(decoder->private_->seekable_stream_decoder, seek_callback_);
  141. FLAC__seekable_stream_decoder_set_tell_callback(decoder->private_->seekable_stream_decoder, tell_callback_);
  142. FLAC__seekable_stream_decoder_set_length_callback(decoder->private_->seekable_stream_decoder, length_callback_);
  143. FLAC__seekable_stream_decoder_set_eof_callback(decoder->private_->seekable_stream_decoder, eof_callback_);
  144. FLAC__seekable_stream_decoder_set_write_callback(decoder->private_->seekable_stream_decoder, write_callback_);
  145. FLAC__seekable_stream_decoder_set_metadata_callback(decoder->private_->seekable_stream_decoder, metadata_callback_);
  146. FLAC__seekable_stream_decoder_set_error_callback(decoder->private_->seekable_stream_decoder, error_callback_);
  147. FLAC__seekable_stream_decoder_set_client_data(decoder->private_->seekable_stream_decoder, decoder);
  148. if(FLAC__seekable_stream_decoder_init(decoder->private_->seekable_stream_decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK)
  149. return decoder->protected_->state = FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR;
  150. return decoder->protected_->state = FLAC__FILE_DECODER_OK;
  151. }
  152. FLAC_API FLAC__bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder)
  153. {
  154. FLAC__ASSERT(0 != decoder);
  155. if(decoder->protected_->state == FLAC__FILE_DECODER_UNINITIALIZED)
  156. return true;
  157. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  158. if(0 != decoder->private_->file && decoder->private_->file != stdin) {
  159. fclose(decoder->private_->file);
  160. decoder->private_->file = 0;
  161. }
  162. if(0 != decoder->private_->filename) {
  163. free(decoder->private_->filename);
  164. decoder->private_->filename = 0;
  165. }
  166. set_defaults_(decoder);
  167. decoder->protected_->state = FLAC__FILE_DECODER_UNINITIALIZED;
  168. return FLAC__seekable_stream_decoder_finish(decoder->private_->seekable_stream_decoder);
  169. }
  170. FLAC_API FLAC__bool FLAC__file_decoder_set_md5_checking(FLAC__FileDecoder *decoder, FLAC__bool value)
  171. {
  172. FLAC__ASSERT(0 != decoder);
  173. FLAC__ASSERT(0 != decoder->private_);
  174. FLAC__ASSERT(0 != decoder->protected_);
  175. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  176. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  177. return false;
  178. return FLAC__seekable_stream_decoder_set_md5_checking(decoder->private_->seekable_stream_decoder, value);
  179. }
  180. FLAC_API FLAC__bool FLAC__file_decoder_set_filename(FLAC__FileDecoder *decoder, const char *value)
  181. {
  182. FLAC__ASSERT(0 != decoder);
  183. FLAC__ASSERT(0 != decoder->private_);
  184. FLAC__ASSERT(0 != decoder->protected_);
  185. FLAC__ASSERT(0 != value);
  186. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  187. return false;
  188. if(0 != decoder->private_->filename) {
  189. free(decoder->private_->filename);
  190. decoder->private_->filename = 0;
  191. }
  192. if(0 != strcmp(value, "-")) {
  193. if(0 == (decoder->private_->filename = (char*)malloc(strlen(value)+1))) {
  194. decoder->protected_->state = FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR;
  195. return false;
  196. }
  197. strcpy(decoder->private_->filename, value);
  198. }
  199. return true;
  200. }
  201. FLAC_API FLAC__bool FLAC__file_decoder_set_write_callback(FLAC__FileDecoder *decoder, FLAC__FileDecoderWriteCallback value)
  202. {
  203. FLAC__ASSERT(0 != decoder);
  204. FLAC__ASSERT(0 != decoder->private_);
  205. FLAC__ASSERT(0 != decoder->protected_);
  206. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  207. return false;
  208. decoder->private_->write_callback = value;
  209. return true;
  210. }
  211. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_callback(FLAC__FileDecoder *decoder, FLAC__FileDecoderMetadataCallback value)
  212. {
  213. FLAC__ASSERT(0 != decoder);
  214. FLAC__ASSERT(0 != decoder->private_);
  215. FLAC__ASSERT(0 != decoder->protected_);
  216. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  217. return false;
  218. decoder->private_->metadata_callback = value;
  219. return true;
  220. }
  221. FLAC_API FLAC__bool FLAC__file_decoder_set_error_callback(FLAC__FileDecoder *decoder, FLAC__FileDecoderErrorCallback value)
  222. {
  223. FLAC__ASSERT(0 != decoder);
  224. FLAC__ASSERT(0 != decoder->private_);
  225. FLAC__ASSERT(0 != decoder->protected_);
  226. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  227. return false;
  228. decoder->private_->error_callback = value;
  229. return true;
  230. }
  231. FLAC_API FLAC__bool FLAC__file_decoder_set_client_data(FLAC__FileDecoder *decoder, void *value)
  232. {
  233. FLAC__ASSERT(0 != decoder);
  234. FLAC__ASSERT(0 != decoder->private_);
  235. FLAC__ASSERT(0 != decoder->protected_);
  236. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  237. return false;
  238. decoder->private_->client_data = value;
  239. return true;
  240. }
  241. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_respond(FLAC__FileDecoder *decoder, FLAC__MetadataType type)
  242. {
  243. FLAC__ASSERT(0 != decoder);
  244. FLAC__ASSERT(0 != decoder->private_);
  245. FLAC__ASSERT(0 != decoder->protected_);
  246. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  247. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  248. return false;
  249. return FLAC__seekable_stream_decoder_set_metadata_respond(decoder->private_->seekable_stream_decoder, type);
  250. }
  251. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_respond_application(FLAC__FileDecoder *decoder, const FLAC__byte id[4])
  252. {
  253. FLAC__ASSERT(0 != decoder);
  254. FLAC__ASSERT(0 != decoder->private_);
  255. FLAC__ASSERT(0 != decoder->protected_);
  256. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  257. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  258. return false;
  259. return FLAC__seekable_stream_decoder_set_metadata_respond_application(decoder->private_->seekable_stream_decoder, id);
  260. }
  261. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_respond_all(FLAC__FileDecoder *decoder)
  262. {
  263. FLAC__ASSERT(0 != decoder);
  264. FLAC__ASSERT(0 != decoder->private_);
  265. FLAC__ASSERT(0 != decoder->protected_);
  266. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  267. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  268. return false;
  269. return FLAC__seekable_stream_decoder_set_metadata_respond_all(decoder->private_->seekable_stream_decoder);
  270. }
  271. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_ignore(FLAC__FileDecoder *decoder, FLAC__MetadataType type)
  272. {
  273. FLAC__ASSERT(0 != decoder);
  274. FLAC__ASSERT(0 != decoder->private_);
  275. FLAC__ASSERT(0 != decoder->protected_);
  276. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  277. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  278. return false;
  279. return FLAC__seekable_stream_decoder_set_metadata_ignore(decoder->private_->seekable_stream_decoder, type);
  280. }
  281. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_ignore_application(FLAC__FileDecoder *decoder, const FLAC__byte id[4])
  282. {
  283. FLAC__ASSERT(0 != decoder);
  284. FLAC__ASSERT(0 != decoder->private_);
  285. FLAC__ASSERT(0 != decoder->protected_);
  286. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  287. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  288. return false;
  289. return FLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder->private_->seekable_stream_decoder, id);
  290. }
  291. FLAC_API FLAC__bool FLAC__file_decoder_set_metadata_ignore_all(FLAC__FileDecoder *decoder)
  292. {
  293. FLAC__ASSERT(0 != decoder);
  294. FLAC__ASSERT(0 != decoder->private_);
  295. FLAC__ASSERT(0 != decoder->protected_);
  296. FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);
  297. if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
  298. return false;
  299. return FLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder->private_->seekable_stream_decoder);
  300. }
  301. FLAC_API FLAC__FileDecoderState FLAC__file_decoder_get_state(const FLAC__FileDecoder *decoder)
  302. {
  303. FLAC__ASSERT(0 != decoder);
  304. FLAC__ASSERT(0 != decoder->protected_);
  305. return decoder->protected_->state;
  306. }
  307. FLAC_API FLAC__SeekableStreamDecoderState FLAC__file_decoder_get_seekable_stream_decoder_state(const FLAC__FileDecoder *decoder)
  308. {
  309. FLAC__ASSERT(0 != decoder);
  310. FLAC__ASSERT(0 != decoder->private_);
  311. return FLAC__seekable_stream_decoder_get_state(decoder->private_->seekable_stream_decoder);
  312. }
  313. FLAC_API FLAC__StreamDecoderState FLAC__file_decoder_get_stream_decoder_state(const FLAC__FileDecoder *decoder)
  314. {
  315. FLAC__ASSERT(0 != decoder);
  316. FLAC__ASSERT(0 != decoder->private_);
  317. return FLAC__seekable_stream_decoder_get_stream_decoder_state(decoder->private_->seekable_stream_decoder);
  318. }
  319. FLAC_API const char *FLAC__file_decoder_get_resolved_state_string(const FLAC__FileDecoder *decoder)
  320. {
  321. if(decoder->protected_->state != FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR)
  322. return FLAC__FileDecoderStateString[decoder->protected_->state];
  323. else
  324. return FLAC__seekable_stream_decoder_get_resolved_state_string(decoder->private_->seekable_stream_decoder);
  325. }
  326. FLAC_API FLAC__bool FLAC__file_decoder_get_md5_checking(const FLAC__FileDecoder *decoder)
  327. {
  328. FLAC__ASSERT(0 != decoder);
  329. FLAC__ASSERT(0 != decoder->private_);
  330. return FLAC__seekable_stream_decoder_get_md5_checking(decoder->private_->seekable_stream_decoder);
  331. }
  332. FLAC_API unsigned FLAC__file_decoder_get_channels(const FLAC__FileDecoder *decoder)
  333. {
  334. FLAC__ASSERT(0 != decoder);
  335. FLAC__ASSERT(0 != decoder->private_);
  336. return FLAC__seekable_stream_decoder_get_channels(decoder->private_->seekable_stream_decoder);
  337. }
  338. FLAC_API FLAC__ChannelAssignment FLAC__file_decoder_get_channel_assignment(const FLAC__FileDecoder *decoder)
  339. {
  340. FLAC__ASSERT(0 != decoder);
  341. FLAC__ASSERT(0 != decoder->private_);
  342. return FLAC__seekable_stream_decoder_get_channel_assignment(decoder->private_->seekable_stream_decoder);
  343. }
  344. FLAC_API unsigned FLAC__file_decoder_get_bits_per_sample(const FLAC__FileDecoder *decoder)
  345. {
  346. FLAC__ASSERT(0 != decoder);
  347. FLAC__ASSERT(0 != decoder->private_);
  348. return FLAC__seekable_stream_decoder_get_bits_per_sample(decoder->private_->seekable_stream_decoder);
  349. }
  350. FLAC_API unsigned FLAC__file_decoder_get_sample_rate(const FLAC__FileDecoder *decoder)
  351. {
  352. FLAC__ASSERT(0 != decoder);
  353. FLAC__ASSERT(0 != decoder->private_);
  354. return FLAC__seekable_stream_decoder_get_sample_rate(decoder->private_->seekable_stream_decoder);
  355. }
  356. FLAC_API unsigned FLAC__file_decoder_get_blocksize(const FLAC__FileDecoder *decoder)
  357. {
  358. FLAC__ASSERT(0 != decoder);
  359. FLAC__ASSERT(0 != decoder->private_);
  360. return FLAC__seekable_stream_decoder_get_blocksize(decoder->private_->seekable_stream_decoder);
  361. }
  362. FLAC_API FLAC__bool FLAC__file_decoder_get_decode_position(const FLAC__FileDecoder *decoder, FLAC__uint64 *position)
  363. {
  364. FLAC__ASSERT(0 != decoder);
  365. FLAC__ASSERT(0 != decoder->private_);
  366. return FLAC__seekable_stream_decoder_get_decode_position(decoder->private_->seekable_stream_decoder, position);
  367. }
  368. FLAC_API FLAC__bool FLAC__file_decoder_process_single(FLAC__FileDecoder *decoder)
  369. {
  370. FLAC__bool ret;
  371. FLAC__ASSERT(0 != decoder);
  372. if(decoder->private_->seekable_stream_decoder->protected_->state == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
  373. decoder->protected_->state = FLAC__FILE_DECODER_END_OF_FILE;
  374. if(decoder->protected_->state == FLAC__FILE_DECODER_END_OF_FILE)
  375. return true;
  376. FLAC__ASSERT(decoder->protected_->state == FLAC__FILE_DECODER_OK);
  377. ret = FLAC__seekable_stream_decoder_process_single(decoder->private_->seekable_stream_decoder);
  378. if(!ret)
  379. decoder->protected_->state = FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR;
  380. return ret;
  381. }
  382. FLAC_API FLAC__bool FLAC__file_decoder_process_until_end_of_metadata(FLAC__FileDecoder *decoder)
  383. {
  384. FLAC__bool ret;
  385. FLAC__ASSERT(0 != decoder);
  386. if(decoder->private_->seekable_stream_decoder->protected_->state == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
  387. decoder->protected_->state = FLAC__FILE_DECODER_END_OF_FILE;
  388. if(decoder->protected_->state == FLAC__FILE_DECODER_END_OF_FILE)
  389. return true;
  390. FLAC__ASSERT(decoder->protected_->state == FLAC__FILE_DECODER_OK);
  391. ret = FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder->private_->seekable_stream_decoder);
  392. if(!ret)
  393. decoder->protected_->state = FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR;
  394. return ret;
  395. }
  396. FLAC_API FLAC__bool FLAC__file_decoder_process_until_end_of_file(FLAC__FileDecoder *decoder)
  397. {
  398. FLAC__bool ret;
  399. FLAC__ASSERT(0 != decoder);
  400. if(decoder->private_->seekable_stream_decoder->protected_->state == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
  401. decoder->protected_->state = FLAC__FILE_DECODER_END_OF_FILE;
  402. if(decoder->protected_->state == FLAC__FILE_DECODER_END_OF_FILE)
  403. return true;
  404. FLAC__ASSERT(decoder->protected_->state == FLAC__FILE_DECODER_OK);
  405. ret = FLAC__seekable_stream_decoder_process_until_end_of_stream(decoder->private_->seekable_stream_decoder);
  406. if(!ret)
  407. decoder->protected_->state = FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR;
  408. return ret;
  409. }
  410. FLAC_API FLAC__bool FLAC__file_decoder_skip_single_frame(FLAC__FileDecoder *decoder)
  411. {
  412. FLAC__bool ret;
  413. FLAC__ASSERT(0 != decoder);
  414. if(decoder->private_->seekable_stream_decoder->protected_->state == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
  415. decoder->protected_->state = FLAC__FILE_DECODER_END_OF_FILE;
  416. if(decoder->protected_->state == FLAC__FILE_DECODER_END_OF_FILE)
  417. return true;
  418. FLAC__ASSERT(decoder->protected_->state == FLAC__FILE_DECODER_OK);
  419. ret = FLAC__seekable_stream_decoder_skip_single_frame(decoder->private_->seekable_stream_decoder);
  420. if(!ret)
  421. decoder->protected_->state = FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR;
  422. return ret;
  423. }
  424. FLAC_API FLAC__bool FLAC__file_decoder_seek_absolute(FLAC__FileDecoder *decoder, FLAC__uint64 sample)
  425. {
  426. FLAC__ASSERT(0 != decoder);
  427. FLAC__ASSERT(decoder->protected_->state == FLAC__FILE_DECODER_OK || decoder->protected_->state == FLAC__FILE_DECODER_END_OF_FILE);
  428. if(decoder->private_->filename == 0) { /* means the file is stdin... */
  429. decoder->protected_->state = FLAC__FILE_DECODER_SEEK_ERROR;
  430. return false;
  431. }
  432. if(!FLAC__seekable_stream_decoder_seek_absolute(decoder->private_->seekable_stream_decoder, sample)) {
  433. decoder->protected_->state = FLAC__FILE_DECODER_SEEK_ERROR;
  434. return false;
  435. }
  436. else {
  437. decoder->protected_->state = FLAC__FILE_DECODER_OK;
  438. return true;
  439. }
  440. }