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(AOMDecoder_h_)
7 #  define AOMDecoder_h_
8 
9 #  include "PlatformDecoderModule.h"
10 #  include "mozilla/Span.h"
11 
12 #  include <stdint.h>
13 #  include "aom/aom_decoder.h"
14 
15 namespace mozilla {
16 
17 DDLoggedTypeDeclNameAndBase(AOMDecoder, MediaDataDecoder);
18 
19 class AOMDecoder : public MediaDataDecoder,
20                    public DecoderDoctorLifeLogger<AOMDecoder> {
21  public:
22   explicit AOMDecoder(const CreateDecoderParams& aParams);
23 
24   RefPtr<InitPromise> Init() override;
25   RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
26   RefPtr<DecodePromise> Drain() override;
27   RefPtr<FlushPromise> Flush() override;
28   RefPtr<ShutdownPromise> Shutdown() override;
GetDescriptionName()29   nsCString GetDescriptionName() const override {
30     return NS_LITERAL_CSTRING("av1 libaom video decoder");
31   }
32 
33   // Return true if aMimeType is a one of the strings used
34   // by our demuxers to identify AV1 streams.
35   static bool IsAV1(const nsACString& aMimeType);
36 
37   // Return true if a sample is a keyframe.
38   static bool IsKeyframe(Span<const uint8_t> aBuffer);
39 
40   // Return the frame dimensions for a sample.
41   static gfx::IntSize GetFrameSize(Span<const uint8_t> aBuffer);
42 
43  private:
44   ~AOMDecoder();
45   RefPtr<DecodePromise> ProcessDecode(MediaRawData* aSample);
46 
47   const RefPtr<layers::ImageContainer> mImageContainer;
48   const RefPtr<TaskQueue> mTaskQueue;
49 
50   // AOM decoder state
51   aom_codec_ctx_t mCodec;
52 
53   const VideoInfo& mInfo;
54 };
55 
56 }  // namespace mozilla
57 
58 #endif  // AOMDecoder_h_
59