int main(int argc, char **argv) { if (argc < 2) { printf("Usage: test_media <video_to_play>\n"); return EXIT_FAILURE; } player = android_media_new_player(); if (player == NULL) { printf("Problem creating new media player.\n"); return EXIT_FAILURE; } // Set player event cb for when the video size is known: android_media_set_video_size_cb(player, set_video_size_cb, NULL); android_media_set_media_prepared_cb(player, media_prepared_cb, NULL); printf("Setting data source to: %s.\n", argv[1]); if (android_media_set_data_source(player, argv[1]) != OK) { printf("Failed to set data source: %s\n", argv[1]); return EXIT_FAILURE; } printf("Creating EGL surface.\n"); struct ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */); if (!cs.surface) { printf("Problem acquiring surface for preview"); return EXIT_FAILURE; } printf("Creating GL texture.\n"); GLuint preview_texture_id; EGLDisplay disp = sf_client_get_egl_display(cs.client); EGLSurface surface = sf_surface_get_egl_surface(cs.surface); sf_surface_make_current(cs.surface); if (setup_video_texture(&cs, &preview_texture_id) != OK) { printf("Problem setting up GL texture for video surface.\n"); return EXIT_FAILURE; } printf("Starting video playback.\n"); android_media_play(player); while (android_media_is_playing(player)) { const GLfloat textureCoordinates[] = { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; android_media_update_surface_texture(player); calculate_position_coordinates(); gProgram = create_program(vertex_shader(), fragment_shader()); gaPositionHandle = glGetAttribLocation(gProgram, "a_position"); gaTexHandle = glGetAttribLocation(gProgram, "a_texCoord"); gsTextureHandle = glGetUniformLocation(gProgram, "s_texture"); gmTexMatrix = glGetUniformLocation(gProgram, "m_texMatrix"); glClear(GL_COLOR_BUFFER_BIT); // Use the program object glUseProgram(gProgram); // Enable attributes glEnableVertexAttribArray(gaPositionHandle); glEnableVertexAttribArray(gaTexHandle); // Load the vertex position glVertexAttribPointer(gaPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, positionCoordinates); // Load the texture coordinate glVertexAttribPointer(gaTexHandle, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinates); GLfloat matrix[16]; android_media_surface_texture_get_transformation_matrix(player, matrix); glUniformMatrix4fv(gmTexMatrix, 1, GL_FALSE, matrix); glActiveTexture(GL_TEXTURE0); // Set the sampler texture unit to 0 glUniform1i(gsTextureHandle, 0); glUniform1i(gmTexMatrix, 0); android_media_update_surface_texture(player); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(gaPositionHandle); glDisableVertexAttribArray(gaTexHandle); eglSwapBuffers(disp, surface); } android_media_stop(player); return EXIT_SUCCESS; }
int main(int argc, char** argv) { CameraControlListener listener; memset(&listener, 0, sizeof(listener)); listener.on_msg_error_cb = error_msg_cb; listener.on_msg_shutter_cb = shutter_msg_cb; listener.on_msg_focus_cb = autofocus_msg_cb; listener.on_msg_zoom_cb = zoom_msg_cb; listener.on_data_raw_image_cb = raw_data_cb; listener.on_data_compressed_image_cb = jpeg_data_cb; listener.on_preview_texture_needs_update_cb = preview_texture_needs_update_cb; camera_control = android_camera_connect_to(BACK_FACING_CAMERA_TYPE, &listener); if (camera_control == NULL) { printf("Problem connecting to camera"); return 1; } listener.context = camera_control; AndroidEventListener event_listener; event_listener.on_new_event = on_new_input_event; event_listener.context = camera_control; InputStackConfiguration input_configuration = { enable_touch_point_visualization : true, default_layer_for_touch_point_visualization : 10000, input_area_width : 1024, input_area_height : 1024 }; android_input_stack_initialize(&event_listener, &input_configuration); android_input_stack_start(); // Set the still photo size android_camera_enumerate_supported_picture_sizes(camera_control, size_cb, NULL); if (camera_width == 0 && camera_height == 0) { camera_width = 320; camera_height = 240; } android_camera_set_picture_size(camera_control, camera_width, camera_height); // Set the still photo thumbnail size android_camera_enumerate_supported_thumbnail_sizes(camera_control, thumbnail_size_cb, NULL); if (thumbnail_width == 0 && thumbnail_height == 0) { thumbnail_width = 320; thumbnail_height = 240; } android_camera_set_thumbnail_size(camera_control, thumbnail_width, thumbnail_height); AutoFocusMode af_mode; android_camera_get_auto_focus_mode(camera_control, &af_mode); printf("Current af mode: %d \n", af_mode); int zoom; android_camera_set_zoom(camera_control, 0); android_camera_get_max_zoom(camera_control, &zoom); printf("Max zoom: %d \n", zoom); android_camera_enumerate_supported_video_sizes(camera_control, size_cb, NULL); android_camera_enumerate_supported_preview_sizes(camera_control, size_cb, NULL); android_camera_set_preview_size(camera_control, camera_width, camera_height); int min_fps, max_fps, current_fps; android_camera_get_preview_fps_range(camera_control, &min_fps, &max_fps); printf("Preview fps range: [%d,%d]\n", min_fps, max_fps); android_camera_get_preview_fps(camera_control, ¤t_fps); printf("Current preview fps range: %d\n", current_fps); #if 0 android_camera_dump_parameters(camera_control); android_camera_set_display_orientation(camera_control, 90); int width, height; android_camera_get_preview_size(camera_control, &width, &height); printf("Current preview size: [%d,%d]\n", width, height); android_camera_get_picture_size(camera_control, &width, &height); printf("Current picture size: [%d,%d]\n", width, height); android_camera_get_current_zoom(camera_control, &zoom); printf("Current zoom: %d \n", zoom); EffectMode effect_mode; FlashMode flash_mode; WhiteBalanceMode wb_mode; //SceneMode scene_mode; CameraPixelFormat pixel_format; android_camera_get_effect_mode(camera_control, &effect_mode); printf("Current effect mode: %d \n", effect_mode); android_camera_get_flash_mode(camera_control, &flash_mode); printf("Current flash mode: %d \n", flash_mode); android_camera_get_white_balance_mode(camera_control, &wb_mode); ALOGD("Current wb mode: %d \n", wb_mode); #if 0 // Disabled, causes the test app to crash android_camera_get_scene_mode(camera_control, &scene_mode); printf("Current scene mode: %d \n", scene_mode); #endif android_camera_get_preview_format(camera_control, &pixel_format); printf("Current preview pixel format: %d \n", pixel_format); //android_camera_set_focus_region(camera_control, -200, -200, 200, 200, 300); #endif printf("Creating client with surface"); ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */); if (!cs.surface) { printf("Problem acquiring surface for preview"); return 1; } printf("Finished creating client with surface\n"); disp = sf_client_get_egl_display(cs.client); surface = sf_surface_get_egl_surface(cs.surface); GLuint preview_texture_id; printf("Getting a texture id\n"); glGenTextures(1, &preview_texture_id); glClearColor(1.0, 0., 0.5, 1.); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri( GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); printf("About to set preview texture\n"); android_camera_set_preview_texture(camera_control, preview_texture_id); #if 0 android_camera_set_effect_mode(camera_control, EFFECT_MODE_SEPIA); android_camera_set_flash_mode(camera_control, FLASH_MODE_AUTO); android_camera_set_auto_focus_mode(camera_control, AUTO_FOCUS_MODE_CONTINUOUS_PICTURE); #endif android_camera_start_preview(camera_control); GLfloat transformation_matrix[16]; android_camera_get_preview_texture_transformation(camera_control, transformation_matrix); glUniformMatrix4fv(render_data.matrix_loc, 1, GL_FALSE, transformation_matrix); printf("Started camera preview.\n"); while (1) { usleep(50); } stop_video_recording(recorder); android_camera_stop_preview(camera_control); android_camera_disconnect(camera_control); }
EGLNativeDisplayType SurfaceFlingerBackend::display() { //EGL_DEFAULT_DISPLAY return sf_client_get_egl_display(sf_client); }