static inline void unmap_last_surface(struct obs_core_video *video) { if (video->mapped_surface) { stagesurface_unmap(video->mapped_surface); video->mapped_surface = NULL; } }
static bool swap_frame(uint64_t timestamp) { struct obs_video *video = &obs->video; stagesurf_t last_surface = video->copy_surfaces[video->cur_texture]; stagesurf_t surface; struct video_frame frame; /* the last frame stays mapped until rendering starts with the next */ if (video->copy_mapped) { stagesurface_unmap(last_surface); video->copy_mapped = false; } video->textures_copied[video->cur_texture] = true; /* TODO: texture staging */ //gs_stage_texture(last_surface, ); if (++video->cur_texture == NUM_TEXTURES) video->cur_texture = 0; if (video->textures_copied[video->cur_texture]) { surface = video->copy_surfaces[video->cur_texture]; video->copy_mapped = stagesurface_map(surface, &frame.data, &frame.row_size); if (video->copy_mapped) { frame.timestamp = timestamp; video_output_frame(video->video, &frame); } } return video->copy_mapped; }
static void obs_free_graphics() { struct obs_video *video = &obs->video; size_t i; if (video->graphics) { int cur_texture = video->cur_texture; gs_entercontext(video->graphics); if (video->copy_mapped) stagesurface_unmap(video->copy_surfaces[cur_texture]); for (i = 0; i < NUM_TEXTURES; i++) { stagesurface_destroy(video->copy_surfaces[i]); texture_destroy(video->render_textures[i]); texture_destroy(video->output_textures[i]); video->copy_surfaces[i] = NULL; video->render_textures[i] = NULL; video->output_textures[i] = NULL; } effect_destroy(video->default_effect); video->default_effect = NULL; gs_leavecontext(); gs_destroy(video->graphics); video->graphics = NULL; video->cur_texture = 0; } }
static void obs_free_video(void) { struct obs_core_video *video = &obs->video; if (video->video) { obs_display_free(&video->main_display); video_output_close(video->video); video->video = NULL; if (!video->graphics) return; gs_entercontext(video->graphics); if (video->mapped_surface) { stagesurface_unmap(video->mapped_surface); video->mapped_surface = NULL; } for (size_t i = 0; i < NUM_TEXTURES; i++) { stagesurface_destroy(video->copy_surfaces[i]); texture_destroy(video->render_textures[i]); texture_destroy(video->convert_textures[i]); texture_destroy(video->output_textures[i]); source_frame_free(&video->convert_frames[i]); video->copy_surfaces[i] = NULL; video->render_textures[i] = NULL; video->convert_textures[i] = NULL; video->output_textures[i] = NULL; } gs_leavecontext(); video->cur_texture = 0; } }