RemuxWorker.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /******************************************************************************
  2. Copyright (C) 2014 by Ruwen Hahn <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "RemuxWorker.hpp"
  15. #include <media-io/media-remux.h>
  16. #include <qt-wrappers.hpp>
  17. void RemuxWorker::UpdateProgress(float percent)
  18. {
  19. if (abs(lastProgress - percent) < 0.1f)
  20. return;
  21. emit updateProgress(percent);
  22. lastProgress = percent;
  23. }
  24. void RemuxWorker::remux(const QString &source, const QString &target)
  25. {
  26. isWorking = true;
  27. auto callback = [](void *data, float percent) {
  28. RemuxWorker *rw = static_cast<RemuxWorker *>(data);
  29. QMutexLocker lock(&rw->updateMutex);
  30. rw->UpdateProgress(percent);
  31. return rw->isWorking;
  32. };
  33. bool stopped = false;
  34. bool success = false;
  35. media_remux_job_t mr_job = nullptr;
  36. if (media_remux_job_create(&mr_job, QT_TO_UTF8(source), QT_TO_UTF8(target))) {
  37. success = media_remux_job_process(mr_job, callback, this);
  38. media_remux_job_destroy(mr_job);
  39. stopped = !isWorking;
  40. }
  41. isWorking = false;
  42. emit remuxFinished(!stopped && success);
  43. }