OMXControlResult OMXControl::getEvent() { if (!bus) return KeyConfig::ACTION_BLANK; dispatch(); DBusMessage *m = dbus_connection_pop_message(bus); if (m == NULL) return KeyConfig::ACTION_BLANK; CLog::Log(LOGDEBUG, "Popped message member: %s interface: %s type: %d path: %s", dbus_message_get_member(m), dbus_message_get_interface(m), dbus_message_get_type(m), dbus_message_get_path(m) ); if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_ROOT, "Quit")) { dbus_respond_ok(m); return KeyConfig::ACTION_EXIT; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanQuit") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Fullscreen")) { dbus_respond_boolean(m, 1); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanSetFullscreen") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanRaise") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "HasTrackList")) { dbus_respond_boolean(m, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Identity")) { dbus_respond_string(m, "OMXPlayer"); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "SupportedUriSchemes")) { const char *UriSchemes[] = {"file", "http"}; dbus_respond_array(m, UriSchemes, 2); // Array is of length 2 return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "SupportedMimeTypes")) { const char *MimeTypes[] = {}; // Needs supplying dbus_respond_array(m, MimeTypes, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanGoNext") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanGoPrevious")) { dbus_respond_boolean(m, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanSeek")) { dbus_respond_boolean(m, reader->CanSeek()); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanControl") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanPlay") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "CanPause")) { dbus_respond_boolean(m, 1); } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Next")) { dbus_respond_ok(m); return KeyConfig::ACTION_NEXT_CHAPTER; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Previous")) { dbus_respond_ok(m); return KeyConfig::ACTION_PREVIOUS_CHAPTER; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Pause") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "PlayPause")) { dbus_respond_ok(m); return KeyConfig::ACTION_PAUSE; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Stop")) { dbus_respond_ok(m); return KeyConfig::ACTION_EXIT; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Seek")) { DBusError error; dbus_error_init(&error); int64_t offset; dbus_message_get_args(m, &error, DBUS_TYPE_INT64, &offset, DBUS_TYPE_INVALID); // Make sure a value is sent for seeking if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "Seek D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_int64(m, offset); return OMXControlResult(KeyConfig::ACTION_SEEK_RELATIVE, offset); } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SetPosition")) { DBusError error; dbus_error_init(&error); int64_t position; dbus_message_get_args(m, &error, DBUS_TYPE_INT64, &position, DBUS_TYPE_INVALID); // Make sure a value is sent for setting position if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "SetPosition D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_int64(m, position); return OMXControlResult(KeyConfig::ACTION_SEEK_ABSOLUTE, position); } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "PlaybackStatus")) { const char *status; if (clock->OMXIsPaused()) { status = "Paused"; } else { status = "Playing"; } dbus_respond_string(m, status); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Volume")) { DBusError error; dbus_error_init(&error); double volume; dbus_message_get_args(m, &error, DBUS_TYPE_DOUBLE, &volume, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { // i.e. Get current volume dbus_error_free(&error); dbus_respond_double(m, audio->GetVolume()); return KeyConfig::ACTION_BLANK; } else { audio->SetVolume(volume); dbus_respond_double(m, volume); return KeyConfig::ACTION_BLANK; } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Mute")) { audio->SetMute(true); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Unmute")) { audio->SetMute(false); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Position")) { // Returns the current position in microseconds int64_t pos = clock->OMXMediaTime(); dbus_respond_int64(m, pos); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "Duration")) { // Returns the duration in microseconds int64_t dur = reader->GetStreamLength(); dur *= 1000; // ms -> us dbus_respond_int64(m, dur); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "MinimumRate")) { dbus_respond_double(m, 0.0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PROPERTIES, "MaximumRate")) { dbus_respond_double(m, 1.125); return KeyConfig::ACTION_BLANK; // Implement extra OMXPlayer controls } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ListSubtitles")) { int count = reader->SubtitleStreamCount(); char** values = new char*[count]; for (int i=0; i < count; i++) { asprintf(&values[i], "%d:%s:%s:%s:%s", i, reader->GetStreamLanguage(OMXSTREAM_SUBTITLE, i).c_str(), reader->GetStreamName(OMXSTREAM_SUBTITLE, i).c_str(), reader->GetCodecName(OMXSTREAM_SUBTITLE, i).c_str(), ((int)subtitles->GetActiveStream() == i) ? "active" : ""); } dbus_respond_array(m, (const char**)values, count); // Cleanup for (int i=0; i < count; i++) { delete[] values[i]; } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "VideoPos")) { DBusError error; dbus_error_init(&error); const char *win; const char *oPath; // ignoring path right now because we don't have a playlist dbus_message_get_args(m, &error, DBUS_TYPE_OBJECT_PATH, &oPath, DBUS_TYPE_STRING, &win, DBUS_TYPE_INVALID); // Make sure a value is sent for setting VideoPos if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "VideoPos D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_string(m, win); return OMXControlResult(KeyConfig::ACTION_MOVE_VIDEO, win); } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "HideVideo")) { dbus_respond_ok(m); return KeyConfig::ACTION_HIDE_VIDEO; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "UnHideVideo")) { dbus_respond_ok(m); return KeyConfig::ACTION_UNHIDE_VIDEO; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ListAudio")) { int count = reader->AudioStreamCount(); char** values = new char*[count]; for (int i=0; i < count; i++) { asprintf(&values[i], "%d:%s:%s:%s:%s", i, reader->GetStreamLanguage(OMXSTREAM_AUDIO, i).c_str(), reader->GetStreamName(OMXSTREAM_AUDIO, i).c_str(), reader->GetCodecName(OMXSTREAM_AUDIO, i).c_str(), (reader->GetAudioIndex() == i) ? "active" : ""); } dbus_respond_array(m, (const char**)values, count); // Cleanup for (int i=0; i < count; i++) { delete[] values[i]; } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ListVideo")) { int count = reader->AudioStreamCount(); char** values = new char*[count]; for (int i=0; i < count; i++) { asprintf(&values[i], "%d:%s:%s:%s:%s", i, reader->GetStreamLanguage(OMXSTREAM_VIDEO, i).c_str(), reader->GetStreamName(OMXSTREAM_VIDEO, i).c_str(), reader->GetCodecName(OMXSTREAM_VIDEO, i).c_str(), (reader->GetVideoIndex() == i) ? "active" : ""); } dbus_respond_array(m, (const char**)values, count); // Cleanup for (int i=0; i < count; i++) { delete[] values[i]; } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SelectSubtitle")) { DBusError error; dbus_error_init(&error); int index; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_boolean(m, 0); } else { if (reader->SetActiveStream(OMXSTREAM_SUBTITLE, index)) { subtitles->SetActiveStream(reader->GetSubtitleIndex()); dbus_respond_boolean(m, 1); } else { dbus_respond_boolean(m, 0); } } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SelectAudio")) { DBusError error; dbus_error_init(&error); int index; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_boolean(m, 0); } else { if (reader->SetActiveStream(OMXSTREAM_AUDIO, index)) { dbus_respond_boolean(m, 1); } else { dbus_respond_boolean(m, 0); } } return KeyConfig::ACTION_BLANK; } // TODO: SelectVideo ??? else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ShowSubtitles")) { subtitles->SetVisible(true); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "HideSubtitles")) { subtitles->SetVisible(false); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Action")) { DBusError error; dbus_error_init(&error); int action; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &action, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_ok(m); return action; // Directly return enum } } else { CLog::Log(LOGWARNING, "Unhandled dbus message, member: %s interface: %s type: %d path: %s", dbus_message_get_member(m), dbus_message_get_interface(m), dbus_message_get_type(m), dbus_message_get_path(m) ); } return KeyConfig::ACTION_BLANK; }
OMXControlResult OMXControl::getEvent() { if (!bus) return KeyConfig::ACTION_BLANK; dispatch(); DBusMessage *m = dbus_connection_pop_message(bus); if (m == NULL) return KeyConfig::ACTION_BLANK; CLog::Log(LOGDEBUG, "Popped message member: %s interface: %s type: %d path: %s", dbus_message_get_member(m), dbus_message_get_interface(m), dbus_message_get_type(m), dbus_message_get_path(m) ); if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_ROOT, "Quit")) { dbus_respond_ok(m); return KeyConfig::ACTION_EXIT; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanQuit") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Fullscreen")) { dbus_respond_boolean(m, 1); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanSetFullscreen") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanRaise") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "HasTrackList")) { dbus_respond_boolean(m, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Identity")) { dbus_respond_string(m, "OMXPlayer"); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "SupportedUriSchemes")) { const char *UriSchemes[] = {"file", "http"}; dbus_respond_array(m, UriSchemes, 2); // Array is of length 2 return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "SupportedMimeTypes")) { const char *MimeTypes[] = {}; // Needs supplying dbus_respond_array(m, MimeTypes, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanGoNext") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanGoPrevious") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanSeek")) { dbus_respond_boolean(m, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanControl") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanPlay") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanPause")) { dbus_respond_boolean(m, 1); } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Next")) { dbus_respond_ok(m); return KeyConfig::ACTION_NEXT_CHAPTER; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Previous")) { dbus_respond_ok(m); return KeyConfig::ACTION_PREVIOUS_CHAPTER; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Pause")) { dbus_respond_ok(m); return KeyConfig::ACTION_PAUSE; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "PlayPause")) { dbus_respond_ok(m); return KeyConfig::ACTION_PAUSE; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Stop")) { dbus_respond_ok(m); return KeyConfig::ACTION_EXIT; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Seek")) { DBusError error; dbus_error_init(&error); int64_t offset; dbus_message_get_args(m, &error, DBUS_TYPE_INT64, &offset, DBUS_TYPE_INVALID); // Make sure a value is sent for seeking if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "Seek D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_int64(m, offset); return OMXControlResult(KeyConfig::ACTION_SEEK_RELATIVE, offset); } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SetPosition")) { DBusError error; dbus_error_init(&error); int64_t position; const char *oPath; // ignoring path right now because we don't have a playlist dbus_message_get_args(m, &error, DBUS_TYPE_OBJECT_PATH, &oPath, DBUS_TYPE_INT64, &position, DBUS_TYPE_INVALID); // Make sure a value is sent for setting position if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "SetPosition D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_int64(m, position); return OMXControlResult(KeyConfig::ACTION_SEEK_ABSOLUTE, position); } } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "PlaybackStatus")) { const char *status; if (clock->OMXIsPaused()) { status = "Paused"; } else { status = "Playing"; } dbus_respond_string(m, status); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Volume")) { DBusError error; dbus_error_init(&error); double vol; dbus_message_get_args(m, &error, DBUS_TYPE_DOUBLE, &vol, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { // i.e. Get current volume dbus_error_free(&error); long volume = audio->GetVolume(); // Volume in millibels double r = pow(10, volume / 2000.0); dbus_respond_double(m, r); return KeyConfig::ACTION_BLANK; } else { long volume = static_cast<long>(2000.0 * log10(vol)); audio->SetVolume(volume); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Position")) { int64_t pos = clock->OMXMediaTime(); dbus_respond_int64(m, pos); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Duration")) { int64_t dur = reader->GetStreamLength(); dur *= 1000; // ms -> us dbus_respond_int64(m, dur); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Time_In_Us")) { int64_t pos = clock->OMXMediaTime(); dbus_respond_int64(m, pos); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "MinimumRate")) { dbus_respond_double(m, 0.0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "MaximumRate")) { dbus_respond_double(m, 1.125); return KeyConfig::ACTION_BLANK; // Implement extra OMXPlayer controls } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Action")) { DBusError error; dbus_error_init(&error); int action; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &action, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_ok(m); return action; // Directly return enum } } else { CLog::Log(LOGWARNING, "Unhandled dbus message, member: %s interface: %s type: %d path: %s", dbus_message_get_member(m), dbus_message_get_interface(m), dbus_message_get_type(m), dbus_message_get_path(m) ); } return KeyConfig::ACTION_BLANK; }