~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/rec-manager.c

  • Committer: Osmo Antero
  • Date: 2019-03-02 21:05:03 UTC
  • Revision ID: osmoma@gmail.com-20190302210503-xx6k0p0v6movm6us
Fix problem with duplicate messages from media players.

Show diffs side-by-side

added added

removed removed

Lines of Context:
157
157
 
158
158
const gchar *rec_manager_get_state_name(gint state) {
159
159
    // Return name of the recording state, state of pipeline.
160
 
 
161
 
    switch (state) {
162
 
    case GST_STATE_PAUSED:
163
 
        return "PAUSED";
164
 
 
165
 
    case GST_STATE_PLAYING:
166
 
        return "RECORDING ON";
167
 
 
168
 
    case GST_STATE_READY:
169
 
        return "IN READY STATE";
170
 
 
171
 
    case GST_STATE_NULL:
172
 
        return "RECORDING OFF";
173
 
 
174
 
    default:
175
 
        return "UNKNOWN STATE";
176
 
    }
 
160
    return rec_get_state_name(state);
 
161
 
177
162
}
178
163
 
179
164
void rec_manager_flip_recording() {
260
245
void rec_manager_stop_recording() {
261
246
    // Stop recording
262
247
 
 
248
    // First we must reset the lastly recorded track data.
 
249
    // Otherwise next PLAY/CONTINUE message from media-player will be understood as duplicate and dropped. 
 
250
    // We could let the recorder do this work in its own stop routines, BUT IT WILL NOT work right. WHY? 
 
251
    // Because the message queue (g_cmd_queue) is asynchronous, AND IT TAKE TIME for the messages pass through.
 
252
    // During that time media-player can have sent several new messages. We must be quicker !  
 
253
    // 
 
254
    // Also rec_manager_stop_recording() is acalled from many places, like the menu, start/stop Button, from media players.
 
255
    //
 
256
    gchar *audio_source = NULL;
 
257
    conf_get_string_value("audio-device-id", &audio_source);
 
258
 
 
259
    // Reset last track data (that we received from media player) 
 
260
    dbus_player_reset_values(audio_source);
 
261
 
 
262
    g_free(audio_source);
 
263
 
263
264
    // Send RECORDING_STOP message to the queue
264
265
    rec_manager_send_command_ex(RECORDING_STOP, NULL, 0);
265
266
}
281
282
    return rec_is_recording();
282
283
}
283
284
 
 
285
gboolean rec_manager_is_paused() {
 
286
    // Is paused?
 
287
    return rec_is_paused();
 
288
}
 
289
 
284
290
void rec_manager_send_gui_msg(gchar *msg) {
285
291
    // Display a message in the GUI (normally a red label in the GUI)
286
292
 
311
317
    cmd->title = g_strdup(txt);  // Convey msg or txt in the "title" field.
312
318
    cmd->flags = flags;
313
319
 
314
 
    // Send the command. The command que will free the cmd after usage.
 
320
    // Send the command. The queue will free the cmd after usage.
315
321
    rec_manager_send_command(cmd);
316
322
}
317
323
 
335
341
#endif
336
342
 
337
343
    if (cmd->type == RECORDING_START) {
338
 
        // Save the values so gst-recorder.c can grab them
339
 
        conf_save_string_value("track/track-name", check_null(cmd->title));
 
344
        // Save the values in Gsettings so gst-recorder.c can grab 
 
345
        // Please see: data/org.gnome.audio-recorder.gschema.xml
 
346
        conf_save_string_value("track/track-title", check_null(cmd->title));
340
347
        conf_save_int_value("track/track-pos", cmd->trackPos);
341
348
        conf_save_int_value("track/track-len", cmd->trackLength);
342
349
        conf_save_string_value("track/artist-name", check_null(cmd->artist));
343
350
        conf_save_string_value("track/album-name", check_null(cmd->album));
 
351
        conf_save_string_value("track/url", check_null(cmd->url));
344
352
    }
345
353
 
346
354
    // Verify the delete flag and filename