Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 :
7 : #ifndef FLAC_FRAME_PARSER_H_
8 : #define FLAC_FRAME_PARSER_H_
9 :
10 : #include "mozilla/Maybe.h"
11 : #include "nsAutoPtr.h"
12 : #include "MediaDecoder.h" // For MetadataTags
13 : #include "MediaInfo.h"
14 : #include "MediaResource.h"
15 :
16 : namespace mozilla
17 : {
18 :
19 : class OpusParser;
20 :
21 : // Decode a Flac Metadata block contained in either a ogg packet
22 : // (https://xiph.org/flac/ogg_mapping.html) or in flac container
23 : // (https://xiph.org/flac/format.html#frame_header)
24 :
25 : class FlacFrameParser
26 : {
27 : public:
28 : FlacFrameParser();
29 : ~FlacFrameParser();
30 :
31 : bool IsHeaderBlock(const uint8_t* aPacket, size_t aLength) const;
32 : // Return the length of the block header (METADATA_BLOCK_HEADER+
33 : // METADATA_BLOCK_DATA), aPacket must point to at least 4
34 : // bytes and to a valid block header start (as determined by IsHeaderBlock).
35 : uint32_t HeaderBlockLength(const uint8_t* aPacket) const;
36 : bool DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength);
37 0 : bool HasFullMetadata() const { return mFullMetadata; }
38 : // Return the duration in frames found in the block. -1 if error
39 : // such as invalid packet.
40 : int64_t BlockDuration(const uint8_t* aPacket, size_t aLength) const;
41 :
42 : // Return a hash table with tag metadata.
43 : MetadataTags* GetTags() const;
44 :
45 : AudioInfo mInfo;
46 :
47 : private:
48 : bool ReconstructFlacGranulepos(void);
49 : Maybe<uint32_t> mNumHeaders;
50 : uint32_t mMinBlockSize;
51 : uint32_t mMaxBlockSize;
52 : uint32_t mMinFrameSize;
53 : uint32_t mMaxFrameSize;
54 : uint64_t mNumFrames;
55 : bool mFullMetadata;
56 : uint32_t mPacketCount;
57 :
58 : // Used to decode the vorbis comment metadata.
59 : nsAutoPtr<OpusParser> mParser;
60 : };
61 :
62 : }
63 :
64 : #endif // FLAC_FRAME_PARSER_H_
|