tor-browser

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

function_video_decoder_factory.h (2513B)


      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_DECODER_FACTORY_H_
     12 #define API_TEST_VIDEO_FUNCTION_VIDEO_DECODER_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_decoder.h"
     22 #include "api/video_codecs/video_decoder_factory.h"
     23 
     24 namespace webrtc {
     25 namespace test {
     26 
     27 // A decoder factory producing decoders by calling a supplied create function.
     28 class FunctionVideoDecoderFactory final : public VideoDecoderFactory {
     29 public:
     30  explicit FunctionVideoDecoderFactory(
     31      std::function<std::unique_ptr<VideoDecoder>()> create)
     32      : create_([create = std::move(create)](const Environment&,
     33                                             const SdpVideoFormat&) {
     34          return create();
     35        }) {}
     36  explicit FunctionVideoDecoderFactory(
     37      std::function<std::unique_ptr<VideoDecoder>(const Environment&,
     38                                                  const SdpVideoFormat&)>
     39          create)
     40      : create_(std::move(create)) {}
     41  FunctionVideoDecoderFactory(
     42      std::function<std::unique_ptr<VideoDecoder>()> create,
     43      std::vector<SdpVideoFormat> sdp_video_formats)
     44      : create_([create = std::move(create)](const Environment&,
     45                                             const SdpVideoFormat&) {
     46          return create();
     47        }),
     48        sdp_video_formats_(std::move(sdp_video_formats)) {}
     49 
     50  std::vector<SdpVideoFormat> GetSupportedFormats() const override {
     51    return sdp_video_formats_;
     52  }
     53 
     54  std::unique_ptr<VideoDecoder> Create(const Environment& env,
     55                                       const SdpVideoFormat& format) override {
     56    return create_(env, format);
     57  }
     58 
     59 private:
     60  const std::function<std::unique_ptr<VideoDecoder>(const Environment& env,
     61                                                    const SdpVideoFormat&)>
     62      create_;
     63  const std::vector<SdpVideoFormat> sdp_video_formats_;
     64 };
     65 
     66 }  // namespace test
     67 }  // namespace webrtc
     68 
     69 #endif  // API_TEST_VIDEO_FUNCTION_VIDEO_DECODER_FACTORY_H_