FilterPictureSink*
FilterPictureSink::make(FilterGraph* graph, AVFilterContext* ctx) {
  Global::init();
  RefPointer<FilterPictureSink> r;
  r.reset(new FilterPictureSink(graph, ctx), true);
  return r.get();
}
示例#2
0
//
// Sign a binary that has no notion of architecture.
// That currently means anything that isn't Mach-O format.
//
void SecCodeSigner::Signer::signArchitectureAgnostic(const Requirement::Context &context)
{
	// non-Mach-O executable - single-instance signing
	RefPointer<DiskRep::Writer> writer = state.mDetached ?
		(new DetachedBlobWriter(*this)) : rep->writer();
	CodeDirectory::Builder builder(state.mDigestAlgorithm);
	InternalRequirements ireqs;
	ireqs(state.mRequirements, rep->defaultRequirements(NULL, state), context);
	populate(*writer);
	populate(builder, *writer, ireqs, rep->signingBase(), rep->signingLimit());
	
	// add identification blob (made from this architecture) only if we're making a detached signature
	if (state.mDetached) {
		CFRef<CFDataRef> identification = rep->identification();
		writer->component(cdIdentificationSlot, identification);
	}
	
	CodeDirectory *cd = builder.build();
	CFRef<CFDataRef> signature = signCodeDirectory(cd);
	if (!state.mDryRun) {
		writer->codeDirectory(cd);
		writer->signature(signature);
		writer->flush();
	}
	::free(cd);
}
示例#3
0
Coder*
Container::Stream::getCoder() {
  if (!mCoder) {
    // we need to know the stream direction...
    AVFormatContext* ctx = mContainer->getFormatCtx();
    AVStream* stream = getCtx();

    if (!ctx || !stream) {
      VS_THROW(HumbleRuntimeError("could not get container context to find coder"));
    }
    if (!stream->codec) {
      VS_THROW(HumbleRuntimeError("No codec set for stream"));
    }
    RefPointer<Codec> codec;

    if (ctx->iformat) {
      // make a copy of the decoder so we decouple it from the container
      // completely
      codec = Codec::findDecodingCodec((Codec::ID)stream->codec->codec_id);
      if (!codec) {
        VS_THROW(HumbleRuntimeError("could not find decoding codec"));
      }
      mCoder = Decoder::make(codec.value(), stream->codec, true);
    } else {
      VS_THROW(HumbleRuntimeError("Got null encoder on MuxerStream which should not be possible"));
    }
  }
  return mCoder.get();
}
示例#4
0
bool SignallingInterface::notify(Notification event)
{
    m_recvMutex.lock();
    RefPointer<SignallingReceiver> tmp = m_receiver;
    m_recvMutex.unlock();
    return tmp && tmp->notify(event);
}
示例#5
0
Codec*
Codec::guessEncodingCodec(MuxerFormat* pFmt, const char* shortName,
    const char* url, const char* mimeType, MediaDescriptor::Type type) {
  Global::init();
  Codec* retval = 0;
  RefPointer<MuxerFormat> fmt = 0;
  AVOutputFormat * oFmt = 0;

  // We acquire here because the RefPointer always
  // releases.
  fmt.reset(dynamic_cast<MuxerFormat*>(pFmt), true);

  if (!fmt) {
    fmt = MuxerFormat::guessFormat(shortName, url, mimeType);
  }
  if (fmt) oFmt = fmt->getCtx();

  // Make sure at least one in put is specified.
  // The av_guess_codec function REQUIRES a
  // non null AVOutputFormat
  // It also examines url with a strcmp(), so let's
  // give it a zero-length string.
  // In reality, it ignores the other params.
  if (!url) url = "";

  if (oFmt) {
    enum AVCodecID id = av_guess_codec(oFmt, shortName, url, mimeType,
        (enum AVMediaType) type);
    retval = Codec::findEncodingCodecByIntID((int) id);
  }
  return retval;
}
示例#6
0
bool SignallingReceiver::control(SignallingInterface::Operation oper, NamedList* params)
{
    m_ifaceMutex.lock();
    RefPointer<SignallingInterface> tmp = m_interface;
    m_ifaceMutex.unlock();
    return TelEngine::controlReturn(params,tmp && tmp->control(oper,params));
}
示例#7
0
bool SignallingInterface::receivedPacket(const DataBlock& packet)
{
    m_recvMutex.lock();
    RefPointer<SignallingReceiver> tmp = m_receiver;
    m_recvMutex.unlock();
    return tmp && tmp->receivedPacket(packet);
}
示例#8
0
void
MetaDataTest :: testStreamSetMetaData()
{
  Helper h;
  h.setupWriting("testStreamSetMetaData.mp3",
      0, "libmp3lame", 0);
  RefPointer<IStream> stream = h.container->getStream(0);
  RefPointer<IMetaData> meta = stream->getMetaData();
  VS_TUT_ENSURE("got meta data", meta);
  meta = IMetaData::make();
  if (meta)
  {
    VS_TUT_ENSURE_EQUALS("", meta->getNumKeys(), 0);
    meta->setValue("author", "Art Clarke");
    stream->setMetaData(meta.value());
  }
  meta = stream->getMetaData();
  VS_TUT_ENSURE("got meta data", meta);
  if (meta)
  {
    VS_TUT_ENSURE_EQUALS("", meta->getNumKeys(), 1);
    const char* value = meta->getValue("author", IMetaData::METADATA_NONE);
    VS_TUT_ENSURE("", strcmp("Art Clarke",value)==0);
  }
}
示例#9
0
  BufferImpl*
  BufferImpl :: make(io::humble::ferry::RefCounted* requestor, int32_t bufferSize)
  {
    RefPointer<BufferImpl> retval;
    if (bufferSize <= 0)
      VS_THROW(HumbleInvalidArgument("bufferSize must be > 0"));
    
    void * allocator = requestor ? requestor->getJavaAllocator() : 0;
    void *buffer = JNIMemoryManager::malloc(allocator, bufferSize);
    if (!buffer) {
      VS_THROW(HumbleBadAlloc());
    }
      
    try {
      retval = BufferImpl::make();

      retval->mBuffer = buffer;
      retval->mBufferSize = bufferSize;
      retval->mInternallyAllocated = true;
    } catch (std::exception & e) {
      JNIMemoryManager::free(buffer);
      throw;
    }
    return retval.get();
  }
示例#10
0
  BufferImpl*
  BufferImpl :: make(io::humble::ferry::RefCounted* /*unused*/, void *bufToWrap, int32_t bufferSize,
      FreeFunc freeFunc, void *closure)
  {
    RefPointer<BufferImpl> retval;

    if (!bufToWrap) {
      VS_THROW(HumbleInvalidArgument("bufToWrap must be non null"));
    }

    if (bufferSize <= 0) {
      VS_THROW(HumbleInvalidArgument("bufferSize must be > 0"));
    }

    if (bufToWrap && bufferSize>0)
    {
      retval = BufferImpl::make();
      retval->mFreeFunc = freeFunc;
      retval->mClosure = closure;
      retval->mBufferSize = bufferSize;
      retval->mBuffer = bufToWrap;
      retval->mInternallyAllocated = false;
    }
    return retval.get();
  }
示例#11
0
// Attach a tone detector on "chan.attach" as consumer or sniffer
bool AttachHandler::received(Message& msg)
{
    String cons(msg.getValue("consumer"));
    if (!cons.startsWith("tone/"))
	cons.clear();
    String snif(msg.getValue("sniffer"));
    if (!snif.startsWith("tone/"))
	snif.clear();
    if (cons.null() && snif.null())
	return false;
    CallEndpoint* ch = static_cast<CallEndpoint*>(msg.userObject("CallEndpoint"));
    RefPointer<DataEndpoint> de = static_cast<DataEndpoint*>(msg.userObject("DataEndpoint"));
    DataSource* ds = static_cast<DataSource*>(msg.userObject("DataSource"));
    if (ch) {
	if (cons) {
	    ToneConsumer* c = new ToneConsumer(ch->id(),cons);
	    c->setFaxDivert(msg);
	    ch->setConsumer(c);
	    c->deref();
	}
	if (snif) {
	    de = ch->setEndpoint();
	    // try to reinit sniffer if one already exists
	    ToneConsumer* c = static_cast<ToneConsumer*>(de->getSniffer(snif));
	    if (c) {
		c->init();
		c->setFaxDivert(msg);
	    }
	    else {
		c = new ToneConsumer(ch->id(),snif);
		c->setFaxDivert(msg);
		de->addSniffer(c);
		c->deref();
	    }
	}
	return msg.getBoolValue("single");
    }
    else if (ds && cons) {
	ToneConsumer* c = new ToneConsumer(msg.getValue("id"),cons);
	c->setFaxDivert(msg);
	bool ok = DataTranslator::attachChain(ds,c);
	if (ok)
	    msg.userData(c);
	else
	    msg.setParam("reason","attach-failure");
	c->deref();
	return ok && msg.getBoolValue("single");
    }
    else if (de && cons) {
	ToneConsumer* c = new ToneConsumer(msg.getValue("id"),cons);
	c->setFaxDivert(msg);
	de->setConsumer(c);
	c->deref();
	return msg.getBoolValue("single");
    }
    else
	Debug(&plugin,DebugWarn,"ToneDetector attach request with no call endpoint!");
    return false;
}
示例#12
0
FilterAudioSource*
FilterAudioSource::make(FilterGraph* graph,
    AVFilterContext* ctx) {
  Global::init();
  RefPointer<FilterAudioSource> r;
  r.reset(new FilterAudioSource(graph, ctx), true);
  return r.get();
}
示例#13
0
bool SignallingReceiver::transmitPacket(const DataBlock& packet, bool repeat,
    SignallingInterface::PacketType type)
{
    m_ifaceMutex.lock();
    RefPointer<SignallingInterface> tmp = m_interface;
    m_ifaceMutex.unlock();
    return tmp && tmp->transmitPacket(packet,repeat,type);
}
void
BitStreamFilterTest::testMakeByType () {
  const char* name = "noise";
  RefPointer<BitStreamFilterType> t = BitStreamFilterType::getBitStreamFilterType(name);
  TS_ASSERT(strcmp(name, t->getName())==0);
  RefPointer<BitStreamFilter> f = BitStreamFilter::make(t.value());
  TS_ASSERT(strcmp(name, f->getName())==0);
}
示例#15
0
void
EncoderTest::testCreation() {
  Logger::setGlobalIsLogging(Logger::LEVEL_TRACE, false);

  RefPointer<Codec> codec = Codec::findEncodingCodec(Codec::CODEC_ID_H264);
  RefPointer<Encoder> encoder = Encoder::make(codec.value());
  TS_ASSERT(encoder);
}
示例#16
0
MediaSubtitleRectangle*
MediaSubtitleRectangle::make(AVSubtitleRect* ctx) {
  if (!ctx)
    throw HumbleInvalidArgument("no context");
  RefPointer<MediaSubtitleRectangle> retval = make();
  retval->mCtx = ctx;
  return retval.get();
}
示例#17
0
void VertexArrayBuffer::UploadData(BindingInfo const & bindingInfo, void const * data, uint16_t count)
{
  RefPointer<DataBuffer> buffer;
  if (!bindingInfo.IsDynamic())
    buffer = GetOrCreateStaticBuffer(bindingInfo);
  else
    buffer = GetOrCreateDynamicBuffer(bindingInfo);
  buffer->UploadData(data, count);
}
void Reader::insertToken(TokenDaemon *tokend)
{
	RefPointer<Token> token = new Token();
	token->insert(*this, tokend);
	mToken = token;
	addReference(*token);
	secdebug("reader", "%p (%s) inserted token %p",
		this, name().c_str(), mToken);
}
示例#19
0
void
MuxerFormatTest::testInstallation() {
  int32_t n = MuxerFormat::getNumFormats();
  TSM_ASSERT("", n > 0);

  for(int32_t i = 0; i < n; i++) {
    RefPointer<MuxerFormat> f = MuxerFormat::getFormat(i);
    VS_LOG_DEBUG("Name: %s; Description: %s", f->getName(), f->getLongName());
  }
}
示例#20
0
void
PropertyTest :: testCreation()
{
  LoggerStack stack;
  stack.setGlobalLevel(Logger::LEVEL_WARN, false);
  RefPointer<Configurable> c = Demuxer::make();
  RefPointer<Property> property =  c->getPropertyMetaData("packetsize");
  VS_LOG_DEBUG("Name: %s", property->getName());
  VS_LOG_DEBUG("Description: %s", property->getHelp());
  TSM_ASSERT("should exist", property);
}
示例#21
0
void
MediaPictureImpl::copy(AVFrame* src, bool complete) {
  if (!src)
    VS_THROW(HumbleInvalidArgument("no src"));
  // release any memory we have
  av_frame_unref(mFrame);
  // and copy any data in.
  av_frame_ref(mFrame, src);
  RefPointer<Rational> timeBase = getTimeBase();
  setTimeBase(timeBase.value());
  mComplete=complete;
}
示例#22
0
Buffer*
MediaPictureImpl::getData(int32_t plane) {
  validatePlane(plane);
  // we get the buffer for the given plane if it exists, and wrap
  // it in an Buffer
  // now we're guaranteed that we should have a plane.
  RefPointer<Buffer> buffer;
  if (mFrame->buf[plane])
    buffer = AVBufferSupport::wrapAVBuffer(this,
        mFrame->buf[plane], mFrame->data[plane], mFrame->buf[plane]->size);
  return buffer.get();
}
RefPointer<Listener::Notification> Listener::JitterBuffer::popNotification()
{
	JBuffer::iterator it = mBuffer.find(mNotifyLast + 1);	// have next message?
	if (it == mBuffer.end())
		return NULL;			// nothing here
	else {
		RefPointer<Notification> result = it->second;	// save value
		mBuffer.erase(it);		// remove from buffer
		secinfo("notify-jit", "%p retrieved from jitter buffer", result.get());
		return result;			// return it
	}
}
示例#24
0
// recode/clone:
//
// Special-purpose constructor for keychain synchronization.  Copies an
// existing keychain but uses the operational keys from secretsBlob.  The 
// new KeychainDatabase will silently replace the existing KeychainDatabase
// as soon as the client declares that re-encoding of all keychain items is
// finished.  This is a little perilous since it allows a client to dictate
// securityd state, but we try to ensure that only the client that started 
// the re-encoding can declare it done.  
//
KeychainDatabase::KeychainDatabase(KeychainDatabase &src, Process &proc, DbHandle dbToClone)
	: LocalDatabase(proc), mValidData(false), mSecret(Allocator::standard(Allocator::sensitive)), mSaveSecret(false), version(0), mBlob(NULL)
{
	mCred = DataWalkers::copy(src.mCred, Allocator::standard());

	// Give this KeychainDatabase a temporary name
	std::string newDbName = std::string("////") + std::string(src.identifier().dbName());
	DLDbIdentifier newDLDbIdent(src.identifier().dlDbIdentifier().ssuid(), newDbName.c_str(), src.identifier().dlDbIdentifier().dbLocation());
	DbIdentifier ident(newDLDbIdent, src.identifier());

    // create common block and initialize
	RefPointer<KeychainDbCommon> newCommon = new KeychainDbCommon(proc.session(), ident);
	StLock<Mutex> _(*newCommon);
	parent(*newCommon);

	// set initial database parameters from the source keychain
	common().mParams = src.common().mParams;
	
	// establish the source keychain's master secret as ours
	// @@@  NB: this is a v. 0.1 assumption.  We *should* trigger new UI 
	//      that offers the user the option of using the existing password 
	//      or choosing a new one.  That would require a new 
	//      SecurityAgentQuery type, new UI, and--possibly--modifications to
	//      ensure that the new password is available here to generate the 
	//      new master secret.  
	src.unlockDb();		// precaution for masterKey()
	common().setup(src.blob(), src.common().masterKey());
	
    // import the operational secrets
	RefPointer<KeychainDatabase> srcKC = Server::keychain(dbToClone);
	common().importSecrets(srcKC->common());
	
	// import source keychain's ACL  
	CssmData pubAcl, privAcl;
	src.acl().exportBlob(pubAcl, privAcl);
	importBlob(pubAcl.data(), privAcl.data());
	src.acl().allocator.free(pubAcl);
	src.acl().allocator.free(privAcl);
	
	// indicate that this keychain should be allowed to do some otherwise
	// risky things required for copying, like re-encoding keys
	mRecodingSource = &src;
	
	common().setUnlocked();
	mValidData = true;
	
    encode();

	proc.addReference(*this);
	secdebug("SSdb", "database %s(%p) created as copy, common at %p",
			 common().dbName(), this, &common());
}
示例#25
0
void
MediaAudioTest::testCreationFromBufferPlanar() {
  const int32_t numSamples = 155; // I choose an odd number because HV will align up to 32
  const int32_t sampleRate = 22050;
  const int32_t channels = 15; // choose a large # of channels to make sure we expand the Frame
  const AudioChannel::Layout layout = AudioChannel::CH_LAYOUT_UNKNOWN;
  const AudioFormat::Type format = AudioFormat::SAMPLE_FMT_DBLP;

  int32_t bufSize = AudioFormat::getBufferSizeNeeded(numSamples, channels,
      format);
  // test that there is rounding up
  int32_t minSize = AudioFormat::getBytesPerSample(format) * numSamples
      * channels;
  TS_ASSERT_LESS_THAN(minSize, bufSize);

  RefPointer<Buffer> src = Buffer::make(0, bufSize);
  double* srcData = (double*) src->getBytes(0, bufSize);

  // now, let's go nuts!
  for (size_t i = 0; i < bufSize / sizeof(double); i++) {
    srcData[i] = i;
  }

  RefPointer<MediaAudio> audio;

  {
    LoggerStack stack;
    stack.setGlobalLevel(Logger::LEVEL_ERROR, false);

    TS_ASSERT_THROWS(MediaAudio::make(0, numSamples, sampleRate, channels, layout,
        format), HumbleInvalidArgument);
  }
  audio = MediaAudio::make(src.value(), numSamples, sampleRate, channels,
      layout, format);
  TS_ASSERT(audio);

  TS_ASSERT_EQUALS(channels, audio->getNumDataPlanes());

  // sigh; time to test each plane.
  for (int i = 0; i < channels; i++) {
    RefPointer<Buffer> dst = audio->getData(i);
    TS_ASSERT(dst);
    double* dstData = (double*) dst->getBytes(0, dst->getBufferSize());

    // the values should be monotonically increasing given how we set them.
    double last = dstData[0];
    for (size_t j = 1; j < dst->getBufferSize() / sizeof(double); j++) {
      TS_ASSERT_DELTA(last + 1, dstData[j], 0.001);
      last = dstData[j];
    }
  }
}
示例#26
0
文件: assist.cpp 项目: guyt101z/yate
bool ChanAssistList::received(Message& msg, int id)
{
    String* chanId = msg.getParam("id");
    if (!chanId || chanId->null())
        return (id < Private) && Module::received(msg,id);
    Lock mylock(this);
    RefPointer <ChanAssist> ca = find(*chanId);
    switch (id) {
    case Startup:
        if (ca) {
            Debug(this,DebugNote,"Channel '%s' already assisted!",chanId->c_str());
            mylock.drop();
            ca->msgStartup(msg);
            return false;
        }
        ca = create(msg,*chanId);
        if (ca) {
            m_calls.append(ca);
            mylock.drop();
            ca->msgStartup(msg);
        }
        return false;
    case Hangup:
        if (ca) {
            removeAssist(ca);
            mylock.drop();
            ca->msgHangup(msg);
            ca->deref();
            ca = 0;
        }
        return false;
    case Execute:
        if (ca) {
            mylock.drop();
            ca->msgExecute(msg);
            return false;
        }
        ca = create(msg,*chanId);
        if (ca) {
            m_calls.append(ca);
            mylock.drop();
            ca->msgStartup(msg);
            ca->msgExecute(msg);
        }
        return false;
    case Disconnected:
        mylock.drop();
        return ca && ca->msgDisconnect(msg,msg.getValue("reason"));
    default:
        mylock.drop();
        if (ca)
            return received(msg,id,ca);
        return (id < Private) && Module::received(msg,id);
    }
}
示例#27
0
void PCSCMonitor::loadSoftToken(Bundle *tokendBundle)
{
	try {
		string bundleName = tokendBundle->identifier();
		
		// prepare a virtual reader, removing any existing one (this would kill a previous tokend)
		assert(mReaders.find(bundleName) == mReaders.end());	// not already present
		RefPointer<Reader> reader = new Reader(tokenCache(), bundleName);

		// now launch the tokend
		RefPointer<TokenDaemon> tokend = new TokenDaemon(tokendBundle,
			reader->name(), reader->pcscState(), reader->cache);
		
		if (tokend->state() == ServerChild::dead) {	// ah well, this one's no good
			secinfo("pcsc", "softtoken %s tokend launch failed", bundleName.c_str());
			Syslog::notice("Software token %s failed to run", tokendBundle->canonicalPath().c_str());
			return;
		}
		
		// probe the (single) tokend
		if (!tokend->probe()) {		// non comprende...
			secinfo("pcsc", "softtoken %s probe failed", bundleName.c_str());
			Syslog::notice("Software token %s refused operation", tokendBundle->canonicalPath().c_str());
			return;
		}
		
		// okay, this seems to work. Set it up
		mReaders.insert(make_pair(reader->name(), reader));
		reader->insertToken(tokend);
		Syslog::notice("Software token %s activated", bundleName.c_str());
	} catch (...) {
		secinfo("pcsc", "exception loading softtoken %s - continuing", tokendBundle->identifier().c_str());
	}
}
示例#28
0
Buffer*
MediaSubtitleRectangle::getPictureData(int line)
{
  if (line < 0 || line >= 4)
    throw HumbleInvalidArgument("line must be between 0 and 3");
  // add ref ourselves for the Buffer
  this->acquire();
  // create a buffer
  RefPointer<Buffer> retval = Buffer::make(this, mCtx->pict.data[line], mCtx->pict.linesize[line],
      Buffer::refCountedFreeFunc, this);
  if (!retval)
    this->release();
  return retval.get();
}
void
BitStreamFilterTest::testNoiseFilter() {
  const char* name = "noise";
  RefPointer<BitStreamFilter> f = BitStreamFilter::make(name);

  // let's generate a buffer to add noise to.
  const int32_t inSize = 1024;
  // Annoyingly I have to add FF_INPUT_BUFFER_PADDING_SIZE because the noise
  // filter incorrectly memcopies an additional 16 bytes, and I want Valgrind to
  // not worry about that.
  RefPointer<Buffer> inBuf = Buffer::make(0, inSize+FF_INPUT_BUFFER_PADDING_SIZE);
  uint8_t* in = static_cast<uint8_t*>(inBuf->getBytes(0, inSize));
  int32_t outSize = inSize;
  RefPointer<Buffer> outBuf = Buffer::make(0, outSize+FF_INPUT_BUFFER_PADDING_SIZE);
  uint8_t* out = static_cast<uint8_t*>(outBuf->getBytes(0, outSize));
  for(int32_t i = 0; i < inSize+FF_INPUT_BUFFER_PADDING_SIZE; i++) {
    in[i] = static_cast<uint8_t>(i);
    out[i] = in[i];
  }

  outSize = f->filter(outBuf.value(), 0, inBuf.value(), 0, inSize, 0, 0, false);
  TS_ASSERT_EQUALS(outSize, inSize);
  int matches = 0;
  for(int32_t i = 0; i < inSize; i++) {
    if (in[i] == out[i])
      ++ matches;
  }
  // noise should make sure that not all elements match.
  TS_ASSERT(matches < inSize);
}
void
BitStreamFilterTest::testChompFilter() {
  const char* name = "chomp";
  RefPointer<BitStreamFilter> f = BitStreamFilter::make(name);

  // let's generate a buffer to chomp nulls off the end of.
  const int32_t inSize = 1024;
  RefPointer<Buffer> inBuf = Buffer::make(0, inSize);
  uint8_t* in = static_cast<uint8_t*>(inBuf->getBytes(0, inSize));
  int32_t outSize = inSize;
  RefPointer<Buffer> outBuf = Buffer::make(0, outSize);
  uint8_t* out = static_cast<uint8_t*>(outBuf->getBytes(0, outSize));

  // set the entire input buffer to null for now.
  memset(in, 0, inSize);
  // then set the first half of the buffer to be non-null.
  for(int32_t i = 0; i < inSize/2; i++) {
    in[i] = 0x01;
    out[i] = in[i];
  }

  // should filter out all the null bytes at the end.
  outSize = f->filter(outBuf.value(), 0, inBuf.value(), 0, inSize, 0, 0, false);
  TS_ASSERT_EQUALS(outSize, inSize/2);
  for(int32_t i = 0; i < inSize/2; i++) {
    TS_ASSERT_EQUALS(in[i], out[i]);
  }
}