Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/EncodedFrameContainer.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef EncodedFrameContainer_H_
7
#define EncodedFrameContainer_H_
8
9
#include "nsTArray.h"
10
11
namespace mozilla {
12
13
class EncodedFrame;
14
15
/*
16
 * This container is used to carry video or audio encoded data from encoder to muxer.
17
 * The media data object is created by encoder and recycle by the destructor.
18
 * Only allow to store audio or video encoded data in EncodedData.
19
 */
20
class EncodedFrameContainer
21
{
22
public:
23
  // Append encoded frame data
24
  void AppendEncodedFrame(EncodedFrame* aEncodedFrame)
25
  {
26
    mEncodedFrames.AppendElement(aEncodedFrame);
27
  }
28
  // Retrieve all of the encoded frames
29
  const nsTArray<RefPtr<EncodedFrame> >& GetEncodedFrames() const
30
  {
31
    return mEncodedFrames;
32
  }
33
private:
34
  // This container is used to store the video or audio encoded packets.
35
  // Muxer should check mFrameType and get the encoded data type from mEncodedFrames.
36
  nsTArray<RefPtr<EncodedFrame> > mEncodedFrames;
37
};
38
39
// Represent one encoded frame
40
class EncodedFrame final
41
{
42
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodedFrame)
43
public:
44
  EncodedFrame() :
45
    mTimeStamp(0),
46
    mDuration(0),
47
    mFrameType(UNKNOWN)
48
  {}
49
  enum FrameType {
50
    VP8_I_FRAME,      // VP8 intraframe
51
    VP8_P_FRAME,      // VP8 predicted frame
52
    OPUS_AUDIO_FRAME, // Opus audio frame
53
    VORBIS_AUDIO_FRAME,
54
    AVC_I_FRAME,
55
    AVC_P_FRAME,
56
    AVC_B_FRAME,
57
    AVC_CSD,          // AVC codec specific data
58
    AAC_AUDIO_FRAME,
59
    AAC_CSD,          // AAC codec specific data
60
    AMR_AUDIO_CSD,
61
    AMR_AUDIO_FRAME,
62
    EVRC_AUDIO_CSD,
63
    EVRC_AUDIO_FRAME,
64
    UNKNOWN           // FrameType not set
65
  };
66
  void SwapInFrameData(nsTArray<uint8_t>& aData)
67
  {
68
    mFrameData.SwapElements(aData);
69
  }
70
  nsresult SwapOutFrameData(nsTArray<uint8_t>& aData)
71
0
  {
72
0
    if (mFrameType != UNKNOWN) {
73
0
      // Reset this frame type to UNKNOWN once the data is swapped out.
74
0
      mFrameData.SwapElements(aData);
75
0
      mFrameType = UNKNOWN;
76
0
      return NS_OK;
77
0
    }
78
0
    return NS_ERROR_FAILURE;
79
0
  }
80
  const nsTArray<uint8_t>& GetFrameData() const
81
0
  {
82
0
    return mFrameData;
83
0
  }
84
  uint64_t GetTimeStamp() const { return mTimeStamp; }
85
  void SetTimeStamp(uint64_t aTimeStamp) { mTimeStamp = aTimeStamp; }
86
87
  uint64_t GetDuration() const { return mDuration; }
88
  void SetDuration(uint64_t aDuration) { mDuration = aDuration; }
89
90
  FrameType GetFrameType() const { return mFrameType; }
91
  void SetFrameType(FrameType aFrameType) { mFrameType = aFrameType; }
92
private:
93
  // Private destructor, to discourage deletion outside of Release():
94
  ~EncodedFrame()
95
  {
96
  }
97
98
  // Encoded data
99
  nsTArray<uint8_t> mFrameData;
100
  uint64_t mTimeStamp;
101
  // The playback duration of this packet in number of samples
102
  uint64_t mDuration;
103
  // Represent what is in the FrameData
104
  FrameType mFrameType;
105
};
106
107
} // namespace mozilla
108
109
#endif