Re: [mpg123-devel] Please test new network code in/out of mpg123 (now with HTTPS support)!
Brought to you by:
sobukus
From: Thomas O. <tho...@or...> - 2022-05-16 07:06:05
|
Am Sun, 15 May 2022 20:53:06 -0700 schrieb Dave Yeo <dav...@gm...>: > On 05/15/22 02:54 PM, Thomas Orgis wrote: > > Am Sun, 15 May 2022 10:55:45 -0700 > > schrieb Dave Yeo <dav...@gm...>: > ... > > So what did this one do? > > > >> Seems bad versioning and actually version 0.59m+, > >> H:\tmp\mpg123_020>mpg123.exe > >> High Performance MPEG 1.0/2.0 Audio Player for Layer 1, 2 and 3. > >> Version 0.59m+ (1997/10/07). Written and copyrights by Michael Hipp. > >> Uses code from various people. See 'README' for more! > >> THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! > >> Modified and ported to OS/2 by Samuel Audet <gu...@ca...> (C) 1998 v0.20 > >> https://www.os2site.com/sw/mmedia/mp3/player/mpg123_020.zip > > > > Where is the source code for that? Can you ask Samuel Audet about that? > > src.zip in the above archive. Samuel seems long gone. Bah! Of course. But it's source.zip, not src.zip;-) I put these sources up as a fork (branch) of 0.59m under svn://scm.orgis.org/mpg123/tags/0.59m+ . > It looks like it should work but your test program doesn't work > > $ gcc -pedantic -o keytest keytest.c > > $ ./keytest > > terminal fd: 0 > > Program hangs at this point. CTRL-C to kill and keys show up So everything is buffered, not just lines. We need to change that. It must be simple. Looking at what Samuel did back then … +void start_keyboard_thread(struct frame *fr) +{ + printf("\nEsc: Unconditional termination Up: Previous Song Down: Next Song\n" + " <-: Rewind ->: Fast Forward J: Jump -/+: Volume P: Pause\n"); + keyboardtid = _beginthread(KeyboardThread,0,16384,(void *) fr); +} Whoa, a background thread reading the keyboard? And messing with the frame struct while the decoder is running? This ran on a machine with a single processor, I'm sure;-) +static void KeyboardThread(void *arg) +{ + struct frame *fr = (struct frame *) arg; + KBDKEYINFO key; + USHORT volume = 100; + + while(key.chChar != 27) + { + KbdCharIn(&key,IO_WAIT,0); + + switch(tolower(key.chChar)) + { + case '-': volume = audio_set_volume(NULL,--volume); break; + case '+': volume = audio_set_volume(NULL,++volume); break; + case 'p': paused = audio_pause(NULL,!paused); break; + case 'j': + { + char *scrstr = "Jump to:"; + USHORT row; USHORT column; + char buffer[128] = {0}; + char zero = 0; + int jumptosecs = -1; + + VioGetCurPos(&row,&column,0); + column = 50; + VioWrtCharStr(scrstr, strlen(scrstr), row, column, 0); + column += strlen(scrstr)+1; + do + { + KbdCharIn(&key,IO_WAIT,0); + switch(key.chChar) + { + case 13: + { + char *seperator = strchr(buffer,':'); + int temp; + if(seperator) + { + temp = atoi(seperator+1); + *seperator = '\0'; + jumptosecs = atoi(buffer)*60 + temp; + } + else + jumptosecs = atoi(buffer); + } + case 27: + VioWrtNChar(&zero,100,row,50, 0); + break; + + case 8: + if(*buffer) + { + *(strchr(buffer,'\0')-1) = '\0'; + VioWrtNChar(&zero,1,row,--column, 0); + } + break; + + default: + *strchr(buffer,'\0') = key.chChar; + VioWrtNChar(&key.chChar,1,row,column++, 0); + break; + } + } + while((key.chChar != 13) && (key.chChar != 27)); + key.chChar = 0; + + if(jumptosecs >= 0) + { + int sfd = freqs[fr->sampling_frequency] * (fr->lsf + 1); + + if(trashbuffers) + audio_trash_buffers(NULL); + + if(jumptosecs) + jumptoframe = (jumptosecs * sfd - (sfd/2))/(fr->lay==1 ? 384 : 1152); + else + jumptoframe = 0; + } + } + break; + } + + switch(key.chScan) + { +/* left */ case 75: + if(ffwd) break; + + if(rew) + { + audio_nobuffermode(NULL, FALSE); + rew = FALSE; + } + else + { + if(trashbuffers) + { + jumptoframe = playingframe; + audio_nobuffermode(NULL, TRUE); + audio_trash_buffers(NULL); + } + rew = TRUE; + } + break; + +/* right */case 77: + if(rew) break; + + if(ffwd) + { + audio_nobuffermode(NULL, FALSE); + ffwd = FALSE; + } + else + { + if(trashbuffers) + { + jumptoframe = playingframe; + audio_nobuffermode(NULL, TRUE); + audio_trash_buffers(NULL); + } + ffwd = TRUE; + } + break; + +/* up */ case 72: intflag = TRUE; previous = TRUE; break; +/* down */ case 80: intflag = TRUE; previous = FALSE; break; + } + } + + DosExit(EXIT_PROCESS,0); +} So the main deal is this: + KbdCharIn(&key,IO_WAIT,0); Waiting for the next keyboard character (scancode?) in a blocking manner. Not that useful. But maybe we could use that without IO_WAIT. Hm, the normal ASCII characters arrive as such and higher codes are used for things like cursor keys? I might have a flashback from old DOS programs I did with Pascal. So this is a very, very custom keyboard contol for OS/2, unrelated to what mpg123 gained later on. If the new terminal stuff worked somehow, that would be preferrable, but we could also add src/term_os2.c that is based on KbdCharIn and maybe other specific API, but since you have that POSIX layer, it would really be nice to only slightly deviate from that. Please keep us posted about progress about making the little test program work on OS/2. It should be a rather basic task for a beginner's course in programming on that platform;-) I hope some information arrives in time so that we can include it in a release. The network stuff is fine now, right? We only got dragged into the hole of terminal control as I got upset by the attribute error message you got so used to … Alrighty then, Thomas |