Browse Source

Stream can now be reused to stop/start different streams.

Jordy Sipkema 9 năm trước cách đây
mục cha
commit
807374f8d0
3 tập tin đã thay đổi với 17 bổ sung11 xóa
  1. 2 2
      main.c
  2. 14 9
      mp3stream.c
  3. 1 0
      mp3stream.h

+ 2 - 2
main.c

@@ -319,8 +319,8 @@ int main(void)
 	/* Enable global interrupts */
 	sei();
 
-
-
+    // Set volume to its default value
+    setVolume();
 	
 	LcdBackLight(LCD_BACKLIGHT_OFF);
 	X12RtcGetClock(&timeCheck);

+ 14 - 9
mp3stream.c

@@ -12,9 +12,11 @@
 
 #include "vs10xx.h"
 
-#define OK       1
-#define NOK      0
-#define MSIZE    1024
+#define OK              1
+#define NOK             0
+#define DEFAULT_VOLUME  7
+#define MSIZE           1024
+#define NUTSEGBUFFER    4096
 
 typedef struct _StreamArgs {
     FILE *stream;
@@ -22,23 +24,21 @@ typedef struct _StreamArgs {
 
 // Prototypes - Functions for internal use only! (They wont be visible outside this file!)
 THREAD(Mp3Player, args);
-void setVolume(void);
 int ProcessStreamMetaData(FILE *stream);
 
 // Variables
 static bool stream_connected = false;
 static bool stream_stopped = false;
 
-static u_char VS_volume = 7; //[0-16]; (Default volume = 7/16
+static u_char VS_volume = DEFAULT_VOLUME; //[0-16]; (Default volume = 7/16
 static u_long metaInt = 0;
 
 FILE *stream;
-
+TCPSOCKET *socket;
 
 bool connectToStream(u_long ipAddressStream, u_short port, char *radioUrl
 )
 {
-    TCPSOCKET *socket;
     stream_connected = false;
     bool result = true;
     char* data;
@@ -68,6 +68,7 @@ bool connectToStream(u_long ipAddressStream, u_short port, char *radioUrl
 
     // Server will respond with a HTTP-header. Fetch it to the buffer.
     stream_connected = true;
+    stream_stopped = false;
 
     data = (char *)malloc(MSIZE * sizeof(char));
 
@@ -144,11 +145,12 @@ u_char volumeDown(void)
 void setVolume(void){
     u_char volumeToSet = (128 - (VS_volume * 8)) % 129;
     VsSetVolume(volumeToSet, volumeToSet);
-    printf("setVolume %d\n", VS_volume);
+    printf("- VS_volume level: %d/16\n", VS_volume);
 }
 
 void killPlayerThread(void)
 {
+    printf("Signal to stop the stream sent.\n");
     stream_stopped = true;
 }
 
@@ -168,7 +170,7 @@ THREAD(Mp3Player, args)
     u_long mp3left = metaInt;
 
     // Init MP3-buffer. NutSegBuf is a global system buffer.
-    if (0 != NutSegBufInit(8192)){
+    if (0 != NutSegBufInit(NUTSEGBUFFER)){
         // Reset the global buffer.
         ief = VsPlayerInterrupts(0);
         NutSegBufReset();
@@ -220,7 +222,10 @@ THREAD(Mp3Player, args)
          */
         while (rbytes) {
             if (stream_stopped == true) {
+                printf("Signal to stop the stream recieved\n.");
+                stream_connected = false;
                 VsPlayerStop();
+                NutTcpCloseSocket(socket);
                 NutThreadExit();
             }
 

+ 1 - 0
mp3stream.h

@@ -19,6 +19,7 @@ void killPlayerThread(void);
 
 u_char volumeUp(void);
 u_char volumeDown(void);
+void setVolume(void); // Do not use this one, this is invoked by volumeUp/Down
 
 
 #endif //MUTLI_OS_BUILD_MP3STREAM_H