~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to src/mpg123.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2009-12-21 00:11:29 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20091221001129-gsbnzbenceqv4pjt
Tags: upstream-1.10.0
ImportĀ upstreamĀ versionĀ 1.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#ifdef HAVE_SYS_RESOURCE_H
18
18
#include <sys/resource.h>
19
19
#endif
20
 
#ifdef WIN32
21
 
#include <windows.h>
22
 
#endif
23
20
 
24
21
#include <errno.h>
25
22
#include <string.h>
73
70
  0 ,     /* force_reopen, always (re)opens audio device for next song */
74
71
  /* test_cpu flag is valid for multi and 3dnow.. even if 3dnow is built alone; ensure it appears only once */
75
72
  FALSE , /* normal operation */
76
 
  FALSE,  /* try to run process in 'realtime mode' */   
 
73
  FALSE,  /* try to run process in 'realtime mode' */
 
74
#ifdef HAVE_WINDOWS_H 
 
75
  0, /* win32 process priority */
 
76
#endif
77
77
  NULL,  /* wav,cdr,au Filename */
78
78
        0, /* default is to play all titles in playlist */
79
79
        NULL, /* no playlist per default */
83
83
#ifdef FIFO
84
84
        ,NULL
85
85
#endif
86
 
#ifndef WIN32
 
86
#if !defined (WIN32) || defined (__CYGWIN__)
87
87
        ,0 /* timeout */
88
88
#endif
89
89
        ,1 /* loop */
136
136
static int filept = -1;
137
137
char *binpath; /* Path to myself. */
138
138
 
 
139
/* File-global storage of command line arguments.
 
140
   They may be needed for cleanup after charset conversion. */
 
141
static char **argv = NULL;
 
142
static int    argc = 0;
 
143
 
 
144
/* Cleanup marker to know that we intiialized libmpg123 already. */
 
145
static int cleanup_mpg123 = FALSE;
 
146
 
139
147
void set_intflag()
140
148
{
141
149
        debug("set_intflag TRUE");
176
184
 
177
185
        if(mh != NULL) mpg123_delete(mh);
178
186
 
179
 
        mpg123_exit();
 
187
        if(cleanup_mpg123) mpg123_exit();
 
188
 
180
189
        httpdata_free(&htd);
 
190
 
 
191
#ifdef WIN32_WANT_UNICODE
 
192
        win32_cmdline_free(argc, argv); /* This handles the premature argv == NULL, too. */
 
193
#endif
 
194
 
181
195
        /* It's ugly... but let's just fix this still-reachable memory chunk of static char*. */
182
196
        split_dir_file("", &dummy, &dammy);
183
197
        exit(code);
400
414
        #ifdef NETWORK
401
415
        {'u', "auth",        GLO_ARG | GLO_CHAR, 0, &httpauth,   0},
402
416
        #endif
403
 
        #ifdef HAVE_SCHED_SETSCHEDULER
 
417
        #if defined (HAVE_SCHED_SETSCHEDULER) || defined (HAVE_WINDOWS_H)
404
418
        /* check why this should be a long variable instead of int! */
405
419
        {'T', "realtime",    GLO_LONG,  0, &param.realtime, TRUE },
406
420
        #else
407
421
        {'T', "realtime",    0,  realtime_not_compiled, 0,           0 },    
408
422
        #endif
 
423
        #ifdef HAVE_WINDOWS_H
 
424
        {0, "priority", GLO_ARG | GLO_INT, 0, &param.w32_priority, 0},
 
425
        #endif
409
426
        {0, "title",         GLO_INT,  0, &param.xterm_title, TRUE },
410
427
        {'w', "wav",         GLO_ARG | GLO_CHAR, set_out_wav, 0, 0 },
411
428
        {0, "cdr",           GLO_ARG | GLO_CHAR, set_out_cdr, 0, 0 },
500
517
        httpdata_reset(&htd);
501
518
        if(MPG123_OK != mpg123_param(mh, MPG123_ICY_INTERVAL, 0, 0))
502
519
        error1("Cannot (re)set ICY interval: %s", mpg123_strerror(mh));
503
 
        if(!strcmp(fname, "-")) filept = STDIN_FILENO;
 
520
        if(!strcmp(fname, "-"))
 
521
        {
 
522
                filept = STDIN_FILENO;
 
523
#ifdef WIN32
 
524
                _setmode(STDIN_FILENO, _O_BINARY);
 
525
#endif
 
526
        }
504
527
        else if (!strncmp(fname, "http://", 7)) /* http stream */
505
528
        {
506
529
                filept = http_open(fname, &htd);
507
530
                /* now check if we got sth. and if we got sth. good */
508
531
                if(    (filept >= 0) && (htd.content_type.p != NULL)
509
 
                          && !param.ignore_mime && strcmp(htd.content_type.p, "audio/mpeg") && strcmp(htd.content_type.p, "audio/x-mpeg") )
 
532
                          && !param.ignore_mime && !(debunk_mime(htd.content_type.p) & IS_FILE) )
510
533
                {
511
534
                        error1("Unknown mpeg MIME type %s - is it perhaps a playlist (use -@)?", htd.content_type.p == NULL ? "<nil>" : htd.content_type.p);
512
535
                        error("If you know the stream is mpeg1/2 audio, then please report this as "PACKAGE_NAME" bug");
675
698
#define skip_or_die(a) TRUE
676
699
#endif
677
700
 
678
 
int main(int argc, char *argv[])
 
701
#if defined (WANT_WIN32_UNICODE)
 
702
static int
 
703
argv_cleanup(void *in)
 
704
{
 
705
        debug ("argv_cleanup running!\n");
 
706
        char ** ptr;
 
707
        ptr = (char **)in;
 
708
        while (ptr && *ptr) 
 
709
        {
 
710
                free ((void *)*ptr);
 
711
                ++ptr;
 
712
        }
 
713
        free(in);
 
714
        debug ("argv_cleanup ran!\n");
 
715
        return 0;
 
716
}
 
717
#endif
 
718
 
 
719
int main(int sys_argc, char ** sys_argv)
679
720
{
680
721
        int result;
681
722
        long parr;
686
727
        struct timeval start_time;
687
728
#endif
688
729
 
 
730
#if defined (WANT_WIN32_UNICODE)
 
731
        if(win32_cmdline_utf8(&argc, &argv) != 0)
 
732
        {
 
733
                error("Cannot convert command line to UTF8!");
 
734
                safe_exit(76);
 
735
        }
 
736
#else
 
737
        argv = sys_argv;
 
738
        argc = sys_argc;
 
739
#endif
 
740
 
689
741
        /* Extract binary and path, take stuff before/after last / or \ . */
690
742
        if((prgName = strrchr(argv[0], '/')) || (prgName = strrchr(argv[0], '\\')))
691
743
        {
706
758
        if(result != MPG123_OK)
707
759
        {
708
760
                error1("Cannot initialize mpg123 library: %s", mpg123_plain_strerror(result));
709
 
                exit(77);
 
761
                safe_exit(77);
710
762
        }
 
763
        cleanup_mpg123 = TRUE;
 
764
 
711
765
        mp = mpg123_new_pars(&result); /* This may get leaked on premature exit(), which is mainly a cosmetic issue... */
712
766
        if(mp == NULL)
713
767
        {
714
768
                error1("Crap! Cannot get mpg123 parameters: %s", mpg123_plain_strerror(result));
715
 
                safe_exit(77);
 
769
                safe_exit(78);
716
770
        }
717
771
 
718
772
        /* get default values */
871
925
        }
872
926
#endif
873
927
 
874
 
#ifdef HAVE_SCHED_SETSCHEDULER
 
928
#if defined (HAVE_SCHED_SETSCHEDULER) && !defined (__CYGWIN__)
 
929
/* Cygwin --realtime seems to fail when accessing network, using win32 set priority instead */
875
930
        if (param.realtime) {  /* Get real-time priority */
876
931
          struct sched_param sp;
877
932
          fprintf(stderr,"Getting real-time priority\n");
882
937
        }
883
938
#endif
884
939
 
 
940
#ifdef HAVE_WINDOWS_H
 
941
        /* argument "3" is equivalent to realtime priority class */
 
942
        win32_set_priority( param.realtime ? 3 : param.w32_priority);
 
943
#endif
 
944
 
885
945
        if(!param.remote) prepare_playlist(argc, argv);
886
946
 
887
947
#if !defined(WIN32) && !defined(GENERIC)
1237
1297
        #ifdef HAVE_SETPRIORITY
1238
1298
        fprintf(o,"        --aggressive       tries to get higher priority (nice)\n");
1239
1299
        #endif
1240
 
        #ifdef HAVE_SCHED_SETSCHEDULER
 
1300
        #if defined (HAVE_SCHED_SETSCHEDULER) || defined (HAVE_WINDOWS_H)
1241
1301
        fprintf(o," -T     --realtime         tries to get realtime priority\n");
1242
1302
        #endif
 
1303
        #ifdef HAVE_WINDOWS_H
 
1304
        fprintf(o,"        --priority <n>     use specified process priority\n");
 
1305
        fprintf(o,"                           accepts -2 to 3 as integer arguments\n");
 
1306
        fprintf(o,"                           -2 as idle, 0 as normal and 3 as realtime.\n");
 
1307
        #endif
1243
1308
        fprintf(o," -?     --help             give compact help\n");
1244
1309
        fprintf(o,"        --longhelp         give this long help listing\n");
1245
1310
        fprintf(o,"        --version          give name / version string\n");