• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef fooa2dpcodechfoo
2 #define fooa2dpcodechfoo
3 
4 /***
5   This file is part of PulseAudio.
6 
7   Copyright 2018-2019 Pali Rohár <pali.rohar@gmail.com>
8 
9   PulseAudio is free software; you can redistribute it and/or modify
10   it under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13 
14   PulseAudio is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   General Public License for more details.
18 
19   You should have received a copy of the GNU Lesser General Public
20   License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
21 ***/
22 
23 #include <pulsecore/core.h>
24 
25 #define MAX_A2DP_CAPS_SIZE 254
26 
27 typedef struct pa_a2dp_codec_capabilities {
28     uint8_t size;
29     uint8_t buffer[]; /* max size is 254 bytes */
30 } pa_a2dp_codec_capabilities;
31 
32 typedef struct pa_a2dp_codec_id {
33     uint8_t codec_id;
34     uint32_t vendor_id;
35     uint16_t vendor_codec_id;
36 } pa_a2dp_codec_id;
37 
38 typedef struct pa_a2dp_codec {
39     /* Unique name of the codec, lowercase and without whitespaces, used for
40      * constructing identifier, D-Bus paths, ... */
41     const char *name;
42     /* Human readable codec description */
43     const char *description;
44 
45     /* A2DP codec id */
46     pa_a2dp_codec_id id;
47 
48     /* True if codec is bi-directional and supports backchannel */
49     bool support_backchannel;
50 
51     /* Returns true if codec accepts capabilities, for_encoding is true when
52      * capabilities are used for encoding */
53     bool (*can_accept_capabilities)(const uint8_t *capabilities_buffer, uint8_t capabilities_size, bool for_encoding);
54     /* Choose remote endpoint based on capabilities from hash map
55      * (const char *endpoint -> const pa_a2dp_codec_capabilities *capability)
56      * and returns corresponding endpoint key (or NULL when there is no valid),
57      * for_encoder is true when capabilities hash map is used for encoding */
58     const char *(*choose_remote_endpoint)(const pa_hashmap *capabilities_hashmap, const pa_sample_spec *default_sample_spec, bool for_encoding);
59     /* Fill codec capabilities, returns size of filled buffer */
60     uint8_t (*fill_capabilities)(uint8_t capabilities_buffer[MAX_A2DP_CAPS_SIZE]);
61     /* Validate codec configuration, returns true on success */
62     bool (*is_configuration_valid)(const uint8_t *config_buffer, uint8_t config_size);
63     /* Fill preferred codec configuration, returns size of filled buffer or 0 on failure */
64     uint8_t (*fill_preferred_configuration)(const pa_sample_spec *default_sample_spec, const uint8_t *capabilities_buffer, uint8_t capabilities_size, uint8_t config_buffer[MAX_A2DP_CAPS_SIZE]);
65 
66     /* Initialize codec, returns codec info data and set sample_spec,
67      * for_encoding is true when codec_info is used for encoding,
68      * for_backchannel is true when codec_info is used for backchannel */
69     void *(*init)(bool for_encoding, bool for_backchannel, const uint8_t *config_buffer, uint8_t config_size, pa_sample_spec *sample_spec);
70     /* Deinitialize and release codec info data in codec_info */
71     void (*deinit)(void *codec_info);
72     /* Reset internal state of codec info data in codec_info, returns
73      * a negative value on failure */
74     int (*reset)(void *codec_info);
75 
76     /* Get read block size for codec, it is minimal size of buffer
77      * needed to decode read_link_mtu bytes of encoded data */
78     size_t (*get_read_block_size)(void *codec_info, size_t read_link_mtu);
79     /* Get write block size for codec, it is maximal size of buffer
80      * which can produce at most write_link_mtu bytes of encoded data */
81     size_t (*get_write_block_size)(void *codec_info, size_t write_link_mtu);
82 
83     /* Reduce encoder bitrate for codec, returns new write block size or zero
84      * if not changed, called when socket is not accepting encoded data fast
85      * enough */
86     size_t (*reduce_encoder_bitrate)(void *codec_info, size_t write_link_mtu);
87 
88     /* Encode input_buffer of input_size to output_buffer of output_size,
89      * returns size of filled ouput_buffer and set processed to size of
90      * processed input_buffer */
91     size_t (*encode_buffer)(void *codec_info, uint32_t timestamp, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed);
92     /* Decode input_buffer of input_size to output_buffer of output_size,
93      * returns size of filled ouput_buffer and set processed to size of
94      * processed input_buffer */
95     size_t (*decode_buffer)(void *codec_info, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed);
96 } pa_a2dp_codec;
97 
98 #endif
99