| 139 | } |
| 140 | |
| 141 | static av_cold int pulse_read_header(AVFormatContext *s) |
| 142 | { |
| 143 | PulseData *pd = s->priv_data; |
| 144 | AVStream *st; |
| 145 | char *device = NULL; |
| 146 | int ret; |
| 147 | enum AVCodecID codec_id = |
| 148 | s->audio_codec_id == AV_CODEC_ID_NONE ? DEFAULT_CODEC_ID : s->audio_codec_id; |
| 149 | const pa_sample_spec ss = { ff_codec_id_to_pulse_format(codec_id), |
| 150 | pd->sample_rate, |
| 151 | pd->channels }; |
| 152 | |
| 153 | pa_buffer_attr attr = { -1 }; |
| 154 | pa_channel_map cmap; |
| 155 | const pa_buffer_attr *queried_attr; |
| 156 | |
| 157 | pa_channel_map_init_extend(&cmap, pd->channels, PA_CHANNEL_MAP_WAVEEX); |
| 158 | |
| 159 | st = avformat_new_stream(s, NULL); |
| 160 | |
| 161 | if (!st) { |
| 162 | av_log(s, AV_LOG_ERROR, "Cannot add stream\n"); |
| 163 | return AVERROR(ENOMEM); |
| 164 | } |
| 165 | |
| 166 | if (pd->fragment_size == -1) { |
| 167 | // 50 ms fragments/latency by default seem good enough |
| 168 | attr.fragsize = pa_frame_size(&ss) * (pd->sample_rate / 20); |
| 169 | } else { |
| 170 | attr.fragsize = pd->fragment_size; |
| 171 | } |
| 172 | |
| 173 | if (s->url[0] != '\0' && strcmp(s->url, "default")) |
| 174 | device = s->url; |
| 175 | |
| 176 | if (!(pd->mainloop = pa_threaded_mainloop_new())) { |
| 177 | pulse_close(s); |
| 178 | return AVERROR_EXTERNAL; |
| 179 | } |
| 180 | |
| 181 | if (!(pd->context = pa_context_new(pa_threaded_mainloop_get_api(pd->mainloop), pd->name))) { |
| 182 | pulse_close(s); |
| 183 | return AVERROR_EXTERNAL; |
| 184 | } |
| 185 | |
| 186 | pa_context_set_state_callback(pd->context, context_state_cb, pd); |
| 187 | |
| 188 | if (pa_context_connect(pd->context, pd->server, 0, NULL) < 0) { |
| 189 | pulse_close(s); |
| 190 | return AVERROR(pa_context_errno(pd->context)); |
| 191 | } |
| 192 | |
| 193 | pa_threaded_mainloop_lock(pd->mainloop); |
| 194 | |
| 195 | if (pa_threaded_mainloop_start(pd->mainloop) < 0) { |
| 196 | ret = -1; |
| 197 | goto unlock_and_fail; |
| 198 | } |
nothing calls this directly
no test coverage detected