[xiph-cvs] cvs commit: ices/src encode.c encode.h cfgparse.c cfgparse.h ices.c stream.c stream_shared.c reencode.c

Karl Heyes karl at xiph.org
Mon Dec 22 06:01:10 PST 2003



karl        03/12/22 09:01:10

  Modified:    src      encode.c encode.h cfgparse.c cfgparse.h ices.c
                        stream.c stream_shared.c reencode.c
  Log:
  don't use the same serial number for multiple outgoing encoded streams,
  not a problem normally except for when an icecast fallback or moveclients
  is invoked.

Revision  Changes    Path
1.19      +29 -5     ices/src/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/encode.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- encode.c	22 Dec 2003 01:53:20 -0000	1.18
+++ encode.c	22 Dec 2003 14:01:09 -0000	1.19
@@ -1,7 +1,7 @@
 /* encode.c
  * - runtime encoding of PCM data.
  *
- * $Id: encode.c,v 1.18 2003/12/22 01:53:20 karl Exp $
+ * $Id: encode.c,v 1.19 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -29,6 +29,23 @@
 #define MODULE "encode/"
 #include "logging.h"
 
+static mutex_t _serial_lock;
+
+static long _get_serial()
+{
+    static long prev_serial = 0;
+    long serial;
+
+    thread_mutex_lock (&_serial_lock);
+    serial = prev_serial;
+    while (serial == prev_serial)
+        serial = rand();
+    prev_serial = serial;
+    thread_mutex_unlock (&_serial_lock);
+
+    return serial;
+}
+
 void encode_clear(encoder_state *s)
 {
     if(s)
@@ -42,9 +59,9 @@
     }
 }
 
+
 encoder_state *encode_initialise(int channels, int rate, int managed,
-        int min_br, int nom_br, int max_br, float quality,
-        int serial, vorbis_comment *vc)
+        int min_br, int nom_br, int max_br, float quality, vorbis_comment *vc)
 {
     encoder_state *s = calloc(1, sizeof(encoder_state));
     ogg_packet h1,h2,h3;
@@ -112,7 +129,7 @@
         vorbis_analysis_init(&s->vd, &s->vi);
         vorbis_block_init(&s->vd, &s->vb);
 
-        ogg_stream_init(&s->os, serial);
+        ogg_stream_init(&s->os, _get_serial());
 
         vorbis_analysis_headerout(&s->vd, vc, &h1,&h2,&h3);
         ogg_stream_packetin(&s->os, &h1);
@@ -275,5 +292,12 @@
         return 1;
 }
 
+void encode_init()
+{
+    thread_mutex_create (&_serial_lock);
+}
 
-
+void encode_close()
+{
+    thread_mutex_destroy (&_serial_lock);
+}

<p><p>1.5       +5 -3      ices/src/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/encode.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- encode.h	16 Mar 2003 14:21:48 -0000	1.4
+++ encode.h	22 Dec 2003 14:01:09 -0000	1.5
@@ -1,7 +1,7 @@
 /* encode.h
  * - encoding functions
  *
- * $Id: encode.h,v 1.4 2003/03/16 14:21:48 msmith Exp $
+ * $Id: encode.h,v 1.5 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -30,14 +30,16 @@
 } encoder_state;
 
 encoder_state *encode_initialise(int channels, int rate, int managed,
-    int min_br, int nom_br, int max_br, float quality,
-    int serial, vorbis_comment *vc);
+    int min_br, int nom_br, int max_br, float quality, vorbis_comment *vc);
 void encode_clear(encoder_state *s);
 void encode_data_float(encoder_state *s, float **pcm, int samples);
 void encode_data(encoder_state *s, signed char *buf, int bytes, int bigendian);
 int encode_dataout(encoder_state *s, ogg_page *og);
 void encode_finish(encoder_state *s);
 int encode_flush(encoder_state *s, ogg_page *og);
+void encode_init();
+void encode_close();
+
 
 #endif
 

<p><p>1.9       +1 -2      ices/src/cfgparse.c

Index: cfgparse.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/cfgparse.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- cfgparse.c	22 Dec 2003 01:53:20 -0000	1.8
+++ cfgparse.c	22 Dec 2003 14:01:09 -0000	1.9
@@ -1,7 +1,7 @@
 /* cfgparse.c
  * - cfgparse file reading code, plus default settings.
  *
- * $Id: cfgparse.c,v 1.8 2003/12/22 01:53:20 karl Exp $
+ * $Id: cfgparse.c,v 1.9 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -142,7 +142,6 @@
 
     instance->queue = calloc(1, sizeof(buffer_queue));
     thread_mutex_create(&instance->queue->lock);
-    instance->serial = rand();
 
     instance->next = NULL;
 }

<p><p>1.6       +1 -2      ices/src/cfgparse.h

Index: cfgparse.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/cfgparse.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- cfgparse.h	21 Dec 2003 03:38:53 -0000	1.5
+++ cfgparse.h	22 Dec 2003 14:01:09 -0000	1.6
@@ -1,7 +1,7 @@
 /* config.h
  * - configuration, and global structures built from config
  *
- * $Id: cfgparse.h,v 1.5 2003/12/21 03:38:53 karl Exp $
+ * $Id: cfgparse.h,v 1.6 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -59,7 +59,6 @@
     
     /* private */
     FILE *savefile;
-    int serial;
     int buffer_failures;
     int died;
     int kill;

<p><p>1.14      +3 -1      ices/src/ices.c

Index: ices.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/ices.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ices.c	21 Dec 2003 03:38:53 -0000	1.13
+++ ices.c	22 Dec 2003 14:01:09 -0000	1.14
@@ -1,7 +1,7 @@
 /* ices.c
  * - Main startup, thread launching, and cleanup code.
  *
- * $Id: ices.c,v 1.13 2003/12/21 03:38:53 karl Exp $
+ * $Id: ices.c,v 1.14 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -50,6 +50,7 @@
     thread_initialize();
     config_initialize();
     shout_init();
+    encode_init();
 
     signals_setup();
 
@@ -100,6 +101,7 @@
     log_close(log);
 
  fail:
+    encode_close();
     shout_shutdown();
     config_shutdown();
     thread_shutdown();

<p><p>1.31      +2 -2      ices/src/stream.c

Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- stream.c	9 Jul 2003 04:26:26 -0000	1.30
+++ stream.c	22 Dec 2003 14:01:09 -0000	1.31
@@ -1,7 +1,7 @@
 /* stream.c
  * - Core streaming functions/main loop.
  *
- * $Id: stream.c,v 1.30 2003/07/09 04:26:26 brendan Exp $
+ * $Id: stream.c,v 1.31 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -192,7 +192,7 @@
             inmod->metadata_update(inmod->internal, &sdsc->vc);
         sdsc->enc = encode_initialise(stream->channels, stream->samplerate,
                 stream->managed, stream->min_br, stream->nom_br, stream->max_br,
-                stream->quality, stream->serial++, &sdsc->vc);
+                stream->quality, &sdsc->vc);
         if(!sdsc->enc) {
             LOG_ERROR0("Failed to configure encoder");
             stream->died = 1;

<p><p>1.17      +2 -2      ices/src/stream_shared.c

Index: stream_shared.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_shared.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- stream_shared.c	4 Apr 2003 16:32:16 -0000	1.16
+++ stream_shared.c	22 Dec 2003 14:01:09 -0000	1.17
@@ -1,7 +1,7 @@
 /* stream_shared.c
  * - Stream utility functions.
  *
- * $Id: stream_shared.c,v 1.16 2003/04/04 16:32:16 karl Exp $
+ * $Id: stream_shared.c,v 1.17 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -172,7 +172,7 @@
                     sdsc->stream->samplerate, sdsc->stream->managed, 
                     sdsc->stream->min_br, sdsc->stream->nom_br, 
                     sdsc->stream->max_br, sdsc->stream->quality,
-                    sdsc->stream->serial++, &sdsc->vc);
+                    &sdsc->vc);
             if(!sdsc->enc) {
                 LOG_ERROR0("Failed to initialise encoder");
                 return -2;

<p><p>1.10      +2 -2      ices/src/reencode.c

Index: reencode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/reencode.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- reencode.c	22 Mar 2003 02:27:55 -0000	1.9
+++ reencode.c	22 Dec 2003 14:01:09 -0000	1.10
@@ -1,7 +1,7 @@
 /* reencode.c
  * - runtime reencoding of vorbis audio (usually to lower bitrates).
  *
- * $Id: reencode.c,v 1.9 2003/03/22 02:27:55 karl Exp $
+ * $Id: reencode.c,v 1.10 2003/12/22 14:01:09 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -155,7 +155,7 @@
                     s->encoder = encode_initialise(s->out_channels, 
                             s->out_samplerate, s->managed, 
                             s->out_min_br, s->out_nom_br, s->out_max_br,
-                            s->quality, s->current_serial, &s->vc);
+                            s->quality, &s->vc);
 
                     if(!s->encoder) {
                         LOG_ERROR0("Failed to configure encoder for reencoding");

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list