changeset 2774:f1f7ee810de8

add metadata to stream + flush() should do a real flush at least with mp3
author Andrew O. Shadoura <bugzilla@tut.by>
date Fri, 13 Jun 2008 04:58:39 +0300
parents 624e5ed793a5
children 5df83337516f
files src/filewriter/filewriter.h src/filewriter/flac.c src/filewriter/mp3.c src/filewriter/vorbis.c src/filewriter/wav.c src/icecast/icecast.c
diffstat 6 files changed, 115 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/filewriter/filewriter.h	Tue Jun 10 21:14:28 2008 +0300
+++ b/src/filewriter/filewriter.h	Fri Jun 13 04:58:39 2008 +0300
@@ -60,6 +60,7 @@
     void (*configure)(void);
     gint (*open)(void);
     void (*write)(void *ptr, gint length);
+    void (*flush)(void);
     void (*close)(void);
     gint (*free)(void);
     gint (*playing)(void);
--- a/src/filewriter/flac.c	Tue Jun 10 21:14:28 2008 +0300
+++ b/src/filewriter/flac.c	Fri Jun 13 04:58:39 2008 +0300
@@ -28,6 +28,7 @@
 
 static gint flac_open(void);
 static void flac_write(gpointer data, gint length);
+static void flac_flush(void);
 static void flac_close(void);
 static gint flac_free(void);
 static gint flac_playing(void);
@@ -39,6 +40,7 @@
     NULL,
     flac_open,
     flac_write,
+    flac_flush,
     flac_close,
     flac_free,
     flac_playing,
@@ -172,6 +174,11 @@
 #endif
 }
 
+static void flac_flush(void)
+{
+    //should we do something here? --AOS
+}
+
 static void flac_close(void)
 {
     FLAC__stream_encoder_finish(flac_encoder);
--- a/src/filewriter/mp3.c	Tue Jun 10 21:14:28 2008 +0300
+++ b/src/filewriter/mp3.c	Fri Jun 13 04:58:39 2008 +0300
@@ -33,6 +33,7 @@
 static void mp3_configure(void);
 static gint mp3_open(void);
 static void mp3_write(void *ptr, gint length);
+static void mp3_flush(void);
 static void mp3_close(void);
 static gint mp3_free(void);
 static gint mp3_playing(void);
@@ -45,6 +46,7 @@
     mp3_configure,
     mp3_open,
     mp3_write,
+    mp3_flush,
     mp3_close,
     mp3_free,
     mp3_playing,
@@ -310,6 +312,12 @@
     olen += length;
 }
 
+static void mp3_flush(void)
+{
+    encout = lame_encode_flush_nogap(gfp, encbuffer, ENCBUFFER_SIZE);
+    write_output(encbuffer, encout);
+}
+
 static void mp3_close(void)
 {
     if (output_file)
@@ -319,13 +327,13 @@
 
 //        lame_mp3_tags_fid(gfp, output_file); // will erase id3v2 tag??
 
-        lame_close(gfp);
-        AUDDBG("lame_close() done\n");
-
-        free_lameid3(&lameid3);
-
         olen = 0;
     }
+
+    lame_close(gfp);
+    AUDDBG("lame_close() done\n");
+
+    free_lameid3(&lameid3);
 }
 
 static gint mp3_free(void)
--- a/src/filewriter/vorbis.c	Tue Jun 10 21:14:28 2008 +0300
+++ b/src/filewriter/vorbis.c	Fri Jun 13 04:58:39 2008 +0300
@@ -30,6 +30,7 @@
 static void vorbis_configure(void);
 static gint vorbis_open(void);
 static void vorbis_write(gpointer data, gint length);
+static void vorbis_flush(void);
 static void vorbis_close(void);
 static gint vorbis_free(void);
 static gint vorbis_playing(void);
@@ -42,6 +43,7 @@
     vorbis_configure,
     vorbis_open,
     vorbis_write,
+    vorbis_flush,
     vorbis_close,
     vorbis_free,
     vorbis_playing,
@@ -207,6 +209,11 @@
     olen += length;
 }
 
+static void vorbis_flush(void)
+{
+    //nothing to do here yet. --AOS
+}
+
 static void vorbis_close(void)
 {
     ogg_stream_clear(&os);
--- a/src/filewriter/wav.c	Tue Jun 10 21:14:28 2008 +0300
+++ b/src/filewriter/wav.c	Fri Jun 13 04:58:39 2008 +0300
@@ -24,6 +24,7 @@
 
 static gint wav_open(void);
 static void wav_write(void *ptr, gint length);
+static void wav_flush(void);
 static void wav_close(void);
 static gint wav_free(void);
 static gint wav_playing(void);
@@ -35,6 +36,7 @@
     NULL,
     wav_open,
     wav_write,
+    wav_flush,
     wav_close,
     wav_free,
     wav_playing,
@@ -88,6 +90,11 @@
     written += aud_vfs_fwrite(ptr, 1, length, output_file);
 }
 
+static void wav_flush(void)
+{
+    //nothing to do here yet. --AOS
+}
+
 static void wav_close(void)
 {
     if (output_file)
--- a/src/icecast/icecast.c	Tue Jun 10 21:14:28 2008 +0300
+++ b/src/icecast/icecast.c	Fri Jun 13 04:58:39 2008 +0300
@@ -148,6 +148,10 @@
 
 static void ice_cleanup(void)
 {
+    if (shout)
+    {
+        shout_close(shout);
+    }
     shout_shutdown();
 }
 
@@ -181,6 +185,8 @@
 static gint ice_open(AFormat fmt, gint rate, gint nch)
 {
     gint rv;
+    gint pos;
+    Playlist *playlist;
 
     if (ice_tid)
     {
@@ -188,63 +194,86 @@
 	ice_tid = 0;
     }
 
-    if (shout) return 1;
-
     input.format = fmt;
     input.frequency = rate;
     input.channels = nch;
 
-    rv = (plugin.open)();
-
-    if (!(shout = shout_new()))
-	return 0;
-
-    if (shout_set_host(shout, server_address) != SHOUTERR_SUCCESS)
-    {
-	printf("Error setting hostname: %s\n", shout_get_error(shout));
-	return 0;
-    }
+    playlist = aud_playlist_get_active();
+    if(!playlist)
+        return 0;
 
-    if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS)
-    {
-	printf("Error setting protocol: %s\n", shout_get_error(shout));
-	return 0;
-    }
+    pos = aud_playlist_get_position(playlist);
+    tuple = aud_playlist_get_tuple(playlist, pos);
 
-    if (shout_set_port(shout, 8000) != SHOUTERR_SUCCESS)
-    {
-	printf("Error setting port: %s\n", shout_get_error(shout));
-	return 0;
-    }
-
-    if (shout_set_password(shout, "password") != SHOUTERR_SUCCESS)
+    if (!shout)
     {
-	printf("Error setting password: %s\n", shout_get_error(shout));
-	return 0;
-    }
+        rv = (plugin.open)();
+
+        if (!(shout = shout_new()))
+            return 0;
+
+        if (shout_set_host(shout, server_address) != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting hostname: %s\n", shout_get_error(shout));
+            return 0;
+        }
+
+        if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting protocol: %s\n", shout_get_error(shout));
+            return 0;
+        }
+
+        if (shout_set_port(shout, 8000) != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting port: %s\n", shout_get_error(shout));
+            return 0;
+        }
 
-    if (shout_set_mount(shout, "/test") != SHOUTERR_SUCCESS)
-    {
-	printf("Error setting mount: %s\n", shout_get_error(shout));
-	return 0;
+        if (shout_set_password(shout, "password") != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting password: %s\n", shout_get_error(shout));
+            return 0;
+        }
+
+        if (shout_set_mount(shout, "/test") != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting mount: %s\n", shout_get_error(shout));
+            return 0;
+        }
+
+        if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting user: %s\n", shout_get_error(shout));
+            return 0;
+        }
+
+        if (shout_set_format(shout, streamformat_shout[streamformat]) != SHOUTERR_SUCCESS)
+        {
+            printf("Error setting user: %s\n", shout_get_error(shout));
+            return 0;
+        }
+
+        if (shout_open(shout) != SHOUTERR_SUCCESS)
+        {
+            printf("Error connecting to server: %s\n", shout_get_error(shout));
+            return 0;
+        }
     }
+    else
+        rv = 1;
 
-    if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS)
     {
-	printf("Error setting user: %s\n", shout_get_error(shout));
-	return 0;
-    }
-
-    if (shout_set_format(shout, streamformat_shout[streamformat]) != SHOUTERR_SUCCESS)
-    {
-	printf("Error setting user: %s\n", shout_get_error(shout));
-	return 0;
-    }
-
-    if (shout_open(shout) != SHOUTERR_SUCCESS)
-    {
-	printf("Error connecting to server: %s\n", shout_get_error(shout));
-	return 0;
+        shout_metadata_t *sm = NULL;
+        sm = shout_metadata_new();
+        if (sm)
+        {
+            shout_metadata_add(sm, "charset", "UTF-8");
+            shout_metadata_add(sm, "title", aud_tuple_get_string(tuple, FIELD_TITLE, NULL));
+            shout_metadata_add(sm, "artist", aud_tuple_get_string(tuple, FIELD_ARTIST, NULL));
+            shout_set_metadata(shout, sm);
+            shout_metadata_free(sm);
+        }
     }
 
     puts("ICE_OPEN");
@@ -320,8 +349,9 @@
 static gint ice_write_output(void *ptr, gint length)
 {
     int i, ret;
-    if (!shout) return 0;
+    if ((!shout) || (!length)) return 0;
     ret = shout_send(shout, ptr, length);
+    //shout_send_raw(shout, ptr, length);
     shout_sync(shout);
     printf("ice_write[%d:%d](", ret, length);
     for (i=0;(i<length)&&(i<16);i++)   printf("%c",g_ascii_isprint(((char*)ptr)[i])?(((char*)ptr)[i]):'.');
@@ -357,6 +387,9 @@
     if (time < 0)
         return;
 
+    plugin.flush();
+    ice_open(input.format, input.frequency, input.channels);
+
     offset = time;
 }