INET Framework for OMNeT++/OMNEST
inet::VoIPStreamReceiver::Connection Class Reference

#include <VoIPStreamReceiver.h>

Public Member Functions

 Connection ()
 
void addAudioStream (enum AVCodecID codec_id)
 
void openAudio (const char *fileName)
 
void writeAudioFrame (uint8_t *buf, int len)
 
void writeLostSamples (int sampleCount)
 
void closeAudio ()
 

Public Attributes

bool offline = true
 
uint16_t seqNo = 0
 
uint32_t timeStamp = 0
 
uint32_t ssrc = 0
 
enum AVCodecID codec = AV_CODEC_ID_NONE
 
short sampleBits = 0
 
int sampleRate = 0
 
int samplesPerPacket = 0
 
int transmitBitrate = 0
 
simtime_t lastPacketFinish
 
AVFormatContext * oc = nullptr
 
AVOutputFormat * fmt = nullptr
 
AVStream * audio_st = nullptr
 
AVCodecContext * decCtx = nullptr
 
AVCodec * pCodecDec = nullptr
 
AudioOutFile outFile
 
L3Address srcAddr
 
int srcPort = -1
 
L3Address destAddr
 
int destPort = -1
 

Constructor & Destructor Documentation

inet::VoIPStreamReceiver::Connection::Connection ( )
inline
70 {}

Member Function Documentation

void inet::VoIPStreamReceiver::Connection::addAudioStream ( enum AVCodecID  codec_id)
void inet::VoIPStreamReceiver::Connection::closeAudio ( )
137 {
138  outFile.close();
139 }
bool close()
Definition: AudioOutFile.cc:149
AudioOutFile outFile
Definition: VoIPStreamReceiver.h:93
void inet::VoIPStreamReceiver::Connection::openAudio ( const char *  fileName)

Referenced by inet::VoIPStreamReceiver::createConnection().

100 {
101  outFile.open(fileName, sampleRate, 8 * av_get_bytes_per_sample(decCtx->sample_fmt));
102 }
int sampleRate
Definition: VoIPStreamReceiver.h:84
AVCodecContext * decCtx
Definition: VoIPStreamReceiver.h:91
AudioOutFile outFile
Definition: VoIPStreamReceiver.h:93
void open(const char *resultFile, int sampleRate, short int sampleBits)
Definition: AudioOutFile.cc:52
void inet::VoIPStreamReceiver::Connection::writeAudioFrame ( uint8_t *  buf,
int  len 
)

Referenced by inet::VoIPStreamReceiver::decodePacket().

115 {
116  AVPacket avpkt;
117  av_init_packet(&avpkt);
118  avpkt.data = inbuf;
119  avpkt.size = inbytes;
120 
121  int gotFrame;
122  AVFrame decodedFrame = {
123  { nullptr }
124  };
125  int consumedBytes = avcodec_decode_audio4(decCtx, &decodedFrame, &gotFrame, &avpkt);
126  if (consumedBytes < 0 || !gotFrame)
127  throw cRuntimeError("Error in avcodec_decode_audio4(): returns: %d, gotFrame: %d", consumedBytes, gotFrame);
128  if (consumedBytes != inbytes)
129  throw cRuntimeError("Model error: remained bytes after avcodec_decode_audio4(): %d = ( %d - %d )", inbytes - consumedBytes, inbytes, consumedBytes);
130  simtime_t decodedTime(1.0 * decodedFrame.nb_samples / sampleRate);
131  lastPacketFinish += decodedTime;
132  if (outFile.isOpen())
133  outFile.write(decodedFrame.data[0], decodedFrame.linesize[0]);
134 }
int sampleRate
Definition: VoIPStreamReceiver.h:84
simtime_t lastPacketFinish
Definition: VoIPStreamReceiver.h:87
AVCodecContext * decCtx
Definition: VoIPStreamReceiver.h:91
bool isOpen() const
Definition: AudioOutFile.h:46
void write(void *inbuf, int inbytes)
Definition: AudioOutFile.cc:108
AudioOutFile outFile
Definition: VoIPStreamReceiver.h:93
void inet::VoIPStreamReceiver::Connection::writeLostSamples ( int  sampleCount)

Referenced by inet::VoIPStreamReceiver::decodePacket().

105 {
106  int pktBytes = sampleCount * av_get_bytes_per_sample(decCtx->sample_fmt);
107  if (outFile.isOpen()) {
108  uint8_t decBuf[pktBytes];
109  memset(decBuf, 0, pktBytes);
110  outFile.write(decBuf, pktBytes);
111  }
112 }
AVCodecContext * decCtx
Definition: VoIPStreamReceiver.h:91
bool isOpen() const
Definition: AudioOutFile.h:46
void write(void *inbuf, int inbytes)
Definition: AudioOutFile.cc:108
AudioOutFile outFile
Definition: VoIPStreamReceiver.h:93

Member Data Documentation

AVStream* inet::VoIPStreamReceiver::Connection::audio_st = nullptr
enum AVCodecID inet::VoIPStreamReceiver::Connection::codec = AV_CODEC_ID_NONE
AVCodecContext* inet::VoIPStreamReceiver::Connection::decCtx = nullptr
L3Address inet::VoIPStreamReceiver::Connection::destAddr
int inet::VoIPStreamReceiver::Connection::destPort = -1
AVOutputFormat* inet::VoIPStreamReceiver::Connection::fmt = nullptr
simtime_t inet::VoIPStreamReceiver::Connection::lastPacketFinish
AVFormatContext* inet::VoIPStreamReceiver::Connection::oc = nullptr
AudioOutFile inet::VoIPStreamReceiver::Connection::outFile
AVCodec* inet::VoIPStreamReceiver::Connection::pCodecDec = nullptr
short inet::VoIPStreamReceiver::Connection::sampleBits = 0
int inet::VoIPStreamReceiver::Connection::samplesPerPacket = 0
L3Address inet::VoIPStreamReceiver::Connection::srcAddr
int inet::VoIPStreamReceiver::Connection::srcPort = -1
uint32_t inet::VoIPStreamReceiver::Connection::ssrc = 0
uint32_t inet::VoIPStreamReceiver::Connection::timeStamp = 0
int inet::VoIPStreamReceiver::Connection::transmitBitrate = 0

The documentation for this class was generated from the following files: