Project

General

Profile

Feature #343 ยป extrapriority.patch

Martin Mrvka, 2011-07-26 17:51

View differences:

src/dvb/dvb.h
205 205
  int tda_unc_is_delta;  /* 1 if we believe FE_READ_UNCORRECTED_BLOCKS
206 206
			  * return dela values */
207 207

  
208
  uint32_t tda_extrapriority; // extra priority for choosing the best adapter/service
209

  
208 210
} th_dvb_adapter_t;
209 211

  
210 212

  
......
247 249

  
248 250
htsmsg_t *dvb_fe_opts(th_dvb_adapter_t *tda, const char *which);
249 251

  
252
void dvb_adapter_set_extrapriority(th_dvb_adapter_t *tda, int extrapriority);
253

  
250 254
/**
251 255
 * DVB Multiplex
252 256
 */
src/dvb/dvb_adapter.c
86 86
  htsmsg_add_u32(m, "dump_muxes", tda->tda_dump_muxes);
87 87
  htsmsg_add_u32(m, "nitoid", tda->tda_nitoid);
88 88
  htsmsg_add_u32(m, "diseqc_version", tda->tda_diseqc_version);
89
  htsmsg_add_u32(m, "extrapriority", tda->tda_extrapriority);
89 90
  hts_settings_save(m, "dvbadapters/%s", tda->tda_identifier);
90 91
  htsmsg_destroy(m);
91 92
}
......
232 233
  tda_save(tda);
233 234
}
234 235

  
236
/**
237
 *
238
 */
239
void
240
dvb_adapter_set_extrapriority(th_dvb_adapter_t *tda, int extrapriority)
241
{
242
  lock_assert(&global_lock);
243

  
244
  if(tda->tda_extrapriority == extrapriority)
245
    return;
246

  
247
  tvhlog(LOG_NOTICE, "dvb", "Adapter \"%s\" extra priority \"%d\" changed to \"%d\"",
248
         tda->tda_displayname, tda->tda_extrapriority, extrapriority);
249

  
250
  tda->tda_extrapriority = extrapriority;
251
  tda_save(tda);
252
}
235 253

  
236 254
/**
237 255
 *
......
383 401
      htsmsg_get_u32(c, "dump_muxes", &tda->tda_dump_muxes);
384 402
      htsmsg_get_u32(c, "nitoid", &tda->tda_nitoid);
385 403
      htsmsg_get_u32(c, "diseqc_version", &tda->tda_diseqc_version);
404
      htsmsg_get_u32(c, "extrapriority", &tda->tda_extrapriority);
386 405
    }
387 406
    htsmsg_destroy(l);
388 407
  }
src/service.c
231 231
static int
232 232
dvb_extra_prio(th_dvb_adapter_t *tda)
233 233
{
234
  return tda->tda_hostconnection * 10;
234
  return tda->tda_extrapriority + tda->tda_hostconnection * 10;
235 235
}
236 236

  
237 237
/**
......
285 285
  service_t *a = *(service_t **)A;
286 286
  service_t *b = *(service_t **)B;
287 287

  
288
  int q = service_get_quality(a) - service_get_quality(b);
288
  /* only check quality if both adapters have the same prio
289
   *
290
   * there needs to be a much more sophisticated algorithm to take priority and quality into account
291
   * additional, it may be problematic, since a higher priority value lowers the ranking
292
   *
293
   */
294
  if (dvb_extra_prio(a->s_dvb_mux_instance->tdmi_adapter) == dvb_extra_prio(b->s_dvb_mux_instance->tdmi_adapter)) {
295

  
296
    int q = service_get_quality(a) - service_get_quality(b);
289 297

  
290
  if(q != 0)
291
    return q; /* Quality precedes priority */
298
    if(q != 0)
299
      return q; /* Quality precedes priority */
300
  }
292 301

  
293 302
  return service_get_prio(a) - service_get_prio(b);
294 303
}
......
335 344
      continue;
336 345
    }
337 346
    vec[cnt++] = t;
347
    tvhlog(LOG_DEBUG, "Service",
348
    		"%s: Adding adapter \"%s\" for service \"%s\"",
349
    		 loginfo, t->s_dvb_mux_instance->tdmi_identifier, service_nicename(t));
338 350
  }
339 351

  
340 352
  /* Sort services, lower priority should come come earlier in the vector
......
358 370
  /* First, try all services without stealing */
359 371
  for(i = off; i < cnt; i++) {
360 372
    t = vec[i];
373
    tvhlog(LOG_DEBUG, "Service", "%s: Probing adapter \"%s\" without stealing for service \"%s\"",
374
	     loginfo, t->s_dvb_mux_instance->tdmi_identifier, service_nicename(t));
375

  
361 376
    if(t->s_status == SERVICE_RUNNING) 
362 377
      return t;
363 378
    if((r = service_start(t, 0, 0)) == 0)
......
372 387

  
373 388
  for(i = off; i < cnt; i++) {
374 389
    t = vec[i];
390
    tvhlog(LOG_DEBUG, "Service", "%s: Probing adapter \"%s\" with weight %d for service \"%s\"",
391
	     loginfo, t->s_dvb_mux_instance->tdmi_identifier, weight, service_nicename(t));
392

  
375 393
    if((r = service_start(t, weight, 0)) == 0)
376 394
      return t;
377 395
    *errorp = r;
src/webui/extjs_dvb.c
156 156
		   ((const char *[]){"DiSEqC 1.0 / 2.0",
157 157
				       "DiSEqC 1.1 / 2.1"})
158 158
		   [tda->tda_diseqc_version % 2]);
159
    htsmsg_add_u32(r, "extrapriority", tda->tda_extrapriority);
159 160
 
160 161
    out = json_single_record(r, "dvbadapters");
161 162
  } else if(!strcmp(op, "save")) {
......
185 186
	dvb_adapter_set_diseqc_version(tda, 1);
186 187
    }
187 188

  
189
    if((s = http_arg_get(&hc->hc_req_args, "extrapriority")) != NULL)
190
      dvb_adapter_set_extrapriority(tda, atoi(s));
191

  
188 192
    out = htsmsg_create_map();
189 193
    htsmsg_add_u32(out, "success", 1);
190 194
  } else if(!strcmp(op, "addnetwork")) {
src/webui/static/app/dvb.js
1048 1048
    var confreader = new Ext.data.JsonReader({
1049 1049
	root: 'dvbadapters'
1050 1050
    }, ['name', 'automux', 'idlescan', 'diseqcversion', 'qmon',
1051
	'dumpmux', 'nitoid']);
1051
	'dumpmux', 'nitoid','extrapriority']);
1052 1052

  
1053 1053
    
1054 1054
    function saveConfForm () {
......
1092 1092
	    fieldLabel: 'NIT-o Network ID',
1093 1093
	    name: 'nitoid',
1094 1094
	    width: 50
1095
	},
1096
	{
1097
	    fieldLabel: 'Extra priority',
1098
	    name: 'extrapriority',
1099
	    width: 50
1095 1100
	}
1096 1101
    ];
1097 1102

  
    (1-1/1)