1 /*****************************************************************************
2  * audio_output.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 #include "cpp_compat.h"
24 
25 typedef struct
26 {
27     AVAudioResampleContext *avr_ctx;
28     uint8_t                *resampled_buffer;
29     int                     resampled_buffer_size;
30     int                     input_planes;
31     uint64_t                input_channel_layout;
32     enum AVSampleFormat     input_sample_format;
33     int                     input_sample_rate;
34     int                     input_block_align;
35     uint64_t                output_channel_layout;
36     enum AVSampleFormat     output_sample_format;
37     int                     output_sample_rate;
38     int                     output_block_align;
39     int                     output_bits_per_sample;
40     int                     s24_output;
41     uint64_t                request_length;
42     uint64_t                skip_decoded_samples;   /* Upsampling by the decoder is considered. */
43     uint64_t                output_sample_offset;
44 } lw_audio_output_handler_t;
45 
46 enum audio_output_flag
47 {
48     AUDIO_OUTPUT_NO_FLAGS         = 0,
49     AUDIO_OUTPUT_ENOUGH           = 1 << 0,
50     AUDIO_DECODER_DELAY           = 1 << 1,
51     AUDIO_DECODER_ERROR           = 1 << 2,
52     AUDIO_RECONFIG_FAILURE        = 1 << 3,
53     AUDIO_DECODER_RECEIVED_PACKET = 1 << 4,
54 };
55 CPP_DEFINE_OR_SUBSTITUTE_OPERATOR( enum audio_output_flag )
56 
57 uint64_t output_pcm_samples_from_buffer
58 (
59     lw_audio_output_handler_t *aohp,
60     AVFrame                   *frame_buffer,
61     uint8_t                  **output_buffer,
62     enum audio_output_flag    *output_flags
63 );
64 
65 uint64_t output_pcm_samples_from_packet
66 (
67     lw_audio_output_handler_t *aohp,
68     AVCodecContext            *ctx,
69     AVPacket                  *pkt,
70     AVFrame                   *frame_buffer,
71     uint8_t                  **output_buffer,
72     enum audio_output_flag    *output_flags
73 );
74 
75 void lw_cleanup_audio_output_handler
76 (
77     lw_audio_output_handler_t *aohp
78 );
79