Code Coverage Report for src/api/seek-tell.c


Hit Total Coverage
Lines: 20 20 100.0%
Branches: 108 108 100.0%

1 /*
2 * libnogg: a decoder library for Ogg Vorbis streams
3 * Copyright (c) 2014-2023 Andrew Church <achurch@achurch.org>
4 *
5 * This software may be copied and redistributed under certain conditions;
6 * see the file "COPYING" in the source code distribution for details.
7 * NO WARRANTY is provided with this software.
8 */
9
10 #include "include/nogg.h"
11 #include "src/common.h"
12 #include "src/util/decode-frame.h"
13
14 #include <stddef.h>
15
16
17 int vorbis_seek(vorbis_t *handle, int64_t position)
18 {
19 (18/18) if (handle->packet_mode) {
20 return 0;
21 }
22 (18/18) if (position < 0) {
23 return 0;
24 }
25
26 (void) stb_vorbis_get_error(handle->decoder);
27 const int offset = stb_vorbis_seek(handle->decoder, position);
28 (18/18) if (stb_vorbis_get_error(handle->decoder) != VORBIS__no_error) {
29 return 0;
30 }
31
32 handle->frame_pos = stb_vorbis_tell_pcm(handle->decoder);
33 handle->decode_buf_pos = 0;
34 handle->decode_buf_len = 0;
35
36 vorbis_error_t error;
37 do {
38 error = decode_frame(handle, NULL, 0);
39 (18/18) } while (error == VORBIS_ERROR_DECODE_RECOVERED);
40 (36/36) if (error != VORBIS_NO_ERROR && error != VORBIS_ERROR_STREAM_END) {
41 return 0;
42 }
43
44 handle->decode_buf_pos += offset;
45 return 1;
46 }
47
48
49 int64_t vorbis_tell(const vorbis_t *handle)
50 {
51 return handle->frame_pos + handle->decode_buf_pos;
52 }