tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

function_video_encoder_factory.h (2142B)


      1 /*
      2 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef API_TEST_VIDEO_FUNCTION_VIDEO_ENCODER_FACTORY_H_
     12 #define API_TEST_VIDEO_FUNCTION_VIDEO_ENCODER_FACTORY_H_
     13 
     14 #include <functional>
     15 #include <memory>
     16 #include <utility>
     17 #include <vector>
     18 
     19 #include "api/environment/environment.h"
     20 #include "api/video_codecs/sdp_video_format.h"
     21 #include "api/video_codecs/video_encoder.h"
     22 #include "api/video_codecs/video_encoder_factory.h"
     23 #include "rtc_base/checks.h"
     24 
     25 namespace webrtc {
     26 namespace test {
     27 
     28 // An encoder factory producing encoders by calling a supplied create
     29 // function.
     30 class FunctionVideoEncoderFactory final : public VideoEncoderFactory {
     31 public:
     32  explicit FunctionVideoEncoderFactory(
     33      std::function<std::unique_ptr<VideoEncoder>()> create)
     34      : create_([create = std::move(create)](const Environment&,
     35                                             const SdpVideoFormat&) {
     36          return create();
     37        }) {}
     38  explicit FunctionVideoEncoderFactory(
     39      std::function<std::unique_ptr<VideoEncoder>(const Environment&,
     40                                                  const SdpVideoFormat&)>
     41          create)
     42      : create_(std::move(create)) {}
     43 
     44  // Unused by tests.
     45  std::vector<SdpVideoFormat> GetSupportedFormats() const override {
     46    RTC_DCHECK_NOTREACHED();
     47    return {};
     48  }
     49 
     50  std::unique_ptr<VideoEncoder> Create(const Environment& env,
     51                                       const SdpVideoFormat& format) override {
     52    return create_(env, format);
     53  }
     54 
     55 private:
     56  const std::function<std::unique_ptr<VideoEncoder>(const Environment&,
     57                                                    const SdpVideoFormat&)>
     58      create_;
     59 };
     60 
     61 }  // namespace test
     62 }  // namespace webrtc
     63 
     64 #endif  // API_TEST_VIDEO_FUNCTION_VIDEO_ENCODER_FACTORY_H_