vod_status_t audio_filter_process(void* context) { audio_filter_state_t* state = context; audio_filter_source_t* source; u_char* read_buffer; uint32_t read_size; bool_t processed_data = FALSE; vod_status_t rc; bool_t frame_done; for (;;) { // choose a source if needed if (state->cur_source == NULL) { rc = audio_filter_choose_source(state, &source); if (rc != VOD_OK) { return rc; } if (source == NULL) { // done return audio_filter_flush_encoder(state); } state->cur_source = source; // start the frame rc = source->cur_frame_part.frames_source->start_frame( source->cur_frame_part.frames_source_context, source->cur_frame); if (rc != VOD_OK) { return rc; } } else { source = state->cur_source; } // read some data from the frame rc = source->cur_frame_part.frames_source->read( source->cur_frame_part.frames_source_context, &read_buffer, &read_size, &frame_done); if (rc != VOD_OK) { if (rc != VOD_AGAIN) { return rc; } if (!processed_data && !state->first_time) { vod_log_error(VOD_LOG_ERR, state->request_context->log, 0, "audio_filter_process: no data was handled, probably a truncated file"); return VOD_BAD_DATA; } state->first_time = FALSE; return VOD_AGAIN; } processed_data = TRUE; if (!frame_done) { // didn't finish the frame, append to the frame buffer vod_memcpy(state->frame_buffer + state->cur_frame_pos, read_buffer, read_size); state->cur_frame_pos += read_size; continue; } if (state->cur_frame_pos != 0) { // copy the remainder vod_memcpy(state->frame_buffer + state->cur_frame_pos, read_buffer, read_size); state->cur_frame_pos = 0; read_buffer = state->frame_buffer; } // process the frame rc = audio_filter_process_frame(state, read_buffer); if (rc != VOD_OK) { return rc; } // move to the next frame source->cur_frame++; state->cur_source = NULL; } }
vod_status_t audio_filter_process(void* context) { audio_filter_state_t* state = context; audio_filter_source_t* source; u_char* read_buffer; uint32_t read_size; uint64_t offset; bool_t processed_data = FALSE; vod_status_t rc; for (;;) { // choose a source if needed if (state->cur_source == NULL) { rc = audio_filter_choose_source(state, &source); if (rc != VOD_OK) { return rc; } if (source == NULL) { // done return audio_filter_flush_encoder(state); } state->cur_source = source; } else { source = state->cur_source; } // read some data from the frame offset = *source->cur_frame_offset + state->cur_frame_pos; if (!read_cache_get_from_cache( state->read_cache_state, source->cur_frame->size - state->cur_frame_pos, source->cache_slot_id, source->frames_source, offset, &read_buffer, &read_size)) { if (!processed_data && !state->first_time) { vod_log_error(VOD_LOG_ERR, state->request_context->log, 0, "audio_filter_process: no data was handled, probably a truncated file"); return VOD_BAD_DATA; } state->first_time = FALSE; return VOD_AGAIN; } processed_data = TRUE; if (state->cur_frame_pos == 0 && read_size >= source->cur_frame->size) { // have the whole frame in one piece rc = audio_filter_process_frame(state, read_buffer); if (rc != VOD_OK) { return rc; } // move to the next frame source->cur_frame++; source->cur_frame_offset++; state->cur_source = NULL; continue; } if (read_size < source->cur_frame->size - state->cur_frame_pos) { // didn't finish the frame, append to the frame buffer vod_memcpy(state->frame_buffer + state->cur_frame_pos, read_buffer, read_size); state->cur_frame_pos += read_size; continue; } // finished the frame vod_memcpy(state->frame_buffer + state->cur_frame_pos, read_buffer, source->cur_frame->size - state->cur_frame_pos); rc = audio_filter_process_frame(state, state->frame_buffer); if (rc != VOD_OK) { return rc; } source->cur_frame++; source->cur_frame_offset++; state->cur_frame_pos = 0; state->cur_source = NULL; } }