video_decoder.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "media/base/video_decoder.h"
  5. #include <algorithm>
  6. #include "base/command_line.h"
  7. #include "base/cxx17_backports.h"
  8. #include "base/strings/string_number_conversions.h"
  9. #include "base/system/sys_info.h"
  10. #include "media/base/limits.h"
  11. #include "media/base/media_switches.h"
  12. #include "media/base/video_frame.h"
  13. namespace media {
  14. VideoDecoder::VideoDecoder() = default;
  15. VideoDecoder::~VideoDecoder() = default;
  16. bool VideoDecoder::NeedsBitstreamConversion() const {
  17. return false;
  18. }
  19. bool VideoDecoder::CanReadWithoutStalling() const {
  20. return true;
  21. }
  22. int VideoDecoder::GetMaxDecodeRequests() const {
  23. return 1;
  24. }
  25. bool VideoDecoder::FramesHoldExternalResources() const {
  26. return false;
  27. }
  28. // static
  29. int VideoDecoder::GetRecommendedThreadCount(int desired_threads) {
  30. // If the thread count is specified on the command line, respect it so long as
  31. // it's greater than zero.
  32. const auto threads =
  33. base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  34. switches::kVideoThreads);
  35. int decode_threads;
  36. if (base::StringToInt(threads, &decode_threads) && decode_threads > 0)
  37. return decode_threads;
  38. // Clamp to the number of available logical processors/cores.
  39. desired_threads =
  40. std::min(desired_threads, base::SysInfo::NumberOfProcessors());
  41. // Always try to use at least two threads for video decoding. There is little
  42. // reason not to since current day CPUs tend to be multi-core and we measured
  43. // performance benefits on older machines such as P4s with hyperthreading.
  44. //
  45. // All our software video decoders treat having one thread the same as having
  46. // zero threads; I.e., decoding will execute on the calling thread. Therefore,
  47. // at least two threads are required to allow decoding to progress outside of
  48. // each Decode() call.
  49. return base::clamp(desired_threads,
  50. static_cast<int>(limits::kMinVideoDecodeThreads),
  51. static_cast<int>(limits::kMaxVideoDecodeThreads));
  52. }
  53. } // namespace media