summaryrefslogtreecommitdiffstats
path: root/dom/media/encoder/fmp4_muxer/ISOTrackMetadata.h
blob: 3613e1e9eb094fc9371b0451b199983e72439364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ISOTrackMetadata_h_
#define ISOTrackMetadata_h_

#include "TrackMetadataBase.h"

namespace mozilla {

class AACTrackMetadata : public AudioTrackMetadata {
public:
  // AudioTrackMetadata members
  uint32_t GetAudioFrameDuration() override { return mFrameDuration; }
  uint32_t GetAudioFrameSize() override { return mFrameSize; }
  uint32_t GetAudioSampleRate() override { return mSampleRate; }
  uint32_t GetAudioChannels() override { return mChannels; }

  // TrackMetadataBase member
  MetadataKind GetKind() const override { return METADATA_AAC; }

  // AACTrackMetadata members
  AACTrackMetadata()
    : mSampleRate(0)
    , mFrameDuration(0)
    , mFrameSize(0)
    , mChannels(0) {
    MOZ_COUNT_CTOR(AACTrackMetadata);
  }
  ~AACTrackMetadata() { MOZ_COUNT_DTOR(AACTrackMetadata); }

  uint32_t mSampleRate;     // From 14496-3 table 1.16, it could be 7350 ~ 96000.
  uint32_t mFrameDuration;  // Audio frame duration based on SampleRate.
  uint32_t mFrameSize;      // Audio frame size, 0 is variant size.
  uint32_t mChannels;       // Channel number, it should be 1 or 2.
};

// AVC clock rate is 90k Hz.
#define AVC_CLOCK_RATE 90000

class AVCTrackMetadata : public VideoTrackMetadata {
public:
  // VideoTrackMetadata members
  uint32_t GetVideoHeight() override { return mHeight; }
  uint32_t GetVideoWidth() override {return mWidth; }
  uint32_t GetVideoDisplayHeight() override { return mDisplayHeight; }
  uint32_t GetVideoDisplayWidth() override { return mDisplayWidth;  }
  uint32_t GetVideoClockRate() override { return AVC_CLOCK_RATE; }
  uint32_t GetVideoFrameRate() override { return mFrameRate; }

  // TrackMetadataBase member
  MetadataKind GetKind() const override { return METADATA_AVC; }

  // AVCTrackMetadata
  AVCTrackMetadata()
    : mHeight(0)
    , mWidth(0)
    , mDisplayHeight(0)
    , mDisplayWidth(0)
    , mFrameRate(0) {
    MOZ_COUNT_CTOR(AVCTrackMetadata);
  }
  ~AVCTrackMetadata() { MOZ_COUNT_DTOR(AVCTrackMetadata); }

  uint32_t mHeight;
  uint32_t mWidth;
  uint32_t mDisplayHeight;
  uint32_t mDisplayWidth;
  uint32_t mFrameRate;       // frames per second
};


// AMR sample rate is 8000 samples/s.
#define AMR_SAMPLE_RATE 8000

// Channel number is always 1.
#define AMR_CHANNELS    1

// AMR speech codec, 3GPP TS 26.071. Encoder and continer support AMR-NB only
// currently.
class AMRTrackMetadata : public AudioTrackMetadata {
public:
  // AudioTrackMetadata members
  //
  // The number of sample sets generates by encoder is variant. So the
  // frame duration and frame size are both 0.
  uint32_t GetAudioFrameDuration() override { return 0; }
  uint32_t GetAudioFrameSize() override { return 0; }
  uint32_t GetAudioSampleRate() override { return AMR_SAMPLE_RATE; }
  uint32_t GetAudioChannels() override { return AMR_CHANNELS; }

  // TrackMetadataBase member
  MetadataKind GetKind() const override { return METADATA_AMR; }

  // AMRTrackMetadata members
  AMRTrackMetadata() { MOZ_COUNT_CTOR(AMRTrackMetadata); }
  ~AMRTrackMetadata() { MOZ_COUNT_DTOR(AMRTrackMetadata); }
};

// EVRC sample rate is 8000 samples/s.
#define EVRC_SAMPLE_RATE 8000

class EVRCTrackMetadata : public AudioTrackMetadata {
public:
  // AudioTrackMetadata members
  //
  // The number of sample sets generates by encoder is variant. So the
  // frame duration and frame size are both 0.
  uint32_t GetAudioFrameDuration() override { return 0; }
  uint32_t GetAudioFrameSize() override { return 0; }
  uint32_t GetAudioSampleRate() override { return EVRC_SAMPLE_RATE; }
  uint32_t GetAudioChannels() override { return mChannels; }

  // TrackMetadataBase member
  MetadataKind GetKind() const override { return METADATA_EVRC; }

  // EVRCTrackMetadata members
  EVRCTrackMetadata()
    : mChannels(0) {
    MOZ_COUNT_CTOR(EVRCTrackMetadata);
  }
  ~EVRCTrackMetadata() { MOZ_COUNT_DTOR(EVRCTrackMetadata); }

  uint32_t mChannels;       // Channel number, it should be 1 or 2.
};

}

#endif // ISOTrackMetadata_h_