1 /*****************************************************************************
2  * libavsmash_audio.h
3  *****************************************************************************
4  * Copyright (C) 2012-2015 L-SMASH Works project
5  *
6  * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *****************************************************************************/
20 
21 /* This file is available under an ISC license. */
22 
23 /*****************************************************************************
24  * Opaque Handlers
25  *****************************************************************************/
26 typedef lw_audio_output_handler_t libavsmash_audio_output_handler_t;
27 
28 typedef struct libavsmash_audio_decode_handler_tag libavsmash_audio_decode_handler_t;
29 
30 /*****************************************************************************
31  * Allocators / Deallocators
32  *****************************************************************************/
33 libavsmash_audio_decode_handler_t *libavsmash_audio_alloc_decode_handler
34 (
35     void
36 );
37 
38 libavsmash_audio_output_handler_t *libavsmash_audio_alloc_output_handler
39 (
40     void
41 );
42 
43 void libavsmash_audio_free_decode_handler
44 (
45     libavsmash_audio_decode_handler_t *adhp
46 );
47 
48 void libavsmash_audio_free_output_handler
49 (
50     libavsmash_audio_output_handler_t *aohp
51 );
52 
53 void libavsmash_audio_free_decode_handler_ptr
54 (
55     libavsmash_audio_decode_handler_t **adhpp
56 );
57 
58 void libavsmash_audio_free_output_handler_ptr
59 (
60     libavsmash_audio_output_handler_t **aohpp
61 );
62 
63 /*****************************************************************************
64  * Setters
65  *****************************************************************************/
66 void libavsmash_audio_set_root
67 (
68     libavsmash_audio_decode_handler_t *adhp,
69     lsmash_root_t                     *root
70 );
71 
72 void libavsmash_audio_set_track_id
73 (
74     libavsmash_audio_decode_handler_t *adhp,
75     uint32_t                           track_id
76 );
77 
78 void libavsmash_audio_set_preferred_decoder_names
79 (
80     libavsmash_audio_decode_handler_t *adhp,
81     const char                       **preferred_decoder_names
82 );
83 
84 /*****************************************************************************
85  * Getters
86  *****************************************************************************/
87 lsmash_root_t *libavsmash_audio_get_root
88 (
89     libavsmash_audio_decode_handler_t *adhp
90 );
91 
92 uint32_t libavsmash_audio_get_track_id
93 (
94     libavsmash_audio_decode_handler_t *adhp
95 );
96 
97 AVCodecContext *libavsmash_audio_get_codec_context
98 (
99     libavsmash_audio_decode_handler_t *adhp
100 );
101 
102 const char **libavsmash_audio_get_preferred_decoder_names
103 (
104     libavsmash_audio_decode_handler_t *adhp
105 );
106 
107 int libavsmash_audio_get_error
108 (
109     libavsmash_audio_decode_handler_t *adhp
110 );
111 
112 uint64_t libavsmash_audio_get_best_used_channel_layout
113 (
114     libavsmash_audio_decode_handler_t *adhp
115 );
116 
117 enum AVSampleFormat libavsmash_audio_get_best_used_sample_format
118 (
119     libavsmash_audio_decode_handler_t *adhp
120 );
121 
122 int libavsmash_audio_get_best_used_sample_rate
123 (
124     libavsmash_audio_decode_handler_t *adhp
125 );
126 
127 int libavsmash_audio_get_best_used_bits_per_sample
128 (
129     libavsmash_audio_decode_handler_t *adhp
130 );
131 
132 lw_log_handler_t *libavsmash_audio_get_log_handler
133 (
134     libavsmash_audio_decode_handler_t *adhp
135 );
136 
137 uint32_t libavsmash_audio_get_sample_count
138 (
139     libavsmash_audio_decode_handler_t *adhp
140 );
141 
142 uint32_t libavsmash_audio_get_media_timescale
143 (
144     libavsmash_audio_decode_handler_t *adhp
145 );
146 
147 uint64_t libavsmash_audio_get_media_duration
148 (
149     libavsmash_audio_decode_handler_t *adhp
150 );
151 
152 /* Return UINT64_MAX if failed. */
153 uint64_t libavsmash_audio_get_min_cts
154 (
155     libavsmash_audio_decode_handler_t *adhp
156 );
157 
158 /*****************************************************************************
159  * Others
160  *****************************************************************************/
161 int libavsmash_audio_get_track
162 (
163     libavsmash_audio_decode_handler_t *adhp,
164     uint32_t                           track_number
165 );
166 
167 int libavsmash_audio_initialize_decoder_configuration
168 (
169     libavsmash_audio_decode_handler_t *adhp,
170     AVFormatContext                   *format_ctx,
171     int                                threads
172 );
173 
174 int libavsmash_audio_get_summaries
175 (
176     libavsmash_audio_decode_handler_t *adhp
177 );
178 
179 void libavsmash_audio_force_seek
180 (
181     libavsmash_audio_decode_handler_t *adhp
182 );
183 
184 void libavsmash_audio_clear_error
185 (
186     libavsmash_audio_decode_handler_t *adhp
187 );
188 
189 void libavsmash_audio_close_codec_context
190 (
191     libavsmash_audio_decode_handler_t *adhp
192 );
193 
194 void libavsmash_audio_apply_delay
195 (
196     libavsmash_audio_decode_handler_t *adhp,
197     int64_t                            delay
198 );
199 
200 void libavsmash_audio_set_implicit_preroll
201 (
202     libavsmash_audio_decode_handler_t *adhp
203 );
204 
205 uint64_t libavsmash_audio_count_overall_pcm_samples
206 (
207     libavsmash_audio_decode_handler_t *adhp,
208     int                                output_sample_rate,
209     uint64_t                           start_time
210 );
211 
212 uint64_t libavsmash_audio_get_pcm_samples
213 (
214     libavsmash_audio_decode_handler_t *adhp,
215     libavsmash_audio_output_handler_t *aohp,
216     void                              *buf,
217     int64_t                            start,
218     int64_t                            wanted_length
219 );
220