Index: include/libroar/stream.h
===================================================================
--- include/libroar/stream.h	(revision 1032)
+++ include/libroar/stream.h	(revision 1043)
@@ -58,4 +58,7 @@
 //#define ROAR_FLAG_SYNC           0x08
 
+#define ROAR_SET_FLAG            0
+#define ROAR_RESET_FLAG          1
+
 struct roar_stream_info {
  int block_size;
@@ -84,4 +87,6 @@
 int roar_stream_get_info (struct roar_connection * con, struct roar_stream * s, struct roar_stream_info * info);
 
+int roar_stream_set_flags (struct roar_connection * con, struct roar_stream * s, int flags, int reset);
+
 int roar_stream_s2m     (struct roar_stream * s, struct roar_message * m);
 int roar_stream_m2s     (struct roar_stream * s, struct roar_message * m);
Index: libroar/stream.c
===================================================================
--- libroar/stream.c	(revision 964)
+++ libroar/stream.c	(revision 1043)
@@ -289,4 +289,32 @@
  info->codec          = data[5];
  info->flags          = data[6];
+
+ return 0;
+}
+
+int roar_stream_set_flags (struct roar_connection * con, struct roar_stream * s, int flags, int reset) {
+ struct roar_message m;
+ uint16_t * data = (uint16_t *) m.data;
+ int i;
+
+ m.cmd     = ROAR_CMD_SET_STREAM_PARA;
+ m.stream  = s->id;
+ m.datalen = 8;
+ m.pos     = 0;
+
+ data[0] = 0; // Version and reserved
+ data[1] = 2; // flags
+ data[2] = reset == ROAR_RESET_FLAG ? ROAR_RESET_FLAG : ROAR_SET_FLAG;
+ data[3] = flags;
+
+ for (i = 0; i < m.datalen/2; i++) {
+  data[i] = ROAR_HOST2NET16(data[i]);
+ }
+
+ if ( roar_req(con, &m, NULL) == -1 )
+  return -1;
+
+ if ( m.cmd != ROAR_CMD_OK )
+  return -1;
 
  return 0;
Index: roarclients/roarctl.c
===================================================================
--- roarclients/roarctl.c	(revision 1032)
+++ roarclients/roarctl.c	(revision 1043)
@@ -379,4 +379,30 @@
 }
 
+int set_flags (struct roar_connection * con, int id, int reset, char * flags) {
+ int f = ROAR_FLAG_NONE;
+ char * c;
+ struct roar_stream s[1];
+
+ memset(s, 0, sizeof(struct roar_stream));
+
+ s->id = id;
+
+ c = strtok(flags, ",");
+ while (c != NULL) {
+  if ( !strcmp(c, "meta") ) {
+   f |= ROAR_FLAG_META;
+  } else if ( !strcmp(c, "primary") ) {
+   f |= ROAR_FLAG_PRIMARY;
+  } else {
+   fprintf(stderr, "Error: unknown flag: %s\n", c);
+   return -1;
+  }
+
+  c = strtok(NULL, ",");
+ }
+
+ return roar_stream_set_flags(con, s, f, reset);
+}
+
 int main (int argc, char * argv[]) {
  struct roar_connection con;
@@ -513,4 +539,20 @@
    }
 
+  } else if ( !strcmp(k, "flag") ) {
+   i++;
+   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
+    fprintf(stderr, "Error: can not set flags\n");
+   } else {
+    printf("flags changed\n");
+   }
+   i++;
+  } else if ( !strcmp(k, "unflag") ) {
+   i++;
+   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
+    fprintf(stderr, "Error: can not reset flags\n");
+   } else {
+    printf("flags changed\n");
+   }
+   i++;
   } else if ( !strcmp(k, "metaset") ) {
    i++;
Index: roard/commands.c
===================================================================
--- roard/commands.c	(revision 768)
+++ roard/commands.c	(revision 1043)
@@ -55,4 +55,5 @@
   {ROAR_CMD_GET_VOL,      "GET_VOL",      req_on_get_vol},
   {ROAR_CMD_GET_STREAM_PARA, "GET_STREAM_PARA", req_on_get_stream_para},
+  {ROAR_CMD_SET_STREAM_PARA, "SET_STREAM_PARA", req_on_set_stream_para},
 
   {ROAR_CMD_ADD_DATA,     "ADD_DATA",     req_on_add_data},
Index: roard/include/req.h
===================================================================
--- roard/include/req.h	(revision 768)
+++ roard/include/req.h	(revision 1043)
@@ -56,4 +56,5 @@
 
 int req_on_get_stream_para (int client, struct roar_message * mes, char * data);
+int req_on_set_stream_para (int client, struct roar_message * mes, char * data);
 
 int req_on_kick        (int client, struct roar_message * mes, char * data);
Index: roard/req.c
===================================================================
--- roard/req.c	(revision 1038)
+++ roard/req.c	(revision 1043)
@@ -501,4 +501,34 @@
 }
 
+int req_on_set_stream_para (int client, struct roar_message * mes, char * data) {
+ uint16_t * d = (uint16_t *) mes->data;
+ int i;
+
+ if ( mes->datalen != 8 )
+  return -1;
+
+ for (i = 0; i < mes->datalen/2; i++) {
+  d[i] = ROAR_NET2HOST16(d[i]);
+ }
+
+ if ( d[0] != 0 || d[1] != 2 ) {
+  ROAR_WARN("req_on_set_stream_para(*): unsupported command version: %i, %i", d[0], d[1]);
+  return -1;
+ }
+
+ mes->cmd     = ROAR_CMD_OK;
+ mes->datalen = 0;
+
+ ROAR_WARN("req_on_set_stream_para(*): request seems to be valid");
+
+ if ( d[2] == ROAR_RESET_FLAG ) {
+  return streams_reset_flag(mes->stream, d[3]);
+ } else {
+  return streams_set_flag(mes->stream, d[3]);
+ }
+
+ return -1;
+}
+
 int req_on_kick (int client, struct roar_message * mes, char * data) {
  uint16_t * info = (uint16_t *) mes->data;
Index: roard/streams.c
===================================================================
--- roard/streams.c	(revision 1042)
+++ roard/streams.c	(revision 1043)
@@ -267,6 +267,14 @@
   return -1;
 
+ if ( flag & ROAR_FLAG_PRIMARY ) {
+  streams_set_primary(id, 1);
+  flag -= ROAR_FLAG_PRIMARY;
+ }
+
  g_streams[id]->flags |= flag;
 
+ if ( flag & ROAR_FLAG_META )
+  stream_meta_finalize(id);
+
  return 0;
 }
@@ -275,4 +283,9 @@
  if ( g_streams[id] == NULL )
   return -1;
+
+ if ( flag & ROAR_FLAG_PRIMARY ) {
+  streams_set_primary(id, 0);
+  flag -= ROAR_FLAG_PRIMARY;
+ }
 
  g_streams[id]->flags |= flag;
