/src/mozilla-central/dom/media/platforms/agnostic/VPXDecoder.h
Line | Count | Source (jump to first uncovered line) |
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(VPXDecoder_h_) |
7 | | #define VPXDecoder_h_ |
8 | | |
9 | | #include "PlatformDecoderModule.h" |
10 | | #include "mozilla/Span.h" |
11 | | |
12 | | #include <stdint.h> |
13 | | #define VPX_DONT_DEFINE_STDINT_TYPES |
14 | | #include "vpx/vp8dx.h" |
15 | | #include "vpx/vpx_codec.h" |
16 | | #include "vpx/vpx_decoder.h" |
17 | | |
18 | | namespace mozilla { |
19 | | |
20 | | DDLoggedTypeDeclNameAndBase(VPXDecoder, MediaDataDecoder); |
21 | | |
22 | | class VPXDecoder |
23 | | : public MediaDataDecoder |
24 | | , public DecoderDoctorLifeLogger<VPXDecoder> |
25 | | { |
26 | | public: |
27 | | explicit VPXDecoder(const CreateDecoderParams& aParams); |
28 | | |
29 | | RefPtr<InitPromise> Init() override; |
30 | | RefPtr<DecodePromise> Decode(MediaRawData* aSample) override; |
31 | | RefPtr<DecodePromise> Drain() override; |
32 | | RefPtr<FlushPromise> Flush() override; |
33 | | RefPtr<ShutdownPromise> Shutdown() override; |
34 | | nsCString GetDescriptionName() const override |
35 | 0 | { |
36 | 0 | return NS_LITERAL_CSTRING("libvpx video decoder"); |
37 | 0 | } |
38 | | |
39 | | enum Codec: uint8_t |
40 | | { |
41 | | VP8 = 1 << 0, |
42 | | VP9 = 1 << 1, |
43 | | Unknown = 1 << 7, |
44 | | }; |
45 | | |
46 | | // Return true if aMimeType is a one of the strings used by our demuxers to |
47 | | // identify VPX of the specified type. Does not parse general content type |
48 | | // strings, i.e. white space matters. |
49 | | static bool IsVPX(const nsACString& aMimeType, uint8_t aCodecMask=VP8|VP9); |
50 | | static bool IsVP8(const nsACString& aMimeType); |
51 | | static bool IsVP9(const nsACString& aMimeType); |
52 | | |
53 | | // Return true if a sample is a keyframe for the specified codec. |
54 | | static bool IsKeyframe(Span<const uint8_t> aBuffer, Codec aCodec); |
55 | | |
56 | | // Return the frame dimensions for a sample for the specified codec. |
57 | | static gfx::IntSize GetFrameSize(Span<const uint8_t> aBuffer, Codec aCodec); |
58 | | |
59 | | private: |
60 | | ~VPXDecoder(); |
61 | | RefPtr<DecodePromise> ProcessDecode(MediaRawData* aSample); |
62 | | MediaResult DecodeAlpha(vpx_image_t** aImgAlpha, const MediaRawData* aSample); |
63 | | |
64 | | const RefPtr<layers::ImageContainer> mImageContainer; |
65 | | RefPtr<layers::KnowsCompositor> mImageAllocator; |
66 | | const RefPtr<TaskQueue> mTaskQueue; |
67 | | |
68 | | // VPx decoder state |
69 | | vpx_codec_ctx_t mVPX; |
70 | | |
71 | | // VPx alpha decoder state |
72 | | vpx_codec_ctx_t mVPXAlpha; |
73 | | |
74 | | const VideoInfo& mInfo; |
75 | | |
76 | | const Codec mCodec; |
77 | | }; |
78 | | |
79 | | } // namespace mozilla |
80 | | |
81 | | #endif |