~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/dbus-player.c

  • Committer: Osmo Antero
  • Date: 2012-09-29 18:12:44 UTC
  • Revision ID: osmoma@gmail.com-20120929181244-gmrxd5xww9pua60a
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
// MPRIS2 compliant players.
33
33
#include "dbus-mpris2.h"
34
34
 
35
 
// Handcrafted DBus-interfaces for Skype.
 
35
// Handcrafted DBus-interface for Skype.
36
36
#include "dbus-skype.h"
37
37
 
 
38
// Send commands to rec-manager.c
 
39
#include "rec-manager-struct.h"
 
40
 
38
41
// List of players
39
42
static GHashTable *g_player_list = NULL;
40
43
 
41
 
// Hopefully the core system sets this function
42
 
static DBusDataCallbackFunc g_data_callback_func;
43
 
 
44
44
static void dbus_player_disconnect_signals();
45
45
static void dbus_player_clear_list();
46
46
 
71
71
    skype_module_exit();
72
72
}
73
73
 
74
 
void dbus_player_set_callback_func(DBusDataCallbackFunc data_callback_func) {
75
 
    // Set data callback function so we can send messages to rec-manager.c
76
 
    g_data_callback_func = data_callback_func;
 
74
static RecorderCommand *convert_data(MediaPlayerRec *pl) {
 
75
    // Convert MediaPlayerRec to RecorderCommand
 
76
 
 
77
    if (!pl) return NULL;
 
78
    TrackInfo *tr = &pl->track;
 
79
 
 
80
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
 
81
    cmd->track = g_strndup(tr->track, MPRIS_STRLEN);
 
82
    cmd->artist = g_strndup(tr->artist, MPRIS_STRLEN);
 
83
    cmd->album = g_strndup(tr->album, MPRIS_STRLEN);
 
84
    cmd->track_pos = tr->current_secs;
 
85
    cmd->track_len = tr->total_secs;
 
86
    cmd->flags = tr->flags;
 
87
 
 
88
    // MediaPlayer changed status.
 
89
    // Check its status.
 
90
    if (tr->status == PLAYER_STATUS_PAUSED) {
 
91
        cmd->type = RECORDING_PAUSE;
 
92
 
 
93
    } else if (tr->status == PLAYER_STATUS_PLAYING) {
 
94
        cmd->type = RECORDING_START;
 
95
 
 
96
    } else if (tr->status == PLAYER_STATUS_NOTIFY_MSG) {
 
97
        cmd->type = RECORDING_NOTIFY_MSG;
 
98
 
 
99
    } else {
 
100
        // tr.status == PLAYER_STATUS_CLOSED ||
 
101
        // tr.status == PLAYER_STATUS_STOPPED
 
102
        cmd->type = RECORDING_STOP;
 
103
    }
 
104
 
 
105
    return cmd;
77
106
}
78
107
 
79
108
void dbus_player_process_data(gpointer player) {
80
 
    // Send message to the rec-manager.c?
81
 
 
82
 
    // Has callback function?
83
 
    if (g_data_callback_func) {
84
 
        // Send
85
 
        g_data_callback_func(player);
86
 
    }
 
109
    // Send message to the rec-manager.c
 
110
    if (!player) return;
 
111
 
 
112
    // Convert MediaPlayerRec to RecorderCommand
 
113
    RecorderCommand *cmd = convert_data(player);
 
114
 
 
115
    // Send the command. Rec-manager will free the cmd structure after processing.
 
116
    rec_manager_send_command(cmd);
87
117
}
88
118
 
89
119
void dbus_player_player_changed(gchar *service_name) {
353
383
    player->type = COMM_PROGRAM;
354
384
 
355
385
    // Set application name
356
 
    skype_get_app_name(player);
 
386
    player->app_name = skype_get_app_name();
357
387
 
358
388
    // Function to register/unregister notification methods
359
389
    player->func_set_signals = skype_setup;
377
407
    }
378
408
}
379
409
 
380
 
void dbus_player_send_notification(MediaPlayerRec *player, gchar *msg) {
381
 
    // Send notification msg to the recorder/GUI.
382
 
    MediaPlayerRec *p = NULL;
383
 
    if (player) {
384
 
        p = player;
385
 
    } else {
386
 
        // Create a dummy MediaPlayerRec
387
 
        p = mpris2_player_new(NULL);
388
 
    }
389
 
 
390
 
    // Send msg in the track field
391
 
    TrackInfo *tr = &p->track;
392
 
 
393
 
    str_copy(tr->track, msg, MPRIS_STRLEN-1);
394
 
 
395
 
    tr->status = PLAYER_STATUS_NOTIFY_MSG;
396
 
 
397
 
    // Sends the message via dbus-player.c
398
 
    dbus_player_process_data(p);
399
 
 
400
 
    // Delete it
401
 
    if (!player) {
402
 
        dbus_player_delete_item(p);
403
 
    }
 
410
void dbus_player_send_notification(gchar *msg) {
 
411
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
 
412
    cmd->type = RECORDING_NOTIFY_MSG;
 
413
    cmd->track = g_strndup(msg, MPRIS_STRLEN);
 
414
 
 
415
    // Send command to rec-manager.c. 
 
416
    // It will free the cmd structure after processing.
 
417
    rec_manager_send_command(cmd);
404
418
}
405
419