Example #1
0
// decode data in d->packetData and fill d->outputBuffer
int K3bFFMpegFile::fillOutputBuffer()
{
  // decode if the output buffer is empty
  if( d->outputBufferSize <= 0 ) {

    // make sure we have data to decode
    if( readPacket() == 0 ) {
      return 0;
    }

    d->outputBufferPos = d->outputBuffer;

#ifdef FFMPEG_BUILD_PRE_4629
    int len = avcodec_decode_audio( &d->formatContext->streams[0]->codec,
#else
    int len = avcodec_decode_audio( d->formatContext->streams[0]->codec,
#endif
				    (short*)d->outputBuffer, &d->outputBufferSize,
				    d->packetData, d->packetSize );

    d->packetSize -= len;
    d->packetData += len;

    if( d->packetSize <= 0 )
      av_free_packet( &d->packet );
  }

  // if it is still empty try again
  if( d->outputBufferSize <= 0 )
    return fillOutputBuffer();
  else
    return d->outputBufferSize;
}
Example #2
0
void Logger::log(const std::string &tag, const char *funcName,
                 const char *sourceFile, unsigned int lineNum, 
					  const std::string& fmt, ...)
{
	std::string fileBuffer;

	fillFileBuffer(fileBuffer, tag, fmt, funcName, sourceFile, lineNum);

	// Print to file
	va_list args;
	const char* bufferCStr = fileBuffer.c_str();
	va_start(args, bufferCStr);
	vfprintf(m_pLogFile, bufferCStr, args);
	va_end(args);

	if (printToScreen)
	{
		std::string outputBuffer;
		fillOutputBuffer(outputBuffer, tag, fmt, funcName, sourceFile, lineNum);
		// Print to screen
		const char* bufferCStr = outputBuffer.c_str();
		va_start(args, bufferCStr);
		vfprintf(stdout, bufferCStr, args);
		va_end(args);
	}
}
Example #3
0
void
Base64Encode::finalize()
{
  if (BIO_flush(m_impl->m_base64) != 1)
    BOOST_THROW_EXCEPTION(Error(getIndex(), "Failed to flush"));

  while (!isConverterEmpty()) {
    fillOutputBuffer();
    while (!isOutputBufferEmpty()) {
      flushOutputBuffer();
    }
  }
}
Example #4
0
// decode data in d->packetData and fill d->outputBuffer
int K3bFFMpegFile::fillOutputBuffer()
{
    // decode if the output buffer is empty
    if( d->outputBufferSize <= 0 ) {

        // make sure we have data to decode
        if( readPacket() == 0 ) {
            return 0;
        }

        d->outputBufferPos = d->alignedOutputBuffer;
        d->outputBufferSize = AVCODEC_MAX_AUDIO_FRAME_SIZE;

#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO3
        int len = ::avcodec_decode_audio3(
#else
#  ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO2
        int len = ::avcodec_decode_audio2(
#  else
        int len = ::avcodec_decode_audio(
#  endif
#endif

            FFMPEG_CODEC(d->formatContext->streams[0]),
            (short*)d->alignedOutputBuffer,
            &d->outputBufferSize,
#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO3
            &d->packet );
#else
            d->packetData, d->packetSize );
#endif

        if( d->packetSize <= 0 || len < 0 )
            ::av_free_packet( &d->packet );
        if( len < 0 ) {
            kDebug() << "(K3bFFMpegFile) decoding failed for " << m_filename;
            return -1;
        }

        d->packetSize -= len;
        d->packetData += len;
    }

    // if it is still empty try again
    if( d->outputBufferSize <= 0 )
        return fillOutputBuffer();
    else
        return d->outputBufferSize;
}
Example #5
0
size_t
Base64Encode::convert(const uint8_t* data, size_t dataLen)
{
  if (dataLen == 0)
    return 0;

  int wLen = BIO_write(m_impl->m_base64, data, dataLen);

  if (wLen <= 0) { // fail to write data
    if (!BIO_should_retry(m_impl->m_base64)) {
      // we haven't written everything but some error happens, and we cannot retry
      BOOST_THROW_EXCEPTION(Error(getIndex(), "Failed to accept more input"));
    }
    return 0;
  }
  else { // update number of bytes written
    fillOutputBuffer();
    return wLen;
  }
}
Example #6
0
int K3bFFMpegFile::read( char* buf, int bufLen )
{
  if( fillOutputBuffer() > 0 ) {
    int len = QMIN(bufLen, d->outputBufferSize);
    ::memcpy( buf, d->outputBufferPos, len );

    // TODO: only swap if needed
    for( int i = 0; i < len-1; i+=2 ) {
      char a = buf[i];
      buf[i] = buf[i+1];
      buf[i+1] = a;
    }

    d->outputBufferPos += len;
    d->outputBufferSize -= len;
    return len;
  }
  else
    return 0;
}
Example #7
0
int K3bFFMpegFile::read( char* buf, int bufLen )
{
    int ret = fillOutputBuffer();
    if (ret <= 0) {
        return ret;
    }

    int len = qMin(bufLen, d->outputBufferSize);
    ::memcpy( buf, d->outputBufferPos, len );

    // TODO: only swap if needed
    for( int i = 0; i < len-1; i+=2 ) {
        char a = buf[i];
        buf[i] = buf[i+1];
        buf[i+1] = a;
    }

    d->outputBufferPos += len;
    d->outputBufferSize -= len;
    return len;
}
Example #8
0
void
Base64Encode::preTransform()
{
  fillOutputBuffer();
}