tor-browser

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

DAV1DDecoder.h (2713B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 #if !defined(DAV1DDecoder_h_)
      7 #  define DAV1DDecoder_h_
      8 
      9 #  include "PerformanceRecorder.h"
     10 #  include "PlatformDecoderModule.h"
     11 #  include "dav1d/dav1d.h"
     12 #  include "mozilla/Result.h"
     13 #  include "nsRefPtrHashtable.h"
     14 
     15 namespace mozilla {
     16 namespace layers {
     17 class BufferRecycleBin;
     18 }
     19 
     20 DDLoggedTypeDeclNameAndBase(DAV1DDecoder, MediaDataDecoder);
     21 
     22 typedef nsRefPtrHashtable<nsPtrHashKey<const uint8_t>, MediaRawData>
     23    MediaRawDataHashtable;
     24 
     25 class DAV1DDecoder final : public MediaDataDecoder,
     26                           public DecoderDoctorLifeLogger<DAV1DDecoder> {
     27 public:
     28  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DAV1DDecoder, final);
     29 
     30  explicit DAV1DDecoder(const CreateDecoderParams& aParams);
     31 
     32  RefPtr<InitPromise> Init() override;
     33  RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
     34  RefPtr<DecodePromise> Drain() override;
     35  RefPtr<FlushPromise> Flush() override;
     36  RefPtr<ShutdownPromise> Shutdown() override;
     37  nsCString GetDescriptionName() const override {
     38    return "av1 libdav1d video decoder"_ns;
     39  }
     40  nsCString GetCodecName() const override { return "av1"_ns; }
     41 
     42  void ReleaseDataBuffer(const uint8_t* buf);
     43 
     44  static Maybe<gfx::YUVColorSpace> GetColorSpace(const Dav1dPicture& aPicture,
     45                                                 LazyLogModule& aLogger);
     46 
     47  static Maybe<gfx::ColorSpace2> GetColorPrimaries(const Dav1dPicture& aPicture,
     48                                                   LazyLogModule& aLogger);
     49 
     50 private:
     51  virtual ~DAV1DDecoder();
     52  RefPtr<DecodePromise> InvokeDecode(MediaRawData* aSample);
     53  Result<already_AddRefed<VideoData>, MediaResult> GetPicture();
     54  Result<already_AddRefed<VideoData>, MediaResult> ConstructImage(
     55      const Dav1dPicture& aPicture);
     56 
     57  Dav1dContext* mContext = nullptr;
     58 
     59  const VideoInfo mInfo;
     60  const RefPtr<TaskQueue> mTaskQueue;
     61  const RefPtr<layers::ImageContainer> mImageContainer;
     62  const RefPtr<layers::KnowsCompositor> mImageAllocator;
     63  const Maybe<TrackingId> mTrackingId;
     64  const bool mLowLatency;
     65  PerformanceRecorderMulti<DecodeStage> mPerformanceRecorder;
     66 
     67  // Keep the buffers alive until dav1d
     68  // does not need them any more.
     69  MediaRawDataHashtable mDecodingBuffers;
     70 
     71  // Convert to 8-bit when GPU doesn't support 10 or 12-bit image.
     72  const bool m8bpcOutput;
     73  RefPtr<layers::BufferRecycleBin> m8bpcRecycleBin;
     74 };
     75 
     76 }  // namespace mozilla
     77 
     78 #endif  // DAV1DDecoder_h_