Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/FlacFrameParser.h
Line
Count
Source (jump to first uncovered line)
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 "mozilla/Result.h"
12
#include "nsAutoPtr.h"
13
#include "MediaDecoder.h" // For MetadataTags
14
#include "MediaInfo.h"
15
#include "MediaResource.h"
16
17
namespace mozilla
18
{
19
20
0
#define FLAC_MAX_CHANNELS           8
21
#define FLAC_MIN_BLOCKSIZE         16
22
0
#define FLAC_MAX_BLOCKSIZE      65535
23
0
#define FLAC_MIN_FRAME_SIZE        11
24
0
#define FLAC_MAX_FRAME_HEADER_SIZE 16
25
0
#define FLAC_MAX_FRAME_SIZE (FLAC_MAX_FRAME_HEADER_SIZE \
26
0
                             +FLAC_MAX_BLOCKSIZE*FLAC_MAX_CHANNELS*3)
27
28
class OpusParser;
29
30
// Decode a Flac Metadata block contained in either a ogg packet
31
// (https://xiph.org/flac/ogg_mapping.html) or in flac container
32
// (https://xiph.org/flac/format.html#frame_header)
33
34
class FlacFrameParser
35
{
36
public:
37
  FlacFrameParser();
38
  ~FlacFrameParser();
39
40
  Result<bool, nsresult> IsHeaderBlock(const uint8_t* aPacket, size_t aLength) const;
41
  // Return the length of the block header (METADATA_BLOCK_HEADER+
42
  // METADATA_BLOCK_DATA), aPacket must point to at least 4
43
  // bytes and to a valid block header start (as determined by IsHeaderBlock).
44
  uint32_t HeaderBlockLength(const uint8_t* aPacket) const;
45
  Result<Ok, nsresult> DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength);
46
0
  bool HasFullMetadata() const { return mFullMetadata; }
47
  // Return the duration in frames found in the block. -1 if error
48
  // such as invalid packet.
49
  int64_t BlockDuration(const uint8_t* aPacket, size_t aLength) const;
50
51
  // Return a hash table with tag metadata.
52
  MetadataTags* GetTags() const;
53
54
  AudioInfo mInfo;
55
56
private:
57
  bool ReconstructFlacGranulepos(void);
58
  Maybe<uint32_t> mNumHeaders;
59
  uint32_t mMinBlockSize;
60
  uint32_t mMaxBlockSize;
61
  uint32_t mMinFrameSize;
62
  uint32_t mMaxFrameSize;
63
  uint64_t mNumFrames;
64
  bool mFullMetadata;
65
  uint32_t mPacketCount;
66
67
  // Used to decode the vorbis comment metadata.
68
  nsAutoPtr<OpusParser> mParser;
69
};
70
71
}
72
73
#endif // FLAC_FRAME_PARSER_H_