decoder_database.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef MODULES_VIDEO_CODING_DECODER_DATABASE_H_
  11. #define MODULES_VIDEO_CODING_DECODER_DATABASE_H_
  12. #include <map>
  13. #include <memory>
  14. #include "modules/video_coding/generic_decoder.h"
  15. namespace webrtc {
  16. struct VCMDecoderMapItem {
  17. public:
  18. VCMDecoderMapItem(VideoCodec* settings, int number_of_cores);
  19. ~VCMDecoderMapItem();
  20. std::unique_ptr<VideoCodec> settings;
  21. int number_of_cores;
  22. };
  23. struct VCMExtDecoderMapItem {
  24. public:
  25. VCMExtDecoderMapItem(VideoDecoder* external_decoder_instance,
  26. uint8_t payload_type);
  27. uint8_t payload_type;
  28. VideoDecoder* external_decoder_instance;
  29. };
  30. class VCMDecoderDataBase {
  31. public:
  32. VCMDecoderDataBase();
  33. ~VCMDecoderDataBase();
  34. bool DeregisterExternalDecoder(uint8_t payload_type);
  35. void RegisterExternalDecoder(VideoDecoder* external_decoder,
  36. uint8_t payload_type);
  37. bool RegisterReceiveCodec(uint8_t payload_type,
  38. const VideoCodec* receive_codec,
  39. int number_of_cores);
  40. bool DeregisterReceiveCodec(uint8_t payload_type);
  41. // Returns a decoder specified by frame.PayloadType. The decoded frame
  42. // callback of the decoder is set to |decoded_frame_callback|. If no such
  43. // decoder already exists an instance will be created and initialized.
  44. // nullptr is returned if no decoder with the specified payload type was found
  45. // and the function failed to create one.
  46. VCMGenericDecoder* GetDecoder(
  47. const VCMEncodedFrame& frame,
  48. VCMDecodedFrameCallback* decoded_frame_callback);
  49. // Returns true if the currently active decoder prefer to decode frames late.
  50. // That means that frames must be decoded near the render times stamp.
  51. bool PrefersLateDecoding() const;
  52. private:
  53. typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
  54. typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
  55. std::unique_ptr<VCMGenericDecoder> CreateAndInitDecoder(
  56. const VCMEncodedFrame& frame,
  57. VideoCodec* new_codec) const;
  58. const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const;
  59. const VCMExtDecoderMapItem* FindExternalDecoderItem(
  60. uint8_t payload_type) const;
  61. uint8_t current_payload_type_; // Corresponding to receive_codec_.
  62. VideoCodec receive_codec_;
  63. std::unique_ptr<VCMGenericDecoder> ptr_decoder_;
  64. DecoderMap dec_map_;
  65. ExternalDecoderMap dec_external_map_;
  66. };
  67. } // namespace webrtc
  68. #endif // MODULES_VIDEO_CODING_DECODER_DATABASE_H_