static ngx_int_t ngx_http_vod_hls_init_frame_processor( ngx_http_vod_submodule_context_t* submodule_context, read_cache_state_t* read_cache_state, segment_writer_t* segment_writer, ngx_http_vod_frame_processor_t* frame_processor, void** frame_processor_state, ngx_str_t* output_buffer, size_t* response_size, ngx_str_t* content_type) { hls_muxer_state_t* state; vod_status_t rc; bool_t simulation_supported; state = ngx_pcalloc(submodule_context->request_context.pool, sizeof(hls_muxer_state_t)); if (state == NULL) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, submodule_context->request_context.log, 0, "ngx_http_vod_hls_init_frame_processor: ngx_pcalloc failed"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } rc = hls_muxer_init( state, &submodule_context->request_context, submodule_context->request_params.segment_index, &submodule_context->mpeg_metadata, read_cache_state, segment_writer->write_tail, segment_writer->context, &simulation_supported); if (rc != VOD_OK) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, submodule_context->request_context.log, 0, "ngx_http_vod_hls_init_frame_processor: hls_muxer_init failed %i", rc); return ngx_http_vod_status_to_ngx_error(rc); } if (simulation_supported) { *response_size = hls_muxer_simulate_get_segment_size(state); hls_muxer_simulation_reset(state); } *frame_processor = (ngx_http_vod_frame_processor_t)hls_muxer_process; *frame_processor_state = state; content_type->len = sizeof(mpeg_ts_content_type) - 1; content_type->data = (u_char *)mpeg_ts_content_type; return NGX_OK; }
vod_status_t hls_muxer_init_segment( request_context_t* request_context, hls_muxer_conf_t* conf, hls_encryption_params_t* encryption_params, uint32_t segment_index, media_set_t* media_set, write_callback_t write_callback, void* write_context, size_t* response_size, vod_str_t* response_header, hls_muxer_state_t** processor_state) { hls_muxer_state_t* state; bool_t simulation_supported; vod_status_t rc; state = vod_alloc(request_context->pool, sizeof(*state)); if (state == NULL) { vod_log_debug0(VOD_LOG_DEBUG_LEVEL, request_context->log, 0, "hls_muxer_init_segment: vod_alloc failed"); return VOD_ALLOC_FAILED; } rc = hls_muxer_init_base( state, request_context, conf, encryption_params, segment_index, media_set, write_callback, write_context, &simulation_supported, response_header); if (rc != VOD_OK) { return rc; } if (simulation_supported) { rc = hls_muxer_simulate_get_segment_size(state, response_size); if (rc != VOD_OK) { return rc; } hls_muxer_simulation_reset(state); } rc = hls_muxer_start_frame(state); if (rc != VOD_OK) { if (rc != VOD_NOT_FOUND) { return rc; } *processor_state = NULL; // no frames, nothing to do } else { *processor_state = state; } if (state->encrypted_write_context != NULL) { rc = aes_cbc_encrypt( state->encrypted_write_context, response_header, response_header, *processor_state == NULL); if (rc != VOD_OK) { return rc; } } return VOD_OK; }