~ubuntu-branches/ubuntu/karmic/aqualung/karmic

« back to all changes in this revision

Viewing changes to src/core.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Cécile (Le_Vert)
  • Date: 2007-10-04 14:03:26 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071004140326-h00cr9l1jibc74j0
Tags: 0.9~beta8-2
* Improve debian/menu (Closes: #445126).
* Improve .desktop to fit current FreeDesktop specifications.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    along with this program; if not, write to the Free Software
16
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
17
 
18
 
    $Id: core.c 586 2007-02-18 09:30:01Z tszilagyi $
 
18
    $Id: core.c 690 2007-06-24 11:53:48Z peterszilagyi $
19
19
*/
20
20
 
21
21
#include <config.h>
66
66
#endif /* _WIN32 */
67
67
 
68
68
#include "common.h"
 
69
#include "utils.h"
69
70
#include "version.h"
70
71
#include "rb.h"
71
72
#include "options.h"
142
143
#endif /* HAVE_LADSPA */
143
144
 
144
145
/* remote control */
 
146
extern char * tab_name;
145
147
extern int immediate_start;
146
148
extern int aqualung_session_id;
147
149
extern int aqualung_socket_fd;
234
236
        return (track == track_prev + 1) ? 1 : 0;
235
237
}
236
238
#endif /* HAVE_CDDA */
 
239
 
 
240
 
 
241
/* roll back sample_offset samples, if possible */
 
242
void
 
243
rollback(rb_t * rb, file_decoder_t * fdec, double src_ratio) {
 
244
 
 
245
        sample_offset = rb_read_space(rb) /
 
246
                (2 * sample_size) * src_ratio;
 
247
        if (sample_offset < fdec->fileinfo.total_samples - fdec->samples_left)
 
248
                file_decoder_seek(fdec, fdec->fileinfo.total_samples - fdec->samples_left - sample_offset);
 
249
        else
 
250
                file_decoder_seek(fdec, 0);
 
251
}
 
252
 
 
253
 
 
254
void
 
255
send_meta(metadata_t * meta) {
 
256
 
 
257
        char send_cmd = CMD_METABLOCK;
 
258
        rb_write(rb_disk2gui, &send_cmd, 1);
 
259
        rb_write(rb_disk2gui, (char *)&meta, sizeof(metadata_t *));
 
260
}
237
261
 
238
262
 
239
263
void *
279
303
                fprintf(stderr, "disk thread: error: file_decoder_new() failed\n");
280
304
                exit(1);
281
305
        }
 
306
        file_decoder_set_meta_cb(fdec, send_meta);
282
307
 
283
308
        if ((!readbuf) || (!framebuf)) {
284
309
                fprintf(stderr, "disk thread: malloc error\n");
424
449
                                send_cmd = CMD_FLUSH;
425
450
                                rb_write(rb_disk2out, &send_cmd, 1);
426
451
 
427
 
                                /* roll back sample_offset samples, if possible */
428
 
                                sample_offset = rb_read_space(rb) /
429
 
                                        (2 * sample_size) * src_ratio;
430
 
                                if (sample_offset <
431
 
                                    fdec->fileinfo.total_samples - fdec->samples_left)
432
 
                                        file_decoder_seek(fdec,
433
 
                                           fdec->fileinfo.total_samples - fdec->samples_left
434
 
                                           - sample_offset);
435
 
                                else
436
 
                                        file_decoder_seek(fdec, 0);
 
452
                                rollback(rb, fdec, src_ratio);
 
453
                                if (fdec->is_stream) {
 
454
                                        file_decoder_pause(fdec);
 
455
                                }
437
456
                                break;
438
457
                        case CMD_RESUME:
439
458
                                info->is_streaming = 1;
 
459
                                if (fdec->is_stream) {
 
460
                                        file_decoder_resume(fdec);
 
461
                                }
440
462
                                break;
441
463
                        case CMD_FINISH:
442
464
                                /* send FINISH to output thread, then goto exit */
453
475
                                        /* send a FLUSH command to output thread */
454
476
                                        send_cmd = CMD_FLUSH;
455
477
                                        rb_write(rb_disk2out, &send_cmd, 1);
 
478
 
 
479
                                        if (fdec->is_stream && !info->is_streaming) {
 
480
                                                file_decoder_pause(fdec);
 
481
                                        }
456
482
                                } else {
457
483
                                        /* send dummy STATUS to gui, to set pos slider to zero */
458
484
                                        disk_thread_status.samples_left = 0;
1982
2008
                
1983
2009
                "\nOptions for file loading:\n"
1984
2010
                "-E, --enqueue: Don't clear the contents of the playlist when adding new items.\n"
 
2011
                "-t[<name>], --tab[=<name>]: Add files to the specified playlist tab.\n"
1985
2012
                
1986
2013
                "\nIf you don't specify a session number via --session, the files will be opened by "
1987
2014
                "the new\ninstance, otherwise they will be sent to the already running instance you "
2087
2114
        int remote_quit = 0;
2088
2115
        char * voladj_arg = NULL;
2089
2116
 
2090
 
        char * optstring = "vho:d:c:n:p:r:a::RP:DY:s::l:m:N:BLUTFEV:Q";
 
2117
        char * optstring = "vho:d:c:n:p:r:a::RP:DY:s::l:m:N:BLUTFEV:Qt::";
2091
2118
        struct option long_options[] = {
2092
2119
                { "version", 0, 0, 'v' },
2093
2120
                { "help", 0, 0, 'h' },
2102
2129
                { "priority", 1, 0, 'P' },
2103
2130
                { "disk-realtime", 0, 0, 'D' },
2104
2131
                { "disk-priority", 1, 0, 'Y' },
2105
 
                { "srctype", 2, 0, 's' },       
 
2132
                { "srctype", 2, 0, 's' },
2106
2133
                { "show-pl", 1, 0, 'l' },
2107
2134
                { "show-ms", 1, 0, 'm' },
 
2135
                { "tab", 2, 0, 't' },
2108
2136
 
2109
2137
                { "session", 1, 0, 'N' },
2110
2138
                { "back", 0, 0, 'B' },
2124
2152
#endif /* jack || alsa || oss */
2125
2153
 
2126
2154
 
2127
 
#ifndef _WIN32
 
2155
#ifdef HAVE_JACK
2128
2156
        /* unlock memory (implicitly locked by libjack when Jack runs realtime) */
2129
2157
        if (munlockall() < 0) {
2130
2158
                fprintf(stderr, "aqualung main(): munlockall() failed\n");
2131
2159
        }
2132
 
#endif /* !_WIN32 */
 
2160
#endif /* HAVE_JACK */
2133
2161
 
2134
2162
#ifdef _WIN32
2135
2163
        g_thread_init(NULL);
2197
2225
                                                "compiled-in features.\n");
2198
2226
                                        exit(1);
2199
2227
#endif /* HAVE_OSS*/
 
2228
                                        free(output_str);
2200
2229
                                        break;
2201
2230
                                }
2202
2231
                                if (strcmp(output_str, "alsa") == 0) {
2211
2240
                                                "compiled-in features.\n");
2212
2241
                                        exit(1);
2213
2242
#endif /* HAVE_ALSA */
 
2243
                                        free(output_str);
2214
2244
                                        break;
2215
2245
                                }
2216
2246
                                if (strcmp(output_str, "jack") == 0) {
2225
2255
                                                "compiled-in features.\n");
2226
2256
                                        exit(1);
2227
2257
#endif /* HAVE_JACK */
 
2258
                                        free(output_str);
2228
2259
                                        break;
2229
2260
                                }
2230
2261
                                if (strcmp(output_str, "win32") == 0) {
2239
2270
                                                "compiled-in features.\n");
2240
2271
                                        exit(1);
2241
2272
#endif /* _WIN32 */
 
2273
                                        free(output_str);
2242
2274
                                        break;
2243
2275
                                }
 
2276
                                fprintf(stderr, "Invalid output device: %s\n", output_str);
2244
2277
                                free(output_str);
 
2278
                                exit(0);
 
2279
                                break;
2245
2280
                        case 'd':
2246
2281
                                device_name = strdup(optarg);
2247
2282
                                break;
2365
2400
                                }
2366
2401
                                break;
2367
2402
 
 
2403
                        case 't':
 
2404
                                if (optarg != NULL) {
 
2405
                                        tab_name = strdup(optarg);
 
2406
                                } else {
 
2407
                                        tab_name = strdup("");
 
2408
                                }
 
2409
                                break;
2368
2410
                        case 'N':
2369
2411
                                no_session = atoi(optarg);
2370
2412
                                break;
2463
2505
                        no_session = 0;
2464
2506
                buf[0] = RCMD_VOLADJ;
2465
2507
                buf[1] = '\0';
2466
 
                strncat(buf, voladj_arg, MAXLEN-1);
 
2508
                strncat(buf, voladj_arg, MAXLEN-2);
2467
2509
                send_message_to_session(no_session, buf, strlen(buf));
2468
2510
                close_app_socket();
2469
2511
                exit(1);
2475
2517
                char fullname[MAXLEN];
2476
2518
 
2477
2519
                if ((no_session != -1) && (no_session != aqualung_session_id)) {
 
2520
 
2478
2521
                        for (i = optind; argv[i] != NULL; i++) {                                
2479
2522
 
2480
2523
                                normalize_filename(argv[i], fullname);
2481
2524
 
2482
 
                                if ((enqueue) || (i > optind)) {
2483
 
                                        buffer[0] = RCMD_ENQUEUE;
2484
 
                                        buffer[1] = '\0';
2485
 
                                        strncat(buffer, fullname, MAXLEN-1);
2486
 
                                        send_message_to_session(no_session, buffer, strlen(buffer));
2487
 
                                } else {
2488
 
                                        buffer[0] = RCMD_LOAD;
2489
 
                                        buffer[1] = '\0';
2490
 
                                        strncat(buffer, fullname, MAXLEN-1);
2491
 
                                        send_message_to_session(no_session, buffer, strlen(buffer));
 
2525
                                buffer[0] = RCMD_ADD_FILE;
 
2526
                                buffer[1] = '\0';
 
2527
                                strncat(buffer, fullname, MAXLEN-2);
 
2528
                                send_message_to_session(no_session, buffer, strlen(buffer));
 
2529
                        }
 
2530
 
 
2531
                        if (argv[optind] != NULL) {
 
2532
 
 
2533
                                buffer[0] = RCMD_ADD_COMMIT;
 
2534
                                buffer[1] = (enqueue) ? 1 : 0;
 
2535
                                buffer[2] = (play) ? 1 : 0;
 
2536
                                buffer[3] = (tab_name != NULL) ? 1 : 0;
 
2537
                                buffer[4] = '\0';
 
2538
 
 
2539
                                if (tab_name != NULL) {
 
2540
                                        strncat(buffer + 4, tab_name, MAXLEN-5);
2492
2541
                                }
2493
 
                        }
2494
 
                        if (play) {
2495
 
                                rcmd = RCMD_PLAY;
2496
 
                                send_message_to_session(no_session, &rcmd, 1);
2497
 
                        }
2498
 
                        close_app_socket();
2499
 
                        exit(0);
 
2542
 
 
2543
                                send_message_to_session(no_session, buffer, 4 + strlen(buffer + 4));
 
2544
                                close_app_socket();
 
2545
                                exit(0);
 
2546
                        }
2500
2547
                }
2501
2548
        }
2502
2549