| 2132 | } |
| 2133 | |
| 2134 | static int InitAudio( sync_common_t * common, int index ) |
| 2135 | { |
| 2136 | hb_work_object_t * w = NULL; |
| 2137 | hb_work_private_t * pv; |
| 2138 | hb_audio_t * audio; |
| 2139 | |
| 2140 | audio = hb_list_item(common->job->list_audio, index); |
| 2141 | if (audio->priv.fifo_raw == NULL) |
| 2142 | { |
| 2143 | // No input fifo, not configured |
| 2144 | return 0; |
| 2145 | } |
| 2146 | pv = calloc(1, sizeof(hb_work_private_t)); |
| 2147 | if (pv == NULL) goto fail; |
| 2148 | |
| 2149 | w = hb_get_work(common->job->h, WORK_SYNC_AUDIO); |
| 2150 | w->private_data = pv; |
| 2151 | w->audio = audio; |
| 2152 | w->fifo_in = audio->priv.fifo_raw; |
| 2153 | w->fifo_out = audio->priv.fifo_sync; |
| 2154 | |
| 2155 | pv->common = common; |
| 2156 | pv->stream = &common->streams[1 + index]; |
| 2157 | pv->stream->common = common; |
| 2158 | pv->stream->in_queue = hb_list_init(); |
| 2159 | pv->stream->scr_delay_queue = hb_list_init(); |
| 2160 | pv->stream->max_len = SYNC_MAX_AUDIO_QUEUE_LEN; |
| 2161 | pv->stream->min_len = SYNC_MIN_AUDIO_QUEUE_LEN; |
| 2162 | if (pv->stream->in_queue == NULL) goto fail; |
| 2163 | pv->stream->delta_list = hb_list_init(); |
| 2164 | if (pv->stream->delta_list == NULL) goto fail; |
| 2165 | pv->stream->type = SYNC_TYPE_AUDIO; |
| 2166 | pv->stream->first_pts = AV_NOPTS_VALUE; |
| 2167 | pv->stream->next_pts = (int64_t)AV_NOPTS_VALUE; |
| 2168 | pv->stream->last_pts = (int64_t)AV_NOPTS_VALUE; |
| 2169 | pv->stream->last_scr_pts = (int64_t)AV_NOPTS_VALUE; |
| 2170 | pv->stream->last_scr_sequence = -1; |
| 2171 | pv->stream->last_duration = (int64_t)AV_NOPTS_VALUE; |
| 2172 | pv->stream->audio.audio = audio; |
| 2173 | pv->stream->fifo_out = w->fifo_out; |
| 2174 | |
| 2175 | if (!(audio->config.out.codec & HB_ACODEC_PASS_FLAG) && |
| 2176 | audio->config.in.samplerate != audio->config.out.samplerate) |
| 2177 | { |
| 2178 | /* Initialize samplerate conversion */ |
| 2179 | pv->stream->audio.resample = |
| 2180 | hb_audio_resample_init(AV_SAMPLE_FMT_FLT, |
| 2181 | audio->config.out.samplerate, |
| 2182 | audio->config.out.mixdown, |
| 2183 | audio->config.out.normalize_mix_level); |
| 2184 | if (pv->stream->audio.resample == NULL) |
| 2185 | { |
| 2186 | hb_error("sync: audio 0x%x resample init failed", audio->id); |
| 2187 | goto fail; |
| 2188 | } |
| 2189 | hb_audio_resample_set_sample_rate(pv->stream->audio.resample, |
| 2190 | audio->config.in.samplerate); |
| 2191 | if (hb_audio_resample_update(pv->stream->audio.resample)) |
no test coverage detected