本文整理汇总了C++中FileSink类的典型用法代码示例。如果您正苦于以下问题:C++ FileSink类的具体用法?C++ FileSink怎么用?C++ FileSink使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSink类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
void FileSource::visit(FileSink& v)
{
#if 0
// only works if target is a pipe.
loff_t offset = offset_;
result_ = ::splice(handle(), &offset, v.handle(), NULL, count_,
SPLICE_F_MOVE | SPLICE_F_NONBLOCK | SPLICE_F_MORE);
if (result_ > 0) {
offset_ = offset;
count_ -= result_;
}
#endif
char buf[8 * 1024];
result_ = pread(handle(), buf, sizeof(buf), offset_);
if (result_ <= 0)
return;
result_ = v.write(buf, result_);
if (result_ <= 0)
return;
offset_ += result_;
count_ -= result_;
}
示例2: afterGettingFrame
void FileSink::afterGettingFrame(void* clientData, unsigned frameSize,
unsigned numTruncatedBytes,
struct timeval presentationTime,
unsigned /*durationInMicroseconds*/) {
FileSink* sink = (FileSink*)clientData;
sink->afterGettingFrame(frameSize, numTruncatedBytes, presentationTime);
}
示例3: setupStreams
void setupStreams() {
static MediaSubsessionIterator* setupIter = NULL;
if (setupIter == NULL) setupIter = new MediaSubsessionIterator(*session);
while ((subsession = setupIter->next()) != NULL) {
// We have another subsession left to set up:
if (subsession->clientPortNum() == 0) continue; // port # was not set
setupSubsession(subsession, streamUsingTCP, continueAfterSETUP);
return;
}
// We're done setting up subsessions.
delete setupIter;
if (!madeProgress) shutdown();
// Create output files:
if (createReceivers) {
#if 0 /*wayde*/
if (outputQuickTimeFile) {
// Create a "QuickTimeFileSink", to write to 'stdout':
qtOut = QuickTimeFileSink::createNew(*env, *session, "stdout",
fileSinkBufferSize,
movieWidth, movieHeight,
movieFPS,
packetLossCompensate,
syncStreams,
generateHintTracks,
generateMP4Format);
if (qtOut == NULL) {
*env << "Failed to create QuickTime file sink for stdout: " << env->getResultMsg();
shutdown();
}
qtOut->startPlaying(sessionAfterPlaying, NULL);
} else if (outputAVIFile) {
// Create an "AVIFileSink", to write to 'stdout':
aviOut = AVIFileSink::createNew(*env, *session, "stdout",
fileSinkBufferSize,
movieWidth, movieHeight,
movieFPS,
packetLossCompensate);
if (aviOut == NULL) {
*env << "Failed to create AVI file sink for stdout: " << env->getResultMsg();
shutdown();
}
aviOut->startPlaying(sessionAfterPlaying, NULL);
#endif /*wayde*/
} else {
// Create and start "FileSink"s for each subsession:
madeProgress = False;
MediaSubsessionIterator iter(*session);
while ((subsession = iter.next()) != NULL) {
if (subsession->readSource() == NULL) continue; // was not initiated
// Create an output file for each desired stream:
char outFileName[1000];
if (singleMedium == NULL) {
// Output file name is
// "<filename-prefix><medium_name>-<codec_name>-<counter>"
static unsigned streamCounter = 0;
snprintf(outFileName, sizeof outFileName, "%s%s-%s-%d",
fileNamePrefix, subsession->mediumName(),
subsession->codecName(), ++streamCounter);
} else {
sprintf(outFileName, "stdout");
}
FileSink* fileSink;
if (strcmp(subsession->mediumName(), "audio") == 0 &&
(strcmp(subsession->codecName(), "AMR") == 0 ||
strcmp(subsession->codecName(), "AMR-WB") == 0)) {
// For AMR audio streams, we use a special sink that inserts AMR frame hdrs:
fileSink = AMRAudioFileSink::createNew(*env, outFileName,
fileSinkBufferSize, oneFilePerFrame);
} else if (strcmp(subsession->mediumName(), "video") == 0 &&
(strcmp(subsession->codecName(), "H264") == 0)) {
// For H.264 video stream, we use a special sink that insert start_codes:
fileSink = H264VideoFileSink::createNew(*env, outFileName,
fileSinkBufferSize, oneFilePerFrame);
} else {
// Normal case:
fileSink = FileSink::createNew(*env, outFileName,
fileSinkBufferSize, oneFilePerFrame);
}
subsession->sink = fileSink;
if (subsession->sink == NULL) {
*env << "Failed to create FileSink for \"" << outFileName
<< "\": " << env->getResultMsg() << "\n";
} else {
if (singleMedium == NULL) {
*env << "Created output file: \"" << outFileName << "\"\n";
} else {
*env << "Outputting data from the \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession to 'stdout'\n";
}
if (strcmp(subsession->mediumName(), "video") == 0 &&
strcmp(subsession->codecName(), "MP4V-ES") == 0 &&
subsession->fmtp_config() != NULL) {
//.........这里部分代码省略.........
示例4: configFileCast
//.........这里部分代码省略.........
"invalid bitrate mode: ", str);
}
if (Util::strEq(format, "aac") && bitrateMode != AudioEncoder::abr) {
throw Exception(__FILE__, __LINE__,
"currently the AAC format only supports "
"average bitrate mode");
}
if (Util::strEq(format, "aacp") && bitrateMode != AudioEncoder::cbr) {
throw Exception(__FILE__, __LINE__,
"currently the AAC+ format only supports "
"constant bitrate mode");
}
str = cs->get( "lowpass");
lowpass = str ? Util::strToL( str) : 0;
str = cs->get( "highpass");
highpass = str ? Util::strToL( str) : 0;
// go on and create the things
// the underlying file
if ( fileAddDate ) {
if (fileDateFormat == 0) {
targetFileName = Util::fileAddDate( targetFileName);
}
else {
targetFileName = Util::fileAddDate( targetFileName,
fileDateFormat );
}
}
FileSink * targetFile = new FileSink( stream, targetFileName);
if ( !targetFile->exists() ) {
if ( !targetFile->create() ) {
throw Exception( __FILE__, __LINE__,
"can't create output file", targetFileName);
}
}
// streaming related stuff
audioOuts[u].socket = 0;
audioOuts[u].server = new FileCast( targetFile );
if ( Util::strEq( format, "mp3") ) {
#ifndef HAVE_LAME_LIB
throw Exception( __FILE__, __LINE__,
"DarkIce not compiled with lame support, "
"thus can't create mp3 stream: ",
stream);
#else
audioOuts[u].encoder = new LameLibEncoder(
audioOuts[u].server.get(),
dsp.get(),
bitrateMode,
bitrate,
quality,
sampleRate,
dsp->getChannel(),
lowpass,
highpass );
#endif // HAVE_TWOLAME_LIB
} else if ( Util::strEq( format, "mp2") ) {
#ifndef HAVE_TWOLAME_LIB
throw Exception( __FILE__, __LINE__,
示例5: configShoutCast
/*------------------------------------------------------------------------------
* Look for the ShoutCast stream outputs in the config file
*----------------------------------------------------------------------------*/
void
DarkIce :: configShoutCast ( const Config & config,
unsigned int bufferSecs )
throw ( Exception )
{
// look for Shoutcast encoder output streams,
// sections [shoutcast-0], [shoutcast-1], ...
char stream[] = "shoutcast- ";
size_t streamLen = Util::strLen( stream);
unsigned int u;
for ( u = noAudioOuts; u < maxOutput; ++u ) {
const ConfigSection * cs;
// ugly hack to change the section name to "stream0", "stream1", etc.
stream[streamLen-1] = '0' + (u - noAudioOuts);
if ( !(cs = config.get( stream)) ) {
break;
}
#ifndef HAVE_LAME_LIB
throw Exception( __FILE__, __LINE__,
"DarkIce not compiled with lame support, "
"thus can't connect to ShoutCast, stream: ",
stream);
#else
const char * str;
unsigned int sampleRate = 0;
unsigned int channel = 0;
AudioEncoder::BitrateMode bitrateMode;
unsigned int bitrate = 0;
double quality = 0.0;
const char * server = 0;
unsigned int port = 0;
const char * password = 0;
const char * name = 0;
const char * url = 0;
const char * genre = 0;
bool isPublic = false;
const char * mountPoint = 0;
int lowpass = 0;
int highpass = 0;
const char * irc = 0;
const char * aim = 0;
const char * icq = 0;
const char * localDumpName = 0;
FileSink * localDumpFile = 0;
bool fileAddDate = false;
const char * fileDateFormat = 0;
str = cs->get( "sampleRate");
sampleRate = str ? Util::strToL( str) : dsp->getSampleRate();
str = cs->get( "channel");
channel = str ? Util::strToL( str) : dsp->getChannel();
str = cs->get( "bitrate");
bitrate = str ? Util::strToL( str) : 0;
str = cs->get( "quality");
quality = str ? Util::strToD( str) : 0.0;
str = cs->getForSure( "bitrateMode",
" not specified in section ",
stream);
if ( Util::strEq( str, "cbr") ) {
bitrateMode = AudioEncoder::cbr;
if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__,
"bitrate not specified for CBR encoding");
}
if ( cs->get( "quality" ) == 0 ) {
throw Exception( __FILE__, __LINE__,
"quality not specified for CBR encoding");
}
} else if ( Util::strEq( str, "abr") ) {
bitrateMode = AudioEncoder::abr;
if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__,
"bitrate not specified for ABR encoding");
}
} else if ( Util::strEq( str, "vbr") ) {
bitrateMode = AudioEncoder::vbr;
if ( cs->get( "quality" ) == 0 ) {
throw Exception( __FILE__, __LINE__,
"quality not specified for VBR encoding");
}
} else {
throw Exception( __FILE__, __LINE__,
"invalid bitrate mode: ", str);
}
server = cs->getForSure( "server", " missing in section ", stream);
//.........这里部分代码省略.........
示例6: configIceCast2
/*------------------------------------------------------------------------------
* Look for the IceCast2 stream outputs in the config file
*----------------------------------------------------------------------------*/
void
DarkIce :: configIceCast2 ( const Config & config,
unsigned int bufferSecs )
throw ( Exception )
{
// look for IceCast2 encoder output streams,
// sections [icecast2-0], [icecast2-1], ...
char stream[] = "icecast2- ";
size_t streamLen = Util::strLen( stream);
unsigned int u;
for ( u = noAudioOuts; u < maxOutput; ++u ) {
const ConfigSection * cs;
// ugly hack to change the section name to "stream0", "stream1", etc.
stream[streamLen-1] = '0' + (u - noAudioOuts);
if ( !(cs = config.get( stream)) ) {
break;
}
const char * str;
IceCast2::StreamFormat format;
unsigned int sampleRate = 0;
unsigned int channel = 0;
AudioEncoder::BitrateMode bitrateMode;
unsigned int bitrate = 0;
unsigned int maxBitrate = 0;
double quality = 0.0;
const char * server = 0;
unsigned int port = 0;
const char * password = 0;
const char * mountPoint = 0;
const char * name = 0;
const char * description = 0;
const char * url = 0;
const char * genre = 0;
bool isPublic = false;
int lowpass = 0;
int highpass = 0;
const char * localDumpName = 0;
FileSink * localDumpFile = 0;
bool fileAddDate = false;
const char * fileDateFormat = 0;
str = cs->getForSure( "format", " missing in section ", stream);
if ( Util::strEq( str, "vorbis") ) {
format = IceCast2::oggVorbis;
} else if ( Util::strEq( str, "mp3") ) {
format = IceCast2::mp3;
} else if ( Util::strEq( str, "mp2") ) {
format = IceCast2::mp2;
} else if ( Util::strEq( str, "aac") ) {
format = IceCast2::aac;
} else if ( Util::strEq( str, "aacp") ) {
format = IceCast2::aacp;
} else {
throw Exception( __FILE__, __LINE__,
"unsupported stream format: ", str);
}
str = cs->get( "sampleRate");
sampleRate = str ? Util::strToL( str) : dsp->getSampleRate();
str = cs->get( "channel");
channel = str ? Util::strToL( str) : dsp->getChannel();
// determine fixed bitrate or variable bitrate quality
str = cs->get( "bitrate");
bitrate = str ? Util::strToL( str) : 0;
str = cs->get( "maxBitrate");
maxBitrate = str ? Util::strToL( str) : 0;
str = cs->get( "quality");
quality = str ? Util::strToD( str) : 0.0;
str = cs->getForSure( "bitrateMode",
" not specified in section ",
stream);
if ( Util::strEq( str, "cbr") ) {
bitrateMode = AudioEncoder::cbr;
if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__,
"bitrate not specified for CBR encoding");
}
} else if ( Util::strEq( str, "abr") ) {
bitrateMode = AudioEncoder::abr;
if ( bitrate == 0 ) {
throw Exception( __FILE__, __LINE__,
"bitrate not specified for ABR encoding");
}
} else if ( Util::strEq( str, "vbr") ) {
bitrateMode = AudioEncoder::vbr;
if ( cs->get( "quality" ) == 0 ) {
throw Exception( __FILE__, __LINE__,
//.........这里部分代码省略.........
示例7: configShoutCast
/*------------------------------------------------------------------------------
* Look for the ShoutCast stream outputs in the config file
*----------------------------------------------------------------------------*/
void
DarkIce :: configShoutCast ( const Config & config,
unsigned int bufferSecs )
throw ( Exception )
{
// look for IceCast encoder output streams,
// sections [shoutcast-0], [shoutcast-1], ...
char stream[] = "shoutcast- ";
size_t streamLen = Util::strLen( stream);
unsigned int u;
for ( u = 0; u < maxOutput; ++u ) {
const ConfigSection * cs;
// ugly hack to change the section name to "stream0", "stream1", etc.
stream[streamLen-1] = '0' + u;
if ( !(cs = config.get( stream)) ) {
break;
}
#ifndef HAVE_LAME_LIB
throw Exception( __FILE__, __LINE__,
"DarkIce not compiled with lame support, "
"thus can't connect to ShoutCast, stream: ",
stream);
#else
const char * str;
unsigned int sampleRate = 0;
unsigned int bitrate = 0;
const char * server = 0;
unsigned int port = 0;
const char * password = 0;
const char * name = 0;
const char * url = 0;
const char * genre = 0;
bool isPublic = false;
int lowpass = 0;
int highpass = 0;
const char * irc = 0;
const char * aim = 0;
const char * icq = 0;
const char * localDumpName = 0;
FileSink * localDumpFile = 0;
str = cs->get( "sampleRate");
sampleRate = str ? Util::strToL( str) : dsp->getSampleRate();
str = cs->getForSure("bitrate", " missing in section ", stream);
bitrate = Util::strToL( str);
server = cs->getForSure( "server", " missing in section ", stream);
str = cs->getForSure( "port", " missing in section ", stream);
port = Util::strToL( str);
password = cs->getForSure("password"," missing in section ",stream);
name = cs->get( "name");
url = cs->get( "url");
genre = cs->get( "genre");
str = cs->get( "public");
isPublic = str ? (Util::strEq( str, "yes") ? true : false) : false;
str = cs->get( "lowpass");
lowpass = str ? Util::strToL( str) : 0;
str = cs->get( "highpass");
highpass = str ? Util::strToL( str) : 0;
irc = cs->get( "irc");
aim = cs->get( "aim");
icq = cs->get( "icq");
localDumpName = cs->get( "localDumpFile");
// go on and create the things
// check for and create the local dump file if needed
if ( localDumpName != 0 ) {
localDumpFile = new FileSink( localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
localDumpName);
localDumpFile = 0;
}
}
}
// encoder related stuff
unsigned int bs = bufferSecs *
(dsp->getBitsPerSample() / 8) *
dsp->getChannel() *
dsp->getSampleRate();
reportEvent( 6, "using buffer size", bs);
// streaming related stuff
audioOuts[u].socket = new TcpSocket( server, port);
audioOuts[u].server = new ShoutCast( audioOuts[u].socket.get(),
password,
bitrate,
name,
url,
//.........这里部分代码省略.........
示例8: configIceCast2
/*------------------------------------------------------------------------------
* Look for the IceCast2 stream outputs in the config file
*----------------------------------------------------------------------------*/
void
DarkIce :: configIceCast2 ( const Config & config,
unsigned int bufferSecs )
throw ( Exception )
{
// look for IceCast2 encoder output streams,
// sections [icecast2-0], [icecast2-1], ...
char stream[] = "icecast2- ";
size_t streamLen = Util::strLen( stream);
unsigned int u;
for ( u = 0; u < maxOutput; ++u ) {
const ConfigSection * cs;
// ugly hack to change the section name to "stream0", "stream1", etc.
stream[streamLen-1] = '0' + u;
if ( !(cs = config.get( stream)) ) {
break;
}
const char * str;
IceCast2::StreamFormat format;
unsigned int bitrate = 0;
const char * server = 0;
unsigned int port = 0;
const char * password = 0;
const char * mountPoint = 0;
const char * name = 0;
const char * description = 0;
const char * url = 0;
const char * genre = 0;
bool isPublic = false;
const char * localDumpName = 0;
FileSink * localDumpFile = 0;
str = cs->getForSure( "format", " missing in section ", stream);
if ( Util::strEq( str, "vorbis") ) {
format = IceCast2::oggVorbis;
} else if ( Util::strEq( str, "mp3") ) {
format = IceCast2::mp3;
// TODO: enable this format in the future, when icecast2
// supports it as well
throw Exception( __FILE__, __LINE__,
"unsupported stream format: ", str);
} else {
throw Exception( __FILE__, __LINE__,
"unsupported stream format: ", str);
}
str = cs->getForSure("bitrate", " missing in section ", stream);
bitrate = Util::strToL( str);
server = cs->getForSure( "server", " missing in section ", stream);
str = cs->getForSure( "port", " missing in section ", stream);
port = Util::strToL( str);
password = cs->getForSure("password"," missing in section ",stream);
mountPoint = cs->getForSure( "mountPoint",
" missing in section ",
stream);
name = cs->get( "name");
description = cs->get("description");
url = cs->get( "url");
genre = cs->get( "genre");
str = cs->get( "public");
isPublic = str ? (Util::strEq( str, "yes") ? true : false) : false;
localDumpName = cs->get( "localDumpFile");
// go on and create the things
// check for and create the local dump file if needed
if ( localDumpName != 0 ) {
localDumpFile = new FileSink( localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
localDumpName);
localDumpFile = 0;
}
}
}
// encoder related stuff
unsigned int bs = bufferSecs *
(dsp->getBitsPerSample() / 8) *
dsp->getChannel() *
dsp->getSampleRate();
reportEvent( 6, "using buffer size", bs);
// streaming related stuff
audioOuts[u].socket = new TcpSocket( server, port);
audioOuts[u].server = new IceCast2( audioOuts[u].socket.get(),
password,
mountPoint,
format,
bitrate,
name,
//.........这里部分代码省略.........
示例9: createOutputFiles
void createOutputFiles(char const* periodicFilenameSuffix) {
char outFileName[1000];
if (outputQuickTimeFile || outputAVIFile) {
if (periodicFilenameSuffix[0] == '\0') {
// Normally (unless the '-P <interval-in-seconds>' option was given) we output to 'stdout':
sprintf(outFileName, "stdout");
} else {
// Otherwise output to a type-specific file name, containing "periodicFilenameSuffix":
char const* prefix = fileNamePrefix[0] == '\0' ? "output" : fileNamePrefix;
snprintf(outFileName, sizeof outFileName, "%s%s.%s", prefix, periodicFilenameSuffix,
outputAVIFile ? "avi" : generateMP4Format ? "mp4" : "mov");
}
if (outputQuickTimeFile) {
qtOut = QuickTimeFileSink::createNew(*env, *session, outFileName,
fileSinkBufferSize,
movieWidth, movieHeight,
movieFPS,
packetLossCompensate,
syncStreams,
generateHintTracks,
generateMP4Format);
if (qtOut == NULL) {
*env << "Failed to create a \"QuickTimeFileSink\" for outputting to \""
<< outFileName << "\": " << env->getResultMsg() << "\n";
shutdown();
} else {
*env << "Outputting to the file: \"" << outFileName << "\"\n";
}
qtOut->startPlaying(sessionAfterPlaying, NULL);
} else { // outputAVIFile
aviOut = AVIFileSink::createNew(*env, *session, outFileName,
fileSinkBufferSize,
movieWidth, movieHeight,
movieFPS,
packetLossCompensate);
if (aviOut == NULL) {
*env << "Failed to create an \"AVIFileSink\" for outputting to \""
<< outFileName << "\": " << env->getResultMsg() << "\n";
shutdown();
} else {
*env << "Outputting to the file: \"" << outFileName << "\"\n";
}
aviOut->startPlaying(sessionAfterPlaying, NULL);
}
} else {
// Create and start "FileSink"s for each subsession:
madeProgress = False;
MediaSubsessionIterator iter(*session);
while ((subsession = iter.next()) != NULL) {
if (subsession->readSource() == NULL) continue; // was not initiated
// Create an output file for each desired stream:
if (singleMedium == NULL || periodicFilenameSuffix[0] != '\0') {
// Output file name is
// "<filename-prefix><medium_name>-<codec_name>-<counter><periodicFilenameSuffix>"
static unsigned streamCounter = 0;
snprintf(outFileName, sizeof outFileName, "%s%s-%s-%d%s",
fileNamePrefix, subsession->mediumName(),
subsession->codecName(), ++streamCounter, periodicFilenameSuffix);
} else {
// When outputting a single medium only, we output to 'stdout
// (unless the '-P <interval-in-seconds>' option was given):
sprintf(outFileName, "stdout");
}
FileSink* fileSink;
if (strcmp(subsession->mediumName(), "audio") == 0 &&
(strcmp(subsession->codecName(), "AMR") == 0 ||
strcmp(subsession->codecName(), "AMR-WB") == 0)) {
// For AMR audio streams, we use a special sink that inserts AMR frame hdrs:
fileSink = AMRAudioFileSink::createNew(*env, outFileName,
fileSinkBufferSize, oneFilePerFrame);
} else if (strcmp(subsession->mediumName(), "video") == 0 &&
(strcmp(subsession->codecName(), "H264") == 0)) {
// For H.264 video stream, we use a special sink that adds 'start codes',
// and (at the start) the SPS and PPS NAL units:
fileSink = H264VideoFileSink::createNew(*env, outFileName,
subsession->fmtp_spropparametersets(),
fileSinkBufferSize, oneFilePerFrame);
} else if (strcmp(subsession->mediumName(), "video") == 0 &&
(strcmp(subsession->codecName(), "H265") == 0)) {
// For H.265 video stream, we use a special sink that adds 'start codes',
// and (at the start) the VPS, SPS, and PPS NAL units:
fileSink = H265VideoFileSink::createNew(*env, outFileName,
subsession->fmtp_spropvps(),
subsession->fmtp_spropsps(),
subsession->fmtp_sproppps(),
fileSinkBufferSize, oneFilePerFrame);
} else {
// Normal case:
fileSink = FileSink::createNew(*env, outFileName,
fileSinkBufferSize, oneFilePerFrame);
}
subsession->sink = fileSink;
if (subsession->sink == NULL) {
*env << "Failed to create FileSink for \"" << outFileName
<< "\": " << env->getResultMsg() << "\n";
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
case 'w': { // specify a width (pixels) for an output QuickTime or AVI movie
if (sscanf(argv[2], "%hu", &movieWidth) != 1) {
usage();
}
movieWidthOptionSet = True;
++argv; --argc;
break;
}
case 'h': { // specify a height (pixels) for an output QuickTime or AVI movie
if (sscanf(argv[2], "%hu", &movieHeight) != 1) {
usage();
}
movieHeightOptionSet = True;
++argv; --argc;
break;
}
case 'f': { // specify a frame rate (per second) for an output QT or AVI movie
if (sscanf(argv[2], "%u", &movieFPS) != 1) {
usage();
}
movieFPSOptionSet = True;
++argv; --argc;
break;
}
case 'F': { // specify a prefix for the audio and video output files
fileNamePrefix = argv[2];
++argv; --argc;
break;
}
case 'b': { // specify the size of buffers for "FileSink"s
if (sscanf(argv[2], "%u", &fileSinkBufferSize) != 1) {
usage();
}
++argv; --argc;
break;
}
case 'B': { // specify the size of input socket buffers
if (sscanf(argv[2], "%u", &socketInputBufferSize) != 1) {
usage();
}
++argv; --argc;
break;
}
// Note: The following option is deprecated, and may someday be removed:
case 'l': { // try to compensate for packet loss by repeating frames
packetLossCompensate = True;
break;
}
case 'y': { // synchronize audio and video streams
syncStreams = True;
break;
}
case 'H': { // generate hint tracks (as well as the regular data tracks)
generateHintTracks = True;
break;
}
case 'Q': { // output QOS measurements
示例11: main
int main(int argc, char *argv[]) {
Opt opt;
opt.registerOpt(P_DeviceName, "-d", false, true, "specify DV4Mini device name", "/dev/ttyACM0");
opt.registerOpt(P_Frequency, "-f", false, true, "set frequency in Hz", "430312500");
opt.registerOpt(P_WriteRxToFile, "-w", false, true, "write received data to file");
opt.registerOpt(P_TxFromFile, "-tx", false, true, "transmit data from file");
opt.registerOpt(P_SimMode, "-s", false, false, "simulate without real hardware");
opt.registerOpt(P_LogLevel, "-ll", false, true, "log level");
opt.registerOpt(P_DebugMode, "-debug", false, false, "set debug mode");
if(!opt.parse(argc, argv)) {
opt.printHelp();
return 1;
}
bool bDebug = opt.get(P_DebugMode);
bool bSimMode = opt.get(P_SimMode);
if(bDebug) opt.dump();
std::string sDeviceName = opt.getString(P_DeviceName);
int iFrequency_Hz = opt.getInt(P_Frequency);
DV4Mini mini;
if(bSimMode) {
sDeviceName = "/dev/null";
mini.setSimulationMode(true);
}
mini.setLogFile(stdout, opt.getInt(P_LogLevel));
if(!mini.open(sDeviceName.c_str())) {
perror(sDeviceName.c_str());
return 1;
}
mini.setFrequency(iFrequency_Hz);
printf("Using device \"%s\" at %d Hz (%.3f kHz).\n", sDeviceName.c_str(), iFrequency_Hz, iFrequency_Hz / 1000.);
mini.setLED(true);
FileSink fsink;
if(opt.get(P_WriteRxToFile)) {
const char *pszWriteFileName = opt.getString(P_WriteRxToFile).c_str();
if(!fsink.open(pszWriteFileName)) {
perror(pszWriteFileName);
return 1;
}
mini.setRxSink(&fsink);
printf("Writing received data to file \"%s\".\n", pszWriteFileName);
}
if(opt.get(P_TxFromFile)) {
const char *pszReadFileName = opt.getString(P_TxFromFile).c_str();
FILE *pFile = fopen(pszReadFileName, "r");
if(!pFile) {
perror(pszReadFileName);
return 1;
}
printf("Sending file \"%s\"", pszReadFileName);
BYTE buf[100];
while(true) {
putchar('.');
int iBytes = fread(buf, 1, sizeof buf, pFile);
if(iBytes <= 0) break;
mini.transmit(buf, iBytes);
usleep(10);
}
puts("done!\n");
mini.flush();
fclose(pFile);
mini.close();
return 0;
}
#if 1
for(int i = 0; i < 5; ++i) {
sleep(1);
printf("RSSI=%d\n", mini.getRSSI());
}
#else
for(int i = 0; i < 50; ++i) {
usleep(100);
printf("RSSI=%d\n", mini.getRSSI());
}
#endif
mini.close();
return 0;
}