cdm_helpers.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_CDM_CDM_HELPERS_H_
  5. #define MEDIA_CDM_CDM_HELPERS_H_
  6. #include <stdint.h>
  7. #include "base/compiler_specific.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "media/base/media_export.h"
  11. #include "media/base/video_color_space.h"
  12. #include "media/cdm/api/content_decryption_module.h"
  13. #include "ui/gfx/geometry/size.h"
  14. namespace media {
  15. class VideoFrame;
  16. class DecryptedBlockImpl final : public cdm::DecryptedBlock {
  17. public:
  18. DecryptedBlockImpl();
  19. DecryptedBlockImpl(const DecryptedBlockImpl&) = delete;
  20. DecryptedBlockImpl& operator=(const DecryptedBlockImpl&) = delete;
  21. ~DecryptedBlockImpl() final;
  22. // cdm::DecryptedBlock implementation.
  23. void SetDecryptedBuffer(cdm::Buffer* buffer) final;
  24. cdm::Buffer* DecryptedBuffer() final;
  25. void SetTimestamp(int64_t timestamp) final;
  26. int64_t Timestamp() const final;
  27. private:
  28. raw_ptr<cdm::Buffer> buffer_;
  29. int64_t timestamp_;
  30. };
  31. class MEDIA_EXPORT VideoFrameImpl : public cdm::VideoFrame,
  32. public cdm::VideoFrame_2 {
  33. public:
  34. VideoFrameImpl();
  35. VideoFrameImpl(const VideoFrameImpl&) = delete;
  36. VideoFrameImpl& operator=(const VideoFrameImpl&) = delete;
  37. ~VideoFrameImpl() override;
  38. // cdm::VideoFrame and cdm::VideoFrame_2 common implementation.
  39. void SetFormat(cdm::VideoFormat format) final;
  40. cdm::VideoFormat Format() const final;
  41. void SetSize(cdm::Size size) final;
  42. cdm::Size Size() const final;
  43. void SetFrameBuffer(cdm::Buffer* frame_buffer) final;
  44. cdm::Buffer* FrameBuffer() final;
  45. void SetPlaneOffset(cdm::VideoPlane plane, uint32_t offset) final;
  46. uint32_t PlaneOffset(cdm::VideoPlane plane) final;
  47. void SetStride(cdm::VideoPlane plane, uint32_t stride) final;
  48. uint32_t Stride(cdm::VideoPlane plane) final;
  49. void SetTimestamp(int64_t timestamp) final;
  50. int64_t Timestamp() const final;
  51. // cdm::VideoFrame_2 specific implementation.
  52. void SetColorSpace(cdm::ColorSpace color_space) final;
  53. // Helper functions to get the ColorSpace.
  54. media::VideoColorSpace MediaColorSpace() const;
  55. // Create a media::VideoFrame based on the data contained in this object.
  56. // |natural_size| is the visible portion of the video frame, and is
  57. // provided separately as it comes from the configuration, not the CDM.
  58. // The returned object will own |frame_buffer_| and will be responsible for
  59. // calling Destroy() on it when the data is no longer needed.
  60. // Preconditions:
  61. // - |this| needs to be properly initialized.
  62. // Postconditions:
  63. // - |frame_buffer_| will be NULL (now owned by returned media::VideoFrame).
  64. virtual scoped_refptr<media::VideoFrame> TransformToVideoFrame(
  65. gfx::Size natural_size) = 0;
  66. protected:
  67. // The video buffer format.
  68. cdm::VideoFormat format_;
  69. cdm::ColorSpace color_space_;
  70. // Width and height of the video frame.
  71. cdm::Size size_;
  72. // The video frame buffer.
  73. raw_ptr<cdm::Buffer> frame_buffer_;
  74. // Array of data pointers to each plane in the video frame buffer.
  75. uint32_t plane_offsets_[cdm::kMaxPlanes];
  76. // Array of strides for each plane, typically greater or equal to the width
  77. // of the surface divided by the horizontal sampling period. Note that
  78. // strides can be negative.
  79. uint32_t strides_[cdm::kMaxPlanes];
  80. // Presentation timestamp in microseconds.
  81. int64_t timestamp_;
  82. };
  83. class AudioFramesImpl final : public cdm::AudioFrames {
  84. public:
  85. AudioFramesImpl();
  86. AudioFramesImpl(const AudioFramesImpl&) = delete;
  87. AudioFramesImpl& operator=(const AudioFramesImpl&) = delete;
  88. ~AudioFramesImpl() final;
  89. // cdm::AudioFrames implementation.
  90. void SetFrameBuffer(cdm::Buffer* buffer) final;
  91. cdm::Buffer* FrameBuffer() final;
  92. void SetFormat(cdm::AudioFormat format) final;
  93. cdm::AudioFormat Format() const final;
  94. cdm::Buffer* PassFrameBuffer();
  95. private:
  96. raw_ptr<cdm::Buffer> buffer_;
  97. cdm::AudioFormat format_;
  98. };
  99. } // namespace media
  100. #endif // MEDIA_CDM_CDM_HELPERS_H_