/usr/include/thunderbird/TrackEncoder.h is in thunderbird-dev 1:24.4.0+build1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | /* -*- 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 TrackEncoder_h_
#define TrackEncoder_h_
#include "mozilla/ReentrantMonitor.h"
#include "AudioSegment.h"
#include "StreamBuffer.h"
namespace mozilla {
class MediaStreamGraph;
/**
* Base class of AudioTrackEncoder and VideoTrackEncoder. Lifetimes managed by
* MediaEncoder. Most methods can only be called on the MediaEncoder's thread,
* but some subclass methods can be called on other threads when noted.
*
* NotifyQueuedTrackChanges is called on subclasses of this class from the
* MediaStreamGraph thread, and AppendAudioSegment/AppendVideoSegment is then
* called to store media data in the TrackEncoder. Later on, GetEncodedTrack is
* called on MediaEncoder's thread to encode and retrieve the encoded data.
*/
class TrackEncoder
{
public:
TrackEncoder() {}
virtual ~TrackEncoder() {}
/**
* Notified by the same callbcak of MediaEncoder when it has received a track
* change from MediaStreamGraph. Called on the MediaStreamGraph thread.
*/
virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
TrackRate aTrackRate,
TrackTicks aTrackOffset,
uint32_t aTrackEvents,
const MediaSegment& aQueuedMedia) = 0;
/**
* Notified by the same callback of MediaEncoder when it has been removed from
* MediaStreamGraph. Called on the MediaStreamGraph thread.
*/
virtual void NotifyRemoved(MediaStreamGraph* aGraph) = 0;
/**
* Creates and sets up header for a specific codec. Result data is returned
* in aOutput.
*/
virtual nsresult GetHeader(nsTArray<uint8_t>* aOutput) = 0;
/**
* Encodes raw segments. Result data is returned in aOutput. aOutputDuration
* is the playback duration of this packet in number of samples.
*/
virtual nsresult GetEncodedTrack(nsTArray<uint8_t>* aOutput,
int &aOutputDuration) = 0;
};
class AudioTrackEncoder : public TrackEncoder
{
public:
AudioTrackEncoder()
: TrackEncoder()
, mChannels(0)
, mSamplingRate(0)
, mInitialized(false)
, mDoneEncoding(false)
, mReentrantMonitor("media.AudioEncoder")
, mRawSegment(new AudioSegment())
, mEndOfStream(false)
, mCanceled(false)
{}
void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
TrackRate aTrackRate,
TrackTicks aTrackOffset,
uint32_t aTrackEvents,
const MediaSegment& aQueuedMedia) MOZ_OVERRIDE;
void NotifyRemoved(MediaStreamGraph* aGraph) MOZ_OVERRIDE;
bool IsEncodingComplete()
{
return mDoneEncoding;
}
/**
* Notifies from MediaEncoder to cancel the encoding, and wakes up
* mReentrantMonitor if encoder is waiting on it.
*/
void NotifyCancel()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mCanceled = true;
mReentrantMonitor.NotifyAll();
}
protected:
/**
* Number of samples per channel in a pcm buffer. This is also the value of
* frame size required by audio encoder, and mReentrantMonitor will be
* notified when at least this much data has been added to mRawSegment.
*/
virtual int GetPacketDuration() = 0;
/**
* Initializes the audio encoder. The call of this method is delayed until we
* have received the first valid track from MediaStreamGraph, and the
* mReentrantMonitor will be notified if other methods is waiting for encoder
* to be completely initialized. This method is called on the MediaStreamGraph
* thread.
*/
virtual nsresult Init(int aChannels, int aSamplingRate) = 0;
/**
* Appends and consumes track data from aSegment, this method is called on
* the MediaStreamGraph thread. mReentrantMonitor will be notified when at
* least GetPacketDuration() data has been added to mRawSegment, wake up other
* method which is waiting for more data from mRawSegment.
*/
nsresult AppendAudioSegment(MediaSegment* aSegment);
/**
* Notifies the audio encoder that we have reached the end of source stream,
* and wakes up mReentrantMonitor if encoder is waiting for more track data.
*/
void NotifyEndOfStream()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mEndOfStream = true;
mReentrantMonitor.NotifyAll();
}
/**
* Interleaves the track data and stores the result into aOutput. Might need
* to up-mix or down-mix the channel data if the channels number of this chunk
* is different from mChannels. The channel data from aChunk might be modified
* by up-mixing.
*/
void InterleaveTrackData(AudioChunk& aChunk, int32_t aDuration,
uint32_t aOutputChannels, AudioDataValue* aOutput);
/**
* The number of channels in the first valid audio chunk, and is being used
* to initialize the audio encoder.
*/
int mChannels;
int mSamplingRate;
bool mInitialized;
bool mDoneEncoding;
/**
* A ReentrantMonitor to protect the pushing and pulling of mRawSegment.
*/
ReentrantMonitor mReentrantMonitor;
/**
* A segment queue of audio track data, protected by mReentrantMonitor.
*/
nsAutoPtr<AudioSegment> mRawSegment;
/**
* True if we have received an event of TRACK_EVENT_ENDED from MediaStreamGraph,
* or the MediaEncoder is removed from its source stream, protected by
* mReentrantMonitor.
*/
bool mEndOfStream;
/**
* True if a cancellation of encoding is sent from MediaEncoder, protected by
* mReentrantMonitor.
*/
bool mCanceled;
};
class VideoTrackEncoder : public TrackEncoder
{
};
}
#endif
|