content/media/AudioNodeExternalInputStream.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef MOZILLA_AUDIONODEEXTERNALINPUTSTREAM_H_
michael@0 7 #define MOZILLA_AUDIONODEEXTERNALINPUTSTREAM_H_
michael@0 8
michael@0 9 #include "MediaStreamGraph.h"
michael@0 10 #include "AudioNodeStream.h"
michael@0 11
michael@0 12 // Forward declaration for mResamplerMap
michael@0 13 typedef struct SpeexResamplerState_ SpeexResamplerState;
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16
michael@0 17 /**
michael@0 18 * This is a MediaStream implementation that acts for a Web Audio node but
michael@0 19 * unlike other AudioNodeStreams, supports any kind of MediaStream as an
michael@0 20 * input --- handling any number of audio tracks, resampling them from whatever
michael@0 21 * sample rate they're using, and handling blocking of the input MediaStream.
michael@0 22 */
michael@0 23 class AudioNodeExternalInputStream : public AudioNodeStream {
michael@0 24 public:
michael@0 25 AudioNodeExternalInputStream(AudioNodeEngine* aEngine, TrackRate aSampleRate);
michael@0 26 ~AudioNodeExternalInputStream();
michael@0 27
michael@0 28 virtual void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) MOZ_OVERRIDE;
michael@0 29
michael@0 30 private:
michael@0 31 // For storing pointers and data about input tracks, like the last TrackTick which
michael@0 32 // was read, and the associated speex resampler.
michael@0 33 struct TrackMapEntry {
michael@0 34 ~TrackMapEntry();
michael@0 35
michael@0 36 /**
michael@0 37 * Resamples data from all chunks in aIterator and following, using mResampler,
michael@0 38 * adding the results to mResampledData.
michael@0 39 */
michael@0 40 void ResampleInputData(AudioSegment* aSegment);
michael@0 41 /**
michael@0 42 * Resamples a set of channel buffers using mResampler, adding the results
michael@0 43 * to mResampledData.
michael@0 44 */
michael@0 45 void ResampleChannels(const nsTArray<const void*>& aBuffers,
michael@0 46 uint32_t aInputDuration,
michael@0 47 AudioSampleFormat aFormat,
michael@0 48 float aVolume);
michael@0 49
michael@0 50 // mEndOfConsumedInputTicks is the end of the input ticks that we've consumed.
michael@0 51 // 0 if we haven't consumed any yet.
michael@0 52 TrackTicks mEndOfConsumedInputTicks;
michael@0 53 // mEndOfLastInputIntervalInInputStream is the timestamp for the end of the
michael@0 54 // previous interval which was unblocked for both the input and output
michael@0 55 // stream, in the input stream's timeline, or -1 if there wasn't one.
michael@0 56 StreamTime mEndOfLastInputIntervalInInputStream;
michael@0 57 // mEndOfLastInputIntervalInOutputStream is the timestamp for the end of the
michael@0 58 // previous interval which was unblocked for both the input and output
michael@0 59 // stream, in the output stream's timeline, or -1 if there wasn't one.
michael@0 60 StreamTime mEndOfLastInputIntervalInOutputStream;
michael@0 61 /**
michael@0 62 * Number of samples passed to the resampler so far.
michael@0 63 */
michael@0 64 TrackTicks mSamplesPassedToResampler;
michael@0 65 /**
michael@0 66 * Resampler being applied to this track.
michael@0 67 */
michael@0 68 SpeexResamplerState* mResampler;
michael@0 69 /**
michael@0 70 * The track data that has been resampled to the rate of the
michael@0 71 * AudioNodeExternalInputStream. All data in these chunks is in floats (or null),
michael@0 72 * and has the number of channels given in mResamplerChannelCount.
michael@0 73 * mResampledData starts at zero in the stream's output track (so generally
michael@0 74 * it will consist of null data followed by actual data).
michael@0 75 */
michael@0 76 AudioSegment mResampledData;
michael@0 77 /**
michael@0 78 * Number of channels used to create mResampler.
michael@0 79 */
michael@0 80 uint32_t mResamplerChannelCount;
michael@0 81 /**
michael@0 82 * The ID for the track of the input stream this entry is for.
michael@0 83 */
michael@0 84 TrackID mTrackID;
michael@0 85 };
michael@0 86
michael@0 87 nsTArray<TrackMapEntry> mTrackMap;
michael@0 88 // Amount of track data produced so far. A multiple of WEBAUDIO_BLOCK_SIZE.
michael@0 89 TrackTicks mCurrentOutputPosition;
michael@0 90
michael@0 91 /**
michael@0 92 * Creates a TrackMapEntry for the track, if needed. Returns the index
michael@0 93 * of the TrackMapEntry or NoIndex if no entry is needed yet.
michael@0 94 */
michael@0 95 uint32_t GetTrackMapEntry(const StreamBuffer::Track& aTrack,
michael@0 96 GraphTime aFrom);
michael@0 97 };
michael@0 98
michael@0 99 }
michael@0 100
michael@0 101 #endif /* MOZILLA_AUDIONODESTREAM_H_ */

mercurial