/src/mozilla-central/dom/media/platforms/agnostic/OpusDecoder.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(OpusDecoder_h_) |
7 | | #define OpusDecoder_h_ |
8 | | |
9 | | #include "PlatformDecoderModule.h" |
10 | | |
11 | | #include "mozilla/Maybe.h" |
12 | | #include "nsAutoPtr.h" |
13 | | #include "nsTArray.h" |
14 | | |
15 | | struct OpusMSDecoder; |
16 | | |
17 | | namespace mozilla { |
18 | | |
19 | | class OpusParser; |
20 | | |
21 | | DDLoggedTypeDeclNameAndBase(OpusDataDecoder, MediaDataDecoder); |
22 | | |
23 | | class OpusDataDecoder |
24 | | : public MediaDataDecoder |
25 | | , public DecoderDoctorLifeLogger<OpusDataDecoder> |
26 | | { |
27 | | public: |
28 | | explicit OpusDataDecoder(const CreateDecoderParams& aParams); |
29 | | ~OpusDataDecoder(); |
30 | | |
31 | | RefPtr<InitPromise> Init() override; |
32 | | RefPtr<DecodePromise> Decode(MediaRawData* aSample) override; |
33 | | RefPtr<DecodePromise> Drain() override; |
34 | | RefPtr<FlushPromise> Flush() override; |
35 | | RefPtr<ShutdownPromise> Shutdown() override; |
36 | | nsCString GetDescriptionName() const override |
37 | 0 | { |
38 | 0 | return NS_LITERAL_CSTRING("opus audio decoder"); |
39 | 0 | } |
40 | | |
41 | | // Return true if mimetype is Opus |
42 | | static bool IsOpus(const nsACString& aMimeType); |
43 | | |
44 | | // Pack pre-skip/CodecDelay, given in microseconds, into a |
45 | | // MediaByteBuffer. The decoder expects this value to come |
46 | | // from the container (if any) and to precede the OpusHead |
47 | | // block in the CodecSpecificConfig buffer to verify the |
48 | | // values match. |
49 | | static void AppendCodecDelay(MediaByteBuffer* config, uint64_t codecDelayUS); |
50 | | |
51 | | private: |
52 | | nsresult DecodeHeader(const unsigned char* aData, size_t aLength); |
53 | | |
54 | | RefPtr<DecodePromise> ProcessDecode(MediaRawData* aSample); |
55 | | |
56 | | const AudioInfo& mInfo; |
57 | | const RefPtr<TaskQueue> mTaskQueue; |
58 | | |
59 | | // Opus decoder state |
60 | | nsAutoPtr<OpusParser> mOpusParser; |
61 | | OpusMSDecoder* mOpusDecoder; |
62 | | |
63 | | uint16_t mSkip; // Samples left to trim before playback. |
64 | | bool mDecodedHeader; |
65 | | |
66 | | // Opus padding should only be discarded on the final packet. Once this |
67 | | // is set to true, if the reader attempts to decode any further packets it |
68 | | // will raise an error so we can indicate that the file is invalid. |
69 | | bool mPaddingDiscarded; |
70 | | int64_t mFrames; |
71 | | Maybe<int64_t> mLastFrameTime; |
72 | | AutoTArray<uint8_t, 8> mMappingTable; |
73 | | AudioConfig::ChannelLayout::ChannelMap mChannelMap; |
74 | | }; |
75 | | |
76 | | } // namespace mozilla |
77 | | #endif |