summaryrefslogtreecommitdiff
path: root/dom/media/gmp/GMPAudioHost.cpp
blob: 4e14fed0b90a8243da7cd8a208829594f3bf3edd (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* -*- 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/. */

#include "GMPAudioHost.h"
#include "gmp-audio-samples.h"
#include "gmp-errors.h"
#include "GMPEncryptedBufferDataImpl.h"
#include "MediaData.h"

namespace mozilla {
namespace gmp {

GMPAudioSamplesImpl::GMPAudioSamplesImpl(GMPAudioFormat aFormat)
  : mFormat(aFormat)
  , mTimeStamp(0)
  , mChannels(0)
  , mRate(0)
{
}

GMPAudioSamplesImpl::GMPAudioSamplesImpl(const GMPAudioEncodedSampleData& aData)
  : mFormat(kGMPAudioEncodedSamples)
  , mBuffer(aData.mData())
  , mTimeStamp(aData.mTimeStamp())
  , mChannels(aData.mChannelCount())
  , mRate(aData.mSamplesPerSecond())
{
  if (aData.mDecryptionData().mKeyId().Length() > 0) {
    mCrypto = new GMPEncryptedBufferDataImpl(aData.mDecryptionData());
  }
}

GMPAudioSamplesImpl::GMPAudioSamplesImpl(MediaRawData* aSample,
                                         uint32_t aChannels,
                                         uint32_t aRate)
 : mFormat(kGMPAudioEncodedSamples)
 , mTimeStamp(aSample->mTime)
 , mChannels(aChannels)
 , mRate(aRate)
{
  mBuffer.AppendElements(aSample->Data(), aSample->Size());
  if (aSample->mCrypto.mValid) {
    mCrypto = new GMPEncryptedBufferDataImpl(aSample->mCrypto);
  }
}

GMPAudioSamplesImpl::~GMPAudioSamplesImpl()
{
}

GMPAudioFormat
GMPAudioSamplesImpl::GetFormat()
{
  return mFormat;
}

void
GMPAudioSamplesImpl::Destroy()
{
  delete this;
}

GMPErr
GMPAudioSamplesImpl::SetBufferSize(uint32_t aSize)
{
  mBuffer.SetLength(aSize);
  return GMPNoErr;
}

uint32_t
GMPAudioSamplesImpl::Size()
{
  return mBuffer.Length();
}

void
GMPAudioSamplesImpl::SetTimeStamp(uint64_t aTimeStamp)
{
  mTimeStamp = aTimeStamp;
}

uint64_t
GMPAudioSamplesImpl::TimeStamp()
{
  return mTimeStamp;
}

const uint8_t*
GMPAudioSamplesImpl::Buffer() const
{
  return mBuffer.Elements();
}

uint8_t*
GMPAudioSamplesImpl::Buffer()
{
  return mBuffer.Elements();
}

const GMPEncryptedBufferMetadata*
GMPAudioSamplesImpl::GetDecryptionData() const
{
  return mCrypto;
}

void
GMPAudioSamplesImpl::InitCrypto(const CryptoSample& aCrypto)
{
  if (!aCrypto.mValid) {
    return;
  }
  mCrypto = new GMPEncryptedBufferDataImpl(aCrypto);
}

void
GMPAudioSamplesImpl::RelinquishData(GMPAudioEncodedSampleData& aData)
{
  aData.mData() = Move(mBuffer);
  aData.mTimeStamp() = TimeStamp();
  if (mCrypto) {
    mCrypto->RelinquishData(aData.mDecryptionData());
  }
}

uint32_t
GMPAudioSamplesImpl::Channels() const
{
  return mChannels;
}

void
GMPAudioSamplesImpl::SetChannels(uint32_t aChannels)
{
  mChannels = aChannels;
}

uint32_t
GMPAudioSamplesImpl::Rate() const
{
  return mRate;
}

void
GMPAudioSamplesImpl::SetRate(uint32_t aRate)
{
  mRate = aRate;
}


GMPErr
GMPAudioHostImpl::CreateSamples(GMPAudioFormat aFormat,
                                GMPAudioSamples** aSamples)
{

  *aSamples = new GMPAudioSamplesImpl(aFormat);
  return GMPNoErr;
}

} // namespace gmp
} // namespace mozilla