summaryrefslogtreecommitdiffstats
path: root/dom/media/gmp/gmp-api/gmp-audio-samples.h
blob: a47fc74b9918c7d5f9b4852111117036873c563e (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
/*
* Copyright 2013, Mozilla Foundation and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef GMP_AUDIO_FRAME_h_
#define GMP_AUDIO_FRAME_h_

#include <stdint.h>
#include "gmp-errors.h"
#include "gmp-decryption.h"

enum GMPAudioFormat
{
  kGMPAudioEncodedSamples, // Raw compressed data, i.e. an AAC/Vorbis packet.
  kGMPAudioIS16Samples, // Interleaved int16_t PCM samples.
  kGMPAudioSamplesFormatInvalid // Should always be last.
};

class GMPAudioSamples {
public:
  // The format of the buffer.
  virtual GMPAudioFormat GetFormat() = 0;
  virtual void Destroy() = 0;

  // MAIN THREAD ONLY
  // Buffer size must be exactly what's required to contain all samples in
  // the buffer; every byte is assumed to be part of a sample.
  virtual GMPErr SetBufferSize(uint32_t aSize) = 0;

  // Size of the buffer in bytes.
  virtual uint32_t Size() = 0;

  // Timestamps are in microseconds, and are the playback start time of the
  // first sample in the buffer.
  virtual void SetTimeStamp(uint64_t aTimeStamp) = 0;
  virtual uint64_t TimeStamp() = 0;
  virtual const uint8_t* Buffer() const = 0;
  virtual uint8_t*       Buffer() = 0;

  // Get metadata describing how this frame is encrypted, or nullptr if the
  // buffer is not encrypted.
  virtual const GMPEncryptedBufferMetadata* GetDecryptionData() const = 0;

  virtual uint32_t Channels() const = 0;
  virtual void SetChannels(uint32_t aChannels) = 0;

  // Rate; the number of frames per second, where a "frame" is one sample for
  // each channel.
  //
  // For IS16 samples, the number of samples should be:
  //   Size() / (Channels() * sizeof(int16_t)).
  //
  // Note: Channels() and Rate() may not be constant across a decoding
  // session. For example the rate for decoded samples may be different
  // than the rate advertised by the MP4 container for encoded samples
  // for HE-AAC streams with SBR/PS, and an EME-GMP may need to downsample
  // to satisfy DRM requirements.
  virtual uint32_t Rate() const = 0;
  virtual void SetRate(uint32_t aRate) = 0;
};

#endif // GMP_AUDIO_FRAME_h_