2
0

codecwidget.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "codecwidget.h"
  2. #include "ui_codecwidget.h"
  3. #include "fshost.h"
  4. CodecWidget::CodecWidget(QWidget *parent) :
  5. QWidget(parent),
  6. ui(new Ui::CodecWidget)
  7. {
  8. ui->setupUi(this);
  9. connect(ui->btnEnable, SIGNAL(clicked()), this, SLOT(enableCodecs()));
  10. connect(ui->btnDisable, SIGNAL(clicked()), this, SLOT(disableCodecs()));
  11. connect(ui->btnUp, SIGNAL(clicked()), this, SLOT(moveUp()));
  12. connect(ui->btnDown, SIGNAL(clicked()), this, SLOT(moveDown()));
  13. readCodecs();
  14. }
  15. CodecWidget::~CodecWidget()
  16. {
  17. delete ui;
  18. }
  19. void CodecWidget::moveUp()
  20. {
  21. QList<QListWidgetItem *>items = ui->listEnabledCodecs->selectedItems();
  22. foreach(QListWidgetItem *item, items)
  23. {
  24. int row = ui->listEnabledCodecs->row(item);
  25. if (row != 0)
  26. ui->listEnabledCodecs->insertItem(row-1, ui->listEnabledCodecs->takeItem(row));
  27. }
  28. }
  29. void CodecWidget::moveDown()
  30. {
  31. QList<QListWidgetItem *>items = ui->listEnabledCodecs->selectedItems();
  32. foreach(QListWidgetItem *item, items)
  33. {
  34. int row = ui->listEnabledCodecs->row(item);
  35. if (row != ui->listEnabledCodecs->count())
  36. ui->listEnabledCodecs->insertItem(row+1, ui->listEnabledCodecs->takeItem(row));
  37. }
  38. }
  39. void CodecWidget::enableCodecs()
  40. {
  41. QList<QListWidgetItem *>items = ui->listAvailCodecs->selectedItems();
  42. foreach(QListWidgetItem *item, items)
  43. {
  44. ui->listEnabledCodecs->insertItem(0,item->text());
  45. delete item;
  46. }
  47. }
  48. void CodecWidget::disableCodecs()
  49. {
  50. QList<QListWidgetItem *>items = ui->listEnabledCodecs->selectedItems();
  51. foreach(QListWidgetItem *item, items)
  52. {
  53. ui->listAvailCodecs->insertItem(0,item->text());
  54. delete item;
  55. }
  56. }
  57. void CodecWidget::changeEvent(QEvent *e)
  58. {
  59. QWidget::changeEvent(e);
  60. switch (e->type()) {
  61. case QEvent::LanguageChange:
  62. ui->retranslateUi(this);
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. void CodecWidget::readCodecs(void)
  69. {
  70. /* This is here to show the proper codec config! */
  71. const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
  72. uint32_t num_codecs = switch_loadable_module_get_codecs(codecs, sizeof(codecs) / sizeof(codecs[0]));
  73. uint32_t x;
  74. for (x = 0; x < num_codecs; x++) {
  75. /* Codecs we cannot enable/disable or dont want to */
  76. if (QString(codecs[x]->iananame) == "PROXY" ||
  77. QString(codecs[x]->iananame) == "PROXY-VID")
  78. {
  79. continue;
  80. }
  81. QList<QHash<QString, QString> > implList;
  82. QHash<QString, QString> implPair;
  83. implPair.insert(QString::number(codecs[x]->samples_per_second), QString::number(codecs[x]->microseconds_per_packet/1000));
  84. implList.append(implPair);
  85. /* Iterate over the other implementations */
  86. switch_codec_implementation_t *curr = codecs[x]->next;
  87. while (curr != NULL)
  88. {
  89. QHash<QString, QString> implPair;
  90. implPair.insert(QString::number(curr->samples_per_second), QString::number(curr->microseconds_per_packet/1000));
  91. implList.append(implPair);
  92. curr = curr->next;
  93. }
  94. _listCodecs.insert(codecs[x]->iananame, implList);
  95. ui->listAvailCodecs->insertItem(0, codecs[x]->iananame);
  96. }
  97. ui->listAvailCodecs->sortItems(Qt::AscendingOrder);
  98. }
  99. QString CodecWidget::getCodecString()
  100. {
  101. QString codecList;
  102. for(int i = 0; i<ui->listEnabledCodecs->count(); i++)
  103. {
  104. QString codecName = ui->listEnabledCodecs->item(i)->text();
  105. if (!_listCodecs.contains(codecName))
  106. QMessageBox::warning(this, tr("Error"), tr("Codec %1 does not exist as loaded codec, therefore will not be used.").arg(codecName), QMessageBox::Ok);
  107. codecList += codecName;
  108. if (i!= ui->listEnabledCodecs->count()-1)
  109. codecList += ",";
  110. }
  111. return codecList;
  112. }
  113. void CodecWidget::setCodecString(QString codecList)
  114. {
  115. /* Mostly for backwards compatibility. */
  116. if ( codecList.startsWith("$")) {
  117. QStringList parsed = codecList.split("{");
  118. QString var = parsed.at(1);
  119. var = var.split("}").at(0);
  120. // warning switch_core_get_Variable may return an unsafe pointer in some cases.
  121. // revise to use switch_core_get_variable_dup, and then free it after you are done.
  122. var = switch_core_get_variable(var.toAscii().data());
  123. if ( ! var.isEmpty() ) {
  124. codecList = var;
  125. }
  126. }
  127. QStringList rawEnCodecs;
  128. QStringList split = codecList.split(",");
  129. foreach(QString s, split)
  130. {
  131. QStringList cs = s.split("@");
  132. if (!rawEnCodecs.contains(cs[0]))
  133. {
  134. ui->listEnabledCodecs->insertItem(ui->listEnabledCodecs->count(), cs[0]);
  135. rawEnCodecs.append(cs[0]);
  136. }
  137. }
  138. foreach(QString c, rawEnCodecs)
  139. {
  140. foreach(QListWidgetItem *i, ui->listAvailCodecs->findItems(c, Qt::MatchExactly))
  141. {
  142. delete i;
  143. }
  144. }
  145. }