コード例 #1
0
ファイル: AudioDecoder.cpp プロジェクト: Kthulhu/avTranscoder
bool AudioDecoder::decodeNextFrame()
{
	if(!_isSetup)
		setupDecoder();

	int got_frame = 0;
	while( ! got_frame )
	{
		CodedData data;

		bool nextPacketRead = _inputStream->readNextPacket( data );
		if( ! nextPacketRead ) // error or end of file
			data.clear();

		int ret = avcodec_decode_audio4( &_inputStream->getAudioCodec().getAVCodecContext(), _frame, &got_frame, &data.getAVPacket() );
		if( ! nextPacketRead && ret == 0 && got_frame == 0 ) // no frame could be decompressed
			return false;
		
		if( ret < 0 )
		{
			throw std::runtime_error( "an error occured during audio decoding" + getDescriptionFromErrorCode( ret ) );
		}
	}
	return true;
}
コード例 #2
0
ファイル: VDPAUDecoder.cpp プロジェクト: JohnChu/libavg
void VDPAUDecoder::render(AVCodecContext* pContext, const AVFrame* pFrame)
{
    vdpau_render_state* pRenderState = (vdpau_render_state*)pFrame->data[0];

    if (m_VDPDecoder == VDP_INVALID_HANDLE) {
        setupDecoder(pContext);
    }

    VdpStatus status = vdp_decoder_render(m_VDPDecoder, pRenderState->surface,
            (VdpPictureInfo const*)&(pRenderState->info),
            pRenderState->bitstream_buffers_used, pRenderState->bitstream_buffers);
    AVG_ASSERT(status == VDP_STATUS_OK);
}
コード例 #3
0
bool AudioPlaySdAac::setupMp4(void)
{
	_ATOM ftyp = findMp4Atom("ftyp",0, false);
	if (!ftyp.size)
		return false; //no mp4/m4a file

	//go through the boxes to find the interesting atoms:
	uint32_t moov = findMp4Atom("moov", 0).position;
	uint32_t trak = findMp4Atom("trak", moov + 8).position;
	uint32_t mdia = findMp4Atom("mdia", trak + 8).position;

	//determine duration:
	uint32_t mdhd = findMp4Atom("mdhd", mdia + 8).position;
	uint32_t timescale = fread32(mdhd + 8 + 0x0c);
	duration = 1000.0 * ((float)fread32(mdhd + 8 + 0x10) / (float)timescale);

	//MP4-data has no aac-frames, so we have to set the parameters by hand.
	uint32_t minf = findMp4Atom("minf", mdia + 8).position;
	uint32_t stbl = findMp4Atom("stbl", minf + 8).position;
	//stsd sample description box: - infos to parametrize the decoder
	_ATOM stsd = findMp4Atom("stsd", stbl + 8);
	if (!stsd.size)
		return false; //something is not ok

	uint16_t channels = fread16(stsd.position + 8 + 0x20);
	//uint16_t channels = 1;
	//uint16_t bits		= fread16(stsd.position + 8 + 0x22); //not used
	uint16_t samplerate = fread32(stsd.position + 8 + 0x26);

	setupDecoder(channels, samplerate, AAC_PROFILE_LC);

	//stco - chunk offset atom:
	uint32_t stco = findMp4Atom("stco", stbl + 8).position;

	//number of chunks:
	uint32_t nChunks = fread32(stco + 8 + 0x04);
	//first entry from chunk table:
	firstChunk = fread32(stco + 8 + 0x08);
	//last entry from chunk table:
	lastChunk = fread32(stco + 8 + 0x04 + nChunks * 4);

	if (nChunks == 1) {
		_ATOM mdat =  findMp4Atom("mdat", 0);
		lastChunk = mdat.size;
	}

#if 0
	Serial.print("mdhd duration=");
	Serial.print(duration);
	Serial.print(" ms, stsd: chan=");
	Serial.print(channels);
	Serial.print(" samplerate=");
	Serial.print(samplerate);
	Serial.print(" nChunks=");
	Serial.print(nChunks);
	Serial.print(" firstChunk=");
	Serial.println(firstChunk, HEX);
	Serial.print(" lastChunk=");
	Serial.println(lastChunk, HEX);
#endif

	return true;
}