tor-browser

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

decoder_database.h (2755B)


      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 MODULES_VIDEO_CODING_DECODER_DATABASE_H_
     12 #define MODULES_VIDEO_CODING_DECODER_DATABASE_H_
     13 
     14 #include <stdint.h>
     15 
     16 #include <map>
     17 #include <memory>
     18 #include <optional>
     19 
     20 #include "api/sequence_checker.h"
     21 #include "api/video/encoded_frame.h"
     22 #include "api/video_codecs/video_decoder.h"
     23 #include "modules/video_coding/generic_decoder.h"
     24 #include "rtc_base/thread_annotations.h"
     25 
     26 namespace webrtc {
     27 
     28 class VCMDecoderDatabase {
     29 public:
     30  VCMDecoderDatabase();
     31  VCMDecoderDatabase(const VCMDecoderDatabase&) = delete;
     32  VCMDecoderDatabase& operator=(const VCMDecoderDatabase&) = delete;
     33  ~VCMDecoderDatabase() = default;
     34 
     35  // Returns a pointer to the previously registered decoder or nullptr if none
     36  // was registered for the `payload_type`.
     37  void DeregisterExternalDecoder(uint8_t payload_type);
     38  void RegisterExternalDecoder(uint8_t payload_type,
     39                               std::unique_ptr<VideoDecoder> external_decoder);
     40  bool IsExternalDecoderRegistered(uint8_t payload_type) const;
     41 
     42  void RegisterReceiveCodec(uint8_t payload_type,
     43                            const VideoDecoder::Settings& settings);
     44  bool DeregisterReceiveCodec(uint8_t payload_type);
     45  void DeregisterReceiveCodecs();
     46 
     47  // Returns a decoder specified by frame.PayloadType. The decoded frame
     48  // callback of the decoder is set to `decoded_frame_callback`. If no such
     49  // decoder already exists an instance will be created and initialized.
     50  // nullptr is returned if no decoder with the specified payload type was found
     51  // and the function failed to create one.
     52  VCMGenericDecoder* GetDecoder(
     53      const EncodedFrame& frame,
     54      VCMDecodedFrameCallback* decoded_frame_callback);
     55 
     56 private:
     57  void CreateAndInitDecoder(const EncodedFrame& frame)
     58      RTC_RUN_ON(decoder_sequence_checker_);
     59 
     60  SequenceChecker decoder_sequence_checker_;
     61 
     62  std::optional<uint8_t> current_payload_type_;
     63  std::optional<VCMGenericDecoder> current_decoder_
     64      RTC_GUARDED_BY(decoder_sequence_checker_);
     65  // Initialization paramaters for decoders keyed by payload type.
     66  std::map<uint8_t, VideoDecoder::Settings> decoder_settings_;
     67  // Decoders keyed by payload type.
     68  std::map<uint8_t, std::unique_ptr<VideoDecoder>> decoders_
     69      RTC_GUARDED_BY(decoder_sequence_checker_);
     70 };
     71 
     72 }  // namespace webrtc
     73 
     74 #endif  // MODULES_VIDEO_CODING_DECODER_DATABASE_H_