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/. */
7 #ifndef FLAC_FRAME_PARSER_H_
8 #define FLAC_FRAME_PARSER_H_
10 #include "mozilla/Maybe.h"
11 #include "mozilla/Result.h"
12 #include "MediaDecoder.h" // For MetadataTags
13 #include "MediaInfo.h"
14 #include "MediaResource.h"
18 #define FLAC_MAX_CHANNELS 8
19 #define FLAC_MIN_BLOCKSIZE 16
20 #define FLAC_MAX_BLOCKSIZE 65535
21 #define FLAC_MIN_FRAME_SIZE 11
22 #define FLAC_MAX_FRAME_HEADER_SIZE 16
23 #define FLAC_MAX_FRAME_SIZE \
24 (FLAC_MAX_FRAME_HEADER_SIZE + FLAC_MAX_BLOCKSIZE * FLAC_MAX_CHANNELS * 3)
28 // Decode a Flac Metadata block contained in either a ogg packet
29 // (https://xiph.org/flac/ogg_mapping.html) or in flac container
30 // (https://xiph.org/flac/format.html#frame_header)
32 class FlacFrameParser
{
37 Result
<bool, nsresult
> IsHeaderBlock(const uint8_t* aPacket
,
38 size_t aLength
) const;
39 // Return the length of the block header (METADATA_BLOCK_HEADER+
40 // METADATA_BLOCK_DATA), aPacket must point to at least 4
41 // bytes and to a valid block header start (as determined by IsHeaderBlock).
42 uint32_t HeaderBlockLength(const uint8_t* aPacket
) const;
43 Result
<Ok
, nsresult
> DecodeHeaderBlock(const uint8_t* aPacket
,
45 bool HasFullMetadata() const { return mFullMetadata
; }
46 // Return the duration in frames found in the block. -1 if error
47 // such as invalid packet.
48 int64_t BlockDuration(const uint8_t* aPacket
, size_t aLength
) const;
50 // Return a hash table with tag metadata.
51 UniquePtr
<MetadataTags
> GetTags() const;
56 bool ReconstructFlacGranulepos(void);
57 Maybe
<uint32_t> mNumHeaders
;
58 uint32_t mMinBlockSize
;
59 uint32_t mMaxBlockSize
;
60 uint32_t mMinFrameSize
;
61 uint32_t mMaxFrameSize
;
64 uint32_t mPacketCount
;
66 // Used to decode the vorbis comment metadata.
67 UniquePtr
<OpusParser
> mParser
;
70 } // namespace mozilla
72 #endif // FLAC_FRAME_PARSER_H_