summaryrefslogtreecommitdiff
path: root/chromium/media/base/video_decoder.cc
blob: 626ca0f0182b68588ddc4018edb4c7efa6c7fb66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/video_decoder.h"

#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "base/system/sys_info.h"
#include "media/base/limits.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"

namespace media {

VideoDecoder::VideoDecoder() = default;

VideoDecoder::~VideoDecoder() = default;

bool VideoDecoder::IsPlatformDecoder() const {
  return false;
}

bool VideoDecoder::NeedsBitstreamConversion() const {
  return false;
}

bool VideoDecoder::CanReadWithoutStalling() const {
  return true;
}

int VideoDecoder::GetMaxDecodeRequests() const {
  return 1;
}

// static
int VideoDecoder::GetRecommendedThreadCount(int desired_threads) {
  // If the thread count is specified on the command line, respect it so long as
  // it's greater than zero.
  const auto threads =
      base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
          switches::kVideoThreads);
  int decode_threads;
  if (base::StringToInt(threads, &decode_threads) && decode_threads > 0)
    return decode_threads;

  // Clamp to the number of available logical processors/cores.
  desired_threads =
      std::min(desired_threads, base::SysInfo::NumberOfProcessors());

  // Always try to use at least two threads for video decoding. There is little
  // reason not to since current day CPUs tend to be multi-core and we measured
  // performance benefits on older machines such as P4s with hyperthreading.
  //
  // All our software video decoders treat having one thread the same as having
  // zero threads; I.e., decoding will execute on the calling thread. Therefore,
  // at least two threads are required to allow decoding to progress outside of
  // each Decode() call.
  return std::min(std::max(desired_threads,
                           static_cast<int>(limits::kMinVideoDecodeThreads)),
                  static_cast<int>(limits::kMaxVideoDecodeThreads));
}

}  // namespace media