| 2125 | } |
| 2126 | |
| 2127 | static int audio_thread(void *arg) |
| 2128 | { |
| 2129 | VideoState *is = arg; |
| 2130 | AVFrame *frame = av_frame_alloc(); |
| 2131 | Frame *af; |
| 2132 | int last_serial = -1; |
| 2133 | int reconfigure; |
| 2134 | int got_frame = 0; |
| 2135 | AVRational tb; |
| 2136 | int ret = 0; |
| 2137 | |
| 2138 | if (!frame) |
| 2139 | return AVERROR(ENOMEM); |
| 2140 | |
| 2141 | do { |
| 2142 | if ((got_frame = decoder_decode_frame(&is->auddec, frame, NULL)) < 0) |
| 2143 | goto the_end; |
| 2144 | |
| 2145 | if (got_frame) { |
| 2146 | tb = (AVRational){1, frame->sample_rate}; |
| 2147 | |
| 2148 | reconfigure = |
| 2149 | cmp_audio_fmts(is->audio_filter_src.fmt, is->audio_filter_src.ch_layout.nb_channels, |
| 2150 | frame->format, frame->ch_layout.nb_channels) || |
| 2151 | av_channel_layout_compare(&is->audio_filter_src.ch_layout, &frame->ch_layout) || |
| 2152 | is->audio_filter_src.freq != frame->sample_rate || |
| 2153 | is->auddec.pkt_serial != last_serial; |
| 2154 | |
| 2155 | if (reconfigure) { |
| 2156 | char buf1[1024], buf2[1024]; |
| 2157 | av_channel_layout_describe(&is->audio_filter_src.ch_layout, buf1, sizeof(buf1)); |
| 2158 | av_channel_layout_describe(&frame->ch_layout, buf2, sizeof(buf2)); |
| 2159 | av_log(NULL, AV_LOG_DEBUG, |
| 2160 | "Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n", |
| 2161 | is->audio_filter_src.freq, is->audio_filter_src.ch_layout.nb_channels, av_get_sample_fmt_name(is->audio_filter_src.fmt), buf1, last_serial, |
| 2162 | frame->sample_rate, frame->ch_layout.nb_channels, av_get_sample_fmt_name(frame->format), buf2, is->auddec.pkt_serial); |
| 2163 | |
| 2164 | is->audio_filter_src.fmt = frame->format; |
| 2165 | ret = av_channel_layout_copy(&is->audio_filter_src.ch_layout, &frame->ch_layout); |
| 2166 | if (ret < 0) |
| 2167 | goto the_end; |
| 2168 | is->audio_filter_src.freq = frame->sample_rate; |
| 2169 | last_serial = is->auddec.pkt_serial; |
| 2170 | |
| 2171 | if ((ret = configure_audio_filters(is, afilters, 1)) < 0) |
| 2172 | goto the_end; |
| 2173 | } |
| 2174 | |
| 2175 | if ((ret = av_buffersrc_add_frame(is->in_audio_filter, frame)) < 0) |
| 2176 | goto the_end; |
| 2177 | |
| 2178 | while ((ret = av_buffersink_get_frame_flags(is->out_audio_filter, frame, 0)) >= 0) { |
| 2179 | FrameData *fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL; |
| 2180 | tb = av_buffersink_get_time_base(is->out_audio_filter); |
| 2181 | if (!(af = frame_queue_peek_writable(&is->sampq))) |
| 2182 | goto the_end; |
| 2183 | |
| 2184 | af->pts = (frame->pts == AV_NOPTS_VALUE) ? NAN : frame->pts * av_q2d(tb); |
nothing calls this directly
no test coverage detected