Page Example

EOM Sample Overview

Mobile native

The EOM sample application demonstrates how you can use the External Output Manager API to manage the EOM modes.

The following figure illustrates the EOM modes. The default mode is mirror mode. If you connect an HDMI cable, the EOM server displays the main LCD image in an external output. If you want to display a different image, set the presentation mode.

Figure: EOM modes

EOM modes

Implementation

To use the EOM features:

  1. Initialize the EOM.

    To use the External Output Manager API, include the eom.h header file and call the eom_init() function:

    #include <eom.h>
    
    {
       eom_init();
    }
    
  2. Get the output ID.

    To retrieve the output ID, use the eom_get_eom_output_ids() function. You need the ID to get information about the output device and to control the external window.

    int 
    sample_get_output_id(const char *output_name)
    {
       eom_output_id *output_ids = NULL;
       eom_output_id output_id = 0;
       eom_output_type_e output_type = EOM_OUTPUT_TYPE_UNKNOWN;
       int id_cnt = 0;
       int i;
    
       output_ids = eom_get_eom_output_ids(&id_cnt);
       for (i = 0; i < id_cnt; i++) 
       {
          eom_get_output_type(output_ids[i], &output_type);
          if (!strncmp(output_name, "HDMI", 4)) 
          {
             if (output_type == EOM_OUTPUT_TYPE_HDMIA || output_type == EOM_OUTPUT_TYPE_HDMIB) 
             {
                output_id = output_ids[i];
                break;
             }
          }
       }
    
       if (output_ids)
          free(output_ids);
    	  
       return output_id;
    }
    
  3. Set the presentation mode.

    To connect to an external output device in the presentation mode, use the eom_set_output_attribute() function to set the presentation mode priority attribute. If the setting is successful, the External Output Manager module uses the presentation mode when the external output device is connected. If the function returns EOM_ERROR_NONE, the application can use the external output device.

    int 
    set_attribute()
    {
       eom_output_id output_id = 0;
       int ret;
    
       output_id = sample_get_output_id("HDMI");
       ret = eom_set_output_attribute(output_id, EOM_OUTPUT_ATTRIBUTE_NORMAL);
       if (ret != EOM_ERROR_NONE) 
       {
          // Attribute setting failed, the external output device cannot be used
          // Deinitializing
          eom_deinit();
    	  
          return -1;
       }
    
       return 0;
    }
    
  4. Set the external window to display an image to the external output.

    To set an external window, use the eom_set_output_window() function. This function moves the window to the external output and automatically resizes it to the best resolution of the external output.

    Before calling this function, you must receive a success return from the eom_set_output_attribute() function.

    int 
    make_external_window()
    {
       Evas_Object *window;
       window = elm_win_add(NULL, "external_window", ELM_WIN_BASIC);
       if (eom_set_output_window(output_id, window) == EOM_ERROR_NONE)
          return 0;
       
       evas_object_del(window);
    
       return -1;
    }
    
  5. Get the status of the external output device:
    • You can retrieve information about the external output device details with the following functions:

      • eom_get_output_type(): Get the connection type of the external output.
      • eom_get_output_mode(): Get the external output mode.
      • eom_get_output_attribute(): Get the presentation mode priority attribute information.
      • eom_get_output_attribute_state(): Get the attribute state information:
        • ACTIVE: The application can use the external output.
        • INACTIVE: The application was disconnected from the external output.
        • LOST: The application cannot use the external output because another application has set the attribute. The application can no longer receive the attribute state.
      • eom_get_output_resolution(): Get the best resolution of the external output device.
      • eom_get_output_physical_size(): Get the physical size of the external output device.
    • You can receive notifications about state changes of the external output device through callback functions:

      1. You can define 4 callbacks (add, remove, mode change, and attribute change):
        typedef struct
        {
           Evas_Object *external_window;
           int output_id;
        } SampleInfo;
        
        // Triggered when the external output is connected
        static void
        sample_notify_cb_output_add(eom_output_id output_id, void *user_data)
        {
           SampleInfo *info = (SampleInfo*)user_data;
           if (!info->external_window) 
           {
              // Create the external window
              make_external_window(info->external_window);
           }
        }
        
        // Triggered when the external output is disconnected
        static void
        sample_notify_cb_output_remove(eom_output_id output_id, void *user_data)
        {
           SampleInfo *info = (SampleInfo*)user_data;
           if (!info->external_window)
           {
              evas_object_del(info->external_window)
              info->external_window = NULL;
           }
        }
        
        // Triggered when the state of the EOM output attribute changes
        static void
        sample_notify_cb_attribute_changed(eom_output_id output_id, void *user_data)
        {
           SampleInfo *info = (SampleInfo*)user_data;
           eom_output_attribute_e attribute = EOM_OUTPUT_ATTRIBUTE_NONE;
           eom_output_attribute_state_e state = EOM_OUTPUT_ATTRIBUTE_STATE_NONE;
           
           eom_get_output_attribute(output_id, &attribute);
           eom_get_output_attribute_state(output_id, &state);
           
           if (state == EOM_OUTPUT_ATTRIBUTE_STATE_ACTIVE)
           {
              // Start displaying the image to the external output (info->external_window)
           }
           else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_INACTIVE)
           {
              // Stop displaying the image
              // Destroy the external_window
           }
           else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_LOST)
           {
              // Stop displaying the image
              // Destroy the external_window
              // Remove the callbacks
           }
        }
        
      2. Register the callbacks:
        int 
        elm_main()
        {
           SampleInfo *info;
           eom_output_mode_e output_mode = EOM_OUTPUT_MODE_NONE;
           int ret;
           info = calloc(sizeof(SampleInfo));
           
           eom_init();
           info->output_id = sample_get_output_id ("HDMI");
           ret = eom_set_output_attribute(info->hdmi_output_id, EOM_OUTPUT_ATTRIBUTE_NORMAL);
           if (ret != EOM_ERROR_NONE) 
           {
              // Cannot use the external output device
              eom_deinit();
           } 
           else 
           {
              eom_get_output_mode(info->output_id, &output_mode);
              if (output_mode != EOM_OUTPUT_MODE_NONE) 
              {
                 // Create the external window
                 make_external_window(info->external_window);
              }
              // Add the callbacks
              eom_set_output_added_cb(sample_notify_cb_output_add, info);
              eom_set_output_removed_cb(sample_notify_cb_output_remove, info);
              eom_set_attribute_changed_cb(sample_notify_cb_attribute_changed, info);
           }
           elm_run();
        }
        
      3. When no longer needed, delete the callbacks and call the eom_deinit() function:
        static void 
        _destroy()
        {
           eom_unset_output_added_cb(sample_notify_cb_output_add);
           eom_unset_output_removed_cb(sample_notify_cb_output_remove);
           eom_unset_attribute_changed_cb(sample_notify_cb_attribute_changed);
           eom_deinit();
        }